Repository: FHIR/sushi (ts)

Issue:
Aliases are limited
If you define `Alias: systemCPN = example.com`, then you can use that alias in some places, but not others. For example, you could use the alias in a code, like `someCode#systemCPN`, but you could not use the alias when fixing a value, `* identifier[0].system = systemCPN`. It may be better to expand the usefulness of aliases by allowing them to appear in more places.

Pull request description:
Resolve Aliases used in Fixed Value Rules
Fixes #87 

This PR adds support for resolving aliases that are used in Fixed Value rules. I also updated the check for if a rule is referencing a resource to not evaluate to true if we are resolving an alias. The two tests show two examples to test to ensure this works. These tests will fail on master, but pass on this branch.

I also looked through the other rules where aliases could potentially be used, and it looks like all other rules resolve aliases where possible.

Patch:
diff --git a/src/import/FSHImporter.ts b/src/import/FSHImporter.ts
index 71e15a9..77c6a97 100644
--- a/src/import/FSHImporter.ts
+++ b/src/import/FSHImporter.ts
@@ -987,13 +987,14 @@ export class FSHImporter extends FSHVisitor {
     fixedValueRule.fixedValue = this.visitValue(ctx.value());
     fixedValueRule.exactly = ctx.KW_EXACTLY() != null;
     fixedValueRule.units = ctx.KW_UNITS() != null;
-    fixedValueRule.isResource = ctx.value().SEQUENCE() != null;
+    fixedValueRule.isResource =
+      ctx.value().SEQUENCE() != null && !this.allAliases.has(ctx.value().SEQUENCE().getText());
     return fixedValueRule;
   }
 
   visitValue(ctx: pc.ValueContext): FixedValueType {
     if (ctx.SEQUENCE()) {
-      return ctx.SEQUENCE().getText();
+      return this.aliasAwareValue(ctx, ctx.SEQUENCE().getText());
     }
 
     if (ctx.STRING()) {


Test patch:
diff --git a/test/import/FSHImporter.Instance.test.ts b/test/import/FSHImporter.Instance.test.ts
index 5cdf815..b86c288 100644
--- a/test/import/FSHImporter.Instance.test.ts
+++ b/test/import/FSHImporter.Instance.test.ts
@@ -189,6 +189,23 @@ describe('FSHImporter', () => {
         );
       });
 
+      it('should parse an instance with fixed values that are an alias', () => {
+        const input = `
+        Alias: EXAMPLE = http://example.org
+
+        Instance: PatientExample
+        InstanceOf: Patient
+        * identifier[0].system = EXAMPLE
+        `;
+
+        const result = importSingleText(input);
+        expect(result.instances.size).toBe(1);
+        const instance = result.instances.get('PatientExample');
+        expect(instance.rules).toHaveLength(1);
+        expect(instance.instanceOf).toBe('Patient');
+        assertFixedValueRule(instance.rules[0], 'identifier[0].system', 'http://example.org');
+      });
+
       it('should parse an instance with fixed value resource rules', () => {
         const input = `
         Instance: SamplePatient
diff --git a/test/import/FSHImporter.Profile.test.ts b/test/import/FSHImporter.Profile.test.ts
index bd09d62..6196ffb 100644
--- a/test/import/FSHImporter.Profile.test.ts
+++ b/test/import/FSHImporter.Profile.test.ts
@@ -1123,6 +1123,21 @@ describe('FSHImporter', () => {
         assertFixedValueRule(profile.rules[0], 'basedOn', expectedReference);
       });
 
+      it('should parse fixed values that are an alias', () => {
+        const input = `
+        Alias: EXAMPLE = http://example.org
+
+        Profile: PatientProfile
+        Parent: Patient
+        * identifier.system = EXAMPLE
+        `;
+
+        const result = importSingleText(input);
+        const profile = result.profiles.get('PatientProfile');
+        expect(profile.rules).toHaveLength(1);
+        assertFixedValueRule(profile.rules[0], 'identifier.system', 'http://example.org');
+      });
+
       it('should log an error and skip the rule when parsing fixed value Resource rule', () => {
         const input = `