FHIR Clinical Guidelines (v1.0.0) (STU1)

This page is part of the Clinical Guidelines (v1.0.0: STU 1) based on FHIR R4. This is the current published version. For a full list of available versions, see the Directory of published versions

CKDRiskLogic

Formats: Narrative, XML, JSON, Turtle

Raw json


{
  "resourceType" : "Library",
  "id" : "CKDRiskLogic",
  "meta" : {
    "profile" : [
      "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-computablelibrary"
    ]
  },
  "text" : {
    "status" : "generated",
    "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h2>Contents</h2><p><code>text/cql</code></p><pre><code class=\"language-sql\">library CKDRiskLogic version '1.0'\n\nusing FHIR version '4.0.0'\n\ninclude FHIRHelpers version '4.0.0' called FHIRHelpers\n\ncodesystem \"SNOMEDCT\": 'http://snomed.info/sct'\ncodesystem \"LOINC\": 'http://loinc.org'\ncodesystem \"RxNorm\": 'http://www.nlm.nih.gov/research/umls/rxnorm'\n\nvalueset \"Chronic Kidney Disease\": 'ckd-valueset-ckd'\nvalueset \"Diabetes mellitus\": 'ckd-valueset-diabetes'\n\nvalueset \"eGFR Labs\": 'ckd-valueset-egfr'\nvalueset \"UACR Labs\": 'ckd-valueset-uacr'\nvalueset \"Creatinine Labs\": 'ckd-valueset-creatinine'\n\ncode \"Blood pressure systolic and diastolic\": '55284-4' from \"LOINC\"\n\ncontext Patient\n\n// Conditions\n//\ndefine \"Has CKD or Diabetes\":\n  \"Has CKD\" or \"Has Diabetes\"\n\ndefine \"Has CKD\":\n  exists( \"Chronic Kidney Disease Dx\" )\n\ndefine \"Has Diabetes\":\n  exists( \"Diabetes Dx\" )\n\ndefine \"CKD or Diabetes Dx\":\n  \"Chronic Kidney Disease Dx\" union \"Diabetes Dx\"\n\ndefine \"Chronic Kidney Disease Dx\":\n  [Condition: code in \"Chronic Kidney Disease\"] condition\n    where condition.clinicalStatus.value in { 'active', 'recurrence' }\n\ndefine \"Diabetes Dx\":\n  [Condition: code in \"Diabetes mellitus\"] condition\n    where condition.clinicalStatus.value in { 'active', 'recurrence' }\n\n// Laboratory observations\n//\ndefine \"Has eGFR or UACR Lab\":\n  \"Last eGFR Lab Result\" is not null\n\tor \"Last UACR Lab Result\" is not null\n\ndefine \"Last eGFR Lab Result\":\n  Last( [Observation: code in \"eGFR Labs\"] )\n\ndefine \"Last eGFR Quantity\":\n  \"Last eGFR Lab Result\" Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine \"Has Abnormal eGFR\":\n  \"Last eGFR Quantity\".value &lt; 60\n\ndefine \"Last UACR Lab Result\":\n  Last( [Observation: code in \"UACR Labs\"] )\n\ndefine \"Last UACR Quantity\":\n  \"Last UACR Lab Result\" Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine \"Has Abnormal UACR\":\n  \"Last UACR Quantity\" uacr\n    return UACRtoMetric(uacr).value &gt; 30\n\ndefine \"Last Creatinine Lab Result\":\n  Last( [Observation: code in \"Creatinine Labs\"] )\n\ndefine \"Last Creatinine Quantity\":\n  \"Last Creatinine Lab Result\" Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine \"Needs eGFR Lab\":\n\t\"eGFR Lab is Overdue\"\n\t\tor (\"eGFR Lab Frequency\" is not null and \"Last eGFR Lab Result\" is null)\n\ndefine \"eGFR Lab Frequency\":\n\tcase\n\t\twhen \"CKD Stage\" &gt;= 4\n\t\t\tthen 3 months\n\t\twhen \"CKD Stage\" &gt;= 3\n\t\t\tthen 6 months\n\t\twhen \"Has CKD or Diabetes\"\n\t\t\tthen 12 months\n\t\telse null\n\tend\n\ndefine \"eGFR Lab is Overdue\":\n  \"Last eGFR Lab Result\" Result\n    return\n      case\n        when Result.effective is null\n          then true\n        when Result.effective is dateTime\n          then (Result.effective.value + \"eGFR Lab Frequency\") &lt; Today()\n        when Result.effective is Period\n          then (end of PeriodToInterval(Result.effective) + \"eGFR Lab Frequency\") &lt; Today()\n        else false\n      end\n\ndefine NeedsGFRSummary: 'Order Renal Lab Panel'\n\ndefine NeedsGFRDetail:\n\tcase\n\t\twhen \"CKD Stage\" &gt;= 1\n\t\t\tthen 'eGFR lab recommended every ' + ToString(\"eGFR Lab Frequency\") + ' for Stage ' + ToString(\"CKD Stage\") + ' CKD.'\n\t\twhen \"Has CKD or Diabetes\"\n\t\t\tthen 'eGFR lab recommended every ' + ToString(\"eGFR Lab Frequency\") + ' for CKD or Diabetes.'\n\t\telse null\n\tend\n\ndefine NeedsGFRSeverity: 'info'\n\ndefine \"CKD Stage\":\n  \"Last eGFR Quantity\" egfr\n  \treturn case\n      when egfr.value &lt; 15\n    \t\tthen 5\n    \twhen egfr.value &lt; 30\n    \t\tthen 4\n    \twhen egfr.value &lt; 60\n    \t\tthen 3\n    \twhen egfr.value &lt; 90\n    \t\tthen 2\n    \twhen egfr.value &gt;= 90\n        // TODO this does not parse\n        //case  when UACRtoMetric(\"Get UACR Quantity\").value &gt; 20\n  \t\t  //  then 1\n        //else 0\n        //end\n        then 0\n      else 0\n  \tend\n\n// Referrals\n//\ndefine \"Recommend Nephrology Referral\":\n\t\"5-Year Risk Level\" = 'High'\n\ndefine NephrologyReferralDetail: 'Referral to a nephrologist is recommended when 5-year risk is High'\n\ndefine NephrologyReferralSeverity: 'info'\n\n//\n// Tangri CKD risk model\n//\n// 4 variable\n// 1 – 0.9750 ^ exp (-0.2201 × (age/10 – 7.036) + 0.2467 × (male – 0.5642) – 0.5567 × (eGFR/5 – 7.222) + 0.4510 × (logACR – 5.137))\n// 5 year factor =  0.9240\n//\n// 8 variable\n// 1 – 0.9780 ^ exp (-0.1992 × (age/10 – 7.036) + 0.1602 × (male – 0.5642) – 0.4919 × (eGFR/5 – 7.222) + 0.3364 × (logACR – 5.137)\n//\t\t– 0.3441 × (albumin – 3.997) + 0.2604 × (phosphorous – 3.916) – 0.07354 × (bicarbonate – 25.57) – 0.2228 × (calcium – 9.355))\n// 5 year factor = 0.9301\n\ndefine \"2-YearRiskDetail\":\n\t'2-year kidney failure risk of ' + ToString(\"2-Year CKD Risk Percent\") + '% is considered to be ' + \"2-Year Risk Level\" + ' risk.'\n\ndefine \"5-YearRiskDetail\":\n\t'5-year kidney failure risk of ' + ToString(\"5-Year CKD Risk Percent\") + '% is considered to be ' + \"5-Year Risk Level\" + ' risk.'\n\ndefine \"2-YearRiskSeverity\": if \"2-Year Risk Level\" = 'High' then 'warning' else 'info'\n\ndefine \"5-YearRiskSeverity\": if \"5-Year Risk Level\" = 'High' then 'warning' else 'info'\n\ndefine \"2-Year CKD Risk Percent\":\n  \"2-Year CKD Risk\" risk\n    return Round(risk * 100, 2)\n\ndefine \"5-Year CKD Risk Percent\":\n  \"5-Year CKD Risk\" risk\n    return Round(risk * 100, 2)\n\ndefine \"2-Year CKD Risk\":\n  \"Last eGFR Quantity\" egfr\n    return calculateCkdRisk(0.9750, 0, AgeInYears(), egfr, UACRtoMetric(\"Last UACR Quantity\"))\n\ndefine \"5-Year CKD Risk\":\n  \"Last eGFR Quantity\" egfr\n    return calculateCkdRisk(0.9240, 0, AgeInYears(), egfr, UACRtoMetric(\"Last UACR Quantity\"))\n\n// The ckdFactor is a variable determined by (Non-) North American location and whether calculation is 2 or 5 year prediction\ndefine function calculateCkdRisk(ckdFactor Decimal, sex Integer, age Integer, egfr System.Quantity, acr System.Quantity):\n  1.0 - Power(ckdFactor, Exp(-0.2201 * (age / 10 - 7.036) + 0.2467 * (sex - 0.5642) - 0.5567 * (egfr.value / 5 - 7.222) + 0.4510 * (Ln(acr.value) - 5.137)))\n\ndefine \"2-Year Risk Level\":\n  \"2-Year CKD Risk Percent\" riskPercent\n  \treturn case\n      when riskPercent &lt; 5\n    \t\tthen 'Low'\n    \twhen riskPercent &lt; 15\n    \t\tthen 'Intermediate'\n    \twhen riskPercent &gt; 15\n    \t\tthen 'High'\n      else null\n  \tend\n\ndefine \"5-Year Risk Level\":\n  \"5-Year CKD Risk Percent\" riskPercent\n  \treturn case\n      when riskPercent &lt; 5\n    \t\tthen 'Low'\n    \twhen riskPercent &lt; 15\n    \t\tthen 'Intermediate'\n    \twhen riskPercent &gt; 15\n    \t\tthen 'High'\n      else null\n  \tend\n\n// Conversion functions\n\ndefine function PeriodToInterval(value FHIR.Period):\n\tInterval[value.\"start\".value, value.\"end\".value]\n\ndefine function CodingToCode(coding FHIR.Coding):\n\tSystem.Code {\n\t\tcode: coding.code.value,\n\t\tsystem: coding.system.value,\n\t\tversion: coding.version.value,\n\t\tdisplay: coding.display.value\n\t}\n\ndefine function ToConcept(concept FHIR.CodeableConcept):\n    System.Concept {\n        codes: concept.coding C return CodingToCode(C),\n        display: concept.text.value\n    }\n\ndefine function ToQuantity(quantity FHIR.Quantity):\n    System.Quantity {\n        value: quantity.value.value,\n        unit: quantity.unit.value\n    }\n\ndefine function UACRtoMetric(qty System.Quantity):\n\tcase when qty.unit = 'mg/mmol creatinine' then\n\t\tSystem.Quantity { value: qty.value * 8.84, unit: 'mg/g' }\n\twhen qty.unit = 'mg/g' then\n    qty\n\telse\n    // unknown units, ignore this quantity in calculation\n\t\tnull\n\tend\n\ndefine function ToMetric(qty System.Quantity):\n\tcase when qty.unit = 'lb' then\n\t\tSystem.Quantity { value: qty.value * 0.454, unit: 'kg' }\n\twhen qty.unit = 'in' then\n\t\tSystem.Quantity { value: qty.value * 0.0254, unit: 'm' }\n\telse\n\t\tqty\n\tend\n</code></pre></div>"
  },
  "extension" : [
    {
      "url" : "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability",
      "valueCode" : "shareable"
    },
    {
      "url" : "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability",
      "valueCode" : "computable"
    },
    {
      "url" : "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability",
      "valueCode" : "publishable"
    },
    {
      "url" : "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeRepresentationLevel",
      "valueCode" : "structured"
    }
  ],
  "url" : "http://hl7.org/fhir/uv/cpg/Library/CKDRiskLogic",
  "version" : "1.0.0",
  "name" : "CKDRiskLogic",
  "title" : "Chronic Kidney Disease (CKD) risk screening logic",
  "status" : "active",
  "experimental" : true,
  "type" : {
    "coding" : [
      {
        "system" : "http://terminology.hl7.org/CodeSystem/library-type",
        "code" : "logic-library"
      }
    ]
  },
  "date" : "2021-02-11T20:43:58+00:00",
  "publisher" : "HL7 FHIR Clinical Guidelines Example Artifact",
  "description" : "Chronic Kidney Disease (CKD) risk screening logic",
  "jurisdiction" : [
    {
      "coding" : [
        {
          "system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
          "code" : "001",
          "display" : "World"
        }
      ]
    }
  ],
  "content" : [
    {
      "contentType" : "text/cql",
      "data" : "bGlicmFyeSBDS0RSaXNrTG9naWMgdmVyc2lvbiAnMS4wJwoKdXNpbmcgRkhJUiB2ZXJzaW9uICc0LjAuMCcKCmluY2x1ZGUgRkhJUkhlbHBlcnMgdmVyc2lvbiAnNC4wLjAnIGNhbGxlZCBGSElSSGVscGVycwoKY29kZXN5c3RlbSAiU05PTUVEQ1QiOiAnaHR0cDovL3Nub21lZC5pbmZvL3NjdCcKY29kZXN5c3RlbSAiTE9JTkMiOiAnaHR0cDovL2xvaW5jLm9yZycKY29kZXN5c3RlbSAiUnhOb3JtIjogJ2h0dHA6Ly93d3cubmxtLm5paC5nb3YvcmVzZWFyY2gvdW1scy9yeG5vcm0nCgp2YWx1ZXNldCAiQ2hyb25pYyBLaWRuZXkgRGlzZWFzZSI6ICdja2QtdmFsdWVzZXQtY2tkJwp2YWx1ZXNldCAiRGlhYmV0ZXMgbWVsbGl0dXMiOiAnY2tkLXZhbHVlc2V0LWRpYWJldGVzJwoKdmFsdWVzZXQgImVHRlIgTGFicyI6ICdja2QtdmFsdWVzZXQtZWdmcicKdmFsdWVzZXQgIlVBQ1IgTGFicyI6ICdja2QtdmFsdWVzZXQtdWFjcicKdmFsdWVzZXQgIkNyZWF0aW5pbmUgTGFicyI6ICdja2QtdmFsdWVzZXQtY3JlYXRpbmluZScKCmNvZGUgIkJsb29kIHByZXNzdXJlIHN5c3RvbG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