library FollowUpCareforChildrenPrescribedADHDMedicationADDFHIR version '0.0.002' using QICore version '4.1.1' include FHIRHelpers version '4.2.000' called FHIRHelpers include SupplementalDataElements version '3.2.000' called SDE include QICoreCommon version '1.3.000' called QICoreCommon include CQMCommon version '1.1.000' called CQMCommon include Hospice version '6.4.000' called Hospice include CumulativeMedicationDuration version '3.1.000' called CMD codesystem "RXNORM": 'http://www.nlm.nih.gov/research/umls/rxnorm' codesystem "V3TimingEvent": 'http://terminology.hl7.org/CodeSystem/v3-TimingEvent' codesystem "EventTiming": 'http://hl7.org/fhir/event-timing' valueset "Ambulatory": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.122.12.1003' valueset "Atomoxetine": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1170' valueset "Behavioral Health Follow up Visit": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1054' valueset "Clonidine": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1171' valueset "Dexmethylphenidate": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1172' valueset "Dextroamphetamine": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1173' valueset "Encounter Inpatient": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307' valueset "Guanfacine": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.196.11.1252' valueset "Home Healthcare Services": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016' valueset "Initial Hospital Observation Care": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1002' valueset "Lisdexamfetamine": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1174' valueset "Mental Behavioral and Neurodevelopmental Disorders": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.105.12.1203' valueset "Methylphenidate": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1176' valueset "Narcolepsy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.114.12.1011' valueset "Office Visit": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001' valueset "Online Assessments": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089' valueset "Outpatient Consultation": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1008' valueset "Preventive Care Services Group Counseling": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1027' valueset "Preventive Care Services Individual Counseling": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1026' valueset "Preventive Care Services, Initial Office Visit, 0 to 17": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1022' valueset "Preventive Care, Established Office Visit, 0 to 17": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1024' valueset "Psych Visit Diagnostic Evaluation": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1492' valueset "Psych Visit Psychotherapy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1496' valueset "Psychotherapy and Pharmacologic Management": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1055' valueset "Telephone Visits": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080' code "24 HR dexmethylphenidate hydrochloride 40 MG Extended Release Oral Capsule": '1006608' from "RXNORM" display '24 HR dexmethylphenidate hydrochloride 40 MG Extended Release Oral Capsule' code "methamphetamine hydrochloride 5 MG Oral Tablet": '977860' from "RXNORM" display 'methamphetamine hydrochloride 5 MG Oral Tablet' code "HS": 'HS' from "V3TimingEvent" // event occurs [offset] before the hour of sleep (or trying to) code "WAKE": 'WAKE' from "V3TimingEvent" // event occurs [offset] after waking code "C": 'C' from "V3TimingEvent" // event occurs at a meal (from the Latin cibus) code "CM": 'CM' from "V3TimingEvent" // event occurs at breakfast (from the Latin cibus matutinus) code "CD": 'CD' from "V3TimingEvent" // event occurs at lunch (from the Latin cibus diurnus) code "CV": 'CV' from "V3TimingEvent" // event occurs at dinner (from the Latin ante cibus vespertinus) code "AC": 'AC' from "V3TimingEvent" // event occurs [offset] before a meal (from the Latin ante cibus) code "ACM": 'ACM' from "V3TimingEvent" // event occurs [offset] before breakfast (from the Latin ante cibus matutinus) code "ACD": 'ACD' from "V3TimingEvent" // event occurs [offset] before lunch (from the Latin ante cibus diurnus) code "ACV": 'ACV' from "V3TimingEvent" // event occurs [offset] before dinner (from the Latin ante cibus vespertinus) code "PC": 'PC' from "V3TimingEvent" // event occurs [offset] after a meal (from the Latin post cibus) code "PCM": 'PCM' from "V3TimingEvent" // event occurs [offset] after breakfast (from the Latin post cibus matutinus) code "PCD": 'PCD' from "V3TimingEvent" // event occurs [offset] after lunch (from the Latin post cibus diurnus) code "PCV": 'PCV' from "V3TimingEvent" // event occurs [offset] after dinner (from the Latin post cibus vespertinus) code "MORN": 'MORN' from EventTiming // Event occurs during the morning. The exact time is unspecified and established by institution convention or patient interpretation. code "MORN.early": 'MORN.early' from EventTiming // Early Morning Event occurs during the early morning. The exact time is unspecified and established by institution convention or patient interpretation. code "MORN.late": 'MORN.late' from EventTiming // Late Morning Event occurs during the late morning. The exact time is unspecified and established by institution convention or patient interpretation. code "NOON": 'NOON' from EventTiming // Noon Event occurs around 12:00pm. The exact time is unspecified and established by institution convention or patient interpretation. code "AFT": 'AFT' from EventTiming // Afternoon Event occurs during the afternoon. The exact time is unspecified and established by institution convention or patient interpretation. code "AFT.early": 'AFT.early' from EventTiming // Early Afternoon Event occurs during the early afternoon. The exact time is unspecified and established by institution convention or patient interpretation. code "AFT.late": 'AFT.late' from EventTiming // Late Afternoon Event occurs during the late afternoon. The exact time is unspecified and established by institution convention or patient interpretation. code "EVE": 'EVE' from EventTiming // Evening Event occurs during the evening. The exact time is unspecified and established by institution convention or patient interpretation. code "EVE.early": 'EVE.early' from EventTiming // Early Evening Event occurs during the early evening. The exact time is unspecified and established by institution convention or patient interpretation. code "EVE.late": 'EVE.late' from EventTiming // Late Evening Event occurs during the late evening. The exact time is unspecified and established by institution convention or patient interpretation. code "NIGHT": 'NIGHT' from EventTiming // Night Event occurs during the night. The exact time is unspecified and established by institution convention or patient interpretation. code "PHS": 'PHS' from EventTiming // After Sleep Event occurs [offset] after subject goes to sleep. The exact time is unspecified and established by institution convention or patient interpretation. code "Every eight hours (qualifier value)": '307469008' from QICoreCommon."SNOMEDCT" display 'Every eight hours (qualifier value)' code "Every eight to twelve hours (qualifier value)": '396140003' from QICoreCommon."SNOMEDCT" display 'Every eight to twelve hours (qualifier value)' code "Every forty eight hours (qualifier value)": '396131002' from QICoreCommon."SNOMEDCT" display 'Every forty eight hours (qualifier value)' code "Every forty hours (qualifier value)": '396130001' from QICoreCommon."SNOMEDCT" display 'Every forty hours (qualifier value)' code "Every four hours (qualifier value)": '225756002' from QICoreCommon."SNOMEDCT" display 'Every four hours (qualifier value)' code "Every seventy two hours (qualifier value)": '396143001' from QICoreCommon."SNOMEDCT" display 'Every seventy two hours (qualifier value)' code "Every six hours (qualifier value)": '307468000' from QICoreCommon."SNOMEDCT" display 'Every six hours (qualifier value)' code "Every six to eight hours (qualifier value)": '396139000' from QICoreCommon."SNOMEDCT" display 'Every six to eight hours (qualifier value)' code "Every thirty six hours (qualifier value)": '396126004' from QICoreCommon."SNOMEDCT" display 'Every thirty six hours (qualifier value)' code "Every three to four hours (qualifier value)": '225754004' from QICoreCommon."SNOMEDCT" display 'Every three to four hours (qualifier value)' code "Every three to six hours (qualifier value)": '396127008' from QICoreCommon."SNOMEDCT" display 'Every three to six hours (qualifier value)' code "Every twelve hours (qualifier value)": '307470009' from QICoreCommon."SNOMEDCT" display 'Every twelve hours (qualifier value)' code "Every twenty four hours (qualifier value)": '396125000' from QICoreCommon."SNOMEDCT" display 'Every twenty four hours (qualifier value)' code "Every two to four hours (qualifier value)": '225752000' from QICoreCommon."SNOMEDCT" display 'Every two to four hours (qualifier value)' code "Four times daily (qualifier value)": '307439001' from QICoreCommon."SNOMEDCT" display 'Four times daily (qualifier value)' code "Once daily (qualifier value)": '229797004' from QICoreCommon."SNOMEDCT" display 'Once daily (qualifier value)' code "One to four times a day (qualifier value)": '396109005' from QICoreCommon."SNOMEDCT" display 'One to four times a day (qualifier value)' code "One to three times a day (qualifier value)": '396108002' from QICoreCommon."SNOMEDCT" display 'One to three times a day (qualifier value)' code "One to two times a day (qualifier value)": '396107007' from QICoreCommon."SNOMEDCT" display 'One to two times a day (qualifier value)' code "Three times daily (qualifier value)": '229798009' from QICoreCommon."SNOMEDCT" display 'Three times daily (qualifier value)' code "Twice a day (qualifier value)": '229799001' from QICoreCommon."SNOMEDCT" display 'Twice a day (qualifier value)' code "Two to four times a day (qualifier value)": '396111001' from QICoreCommon."SNOMEDCT" display 'Two to four times a day (qualifier value)' parameter "Measurement Period" Interval parameter ErrorLevel String default 'Warning' context Patient define "Initial Population 1": AgeInYearsAt(date from start of "Intake Period")>= 6 and AgeInYearsAt(date from end of "Intake Period" )<= 12 and exists "Qualifying Encounter" and "First ADHD Medication Prescribed During Intake Period" is not null and not exists "Inpatient Stay with Qualifying Diagnosis During Initiation Phase" define "Intake Period": Interval["March 1 of Year Prior to Measurement Period", "Last Calendar Day of February of Measurement Period"] define "Last Calendar Day of February of Measurement Period": ( DateTime(year from start of "Measurement Period", 3, 1, 23, 59, 59, 0, 0)) - 1 day define "March 1 of Year Prior to Measurement Period": DateTime((year from start of "Measurement Period" - 1), 3, 1, 0, 0, 0, 0, 0) define "Qualifying Encounter": ( ["Encounter": "Office Visit"] union ["Encounter": "Home Healthcare Services"] union ["Encounter": "Preventive Care, Established Office Visit, 0 to 17"] union ["Encounter": "Preventive Care Services, Initial Office Visit, 0 to 17"] ) ValidEncounters where QICoreCommon."ToInterval" ( ValidEncounters.period ) during day of Interval["IPSD" - 6 months, "IPSD"] /*Index Prescription Start Date (IPSD)*/ define "IPSD": "First ADHD Medication Prescribed During Intake Period" define "First ADHD Medication Prescribed During Intake Period": First("ADHD Medication Prescribed During Intake Period and Not Previously on ADHD Medication".startDate) /*Note relevantPeriod.low represents the interval's lower boundary and its usage is to ensure appropriate evaluation of the coalesce.*/ define "ADHD Medication Prescribed During Intake Period and Not Previously on ADHD Medication": ( ( ( ["MedicationRequest": "Atomoxetine"] union ["MedicationRequest": "Clonidine"] union ["MedicationRequest": "Dexmethylphenidate"] union ["MedicationRequest": "Dextroamphetamine"] union ["MedicationRequest": "Lisdexamfetamine"] union ["MedicationRequest": "methamphetamine hydrochloride 5 MG Oral Tablet"] union ["MedicationRequest": "Methylphenidate"] union ["MedicationRequest": "Guanfacine"] ) ADHDMedications where CMD."MedicationRequestPeriod"(ADHDMedications) starts during "Intake Period" ) ADHDMedicationOrder without ( ["MedicationRequest": "Atomoxetine"] union ["MedicationRequest": "Clonidine"] union ["MedicationRequest": "Dexmethylphenidate"] union ["MedicationRequest": "Dextroamphetamine"] union ["MedicationRequest": "Lisdexamfetamine"] union ["MedicationRequest": "methamphetamine hydrochloride 5 MG Oral Tablet"] union ["MedicationRequest": "Methylphenidate"] union ["MedicationRequest": "Guanfacine"] ) ActiveADHDMedication such that CMD."MedicationRequestPeriod"(ActiveADHDMedication) overlaps Interval[date from start of CMD."MedicationRequestPeriod"(ADHDMedicationOrder) - 120 days, date from start of CMD."MedicationRequestPeriod"(ADHDMedicationOrder)) ) QualifyingMed return all { startDate: start of CMD."MedicationRequestPeriod"(QualifyingMed) } sort by startDate asc define "Inpatient Stay with Qualifying Diagnosis During Initiation Phase": "Inpatient Stay with Qualifying Diagnosis" InpatientStay where CQMCommon."ToDateInterval" ( InpatientStay.period ) starts 30 days or less after day of "IPSD" define "Inpatient Stay with Qualifying Diagnosis": ["Encounter": "Encounter Inpatient"] InpatientStay where exists (( "PrincipalDiagnosis"(InpatientStay)) EncounterDiagnosis where EncounterDiagnosis.code in "Mental Behavioral and Neurodevelopmental Disorders") define function "PrincipalDiagnosis"(Encounter Encounter ): (Encounter.diagnosis D where D.rank = 1) PD return singleton from ([Condition] C where C.id = PD.condition.reference.getId()) define "Denominator 1": "Initial Population 1" define "Denominator Exclusions": Hospice."Has Hospice Services" or exists ( "Narcolepsy Exclusion" ) define "Narcolepsy Exclusion": ["Condition": "Narcolepsy"] Narcolepsy where QICoreCommon."ToPrevalenceInterval"(Narcolepsy) starts on or before end of "Measurement Period" define "Numerator 1": exists ( "Encounter During Initiation Phase" ) define "Encounter During Initiation Phase": "Qualifying Numerator Encounter" ValidNumeratorEncounter where CQMCommon."ToDateInterval" ( ValidNumeratorEncounter.period ) starts 30 days or less after day of "IPSD" define "Qualifying Numerator Encounter": ( ["Encounter": "Office Visit"] union ["Encounter": "Initial Hospital Observation Care"] union ["Encounter": "Preventive Care Services Group Counseling"] union ["Encounter": "Behavioral Health Follow up Visit"] union ["Encounter": "Preventive Care Services Individual Counseling"] union ( ["Encounter": "Psychotherapy and Pharmacologic Management"] PsychPharmManagement where exists ( PsychPharmManagement.location Location where CQMCommon."GetLocation"(Location.location).type in "Ambulatory" ) ) union ["Encounter": "Outpatient Consultation"] union ["Encounter": "Home Healthcare Services"] union ["Encounter": "Preventive Care Services, Initial Office Visit, 0 to 17"] union ["Encounter": "Preventive Care, Established Office Visit, 0 to 17"] union ["Encounter": "Psych Visit Diagnostic Evaluation"] union ["Encounter": "Psych Visit Psychotherapy"] union ["Encounter": "Telephone Visits"] ) define "Initial Population 2": AgeInYearsAt(date from start of "Intake Period")>= 6 and AgeInYearsAt(date from end of "Intake Period" )<= 12 and exists "Qualifying Encounter" and "First ADHD Medication Prescribed During Intake Period" is not null and "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days" and not exists "Inpatient Stay with Qualifying Diagnosis During Continuation and Maintenance Phase" define "Has ADHD Cumulative Medication Duration Greater Than or Equal to 210 Days": "ADHD Cumulative Medication Duration" >= 210 define "ADHD Cumulative Medication Duration": "CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" ) // define "ADHD Cumulative Medication Duration": // CMD."CumulativeDuration" ( "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase" ) define "Inpatient Stay with Qualifying Diagnosis During Continuation and Maintenance Phase": "Inpatient Stay with Qualifying Diagnosis" InpatientStay where CQMCommon."ToDateInterval" ( InpatientStay.period ) starts 300 days or less after day of "IPSD" define function ToDaily(frequency System.Integer, period System.Quantity): case period.unit when 'h' then frequency * (24.0 / period.value) when 'min' then frequency * (24.0 / period.value) * 60 when 's' then frequency * (24.0 / period.value) * 60 * 60 when 'd' then frequency * (24.0 / period.value) / 24 when 'wk' then frequency * (24.0 / period.value) / (24 * 7) when 'mo' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'a' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ when 'hour' then frequency * (24.0 / period.value) when 'minute' then frequency * (24.0 / period.value) * 60 when 'second' then frequency * (24.0 / period.value) * 60 * 60 when 'day' then frequency * (24.0 / period.value) / 24 when 'week' then frequency * (24.0 / period.value) / (24 * 7) when 'month' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'year' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ when 'hours' then frequency * (24.0 / period.value) when 'minutes' then frequency * (24.0 / period.value) * 60 when 'seconds' then frequency * (24.0 / period.value) * 60 * 60 when 'days' then frequency * (24.0 / period.value) / 24 when 'weeks' then frequency * (24.0 / period.value) / (24 * 7) when 'months' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'years' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ else Message(null, true, 'CMDLogic.ToDaily.UnknownUnit', ErrorLevel, 'Unknown unit ' & period.unit) end /* Returns a daily frequency for the given code representation of frequency. The function expects codes from the [EventTiming](http://hl7.org/fhir/codesystem-event-timing.html) or [V3TimingEvent](http://hl7.org/fhir/v3/TimingEvent/cs.html) code systems. // TODO: Determine whether or not we should use timing.code at all.... */ define function ToDaily(frequency Code): case when frequency ~ "HS" then 1 // event occurs [offset] before the hour of sleep (or trying to) when frequency ~ "WAKE" then 1 // event occurs [offset] after waking when frequency ~ "C" then 3 // event occurs at a meal (from the Latin cibus) when frequency ~ "CM" then 1 // event occurs at breakfast (from the Latin cibus matutinus) when frequency ~ "CD" then 1 // event occurs at lunch (from the Latin cibus diurnus) when frequency ~ "CV" then 1 // event occurs at dinner (from the Latin ante cibus vespertinus) when frequency ~ "AC" then 3 // event occurs [offset] before a meal (from the Latin ante cibus) when frequency ~ "ACM" then 1 // event occurs [offset] before breakfast (from the Latin ante cibus matutinus) when frequency ~ "ACD" then 1 // event occurs [offset] before lunch (from the Latin ante cibus diurnus) when frequency ~ "ACV" then 1 // event occurs [offset] before dinner (from the Latin ante cibus vespertinus) when frequency ~ "PC" then 3 // event occurs [offset] after a meal (from the Latin post cibus) when frequency ~ "PCM" then 1 // event occurs [offset] after breakfast (from the Latin post cibus matutinus) when frequency ~ "PCD" then 1 // event occurs [offset] after lunch (from the Latin post cibus diurnus) when frequency ~ "PCV" then 1 // event occurs [offset] after dinner (from the Latin post cibus vespertinus) when frequency ~ "MORN" then 1 // Event occurs during the morning. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "MORN.early" then 1 // Early Morning Event occurs during the early morning. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "MORN.late" then 1 // Late Morning Event occurs during the late morning. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "NOON" then 1 // Noon Event occurs around 12:00pm. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "AFT" then 1 // Afternoon Event occurs during the afternoon. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "AFT.early" then 1 // Early Afternoon Event occurs during the early afternoon. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "AFT.late" then 1 // Late Afternoon Event occurs during the late afternoon. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "EVE" then 1 // Evening Event occurs during the evening. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "EVE.early" then 1 // Early Evening Event occurs during the early evening. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "EVE.late" then 1 // Late Evening Event occurs during the late evening. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "NIGHT" then 1 // Night Event occurs during the night. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "PHS" then 1 // After Sleep Event occurs [offset] after subject goes to sleep. The exact time is unspecified and established by institution convention or patient interpretation. when frequency ~ "Once daily (qualifier value)" then 1.0 when frequency ~ "Twice a day (qualifier value)" then 2.0 when frequency ~ "Three times daily (qualifier value)" then 3.0 when frequency ~ "Four times daily (qualifier value)" then 4.0 when frequency ~ "Every twenty four hours (qualifier value)" then 1.0 when frequency ~ "Every twelve hours (qualifier value)" then 2.0 when frequency ~ "Every thirty six hours (qualifier value)" then 0.67 when frequency ~ "Every eight hours (qualifier value)" then 3.0 when frequency ~ "Every four hours (qualifier value)" then 6.0 when frequency ~ "Every six hours (qualifier value)" then 4.0 when frequency ~ "Every seventy two hours (qualifier value)" then 0.33 when frequency ~ "Every forty eight hours (qualifier value)" then 0.5 when frequency ~ "Every eight to twelve hours (qualifier value)" then 3.0 when frequency ~ "Every six to eight hours (qualifier value)" then 4.0 when frequency ~ "Every three to four hours (qualifier value)" then 8.0 when frequency ~ "Every three to six hours (qualifier value)" then 8.0 when frequency ~ "Every two to four hours (qualifier value)" then 12.0 when frequency ~ "One to four times a day (qualifier value)" then 4.0 when frequency ~ "One to three times a day (qualifier value)" then 3.0 when frequency ~ "One to two times a day (qualifier value)" then 2.0 when frequency ~ "Two to four times a day (qualifier value)" then 4.0 else Message(null, true, 'CMDLogic.ToDaily.UnknownFrequencyCode', ErrorLevel, 'Unknown frequency code ' & frequency.code) end // define function MedicationRequestPeriod(Request "MedicationRequest"): // Request R // let // dosage: singleton from R.dosageInstruction, // doseAndRate: singleton from dosage.doseAndRate, // timing: dosage.timing, // frequency: Coalesce(timing.repeat.frequencyMax, timing.repeat.frequency), // period: Quantity(timing.repeat.period, timing.repeat.periodUnit), // doseRange: doseAndRate.dose, // doseQuantity: doseAndRate.dose, // dose: Coalesce(end of doseRange, doseQuantity), // dosesPerDay: Coalesce(ToDaily(frequency, period), Count(timing.repeat.timeOfDay), 1.0), // boundsPeriod: timing.repeat.bounds as Interval, // daysSupply: (convert R.dispenseRequest.expectedSupplyDuration to days).value, // quantity: R.dispenseRequest.quantity, // refills: Coalesce(R.dispenseRequest.numberOfRepeatsAllowed, 0), // startDate: // Coalesce( // date from start of boundsPeriod, // date from R.authoredOn, // date from start of R.dispenseRequest.validityPeriod // ), // totalDaysSupplied: Coalesce(daysSupply, quantity.value / (dose.value * dosesPerDay)) * (1 + refills) // return // if startDate is not null and totalDaysSupplied is not null then // Interval[startDate, startDate + Quantity(totalDaysSupplied - 1, 'day') ] // else if startDate is not null and boundsPeriod."high" is not null then // Interval[startDate, end of boundsPeriod] // else // null define function MedicationRequestPeriod(Request "MedicationRequest"): Request R let dosage: singleton from R.dosageInstruction, doseAndRate: singleton from dosage.doseAndRate, timing: dosage.timing, frequency: Coalesce(timing.repeat.frequencyMax, timing.repeat.frequency), period: Quantity(timing.repeat.period, timing.repeat.periodUnit), doseRange: doseAndRate.dose, doseQuantity: doseAndRate.dose, dose: Coalesce(end of doseRange, doseQuantity), dosesPerDay: Coalesce(ToDaily(frequency, period), Count(timing.repeat.timeOfDay), 1.0), boundsPeriod: timing.repeat.bounds as Interval, daysSupply: (convert R.dispenseRequest.expectedSupplyDuration to days).value, quantity: R.dispenseRequest.quantity, refills: Coalesce(R.dispenseRequest.numberOfRepeatsAllowed, 0), startDate: Coalesce( date from start of boundsPeriod, date from R.authoredOn, date from start of R.dispenseRequest.validityPeriod ), totalDaysSupplied: Coalesce(daysSupply, quantity.value / (dose.value * dosesPerDay)) * (1 + refills) return if startDate is not null and totalDaysSupplied is not null then Interval[startDate, startDate + Quantity(totalDaysSupplied - 1, 'day') ] else if startDate is not null and boundsPeriod."high" is not null then Interval[startDate, date from end of boundsPeriod] else null // define function RolloutIntervals(intervals List>): // intervals I aggregate all R starting ( null as List>): R // union ( { I X // let S: Max({ // end of Last(R)+ 1 day, start of X } // ), // E: S + Quantity(Coalesce(duration in days of X, 0), 'day') // return Interval[S, E]} // ) define function CumulativeDuration(Intervals List>): if Intervals is not null then ( Sum((collapse Intervals per day)X return all(difference in days between start of X and end of X )+ 1 ) ) else null define function RolloutIntervals(intervals List>): intervals I aggregate all R starting ( null as List>): R union ( { I X let S: Max({ end of Last(R)+ 1 day, start of X } ), E: S + Quantity(Coalesce(duration in days of X, 0), 'day') return Interval[S, E]} ) define function Quantity(value Decimal, unit String): if value is not null then System.Quantity { value: value, unit: unit } else null define "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase": ( ( "RolloutIntervals" ( ( ["MedicationRequest": "Atomoxetine"] AtomoxetineMed return all { period: "MedicationRequestPeriod" ( AtomoxetineMed ), periodStart: start of "MedicationRequestPeriod" ( AtomoxetineMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Clonidine"] ClonidineMed return all { period: "MedicationRequestPeriod" ( ClonidineMed ), periodStart: start of "MedicationRequestPeriod" ( ClonidineMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Dexmethylphenidate"] DexmethylphenidateMed return all { period: "MedicationRequestPeriod" ( DexmethylphenidateMed ), periodStart: start of "MedicationRequestPeriod" ( DexmethylphenidateMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Dextroamphetamine"] DextroamphetamineMed return all { period: "MedicationRequestPeriod" ( DextroamphetamineMed ), periodStart: start of "MedicationRequestPeriod" ( DextroamphetamineMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Lisdexamfetamine"] LisdexamfetamineMed return all { period: "MedicationRequestPeriod" ( LisdexamfetamineMed ), periodStart: start of "MedicationRequestPeriod" ( LisdexamfetamineMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Methylphenidate"] MethylphenidateMed return all { period: "MedicationRequestPeriod" ( MethylphenidateMed ), periodStart: start of "MedicationRequestPeriod" ( MethylphenidateMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "Guanfacine"] GuanfacineMed return all { period: "MedicationRequestPeriod" ( GuanfacineMed ), periodStart: start of "MedicationRequestPeriod" ( GuanfacineMed ) } sort by periodStart ).period ) ) union ( "RolloutIntervals" ( ( ["MedicationRequest": "methamphetamine hydrochloride 5 MG Oral Tablet"] MethamphetamineMed return all { period: "MedicationRequestPeriod" ( MethamphetamineMed ), periodStart: start of "MedicationRequestPeriod" ( MethamphetamineMed ) } sort by periodStart ).period ) )) ADHDMedication let IPSDAndContinuationMaintenancePhase: Interval["IPSD", "IPSD" + 300 days] return all ADHDMedication intersect IPSDAndContinuationMaintenancePhase // define "ADHD Medications Taken on IPSD or During Continuation and Maintenance Phase": // ( ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Atomoxetine"] AtomoxetineMed // return all { // period: CMD."MedicationRequestPeriod" ( AtomoxetineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( AtomoxetineMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Clonidine"] ClonidineMed // return all { // period: CMD."MedicationRequestPeriod" ( ClonidineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( ClonidineMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Dexmethylphenidate"] DexmethylphenidateMed // return all { // period: CMD."MedicationRequestPeriod" ( DexmethylphenidateMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( DexmethylphenidateMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Dextroamphetamine"] DextroamphetamineMed // return all { // period: CMD."MedicationRequestPeriod" ( DextroamphetamineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( DextroamphetamineMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Lisdexamfetamine"] LisdexamfetamineMed // return all { // period: CMD."MedicationRequestPeriod" ( LisdexamfetamineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( LisdexamfetamineMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Methylphenidate"] MethylphenidateMed // return all { // period: CMD."MedicationRequestPeriod" ( MethylphenidateMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( MethylphenidateMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "Guanfacine"] GuanfacineMed // return all { // period: CMD."MedicationRequestPeriod" ( GuanfacineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( GuanfacineMed ) // } // sort by periodStart // ).period ) // ) // union ( CMD."RolloutIntervals" ( ( ["MedicationRequest": "methamphetamine hydrochloride 5 MG Oral Tablet"] MethamphetamineMed // return all { // period: CMD."MedicationRequestPeriod" ( MethamphetamineMed ), // periodStart: start of CMD."MedicationRequestPeriod" ( MethamphetamineMed ) // } // sort by periodStart // ).period ) // )) ADHDMedication // let IPSDAndContinuationMaintenancePhase: Interval["IPSD", "IPSD" + 300 days] // return all ADHDMedication // intersect IPSDAndContinuationMaintenancePhase define "Denominator 2": "Initial Population 2" define "Numerator 2": exists ( "Encounter During Initiation Phase" ) and ( ( "Two or More Encounters 31 to 300 Days into Continuation and Maintenance Phase" ) or ( exists ( "Encounter 31 to 300 Days into Continuation and Maintenance Phase" Encounter1 with "Online Assessment 31 to 300 Days into Continuation and Maintenance Phase" Encounter2 such that Encounter1 is not null and Encounter2 is not null and Encounter1 !~ Encounter2 ) ) ) define "Two or More Encounters 31 to 300 Days into Continuation and Maintenance Phase": Count("Encounter 31 to 300 Days into Continuation and Maintenance Phase")>= 2 define "Encounter 31 to 300 Days into Continuation and Maintenance Phase": "Qualifying Numerator Encounter" ValidNumeratorEncounter where CQMCommon."ToDateInterval" ( ValidNumeratorEncounter.period ) starts during day of Interval["IPSD" + 31 days, "IPSD" + 300 days] return date from start of ValidNumeratorEncounter.period define "Online Assessment 31 to 300 Days into Continuation and Maintenance Phase": ["Encounter": "Online Assessments"] OnlineAssessment where CQMCommon."ToDateInterval" ( OnlineAssessment.period ) starts during day of Interval["IPSD" + 31 days, "IPSD" + 300 days] return date from start of OnlineAssessment.period define "SDE Ethnicity": SDE."SDE Ethnicity" define "SDE Payer": SDE."SDE Payer" define "SDE Race": SDE."SDE Race" define "SDE Sex": SDE."SDE Sex"