From 1e1297ab980ef85a37e96c9295bab945647808b0 Mon Sep 17 00:00:00 2001 From: sebg-mio42 <102145655+sebg-mio42@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:09:22 +0200 Subject: [PATCH] Valueset versioned caret rules (#1493) Fixes #1492 --- src/export/ValueSetExporter.ts | 11 ++++-- test/export/ValueSetExporter.test.ts | 59 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/export/ValueSetExporter.ts b/src/export/ValueSetExporter.ts index 4e74631ba..e27ca9ed7 100644 --- a/src/export/ValueSetExporter.ts +++ b/src/export/ValueSetExporter.ts @@ -298,11 +298,16 @@ export class ValueSetExporter { for (const rule of rules) { const splitConcept = rule.pathArray[0].split('#'); const system = splitConcept[0]; + const baseSystem = system?.split('|')[0]; + const version = system?.split('|')[1]; const code = splitConcept.slice(1).join('#'); - const systemMeta = this.fisher.fishForMetadata(system, Type.CodeSystem); + const systemMeta = this.fisher.fishForMetadata(baseSystem, Type.CodeSystem); let composeIndex = vs.compose?.include?.findIndex(composeElement => { - return composeElement.system === system || composeElement.system === systemMeta?.url; + return ( + (composeElement.system === baseSystem && composeElement.version === version) || + (composeElement.system === systemMeta?.url && composeElement.version === version) + ); }) ?? -1; let composeArray: string; let composeElement: ValueSetComposeIncludeOrExclude; @@ -317,7 +322,7 @@ export class ValueSetExporter { if (conceptIndex === -1) { composeIndex = vs.compose?.exclude?.findIndex(composeElement => { - return composeElement.system === system; + return composeElement.system === baseSystem; }) ?? -1; if (composeIndex !== -1) { composeArray = 'exclude'; diff --git a/test/export/ValueSetExporter.test.ts b/test/export/ValueSetExporter.test.ts index 3a7793bb7..b6f9a35a4 100644 --- a/test/export/ValueSetExporter.test.ts +++ b/test/export/ValueSetExporter.test.ts @@ -2269,6 +2269,65 @@ describe('ValueSetExporter', () => { expect(loggerSpy.getLastMessage('error')).toMatch(/File: ValueSet\.fsh.*Line: 4\D*/s); }); + it('should not throw an error when caret rules are applied to a code from a specific version of a codeSystem', () => { + const valueSet = new FshValueSet('DinnerVS'); + const unversionedComponent = new ValueSetConceptComponentRule(true); + unversionedComponent.from = { system: 'http://food.org/food' }; + unversionedComponent.concepts.push( + new FshCode('Pizza', 'http://food.org/food', 'Delicious pizza to share.') + ); + const versionComponent = new ValueSetConceptComponentRule(true); + versionComponent.from = { system: 'http://food.org/food|2.0.1' }; + versionComponent.concepts.push( + new FshCode('Salad', 'http://food.org/food|2.0.1', 'Plenty of fresh vegetables.') + ); + const designationValue = new CaretValueRule(''); + designationValue.caretPath = 'designation.value'; + designationValue.pathArray = ['http://food.org/food|2.0.1#Salad']; + designationValue.value = 'Salat'; + valueSet.rules.push(unversionedComponent, versionComponent, designationValue); + doc.valueSets.set(valueSet.name, valueSet); + const exported = exporter.export().valueSets; + expect(exported.length).toBe(1); + expect(exported[0]).toEqual({ + resourceType: 'ValueSet', + id: 'DinnerVS', + name: 'DinnerVS', + url: 'http://hl7.org/fhir/us/minimal/ValueSet/DinnerVS', + status: 'draft', + compose: { + include: [ + { + system: 'http://food.org/food', + concept: [ + { + code: 'Pizza', + display: 'Delicious pizza to share.' + } + ] + }, + { + system: 'http://food.org/food', + version: '2.0.1', + concept: [ + { + code: 'Salad', + display: 'Plenty of fresh vegetables.', + designation: [ + { + value: 'Salat' + } + ] + } + ] + } + ] + } + }); + expect(designationValue.isCodeCaretRule).toBeTrue(); + expect(loggerSpy.getAllMessages('error')).toHaveLength(0); + }); + describe('#insertRules', () => { let vs: FshValueSet; let ruleSet: RuleSet;