oehf / ipf

Open eHealth Integration Platform
http://oehf.github.io/ipf-docs
Apache License 2.0
170 stars 62 forks source link

GenericPatientIdExtractor: solve without using FhirPath #455

Open ohr opened 1 month ago

ohr commented 1 month ago

GenericPatientIdExtractor uses FhirPatient to extract the Patient reference of a resource. This unfortunately leads to calling parts of HAPI FHIR that may require to include structure libraries (stu3, r4b etc.) that are not used at all. Still it can cause exceptions like:

Caused by: java.lang.ClassNotFoundException: org.hl7.fhir.r4b.model.Resource
    at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
    at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?]
    at java.lang.Class.forName0(Native Method) ~[?:?]
    at java.lang.Class.forName(Class.java:375) ~[?:?]
    at ca.uhn.fhir.util.ReflectionUtil.typeExists(ReflectionUtil.java:287) ~[hapi-fhir-base-6.10.2.jar:?]
    at ca.uhn.fhir.context.FhirContext.getValidationSupport(FhirContext.java:716) ~[hapi-fhir-base-6.10.2.jar:?]
    at org.hl7.fhir.r4.hapi.fluentpath.FhirPathR4.<init>(FhirPathR4.java:30) ~[hapi-fhir-structures-r4-6.10.2.jar:?]
    at org.hl7.fhir.r4.hapi.ctx.FhirR4.createFhirPathExecutor(FhirR4.java:45) ~[hapi-fhir-structures-r4-6.10.2.jar:?]
    at ca.uhn.fhir.context.FhirContext.newFhirPath(FhirContext.java:859) ~[hapi-fhir-base-6.10.2.jar:?]
    at org.openehealth.ipf.commons.ihe.fhir.audit.GenericPatientIdExtractor.lambda$patientReferenceFromResource$2(GenericPatientIdExtractor.java:59) ~[ipf-commons-ihe-fhir-core-4.8.0.jar:4.8.0]
Thopap commented 2 weeks ago

Intesting how this stacktrace could occure? https://github.com/hapifhir/hapi-fhir/blob/882e7a33ef27996f33bd719130464b0b6e99ec9c/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ReflectionUtil.java#L287 seems to catch the ClassNotFoundException.