Repository: FHIR/sushi (ts)

Issue:
IG resource generating "description" incorrectly
Reported by Eric Haas on Zulip ([link](https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/bug.20in.20ig.20.20resource.20generation.20for.20v.201.2E0.2E0)):

The IG Resource has a incorrect structure when add in a Goal example resource to the definitions list.
briefly is creating description object instead of string using the content from Goal.description which is type codeable concept. This may happen with other non conformance resource with a `description` element too, so I would check that out...

Here is the example file: https://www.hl7.org/fhir/us/core/Goal-goal-1.html

here is the offending bit in the generated IG resource:

```yaml
    - reference:
        reference: Goal/goal-1
      description:  #####should be string not object####
        text: Patient is targeting a pulse oximetry of 92% and a weight of 195 lbs
      name: goal-1
      exampleCanonical: 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-goal'
```

should be:

```yaml
    - reference:
        reference: Goal/goal-1
      description:  Patient is targeting a pulse oximetry of 92% and a weight of 195 lbs
      name: goal-1
      exampleCanonical: 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-goal'
```

Pull request description:
Don't use non-conformance type descriptions when building IG resource
Fixes #629

Patch:
diff --git a/src/ig/IGExporter.ts b/src/ig/IGExporter.ts
index 716d8e4..3de2004 100644
--- a/src/ig/IGExporter.ts
+++ b/src/ig/IGExporter.ts
@@ -32,6 +32,25 @@ import { logger, Type } from '../utils';
 import { FHIRDefinitions } from '../fhirdefs';
 import { Configuration } from '../fshtypes';
 
+// List of Conformance and Terminology resources from http://hl7.org/fhir/R4/resourcelist.html
+const CONFORMANCE_AND_TERMINOLOGY_RESOURCES = new Set([
+  'CapabilityStatement',
+  'StructureDefinition',
+  'ImplementationGuide',
+  'SearchParameter',
+  'MessageDefinition',
+  'OperationDefinition',
+  'CompartmentDefinition',
+  'StructureMap',
+  'GraphDefinition',
+  'ExampleScenario',
+  'CodeSystem',
+  'ValueSet',
+  'ConceptMap',
+  'NamingSystem',
+  'TerminologyCapabilities'
+]);
+
 /**
  * The IG Exporter exports the FSH artifacts into a file structure supported by the IG Publisher.
  * This allows a FSH Tank to be built as a FHIR IG.  Currently, template-based IG publishing is
@@ -967,7 +986,11 @@ export class IGExporter {
               const existingName = existingIsExample ? existingResource.name : null;
               const existingDescription = existingIsExample ? existingResource.description : null;
               newResource.description =
-                configResource?.description ?? existingDescription ?? resourceJSON.description;
+                configResource?.description ??
+                existingDescription ??
+                (CONFORMANCE_AND_TERMINOLOGY_RESOURCES.has(resourceJSON.resourceType)
+                  ? resourceJSON.description
+                  : undefined);
               if (configResource?.fhirVersion) {
                 newResource.fhirVersion = configResource.fhirVersion;
               }


Test patch:
diff --git a/test/ig/IGExporter.IG.test.ts b/test/ig/IGExporter.IG.test.ts
index db150e5..2f80af6 100644
--- a/test/ig/IGExporter.IG.test.ts
+++ b/test/ig/IGExporter.IG.test.ts
@@ -865,6 +865,7 @@ describe('IGExporter', () => {
       expect(directoryContents.get('resources')).toEqual(['Patient-BazPatient.json']);
       expect(directoryContents.get('vocabulary')).toEqual(['ValueSet-MyVS.json']);
       expect(directoryContents.get('examples')).toEqual([
+        'Goal-GoalWithDescription.json',
         'Patient-BarPatient.json',
         'Patient-FooPatient.json' // Renamed from "PoorlyNamedPatient.json"
       ]);
@@ -1037,6 +1038,26 @@ describe('IGExporter', () => {
       });
     });
 
+    it('should not include a description for non-conformance resources when adding them to the ImplementationGuide resource', () => {
+      exporter.export(tempOut);
+      const igPath = path.join(
+        tempOut,
+        'fsh-generated',
+        'resources',
+        'ImplementationGuide-fhir.us.minimal.json'
+      );
+      expect(fs.existsSync(igPath)).toBeTruthy();
+      const igContent: ImplementationGuide = fs.readJSONSync(igPath);
+      expect(igContent.definition.resource).toContainEqual({
+        reference: {
+          reference: 'Goal/GoalWithDescription'
+        },
+        name: 'GoalWithDescription',
+        // NOTE: no description since Goal is not a conformance resource (and Goal.description is a CodeableConcept)
+        exampleBoolean: true
+      });
+    });
+
     it('should add example references to the ImplementationGuide resource', () => {
       exporter.export(tempOut);
       const igPath = path.join(
@@ -1063,6 +1084,13 @@ describe('IGExporter', () => {
         name: 'BarPatient',
         exampleCanonical: 'http://hl7.org/fhir/sushi-test/StructureDefinition/MyPatient'
       });
+      expect(igContent.definition.resource).toContainEqual({
+        reference: {
+          reference: 'Goal/GoalWithDescription'
+        },
+        name: 'GoalWithDescription',
+        exampleBoolean: true
+      });
     });
 
     it('should add resource references with a title to the ImplementationGuide resource', () => {
diff --git a/test/ig/fixtures/customized-ig-with-resources/ig-data/input/examples/Goal-GoalWithDescription.json b/test/ig/fixtures/customized-ig-with-resources/ig-data/input/examples/Goal-GoalWithDescription.json
new file mode 100644
index 0000000..0c0e575
--- /dev/null
+++ b/test/ig/fixtures/customized-ig-with-resources/ig-data/input/examples/Goal-GoalWithDescription.json
@@ -0,0 +1,11 @@
+{
+  "resourceType": "Goal",
+  "id": "GoalWithDescription",
+  "lifecycleStatus": "on-hold",
+  "description": {
+    "text": "Target weight is 160 to 180 lbs."
+  },
+  "subject": {
+    "reference": "Patient/BarPatient"
+  }
+}