Skip to content

Cooking with CQL Q&A Index Queries in CQL Category

rhondaschwartz edited this page Apr 21, 2021 · 23 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.

Cross-Context Query for a Related Person: Looking at the solution for the connection of the mother and baby, is the capability for a cross-context query for a related person new to CQL? (Session 33 - 3/28/19)
  • Yes, it is new. We would like feedback in order to gain further understanding of the "operator" and how it is being used.
'from' vs 'with' with 2 sources: Is 'from' required when setting up a relationship between more than two sources and 'with' when setting up a relationship with only two sources? (Session 32 - 2/28/19)
  • Yes, that’s correct, ‘from’ is used to set up a “multi-source” query where you want to be able to talk about more than two sources at once. If you have a “single-source” query, you can use ‘with’ and ‘without’ to establish relationships between the primary source of the query and one other source at a time.
immune check inhibitor (ICI) therapies: How do you write an expression to return all immune check inhibitor (ICI) therapies, over a 12-month period, where the ICI administration dates are eight weeks or less between administration? (Session 52 - 3/25/21)
  • The intent is that the administrations are eight weeks or less apart. There is a string of data points that are no more than eight weeks apart until the endpoint. The endpoint could be where the ICI therapy is greater than eight weeks from the previous administration, the end of the one-year treatment period from the start of ICI therapy, or the end of the measurement period.

define "ICI Starts Within 8 weeks Interval":
  "ICI Therapy" Therapy
    without "ICI Therapy" PriorTherapy
      such that PriorTherapy !~ Therapy
        and PriorTherapy.relevantPeriod starts 57 days or more before day of start of Therapy.relevantPeriod

define "Start of ICI":
  Min("ICI Starts Within 8 weeks Interval" ICITherapy
      return start of ICITherapy.relevantPeriod
  )

define "End of ICI":
  Min({
    end of "Measurement Period", "Start of ICI" + 1 year, Max("ICI Starts Within 8 weeks Interval" Therapy
        return
        end of Therapy.relevantPeriod
    )}
  )

Multiple Source Queries with No Attributes: In multi-source queries, if an attribute is not mentioned specifically in the query, like the "method" attribute, will it still be included in the return? (Session 35 - 5/23/19)
  • Yes, if it is defined as an attribute in that source. For example, “method” is one of the attributes for “Physical Exam, Performed”. So, for the default behavior (when no return is specified), each element will have the same structure as the source it came from.
Multiple Source Queries with No Return Statement: When setting up relationships between multiple sources of data at the same time, what should you expect to see as the return with multi-source queries without specifying a return statement? For example, in CMS144v7: Consecutive Heart Rates less than 50 Inpatients, what would you expect to see as the return if not using a return statement? (Session 35 - 5/23/19)
  • Without a return statement, you’ll get a couple of results that have elements for each of the sources. So, you’ll get heart rate and a moderate or severe LVSDHF (left ventricular systolic dysfunction heart failure) inpatient encounter:

// Result Type:
{
  { HeartRate: { id: 'obs-1', code: ... }, ModerateOrSevereLVSDHFInpatientEncounter: { id: 'enc-1', code: ... } }     
  { HeartRate: { id: 'obs-2', code: ... }, ModerateOrSevereLVSDHFInpatientEncounter: { id: 'enc-1', code: ... } }     
  { HeartRate: { id: 'obs-3', code: ... }, ModerateOrSevereLVSDHFInpatientEncounter: { id: 'enc-2', code: ... } }     
  { HeartRate: { id: 'obs-4', code: ... }, ModerateOrSevereLVSDHFInpatientEncounter: { id: 'enc-2', code: ... } }     
  ...
}

If you don’t specify a return, then for each of the items in your “from,” you’ll get a result. The actual result of the query will be a list where you’ll have every combination of heart rate and moderate or severe LVSDHF inpatient encounter for this patient. A return is typically used with a multi-source query to pick out particular elements to be returned. The “where” clause eliminates combinations of those encounters so it would pull out the rows that don’t match that criteria. In the end, you only end up with rows that match the criteria, but since you didn’t specify the return, you will still get this list. Typically, if the result is used elsewhere, then a return would be included. If you’re only using it in something like an “exists”, then you don’t need to include a return.

Multiple Source Queries with Specified Attributes Returned: In multi-source queries, is it feasible to specify the type of attributes we want returned? (Session 35 - 5/23/19)
  • Yes, you can use return, it’s an arbitrary expression. So whatever you want to return from the “from,” you can.
Related Person Query: Is the related person query included in the FHIR Quality Measure Implementation Guide? (Session 33 - 3/28/19)
  • In the FHIR Quality Measure Implementation Guide May 2019 ballot content there is an example of this use case and we are seeking comments. Terminology is also being worked on within this example. There is nothing specific about this type of query in the base FHIR Clinical Reasoning measure specification.
Running CQL Queries: I am new to CQL, how do we run CQL queries - is it against C-CDA documents? (Session 31 - 1/31/19)
  • CQL can be used with any data model. In the examples in this series we are focused on using the Quality Data Model (QDM), which has a serialization as Quality Reporting Document Architecture (QRDA). QRDA is similar to C-CDA (they are both Health Level Seven International [HL7] V3 standards), but not the same. FHIR resources may also be used.
Substance Use Disorder (SUD) Encounter During Identification with Patient Age at Start: How should we express the criteria that a Substance Use Disorder (SUD) encounter in the "identification period" (6 months before through the first 6 months of the measurement period) is considered new if there are no other SUD encounters in the 60 days prior to the encounter, and that for each new SUD encounter, there is a baseline Quality of Life (QOL) assessment in the 14 days on or before the new SUD encounter, and a corresponding follow up QOL using the same assessment tool within 3 to 6 months of the new SUD encounter, and having a SUD encounter within 60 days of the follow up QOL assessment? (Session 34 - 4/25/19)
  • For each SUD encounter, there should be a baseline QOL assessment 14 days on or before the new SUD encounter and a follow up QOL assessment using the same QOL tool within 3-6 months and that had a SUD encounter within 60 days before that follow up QOL assessment, which could take place on the same day as the SUD encounter. Please see the example below of how this query should be expressed.

define "New SUD Encounter":
  "SUD Encounters" S
    without "SUD Encounters" S2 such that S2.relevantPeriod ends 60 days or less before start of S.relevantPeriod
    where S.relevantPeriod starts during "Identification Period"

    
define "Follow Up QOL Assessment":
	from
		"SUD Encounter During Identification Period with Patient Age at Start" NewSUDEncounter,
		"QOL Assessment" BaselineAssessment,
		"QOL Assessment" FollowupAssessment
		where (BaselineAssessment.authorDatetime 14 days or less before or on start of 
NewSUDEncounter.relevantPeriod
      or BaselineAssessment.authorDatetime during NewSUDEncounter.relevantPeriod)
      and FollowupAssessment.authorDatetime 3 months or more after start of NewSUDEncounter.relevantPeriod
			and FollowupAssessment.authorDatetime 6 months or less after start of 
NewSUDEncounter.relevantPeriod
      and exists ("SUD Encounter" SUDEncounter where SUDEncounter.relevantPeriod starts 60 days or less before or on
 FollowupAssessment.authorDatetime)
      and BaselineAssessment.code ~ FollowupAssessment.code
    return FollowupAssessment

TST Testing very 8 Weeks: When working with a measure that is looking for patients for whom thyroid stimulating hormone (TSH or T4) testing is performed at least once every 8 weeks while receiving immune check inhibitor (ICI) therapy for a maximum duration of 1 year from the start of ICI therapy, how can the data be sorted into relevant bins while looking for an abnormal TSH or T4 result? (Session 52 - 3/25/21)
  • For each TSH or T4 lab test performed, there should be a laboratory test result returned to the eight-week bin that the lab result is associated with. Lab results are assigned to a bin by the result date being within the bin boundaries. Bins start with the beginning of ICI therapy, indexed 1 through x, where bin 1 is from zero to eight weeks after the start of ICI therapy and x is the end of that eight-week period. The subsequent bin, e.g., bin 2, starts at the previous bin’s ending point and goes through the next eight-week period.

The bin intervals could be constructed as follows: Bin 1: 0 weeks <= x < 8 weeks Bin 2: 8 weeks <= x < 16 weeks Bin 3: 16 weeks <= x < 24 weeks Bin 4: 24 weeks <= x < 32 weeks Bin 5: 32 weeks <= x < 40 weeks Bin 6: 40 weeks <= x < 48 weeks Bin 7: 48 weeks <= x < 56 weeks

If the patient stops therapy before exactly 1 year from therapy start date, look for 1 TSH test within the bin for which the patient therapy end date falls. If the patient is still on therapy when they reach 1 year from therapy start date, look for a final TSH test within bin 7 (week 48-56). If the patient is on therapy for less than 8 weeks, look for 1 TSH test within bin 1.

define "ICI Therapy Bins":
   expand Interval[1, "Required Bins"]

Then use the bin numbers to construct 8-week intervals, beginning at the start of ICI:

define "ICI Therapy Bin Periods":
   "ICI Therapy Bins" Bin
     return Interval["Start of ICI" + ((Bin - 1) * 8 weeks), "Start of ICI" + (Bin * 8 weeks))

Then look for bin periods that contain the expected tests:

define "ICI Therapy Bin Periods with Required Test Lab":
   "ICI Therapy Bin Periods" Period
     with "Test Lab" LT
       such that LT.relevantDatetime during Period

Then in the numerator:

define "Required Bins":
  (weeks between "Start of ICI" and "End of ICI") div 8

define "Proposed Numerator":
   Count("ICI Therapy Bin Periods with Required Test Lab") = "Required Bins"

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