FHIR Chat · CDS Authoring Tool Logic Capabilities · cql

Stream: cql

Topic: CDS Authoring Tool Logic Capabilities


view this post on Zulip Chris Moesel (Jun 24 2020 at 16:29):

For those of you who use or have used the CDS Authoring Tool, what additional CQL logic features would you like to see supported?

For example, something as simple as support for First and Last expressions on lists... or better support for timing relationships... or a more complex query builder... etc.

view this post on Zulip Tien Thai (Aug 17 2020 at 16:34):

I am working on a CDS artifact and came across a requirement where if the patient does not meet the inclusion criteria, then check if the patient is willing to take a specific medication and if the answer is YES, then provide a recommendation. When looking at what being provided in the CDS Authoring Tool, I cannot really find a suited element for this check. Can you please let me know which element is going to be used for this criteria.
Your help is appreciated.

Best,
Tien Thai

view this post on Zulip Bryn Rhodes (Aug 18 2020 at 22:16):

Hi Tien, typically this sort of interaction is handled with a Questionnaire to describe the question, a QuestionnaireResponse for the response from the patient with the answer, and an Observation generated from that QuestionnaireResponse. The CDS Logic can then be written to look for the Observation, recognizing that using a Questionnaire/QuestionnaireResponse is just one way that that Observation might be gathered.

view this post on Zulip Tien Thai (Aug 20 2020 at 15:40):

Hi Bryn,
Thank you very much for your quick response.

TT

view this post on Zulip Chris Moesel (Aug 20 2020 at 17:52):

To further clarify on Bryn's response, it's not possible to create a workflow to present a questionnaire in the CDS Authoring Tool. You'll need additional tools (and/or manual authoring) to represent something like that. That said, as Bryn suggested, youcan use the CDS Authoring Tool to add inclusion logic that checks for the Observation indicating the patient consented to the medication.

view this post on Zulip Tien Thai (Aug 20 2020 at 18:07):

Hi Chris,
Thank you very much for your comment.
Are you saying that after downloading the exported zip file, I can unzip and edit the CQL file? Can you please elaborate a little bit more about "manual authoring"? Many thanks for your help.

TT

view this post on Zulip Chris Moesel (Aug 20 2020 at 18:26):

If you want a standards based way to indicate that a Questionnaire should be provided, I think you need more than just CQL (which represents only logic). You'll probably need to author some CPG-on-FHIR resources to formally describe that process and workflow. The CDS Authoring Tool does not currently support authoring things like ActivityDefinitions and PlanDefinitions.

That said, if you do run into issues where you need to add CQL logic that the CDS Authoring Tool does not support, then yes --you can download the exported CQL and modify it by hand.

view this post on Zulip Tien Thai (Aug 20 2020 at 19:00):

Thanks Chris.
Instead of manually adding the CQL logic directly to the exported CQL file, can create a separate CQL file which contains the additional logic and then drag it into the CDS Authoring Tool as External CQL? Many thanks.

Best,
Tien Thai

view this post on Zulip Chris Moesel (Aug 20 2020 at 19:02):

Yes, you can do that as well, as long as the extra logic can be defined using a normal define statement (not a function). The AT doesn't yet support calling functions from external CQL.

view this post on Zulip John Silva (Aug 21 2020 at 00:25):

@Chris Moesel Have you tried using Atom with the language-cql plugin? https://atom.io/packages/language-cql
[I just installed it today, just tried it but not sure how to feed input data to it. The plugin adds a CQL -> Execute menu to directly execute the CQL code.]

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 01:43):

@John Silva , yeah, there's not great documentation on that yet, but there are examples, here's one: https://github.com/cqframework/opioid-mme-r4

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 01:44):

See the "tests" folder, basically, the execution expects a folder under tests named the same as the library, and each folder in that is the id of a Patient representing a test case.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 01:45):

If you open the Atom editor on the root of the ig, then when you're editing the CQL and you click execute, it will use the data from the tests folder.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 01:45):

It will also load vocabulary from the vocabulary folder.

view this post on Zulip Chris Moesel (Aug 21 2020 at 11:40):

@John Silva -- Yes, I've tried it (with varying success). As you can see, @Bryn Rhodes is the expert on that capability. @Bryn Rhodes -- I think most of my issues have been that I don't have my CQL files named (or located?) exactly the way the plugin wants them. Usually it fails for me just trying to convert the CQL to ELM. Is the required file naming and placement convention documented anywhere? If not, you might want to consider it.

view this post on Zulip John Silva (Aug 21 2020 at 13:47):

@Bryn Rhodes - OK, when I run 'npx sushi -o build' (sushi 0.12.7) I get the following directory structure:

build build/input build/input/resources build/input/extensions build/input/examples build/input/profiles build/input/vocabulary

But this isn't the same directory from where the CQL and FSH files are located; I have them in a parallel directory .fsh

I just noticed that Atom (and the plugin) automatically created a ./input/tests/results' folder I suppose because of when I tried to run 'CQL -> Execute' in Atom. I wonder if I have this directory structure with the CQL and FSH files in these directories if it will work (of course once I add ./tests/<patientId> subdirs

build build/input build/input/resources build/input/extensions build/input/examples build/input/profiles build/input/vocabulary build/cql build/elm

view this post on Zulip John Silva (Aug 21 2020 at 14:11):

Yes @Chris Moesel -- I'm trying to setup the directory structure and I'm making incremental progress. First it was looking for a directory under .../tests with the name of the Library so I created one, but I wasn't sure to use the id value of the library of the name of the file, e.g.
"id": "MyLibrary". and filename =. "Library-MyLibrary.json". (because that's what SUSHI generates from my .fsh file). It also seemed to want a ../input/vocabulary/valueset folder so I created one and it stopped complaining about t but I'm not sure what's supposed to be in there, if anything. The .../input/vocabulary folder already has the SUSHI generated vocab resources, e.g. ConceptMap-.json and ValueSet-.json in them? I guess I'll keep trying things to see if I can get this to work.

UPDATE: found a (maybe not only) problem. In the *.cql file I had the wrong name for the library entry, e.g.

library MyFooLibrary version '0.0.1'.

but my fsh file (and generated library) were name (and id)

MyLibrary

Once I fixed the library entry in the .cql file the CQL->Execute ran and showed the results. Now I just have to figure out the CQL logic. (time for a separate question -- I'm trying to figure out how to code for patient greater than a certain age. - ah, use AgeInYears() -- quite straight-forward. Just need to get it to read the patient.json file for the test)

view this post on Zulip John Silva (Aug 21 2020 at 19:14):

Got a lot further along from yesterday. Still having problems with running the tests. The CQL -> Execute CQL is running the tests but its not finding my test patient. Here's the simple CQL:

`
library MyTest version '0.0.1'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
context Patient
// Region: Initial Population

define "Is Older than 50":
AgeInYears() > 50
`

And when the tests run, here's what it shows:

Running tests. Data path: /Users/.../input/tests/MyTest Terminology path: /Users/.../input/vocabulary/valueset Test h16754 Fri Aug 21 2020 15:10:23 GMT-0400 (Eastern Daylight Time) Patient=null Is Older than 50=null elapsed: 3.494 seconds

view this post on Zulip John Silva (Aug 21 2020 at 19:18):

And here's how I have the directory structure setup (I tried to mimic what's in the opiod-mme example)

input/tests/MyTest input/tests/MyTest/h16754 input/tests/MyTest/h16754/Patient input/tests/MyTest/h16754/Patient/patient-h16754.json

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 19:56):

@John Silva , is this somewhere I can reproduce it?

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 19:57):

@Chris Moesel , yes, we definitely need better documentation on this, but in general, the cql is expected to be in "input/cql" relative to the IG root.

view this post on Zulip Chris Moesel (Aug 21 2020 at 20:01):

@Bryn Rhodes -- so you can only execute CQL that is part of an IG? I can't have a CQL-only project?

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:06):

No, you can, we just chose a directory structure layout that it expects that is consistent with the way the IGs are laid out so that you _can_ use it to execute CQL in an IG.

view this post on Zulip Rob Hausam (Aug 21 2020 at 20:07):

@Bryn Rhodes I'm working with John on this. I'm not sure that he's checked this in, but I can try to check.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:08):

input/cql
input/tests
input/tests/<cql-library-name>
input/tests/<cql-library-name>/<patient-id>
input/tests/<cql-library-name>/<patient-id>/<resource-type-name>/<resource files>
input/vocabulary/codesystem
input/vocabulary/valueset

view this post on Zulip John Silva (Aug 21 2020 at 20:23):

@Bryn Rhodes - I've created a minimal CQL (with NO valueset and only 1 define) but it still gives same error -- it doesn't find the patient.

Ah, I found the problem; it goes back to a question (we) asked here before. Does/will FSH support a date relative mechanism. I had :

"birthDate": "referenceDate - 20206 days",

(we have a pre-processor that converts that to an ISO date --- I forgot it was in there. Once I put in a real data the CQL test ran!! :-) )

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:24):

Hooray! Did the error get displayed in the log? (We try to pipe all error output to the console in Atom to help figure things like that out)

view this post on Zulip John Silva (Aug 21 2020 at 20:27):

It doesn't show up when I use the CQL -> Execute CQL (verbose) option, at least not in the .txt window that shows up. Is there another location where there's a 'full log'?

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:28):

No, the verbose option is the full log, and if it was a parsing error, I'm surprised that didn't show up.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:30):

For a possible answer to the "date relative" question, we use a cqf-expression extension to specify dynamic values. We have logic that runs that in the CQF Ruler, and are refactoring that so that we can use it in the Atom plugin as well.

view this post on Zulip John Silva (Aug 21 2020 at 20:33):

OK, thanks! I'm about to finish for today. At least now I know what I need to do.
Maybe you could try creating your own test with a 'bad resource' file and see why or if the log shows it or not.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:34):

Yep, for sure, should be easy to reproduce.

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:34):

And BTW, this prompted me to update the documentation on the Atom Plugin Readme:

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:34):

https://github.com/cqframework/atom_cql_support/blob/master/README.md#using-the-cql-support-in-atom

view this post on Zulip Chris Moesel (Aug 21 2020 at 20:44):

Thanks, Bryn. Aren't there also assumptions about how the CQL files are named? IIRC, the file name needs to be of a certain format for the engine (and/or translator) to find it (particularly for included CQL libraries). Is that still the case?

view this post on Zulip Bryn Rhodes (Aug 21 2020 at 20:49):

Yes, the translator expects files to be named <library-name>[-<version>].cql

view this post on Zulip John Silva (Aug 22 2020 at 12:26):

@Bryn Rhodes - thank you for updating the documentation and taking the time to help me (us) through these problems! Hopefully this will benefit many other people who use this very useful tool/package!

One other comment/suggestion: it's hard to tell which version or the executable path that this uses to find the Java JRE (or does it need the Java SDK). It would be helpful if there was a setting on the package that allowed the user to choose the path to the JRE (or SDK). I end up having multiple versions because of using a package manager on the Mac (asdf) and it doesn't seem to find the JRE.

BTW, I didn't name the <library-name> nor the Library json file with the version number in it yet it still seems to work. Is there a default such that it finds it based only on the name (or id) of the Library without the version? (e.g. I had version '0.0.1' in my CQL file.

view this post on Zulip Tien Thai (Sep 18 2020 at 12:40):

While testing my CDS artifact using CDS authoring tool, I noticed something that does not work right. In fact, I have 2 testing patients and if I test them individually, I get back the correct recommendation but if test them both, one of them is showing incorrect recommendation. The CDS artifact I am working on named as "Vitamin D Supplement Use". I am not sure if this is a bug with the tool or my logic is incorrect. Can you please help me clear this out. Thank you very much.
Tien Thai

view this post on Zulip Chris Moesel (Sep 18 2020 at 12:59):

Hi @Tien Thai. That is certainly odd and not expected to happen. We'll try to take a look at this and see if we can figure out what is going on.

view this post on Zulip Tien Thai (Sep 18 2020 at 15:26):

Chris,
I think I have figured out the cause of the issue. It was because these 2 testing patients have the same ID. Thank you very much for your attention.

Best,
Tien Thai

view this post on Zulip Chris Moesel (Sep 18 2020 at 15:32):

Ah! Thank you for letting us know. That would affect things. I think we should consider how the CDS Authoring Tool should handle this situation. If a user attempts to upload a patient w/ an already existing ID, we should do one of the following:

  • reject the upload, OR
  • replace the existing test patient w/ the new one, OR
  • modify the id so it is no longer the same as the existing one, OR
  • present a choice to the user so they can choose which of the above options they want to happen.

Thanks again for bringing up this issue.

view this post on Zulip Tien Thai (Sep 18 2020 at 17:05):

I have been trying to setup AHRQ--CDS-CONNECT-CQL-SERVICE project but kept getting the following error upon starting the service (See log below). Can you please give me any suggestion you might have to resolve this error? Thank you very much for your help.

Best,
Tien Thai


PS C:\CQL_Proj\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1> yarn start
yarn run v1.22.5
$ node ./bin/www
internal/modules/cjs/loader.js:968
throw err;
^

Error: Cannot find module 'express'
Require stack:

  • C:\CQL_Proj\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1\app.js
  • C:\CQL_Proj\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1\bin\www
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\CQL_Proj\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1\app.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'C:\\CQL_Proj\\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1\\app.js',
    'C:\\CQL_Proj\\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1\\bin\\www'
    ]
    }
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    PS C:\CQL_Proj\AHRQ-CDS-Connect-CQL-SERVICES-1.6.1>

view this post on Zulip Chris Moesel (Sep 18 2020 at 18:03):

It looks to me like you haven't installed the dependencies. First you need to run yarn install (or just yarn will actually do it as well). After you do this once, you won't need to do it again unless you update the code.

view this post on Zulip Tien Thai (Sep 21 2020 at 20:29):

Hi Chris,
Thank you very much for your suggestion. I was able to get the CDS service project up and running. However, when testing my service against default patient (i.e. Daniel Adams) in the CDS Sandbox, I am getting an error in the response section saying that "Could not get a response from the CDS Service. See developer tools for me details." Is it because this patient Daniel does not meet the inclusion criteria? Additionally, how would you add your own patients to this Sandbox so you can test your service against them? Many thanks for your help.
Best,
Tien Thai

view this post on Zulip Chris Moesel (Sep 23 2020 at 14:57):

Hi @Tien Thai. Sorry for the late response... "Could not get a response from the CDS Service. See developer tools for me details" could be caused by nearly anything. Did you look in your browsers developer tools (and more specifically, the console) to see if it provided any additional detail? You could also look to see if CQL Services emitted any logs in the window you're running it in.

One common thing that could potentially cause this is if you have not configured the UMLS username and password for CQL Services to use. You need to do this by setting UMLS_USER_NAME and UMLS_PASSWORD environment variables and ensuring that CQL Services can access those variables when it starts. See: https://github.com/AHRQ-CDS/AHRQ-CDS-Connect-CQL-SERVICES#setting-nlm-credentials-for-vsac-downloads.

If the patient doesn't meet the inclusion criteria then you just don't get a card in the response. An error like you received indicates that something is actually not working correctly.

view this post on Zulip Tien Thai (Sep 23 2020 at 18:49):

Hi @Chris Moesel ! before executing the "yarn start" command, I did execute those 4 environment variables as instructed. The server started OK with no error. The Statin-Use along with other services are working as well. However, my service is still giving the same error. Looking into the console, I am seeing the following error. Any suggestion on this error? Many thanks.

Best,
Tien Thai

Could not POST data to CDS Service http://localhost:3000/cds-services/vitaminD-use Error: Request failed with status code 412
at e.exports (app.bundle.js:22)
at e.exports (app.bundle.js:111)
at XMLHttpRequest.p.onreadystatechange (app.bundle.js:22)

view this post on Zulip Chris Moesel (Sep 23 2020 at 19:23):

CQL Services requires all data to be sent in the prefetch. It will respond with HTTP 412 (Precondition Failed) if the service request does not contain the necessary prefetch data. In my experience, the CDS Hooks Sandbox will do it's best to send the prefetch data. Are you using the public sandbox? Did you make any config changes that would cause the prefetch data not to be sent?

view this post on Zulip Tien Thai (Sep 23 2020 at 19:46):

Yes, I am using the public sandbox @ http://sandbox.cds-hooks.org. I basically added the service (http://localhost:300/cds-service) and then selected the service from the list of services provided by the service. Below is the hook configuration for my service:
{
"id": "vitaminD-use",
"hook": "patient-view",
"title": "Vitamin D Use for Falls Prevention",
"description": "Presents Vitamin D recommendation for adults aged 65 years and older.",
"_config": {
"cards": [{
"conditionExpression": "InPopulation",
"card": {
"summary": "Vitamin D Use for Falls Prevention in adults 65 years of age and older",
"indicator": "info",
"detail": "${Recommendation}",
"source": {
"label": "CDS Connect: Vitamin D Use for Falls Prevention in Adults",
"url": "https://cds.ahrq.gov/cdsconnect/artifact/Vitamin-D-Supplement-Use"
},
"extension": {
"grade": "${Errors}"
}
}
}],
"cql": {
"library": {
"id": "Vitamin-D-Supplement-Use",
"version": "1.0.0"
}
}
}
}

Thanks.
TT

view this post on Zulip Chris Moesel (Sep 24 2020 at 12:33):

Hi @Tien Thai. I've been trying to reproduce your experience. I think I may know what is going on. I suspect that your CDS uses one version of FHIR (e.g., R4) and the CDS Hooks Sandbox is using a server that supports a different version of FHIR (e.g., DSTU2). Some resources changed names -- most notably MedicationOrder in DSTU2 is MedicationRequest in R4 -- so when your service prefetch asks for MedicationRequest resources, the server cannot fulfill that request.

By default, the CDS Hooks Sandbox uses DSTU2, so I'm guessing that your CQL is using FHIR R4? If that's correct, try changing the FHIR server in the CDS Hooks Sandbox so it is: http://launch.smarthealthit.org/v/r4/fhir and then change the patient to 46d3785e-865b-46a5-8ea9-86a72a183de3 (a randomly selected R4 patient). You might not get a card from your service (e.g. its response may be { "cards": []}) but hopefully you will not get that error. Then that would mean the hooks are connected properly -- the patient just didn't have the data to activate a response.

If you want to browse the patients that are in that R4 FHIR server, you can go to: http://patient-browser.smarthealthit.org/?config=r4. Once you find a patient you like, copy its ID and use that in the "Change Patient" dialog of the CDS Services Sandbox.

I hope that I guessed the problem right. Let me know!

view this post on Zulip Tien Thai (Sep 24 2020 at 13:06):

Hi @Chris Moesel Yes, indeed! Just to tested out my CDS in both R4 and DSTU2 versions and it returns empty card as expected.

For testing with DSTU2 version:

  1. Downloaded the CDS in DSTU2 and copy the ELM files to config/libraries folder
  2. Restart the CQL Service
  3. Use default FHIR server on the Sandbox.

For testing with R4 version, I followed steps above using R4 CDS libraries, FHIR server's URL and new patient.

Thank you very much for your excellent help.

Tien Thai

view this post on Zulip Chris Moesel (Sep 24 2020 at 14:14):

Glad we figured it out! Thanks for reporting back!

view this post on Zulip Tien Thai (Sep 28 2020 at 19:30):

Hi @Chris Moesel
When testing my sample CDS Service with my custom patients in CDS Authoring Tool, it does return the recommendations as expected. I downloaded the CDS artifact as R4 and copied all the files to /config/libraries folder. The hook for this CDS service is also configured in /config/hooks folder as shown below:
=================
{
"id": "vitaminD-use",
"hook": "patient-view",
"title": "Vitamin D Use for Falls Prevention",
"description": "Presents Vitamin D recommendation for adults aged 65 years and older.",
"_config": {
"cards": [{
"conditionExpression": "InPopulation",
"card": {
"summary": "Vitamin D Use for Falls Prevention in adults 65 years of age and older",
"indicator": "info",
"detail": "${Recommendation}",
"source": {
"label": "CDS Connect: Vitamin D Use for Falls Prevention in Adults",
"url": "https://cds.ahrq.gov/cdsconnect/artifact/Vitamin-D-Supplement-Use"
},
"extension": {
"grade": "${Errors}"
}
}
}],
"cql": {
"library": {
"id": "Vitamin-D-Supplement-Use",
"version": "1.0.0"
}
}
}
}
======================

When testing this CDS artifact with a random patient from the Sandbox, "No cards" was returned. This is fine since I know none of those random patients will return anything as they do not meet the criteria defined for the Recommendations (i.e. There exists an Active Medication Request with a code from "Vitamin D" value set.)

When testing with my custom patient , i.e. the one that works in the CDS Authoring Tool, from the Logica Sandbox, there was still no cards returned. This really made me scratched my head :) as I have no way to debug the CDS artifact. I can see the content of the JSON request but cannot see the content of the JSON response. In your experience, can you please let me know the best tool you used to debug your CDS service? Is there a way to get to the content of the JSON response from the CDS service? Thank you very much for your help.

PS:
When looking at the log (see below), I noticed the request was successfully posted but I did not see any line that indicates a successful response. Does it mean that my CDS service does not return anything back to caller?

Loaded 4 hooks

- ascvd-risk
- cond-med-count-r4
- statin-use
- vitaminD-use
**2020-09-28T19:09:15.828Z ::1 "OPTIONS /cds-services/vitaminD-use" 204 0
2020-09-28T19:09:16.156Z ::1 "POST /cds-services/vitaminD-use" 200 12**

Regards,
Tien Thai

view this post on Zulip Chris Moesel (Sep 29 2020 at 15:33):

Hi @Tien Thai. If you'd like to see the full set of CQL results when you call a CDS Hooks service, you can add a logging statement around line 199 of routes/cds-services.js. It should look like this:
image.png

view this post on Zulip Tien Thai (Sep 29 2020 at 18:09):

Hi @Chris Moesel It is very helpful info. Thank you very much.

view this post on Zulip Tien Thai (Dec 23 2020 at 15:33):

Suppose that a recommendation is returned if there exists an active MedicationRequest where code in some value sets, is it possible to include the name and the RxNORM of that medication in the recommendation?

Additionally, can you please explain how you authored the Condition_and_Medication_Count_FHIRv400 using the CDS Authoring Tool? Is it an external CQL being imported into the CDS?

Many thanks for your help.

Regards,
Tien Thai

view this post on Zulip Chris Moesel (Dec 31 2020 at 00:51):

Currently, the CDS Authoring Tool only supports returning text-based recommendations where the full text is known at build time (i.e., it is not dynamic). That said, it's possible to build the CDS/CQL in such a way that an engine might be able to easily pull the name and code of the medication from one of the other exported expressions (not the "Recommendation" expression) -- but I don't think this is what you're asking for. For now, you would probably need to manually edit the CQL after downloading it from the Authoring Tool.

As for the Condition_and_Medication_Count CQL, I believe we authored that manually (not using the CDS Authoring Tool).

view this post on Zulip Tien Thai (Jan 14 2021 at 13:42):

Hi Chris,
Thank you very much for your reply. I have attempted to define the following base element in CDS authoring tool:


define "On Fall Risk Increasing Drugs (FRIDs)":
ActiveMedicationRequest([MedicationRequest: "Fall Risk Increasing Drugs (FRIDs) VS"])


and then referenced the "On Fall Risk Increasing Drugs (FRIDs)" in the hook config file (see card configuration below). Upon successful invoking the CDS service, the card only displays the word "object Object" instead of the list of medications with codes from the "Fall Risk Increasing Drugs (FRIDs) VS" value set. Can you please provide me any suggestion on how to return this list of medication back to the CDS client when invoking the CDS service? Many thanks for your help.
Tien Thai


"cards": [{
"conditionExpression": "InPopulation",
"card": {
"summary": "Fall Prevention Risk Factors for Patient 65 Years of Age and Older",
"indicator": "info",
"detail": "Returned medications: ${On Fall Risk Increasing Drugs (FRIDs)}",
"source": {
"label": "CDS Connect: Fall Prevention Risk Factor - Medication Service",
"url": "https://cds.ahrq.gov/cdsconnect/artifact/fall-prevention-risk-factors-r4"
},
"extension": {
"grade": "${RecommendationGrade}",
"rationale": "${Rationale}"
},
"error":"Error: ${Error}"
}
}],

view this post on Zulip Chris Moesel (Jan 14 2021 at 17:25):

Hi @Tien Thai. What is the behavior you want? Do you want the full MedicationRequest objects or just some info from the medications? The ${...} string interpolation feature works best when the expression you reference is a String -- but On Fall Risk Increasing Drugs (FRIDs) is a list of MedicationRequest objects. If you want to just display certain information from the requests to the user (like the med name, request date, etc), then you likely need to use CQL String operators to construct the message you want in CQL -- and then you can reference that message in the card using ${...}. Constructing these types of dynamic messages using CQL is not supported in the CDS Authoring Tool though -- so you'll need to hand modify the CQL to support that.

If you actually want the hook to return a list of MedicationRequests as suggestions that the user can act on (to prescribe, for example), then you need to use the card's suggestions property to return the list of MedicationRequests. I haven't tried this in a while, but you could try: "suggestions": "${On Fall Risk Increasing Drugs (FRIDs)}" -- although I don't recall how well that works. Even if it does return objects, I think it may return them in a format representing the FHIR modelinfo rather than real FHIR JSON serialization -- in which case you'd need a Tuple to do what you want. The other approach is if the list of suggested meds is known at build time, you could take an approach like shown here.

view this post on Zulip Tien Thai (Jan 19 2021 at 21:56):

Hi Chris,
Thank you very much for the suggestion.
I did try to define the following in an external CQL, then attached it to the CDS service using the CDS Authoring Tool.


**define ActiveFRIDsMeds:
[MedicationRequest: medication in "Fall Risk Increasing Drugs (FRIDs) VS"] A
return{
medcode: A.medication.coding.code.value
}**


In the card config file, I used the "suggestions" property to display the above definition as shown below and restarted the CDS service.

Upon calling the service, the card was successfully returned. However, when looking at the content of the card, I did not see the "suggestions" property nor its content in the card itself. Did I miss anything? Many thanks for your help.


{
"id": "fall-prevention-risk-factors-r4",
"hook": "medication-prescribe",
"title": "Fall Prevention Risk Factors",
"description": "CDS Service that provides guidance to the prescriber if the patient is at least 65 years of age and is on FRIDs medication.",
"_config": {
"cards": [{
"conditionExpression": "InPopulation",
"card": {
"summary": "Fall Prevention Risk Factors for Patient 65 Years of Age and Older",
"indicator": "info",
"detail": "Returned Recommendation: ${Recommendation}",
"source": {
"label": "CDS Connect: Fall Prevention Risk Factor - Medication Service",
"url": "https://cds.ahrq.gov/cdsconnect/artifact/fall-prevention-risk-factors-r4"
},
"extension": {
"grade": "${RecommendationGrade}",
"rationale": "${Rationale}"
},
"error":"Error: ${Error}"
}
}],
"suggestions": "${ActiveFRIDsMeds.medcode}",
"cql": {
"library": {
"id": "Fall-Prevention-Medication-Risk-Factors",
"version": "1"
}
}
}
}


Below is the returned CARD upon calling the CDS Servicve:


{
"cards": [
{
"summary": "Fall Prevention Risk Factors for Patient 65 Years of Age and Older",
"indicator": "info",
"detail": "Returned Recommendation: Considering 18-week tapering protocol, provide patient education brochure.",
"source": {
"label": "CDS Connect: Fall Prevention Risk Factor - Medication Service",
"url": "https://cds.ahrq.gov/cdsconnect/artifact/fall-prevention-risk-factors-r4"
},
"extension": {
"grade": "",
"rationale": ""
},
"error": "Error: "
}
]
}

view this post on Zulip Chris Moesel (Jan 20 2021 at 17:02):

Hi @Tien Thai. It looks like you have not actually put suggestions in the card object. In the JSON you posted above, it is outside of the cards array. I also noticed that you added an error attribute -- but since that is not defined by CDS Hooks, it should really go inside the extension part of the card.

I think you want something more like this:

{
  "id": "fall-prevention-risk-factors-r4",
  "hook": "medication-prescribe",
  "title": "Fall Prevention Risk Factors",
  "description": "CDS Service that provides guidance to the prescriber if the patient is at least 65 years of age and is on FRIDs medication.",
  "_config": {
    "cards": [
      {
        "conditionExpression": "InPopulation",
        "card": {
          "summary": "Fall Prevention Risk Factors for Patient 65 Years of Age and Older",
          "indicator": "info",
          "detail": "Returned Recommendation: ${Recommendation}",
          "source": {
            "label": "CDS Connect: Fall Prevention Risk Factor - Medication Service",
            "url": "https://cds.ahrq.gov/cdsconnect/artifact/fall-prevention-risk-factors-r4"
          },
          "suggestions": "${ActiveFRIDsMeds.medcode}",
          "extension": {
            "error": "Error: ${Error}",
            "grade": "${RecommendationGrade}",
            "rationale": "${Rationale}"
          }
        }
      }
    ],
    "cql": {
      "library": {
        "id": "Fall-Prevention-Medication-Risk-Factors",
        "version": "1"
      }
    }
  }
}

That said, putting an array of the med codes in suggestions is not quite correct either. Suggestions should follow a particular format that defines actions on FHIR resources. See the CDS Hooks spec for more details: https://cds-hooks.hl7.org/1.0/#suggestion

view this post on Zulip Tien Thai (Jan 20 2021 at 17:14):

Chris,
Thanks for your reply. I did realize that this morning and I move the suggestion property into the card exactly like the way you suggested but I got an error like the one below. I am looking for a standard template for suggestion to resolve this error.

Error: Card has suggestions but no selectionBehavior field.

Thanks.
Regards,
Tien Thai

view this post on Zulip Chris Moesel (Jan 20 2021 at 17:37):

That link to the CDS Hooks spec I posted above should get you to the definition of suggestions and what are the required fields. You can also see the basic layout in the alternative hook configuration I linked to at the end of my first message.

view this post on Zulip Tien Thai (Jan 20 2021 at 21:06):

@Chris,
Thank you very much. The issue is resolved after adding the "selectionBehavior" attribute to the CDS card.

Best,
Tien Thai


Last updated: Apr 12 2022 at 19:14 UTC