diff --git a/src/utils/Processing.ts b/src/utils/Processing.ts index c3d7a7be..6dbebcb3 100644 --- a/src/utils/Processing.ts +++ b/src/utils/Processing.ts @@ -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 ?? [], diff --git a/test/api/FhirToFsh.test.ts b/test/api/FhirToFsh.test.ts index 51140e4b..f1a75b49 100644 --- a/test/api/FhirToFsh.test.ts +++ b/test/api/FhirToFsh.test.ts @@ -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'; @@ -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({ diff --git a/test/utils/Processing.test.ts b/test/utils/Processing.test.ts index 6a74462c..5d11bcc2 100644 --- a/test/utils/Processing.test.ts +++ b/test/utils/Processing.test.ts @@ -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', () => {