Repository: FHIR/sushi (ts)

Issue:
Cannot set version on ValueSet compose.include elements
See this thread for details: https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/Specifying.20version.20on.20a.20code.20system.20URI.

We support setting versions using the `|` when fixing codes, but we don't support this when setting the `compose.include` or `compose.exclude` elements on a ValueSet, so it is difficult to set a version.

Pull request description:
Allow version in concept system for ValueSet
Fixes #346 and completes task https://standardhealthrecord.atlassian.net/browse/CIMPL-334

When declaring a concept component for a ValueSet, the system uri may be followed by a pipe and a version string. This is aligned with other scenarios that use a system uri.

Note that this fix is specifically for specifying the version in a uri for a code system when defining a value set component. Specifying the version in a uri for a value set in this situation was already working.

Patch:
diff --git a/src/export/ValueSetExporter.ts b/src/export/ValueSetExporter.ts
index 957f29e..9958180 100644
--- a/src/export/ValueSetExporter.ts
+++ b/src/export/ValueSetExporter.ts
@@ -47,9 +47,12 @@ export class ValueSetExporter {
       components.forEach(component => {
         const composeElement: ValueSetComposeIncludeOrExclude = {};
         if (component.from.system) {
-          composeElement.system =
+          const foundSystem = (
             this.fisher.fishForMetadata(component.from.system, Type.CodeSystem)?.url ??
-            component.from.system;
+            component.from.system
+          ).split('|');
+          composeElement.system = foundSystem[0];
+          composeElement.version = foundSystem.slice(1).join('|') || undefined;
           if (!isUri(composeElement.system)) {
             throw new InvalidUriError(composeElement.system);
           }


Test patch:
diff --git a/test/export/ValueSetExporter.test.ts b/test/export/ValueSetExporter.test.ts
index 317616c..10f271c 100644
--- a/test/export/ValueSetExporter.test.ts
+++ b/test/export/ValueSetExporter.test.ts
@@ -301,6 +301,43 @@ describe('ValueSetExporter', () => {
     });
   });
 
+  it('should export a value set that includes a concept component where the concept system includes a version', () => {
+    const valueSet = new FshValueSet('BreakfastVS');
+    const toastComponent = new ValueSetConceptComponent(true);
+    toastComponent.from = { system: 'http://food.org/food|2.0.1' };
+    toastComponent.concepts.push(new FshCode('Toast', 'http://food.org/food|2.0.1'));
+    valueSet.components.push(toastComponent);
+    const juiceComponent = new ValueSetConceptComponent(true);
+    juiceComponent.from = { system: 'http://food.org/beverage|1.1|x' };
+    juiceComponent.concepts.push(new FshCode('Orange juice', 'http://food.org/beverage|1.1|x'));
+    valueSet.components.push(juiceComponent);
+    doc.valueSets.set(valueSet.name, valueSet);
+    const exported = exporter.export().valueSets;
+    expect(exported.length).toBe(1);
+    expect(exported[0]).toEqual({
+      resourceType: 'ValueSet',
+      id: 'BreakfastVS',
+      name: 'BreakfastVS',
+      url: 'http://example.com/ValueSet/BreakfastVS',
+      version: '0.0.1',
+      status: 'active',
+      compose: {
+        include: [
+          {
+            system: 'http://food.org/food',
+            concept: [{ code: 'Toast' }],
+            version: '2.0.1'
+          },
+          {
+            system: 'http://food.org/beverage',
+            concept: [{ code: 'Orange juice' }],
+            version: '1.1|x'
+          }
+        ]
+      }
+    });
+  });
+
   it('should export a value set that includes a filter component with a regex filter', () => {
     const valueSet = new FshValueSet('BreakfastVS');
     const component = new ValueSetFilterComponent(true);