FHIR / sushi

SUSHI (aka "SUSHI Unshortens Short Hand Inputs") is a reference implementation command-line interpreter/compiler for FHIR Shorthand (FSH).
Apache License 2.0
145 stars 44 forks source link

SUSHI errors when an instance adds an extension on meta.profile without explicitly setting the profile #1330

Closed cmoesel closed 1 year ago

cmoesel commented 1 year ago

Given FSH like the following:

Instance: PatientExample
InstanceOf: MyPatient
Description: "An example of a patient with a license to krill."
* meta.profile.extension[MyExtension].valueString = "Howdy"
* name
  * given[0] = "James"
  * family = "Pond"

SUSHI will emit the following error: Cannot read properties of undefined (reading 'startsWith')

This is because the InstanceExporter is trying to check if the meta.profile value starts with a particular string -- but in this case, although meta.profile is not null, it does not yet have an assigned value. In fact, the code where this is happening is the code that is intended to set the meta.profile value based on the InstanceOf. Oops.

cmoesel commented 1 year ago

The following simple project demonstrates the issue: StartsWithError.zip

cmoesel commented 1 year ago

Note that if you run the test project using PR #1331 and the -l debug flag, you'll get the exact location of where the error is being thrown. But (spoiler alert), it's here: https://github.com/FHIR/sushi/blob/45c944ac0c91bdab8c7d2eaec20559590dcd27f0/src/export/InstanceExporter.ts#L789