Skip to content

Commit

Permalink
Add support for loading FHIR R6 versions
Browse files Browse the repository at this point in the history
Note: this depends on an update from SUSHI that is not available yet
  • Loading branch information
jafeltra committed Oct 9, 2024
1 parent ce66c8d commit 860b816
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 41 deletions.
18 changes: 2 additions & 16 deletions src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`);
}
Expand All @@ -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]');
}

Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/extractor/ConfigurationExtractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,35 @@ describe('ConfigurationExtractor', () => {
expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
});

it('should create a Configuration from an ImplementationGuide with supported fhirVersions', () => {
const ig = JSON.parse(
fs.readFileSync(path.join(__dirname, 'fixtures', 'simple-ig.json'), 'utf-8')
);
let result = ConfigurationExtractor.process([ig, ...resources]);
expect(result).toBeInstanceOf(ExportableConfiguration);
expect(result.config.fhirVersion).toEqual(['4.5.0']); // From IG

ig.fhirVersion = ['4.0.1'];
result = ConfigurationExtractor.process([ig, ...resources]);
expect(result).toBeInstanceOf(ExportableConfiguration);
expect(result.config.fhirVersion).toEqual(['4.0.1']); // From IG

ig.fhirVersion = ['5.0.0'];
result = ConfigurationExtractor.process([ig, ...resources]);
expect(result).toBeInstanceOf(ExportableConfiguration);
expect(result.config.fhirVersion).toEqual(['5.0.0']); // From IG

ig.fhirVersion = ['6.0.0-ballot2'];
result = ConfigurationExtractor.process([ig, ...resources]);
expect(result).toBeInstanceOf(ExportableConfiguration);
expect(result.config.fhirVersion).toEqual(['6.0.0-ballot2']); // From IG

ig.fhirVersion = ['6.0.0'];
result = ConfigurationExtractor.process([ig, ...resources]);
expect(result).toBeInstanceOf(ExportableConfiguration);
expect(result.config.fhirVersion).toEqual(['6.0.0']); // From IG
});

it('should create a Configuration with an inferred url form an ImplementationGuide missing a url', () => {
const ig = JSON.parse(
fs.readFileSync(path.join(__dirname, 'fixtures', 'missing-url-ig.json'), 'utf-8')
Expand Down
88 changes: 63 additions & 25 deletions test/utils/Processing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Fhir } from 'fhir/fhir';
import readlineSync from 'readline-sync';
import { loggerSpy } from '../helpers/loggerSpy';
import {
determineCorePackageId,
ensureOutputDir,
getInputDir,
getResources,
Expand Down Expand Up @@ -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);
Expand All @@ -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();
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 860b816

Please sign in to comment.