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

Issue with accessing FHIR Data types #59

Closed
darena-pjindal opened this issue Aug 2, 2024 · 10 comments
Closed

Issue with accessing FHIR Data types #59

darena-pjindal opened this issue Aug 2, 2024 · 10 comments

Comments

@darena-pjindal
Copy link

Hello - I have been trying some very simple queries but it seems to not recognize the basic FHIR types. Am I don't something wrong here? Here is one of the query I tried.

library SampleTest version '0.0.1'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers

context Patient

define "IsMale":
Patient.gender = 'male'

define "HasHypertension":
exists (
[Observation] O
where exists (O.code.coding C where C.code = 'sys-bld-prs')
and O.value is Quantity
and O.value.value > 140
)

define "HasGlucoseObservation":
exists (
[Observation] O
where exists (O.code.coding C where C.code = 'gluc')
)

define "MeetsCriteria":
"IsMale"
and "HasHypertension"

define "Recommendation":
if "MeetsCriteria" then 'Recommend monitoring blood pressure and lifestyle changes'
else 'No specific recommendation'

define "Rationale":
if "MeetsCriteria" then 'Patient meets criteria for hypertension monitoring'
else 'Patient does not meet criteria for hypertension monitoring'

define "Errors":
null

@evan-gordon
Copy link
Collaborator

Hi @darena-pjindal

Thank you for taking the time to open an issue!

I'm using the cqlplayground to tinker around a bit with the code you linked and I have found a few things but I'm still working on a getting you a proper response. So changing and O.value is Quantity to and O.value is FHIR.Quantity should make that part of the query filter properly.

I think there may be a bug in the engine regarding the conversion of said FHIR.Quantity into a system type that you can compare the value of, but I'm not quite done looking into that at this time.

I'll try to get you an update on this as soon as i can but since it's almost the weekend no promises before Monday :)
If you could add any error outputs from the engine to the ticket that would also be helpful!

@darena-pjindal
Copy link
Author

Thanks, @evan-gordon, for the quick response. Let me know if I can help to provide more details. Thanks for creating such a great tool!

@suyashkumar
Copy link
Contributor

suyashkumar commented Aug 3, 2024

Hi @darena-pjindal, I had some free time and was able to do a lil investigation. It turns out this has to do with a discrepancy in how FHIR protocol buffers represent decimals and how the CQL FHIR ModelInfo statically expects decimal.value properties to behave. #60 should fix the issue you were facing in "HasHypertension" with the following modifications:

and O.value is FHIR.Quantity
and (O.value as FHIR.Quantity).value > 140
define "HasHypertension":
exists (
[Observation] O
where exists (O.code.coding C where C.code = 'sys-bld-prs')
and O.value is FHIR.Quantity
and (O.value as FHIR.Quantity).value > 140
)

I was able to verify this ran in our cql playground (with #60) against the default data without errors, though didn't look at the rest of your logic carefully.

I think there's at least one other bug or improvement to be made here, but hopefully this should unblock your explorations!

@darena-pjindal
Copy link
Author

Thanks @suyashkumar. That worked

@suyashkumar
Copy link
Contributor

Awesome, great to hear! Let us know if you run into any other issues.

@darena-pjindal
Copy link
Author

@suyashkumar—Actually, I am still having a conversion issue. I don't remember what query I tried over the weekend, but this doesn't seem to work. It says Error: failed to eval: failed during CQL evaluation: Explore 1.2.3, internal error—can not convert System.String to a float64.

library Explore version '1.2.3'
using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers

context Patient

define "IsMale":
Patient.gender = 'male'

define "HasHypertension":
exists (
[Observation] O
where exists (O.code.coding C where C.code = 'sys-bld-prs')
and O.value is FHIR.Quantity
and (O.value as FHIR.Quantity).value > 140
)

@suyashkumar
Copy link
Contributor

suyashkumar commented Aug 5, 2024

@darena-pjindal are you using the latest commit on main that includes my PR #60? I'm able to get it to work in the playground with default data at HEAD. If not, let's see if we can debug some more.
Screenshot 2024-08-05 at 12 20 17 PM

@darena-pjindal
Copy link
Author

@suyashkumar - my bad :(. I was using it on a machine with the old version. I was wondering how it suddenly stopped working again :). Thanks so much.

@suyashkumar
Copy link
Contributor

No problem at all, glad it's working! Thanks again for giving our tools a try--please do open any more issues that you run into in the future!

@evan-gordon
Copy link
Collaborator

Glad to hear you're unblocked @darena-pjindal ! Let us know if anything else comes up!

@suyashkumar thanks for your quick work here!

Closing the issue as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants