Skip to content

Commit

Permalink
Issue #1128 - add snapshot option to FshToFhir (#1465)
Browse files Browse the repository at this point in the history
* Issue #1128 - Enable sushiClient (FshToFhir) to create StructureDefinitions with the snapshot data element

* Issue #1128 - add comment about use of snapshot option

* Issue #1128 - update tests
  • Loading branch information
joepaquette authored Jun 4, 2024
1 parent 70865fd commit 54bdd4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/run/FshToFhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export async function fshToFhir(
logger.level = options.logLevel;
}

const snapshot = options.snapshot ?? false;

// set up a config so that sushi can run
const config = {
canonical: options.canonical ?? 'http://example.org',
Expand Down Expand Up @@ -87,7 +89,7 @@ export async function fshToFhir(
] as const
).forEach(artifactType => {
outPackage[artifactType].forEach((artifact: { toJSON: (snapshot: boolean) => any }) => {
fhir.push(artifact.toJSON(false));
fhir.push(artifact.toJSON(snapshot));
});
});

Expand All @@ -98,12 +100,18 @@ export async function fshToFhir(
};
}

// *** WARNING ***
// The 'snapshot' option, when set to true, triggers the generation of StructureDefinition.snapshot data elements.
// Use of this option should be considered EXPERIMENTAL! The StructureDefinition.snapshot data elements generated
// by SUSHI are likely not perfect and differ from the snapshots that the IG Publisher and/or Simplifier would create.
// If you plan to publish these resources, it would be better to use one of those other tools to generate the snapshots.
type fshToFhirOptions = {
canonical?: string;
version?: string;
fhirVersion?: string;
dependencies?: ImplementationGuideDependsOn[];
logLevel?: Level;
snapshot?: boolean;
};

// Winston levels: https://github.com/winstonjs/winston#logging-levels plus a silent option
Expand Down
43 changes: 43 additions & 0 deletions test/run/FshToFhir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe('#FshToFhir', () => {
expect(results.fhir[0].id).toBe('MyPatient');
const name = results.fhir[0].differential.element.find((e: any) => e.id == 'Patient.name');
expect(name.mustSupport).toBe(true);
expect(results.fhir[0].snapshot).toBeUndefined();
});

it('should convert valid FSH into FHIR with several inputs', async () => {
Expand All @@ -184,11 +185,13 @@ describe('#FshToFhir', () => {
expect(results.fhir[0].id).toBe('MyPatient1');
const name = results.fhir[0].differential.element.find((e: any) => e.id == 'Patient.name');
expect(name.mustSupport).toBe(true);
expect(results.fhir[0].snapshot).toBeUndefined();
expect(results.fhir[1].id).toBe('MyPatient2');
const gender = results.fhir[1].differential.element.find(
(e: any) => e.id == 'Patient.gender'
);
expect(gender.mustSupport).toBe(true);
expect(results.fhir[1].snapshot).toBeUndefined();
});

it('should trace errors back to the originating input when multiple inputs are given', async () => {
Expand All @@ -213,5 +216,45 @@ describe('#FshToFhir', () => {
expect(results.fhir).toHaveLength(0);
expect(results.fhir).toEqual([]);
});

it('should honor snapshot option = true when converting valid FSH into FHIR', async () => {
const results = await fshToFhir(
leftAlign(`
Profile: MyPatient
Parent: Patient
* name MS
`),
{
snapshot: true
}
);
expect(results.errors).toHaveLength(0);
expect(results.warnings).toHaveLength(0);

expect(results.fhir).toHaveLength(1);
expect(results.fhir[0].id).toBe('MyPatient');
expect(results.fhir[0].snapshot).toBeDefined();
const nameSnap = results.fhir[0].snapshot.element.find((e: any) => e.id == 'Patient.name');
expect(nameSnap.mustSupport).toBe(true);
});

it('should honor snapshot option = false when converting valid FSH into FHIR', async () => {
const results = await fshToFhir(
leftAlign(`
Profile: MyPatient
Parent: Patient
* name MS
`),
{
snapshot: false
}
);
expect(results.errors).toHaveLength(0);
expect(results.warnings).toHaveLength(0);

expect(results.fhir).toHaveLength(1);
expect(results.fhir[0].id).toBe('MyPatient');
expect(results.fhir[0].snapshot).toBeUndefined();
});
});
});

0 comments on commit 54bdd4e

Please sign in to comment.