Repository: FHIR/sushi (ts)

Issue:
Add version to system using |
The FSH documentation (http://build.fhir.org/ig/HL7/fhir-shorthand/branches/master/index.html#coding) implies that we should be able to set version info on Coding using the syntax:
```
{system}|{version}#{code} "{display text}"
```

This is not yet the case, when an author puts a `|` in the URI, it gets interpreted as a part of the URI. So the line:
```
* qualification.code = http://terminology.hl7.org/CodeSystem/v2-0360|2.7#MD
```
Leads to a coding: 
```
{
  "code": "MD",
  "system": "http://terminology.hl7.org/CodeSystem/v2-0360|2.7"
}
```
When it should make the coding:
```
{
  "code": "MD",
  "system": "http://terminology.hl7.org/CodeSystem/v2-0360"
  "version": "2.7"
}
```


Pull request description:
Specify system version when fixing a code
Fixes #252 and completes task https://standardhealthrecord.atlassian.net/browse/CIMPL-287

When fixing a code to a Coding or CodeableConcept, the system string will be split based on a | character into a system and version. If this character is not present, the version will not be defined.

Patch:
diff --git a/src/fhirtypes/ElementDefinition.ts b/src/fhirtypes/ElementDefinition.ts
index 5f61c3f..5a3437e 100644
--- a/src/fhirtypes/ElementDefinition.ts
+++ b/src/fhirtypes/ElementDefinition.ts
@@ -1307,7 +1307,11 @@ export class ElementDefinition {
       coding.code = code.code;
     }
     if (code.system) {
-      coding.system = code.system;
+      if (code.system.indexOf('|') > -1) {
+        [coding.system, coding.version] = code.system.split('|', 2);
+      } else {
+        coding.system = code.system;
+      }
     }
     this.patternCodeableConcept = {
       coding: [coding]
@@ -1341,7 +1345,11 @@ export class ElementDefinition {
       this.patternCoding.code = code.code;
     }
     if (code.system) {
-      this.patternCoding.system = code.system;
+      if (code.system.indexOf('|') > -1) {
+        [this.patternCoding.system, this.patternCoding.version] = code.system.split('|', 2);
+      } else {
+        this.patternCoding.system = code.system;
+      }
     }
   }
 


Test patch:
diff --git a/test/fhirtypes/ElementDefinition.fixFshCode.test.ts b/test/fhirtypes/ElementDefinition.fixFshCode.test.ts
index 740ffcb..a77ff08 100644
--- a/test/fhirtypes/ElementDefinition.fixFshCode.test.ts
+++ b/test/fhirtypes/ElementDefinition.fixFshCode.test.ts
@@ -11,6 +11,7 @@ describe('ElementDefinition', () => {
   let observation: StructureDefinition;
   let fooBarCode: FshCode;
   let barFooCode: FshCode;
+  let versionedCode: FshCode;
   let fisher: TestFisher;
   beforeAll(() => {
     defs = new FHIRDefinitions();
@@ -25,6 +26,7 @@ describe('ElementDefinition', () => {
     observation = fisher.fishForStructureDefinition('Observation');
     fooBarCode = new FshCode('bar', 'http://foo.com');
     barFooCode = new FshCode('foo', 'http://bar.com');
+    versionedCode = new FshCode('versioned', 'http://versioned.com|7.6.5');
   });
 
   describe('#fixFshCode()', () => {
@@ -36,6 +38,20 @@ describe('ElementDefinition', () => {
       });
     });
 
+    it('should fix a code with a version to a CodeableConcept', () => {
+      const concept = observation.findElementByPath('code', fisher);
+      concept.fixFshCode(versionedCode);
+      expect(concept.patternCodeableConcept).toEqual({
+        coding: [
+          {
+            code: 'versioned',
+            system: 'http://versioned.com',
+            version: '7.6.5'
+          }
+        ]
+      });
+    });
+
     it('should throw CodeAlreadyFixedError when fixing a code to a CodeableConcept fixed to a different code', () => {
       const concept = observation.elements.find(e => e.id === 'Observation.code');
       // Setup original fixed code
@@ -67,6 +83,16 @@ describe('ElementDefinition', () => {
       expect(coding.patternCoding).toEqual({ code: 'bar', system: 'http://foo.com' });
     });
 
+    it('should fix a code with a version to a Coding', () => {
+      const coding = observation.findElementByPath('code.coding', fisher);
+      coding.fixFshCode(versionedCode);
+      expect(coding.patternCoding).toEqual({
+        code: 'versioned',
+        system: 'http://versioned.com',
+        version: '7.6.5'
+      });
+    });
+
     it('should throw CodeAlreadyFixedError when fixing a code to a Coding fixed to a different code', () => {
       const concept = observation.elements.find(e => e.id === 'Observation.code');
       concept.unfold(fisher);