Skip to content

Commit

Permalink
Handle missing snapshot better when checking isModifierExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
jafeltra committed Dec 2, 2024
1 parent 2b35b9b commit e64c461
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ export function isExtension(path: string): boolean {

export function isModifierExtension(extension: any): boolean {
return (
extension?.snapshot.element.find((el: ElementDefinition) => el.id === 'Extension')
extension?.snapshot?.element.find((el: ElementDefinition) => el.id === 'Extension')
?.isModifier === true
);
}
Expand Down
25 changes: 25 additions & 0 deletions test/export/StructureDefinitionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7976,6 +7976,31 @@ describe('StructureDefinitionExporter R4', () => {
/Cannot slice element 'status'.*File: SingleElement\.fsh.*Line: 6\D*/s
);
});

it('should not report an error for an extension Contains rule with an extension that is missing a snapshot when checking if its a modifierExtension', () => {
// Create an extension without a snapshot for testing
// Note: SUSHI wouldn't create an extension like this, but it might be provided by a package or custom resource
const noSnapshotExtension = cloneDeep(defs.fishForFHIR('familymemberhistory-type'));
noSnapshotExtension.id = 'familymemberhistory-type-no-snapshot';
noSnapshotExtension.url =
'http://hl7.org/fhir/StructureDefinition/familymemberhistory-type-no-snapshot';
delete noSnapshotExtension.snapshot;
defs.add(noSnapshotExtension);

const profile = new Profile('Foo');
profile.parent = 'Observation';
const containsRule = new ContainsRule('extension')
.withFile('BadExt.fsh')
.withLocation([6, 3, 6, 12]);
containsRule.items = [{ name: 'nosnapshot', type: 'familymemberhistory-type-no-snapshot' }];
profile.rules.push(containsRule);

exporter.exportStructDef(profile);
const sd = pkg.profiles[0];
const noSnapshotSlice = sd.elements.find(e => e.id === 'Observation.extension:nosnapshot');
expect(noSnapshotSlice).toBeDefined();
expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
});
});

describe('#CaretValueRule', () => {
Expand Down

0 comments on commit e64c461

Please sign in to comment.