standardhealth / shr-es6-export

ES6 library for exporting SHR models to ES6 classes
Apache License 2.0
3 stars 0 forks source link

Prevent crashes on extensions that don't have target profiles #44

Closed dehall closed 5 years ago

dehall commented 5 years ago

Something changed upstream recently and the es6 exporter is now being passed slightly different element definitions for the slice root and fields on Extension.extension. This is causing the exporter to crash as it expects every element definition under an Extension to have a target profile, but the slice root isn't going to have a target profile. (see master where the tests are currently failing despite no changes to the test fixture spec here) This change just checks for whether the field structure is present before trying to read it, so it doesn't crash if the expected field isn't there.

I do think more testing would be good to ensure that extensions are truly handled correctly in all cases, but at minimum this will ensure the generator continues to function as it did previously, and more importantly doesn't crash. The test on PatientEntry.fromFHIR includes a complex extension which is still handled correctly.

Note: this also disables the BloodPressureSliceByNumber test which is suddenly failing. Based on some limited investigation the issue also seems to be upstream since the profile the generator receives here doesn't contain fixed values for the field named as the discriminator.

cmoesel commented 5 years ago

Code looks good, tests pass, and it doesn't crash running against the SHR spec. There are tons of errors, but I think that's expected (and the purpose of this PR is to prevent the crash).

I'll bump the version number, push to the branch, and then merge. Thanks, @dehall!