cqframework / cqf-ruler

FHIR Clinical Reasoning Module Server
Apache License 2.0
64 stars 49 forks source link

PlanDefinition can be applied by $apply operation but there is an error when uses it as cds-services #45

Closed binhphi109 closed 2 years ago

binhphi109 commented 6 years ago

Case 1: I were using plandefinition-apply.json to test $apply operation. It works as expected. However, I made some changes to the apply-example PlanDefinition as below:

"library": [
  {
    "reference": "Library/plandefinitionApplyTest"
  }
],
"action": [
  {
    "triggerDefinition": {
      "type": "named-event",
      "eventName": "medication-prescribe"
    }, // <-- **NEW CHANGE HERE**
    "condition": [
      {
        "kind": "applicability",
        "description": "Simple test",
        "language": "text/cql",
        "expression": "plandefinitionApplyTest.Results"
      }
    ],
    "dynamicValue": [
      {
        "description": "Set CarePlan detail definition",
        "path": "title",
        "expression": "plandefinitionApplyTest.\"Dynamic Detail Definition\""
      }
    ]
  }
]

After that, I created a request, sent it to http://localhost:8080/cqf-ruler/cds-services/apply-example service, and then the service encountered an error: "Could not resolve expression reference 'plandefinitionApplyTest.Results' in library 'plandefinitionApplyTest'."

java.lang.IllegalArgumentException: Could not resolve expression reference 'plandefinitionApplyTest.Results' in library 'plandefinitionApplyTest'.
    at org.opencds.cqf.cql.execution.Context.resolveExpressionRef(Context.java:227)
    at org.opencds.cqf.providers.FHIRPlanDefinitionResourceProvider.resolveActions(FHIRPlanDefinitionResourceProvider.java:278)
    at org.opencds.cqf.providers.FHIRPlanDefinitionResourceProvider.resolveCdsHooksPlanDefinition(FHIRPlanDefinitionResourceProvider.java:257)
    at org.opencds.cqf.cdshooks.request.CdsRequest.process(CdsRequest.java:86)
    at org.opencds.cqf.servlet.CdsServicesServlet.doPost(CdsServicesServlet.java:40)
    at ca.uhn.fhir.rest.server.RestfulServer.service(RestfulServer.java:1460)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:860)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
    at org.ebaysf.web.cors.CORSFilter.handleNonCORS(CORSFilter.java:437)
    at org.ebaysf.web.cors.CORSFilter.doFilter(CORSFilter.java:172)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1629)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.Server.handle(Server.java:530)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:256)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
    at java.lang.Thread.run(Thread.java:748)

Case 2: I tried to send different request to http://localhost:8080/cqf-ruler/cds-services/cdc-opioid-guidance-05. The service works as expected. Nevertheless, cdc-opioid-guidance-05 PlanDefinition cannot be applied using $apply operation.

ca.uhn.fhir.rest.server.exceptions.InternalErrorException: Failed to call access method
    at ca.uhn.fhir.rest.server.method.BaseMethodBinding.invokeServerMethod(BaseMethodBinding.java:261)
    at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:254)
    at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.doInvokeServer(BaseResourceReturningMethodBinding.java:237)
    at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.invokeServer(BaseResourceReturningMethodBinding.java:371)
    at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:229)
    at ca.uhn.fhir.rest.server.RestfulServer.handleRequest(RestfulServer.java:877)
    at ca.uhn.fhir.rest.server.RestfulServer.doPost(RestfulServer.java:1488)
    at ca.uhn.fhir.rest.server.RestfulServer.service(RestfulServer.java:1460)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:860)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
    at org.ebaysf.web.cors.CORSFilter.handleNonCORS(CORSFilter.java:437)
    at org.ebaysf.web.cors.CORSFilter.doFilter(CORSFilter.java:172)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1629)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.Server.handle(Server.java:530)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:256)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at ca.uhn.fhir.rest.server.method.BaseMethodBinding.invokeServerMethod(BaseMethodBinding.java:256)
    ... 45 common frames omitted
Caused by: java.lang.IllegalArgumentException: [LocalLibrary[1:262, 1:268]Could not resolve identifier Results in the current library.]
    at org.opencds.cqf.helpers.LibraryHelper.getTranslator(LibraryHelper.java:64)
    at org.opencds.cqf.helpers.LibraryHelper.translateLibrary(LibraryHelper.java:75)
    at org.opencds.cqf.helpers.LibraryHelper.translateLibrary(LibraryHelper.java:71)
    at org.opencds.cqf.providers.CqlExecutionProvider.evaluateInContext(CqlExecutionProvider.java:173)
    at org.opencds.cqf.providers.FHIRPlanDefinitionResourceProvider.meetsConditions(FHIRPlanDefinitionResourceProvider.java:212)
    at org.opencds.cqf.providers.FHIRPlanDefinitionResourceProvider.resolveActions(FHIRPlanDefinitionResourceProvider.java:96)
    at org.opencds.cqf.providers.FHIRPlanDefinitionResourceProvider.applyPlanDefinition(FHIRPlanDefinitionResourceProvider.java:90)

Root cause: From my investigation, when $apply in the case 1, the system can resolve the condition's expression as Results defined in PlanDefinition. However, when processing the cds-services' request, the system resolves the condition's expression as plandefinitionApplyTest.Results, not Results anymore.

c-schuler commented 6 years ago

Yes, this is definitely an inconsistency that needs to be addressed. The $apply operation and the CDS Hooks functionality resolve the PlanDefinition condition expressions in different ways and should be consistent.

JPercival commented 2 years ago

Duplicated by #539