Skip to content

QA Differences Between QDM Timing and CQL Timing

Darren Duncan edited this page Oct 12, 2017 · 1 revision

Questions and Answers


Q&A - Differences Between QDM Timing and CQL Timing

Question

How do timing interval calculations compare and contrast between QDM and CQL?

Answer

Note that the following only applies to QDM 4 and not to QDM 5.

Timing interval calculations between QDM 4 and CQL are largely similar, but have important differences.

Instant Granularity

An instant (calendar date or calendar date plus time of day) may be measured at various explicit levels of granularity (such as years, months, days, hours, minutes, or seconds) and EHRs have a variety of formats for representing these instants. Some EHRs will have instants explicitly to the significant or measured level of precision, which may mean partial dates or partial times of day. Other EHRs will have instants in a fixed precision format (typically to the second or to the day) regardless of the actual measurement precision.

Examples of different precisions of instants:

  Instant I1: 2012
  Instant I2: 2012-03
  Instant I3: 2012-03-10
  Instant I4: 2012-03-10 22
  Instant I5: 2012-03-10 22:05
  Instant I6: 2012-03-10 22:05:09

A CQL instant explicitly supports partial datetimes and therefore preserving and reasoning with the actual level of precision given by an EHR. CQL treats date/time values that are only known to some specific precision as an uncertainty over the range at the first unspecified precision. For example, DateTime(2014) can be read as "some date within the year 2014", because only the year component is known.

A QDM 4 instant may only support a fixed precision format, not necessarily partial datetimes, and so it may have more precision than the source EHR provides.

CQL formally defines an instant to support a maximum precision of a millisecond, while QDM 4 doesn't mandate a support level but requires at least a minute's precision for temporal operators.

Comparing Instants

Both CQL and QDM 4 support comparison of 2 instants, asking whether one is before or after the other where the desired duration between them can be specified to a given precision; they also both support asking what the duration to a given precision is between 2 instants.

A significant way that CQL and QDM 4 differ is in how they handle unknowns.

Take the situation where one wants to compare or find the difference between 2 inputs and one of those inputs is null (the instant is missing).

This CQL results in null, meaning "I don't know", which is an accurate response:

  DateTime(2015,2,5) < null

In contrast, this QDM 4 results in false when either x or y are null, meaning it is explicitly denying that x is before y even though it actually has no way of knowing that:

  x Ends Before Start Of y

Managing Uncertainty

CQL has a significant core feature such that it can give useful insights on data even when the data is partially missing. Its semantics yield the intuitively correct results when comparing date/time values with varying levels of precision.

  DateTime(2012) < DateTime(2014, 2, 15)

This example returns true because even though the month and day of the first date are unknown, the year, 2012, is known to be less than the year of the second date, 2014. By contrast:

  DateTime(2015) < DateTime(2014, 2, 15)

The result in this example is false because the year, 2015, is not less than the year of the second date. And finally:

  DateTime(2014) < DateTime(2014, 2, 15)

The result in this example is null because the first date could be any date within the year 2014, so it could be less than the second date, but it could be greater.

Now consider a different kind of question, in 2 versions:

  define x: difference in days between DateTime(2015,2,5) and DateTime(2015,2,8)
  define y: difference in days between DateTime(2015,2,5) and DateTime(2015,2)

These are the answers that CQL gives:

  >> x [1:1] 3
  >> y [2:1] Interval [ -4, 23 ]

For x the question is straightforward, the difference in days of 2 instants precise to the day, gives an integer. For y the second instant is only precise to the month, and the answer CQL gives is an interval which includes all the integers for all the possible answers to that question; since we don't know which day of the month is being compared to, we get the answers for every day of the month at once; the result has a spread of the number of days in the month.

Both the comparison and difference scenarios above are enabled by the same CQL "uncertainty" feature.

QDM 4 doesn't support this feature.

Comparisons When No Calculation Unit Given

In QDM 4, when no threshold is defined in a measure phrase that compares timing between two elements, a common level of granularity needs to be established for comparisons within and across EHRs. For example, the following criterion does not indicate a unit of comparison:

  A starts before start of B

Consider the following data, which is precise to the second:

  A: 2012-01-01 11:00:01
  B: 2012-01-01 11:00:02
  C: A starts before B

In QDM 4, this comparison actually evaluates to false, since QDM implicitly ignores seconds.

CQL, in contrast, evaluates that to true as seconds are respected:

  define A: DateTime(2012,01,01,11,00,01)
  define B: DateTime(2012,01,01,11,00,02)
  define C: A < B

Calculating Interval Durations

When one wants to calculate the duration of time between 2 instants, there are two distinct conceptualizations of time measurement that may come into play.

The first conceptualization is a linear continuum with effectively infinite divisibility where an instant is a point on the line and a duration is the quantity of distance between 2 such points. For this view everything is typically expressed as just a real numeric quantity of seconds, either context-free in the case of a duration or relative to an epoch point for an instant. The internal time-keeping mechanism of a computer typically works this way, for example simply tracking the number of seconds since January 1st, 1970. Language for instants here tends to be that some event is "at" a particular time, where "at" language is more point-like.

The second conceptualization is a sequence of discrete buckets where every bucket has a name and may also be divided into other buckets. For this view everything is typically expressed first as integer counts of the bucket unit of years starting with 1 CE (there is no year zero CE), which are then divided into buckets of days or otherwise buckets of months which are then into buckets of days, each named starting with 1 (there is no zeroth month or zeroth day), and then buckets of hours, minutes, and seconds, those last 3 each named starting with zero. At the hours and smaller level, conceptualization can optionally be said to swing towards linear where we are more likely to think in terms of a real number quantity of time since the start of the current day. Language for instants here tends to be that some event is "on" a particular year/month/date, or "at" a time "on" a date, where "on" language is more bucket-like.

CQL and QDM 4 both have fundamentally bucket-oriented semantics. Their instants are defined as nested calendar year/month/etc buckets and their durations are defined as a quantity of buckets of particular kinds or combinations of larger and smaller buckets. However, CQL requires a smallest bucket size of a millisecond while QDM effectively treats systems as having a smallest bucket size of a minute, QDM so being less precise.

CQL supports the ability to compute "duration" and "difference" between two datetimes. For duration, the calculation is performed based on the calendar duration for the precision, the number of whole periods (bucket units) that fit between two datetimes. For difference, the calculation is performed by counting the number of boundaries of the specific precision (adjacent bucket boundaries) crossed between the two datetimes.

  months between X and Y

This example calculates the number of months between its arguments. For variable length precisions (months and years), the operation uses the calendar length of the precision to determine the number of periods. For example, the following expression returns 2:

  months between @2014-01-01 and @2014-03-01

This is because there are two whole calendar months between the two dates. Fractional months are not included in the result. This means that this expression also returns 2:

  months between @2014-01-01 and @2014-03-15

For difference, the calculation is concerned with the number of boundaries crossed:

  difference in months between X and Y

The above example calculates the number of month boundaries crossed between X and Y.

To illustrate the difference between the two calculations, consider the following examples:

  duration in months between @2014-01-31 and @2014-02-01
  difference in months between @2014-01-31 and @2014-02-01

The first example returns 0 because there is less than one calendar month between the two dates. The second example, however, returns 1, because a month boundary was crossed between the two dates.

In contrast to CQL with its 2 methods, QDM 4 only supports the behavior described as "duration", and not the behaviour described as "difference".

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