From 5a0c9b3a53ca3226d3c46d0b0953e2d94d0850bc Mon Sep 17 00:00:00 2001 From: Mint Thompson Date: Wed, 2 Aug 2023 13:16:27 -0400 Subject: [PATCH 1/2] System version doesn't need to match when assigning a code A code assigned with a system may include a version as part of the system. This is generally intended to refer to the system's published version in the world, and is not guaranteed to match the version of the CodeSystem FHIR resource. Fish for any version when resolving the system, and do not emit a warning even if the versions don't match. --- src/fhirtypes/common.ts | 5 ++++- test/export/InstanceExporter.test.ts | 30 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/fhirtypes/common.ts b/src/fhirtypes/common.ts index 03097562a..ddda75359 100644 --- a/src/fhirtypes/common.ts +++ b/src/fhirtypes/common.ts @@ -942,9 +942,12 @@ export function replaceReferences( } } } else if (value instanceof FshCode) { + // the version on a CodeSystem resource is not the same as the system's actual version out in the world. + // so, they don't need to match. + const baseSystem = value.system?.split('|')[0]; const codeSystemMeta = fishForMetadataBestVersion( fisher, - value.system, + baseSystem, rule.sourceInfo, Type.CodeSystem ); diff --git a/test/export/InstanceExporter.test.ts b/test/export/InstanceExporter.test.ts index b5b61c423..7f76a9145 100644 --- a/test/export/InstanceExporter.test.ts +++ b/test/export/InstanceExporter.test.ts @@ -6287,6 +6287,36 @@ describe('InstanceExporter', () => { ]); }); + it('should assign a code with a version while replacing the code system name with its url regardless of the specified version', () => { + // the version on a CodeSystem resource is not the same as the system's actual version out in the world. + // so, they don't need to match. + const brightInstance = new Instance('BrightObservation'); + brightInstance.instanceOf = 'Observation'; + const assignedCodeRule = new AssignmentRule('code'); + assignedCodeRule.value = new FshCode('bright', 'Visible|1.2.3'); + brightInstance.rules.push(assignedCodeRule); + doc.instances.set(brightInstance.name, brightInstance); + + const visibleSystem = new FshCodeSystem('Visible'); + const visibleSystemUrl = new CaretValueRule(''); + visibleSystemUrl.caretPath = 'url'; + visibleSystemUrl.value = 'http://hl7.org/fhir/us/minimal/CodeSystem/Visible'; + const visibleSystemVersion = new CaretValueRule(''); + visibleSystemVersion.caretPath = 'version'; + visibleSystemVersion.value = '1.0.0'; + visibleSystem.rules.push(visibleSystemUrl, visibleSystemVersion); + doc.codeSystems.set(visibleSystem.name, visibleSystem); + const exported = exportInstance(brightInstance); + expect(exported.code.coding).toEqual([ + { + code: 'bright', + version: '1.2.3', + system: 'http://hl7.org/fhir/us/minimal/CodeSystem/Visible' + } + ]); + expect(loggerSpy.getAllMessages('warn')).toHaveLength(0); + }); + it('should assign a code to a top level element if the code system was defined as an instance of usage definition', () => { const visibleSystem = new Instance('Visible'); visibleSystem.instanceOf = 'CodeSystem'; From ac986ca789f78e524aee298fe90860aa1fca1247 Mon Sep 17 00:00:00 2001 From: Mint Thompson Date: Fri, 4 Aug 2023 11:44:45 -0400 Subject: [PATCH 2/2] Use regular metadata fishing when we remove the version --- src/fhirtypes/common.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/fhirtypes/common.ts b/src/fhirtypes/common.ts index 0da61acf0..83b61fcde 100644 --- a/src/fhirtypes/common.ts +++ b/src/fhirtypes/common.ts @@ -35,7 +35,7 @@ import { } from '../fshtypes'; import { FSHTank } from '../import'; import { Type, Fishable, Metadata } from '../utils/Fishable'; -import { fishForMetadataBestVersion, fishInTankBestVersion, logger } from '../utils'; +import { fishInTankBestVersion, logger } from '../utils'; import { buildSliceTree, calculateSliceTreeCounts } from './sliceTree'; import { InstanceExporter } from '../export'; import { MismatchedTypeError } from '../errors'; @@ -955,12 +955,7 @@ export function replaceReferences( // the version on a CodeSystem resource is not the same as the system's actual version out in the world. // so, they don't need to match. const baseSystem = value.system?.split('|')[0]; - const codeSystemMeta = fishForMetadataBestVersion( - fisher, - baseSystem, - rule.sourceInfo, - Type.CodeSystem - ); + const codeSystemMeta = fisher.fishForMetadata(baseSystem, Type.CodeSystem); if (codeSystemMeta) { clone = cloneDeep(rule); const assignedCode = getRuleValue(clone) as FshCode;