Your User Friendly Name for MyContentIG Here
0.4.7 - CI Build International flag

Your User Friendly Name for MyContentIG Here, published by HL7 International - [Some] Work Group. This guide is not an authorized publication; it is the continuous build for version 0.4.7 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/sample-content-ig/ and changes regularly. See the Directory of published versions

Library: PHQ-9 Depression Scoring Logic Example (Experimental)

Official URL: http://somewhere.org/fhir/uv/mycontentig/Library/PHQ9LogicExample Version: 0.4.7
Draft as of 2024-12-09 Computable Name: PHQ9LogicExample

Example library illustrating basic CQL constructs using PHQ-9 Logic as an Example

Knowledge Artifact Metadata
Name (machine-readable) PHQ9LogicExample
Title (human-readable) PHQ-9 Depression Scoring Logic Example
Status Draft
Experimental true
Description

Example library illustrating basic CQL constructs using PHQ-9 Logic as an Example

Library Steward HL7 International - [Some] Work Group
Steward Contact Details http://hl7.org/Special/committees/[something]
Dependency Description: FHIR model information
Resource: http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
Canonical URL: http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
Dependency Description: Library FHIRHelpers
Resource: http://hl7.org/fhir/Library/FHIRHelpers|4.0.1
Canonical URL: http://hl7.org/fhir/Library/FHIRHelpers|4.0.1
Dependency Description: Code system LOINC
Resource: Logical Observation Identifiers, Names and Codes (LOINC)
Canonical URL: http://loinc.org
Library Metadata
Version Number 0.4.7
Library Type Logic Library
Library Subject Patient
Parameter Name: response
Use: In
Min Cardinality: 0
Max Cardinality: 1
Type: QuestionnaireResponse
Parameter Name: Patient
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Patient
Parameter Name: QuestionnaireResponses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: QuestionnaireResponse
Parameter Name: QuestionnaireResponse
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: QuestionnaireResponse
Parameter Name: Responses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Parameter Name: CalculateTotalScore
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: integer
Data Requirement Type: Patient
Profile(s): Patient
Data Requirement Type: QuestionnaireResponse
Profile(s): QuestionnaireResponse
Must Support Elements: item, answer
Library Content
CQL Content
library PHQ9LogicExample version '0.4.1'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'

codesystem "LOINC": 'http://loinc.org'

code "Not at all": 'LA6568-5' from "LOINC"
code "Several days": 'LA6569-3' from "LOINC"
code "More than half the days": 'LA6570-1' from "LOINC"
code "Nearly every day": 'LA6571-9' from "LOINC"

parameter response QuestionnaireResponse

context Patient

define QuestionnaireResponses: [QuestionnaireResponse]

// Use the QuestionnaireResponse provided as a parameter if available
// Otherwise look it up from the record
define "QuestionnaireResponse":
  if response is not null then
    response
  else
    Last(
      [QuestionnaireResponse] QR
        where QR.questionnaire = 'http://somewhere.org/fhir/uv/mycontentig/Questionnaire/phq-9-questionnaire'
        sort by (authored as FHIR.dateTime) desc
    )

// NOTE: This ties this logic directly to this particular rendering of the Questionnaire.
// Ideally the items would be filtered based on Code of the Item, rather than the LinkId,
// but that would require pulling in the Questionnaire because the QuestionnaireResponse
// only has the LinkId.
define "Responses":
  "QuestionnaireResponse" QR
    return QR.item I where I.linkId in {
      'LittleInterest',
      'FeelingDown',
      'TroubleSleeping',
      'FeelingTired',
      'BadApetite',
      'FeelingBadAboutSelf',
      'TroubleConcetrating',
      'MovingSpeaking'
    }

/*
@source: https://www.med.umich.edu/1info/FHP/practiceguides/depress/score.pdf
*/
define function "AnswerCardinality"(answer Coding):
  case
    when answer ~ "Not at all" then 0
    when answer ~ "Several days" then 1
    when answer ~ "More than half the days" then 2
    when answer ~ "Nearly every day" then 3
    else null
  end

define "CalculateTotalScore":
  Sum("Responses" R return all AnswerCardinality(First(R.answer.value)))
ELM XML Content
Encoded data (39840 characters)
ELM JSON Content
Encoded data (75124 characters)
Generated using version 0.4.7 of the sample-content-ig Liquid templates