Skip to content

Commit

Permalink
Check for core package before adding it
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-thompson committed Jul 21, 2023
1 parent 55feabf commit 95e7059
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export async function loadExternalDependencies(
(dep: fhirtypes.ImplementationGuideDependsOn) => `${dep.packageId}@${dep.version}`
) ?? [];
const fhirPackageId = determineCorePackageId(config.config.fhirVersion[0]);
allDependencies.push(`${fhirPackageId}@${config.config.fhirVersion[0]}`);
if (!allDependencies.includes(`${fhirPackageId}@${config.config.fhirVersion[0]}`)) {
allDependencies.push(`${fhirPackageId}@${config.config.fhirVersion[0]}`);
}
await utils.loadAutomaticDependencies(
config.config.fhirVersion[0],
config.config.dependencies ?? [],
Expand Down
26 changes: 25 additions & 1 deletion test/api/FhirToFsh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs-extra';
import path from 'path';
import * as processing from '../../src/utils/Processing';
import { fshtypes } from 'fsh-sushi';
import { logger } from '../../src/utils';
import { FHIRDefinitions, logger } from '../../src/utils';
import { fhirToFsh, ResourceMap } from '../../src/api';
import { loggerSpy } from '../helpers/loggerSpy';
import { EOL } from 'os';
Expand Down Expand Up @@ -111,6 +111,30 @@ describe('fhirToFsh', () => {
expect(results.configuration).toEqual(defaultConfig);
});

it('should try to load external dependencies', async () => {
await fhirToFsh([], {
dependencies: ['hl7.fhir.us.core#3.1.0', 'hl7.fhir.us.mcode@1.0.0']
});
expect(loadSpy).toHaveBeenCalledTimes(1);
expect(loadSpy).toHaveBeenCalledWith(
expect.any(FHIRDefinitions),
expect.objectContaining({
config: expect.objectContaining({
dependencies: [
{
packageId: 'hl7.fhir.us.core',
version: '3.1.0'
},
{
packageId: 'hl7.fhir.us.mcode',
version: '1.0.0'
}
]
})
})
);
});

it('should parse a string input into JSON', async () => {
const results = await fhirToFsh([
JSON.stringify({
Expand Down
23 changes: 23 additions & 0 deletions test/utils/Processing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,29 @@ describe('Processing', () => {
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,
canonical: 'http://example.org',
fhirVersion: ['4.0.1'],
id: 'example',
name: 'Example',
applyExtensionMetadataToRoot: false,
dependencies: [
{ packageId: 'hl7.fhir.us.core', version: '3.1.0' },
{ packageId: 'hl7.fhir.r4.core', version: '4.0.1' }
]
});
const defs = new FHIRDefinitions();
await loadExternalDependencies(defs, config);
// the core FHIR package is only present once in the list
expect(loadedPackages).toHaveLength(3);
expect(loadedPackages).toContain('hl7.fhir.r4.core#4.0.1');
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);
});
});

describe('loadConfiguredDependencies', () => {
Expand Down

0 comments on commit 95e7059

Please sign in to comment.