### CQL: Calculate Interval Start Source: https://cql.hl7.org/STU4/elm/schema/expression The Start operator calculates the starting point of an interval. It considers whether the interval's low boundary is closed or open. If the low boundary is closed, it uses the low value, defaulting to the minimum if null. If open, it uses the successor of the low value. Handles null intervals by returning null. ```cql Start(i) = if i.lowClosed then Coalesce(i.low, T.MinimumValue()) else Succ(i.low) ``` -------------------------------- ### Sort Exams by Start Time Ascending Source: https://cql.hl7.org/STU4/examples%5CExample.RelatedContextRetrieve-0.1.0 This ELM expression defines a 'sort' clause to order 'Exam' records in ascending order based on their start time. It uses 'ByExpression' with a 'Start' operator referencing 'relevantPeriod'. ```json { "type": "ByExpression", "direction": "asc", "expression": { "type": "Start", "operand": { "name": "relevantPeriod", "type": "IdentifierRef" } } } ``` -------------------------------- ### Get Patient Birth Date and Gender Source: https://cql.hl7.org/STU4/examples%5CChlamydiaScreening_CQM_UsingCommon Retrieves the 'birthDate' and 'gender' properties from the 'Patient' data source. This is a fundamental step for demographic analysis and patient stratification. ```json { "path" : "birthDate", "type" : "Property", "source" : { "name" : "Patient", "type" : "ExpressionRef" } }, { "type" : "InValueSet", "code" : { "path" : "gender", "type" : "Property", "source" : { "name" : "Patient", "type" : "ExpressionRef" } }, "valueset" : { "name" : "Female Administrative Sex", "libraryName" : "Common" } } ``` -------------------------------- ### Same As Operator Examples in CQL Source: https://cql.hl7.org/STU3/09-b-cqlreference The 'Same As' operator compares two date/time values for equality up to a specified precision. Examples demonstrate true, false, and null outcomes based on input values and precision. ```cql define SameAsTrue: @2012-01-01 same day as @2012-01-01 define SameAsFalse: @2012-01-01 same day as @2012-01-02 define UncertainSameAsIsNull: @2012-01-01 same day as @2012-01 define SameAsIsNull: @2012-01-01 same day as null ``` -------------------------------- ### Start of Interval Operator (CQL) Source: https://cql.hl7.org/STU3/09-b-cqlreference The 'start of' operator extracts the starting point of an interval. If the interval's low boundary is open, it returns the successor of the low value. If the low boundary is closed and not null, it returns the low value. For null intervals or null low values, the result is null. It handles different interval types T. ```cql start of(argument Interval) T ``` ```cql define StartOfInterval: start of Interval[1, 5] // 1 define StartIsNull: start of (null as Interval) ``` -------------------------------- ### Interval Operators (After, Before) Source: https://cql.hl7.org/STU4/09-b-cqlreference Documentation for the 'After' and 'Before' interval operators, which compare the start and end points of intervals or points against intervals. ```APIDOC ## Interval Operators ### 9.1. After #### Description The after operator for intervals returns true if the first interval starts after the second one ends. In other words, if the starting point of the first interval is greater than the ending point of the second interval. For the point-interval overload, the operator returns true if the given point is greater than the end of the interval. For the interval-point overload, the operator returns true if the given interval starts after the given point. This operator uses the semantics described in the Start and End operators to determine interval boundaries. If precision is specified and the point type is a Date, DateTime, or Time type, comparisons used in the operation are performed at the specified precision. If either argument is null, the result is null. #### Signature ``` after _precision_ (left Interval, right Interval) Boolean after _precision_ (left T, right Interval) Boolean after _precision_ (left Interval, right T) Boolean ``` #### Examples ``` define AfterIsTrue: 5 after Interval[1, 4] define AfterIsFalse: Interval[1, 4] after 5 define AfterIsNull: Interval[1, 4] after null ``` ### 9.2. Before #### Description The before operator for intervals returns true if the first interval ends before the second one starts. In other words, if the ending point of the first interval is less than the starting point of the second interval. For the point-interval overload, the operator returns true if the given point is less than the start of the interval. For the interval-point overload, the operator returns true if the given interval ends before the given point. This operator uses the semantics described in the Start and End operators to determine interval boundaries. If precision is specified and the point type is a Date, DateTime, or Time type, comparisons used in the operation are performed at the specified precision. If either argument is null, the result is null. #### Signature ``` before _precision_ (left Interval, right Interval) Boolean before _precision_ (left T, right Interval) Boolean before _precision_ (left interval, right T) Boolean ``` #### Examples ``` define BeforeIsTrue: 0 before Interval[1, 4] define BeforeIsFalse: Interval[1, 4] before 0 define BeforeIsNull: Interval[1, 4] before null ``` ``` -------------------------------- ### StartsWith Operator Source: https://cql.hl7.org/STU4/04-logicalspecification Checks if a string begins with a specified prefix. Returns true if it starts with the prefix, false otherwise. Returns true if the prefix is an empty string. Returns null if either argument is null. ```APIDOC ## StartsWith Operator ### Description Returns true if the given string starts with the given prefix. If the prefix is the empty string, the result is true. If either argument is null, the result is null. ### Method N/A (Operator) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "expression": "StartsWith('Hello World', 'Hello')" } ``` ### Response #### Success Response (N/A) - **Boolean** - True if the string starts with the prefix, false otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### CQL Context Declaration Examples Source: https://cql.hl7.org/STU4/02-authorsguide Demonstrates how to declare context in CQL, setting the scope for subsequent expressions. Supports Patient and Practitioner contexts. ```cql context Patient define Patient16To23AndFemale: AgeInYearsAt(start of MeasurementPeriod) >= 16 and AgeInYearsAt(start of MeasurementPeriod) < 24 and Patient.gender in "Female Administrative Sex" ``` ```cql context Practitioner define Encounters: ["Encounter": "Inpatient Encounter"] ``` -------------------------------- ### Check if String Starts With Prefix (CQL) Source: https://cql.hl7.org/STU3/elm/schema/expression The StartsWith operator checks if a string begins with a specified prefix. It returns true if it does, and true if the prefix is an empty string. Returns null if either argument is null. ```cql define "Starts With Prefix": StartsWith(MyString, MyPrefix) ``` -------------------------------- ### CQL Date/Time Interval Representation Source: https://cql.hl7.org/STU4/02-authorsguide Shows how to create intervals using date and time values in CQL. The examples demonstrate the use of specific timestamps and date-only values, highlighting how boundaries are interpreted. ```cql Interval[@2014-01-01T00:00:00.0, @2015-01-01T00:00:00.0) ``` ```cql Interval[@2014-01-01, @2015-01-01) ``` -------------------------------- ### Reference Constructs from Included Library Source: https://cql.hl7.org/STU3/02-authorsguide This example demonstrates how to reference constructs (like 'ConditionsIndicatingSexualActivity') defined in an included library ('CMS153_Common') using its assigned alias ('Common'). The syntax uses a qualified identifier with a dot separator. ```cql define SexuallyActive: exists (Common.ConditionsIndicatingSexualActivity) or exists (Common.LaboratoryTestsIndicatingSexualActivity) ``` ```cql define SexuallyActive: exists (CMS153_Common.ConditionsIndicatingSexualActivity) or exists (CMS153_Common.LaboratoryTestsIndicatingSexualActivity) ``` -------------------------------- ### CQL Retrieve with Condition Context Source: https://cql.hl7.org/STU4/02-authorsguide This example demonstrates retrieving Condition resources within a specific CQL context. It shows how to filter conditions based on their display name and a temporal condition, emphasizing the role of MeasurementPeriod. ```cql Context Patient define "Acute Pharyngitis Conditions": [Condition: "Acute Pharyngitis"] C where C.onsetDateTime during MeasurementPeriod ``` -------------------------------- ### Calculate Patient Age and Compare Source: https://cql.hl7.org/STU4/examples%5CChlamydiaScreening_CQM_UsingCommon Calculates the age of a patient at a specific 'MeasurementPeriod' and compares it against literal integer values (16 and 24). This is useful for age-based cohort definitions. ```json { "valueType" : "{urn:hl7-org:elm-types:r1}Integer", "value" : "16", "type" : "Literal" } ] }, { "type" : "Less", "operand" : [ { "precision" : "Year", "type" : "CalculateAgeAt", "operand" : [ { "path" : "birthDate", "type" : "Property", "source" : { "name" : "Patient", "type" : "ExpressionRef" } }, { "type" : "Start", "operand" : { "name" : "MeasurementPeriod", "type" : "ParameterRef" } } ] }, { "valueType" : "{urn:hl7-org:elm-types:r1}Integer", "value" : "24", "type" : "Literal" } ] } ] } ``` -------------------------------- ### PositionOf Operator for Strings Source: https://cql.hl7.org/STU4/elm/schema/expression Finds the 0-based starting index of a pattern within a string. Returns -1 if the pattern is not found. Returns null if either the string or the pattern is null. ```cql define "Position Of Pattern": PositionOf('abcdefabc', 'abc') // 0 define "Position Not Found": PositionOf('abcdef', 'xyz') // -1 ``` -------------------------------- ### Today Operator Source: https://cql.hl7.org/STU3/09-b-cqlreference Returns the date of the start timestamp of the current evaluation request. ```APIDOC ## Today Operator ### Description Returns the date of the start timestamp associated with the evaluation request. ### Method Operator ### Endpoint N/A (In-line operation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cql Today() ``` ### Response #### Success Response (200) - **Result** (Date) - The current date. #### Response Example ```json { "Result": "2023-10-27" } ``` ``` -------------------------------- ### Check for Conditions Indicating Sexual Activity Source: https://cql.hl7.org/STU4/examples%5CChlamydiaScreening_CQM_UsingCommon Determines if a patient has any 'Conditions Indicating Sexual Activity' recorded within the 'MeasurementPeriod'. It queries for 'onsetDateTime' and checks for overlaps. ```json { "type" : "Exists", "operand" : { "type" : "Query", "source" : [ { "alias" : "C", "expression" : { "name" : "Conditions Indicating Sexual Activity", "libraryName" : "Common", "type" : "ExpressionRef" } } ], "relationship" : [ ], "where" : { "type" : "Overlaps", "operand" : [ { "lowClosed" : true, "highClosed" : true, "type" : "Interval", "low" : { "path" : "onsetDateTime", "scope" : "C", "type" : "Property" }, "high" : { "path" : "abatementDate", "scope" : "C", "type" : "Property" } }, { "name" : "MeasurementPeriod", "type" : "ParameterRef" } ] } } } ``` -------------------------------- ### CQL Unit Interval and Point Extraction Source: https://cql.hl7.org/STU4/02-authorsguide Demonstrates the creation and manipulation of unit intervals in CQL, which contain a single point. The 'point from' operator is shown for extracting this single value, with examples of valid and invalid usage. ```cql Interval[1, 1] // Unit interval containing only the point 1 ``` ```cql point from Interval[1, 1] // Results in 1 ``` ```cql point from Interval[1, 5] // Invalid extractor, this will result in an error ``` -------------------------------- ### CQL Invalid Interval Construction Source: https://cql.hl7.org/STU4/02-authorsguide Provides examples of invalid interval constructions in CQL that will result in run-time errors. This includes cases where the end boundary is less than the start boundary or where boundary inclusivity creates a conflict. ```cql Interval[1, -1] // Invalid interval, this will result in an error ``` ```cql Interval[1, 1) // Invalid interval, conflicting to say it both includes and excludes 1 ``` -------------------------------- ### CQL Ratio Operators: Numerator and Denominator Source: https://cql.hl7.org/STU3/02-authorsguide Explains how to access the numerator and denominator components of a Ratio in CQL. It also shows the definition of a ratio and mentions supported equality operators and conversion functions. ```cql define "Titre Ratio": 1:128 define "Titre Numerator": "Titre Ratio".numerator define "Titre Denominator": "Titre Ratio".denominator ``` -------------------------------- ### Retrieve Data from Related Context (Mother's Record) in CQL Source: https://cql.hl7.org/examples%5CExample.RelatedContextRetrieve-0.1.0 This snippet shows how to define a 'Mother' related person and then perform a retrieve operation within the 'Mother' context to get specific data, like an 'Estimated Due Date Exam'. It utilizes the '->' syntax for related-context retrieves and specifies sorting and filtering criteria. ```cql library Example.RelatedContextRetrieve version '0.1.0' using QDM version '5.5' codesystem "SNOMED": '1.2.3.4.5' valueset "Estimated Due Date Exam": 'TBD' valueset "Live Delivery": 'TBD' code "Mother Relationship": 'Mother' from "SNOMED" context Patient define "Mother": singleton from (["Related Person": "Mother Relationship"]) define "Estimated Due Date": Last( ["Mother" -> "Physical Exam, Performed": "Estimated Due Date Exam"] Exam where Exam.relevantPeriod ends 1 year on or before "Birth Date" sort by start of relevantPeriod ).result as DateTime define "Gestational Age in Days at Birth": (280 - (duration in days between "Estimated Due Date" and "Birth Date")) div 7 define "Birth Date": start of Last( ["Encounter, Performed": "Live Delivery"] Delivery sort by start of relevantPeriod ).relevantPeriod ``` -------------------------------- ### Substring Operator Source: https://cql.hl7.org/STU4/04-logicalspecification Extracts a portion of a string based on a starting index and an optional length. If length is omitted, it extracts to the end of the string. Returns null if the string or start index is null, or if the start index is out of range. ```APIDOC ## Substring Operator ### Description Returns the string within stringToSub, starting at the 0-based index startIndex, and consisting of length characters. If length is omitted, the substring returned starts at startIndex and continues to the end of stringToSub. If stringToSub or startIndex is null, or startIndex is out of range, the result is null. ### Method N/A (Operator) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "expression": "Substring(stringToSub: 'Hello World', startIndex: 6, length: 5)" } ``` ### Response #### Success Response (N/A) - **String** - The extracted substring. - **Null** - If stringToSub or startIndex is null, or startIndex is out of range. #### Response Example ```json { "result": "World" } ``` ``` -------------------------------- ### Mathematical Operators Source: https://cql.hl7.org/STU3/09-b-cqlreference Documentation for mathematical operators like Sum. ```APIDOC ## Sum Operator ### Description The Sum operator returns the sum of non-null elements in the source. If the source contains no non-null elements, null is returned. If the list is null, the result is null. ### Signatures - `Sum(argument List) Integer` - `Sum(argument List) Decimal` - `Sum(argument List) Quantity` ### Examples ```cql define DecimalSum: Sum({ 1.0, 2.0, 3.0, 4.0, 5.0 }) // Result: 15.0 define QuantitySum: Sum({ 1.0 'mg', 2.0 'mg', 3.0 'mg', 4.0 'mg', 5.0 'mg' }) // Result: 15.0 'mg' define SumIsNull: Sum({ null as Quantity, null as Quantity, null as Quantity }) // Result: null define SumIsAlsoNull: Sum(null as List) // Result: null ``` ``` -------------------------------- ### Substring Operator in CQL Source: https://cql.hl7.org/STU4/04-logicalspecification The Substring operator extracts a portion of a string starting at a specified index and with an optional length. If length is omitted, it extracts to the end of the string. Returns null if the main string or start index is null, or if the start index is out of range. ```cql define "Substring Example": Substring("HelloWorld", 5, 5) define "Substring To End": Substring("HelloWorld", 5) ``` -------------------------------- ### OverlapsBefore Interval Operator Logic in CQL Source: https://cql.hl7.org/STU4/elm/schema/expression The OverlapsBefore operator determines if the first interval begins before and intersects with the second. It returns true if the start of the first interval is earlier than the start of the second, and its end is on or after the start of the second. Precision and null handling are consistent with other interval operators. ```cql // OverlapsBefore(i1, i2) = Start(i1) < Start(i2) and End(i1) >= Start(i2) ``` -------------------------------- ### CQL Quantity Operators: Unit and Value Access Source: https://cql.hl7.org/STU3/02-authorsguide Illustrates how to access the unit and value components of a Quantity in CQL. It also shows a simplified syntax for quantity comparisons, leveraging CQL's direct support for arithmetic and comparison operators on quantities, including implicit unit conversion. ```cql define "Is Tall Using Components": height.units = 'm' and height.value > 2 define "Is Tall Direct Comparison": height > 2 'm' ``` -------------------------------- ### Starts Interval Operator Logic in CQL Source: https://cql.hl7.org/STU4/elm/schema/expression The Starts operator verifies if the first interval begins exactly at the same point as the second interval and is contained within it. It returns true if the start points are equal and the end point of the first is less than or equal to the end point of the second. Precision and null inputs are considered. ```cql // Starts(i1, i2) = Start(i1) = Start(i2) and End(i1) <= End(i2) ``` -------------------------------- ### Substring: Extract Part of a String in CQL Source: https://cql.hl7.org/STU3/09-b-cqlreference The Substring operator extracts a portion of a string. It can take a start index and an optional length. If length is omitted, it extracts to the end of the string. Null is returned if the string or start index is null, or if the start index is out of range. ```cql define SubstringWithoutLength: Substring('CQL is awesome', 7) // 'awesome' define SubstringWithLength: Substring('CQL is awesome', 7, 3) // 'awe' define SubstringIsNull: Substring('CQL is awesome', null) define SubstringIsAlsoNull: Substring('CQL is awesome', 14) ``` -------------------------------- ### Calculate Bounded Difference with Conditional Logic in ELM Source: https://cql.hl7.org/examples%5CCMS179v2_CQM This ELM code defines a 'boundedDifference' calculation using nested 'If' conditions. It checks if the 'result' is greater than or equal to the start of the therapeutic range and uses 'Or' to evaluate if the start result is greater than the range's end or the end result is less than the range's start. This is useful for quantifying deviations within a defined acceptable variance. ```json { "name": "boundedDifference", "value": { "type": "If", "condition": { "asType": "{urn:hl7-org:elm-types:r1}Boolean", "type": "As", "operand": { "type": "GreaterOrEqual", "operand": [ { "path": "result", "type": "Property", "source": { "path": "endResult", "scope": "X", "type": "Property" } }, { "path": "result", "type": "Property", "source": { "path": "startResult", "scope": "X", "type": "Property" } } ] }, "asTypeSpecifier": { "name": "{urn:hl7-org:elm-types:r1}Boolean", "type": "NamedTypeSpecifier" } }, "then": { "type": "If", "condition": { "asType": "{urn:hl7-org:elm-types:r1}Boolean", "type": "As", "operand": { "type": "Or", "operand": [ { "type": "Greater", "operand": [ { "path": "result", "type": "Property", "source": { "path": "startResult", "scope": "X", "type": "Property" } }, { "type": "End", "operand": { "name": "TherapeuticRange", "type": "ExpressionRef" } } ] }, { "type": "Less", "operand": [ { "path": "result", "type": "Property", "source": { "path": "endResult", "scope": "X", "type": "Property" } }, { "type": "Start", "operand": { "name": "TherapeuticRange", "type": "ExpressionRef" } } ] } ] }, "asTypeSpecifier": { "name": "{urn:hl7-org:elm-types:r1}Boolean", "type": "NamedTypeSpecifier" } } } } } ``` -------------------------------- ### CQL Date and Time Comparisons with Varying Precision Source: https://cql.hl7.org/STU3/02-authorsguide Demonstrates how CQL handles date comparisons when components are missing. It illustrates that comparisons may result in null if there's ambiguity due to unspecified precision levels. The examples show comparisons where year is known, but month/day are not. ```cql Date(2014) Date(2012) < Date(2014, 2, 15) Date(2015) < Date(2014, 2, 15) Date(2014) < Date(2014, 2, 15) ``` -------------------------------- ### Date Constructor Source: https://cql.hl7.org/STU3/09-b-cqlreference Constructs a Date value from year, month, and day components. All specified components must be valid and adhere to the precision order. ```APIDOC ## Date Constructor ### Description Constructs a Date value from the given year, month, and day components. At least one component must be specified, and no component may be specified at a precision below an unspecified precision (e.g., if day is specified, month and year must also be specified). ### Method Constructor ### Endpoint N/A (Operator within CQL language) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cql define DateValid: Date(2012, 1, 1) define DateInvalid: Date(2012, null, 1) ``` ### Response #### Success Response (Date) - **Date**: A Date value constructed from the provided components. #### Response Example ```json { "DateValid": "2012-01-01", "DateInvalid": null } ``` ``` -------------------------------- ### Interval Meets Operators Source: https://cql.hl7.org/STU3/09-b-cqlreference The meets operator returns true if the first interval ends immediately before the second interval starts, or if the first interval starts immediately after the second interval ends. 'meets before' and 'meets after' are specific variations. ```APIDOC ## Interval Meets Operators ### Description The `meets` operator returns true if the first interval ends immediately before the second interval starts, or if the first interval starts immediately after the second interval ends. The `meets before` operator returns true if the first interval ends immediately before the second interval starts, while the `meets after` operator returns true if the first interval starts immediately after the second interval ends. Precision can be specified for date/time types. ### Method N/A (This is a function/operator) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ``` define MeetsIsTrue: Interval[6, 10] meets Interval[0, 5] define MeetsBeforeIsTrue: Interval[-5, -1] meets before Interval[0, 5] define MeetsAfterIsFalse: Interval[6, 10] meets after Interval[0, 7] ``` ### Response #### Success Response (Boolean) - **Result** (Boolean) - True if the intervals meet according to the specified condition, false otherwise. #### Response Example ```json { "Result": true } ``` ``` -------------------------------- ### CQL Includes Operator for Intervals Source: https://cql.hl7.org/STU3/elm/schema/expression The Includes operator for intervals returns true if the first interval completely includes the second. It checks if the start of the first interval is less than or equal to the start of the second, and the end of the first is greater than or equal to the end of the second. Precision can be specified for date/time types. ```cql Includes(i1 Interval, i2 Interval) : { Start(i1) <= Start(i2) and End(i1) >= End(i2) } ``` -------------------------------- ### CQL Interval Equality Example Source: https://cql.hl7.org/STU4/02-authorsguide Shows the equality comparison for interval data types in CQL. Intervals are considered equal if they share the same point type and define the exact same range of values. This comparison accounts for the inclusivity/exclusivity of interval boundaries. ```cql define "Interval Equality Test": Interval[1,5] = Interval[1,6) ``` -------------------------------- ### Ends Interval Operator Logic in CQL Source: https://cql.hl7.org/STU4/elm/schema/expression The Ends operator checks if the first interval terminates exactly at the same point as the second interval and encompasses it. It returns true if the start point of the first is greater than or equal to the start point of the second, and their end points are equal. Precision and null inputs are handled. ```cql // Ends(i1, i2) = Start(i1) >= Start(i2) and End(i1) = End(i2) ``` -------------------------------- ### Interval Ends Operator Source: https://cql.hl7.org/STU3/09-b-cqlreference The 'ends' operator checks if the first interval ends the second. It returns true if the start of the first interval is greater than or equal to the start of the second, and the end of the first is equal to the end of the second. Precision can be specified for date/time types. ```APIDOC ## Interval Ends Operator ### Description Checks if the first interval ends the second. It returns true if the start of the first interval is greater than or equal to the start of the second, and the end of the first is equal to the end of the second. Precision can be specified for date/time types. Returns null if either argument is null. ### Method FUNCTION ### Endpoint N/A (This is a function-based operator) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **_precision_** (optional) - Specifies the precision for date/time comparisons. - **left** (Interval) - The first interval. - **right** (Interval) - The second interval. ### Request Example ```cql define EndsIsTrue: Interval[0, 5] ends Interval[-1, 5] define EndsIsFalse: Interval[-1, 7] ends Interval[0, 7] define EndsIsNull: Interval[1, 5] ends null ``` ### Response #### Success Response (Boolean) - **Result** (Boolean) - True if the first interval ends the second, false otherwise. #### Response Example ```json { "Result": true } ``` ``` -------------------------------- ### CQL List Equality Example Source: https://cql.hl7.org/STU4/02-authorsguide Illustrates the equality comparison for list data types in CQL. Lists are equal if they contain the exact same elements in the identical order. The comparison is element-by-element and sensitive to the sequence of items within the lists. ```cql define "List Equality Test": { 1, 2, 3, 4, 5 } = { 1, 2, 3, 4, 5 } ``` -------------------------------- ### StartsWith Operator in CQL Source: https://cql.hl7.org/STU4/04-logicalspecification The StartsWith operator returns true if a string begins with a specified prefix. It returns true if the prefix is an empty string. If either argument is null, the result is null. This is useful for prefix matching and validation. ```cql define "Starts With Hello": StartsWith("Hello World", "Hello") define "Starts With Empty": StartsWith("Anything", "") ``` -------------------------------- ### CQL IncludedIn Operator for Intervals Source: https://cql.hl7.org/STU3/elm/schema/expression The IncludedIn operator for intervals returns true if the first interval is completely included within the second. It verifies if the start of the first interval is greater than or equal to the start of the second, and the end of the first is less than or equal to the end of the second. Precision can be specified for date/time types. ```cql IncludedIn(i1 Interval, i2 Interval) : { Start(i1) >= Start(i2) and End(i1) <= End(i2) } ``` -------------------------------- ### CQL Date/Time Interval Duration and Difference Source: https://cql.hl7.org/STU4/02-authorsguide Calculates the duration and difference between the start and end points of date/time intervals. 'duration in days of X' returns the number of whole days, while 'difference in days of X' returns the number of day boundaries crossed. These are equivalent to specifying the duration/difference between the start and end of the interval. ```cql duration in days of X difference in days of X duration in days between start of X and end of X difference in days between start of X and end of X ``` -------------------------------- ### DateTime Constructor Source: https://cql.hl7.org/STU3/09-b-cqlreference Constructs a DateTime value from year, month, day, hour, minute, second, millisecond, and timezoneOffset components. Components must be specified in order of precision. ```APIDOC ## DateTime Constructor ### Description Constructs a DateTime value from the given components. At least one component other than timezoneOffset must be specified, and no component may be specified at a precision below an unspecified precision. If timezoneOffset is not specified, it defaults to the evaluation request's timezone offset. ### Method Constructor ### Endpoint N/A (Operator within CQL language) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cql define DateValid: DateTime(2012, 1, 1, 12, 30, 0, 0, -7) define DateInvalid: DateTime(2012, 1, 1, 12, null, 0, 0, -7) ``` ### Response #### Success Response (DateTime) - **DateTime**: A DateTime value constructed from the provided components. #### Response Example ```json { "DateValid": "2012-01-01T12:30:00.000-07:00", "DateInvalid": null } ``` ``` -------------------------------- ### Calculate Patient Age at Measurement Period (CQL) Source: https://cql.hl7.org/examples%5CChlamydiaScreening_CQM_UsingCommon Calculates the age of a patient at the start of the measurement period. It compares the patient's birth date against the measurement period's start date. This expression is crucial for age-related criteria in clinical quality measures. ```cql define "Age In Years": AgeInYearsAt(MeasurementPeriodStart) ``` -------------------------------- ### CQL Code Declarations Source: https://cql.hl7.org/STU4/02-authorsguide Defines how to declare codes within CQL, specifying their identifier, display name, code system, and version. These declarations can be referenced directly in expressions or used within retrieve statements. ```cql codesystem "SNOMED-CT": 'http://loinc.org' code "Blood Pressure": '55284-4' from "LOINC" display 'Blood pressure' code "Systolic Blood Pressure": '8480-6' from "LOINC" display 'Systolic blood pressure' code "Diastolic Blood Pressure": '8462-4' from "LOINC" display 'Diastolic blood pressure' ``` -------------------------------- ### CQL: Timing Relationships with Duration Offsets Source: https://cql.hl7.org/STU4/02-authorsguide Illustrates how to incorporate time durations to offset timing relationship comparisons between intervals. This allows for specifying relationships with a specific time buffer, such as '3 days before'. ```cql X starts 3 days before start Y X starts 3 days or less before start Y X starts less than 3 days before start Y X starts 3 days or more before start Y X starts more than 3 days before start Y ``` -------------------------------- ### Meets Interval Operator Source: https://cql.hl7.org/STU4/09-b-cqlreference The meets operator checks if two intervals meet. The meets before operator checks if the first interval ends immediately before the second starts, and meets after checks if the first interval starts immediately after the second ends. Precision can be specified for Date, DateTime, or Time types. ```APIDOC ## Meets Interval Operator ### Description The meets operator returns true if the first interval ends immediately before the second interval starts, or if the first interval starts immediately after the second interval ends. The meets before operator returns true if the first interval ends immediately before the second interval starts, while the meets after operator returns true if the first interval starts immediately after the second interval ends. Precision can be specified for Date, DateTime, or Time types. ### Signature ``` meets _precision_ (left Interval, right Interval) Boolean meets before _precision_ (left Interval, right Interval) Boolean meets after _precision_ (left Interval, right Interval) Boolean ``` ### Examples ``` define MeetsIsTrue: Interval[6, 10] meets Interval[0, 5] define MeetsBeforeIsTrue: Interval[-5, -1] meets before Interval[0, 5] define MeetsAfterIsFalse: Interval[6, 10] meets after Interval[0, 7] define MeetsIsNull: Interval[6, 10] meets (null as Interval) ``` ``` -------------------------------- ### CQL Interval 'ends' Operator Source: https://cql.hl7.org/STU3/09-b-cqlreference The 'ends' operator returns true if the first interval ends the second. It checks if the start of the first interval is greater than or equal to the start of the second, and their end points are equal. Precision can be specified for date/time types. Returns null if either argument is null. ```cql define EndsIsTrue: Interval[0, 5] ends Interval[-1, 5] define EndsIsFalse: Interval[-1, 7] ends Interval[0, 7] define EndsIsNull: Interval[1, 5] ends null ``` -------------------------------- ### CQL: Check for Proper Interval Containment Source: https://cql.hl7.org/STU4/elm/schema/expression The ProperContains operator returns true if an interval strictly contains a point, meaning the point is greater than the start and less than the end. It supports overloads for List/T and Interval/T. For intervals, it relies on the Start and End operators for comparison. Precision can be specified for date/time types. Returns null if either argument is null. ```cql ProperContains(i, p) = p > Start(i) and p < End(i) ``` -------------------------------- ### Take Operator Source: https://cql.hl7.org/STU3/09-b-cqlreference Returns the first `number` elements from a given list. Handles cases where the list has fewer elements than requested, or when `number` is null or non-positive. ```APIDOC ## Take ### Description Returns the first `number` elements from the given list. If the list has fewer elements than `number`, the result contains only the available elements. Returns an empty list if `number` is null or less than or equal to 0. Returns null if the source list is null. ### Method Operator ### Endpoint N/A (Operator) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **argument** (List) - Required - The list to take elements from. - **number** (Integer) - Optional - The number of elements to take from the beginning of the list. ### Request Example ``` { "argument": [1, 2, 3, 4], "number": 2 } ``` ### Response #### Success Response (List) - **result** (List) - A new list containing the first `number` elements. #### Response Example ``` { "result": [1, 2] } ``` **Note**: If `number` is null or less than or equal to 0, an empty list is returned. If `argument` is null, the result is null. ``` -------------------------------- ### Same As Interval Operator Source: https://cql.hl7.org/STU3/09-b-cqlreference Determines if two intervals have the same start and end points. Comparisons are made at a specified precision, with default behavior for date/time types starting from years down to the finest specified precision. For date/time types, precision levels range from year to millisecond. Null arguments yield a null result. ```cql // Example demonstrating Same As operator usage would go here. // The provided text describes the operator but does not include specific CQL examples for it. ``` -------------------------------- ### Retrieve Diagnostic Order (Lab Tests During Pregnancy) - CQL Source: https://cql.hl7.org/examples%5CChlamydiaScreening_CDS_Debug This CQL example uses the 'Exists' operator to determine if a 'DiagnosticOrder' for 'Lab Tests During Pregnancy' exists. It targets the 'item[].code' property and uses a ValueSetRef to identify the relevant diagnostic orders. ```cql exists ( Retrieve ( localId: "60", locator: "39:12-39:62", dataType: "{http://hl7.org/fhir}DiagnosticOrder", templateId: "diagnosticorder-qicore-qicore-diagnosticorder", codeProperty: "item[].code", type: "Retrieve", resultTypeSpecifier: { type: "ListTypeSpecifier", elementType: { name: "{http://hl7.org/fhir}DiagnosticOrder", type: "NamedTypeSpecifier" } }, codes: { name: "Lab Tests During Pregnancy", type: "ValueSetRef" } ) ) ``` -------------------------------- ### Interval Includes Operator Source: https://cql.hl7.org/STU4/09-b-cqlreference The includes operator checks if one interval completely contains another interval or a point. It returns true if the start of the first interval is less than or equal to the start of the second, and the end of the first interval is greater than or equal to the end of the second. For point overloads, it acts as a 'contains' operator. ```APIDOC ## Interval Includes Operator ### Description Checks if the `left` interval completely includes the `right` interval or a point. ### Method N/A (Operator) ### Endpoint N/A (Operator) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cql define IncludesIsTrue: Interval[-1, 5] includes Interval[0, 5] define IncludesIsFalse: Interval[-1, 5] includes 6 define IncludesIsNull: Interval[-1, 5] includes null ``` ### Response #### Success Response (Boolean) Returns `true` if the `left` interval includes the `right` interval or point, `false` otherwise. Returns `null` if either argument is `null`. #### Response Example ```json // Example for IncludesIsTrue: true // Example for IncludesIsFalse: false // Example for IncludesIsNull: null ``` ``` -------------------------------- ### CQL Interval Comparison Operators Source: https://cql.hl7.org/STU4/02-authorsguide Compares two interval values using operators like 'meets', 'overlaps', 'before', 'after', 'includes', 'included by', 'starts', 'started by', 'ends', 'ended by'. These operators return true if the specified relationship holds between the intervals, null if either interval is null, and false otherwise. Intervals must be of the same point type for comparison. ```cql // Example: X meets Y X meets Y // Example: X overlaps Y X overlaps Y // Example: X before Y X before Y // Example: X after Y X after Y // Example: X includes Y X includes Y // Example: X included by Y X included by Y // Example: X starts Y X starts Y // Example: X started by Y X started by Y // Example: X ends Y X ends Y // Example: X ended by Y X ended by Y ``` -------------------------------- ### CQL Date, DateTime, and Time Literals Source: https://cql.hl7.org/STU3/02-authorsguide Demonstrates the syntax for representing Date, DateTime, and Time values in CQL using ISO-8601 format prefixed with an '@' symbol. Supports various precisions and timezone specifications. ```cql // DateTime Examples @2014-01-25T14:30 @2014-01-25T14:30:14.559 // Date Example @2014-01-25 // Time Examples @T12:00:00.0Z @T14:30:14.559-07:00 ```