Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1128 - add snapshot option to FshToFhir #1465

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
cmoesel marked this conversation as resolved.
Show resolved Hide resolved
};

// 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();
});
});
});
Loading