hapifhir / org.hl7.fhir.core

Apache License 2.0
156 stars 161 forks source link

DocumentReference 30_40 converter produces NPE on valid DocumentReference.status element #1799

Open tadgh opened 1 week ago

tadgh commented 1 week ago
  1. Create a document reference in R4.
  2. Set theDocumentReference.docStatus = null
  3. Set theDocumentReference.getDocStatusElement().addExtension(someExtension)
  4. Call VersionConvertorFactory_30_40.convertResource(theDocumentReference);
  5. Notice the NPE:

    java.lang.NullPointerException: Cannot invoke "org.hl7.fhir.r4.model.DocumentReference$ReferredDocumentStatus.ordinal()" because the return value of "org.hl7.fhir.r4.model.Enumeration.getValue()" is null
    
    at org.hl7.fhir.convertors.conv30_40.resources30_40.DocumentReference30_40.convertReferredDocumentStatus(DocumentReference30_40.java:275)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.DocumentReference30_40.convertDocumentReference(DocumentReference30_40.java:33)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Resource30_40.convertResource(Resource30_40.java:276)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Resource30_40.convertResource(Resource30_40.java:213)
    at org.hl7.fhir.convertors.conv30_40.VersionConvertor_30_40.convertResource(VersionConvertor_30_40.java:111)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Bundle30_40.convertBundleEntryComponent(Bundle30_40.java:63)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Bundle30_40.convertBundle(Bundle30_40.java:48)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Resource30_40.convertResource(Resource30_40.java:242)
    at org.hl7.fhir.convertors.conv30_40.resources30_40.Resource30_40.convertResource(Resource30_40.java:213)
    at org.hl7.fhir.convertors.conv30_40.VersionConvertor_30_40.convertResource(VersionConvertor_30_40.java:111)
    at org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40.convertResource(VersionConvertorFactory_30_40.java:25)
    at org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40.convertResource(VersionConvertorFactory_30_40.java:20)

Note that this example uses doc status, but I imagine this may exist for any enum'ed field? Worth looking into.

dmuylwyk commented 1 week ago

Note that this example uses doc status, but I imagine this may exist for any enum'ed field? Worth looking into.

This may be limited to DocumentReference.status but I suspect it isn't.

The general case appears to be converting an unpopulated element of type code—which is generally backed by an enum—that includes one or more extensions. The most common extension would likely be a data-absent-reason extension but it's perfectly valid to add any extension to an unpopulated element in this manner.

grahamegrieve commented 1 week ago

@dotasek I think we've discussed this before - it does need a sweeping fix for this, to check if the enum .getValue() is null before doing the switch. Is my memory correct?

dotasek commented 2 days ago

@grahamegrieve I think what was done before was this: https://github.com/hapifhir/org.hl7.fhir.core/pull/1697/files, which is also involved null handling, but not what this fix is asking for.

I'll look into it.