Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow library alpha02 crashes when PlanDefinition has an .action.condition? #1733

Closed
williamito opened this issue Nov 24, 2022 · 10 comments
Closed
Assignees
Labels
P1 High priority issue type:bug Something isn't working

Comments

@williamito
Copy link
Contributor

Describe the bug
I am able to generate a care plan using a minimal Plan Definition. When I add a condition to the plan definition, the app crashes instead with

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.hl7.fhir.r4.model.Base.isResource()' on a null object reference
at org.hl7.fhir.r4.utils.FHIRPathEngine.evaluate(FHIRPathEngine.java:525)
at org.hl7.fhir.r4.hapi.fluentpath.FhirPathR4.evaluate(FhirPathR4.java:31)
at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.evaluateConditionOrDynamicValue(PlanDefinitionProcessor.java:568)
at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.meetsConditions(PlanDefinitionProcessor.java:458)
at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.resolveAction(PlanDefinitionProcessor.java:174)
at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.resolveActions(PlanDefinitionProcessor.java:161)
at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.apply(PlanDefinitionProcessor.java:136)
at com.google.android.fhir.workflow.FhirOperator.generateCarePlan(FhirOperator.kt:241)
at com.example.enginetest.MainActivity$onCreate$1.invokeSuspend(MainActivity.kt:117)

Component
Workflow Library

To Reproduce
See https://github.com/williamito/fhir-engine-test/blob/main/app/src/main/java/com/example/enginetest/MainActivity.kt

It works with

{
  "resourceType": "PlanDefinition",
  "id": "Test-PlanDefinition",
  "status": "active",
  "action": [
    {
      "definitionCanonical": "http://example.org/ActivityDefinition/ADTest"
    }
 ]
}

And crashes with

{
  "resourceType": "PlanDefinition",
  "id": "Test-PlanDefinitionCondition",
  "status": "active",
  "action": [
    {
      "condition": [
        {
          "kind": "applicability",
          "expression": {
            "language": "text/fhirpath",
            "expression": "true"
          }
        }
      ],
      "definitionCanonical": "http://example.org/ActivityDefinition/ADTest"
    }
 ]
}

I also tried variations of "language": "text/cql" and got a similar crash from the CQL libraries complaining about a missing resource.

Expected behavior
Trivial condition evaluates to true and care plan is generated.

@williamito
Copy link
Contributor Author

In case it helps, the actual intent of the condition expression was to check Patient.gender = 'female' which has the same crash. I ended up trying true to make sure I wasn't messing up the use of fhirpath.

@jingtang10 jingtang10 added type:bug Something isn't working P1 High priority issue labels Nov 28, 2022
@jingtang10
Copy link
Collaborator

jingtang10 commented Nov 28, 2022

Bryn's suggestion: try use text/cql-expression as the language of the expression in the condition.

can you plz try william?

@williamito
Copy link
Contributor Author

This is the result of using "language": "text/cql-expression" -

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.enginetest, PID: 3496
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.hl7.fhir.r4.model.Parameters$ParametersParameterComponent.hasValue()' on a null object reference
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.getParameterComponentByName(PlanDefinitionProcessor.java:540)
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.evaluateConditionOrDynamicValue(PlanDefinitionProcessor.java:585)
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.meetsConditions(PlanDefinitionProcessor.java:458)
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.resolveAction(PlanDefinitionProcessor.java:174)
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.resolveActions(PlanDefinitionProcessor.java:161)
        at org.opencds.cqf.cql.evaluator.plandefinition.r4.PlanDefinitionProcessor.apply(PlanDefinitionProcessor.java:136)
        at com.google.android.fhir.workflow.FhirOperator.generateCarePlan(FhirOperator.kt:241)
        at com.example.enginetest.MainActivity$onCreate$1.invokeSuspend(MainActivity.kt:118)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@263a27d, Dispatchers.Main.immediate]

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Nov 29, 2022

This is a bug in FhirPath evaluations with a null base in the FHIR Core: PR: hapifhir/org.hl7.fhir.core#1015

We will need to wait for the solution to trickle down into HAPI, then the cql-evaluator, then workflow.

@williamito
Copy link
Contributor Author

It looks like Vitor's fix was reverted: hapifhir/org.hl7.fhir.core#1017

I'm not sure why, I don't see any discussion on github other than it was reverted by request of Grahame Grieve.

This bug does significantly hamper care plan generation, as encoding the conditional logic in FHIR is a primary value. I'm not sure what the timeline is for the fix to trickle down to the workflow library, is there a workaround besides implementing it in application logic?

@vitorpamplona
Copy link
Collaborator

They are debating if that is the way it should be or not.

The bug should only happen in FhirPath expressions. CQL expressions should work.

@williamito
Copy link
Contributor Author

It seems to also happen with CQL expressions though: please see crash in #1733 (comment)

@vitorpamplona
Copy link
Collaborator

Different error, though. I didn't get there yet.

@vitorpamplona
Copy link
Collaborator

The CQL/expression error is fixed on the CQL Evaluator 2.3. I am making a PR to upgrade the workflow

vitorpamplona added a commit to Path-Check/android-fhir that referenced this issue Nov 29, 2022
@williamito
Copy link
Contributor Author

From Vitor re: CQL

There is a bug in the version of the Jackson processor that HAPI is using hapifhir/hapi-fhir#4308

That bug only happens when using graddle. The evaluator was migrated to the new buggy version and now we need to wait for hapi to upgrade first, update the evaluator and only then update the workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority issue type:bug Something isn't working
Projects
Status: Complete
Development

No branches or pull requests

3 participants