Skip to content

Examples

c-schuler edited this page Jul 20, 2022 · 6 revisions

Case Reporting Examples

$process-message-bundle

$extract-line-list-data

Clinical Practice Guideline Examples

$apply

$cql

Arithmetic Expression

Request

POST [base]/$cql

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "expression",
      "valueString": "5 * 5"
    }
  ]
}
Response
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "value",
      "valueString": "25"
    },
    {
      "name": "resultType",
      "valueString": "Integer"
    }
  ]
}

Referenced Library Expression

Load Resources

POST [base]

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "SimplePatient",
        "birthDate": "1995-01-01",
        "gender": "female"
      },
      "request": {
        "method": "PUT",
        "url": "Patient/SimplePatient"
      }
    },
    {
      "resource": {
        "resourceType": "Library",
        "id": "SimpleLibrary",
        "name": "SimpleLibrary",
        "version": "0.0.1",
        "status": "active",
        "experimental": false,
        "type": {
          "coding": [
            {
              "system": "http://terminology.hl7.org/CodeSystem/library-type",
              "code": "logic-library"
            }
          ]
        },
        "date": "2021-04-23T15:32:03+00:00",
        "publisher": "National Committee for Quality Assurance",
        "description": "Simple Library for Testing Simple Expressions",
        "content": [
          {
            "contentType": "text/cql",
            "data": "bGlicmFyeSBTaW1wbGVSNExpYnJhcnkKCnVzaW5nIEZISVIgdmVyc2lvbiAnNC4wLjEnCgppbmNsdWRlIEZISVJIZWxwZXJzIHZlcnNpb24gJzQuMC4xJyBjYWxsZWQgRkhJUkhlbHBlcnMKCmNvbnRleHQgUGF0aWVudAoKZGVmaW5lIHNpbXBsZUJvb2xlYW5FeHByZXNzaW9uOiB0cnVlCgpkZWZpbmUgb2JzZXJ2YXRpb25SZXRyaWV2ZTogW09ic2VydmF0aW9uXQoKZGVmaW5lIG9ic2VydmF0aW9uSGFzQ29kZTogbm90IElzTnVsbCgoW09ic2VydmF0aW9uXSkuY29kZSkKCmRlZmluZSAiSW5pdGlhbCBQb3B1bGF0aW9uIjogb2JzZXJ2YXRpb25IYXNDb2RlCgpkZWZpbmUgIkRlbm9taW5hdG9yIjogIkluaXRpYWwgUG9wdWxhdGlvbiIKCmRlZmluZSAiTnVtZXJhdG9yIjogIkRlbm9taW5hdG9yIgo="
          }
        ]
      },
      "request": {
        "method": "PUT",
        "url": "Library/SimpleLibrary"
      }
    }
  ]
}
Request

POST [base]/$cql

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "subject",
      "valueString": "Patient/SimplePatient"
    },
    {
      "name": "library",
      "resource": {
        "resourceType": "Parameters",
        "parameter": [
          {
            "name": "url",
            "valueCanonical": "http://www.example.com/Library/SimpleR4Library"
          },
          {
            "name": "name",
            "valueString": "SimpleR4Library"
          }
        ]
      }
    },
    {
      "name": "expression",
      "valueString": "SimpleR4Library.\"simpleBooleanExpression\""
    }
  ]
}
Response
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "value",
      "valueString": "true"
    },
    {
      "name": "resultType",
      "valueString": "Boolean"
    }
  ]
}    

Input Parameters Expression

Request

POST [base]/$cql

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "parameters",
      "resource": {
        "resourceType": "Parameters",
        "parameter": [
          {
            "name": "%inputDate",
            "valueDate": "2019-11-01"
          }
        ]
      }
    },
    {
      "name": "expression",
      "valueString": "year from %inputDate"
    }
  ]
}
Response
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "value",
      "valueString": "2019"
    },
    {
      "name": "resultType",
      "valueString": "Integer"
    }
  ]
}

$evaluate

Simple Library Evaluation

CQL Source
library SimpleR4Library

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers

context Patient

define simpleBooleanExpression: true

define observationRetrieve: [Observation]

define observationHasCode: not IsNull(([Observation]).code)

define "Initial Population": observationHasCode

define "Denominator": "Initial Population"

define "Numerator": "Denominator"
Load Resources

POST [base]

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "SimplePatient",
        "birthDate": "1995-01-01",
        "gender": "female"
      },
      "request": {
        "method": "PUT",
        "url": "Patient/SimplePatient"
      }
    },
    {
      "resource": {
        "resourceType": "Observation",
        "id": "SimpleObservation",
        "status": "final",
        "code": {
          "coding": [
            {
              "system": "http://loinc.org",
              "code": "10524-7",
              "display": "Microscopic observation [Identifier] in Cervix by Cyto stain"
            }
          ]
        },
        "value": {
          "coding": [
            {
              "system": "http://loinc.org",
              "code": "10524-7",
              "display": "Microscopic observation [Identifier] in Cervix by Cyto stain"
            }
          ]
        },
        "subject": {
          "reference": "Patient/SimplePatient",
          "type": "Patient"
        },
        "effectiveDateTime": "2019-11-01T00:00:00"
      },
      "request": {
        "method": "PUT",
        "url": "Observation/SimpleObservation"
      }
    },
    {
      "resource": {
        "resourceType": "Library",
        "id": "SimpleR4Library",
        "name": "SimpleR4Library",
        "status": "active",
        "experimental": false,
        "type": {
          "coding": [
            {
              "system": "http://terminology.hl7.org/CodeSystem/library-type",
              "code": "logic-library"
            }
          ]
        },
        "date": "2021-04-23T15:32:03+00:00",
        "publisher": "National Committee for Quality Assurance",
        "description": "Simple Library for Testing Simple Expressions",
        "content": [
          {
            "contentType": "text/cql",
            "data": "bGlicmFyeSBTaW1wbGVSNExpYnJhcnkKCnVzaW5nIEZISVIgdmVyc2lvbiAnNC4wLjEnCgppbmNsdWRlIEZISVJIZWxwZXJzIHZlcnNpb24gJzQuMC4xJyBjYWxsZWQgRkhJUkhlbHBlcnMKCmNvbnRleHQgUGF0aWVudAoKZGVmaW5lIHNpbXBsZUJvb2xlYW5FeHByZXNzaW9uOiB0cnVlCgpkZWZpbmUgb2JzZXJ2YXRpb25SZXRyaWV2ZTogW09ic2VydmF0aW9uXQoKZGVmaW5lIG9ic2VydmF0aW9uSGFzQ29kZTogbm90IElzTnVsbCgoW09ic2VydmF0aW9uXSkuY29kZSkKCmRlZmluZSAiSW5pdGlhbCBQb3B1bGF0aW9uIjogb2JzZXJ2YXRpb25IYXNDb2RlCgpkZWZpbmUgIkRlbm9taW5hdG9yIjogIkluaXRpYWwgUG9wdWxhdGlvbiIKCmRlZmluZSAiTnVtZXJhdG9yIjogIkRlbm9taW5hdG9yIgo="
          }
        ]
      },
      "request": {
        "method": "PUT",
        "url": "Library/SimpleR4Library"
      }
    }
  ]
}

Request:

GET [base]/Library/SimpleR4Library/$evaluate?subject=Patient/SimplePatient

Response
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "Patient",
      "resource": {
        "resourceType": "Patient",
        "id": "SimplePatient",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2022-07-20T16:24:33.324-06:00",
          "source": "#C0LLbJGJBhdZr5OC"
        },
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><table class=\"hapiPropertyTable\"><tbody><tr><td>Date of birth</td><td><span>01 January 1995</span></td></tr></tbody></table></div>"
        },
        "gender": "female",
        "birthDate": "1995-01-01"
      }
    },
    {
      "name": "simpleBooleanExpression",
      "valueBoolean": true
    },
    {
      "name": "observationRetrieve",
      "resource": {
        "resourceType": "Observation",
        "id": "SimpleObservation",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2022-07-20T16:24:33.324-06:00",
          "source": "#C0LLbJGJBhdZr5OC"
        },
        "status": "final",
        "code": {
          "coding": [
            {
              "system": "http://loinc.org",
              "code": "10524-7",
              "display": "Microscopic observation [Identifier] in Cervix by Cyto stain"
            }
          ]
        },
        "subject": {
          "reference": "Patient/SimplePatient",
          "type": "Patient"
        },
        "effectiveDateTime": "2019-11-01T00:00:00"
      }
    },
    {
      "name": "observationHasCode",
      "valueBoolean": true
    },
    {
      "name": "Initial Population",
      "valueBoolean": true
    },
    {
      "name": "Denominator",
      "valueBoolean": true
    },
    {
      "name": "Numerator",
      "valueBoolean": true
    }
  ]
}

Library with In-line Code Example

CQL Source
library AsthmaTest version '1.0.0'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'

codesystem "SNOMED": 'http://snomed.info/sct'

code "Asthma": '195967001' from "SNOMED"

context Patient

define "Asthma Diagnosis":
    [Condition: "Asthma"]

define "Has Asthma Diagnosis":
    exists("Asthma Diagnosis")
Load Resources

POST [base]

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "SimplePatient",
        "birthDate": "1995-01-01",
        "gender": "female"
      },
      "request": {
        "method": "PUT",
        "url": "Patient/SimplePatient"
      }
    },
    {
      "resource": {
        "resourceType": "Condition",
        "id": "SimpleCondition",
        "code": {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "195967001",
              "display": "Asthma"
            }
          ],
          "text": "Asthma"
        },
        "subject": {
          "reference": "Patient/SimplePatient"
        }
      },
      "request": {
        "method": "PUT",
        "url": "Condition/SimpleCondition"
      }
    },
    {
      "resource": {
        "resourceType": "Library",
        "id": "AsthmaTest",
        "url": "http://example.com/AsthmaTest",
        "version": "1.0.0",
        "name": "AsthmaTest",
        "status": "draft",
        "type": "logic-library",
        "content": [
          {
            "contentType": "text/cql",
            "data": "bGlicmFyeSBBc3RobWFUZXN0IHZlcnNpb24gJzEuMC4wJwoKdXNpbmcgRkhJUiB2ZXJzaW9uICc0LjAuMScKCmluY2x1ZGUgRkhJUkhlbHBlcnMgdmVyc2lvbiAnNC4wLjEnCgpjb2Rlc3lzdGVtICJTTk9NRUQiOiAnaHR0cDovL3Nub21lZC5pbmZvL3NjdCcKCmNvZGUgIkFzdGhtYSI6ICcxOTU5NjcwMDEnIGZyb20gIlNOT01FRCIKCmNvbnRleHQgUGF0aWVudAoKZGVmaW5lICJBc3RobWEgRGlhZ25vc2lzIjoKICAgIFtDb25kaXRpb246ICJBc3RobWEiXQoKZGVmaW5lICJIYXMgQXN0aG1hIERpYWdub3NpcyI6CiAgICBleGlzdHMoIkFzdGhtYSBEaWFnbm9zaXMiKQo="
          }
        ]
      },
      "request": {
        "method": "PUT",
        "url": "Library/AsthmaTest"
      }
    }
  ]
}

Request:

GET [base]/Library/AsthmaTest/$evaluate?subject=Patient/SimplePatient

Response
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "Patient",
      "resource": {
        "resourceType": "Patient",
        "id": "SimplePatient",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2022-07-20T16:24:33.324-06:00",
          "source": "#C0LLbJGJBhdZr5OC"
        },
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><table class=\"hapiPropertyTable\"><tbody><tr><td>Date of birth</td><td><span>01 January 1995</span></td></tr></tbody></table></div>"
        },
        "gender": "female",
        "birthDate": "1995-01-01"
      }
    },
    {
      "name": "Asthma Diagnosis",
      "resource": {
        "resourceType": "Condition",
        "id": "SimpleCondition",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2022-07-20T16:43:50.392-06:00",
          "source": "#fIwI0nB4fCzmH3Bg"
        },
        "code": {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "195967001",
              "display": "Asthma"
            }
          ],
          "text": "Asthma"
        },
        "subject": {
          "reference": "Patient/SimplePatient"
        }
      }
    },
    {
      "name": "Has Asthma Diagnosis",
      "valueBoolean": true
    }
  ]
}

Clinical Reasoning Examples

$apply

$care-gaps

$collect-data

$data-requirements

$evaluate-measure

$submit-data

Risk Adjustment Examples

$report

Structured Data Capture Examples

$extract

$transform