Skip to content

Cooking with CQL Q&A: Date and Time Calculations

rhondaschwartz edited this page Nov 23, 2020 · 24 revisions

Each Q&A has the Cooking with CQL session number and date. For the most current and accurate information, please check the CQL Qs&As for a more recent answer to your question.

authorDatetime: With regard to the QDM attribute author dateTime, 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)
  • Thank you for this question. The issue is something the implementer needs to address. The QDM attribute author dateTime is defined as “The time the data element was entered into the clinical software.” This timing should be equivalent to a time stamp in the software. Any edits to the information entered might update the relevant dateTime or relevantPeriod to address the actual time an action occurred will have a new timestamp for the edits, but the original timestamp to indicate the activity should remain. All changes are new revisions with their own timestamps. While the answer may depend on the activity desired by the measure, the author dateTime should most likely be the time originally documented. Note that another use of author dateTime is to identify the timestamp for documenting negationRationale, the reason an action was not taken. Even if the negationRationale reason was modified, the original time documenting an action that did not happen for a reason should be the timestamp used for the measure concept. In this example, the “Medication, Dispensed” relevant dateTime is the time dispensed (in FHIR, whenHandedOver). If that were edited in a pharmacy system the actual relevant dateTime would be used for the calculation (i.e., the revised version). Implementers will need to determine if the edits are valid and acceptable as part of routine local data maintenance rules.
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.

define DurationInDays: days between @2017-08-07T and @2017-08-14T17:00 // [6, 7]

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, since CQL 1.3, the Date type can be used for the daysInPeriod argument (i.e., List<Date> instead of List<DateTime>).
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.
Interpreting time phrases: When interpreting time phrases in Clinical Quality Language (CQL), for example, an encounter started at midnight on 1/1/2020 and the diagnosis also started at midnight on 1/1/2020. In this case, did the diagnosis start during the encounter? (Session 46 - 07/30/2020)
  • Using the example provided, this expression returns true because it defines during inclusively. The diagnosis is during that interval because during hits the boundaries of this expression. Whether the diagnosis started at midnight or 10:30 am, both of those would count if we are just looking at starts during because it is an inclusive comparison.

@2020-01-01T00:00:00.0 during Interval[@2020-01-01T00:00:00.0, @2020-01-01T10:30:00:00]

Lab Tests Every Six Weeks Revisited : In the Lab Tests Every Six Weeks Revisited example where lab tests need to happen every six weeks or LESS while the therapy is ongoing, why have you chosen to use days instead of weeks?


define "Has Lab Test Intervals More Than Six Weeks":
  "Valid Lab Test Intervals" LTI
   where duration in days of LTI > 42

define "Numerator":
  Count("Valid Lab Test Intervals") >= 2
    and not exists "Has Lab Test Intervals More Than Six Weeks"


(Session 48 - 10/29/2020)

  • We do not want tests performed in the 6th week. If you have a test that is performed at 6 weeks and 1 day, the duration would be 6 weeks since it has not yet hit the 7th week. Any test that is performed up to the day before the 7th week will still render as 6 weeks and since we do not want to count tests performed in the 6th week we need to use days.
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)
  • Since QDM 5.5, a “Laboratory Test, Performed” uses relevant dateTime to represent an activity that occurs at a single point in time (e.g., a fasting blood glucose with a single point in time collection), and relevantPeriod start and stop times for a laboratory test that occurs over a time interval (e.g., a 24-hour urine collection for creatinine clearance).

Note, a measure developer should work with implementers to determine if timed collections are truly documented as a period or as a point in time to determine the appropriate representation in a measure.

Subtraction of one hour when there is a leap second: When interpreting time phrases in Clinical Quality Language (CQL), what is the subtraction of one hour when there is a leap second? (Session 46 - 7/30/20)
  • The definition of a calendar hour is the same time in the next hour so that effectively allows you to treat hours like calendar durations in the same way that we do for leap days. We say that the month is the same date in the next month if that date exists, otherwise it is the previous day. Because leap seconds are so foreign to human experience and our goal is natural language expression for humans, we do not call out leap seconds specifically, but leap seconds are the reason that Unified Code for Units of Measure (UCUM) units and calendar durations units are only equal up to the second. A UCUM unit is not comparable to the calendar duration unit for anything above a second.

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