Skip to content

Cooking with CQL Q&A: Date and Time Calculations

rhondaschwartz edited this page Jun 5, 2020 · 24 revisions
authorDatetime: With regard to authorDatetime, if that’s the time it’s entered into the clinical software then what happens when someone goes back to edit it? Is it the last modified time or the original creation time and do we have a way of handling that? (Session 35 - 5/23/19)
  • We’re not sure as that has not come up before. There’s an amended time, which would still be the recorded time, so it may depend on your use case. The relevantDatetime would still be the dispense time. QDM doesn’t say how to handle it, but we may want to specify if it was the original time or amended time – we’d likely have to define it.
Coalesce: In the Coalesce expression, if the patient record has an order performed date of 12/12 but the performed author DateTime is 12/07 what is the result?

Coalesce(start of ComfortMeasures.relevantPeriod, ComfortMeasures.authorDatetime)

(Session 31 - 1/31/2019)

  • For Coalesce, each argument is considered in order, and the first one with a value is returned. The use of “first” in this description is referring to the list of arguments to the Coalesce function. So in the example of a performed date of 12/12 and an author date of 12/07, since the performed date (start of relevantPeriod) is first in the list of arguments and has a value, that will be returned as the result.
Cumulative Medication Duration: In the example of the QDM documentation illustrating the Cumulative Medication Duration calculation, if the second date is prior to the first date, does that always get to negative? Does this uncertainty play into that calculation? (Session 34 - 4/24/2019)
  • Yes, if the second date is before the first date then you will get a negative number out of it. You will still get the same number, it would just be in the other direction.
Cumulative Medication Duration: In the example of the QDM documentation illustrating the Cumulative Medication Duration calculation, what if the first date is only at the day level but the second level precision is at the time level, do you still end up with an indecision? (Session 34 - 4/24/2019)
  • The engines do all the calculations so the lowest value of the less precise to the highest possible value of the less precise and they do the duration calculation between those and that gives them the result as an interval. In the example below, it would calculate from the earliest possible time, midnight, and the latest possible time, 11:59 PM, on the first date, giving you the same result. In general, it is okay for the format to be different between the 2 days. The actual result will be an uncertainty.
Cumulative Medication Duration: For the interval function of the example of the QDM documentation illustrating the Cumulative Medication Duration calculation, is it required that the first parameter has to be less than or equal to the second parameter? (Session 34 - 4/24/2019)
  • Yes, that is true of intervals. In the example below, that would be an error because it’s not a valid interval. Interval [@2018-02-01, @2018-01-01]
Date vs DateTime: For the glucocorticoid dosage expression, is using Date appropriate in place of DateTime? (Session 31 - 1/31/2019)
define function "Glucocorticoids Dosage Per Day"(glucocorticoids List<Tuple {
  code Code,
  daysInPeriod List<DateTime>,
  dailyDosage Quantity
}>):

  • Yes, in version 1.3 of CQL, the Date type can be used for the daysInPeriod argument (i.e. List instead of List).
DifferenceInDays vs DurationInDays: Using the DifferenceInDays example below: is this the same as calendar days? Would the DurationInDays give you the uncertainty result or would it be different in this situation?

define DifferenceInDays: difference in days between @2017-01-01T22:00:00 and @2017-01-02T02:00:00 // 1

define DifferenceInDays: duration in days between @2017-01-01T22:00:00 and @2017-01-02T02:00:00 // 0

(Session 34 - 4/24/2019)

  • The distinction between Difference and Duration is that Difference is counting the boundaries. You can still get uncertainty in Difference calculations but note that Difference is counting the number of boundaries crossed. In this example, DifferenceInDays is 1 because midnight was crossed once but DurationInDays is 0 because 24 hours have not passed. Note that both Difference and Duration calculations can give you uncertainty but Difference is less sensitive to the time than Duration.
Estimated Due Date: Regarding estimated due date definition – how can we be sure it's the last physical exam we're interested in. Mothers can have multiple babies over a period of time so how do we know which baby it is associated with on the mother"s record? For example, if a mother has 3 pregnancies but we want to reference the 2nd pregnancy, how do we link this last due date in the second pregnancy to the mother's record? (Session 33 - 3/28/2019)
  • This is a case of retrospective data. It might be possible to indicate a one-year time period prior to the delivery date of the referenced pregnancy. One might need to seek guidance from the American College of Obstetrics and Gynecology (ACOG) to get a definition of due date. Regardless, if the expectation is to perform a context-based query, the patient record and the related person might have to exist at the same time.
Leap Year: CQL logic calculates an interval using both days and months. The specific line of code in question refers to: FirstIndexAssessment.authorDatetime where we can use a combination of months and days. For this line of code, are leap years accounted for if you use 14 months? (Session 34 - 4/24/2019)
  • No, because months are still by calendar year too. If you had gone through February in 2012, you would have gotten 29 days. In order to avoid the issue with leap years, you should not combine moths and days and only use days to avoid this variability.
Relevant Period: Referring to CMS52v7, does the laboratory test always have a relevant period? (Session 35 - 5/23/19)
  • It does. It also has a resultDatetime, the time the result was actually reported. The authorDatetime is used to provide the negation time when representing a laboratory test not performed, but resultDatetime is used to indicate when it became available or posted and the relevantDatetime is used for the physiologic time, when it was drawn. There are some specimens that are obtained over a period of time.

Wiki Index

Home

Authoring Patterns - QICore v4.1.1

Authoring Patterns - QICore v5.0.0

Authoring Patterns - QICore v6.0.0

Authoring Measures in CQL

Composite Measure Development

Cooking with CQL Examples

Cooking with CQL Q&A All Categories
Additional Q&A Examples

CQL 1.3 Impact Guidance

CQL Error Messages

Developers Introduction to CQL

Discussion Items

Example Measures

Formatting and Usage Topics

Formatting Conventions

Library Versioning

Negation in QDM

QDM Known Issues

Specific Occurrences

Specifying Population Criteria

Supplemental Data Elements

Terminology in CQL

Translator Options For Measure Development

Unions in CQL

Clone this wiki locally