Skip to content

Commit

Permalink
Use name and description extensions to set values in generated IG (#666)
Browse files Browse the repository at this point in the history
* Use name and description extensions to set values in generated IG

* Filter resources based on conformance and terminology resources

* Use valueMarkdown instead of string for description
  • Loading branch information
ngfreiter authored Nov 13, 2020
1 parent 3379cb2 commit 8e8000f
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/fhirtypes/dataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type Element = {
*/
export type Extension = {
url: string;
[key: string]: any;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/fhirtypes/specialTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Coding } from './dataTypes';
import { Coding, Extension } from './dataTypes';

/**
* Type to represent FHIR R4 resource metadata.
Expand All @@ -14,4 +14,5 @@ export type Meta = {
profile?: string[];
security?: Coding[];
tag?: Coding[];
extension?: Extension[];
};
27 changes: 26 additions & 1 deletion src/ig/IGExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,13 @@ export class IGExporter {
existingResource?.exampleBoolean || existingResource?.exampleCanonical;
const existingName = existingIsExample ? existingResource.name : null;
const existingDescription = existingIsExample ? existingResource.description : null;

const metaExtensionDescription = this.getMetaExtensionDescription(resourceJSON);
const metaExtensionName = this.getMetaExtensionName(resourceJSON);

newResource.description =
configResource?.description ??
metaExtensionDescription ??
existingDescription ??
(CONFORMANCE_AND_TERMINOLOGY_RESOURCES.has(resourceJSON.resourceType)
? resourceJSON.description
Expand All @@ -1000,7 +1005,8 @@ export class IGExporter {
this.addGroup(newResource.groupingId);
}
if (pathEnd === 'examples') {
newResource.name = configResource?.name ?? existingName ?? resourceJSON.id;
newResource.name =
configResource?.name ?? metaExtensionName ?? existingName ?? resourceJSON.id;
// set exampleCanonical or exampleBoolean, preferring configured values
if (configResource?.exampleCanonical) {
newResource.exampleCanonical = configResource.exampleCanonical;
Expand Down Expand Up @@ -1031,6 +1037,7 @@ export class IGExporter {
const name = typeof resourceJSON.name === 'string' ? resourceJSON.name : null;
newResource.name =
configResource?.name ??
metaExtensionName ??
existingResource?.name ??
title ??
name ??
Expand Down Expand Up @@ -1143,6 +1150,24 @@ export class IGExporter {
}
}

private getMetaExtensionDescription(resource: InstanceDefinition): string {
const description = resource.meta?.extension?.find(
e => e.url === 'http://hl7.org/fhir/StructureDefinition/instance-description'
)?.valueMarkdown;
if (!CONFORMANCE_AND_TERMINOLOGY_RESOURCES.has(resource.resourceType)) {
return description;
}
}

private getMetaExtensionName(resource: InstanceDefinition): string {
const name = resource.meta?.extension?.find(
e => e.url === 'http://hl7.org/fhir/StructureDefinition/instance-name'
)?.valueString;
if (!CONFORMANCE_AND_TERMINOLOGY_RESOURCES.has(resource.resourceType)) {
return name;
}
}

/**
* Writes the in-memory ImplementationGuide JSON to the IG output folder.
*
Expand Down
106 changes: 104 additions & 2 deletions test/ig/IGExporter.IG.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,16 @@ describe('IGExporter', () => {
'StructureDefinition-MyPatient.json',
'StructureDefinition-MyTitlePatient.json'
]);
expect(directoryContents.get('resources')).toEqual(['Patient-BazPatient.json']);
expect(directoryContents.get('resources')).toEqual([
'Patient-BazPatient.json',
'Patient-MetaExtensionNotExamplePatient.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"
'Patient-FooPatient.json', // Renamed from "PoorlyNamedPatient.json"
'Patient-MetaExtensionPatient.json'
]);
});
});
Expand Down Expand Up @@ -1117,6 +1121,104 @@ describe('IGExporter', () => {
});
});

it('should add resource references with a description and name extension 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: 'Patient/MetaExtensionPatient'
},
name: 'MetaExtension Patient Name',
description: 'MetaExtension Patient Description',
exampleBoolean: true
});
});

it('should prefer configured names and descriptions to extensions on resource references', () => {
config.resources = [
{
reference: {
reference: 'Patient/MetaExtensionPatient'
},
name: 'Configured Name',
description: 'Configured Description'
}
];
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: 'Patient/MetaExtensionPatient'
},
name: 'Configured Name',
description: 'Configured Description',
exampleBoolean: true
});
});

it('should add non example resource references with a description and name extension 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: 'Patient/MetaExtensionNotExamplePatient'
},
name: 'MetaExtensionNotExample Patient Name',
description: 'MetaExtensionNotExample Patient Description',
exampleBoolean: false
});
});

it('should prefer non example configured names and descriptions to extensions on resource references', () => {
config.resources = [
{
reference: {
reference: 'Patient/MetaExtensionNotExamplePatient'
},
name: 'Configured Name',
description: 'Configured Description'
}
];
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: 'Patient/MetaExtensionNotExamplePatient'
},
name: 'Configured Name',
description: 'Configured Description',
exampleBoolean: false
});
});

it('should omit predefined resources that are configured to be omitted', () => {
config.resources = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"resourceType": "Patient",
"id": "MetaExtensionPatient",
"meta": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-description",
"valueMarkdown": "MetaExtension Patient Description"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-name",
"valueString": "MetaExtension Patient Name"
}
]
},
"name": [{ "family": "MetaExtension" }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"resourceType": "Patient",
"id": "MetaExtensionNotExamplePatient",
"meta": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-description",
"valueMarkdown": "MetaExtensionNotExample Patient Description"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-name",
"valueString": "MetaExtensionNotExample Patient Name"
}
]
},
"name": [{ "family": "MetaExtensionNotExample" }]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"resourceType": "ValueSet",
"id": "MyVS",
"meta": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-description",
"valueMarkdown": "Ignored Description"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/instance-name",
"valueString": "Ignored Name"
}
]
},
"url": "http://hl7.org/fhir/ValueSet/MyVS",
"version": "4.0.1",
"name": "Yes/No/Don't Know",
Expand Down

0 comments on commit 8e8000f

Please sign in to comment.