Skip to content

Commit

Permalink
Allow name/description in Instances (#1104)
Browse files Browse the repository at this point in the history
* Init commit

* Tests added

* Undeleted instancemeta, moved logic to be under the if statement for #definition usage, added tests

* Update test/export/InstanceExporter.test.ts

Co-authored-by: Chris Moesel <[email protected]>

* Update test/export/InstanceExporter.test.ts

Co-authored-by: Chris Moesel <[email protected]>

* Update test/export/InstanceExporter.test.ts

Co-authored-by: Chris Moesel <[email protected]>

* Removed name and status for patient

* Update test case so id/title/description are consistent

Co-authored-by: gthuran <Suma1-dumont>
Co-authored-by: Chris Moesel <[email protected]>
Co-authored-by: Chris Moesel <[email protected]>
  • Loading branch information
3 people committed Feb 24, 2023
1 parent 2c5348b commit e48e550
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/export/InstanceExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,30 @@ export class InstanceExporter implements Fishable {
}
if (fshDefinition.usage) {
instanceDef._instanceMeta.usage = fshDefinition.usage;
if (
fshDefinition.usage === 'Definition' &&
instanceOfStructureDefinition.elements.some(
element => element.id === `${instanceOfStructureDefinition.type}.url`
)
) {
instanceDef.url = `${this.tank.config.canonical}/${instanceOfStructureDefinition.type}/${fshDefinition.id}`;
if (fshDefinition.usage === 'Definition') {
if (
instanceOfStructureDefinition.elements.some(
element => element.id === `${instanceOfStructureDefinition.type}.url`
)
) {
instanceDef.url = `${this.tank.config.canonical}/${instanceOfStructureDefinition.type}/${fshDefinition.id}`;
}
if (
fshDefinition.title &&
instanceOfStructureDefinition.elements.some(
element => element.id === `${instanceOfStructureDefinition.type}.title`
)
) {
instanceDef.title = fshDefinition.title;
}
if (
fshDefinition.description &&
instanceOfStructureDefinition.elements.some(
element => element.id === `${instanceOfStructureDefinition.type}.description`
)
) {
instanceDef.description = fshDefinition.description;
}
}
}
if (isResource) {
Expand Down
62 changes: 62 additions & 0 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5245,6 +5245,68 @@ describe('InstanceExporter', () => {
/CaretValueRule.*Instance.*File: Caret\.fsh.*Line: 1 - 3.*Applied in File: Insert\.fsh.*Applied on Line: 5 - 7/s
);
});

it('should populate title and description when specified for instances with #definition', () => {
// Instance: DemoQuestionnaire
// InstanceOf: Questionnaire
// Usage: #definition
// Title: "My Demo Questionnaire"
// Description: "My Demo Questionnaire's description"
//* name = "DemoQuestionnaire"
//* status = #draft
const goalInstance = new Instance('DemoQuestionnaire');
goalInstance.instanceOf = 'Questionnaire';
goalInstance.usage = 'Definition';
goalInstance.title = 'My Demo Questionnaire';
goalInstance.description = "My Demo Questionnaire's description";
const statusDraft = new AssignmentRule('status');
statusDraft.value = new FshCode('draft');
const nameDemo = new AssignmentRule('name');
nameDemo.value = new FshCode('DemoQuestionnaire');
goalInstance.rules.push(statusDraft, nameDemo);
const exported = exportInstance(goalInstance);
expect(exported.title).toMatch('My Demo Questionnaire');
expect(exported.description).toMatch("My Demo Questionnaire's description");
});

it("should not populate title and description when specified for instances that aren't #definition", () => {
// Instance: DemoQuestionnaire
// InstanceOf: Questionnaire
// Usage: #example
// Title: "My Demo Questionnaire"
// Description: "My Demo Questionnaire's description"
//* name = "DemoQuestionnaire"
//* status = #draft
const goalInstance = new Instance('DemoQuestionnaire');
goalInstance.instanceOf = 'Questionnaire';
goalInstance.usage = 'Example';
goalInstance.title = 'My Demo Questionnaire';
goalInstance.description = "My Demo Questionnaire's description";
const statusDraft = new AssignmentRule('status');
statusDraft.value = new FshCode('draft');
const nameDemo = new AssignmentRule('name');
nameDemo.value = new FshCode('DemoQuestionnaire');
goalInstance.rules.push(statusDraft, nameDemo);
const exported = exportInstance(goalInstance);
expect(exported.title).toBeUndefined();
expect(exported.description).toBeUndefined();
});

it("should not populate title and description for instances that don't have title or description (like Patient)", () => {
// Instance: JustAPatient
// InstanceOf: Patient
// Usage: #definition
// Title: "Just a Patient"
// Description: "This is just a patient"
const goalInstance = new Instance('JustAPatient');
goalInstance.instanceOf = 'Patient';
goalInstance.usage = 'Definition';
goalInstance.title = 'Just a Patient';
goalInstance.description = 'This is just a patient';
const exported = exportInstance(goalInstance);
expect(exported.title).toBeUndefined();
expect(exported.description).toBeUndefined();
});
});
});

Expand Down

0 comments on commit e48e550

Please sign in to comment.