Clinical Practice Guidelines Example Implementation Guide - Chronic Kidney Disease
1.0.0 - ci-build International flag

Clinical Practice Guidelines Example Implementation Guide - Chronic Kidney Disease, published by HL7 International - Clinical Decision Support WG. This guide is not an authorized publication; it is the continuous build for version 1.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/cpg-example-ckd/ and changes regularly. See the Directory of published versions

: Chronic Kidney Disease (CKD) risk screening logic - TTL Representation

Active as of 2024-11-18

Raw ttl | Download

@prefix fhir: <http://hl7.org/fhir/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# - resource -------------------------------------------------------------------

 a fhir:Library ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:id [ fhir:v "CKDRiskLogic"] ; # 
  fhir:text [
fhir:status [ fhir:v "generated" ] ;
fhir:div "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p class=\"res-header-id\"><b>Generated Narrative: Library CKDRiskLogic</b></p><a name=\"CKDRiskLogic\"> </a><a name=\"hcCKDRiskLogic\"> </a><a name=\"CKDRiskLogic-en-US\"> </a><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 &quot;SNOMEDCT&quot;: 'http://snomed.info/sct'\ncodesystem &quot;LOINC&quot;: 'http://loinc.org'\ncodesystem &quot;RxNorm&quot;: 'http://www.nlm.nih.gov/research/umls/rxnorm'\n\nvalueset &quot;Chronic Kidney Disease&quot;: 'ckd-valueset-ckd'\nvalueset &quot;Diabetes mellitus&quot;: 'ckd-valueset-diabetes'\n\nvalueset &quot;eGFR Labs&quot;: 'ckd-valueset-egfr'\nvalueset &quot;UACR Labs&quot;: 'ckd-valueset-uacr'\nvalueset &quot;Creatinine Labs&quot;: 'ckd-valueset-creatinine'\n\ncode &quot;Blood pressure systolic and diastolic&quot;: '55284-4' from &quot;LOINC&quot;\n\ncontext Patient\n\n// Conditions\n//\ndefine &quot;Has CKD or Diabetes&quot;:\n  &quot;Has CKD&quot; or &quot;Has Diabetes&quot;\n\ndefine &quot;Has CKD&quot;:\n  exists( &quot;Chronic Kidney Disease Dx&quot; )\n\ndefine &quot;No CKD Dx&quot;:\n  not exists( &quot;Chronic Kidney Disease Dx&quot; )\n\ndefine &quot;Has Diabetes&quot;:\n  exists( &quot;Diabetes Dx&quot; )\n\ndefine &quot;CKD or Diabetes Dx&quot;:\n  &quot;Chronic Kidney Disease Dx&quot; union &quot;Diabetes Dx&quot;\n\ndefine &quot;Chronic Kidney Disease Dx&quot;:\n  [Condition: code in &quot;Chronic Kidney Disease&quot;] condition\n    where condition.clinicalStatus.value in { 'active', 'recurrence' }\n\ndefine &quot;Diabetes Dx&quot;:\n  [Condition: code in &quot;Diabetes mellitus&quot;] condition\n    where condition.clinicalStatus.value in { 'active', 'recurrence' }\n\n// Laboratory observations\n//\ndefine &quot;Has eGFR or UACR Lab&quot;:\n  &quot;Last eGFR Lab Result&quot; is not null\n	or &quot;Last UACR Lab Result&quot; is not null\n\ndefine &quot;Last eGFR Lab Result&quot;:\n  Last( [Observation: code in &quot;eGFR Labs&quot;] )\n\ndefine &quot;Last eGFR Quantity&quot;:\n  &quot;Last eGFR Lab Result&quot; Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine &quot;Has Abnormal eGFR&quot;:\n  &quot;Last eGFR Quantity&quot;.value &lt; 60\n\ndefine &quot;Last UACR Lab Result&quot;:\n  Last( [Observation: code in &quot;UACR Labs&quot;] )\n\ndefine &quot;Last UACR Quantity&quot;:\n  &quot;Last UACR Lab Result&quot; Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine &quot;Has Abnormal UACR&quot;:\n  &quot;Last UACR Quantity&quot; uacr\n    return UACRtoMetric(uacr).value &gt; 30\n\ndefine &quot;Last Creatinine Lab Result&quot;:\n  Last( [Observation: code in &quot;Creatinine Labs&quot;] )\n\ndefine &quot;Last Creatinine Quantity&quot;:\n  &quot;Last Creatinine Lab Result&quot; Result\n    return ToQuantity(Result.value as Quantity)\n\ndefine &quot;Needs eGFR Lab&quot;:\n	&quot;eGFR Lab is Overdue&quot;\n		or (&quot;eGFR Lab Frequency&quot; is not null and &quot;Last eGFR Lab Result&quot; is null)\n\ndefine &quot;eGFR Lab Frequency&quot;:\n	case\n		when &quot;CKD Stage&quot; &gt;= 4\n			then 3 months\n		when &quot;CKD Stage&quot; &gt;= 3\n			then 6 months\n		when &quot;Has CKD or Diabetes&quot;\n			then 12 months\n		else null\n	end\n\ndefine &quot;eGFR Lab is Overdue&quot;:\n  &quot;Last eGFR Lab Result&quot; 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 + &quot;eGFR Lab Frequency&quot;) &lt; Today()\n        when Result.effective is Period\n          then (end of PeriodToInterval(Result.effective) + &quot;eGFR Lab Frequency&quot;) &lt; Today()\n        else false\n      end\n\ndefine NeedsGFRSummary: 'Order Renal Lab Panel'\n\ndefine NeedsGFRDetail:\n	case\n		when &quot;CKD Stage&quot; &gt;= 1\n			then 'eGFR lab recommended every ' + ToString(&quot;eGFR Lab Frequency&quot;) + ' for Stage ' + ToString(&quot;CKD Stage&quot;) + ' CKD.'\n		when &quot;Has CKD or Diabetes&quot;\n			then 'eGFR lab recommended every ' + ToString(&quot;eGFR Lab Frequency&quot;) + ' for CKD or Diabetes.'\n		else null\n	end\n\ndefine NeedsGFRSeverity: 'info'\n\ndefine &quot;CKD Stage&quot;:\n  &quot;Last eGFR Quantity&quot; egfr\n  	return case\n      when egfr.value &lt; 15\n    		then 5\n    	when egfr.value &lt; 30\n    		then 4\n    	when egfr.value &lt; 60\n    		then 3\n    	when egfr.value &lt; 90\n    		then 2\n    	when egfr.value &gt;= 90\n        // TODO this does not parse\n        //case  when UACRtoMetric(&quot;Get UACR Quantity&quot;).value &gt; 20\n  		  //  then 1\n        //else 0\n        //end\n        then 0\n      else 0\n  	end\n\n// Referrals\n//\ndefine &quot;Recommend Nephrology Referral&quot;:\n	&quot;5-Year Risk Level&quot; = '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//		– 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 &quot;2-YearRiskDetail&quot;:\n	'2-year kidney failure risk of ' + ToString(&quot;2-Year CKD Risk Percent&quot;) + '% is considered to be ' + &quot;2-Year Risk Level&quot; + ' risk.'\n\ndefine &quot;5-YearRiskDetail&quot;:\n	'5-year kidney failure risk of ' + ToString(&quot;5-Year CKD Risk Percent&quot;) + '% is considered to be ' + &quot;5-Year Risk Level&quot; + ' risk.'\n\ndefine &quot;2-YearRiskSeverity&quot;: if &quot;2-Year Risk Level&quot; = 'High' then 'warning' else 'info'\n\ndefine &quot;5-YearRiskSeverity&quot;: if &quot;5-Year Risk Level&quot; = 'High' then 'warning' else 'info'\n\ndefine &quot;2-Year CKD Risk Percent&quot;:\n  &quot;2-Year CKD Risk&quot; risk\n    return Round(risk * 100, 2)\n\ndefine &quot;5-Year CKD Risk Percent&quot;:\n  &quot;5-Year CKD Risk&quot; risk\n    return Round(risk * 100, 2)\n\ndefine &quot;2-Year CKD Risk&quot;:\n  &quot;Last eGFR Quantity&quot; egfr\n    return calculateCkdRisk(0.9750, 0, AgeInYears(), egfr, UACRtoMetric(&quot;Last UACR Quantity&quot;))\n\ndefine &quot;5-Year CKD Risk&quot;:\n  &quot;Last eGFR Quantity&quot; egfr\n    return calculateCkdRisk(0.9240, 0, AgeInYears(), egfr, UACRtoMetric(&quot;Last UACR Quantity&quot;))\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 &quot;2-Year Risk Level&quot;:\n  &quot;2-Year CKD Risk Percent&quot; riskPercent\n  	return case\n      when riskPercent &lt; 5\n    		then 'Low'\n    	when riskPercent &lt; 15\n    		then 'Intermediate'\n    	when riskPercent &gt; 15\n    		then 'High'\n      else null\n  	end\n\ndefine &quot;5-Year Risk Level&quot;:\n  &quot;5-Year CKD Risk Percent&quot; riskPercent\n  	return case\n      when riskPercent &lt; 5\n    		then 'Low'\n    	when riskPercent &lt; 15\n    		then 'Intermediate'\n    	when riskPercent &gt; 15\n    		then 'High'\n      else null\n  	end\n\n// Conversion functions\n\ndefine function PeriodToInterval(value FHIR.Period):\n	Interval[value.&quot;start&quot;.value, value.&quot;end&quot;.value]\n\ndefine function CodingToCode(coding FHIR.Coding):\n	System.Code {\n		code: coding.code.value,\n		system: coding.system.value,\n		version: coding.version.value,\n		display: coding.display.value\n	}\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	case when qty.unit = 'mg/mmol creatinine' then\n		System.Quantity { value: qty.value * 8.84, unit: 'mg/g' }\n	when qty.unit = 'mg/g' then\n    qty\n	else\n    // unknown units, ignore this quantity in calculation\n		null\n	end\n\ndefine function ToMetric(qty System.Quantity):\n	case when qty.unit = 'lb' then\n		System.Quantity { value: qty.value * 0.454, unit: 'kg' }\n	when qty.unit = 'in' then\n		System.Quantity { value: qty.value * 0.0254, unit: 'm' }\n	else\n		qty\n	end\n</code></pre><p><code>No Content</code> (<code>application/elm+xml</code>)</p></div>"
  ] ; # 
  fhir:extension ( [
fhir:url [ fhir:v "http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability"^^xsd:anyURI ] ;
fhir:value [ fhir:v "shareable" ]
  ] [
fhir:url [ fhir:v "http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability"^^xsd:anyURI ] ;
fhir:value [ fhir:v "computable" ]
  ] [
fhir:url [ fhir:v "http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability"^^xsd:anyURI ] ;
fhir:value [ fhir:v "publishable" ]
  ] [
fhir:url [ fhir:v "http://hl7.org/fhir/StructureDefinition/cqf-knowledgeRepresentationLevel"^^xsd:anyURI ] ;
fhir:value [ fhir:v "structured" ]
  ] ) ; # 
  fhir:url [ fhir:v "http://cqframework.org/cpg-example-ckd/Library/CKDRiskLogic"^^xsd:anyURI] ; # 
  fhir:version [ fhir:v "1.0.0"] ; # 
  fhir:name [ fhir:v "CKDRiskLogic"] ; # 
  fhir:title [ fhir:v "Chronic Kidney Disease (CKD) risk screening logic"] ; # 
  fhir:status [ fhir:v "active"] ; # 
  fhir:experimental [ fhir:v "true"^^xsd:boolean] ; # 
  fhir:type [
    ( fhir:coding [
fhir:system [ fhir:v "http://terminology.hl7.org/CodeSystem/library-type"^^xsd:anyURI ] ;
fhir:code [ fhir:v "logic-library" ]     ] )
  ] ; # 
  fhir:date [ fhir:v "2024-11-18T18:20:09+00:00"^^xsd:dateTime] ; # 
  fhir:publisher [ fhir:v "HL7 International - Clinical Decision Support WG"] ; # 
  fhir:contact ( [
fhir:name [ fhir:v "HL7 International - Clinical Decision Support WG" ] ;
    ( fhir:telecom [
fhir:system [ fhir:v "url" ] ;
fhir:value [ fhir:v "http://www.hl7.org/Special/committees/dss/index.cfm" ]     ] )
  ] ) ; # 
  fhir:description [ fhir:v "Chronic Kidney Disease (CKD) risk screening logic"] ; # 
  fhir:jurisdiction ( [
    ( fhir:coding [
fhir:system [ fhir:v "http://unstats.un.org/unsd/methods/m49/m49.htm"^^xsd:anyURI ] ;
fhir:code [ fhir:v "001" ] ;
fhir:display [ fhir:v "World" ]     ] )
  ] ) ; # 
  fhir:content ( [
fhir:contentType [ fhir:v "text/cql" ] ;
fhir:data [ fhir:v "bGlicmFyeSBDS0RSaXNrTG9naWMgdmVyc2lvbiAnMS4wJwoKdXNpbmcgRkhJUiB2ZXJzaW9uICc0LjAuMCcKCmluY2x1ZGUgRkhJUkhlbHBlcnMgdmVyc2lvbiAnNC4wLjAnIGNhbGxlZCBGSElSSGVscGVycwoKY29kZXN5c3RlbSAiU05PTUVEQ1QiOiAnaHR0cDovL3Nub21lZC5pbmZvL3NjdCcKY29kZXN5c3RlbSAiTE9JTkMiOiAnaHR0cDovL2xvaW5jLm9yZycKY29kZXN5c3RlbSAiUnhOb3JtIjogJ2h0dHA6Ly93d3cubmxtLm5paC5nb3YvcmVzZWFyY2gvdW1scy9yeG5vcm0nCgp2YWx1ZXNldCAiQ2hyb25pYyBLaWRuZXkgRGlzZWFzZSI6ICdja2QtdmFsdWVzZXQtY2tkJwp2YWx1ZXNldCAiRGlhYmV0ZXMgbWVsbGl0dXMiOiAnY2tkLXZhbHVlc2V0LWRpYWJldGVzJwoKdmFsdWVzZXQgImVHRlIgTGFicyI6ICdja2QtdmFsdWVzZXQtZWdmcicKdmFsdWVzZXQgIlVBQ1IgTGFicyI6ICdja2QtdmFsdWVzZXQtdWFjcicKdmFsdWVzZXQgIkNyZWF0aW5pbmUgTG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