Skip to content

Commit

Permalink
System version doesn't need to match when assigning a code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mint-thompson committed Aug 2, 2023
1 parent 4d02d90 commit 5a0c9b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,12 @@ export function replaceReferences<T extends AssignmentRule | CaretValueRule>(
}
}
} 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
);
Expand Down
30 changes: 30 additions & 0 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 5a0c9b3

Please sign in to comment.