-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for loading FHIR R6 versions
Note: this depends on an update from SUSHI that is not available yet
- Loading branch information
Showing
3 changed files
with
94 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ export async function loadExternalDependencies( | |
config.config.dependencies?.map( | ||
(dep: fhirtypes.ImplementationGuideDependsOn) => `${dep.packageId}@${dep.version}` | ||
) ?? []; | ||
const fhirPackageId = determineCorePackageId(config.config.fhirVersion[0]); | ||
const fhirPackageId = utils.getFHIRVersionInfo(config.config.fhirVersion[0])?.packageId; | ||
if (!allDependencies.includes(`${fhirPackageId}@${config.config.fhirVersion[0]}`)) { | ||
allDependencies.push(`${fhirPackageId}@${config.config.fhirVersion[0]}`); | ||
} | ||
|
@@ -139,7 +139,7 @@ export function loadConfiguredDependencies( | |
dependencies: string[] = [] | ||
): Promise<FHIRDefinitions | void>[] { | ||
// Automatically include FHIR R4 if no other versions of FHIR are already included | ||
if (!dependencies.some(dep => /hl7\.fhir\.r(4|5|4b)\.core/.test(dep))) { | ||
if (!dependencies.some(dep => /hl7\.fhir\.r(4|5|4b|6)\.core/.test(dep))) { | ||
dependencies.push('[email protected]'); | ||
} | ||
|
||
|
@@ -333,20 +333,6 @@ export function getFilesRecursive(dir: string): string[] { | |
} | ||
} | ||
|
||
export function determineCorePackageId(fhirVersion: string): string { | ||
if (/^4\.0\./.test(fhirVersion)) { | ||
return 'hl7.fhir.r4.core'; | ||
} else if (/^(4\.1\.|4\.3.\d+-)/.test(fhirVersion)) { | ||
return 'hl7.fhir.r4b.core'; | ||
} else if (/^4\.3.\d+$/.test(fhirVersion)) { | ||
return 'hl7.fhir.r4b.core'; | ||
} else if (/^5\.0.\d+$/.test(fhirVersion)) { | ||
return 'hl7.fhir.r5.core'; | ||
} else { | ||
return 'hl7.fhir.r5.core'; | ||
} | ||
} | ||
|
||
const IGNORED_RESOURCE_LIKE_FILES = [ | ||
// If expansions.json is in an output directory, it was likely generated by the IG Publisher | ||
// Since it is a generated file and it can be large, we skip processing it | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import { Fhir } from 'fhir/fhir'; | |
import readlineSync from 'readline-sync'; | ||
import { loggerSpy } from '../helpers/loggerSpy'; | ||
import { | ||
determineCorePackageId, | ||
ensureOutputDir, | ||
getInputDir, | ||
getResources, | ||
|
@@ -40,7 +39,8 @@ jest.mock('fhir-package-loader', () => { | |
if ( | ||
packageName === 'hl7.fhir.r4.core' || | ||
packageName === 'hl7.fhir.us.core' || | ||
packageName === 'hl7.fhir.r4b.core' | ||
packageName === 'hl7.fhir.r4b.core' || | ||
packageName === 'hl7.fhir.r6.core' | ||
) { | ||
loadedPackages.push(`${packageName}#${version}`); | ||
return Promise.resolve(FHIRDefs); | ||
|
@@ -59,7 +59,7 @@ jest.mock('fsh-sushi', () => { | |
utils: { | ||
...original.utils, | ||
loadAutomaticDependencies: jest.fn(async () => { | ||
// this is just one of the usual automatic depencies, as an example | ||
// this is just one of the usual automatic dependencies, as an example | ||
loadedPackages.push('hl7.terminology.r4#1.0.0'); | ||
return Promise.resolve(); | ||
}) | ||
|
@@ -611,6 +611,44 @@ describe('Processing', () => { | |
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
|
||
it('should load FHIR R6 prerelease when specified in config fhirVersion', async () => { | ||
const config = new ExportableConfiguration({ | ||
FSHOnly: true, | ||
canonical: 'http://example.org', | ||
fhirVersion: ['6.0.0-ballot2'], | ||
id: 'example', | ||
name: 'Example', | ||
applyExtensionMetadataToRoot: false, | ||
dependencies: [{ packageId: 'hl7.fhir.us.core', version: '3.1.0' }] | ||
}); | ||
const defs = new FHIRDefinitions(); | ||
await loadExternalDependencies(defs, config); | ||
expect(loadedPackages).toHaveLength(3); | ||
expect(loadedPackages).toContain('hl7.fhir.r6.core#6.0.0-ballot2'); | ||
expect(loadedPackages).toContain('hl7.fhir.us.core#3.1.0'); | ||
expect(loadedPackages).toContain('hl7.terminology.r4#1.0.0'); | ||
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
|
||
it('should load FHIR R6 official release when specified in config fhirVersion', async () => { | ||
const config = new ExportableConfiguration({ | ||
FSHOnly: true, | ||
canonical: 'http://example.org', | ||
fhirVersion: ['6.0.0'], | ||
id: 'example', | ||
name: 'Example', | ||
applyExtensionMetadataToRoot: false, | ||
dependencies: [{ packageId: 'hl7.fhir.us.core', version: '3.1.0' }] | ||
}); | ||
const defs = new FHIRDefinitions(); | ||
await loadExternalDependencies(defs, config); | ||
expect(loadedPackages).toHaveLength(3); | ||
expect(loadedPackages).toContain('hl7.fhir.r6.core#6.0.0'); | ||
expect(loadedPackages).toContain('hl7.fhir.us.core#3.1.0'); | ||
expect(loadedPackages).toContain('hl7.terminology.r4#1.0.0'); | ||
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
|
||
it('should not add the identified FHIR core package to the list of dependencies when it is already there', async () => { | ||
const config = new ExportableConfiguration({ | ||
FSHOnly: true, | ||
|
@@ -702,6 +740,28 @@ describe('Processing', () => { | |
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
it('should load FHIR R6 prerelease if specified', () => { | ||
const defs = new FHIRDefinitions(); | ||
const dependencies = ['[email protected]']; | ||
const dependencyDefs = loadConfiguredDependencies(defs, dependencies); | ||
return Promise.all(dependencyDefs).then(() => { | ||
expect(loadedPackages).toHaveLength(1); | ||
expect(loadedPackages).toContain('hl7.fhir.r6.core#6.0.0-ballot2'); // Only contains r6, doesn't load r4 | ||
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
it('should load FHIR R6 if specified', () => { | ||
const defs = new FHIRDefinitions(); | ||
const dependencies = ['[email protected]']; | ||
const dependencyDefs = loadConfiguredDependencies(defs, dependencies); | ||
return Promise.all(dependencyDefs).then(() => { | ||
expect(loadedPackages).toHaveLength(1); | ||
expect(loadedPackages).toContain('hl7.fhir.r6.core#6.0.0'); // Only contains r6, doesn't load r4 | ||
expect(loggerSpy.getAllMessages('error')).toHaveLength(0); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getIgPathFromIgIni', () => { | ||
|
@@ -737,28 +797,6 @@ describe('Processing', () => { | |
}); | ||
}); | ||
|
||
describe('determineCorePackageId', () => { | ||
it('should get R4 package id with R4 version', () => { | ||
expect(determineCorePackageId('4.0.1')).toEqual('hl7.fhir.r4.core'); | ||
}); | ||
|
||
it('should get R4B package id with R4B versions', () => { | ||
expect(determineCorePackageId('4.1.0')).toEqual('hl7.fhir.r4b.core'); | ||
expect(determineCorePackageId('4.3.0')).toEqual('hl7.fhir.r4b.core'); | ||
expect(determineCorePackageId('4.3.0-snapshot1')).toEqual('hl7.fhir.r4b.core'); | ||
}); | ||
|
||
it('should get R5 package id with R5 version', () => { | ||
expect(determineCorePackageId('4.6.0')).toEqual('hl7.fhir.r5.core'); | ||
expect(determineCorePackageId('5.0.0')).toEqual('hl7.fhir.r5.core'); | ||
expect(determineCorePackageId('5.0.0-snapshot1')).toEqual('hl7.fhir.r5.core'); | ||
}); | ||
|
||
it('should default to R5 package id when version is unrecognized', () => { | ||
expect(determineCorePackageId('6.0.0')).toEqual('hl7.fhir.r5.core'); | ||
}); | ||
}); | ||
|
||
describe('getFhirProcessor', () => { | ||
let fixtures: string; | ||
|
||
|