Stream: cql
Topic: Syntax error
Tien Thai (Nov 21 2019 at 19:22):
Given:
medSupply = 10
drugStrength.value = 5.0
conversionFactor = 1.5
Plug those value to the following expression:
prescriptionMME: Quantity { value: medSupply * drugStrength.value * conversionFactor, unit: dailyDose.unit }
Getting "Expected an expression of type 'System.Decimal', but found an expression of type 'System.Quantity'" error.
Can you please let me know if there is anything wrong with the above expression? Thank you.
Chris Moesel (Nov 21 2019 at 19:41):
Without the full context of the types, it's hard to say. But it seems to me like it's expecting prescriptionMME
to be a Decimal
, but you're assigning it a Quantity
. This may be the case since MME has an assumed unit. But again, it's hard to say without all of the context.
Eghonghon Okpah (Jan 28 2020 at 19:27):
Code :
define function IntervalExtension(collapsed List<Interval<DateTime>>, source List<Interval<DateTime>>):
if collapsed is null then null
else
Interval[
start of collapsed,
start of collapsed + SumInDays(source sr where sr during collapsed)
]
define function ExtendIntervals(intervals List<Interval<DateTime>>) returns List<Interval<DateTime>>:
from (collapse intervals) CollapsedInterval,
intervals I
return (if CollapsedInterval CI includes I and I includes CollapsedInterval then I
else ExtendIntervals(IntervalExtension(CollapsedInterval, intervals)))
Error: Cannot resolve reference to expression or function ExtendIntervals() because it results in a circular reference.
Wondering if there is a better way of writing this code to handle recursion.
Bryn Rhodes (Jan 29 2020 at 00:40):
Hi @Eghonghon Okpah , I'm not sure I'm following what this is trying to do? In general, yes, CQL does not support recursive functions or queries. This is by design to ensure authors cannot build infinite recursion into their expressions, but it does put some recursive patterns out of reach; this might be one such case.
Bryn Rhodes (Jan 29 2020 at 00:41):
We are considering adding recursive capabilities to the language, can you help me understand this use case so we can make sure it is handled by what we end up proposing?
Eghonghon Okpah (Jan 30 2020 at 17:52):
@Bryn Rhodes the goal is to compute MedicationDispenseEvents into a list of Intervals, each Interval corresponding to the date of the event and the amount dispensed, and then recursively collapsing and extending the list of Intervals until a stable result is achieved.
Tien Thai (Mar 06 2020 at 16:36):
I am trying to convert a QDM based eCQM to FHIR based eCQM and for some reasons, it kept giving me the "Expected an expression of type 'FHIR.decimal' , but found an expression of type 'System.Decimal'" error in the function below. Can you please help me point out what could have caused the error? Many thanks.
TT
define function "EnsureMicrogramQuantity"(strength Quantity):
if strength.value < 0.1
and ( PositionOf('mg', strength.unit)= 0 ) then Quantity { value: strength.value * 1000, unit: 'ug' + Substring(strength.unit, 2)}
else strength
JP (Mar 06 2020 at 17:43):
There are actually two quantity types available when you've declared "using FHIR version 'X.X.X'. One is the native CQL quantity (System.Quantity), and the other is the FHIR quantity (FHIR.Quanity). It's not clear from your code which you are intending to use, but here are two potential solutions:
If you're intending to use FHIR.Quantity:
define function "EnsureMicrogramQuantity"(strength FHIR.Quantity): if strength.value < 0.1 and ( PositionOf('mg', strength.unit)= 0 ) then Quantity { value: FHIR.decimal { value : (strength.value * 1000) }, unit: FHIR.string { value: 'ug' + Substring(strength.unit, 2)} } else strength
If you're intending to use System.Quantity:
define function "EnsureMicrogramQuantity"(strength System.Quantity): if strength.value < 0.1 and ( PositionOf('mg', strength.unit)= 0 ) then System.Quantity { value: strength.value * 1000, unit: 'ug' + Substring(strength.unit, 2) } else strength
Tien Thai (Mar 06 2020 at 18:33):
Yes, the System.Quantity clears the error. Thanks very much for your help, Jonathan!
Tien Thai (Mar 06 2020 at 20:58):
Hi Jonathan,
I am defining a function that returns an interval (see below) but kept getting an "Expected an expression of type 'System.Decimal', but found an expression of type 'FHIR.Duration'" error . Can you please let me know what could have caused the error? Your help is appreciated.
TT
define function "MedicationRelevantPeriod"(OpioidMed "MedicationRequest"):
Interval[start of OpioidMed.dispenseRequest.validityPeriod,
case
when OpioidMed.dispenseRequest.expectedSupplyDuration is not null
then start of OpioidMed.dispenseRequest.validityPeriod + System.Quantity { value: OpioidMed.dispenseRequest.expectedSupplyDuration, unit: 'd' }
else
end of OpioidMed.dispenseRequest.validityPeriod
end]
Bryn Rhodes (Mar 08 2020 at 04:24):
Hi @Tien Thai , the issue is that the MedicationRequest.dispenseRequest.expectedSupplyDuration element is a Duration, which is a special type of Quantity, which means it has value and unit elements. So to create a Quantity out of it, you have to access the value
element:
define function "MedicationRelevantPeriod"(OpioidMed "MedicationRequest"): Interval[start of OpioidMed.dispenseRequest.validityPeriod, case when OpioidMed.dispenseRequest.expectedSupplyDuration is not null then start of OpioidMed.dispenseRequest.validityPeriod + System.Quantity { value: OpioidMed.dispenseRequest.expectedSupplyDuration.value, unit: 'd' } else end of OpioidMed.dispenseRequest.validityPeriod end]
Mohammad Afaq Khan (Mar 10 2020 at 17:02):
@Bryn Rhodes what is the future of CQL & FHIR with machine learning? I mean I know JSON is compatible with so many different frameworks and even Tensorflow. Is there any future prospect integration with TensorFlow?
Bryn Rhodes (Mar 10 2020 at 23:36):
It's certainly a possibility, and there's a FHIR tracker about supporting machine learning models with the Library resource (J#25046). We've also looked at supporting predictive models as external
calls in CQL, and enabling machine learning is a key motivator for computable guidelines work with FHIR and CQL. Would welcome any feedback on that topic, and be very interested to hear if you've done any exploration along those lines.
Mohammad Afaq Khan (Mar 11 2020 at 15:07):
Unfortunately, I am exploring this area as well. I think it will definitely become very important in the future. Hopefully, I can catchup on this topic to be able to provide relevant feedback in time :grinning: .
Last updated: Apr 12 2022 at 19:14 UTC