From 5a83439bdd5f359b808b0e2c414cdc8abef50bd0 Mon Sep 17 00:00:00 2001 From: Lalitha Pranathi Pulavarthy Date: Sat, 10 Oct 2026 02:48:14 -0400 Subject: [PATCH] Use the right default url for ValueSet and CodeSystem instances getUrlFromFshDefinition fell back to a StructureDefinition url for any Instance, so the tank matched ValueSet and CodeSystem instances on the wrong url. InstanceExporter gives them {canonical}/ValueSet/{id} and {canonical}/CodeSystem/{id}, so the fallback uses that now. --- src/fhirtypes/common.ts | 6 ++++++ test/import/FSHTank.test.ts | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/fhirtypes/common.ts b/src/fhirtypes/common.ts index c540a7293..a10926934 100644 --- a/src/fhirtypes/common.ts +++ b/src/fhirtypes/common.ts @@ -1438,6 +1438,12 @@ export function getUrlFromFshDefinition( fhirType = 'ValueSet'; } else if (fshDefinition instanceof FshCodeSystem) { fhirType = 'CodeSystem'; + } else if ( + fshDefinition instanceof Instance && + (fshDefinition.instanceOf === 'ValueSet' || fshDefinition.instanceOf === 'CodeSystem') + ) { + // match the default URL that the InstanceExporter assigns to definitional instances + fhirType = fshDefinition.instanceOf; } else { fhirType = 'StructureDefinition'; } diff --git a/test/import/FSHTank.test.ts b/test/import/FSHTank.test.ts index e09f2c4d8..0b0e05685 100644 --- a/test/import/FSHTank.test.ts +++ b/test/import/FSHTank.test.ts @@ -527,6 +527,15 @@ describe('FSHTank', () => { expect(tank.fish('ExtensionInstance|2.0.0', Type.Extension)).toBeUndefined(); }); + it('should find an extension defined as an instance definition when fishing by its default url', () => { + expect( + tank.fish( + 'http://hl7.org/fhir/us/minimal/StructureDefinition/ExtensionInstance', + Type.Extension + ).name + ).toBe('ExtensionInstance'); + }); + it('should only find logical models when logical models are requested', () => { expect(tank.fish('log1', Type.Logical).name).toBe('Logical1'); expect( @@ -744,6 +753,21 @@ describe('FSHTank', () => { expect(tank.fish('ValueSetInstance|2.0.0', Type.ValueSet)).toBeUndefined(); }); + it('should find a valueset defined as an instance definition when fishing by its default url', () => { + expect( + tank.fish('http://hl7.org/fhir/us/minimal/ValueSet/ValueSetInstance2', Type.ValueSet).name + ).toBe('ValueSetInstance2'); + }); + + it('should not find a valueset defined as an instance definition when fishing by a StructureDefinition url', () => { + expect( + tank.fish( + 'http://hl7.org/fhir/us/minimal/StructureDefinition/ValueSetInstance2', + Type.ValueSet + ) + ).toBeUndefined(); + }); + it('should only find codesystems when codesystems are requested', () => { expect(tank.fish('cs1', Type.CodeSystem).name).toBe('CodeSystem1'); expect( @@ -813,6 +837,22 @@ describe('FSHTank', () => { expect(tank.fish('CodeSystemInstance|2.0.0', Type.CodeSystem)).toBeUndefined(); }); + it('should find a codesystem defined as an instance definition when fishing by its default url', () => { + expect( + tank.fish('http://hl7.org/fhir/us/minimal/CodeSystem/CodeSystemInstance2', Type.CodeSystem) + .name + ).toBe('CodeSystemInstance2'); + }); + + it('should not find a codesystem defined as an instance definition when fishing by a StructureDefinition url', () => { + expect( + tank.fish( + 'http://hl7.org/fhir/us/minimal/StructureDefinition/CodeSystemInstance2', + Type.CodeSystem + ) + ).toBeUndefined(); + }); + it('should only find instances when instances are requested', () => { expect(tank.fish('inst1', Type.Instance).name).toBe('Instance1'); expect(