-
Notifications
You must be signed in to change notification settings - Fork 124
CQL Serialization
Bryn Rhodes edited this page May 5, 2024
·
1 revision
This page documents a proposed CQL serialization format using JSON serialization as specified in rfc8259.
- Boolean
- Integer
- Long
- Decimal
- String
- Date
- DateTime
- Time
- Quantity
- Ratio
- Vocabulary
- CodeSystem
- ValueSet
- Code
- Concept
- Interval
- List
- Tuple
- Any JSON-mapped primitive type can be represented directly as the JSON serialization:
- Boolean
- Integer
- Decimal (with the exception that a decimal SHALL be present)
- String
- Any value can be represented as a class value:
- A JSON object with a nominated element
@type
that is the CQL type specifier for the type of the value- For tuple types specifically, the @type element is optional, and if specified, does not have to be the full tuple type, it can be just "Tuple"
- For primitive types, a nominated element
value
that is the JSON-mapped primitive value, or a String that is the CQL literal for the value - For structured types, the set of elements in the structure
- For Interval types,
low
,lowClosed
,high
, andhighClosed
- For Ratio types,
numerator
, anddenominator
- For Quantity types,
value
andunit
- A JSON object with a nominated element
define CQLBooleanExample: true
true
or as a class:
{
"@type": "System.Boolean",
"value": true
}
codesystem ExampleCodeSystem: 'http://hl7.org/fhir/uv/cql/CodeSystem/example'
code ExampleCode: 'example-code' from ExampleCodeSystem
define CQLCodeExample: ExampleCode
{
"@type": "System.Code",
"code": "example-code",
"system": "http://hl7.org/fhir/uv/cql/CodeSystem/example"
}
codesystem ExampleCodeSystem: 'http://hl7.org/fhir/uv/cql/CodeSystem/example'
define CQLCodeSystemExample: ExampleCodeSystem
{
"@type": "System.CodeSystem",
"id": "http://hl7.org/fhir/uv/cql/CodeSystem/example",
"name": "ExampleCodeSystem"
}
codesystem ExampleCodeSystem: 'http://hl7.org/fhir/uv/cql/CodeSystem/example'
code ExampleCode: 'example-code' from ExampleCodeSystem
concept ExampleConcept: { ExampleCode }
define CQLConceptExample: ExampleConcept
{
"@type": "System.Concept",
"codes": [
{
"@type": "System.Code",
"code": "example-code",
"system": "http://hl7.org/fhir/uv/cql/CodeSystem/example"
}
]
}
define CQLDateExample: @2024-01-01
{
"@type": "System.Date",
"value": "@2024-01-01"
}
define CQLDateTimeExample: @2024-01-01T10:30:00Z
{
"@type": "System.DateTime",
"value": "@2024-01-01T10:30:00Z"
}
define CQLDecimalExample: 10.0
10.0
NOTE: When rendered as a JSON-mapped primitive, decimal values SHALL include a decimal point
or as a structured value:
{
"@type": "System.Decimal",
"value": 10.0
}
define CQLLongExample: 10L
{
"@type": "System.Long",
"value": 10
}
define CQLIntegerExample: 10
10
or as a class:
{
"@type": "System.Integer",
"value": 10
}
define CQLQuantityExample: 10 'mg'
{
"@type": "System.Quantity",
"value": 10,
"unit": "mg"
}
define CQLRatioExample: 5 'mg' : 10 'mg'
{
"@type": "System.Ratio",
"numerator":
{
"@type": "System.Quantity",
"value": 5,
"unit": "mg"
},
"denominator":
{
"@type": "System.Quantity",
"value": 10,
"unit": "mg"
}
}
define CQLStringExample: 'John'
"John"
or as a class:
{
"@type": "System.System",
"value": "John"
}
define CQLTimeExample: @T10:30:00
{
"@type": "System.Time",
"value": "@T10:30:00"
}
valueset ExampleValueSet: 'http://hl7.org/fhir/uv/cql/ValueSet/example'
define CQLValueSetExample: ExampleValueSet
{
"@type": "System.ValueSet",
"id": "http://hl7.org/fhir/uv/cql/ValueSet/example",
"name": "ExampleValueSet"
}
parameter ExampleVocabulary Vocabulary default ExampleValueSet
define CQLVocabularyExample: ExampleVocabulary
{
"@type": "System.Vocabulary",
"id": "http://hl7.org/fhir/uv/cql/ValueSet/example",
"name": "ExampleValueSet"
}
define CQLDateIntervalExample: Interval[@2024-01-01, @2024-01-31]
{
"@type": "Interval<System.Date>",
"low":
{
"@type": "System.Date",
"value": "@2024-01-01"
},
"lowClosed": true
"high":
{
"@type": "System.Date",
"value": "@2024-01-31"
},
"highClosed": true
}
define CQLDateTimeIntervalExample: Interval[@2024-01-01T10:30:00Z, @2024-01-31T10:30:00Z]
{
"@type": "Interval<System.DateTime>",
"low":
{
"@type": "System.DateTime",
"value": "@2024-01-01T10:30:00Z"
},
"lowClosed": true
"high":
{
"@type": "System.DateTime",
"value": "@2024-01-31T10:30:00Z"
},
"highClosed": true
}
define CQLTimeIntervalExample: Interval[@T10:30:00, @T11:30:00]
{
"@type": "Interval<System.Time>",
"low":
{
"@type": "System.Time",
"value": "@T10:30:00"
},
"lowClosed": true
"high":
{
"@type": "System.Time",
"value": "@T11:30:00"
},
"highClosed": true
}
define CQLIntegerIntervalExample: Interval[5, 10]
{
"@type": "Interval<System.Integer>",
"low": 5
"lowClosed": true
"high": 10
"highClosed": true
}
define CQLQuantityIntervalExample: Interval[5 'mg', 10 'mg']
{
"@type": "Interval<System.Quantity>",
"low":
{
"@type": "System.Quantity",
"value": 5.0,
"unit": "mg"
},
"lowClosed": true
"high":
{
"@type": "System.Quantity",
"value": 10.0,
"unit": "mg"
},
"highClosed": true
}
define CQLListExample: { 1, 2, 3, 4, 5 }
[ 1, 2, 3, 4, 5 ]
define CQLTupleExample: { X: 1, Y: 1 }
{
"X": 1,
"Y": 1
}
define CQLChoiceListExample: List<Choice<Integer, Decimal>> { 1, 1.0 }
[ 1, 1.0 ]
define CQLTupleListExample: { { X: 1, Y: 1 }, { X: 1, Y: 2 }, { X: 1, Y: 3 } }
[
{ "X": 1, "Y": 1 },
{ "X": 1, "Y": 2 },
{ "X": 1, "Y": 3 }
]
define CQLComplexTupleExample: { id: 1, name: 'Patrick', address: { { street: '123 Spinning Ave', city: 'Dayton', state: 'OH' } } }
{
"id": 1,
"name": "Patrick",
"address": [
{
"street": "123 Spinning Ave",
"city": "Dayton",
"state": "OH"
}
]
}
define CQLComplexTupleExample: { id: 1, name: 'Patrick', address: { { street: '123 Spinning Ave', city: 'Dayton', state: 'OH' } } }
define CQLComplexTupleListExample: { CQLComplexTupleExample }
[
{
"id": 1,
"name": "Patrick",
"address": [
{
"street": "123 Spinning Ave",
"city": "Dayton",
"state": "OH"
}
]
}
]
define CQLComplexTupleExample: { id: 1, name: 'Patrick', address: { { street: '123 Spinning Ave', city: 'Dayton', state: 'OH' } } }
define CQLComplexTupleListExample: { CQLComplexTupleExample }
define CQLEmptyListExample: CQLComplexTupleListExample E where false
[ ]