Stream: cql
Topic: cqf-ruler ActivityDefinition $apply help
ravi.kuchi (Jun 09 2021 at 01:10):
Hi @JP , I am trying out the cqf-ruler-r4 by posting the ActivityDefinition defined at http://hl7.org/fhir/R4/activitydefinition-medicationorder-example.json.html and then executing $apply on this with a Test Patient
I am getting below error:
{
"severity": "error",
"code": "processing",
"diagnostics": "Failed to call access method: org.opencds.cqf.cql.engine.fhir.exception.DataProviderException: Unable to resolve path dispenseRequest.numberOfRepeatsAllowed."
}
Am I missing something here, I could not find any sort of examples to understand the cql that can be executed by this tool on the link https://github.com/DBCG/cqf-ruler and also at the link https://github.com/DBCG/cqf-ruler/wiki
JP (Jun 09 2021 at 15:05):
Hi Ravi!
I'll take a look at the ruler and that example today and see if I can figure out what's going on with that example.
The ruler supports direct CQL execution via the $cql operation. There aren't any examples of that posted in the wiki anywhere but here's a link to the operation definition in the code. I'll add a backlog item for adding documentation for that.
ravi.kuchi (Jun 09 2021 at 18:12):
Thanks @JP , for quick reply!
Can I get some quick samples of how to use $cql and $evaluate , below is a screenshot of what I was trying to get started on using these endpoints
Screen-Shot-2021-06-09-at-2.06.42-PM.png
ravi.kuchi (Jun 09 2021 at 18:54):
@JP , I am able to figure out the $evaluate part , it is really exciting !!! Thanks to this wonderful project
Screen-Shot-2021-06-09-at-2.52.53-PM.png
ravi.kuchi (Jun 09 2021 at 18:57):
My end goal however is to write all my logic into Library and then use the evaluated library contents in the Activity and PlanDefinition Objects for creating Orders and CarePlans. Do you think my understanding is correct?
JP (Jun 09 2021 at 19:04):
Glad you got it figured out! Yes, you can include logic in a CQL library and then reference that logic in PlanDefinitions and so on. That can be in turn used to create CarePlans, cds-hooks services, etc.
ravi.kuchi (Jun 09 2021 at 23:04):
Hi @JP , one quick help, I am executing the $apply on the bundle provided in the page
https://github.com/DBCG/cql-evaluator/blob/master/evaluator.activitydefinition/src/test/resources/org/opencds/cqf/cql/evaluator/activitydefinition/r4/bundle-activityDefinitionTest.json
As per my understanding the doNotPerform should be set as per the ActivityDefinition, but I do not see that in the response, it seems that the dynamicValue is not working, can you please let me know if I am overlooking something:
{
"resourceType": "MedicationRequest",
"intent": "order",
"medicationCodeableConcept": {
"coding": [
{
"system": "http://test/fhir/System",
"code": "productCode"
}
]
},
"subject": {
"reference": "patient-1"
}
}
ravi.kuchi (Jun 10 2021 at 00:03):
I think I made it work, changed the expression with escape characters and library prefix ->
"expression": "\"TestActivityDefinition\".ActiveProcedureStatus"
I am going to try more complex examples, will let u know my progress
ravi.kuchi (Jun 10 2021 at 14:23):
hi @JP, @Bryn Rhodes , As in another thread I stumbled upon the limitation that the dynamicValue seems to only work with Boolean dataType, I did try few things to make it work for code or quantity but am unsuccessful, if you could give me pointers as to the classes in which the changes would be it would be helpful.
JP (Jun 10 2021 at 16:35):
Hi ravi!
I believe the work to update that is already done - https://github.com/DBCG/cqf-ruler/pull/277/files
Just waiting on a review.
JP (Jun 10 2021 at 16:37):
I went ahead and reviewed and merged it, actually.
ravi.kuchi (Jun 14 2021 at 19:00):
Thanks @JP for quick reply, I am trying a simple assignment as below which does not seem to work, the resource is 'CommunicationRequest':
{
"path": "priority",
"expression": {
"language": "text/cql",
"expression": "routine"
}
}
ravi.kuchi (Jun 14 2021 at 19:01):
I am getting below message in logs: 2021-06-14 14:59:04.757 [qtp106424296-40] WARN o.o.c.r.p.PlanDefinitionApplyProvider [ActivityDefinitionApplyProvider.java:171] WARNING: ActivityDefinition has null value for path: priority
JP (Jun 14 2021 at 21:03):
Hmm... Could you post your complete example? I need a bit more context to figure out what's going on?
ravi.kuchi (Jun 14 2021 at 22:06):
Sure @JP , Here is my activity Definition:
{
"resourceType": "ActivityDefinition",
"id": "FMCNAactivityDefinition-test",
"name": "FMCNAactivityDefinition-test",
"title": "CreateProcedure",
"status": "draft",
"description": "Create the procedure.",
"library": [ "http://test/fhir/Library/FMCNAActivityDefinition|1.0.0" ],
"kind": "CommunicationRequest",
"productCodeableConcept": {
"coding": [{
"system": "http://test/fhir/System",
"code": "fmcnaCode"
}]
},
"dynamicValue": [
{
"path": "subject",
"expression": {
"language": "text/cql",
"expression": "\"FMCNAActivityDefinition\".Patient"
}
},
{
"path": "status",
"expression": {
"language": "text/cql",
"expression": "draft"
}
},
{
"path": "doNotPerform",
"expression": {
"language": "text/cql",
"expression": "\"FMCNAActivityDefinition\".isAdult"
}
},
{
"path": "priority",
"expression": {
"language": "text/cql",
"expression": "routine"
}
}
]
}
ravi.kuchi (Jun 14 2021 at 22:07):
Here is the Library I have defined:
library FMCNAActivityDefinition version '1.0.0'
using FHIR version '4.0.1'
include "FHIRHelpers" version '4.0.1' called FHIRHelpers
codesystem "LOINC": 'http://loinc.org'
code "serum creatinine":
'2160-0' from "LOINC"
code "creatinine clearance":
'12195-4' from "LOINC"
context Patient
define "isAdult":
AgeInYears() >= 18
define "isChild":
AgeInYears() < 18
//define "Get Observation from Code Declaration":
// [Observation: "serum creatinine"]
define "LatestSerum":
First([Observation: code = "serum creatinine"] S
where S.effective > Now() - 7 days
sort by (effective as dateTime) desc)
define "LatestSerum value": "LatestSerum".value.value
define "reference range high": "LatestSerum".referenceRange.high.value[0]
//RIFLE Classification
define "Adult RIFLE Class":
case
when "isChild" then 'Not Applicable'
when "LatestSerum value" > 3 * "reference range high" and "isAdult" then 'Failure'
when "LatestSerum value" > 2 * "reference range high" and "isAdult" then 'Injury'
when "LatestSerum value" > 1.5 * "reference range high" and "isAdult" then 'Risk'
else 'Not at Risk'
end
//AKIN Classification
define "Adult AKIN Class":
case
when "isChild" then 'Not Applicable'
when "LatestSerum value" > 3 * "reference range high" and "isAdult" then '3'
when "LatestSerum value" > 2 * "reference range high" and "isAdult" then '2'
when "LatestSerum value" > 1.5 * "reference range high" and "isAdult" then '1'
else 'Not at Risk'
end
define "LatesteCCR":
First([Observation: code = "creatinine clearance"] S
where S.effective > Now() - 7 days
sort by (effective as dateTime) desc)
define "LatestClearance value": "LatesteCCR".value.value
define "reference range low": "LatesteCCR".referenceRange.low.value[0]
//RIFLE Classification
define "Child RIFLE Class":
case
when "isAdult" then 'Not Applicable'
when "LatestClearance value" < 0.25 * "reference range low" and "isChild" then 'Failure'
when "LatestClearance value" < 0.50 * "reference range low" and "isChild" then 'Injury'
when "LatestClearance value" < 0.75 * "reference range low" and "isChild" then 'Risk'
else 'Not at Risk'
end
ravi.kuchi (Jun 14 2021 at 22:09):
@JP, let me know if you need anything else, my goal is to create a CommunicationRequest resource upon the $apply and populate some data of CommunicationRequest from the Library and some data will be static like the 'Status' and 'Priority' which are pre-defined to 'draft' and 'routine'.
ravi.kuchi (Jun 14 2021 at 22:12):
The current output I am getting is :
{
"resourceType": "CommunicationRequest",
"status": "unknown",
"doNotPerform": false,
"subject": {
"reference": "PedPatient"
}
}
My expectation is that the status should be set as 'draft' and the priority is missing
ravi.kuchi (Jun 15 2021 at 02:06):
@Bryn Rhodes One of My challenge is how do I define a static variable so I can assign the priority from enum in CQL
define "MyPriority": CommunicationRequest.CommunicationPriority('routine') -> this is not working , referred CQL guide but unable to find some guidance
Tried below as well:
define "MyPriority": 'Enumeration[routine]'
Bryn Rhodes (Jun 15 2021 at 02:41):
CommunicationRequest.priority is a FHIR.code
, which is an Element
, and has id
, extension
, and value
children. FHIRHelpers is providing implicit conversions so that when you compare to a string, you don't notice that it's a FHIR.code:
[CommunicationRequest] R where R.priority = 'routine'
But if you're constructing a CommunicationRequest, you need to provide that FHIR.code value:
CommunicationRequest {
id: id { value: '123' },
priority: code { value: 'routine' }
}
ravi.kuchi (Jun 15 2021 at 12:32):
Thanks @Bryn Rhodes , part of my problem is I think with the way cqf-ruler works:
I have my Library defined as below:
context Patient
define "Latest":
First([MedicationRequest: code = "Colistin"] S
where S.authoredOn < Now() - 7 days
)
define "LatestPriority": "Latest".priority
define "MyIntent": code { value: 'routine' }
The below works with ActivityDefinition
{
"path": "priority",
"expression": {
"language": "text/cql",
"expression": "\"FMCNAMedDefinition\".LatestPriority"
}
}
ravi.kuchi (Jun 15 2021 at 12:33):
The below does not work in cqf-ruler:
{
"path": "priority",
"expression": {
"language": "text/cql",
"expression": "\"FMCNAMedDefinition\".MyIntent"
}
}
ravi.kuchi (Jun 15 2021 at 16:41):
Also, @Bryn Rhodes I am getting below error with your definition:
define "comm": CommunicationRequest {
id: id { value: '123' },
priority: code { value: 'routine' }
}
Error [31:15] Expected an expression of type 'FHIR.CommunicationPriority', but found an expression of type 'code'.
Bryn Rhodes (Jun 16 2021 at 21:01):
Sorry, yes, needs to use the CommunicationPriority enumerated type:
define "Test1":
CommunicationRequest {
id: id { value: '123' },
priority: CommunicationPriority { value: 'routine' }
}
Bryn Rhodes (Jun 16 2021 at 21:01):
Regarding it not working in the ruler, what error are you getting?
ravi.kuchi (Jun 17 2021 at 18:15):
@Bryn Rhodes The above is working well, Thanks! Can you also help me set some content in the Payload, I tried few things but not getting it right
define "comm": CommunicationRequest {
id: id { value: '123' },
priority: CommunicationPriority { value: 'routine' },
payload : Payload [{content : content as string{value: 'some sample text'} ]
}
Bryn Rhodes (Jun 17 2021 at 18:39):
For backbone elements, the model uses generated structure types, just like the Java and C# reference implementations do, so in this case it would be:
define "comm": CommunicationRequest {
id: id { value: '123' },
priority: CommunicationPriority { value: 'routine' },
payload : {
FHIR.CommunicationRequest.Payload {
content : string { value: 'some sample text' }
}
}
}
Bryn Rhodes (Jun 17 2021 at 18:40):
Note that payload is multi-cardinality, so it takes a List, which uses curly-braces in CQL.
ravi.kuchi (Jun 17 2021 at 19:34):
@Bryn Rhodes , getting below error
Could not resolve type CommunicationRequest.Payload. Primary package for this resolver is org.hl7.fhir.r4.model
Do I need to include any packages?
I have the below as of now :
using FHIR version '4.0.1'
include "FHIRHelpers" version '4.0.1' called FHIRHelpers
Bryn Rhodes (Jun 17 2021 at 21:19):
Hmmm, that seems like a bug in the engine's type resolver, the translator is fine with it. Would you mind submitting a github issue on the engine for that? (https://github.com/dbcg/cql_engine/issues)
ravi.kuchi (Jun 17 2021 at 22:52):
Sure, submitted an issue https://github.com/DBCG/cql_engine/issues/488, thanks for the help!
Last updated: Apr 12 2022 at 19:14 UTC