WHO SMART Guidelines - HIV
0.4.4 - ci-build

WHO SMART Guidelines - HIV, published by WHO. This guide is not an authorized publication; it is the continuous build for version 0.4.4 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/WorldHealthOrganization/smart-hiv/tree/main and changes regularly. See the Directory of published versions

Measure: HIV.IND.5 Number of PEP recipients (Experimental)

Official URL: http://smart.who.int/hiv/Measure/HIVIND5 Version: 0.4.4
Draft as of 2024-08-18 Computable Name: HIVIND5

Number of people prescribed PEP during the reporting period

Knowledge Artifact Metadata
Name (machine-readable) HIVIND5
Title (human-readable) HIV.IND.5 Number of PEP recipients
Status Draft
Experimental true
Description

Number of people prescribed PEP during the reporting period

Measure Steward WHO
Steward Contact Details WHO: http://who.int
Measure Metadata
Version Number 0.4.4
Measure Scoring Continuous Variable
Improvement Notation Increased score indicates improvement
Population Basis boolean
Measure Population Criteria
Initial Population ID: HIV.IND.5.IP
Description:

Initial Population

Logic Definition: Initial Population
Measure Population ID: HIV.IND.5.MP
Description:

Measure Population

Logic Definition: Measure Population
Measure Observation ID: HIV.IND.5.MO
Description:

Measure Observation

Logic Definition: Measure Observation
Stratifier ID: HIV.IND.5.S
Measure Logic
Primary Library HIV.IND.5 Logic
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 HIE
Resource: HIVIndicatorElements
Canonical URL: http://smart.who.int/hiv/Library/HIVIndicatorElements
Dependency Description: Library FHIRHelpers
Resource: http://fhir.org/guides/cqf/common/Library/FHIRHelpers|4.0.1
Canonical URL: http://fhir.org/guides/cqf/common/Library/FHIRHelpers|4.0.1
Dependency Description: Library Concepts
Resource: http://smart.who.int/hiv/Library/HIVConcepts|0.0.2
Canonical URL: http://smart.who.int/hiv/Library/HIVConcepts|0.0.2
Dependency Description: Library Elements
Resource: HIVElements
Canonical URL: http://smart.who.int/hiv/Library/HIVElements
Dependency Description: Library ConceptsCustom
Resource: http://smart.who.int/hiv/Library/HIVConceptsCustom|0.0.1
Canonical URL: http://smart.who.int/hiv/Library/HIVConceptsCustom|0.0.1
Dependency Description: Library WC
Resource: WHOCommon
Canonical URL: http://smart.who.int/hiv/Library/WHOCommon
Dependency Description: Library Common
Resource: HIVCommon
Canonical URL: http://smart.who.int/hiv/Library/HIVCommon
Dependency Description: Code system HIVConcepts
Resource: WHO SMART HIV Concepts CodeSystem
Canonical URL: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Dependency Description: Code system ObservationCategoryCodes
Resource: Observation Category Codes
Canonical URL: http://terminology.hl7.org/CodeSystem/observation-category
Direct Reference Code Display: Male
Code: HIV.A.DE20
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Female
Code: HIV.A.DE19
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Transgender female
Code: HIV.A.DE22
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Transgender male
Code: HIV.A.DE21
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Other
Code: HIV.A.DE23
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Key population member*
Code: HIV.B.DE49
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Social History
Code: social-history
System: http://terminology.hl7.org/CodeSystem/observation-category
Direct Reference Code Display: Community-level testing
Code: HIV.B.DE16
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Rapid diagnostic test for HIV
Code: HIV.B.DE82
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Facility-level testing
Code: HIV.B.DE17
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Currently on PrEP
Code: HIV.C.DE10
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: PrEP for HIV prevention
Code: HIV.C.DE76
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: TDF + FTC
Code: HIV.C.DE18
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: TDF
Code: HIV.C.DE19
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: TDF + 3TC
Code: HIV.C.DE20
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Other TDF-based regimen
Code: HIV.C.DE21
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Dapivirine vaginal ring DVR
Code: HIV.C.DE22
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: CAB-LA
Code: HIV.C.DE23
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: HIV exposure type*
Code: HIV.B.DE61
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Occupational
Code: HIV.B.DE62
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Non-occupational violent
Code: HIV.B.DE63
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: Non-occupational consensual sex
Code: HIV.B.DE64
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Direct Reference Code Display: PEP for HIV prevention
Code: HIV.C.DE77
System: http://smart.who.int/hiv/CodeSystem/HIVConcepts
Parameter Name: Measurement Period
Use: In
Min Cardinality: 0
Max Cardinality: 1
Type: Period
Parameter Name: Initial Population
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: Stratification
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Measure Population
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Measure Logic Data Requirements
Data Requirement Type: Patient
Profile(s): Patient
Must Support Elements: use
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, status, category, effective, issued, code.coding
Code Filter(s):
Path: code
Code:
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: encounter, status, code, issued
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, status, category, value
Code Filter(s):
Path: code
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: location
Data Requirement Type: MedicationStatement
Profile(s): MedicationStatement
Must Support Elements: status, reasonCode, medication, effective
Data Requirement Type: MedicationRequest
Profile(s): MedicationRequest
Must Support Elements: status, intent, medication, dosageInstruction, dispenseRequest, dispenseRequest.expectedSupplyDuration, dispenseRequest.quantity, dispenseRequest.numberOfRepeatsAllowed, dispenseRequest.validityPeriod, authoredOn
Measure Logic Definitions
Logic Definition Library Name: HIVIND5Logic
/*
 * As defined by Member States
 */
define "Initial Population":
  true
Logic Definition Library Name: HIVIndicatorElements
/*
@dataElement: HIV.A.DE18 - Gender
@activity: HIV.A6.1 Review sociodemographic data with client | HIV.A5 Create new client record
@description: Gender of the client
*/

/*
 * By Administrative Gender of Patient Stratifier
 * Need to expand codes
 */

define "By Administrative Gender Stratifier":
  case 
      when Patient.gender = 'male' then Concepts."Male"
      when Patient.gender = 'female' then Concepts."Female"
      when Patient.gender = 'transgender female' then Concepts."Transgender female"
      when Patient.gender = 'transgender male' then Concepts."Transgender male"
      else Concepts."Other - HIV.A.DE23"
  end
Logic Definition Library Name: HIVIndicatorElements
/* End of Visit date A.DE3 */

/*
@dataElement: HIV.A.DE17 - Age
@activity: HIV.A6.1 Review sociodemographic data with client | HIV.A5 Create new client record
@description: Calculated age (number of years) of the client based on date of birth
*/
define "Age In Years":
  AgeInYearsAt(start of "Measurement Period")
Logic Definition Library Name: HIVIndicatorElements
define "By Age Stratifier 3":
  case 
      when "Age In Years" >= 15 and "Age In Years"<= 19 then '15-19'
      when "Age In Years" <= 24 then '20-24'
      when "Age In Years" <= 49 then '25–49'
      when "Age In Years" >= 50 then '50+'
      else null
  end
Logic Definition Library Name: HIVIndicatorElements
// Geographic Region
define "By Geographic Region Stratifier":
    First(Patient.address A where A.use in { 'home' }).state
Logic Definition Library Name: HIVElements
/* End of Key population member B.DE49 */

/*
@dataElement: HIV.B.DE50 - Key population member type
@activity: HIV.B6 Capture or update client history
@description: The type of key population that the client is included in
*/
define "Key population member type Observation":
  [Observation: Concepts."Key population member - HIV.B.DE49"] O
    where O.status in { 'final', 'amended', 'corrected' }
    and exists(O.category OC where OC ~ ConceptsCustom."social-history")
Logic Definition Library Name: HIVIndicatorElements
define "Key population member type Observation":
  Elements."Key population member type Observation" O
    where O.effective.toInterval() before end of "Measurement Period"
    or O.issued before end of "Measurement Period"
Logic Definition Library Name: HIVIndicatorElements
// Stratifier
define patientGroups:
  "Key population member type Observation" O
  return Combine(O.code.coding.code, ':')
Logic Definition Library Name: HIVIndicatorElements
/**
 * HIV Elements
 */

/* General Data Elements */

// From Common

define "Community_testing":
  exists([Observation] O
    with [Encounter] E
      such that O.encounter.references(E) and exists(E.location.physicalType PT where PT ~  Concepts."Community-level testing") 
  where (O.status in { 'final', 'amended' }
  and O.code ~ Concepts."Rapid diagnostic test for HIV - HIV.B.DE82"
  and O.issued after start of "Measurement Period"
  and O.issued before end of "Measurement Period"))
Logic Definition Library Name: HIVIndicatorElements
/*@triggeredBy Encounter with location = facility level testing*/
define "Facility_testing":
  exists([Observation] O
    with [Encounter] E
      such that O.encounter.references(E) and exists(E.location.physicalType PT where PT ~  Concepts."Facility-level testing")
  where (O.status in { 'final', 'amended' }
  and O.code ~ Concepts."Rapid diagnostic test for HIV - HIV.B.DE82"
  and O.issued after start of "Measurement Period"
  and O.issued before end of "Measurement Period")
  )
Logic Definition Library Name: HIVIndicatorElements
define setting:
  case
    when Community_testing then Concepts."Community-level testing"
    when Facility_testing then Concepts."Facility-level testing"
    else null
  end
Logic Definition Library Name: HIVElements
/* End of Date/time of suspected exposure to HIV C.DE9 */

/*
@dataElement: HIV.C.DE10 - Currently on PrEP
@activity: HIV.C3 Capture or update client history
@description: The client is currently taking PrEP. Oral pre-exposure prophylaxis (PrEP) of HIV is the use of ARV drugs by people who are not infected with HIV to block the acquisition of HIV.
*/

/*@triggeredBy Encounter with location = community level testing*/

define "Currently on PrEP":
  [MedicationStatement] MS
    where MS.status = 'completed'
    and exists(MS.reasonCode C where C ~ Concepts."Currently on PrEP")
    and MS.medication ~ Concepts."PrEP for HIV prevention"
Logic Definition Library Name: HIVElements
/* End of Current PrEP regimen */

/*
@dataElement: HIV.C.DE18 - TDF + FTC
@activity: HIV.C3 Capture or update client history
@description: Treated with tenofovir disoproxil fumarate (TDF) and emtricitabine (FTC) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF + FTC C.DE18":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."TDF + FTC - HIV.C.DE18"
Logic Definition Library Name: HIVIndicatorElements
/* End of Other PrEP dosing type */

/*
@dataElement: HIV.C.DE18 - TDF + FTC
@activity: HIV.C3 Capture or update client history
@description: Treated with tenofovir disoproxil fumarate (TDF) and emtricitabine (FTC) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF + FTC C.DE18":
  exists (Elements."TDF + FTC C.DE18" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVElements
/* End of TDF + FTC C.DE18 */

/*
@dataElement: HIV.C.DE19 - TDF
@activity: HIV.C3 Capture or update client history
@description: Treated with single-agent tenofovir disoproxil fumarate (TDF) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF C.DE19":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."TDF - HIV.C.DE19"
Logic Definition Library Name: HIVIndicatorElements
/* End of TDF + FTC C.DE18 */

/*
@dataElement: HIV.C.DE19 - TDF
@activity: HIV.C3 Capture or update client history
@description: Treated with single-agent tenofovir disoproxil fumarate (TDF) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF C.DE19":
  exists (Elements."TDF C.DE19" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVElements
/* End of TDF C.DE19 */

/*
@dataElement: HIV.C.DE20 - TDF + 3TC
@activity: HIV.C3 Capture or update client history
@description: Treated with tenofovir disoproxil fumarate (TDF) and lamivudine (3TC) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF + 3TC C.DE20":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."TDF + 3TC - HIV.C.DE20"
Logic Definition Library Name: HIVIndicatorElements
/* End of TDF C.DE19 */

/*
@dataElement: HIV.C.DE20 - TDF + 3TC
@activity: HIV.C3 Capture or update client history
@description: Treated with tenofovir disoproxil fumarate (TDF) and lamivudine (3TC) pre-exposure prophylaxis (PrEP) regimen (oral PrEP)
*/

define "TDF + 3TC C.DE20":
  exists (Elements."TDF + 3TC C.DE20" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVElements
/* End of TDF + 3TC C.DE20 */

/*
@dataElement: HIV.C.DE21 - Other TDF-based regimen
@activity: HIV.C3 Capture or update client history
@description: Treated with other tenofovir disoproxil fumarate (TDF)-based regimen (oral PrEP)
*/

define "Other TDF-based regimen":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."Other TDF-based regimen"
Logic Definition Library Name: HIVIndicatorElements
/* End of TDF + 3TC C.DE20 */

/*
@dataElement: HIV.C.DE21 - Other TDF-based regimen
@activity: HIV.C3 Capture or update client history
@description: Treated with other tenofovir disoproxil fumarate (TDF)-based regimen (oral PrEP)
*/

define "Other TDF-based regimen":
  exists (Elements."Other TDF-based regimen" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVElements
/* End of Other TDF-based regimen */

/*
@dataElement: HIV.C.DE22 - Dapivirine vaginal ring DVR
@activity: HIV.C3 Capture or update client history
@description: Dapivirine vaginal ring (DVR) for HIV prevention
*/

define "Dapivirine vaginal ring DVR C.DE22":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."Dapivirine vaginal ring DVR - HIV.C.DE22"
Logic Definition Library Name: HIVIndicatorElements
/* End of Other TDF-based regimen */

/*
@dataElement: HIV.C.DE22 - Dapivirine vaginal ring DVR
@activity: HIV.C3 Capture or update client history
@description: Dapivirine vaginal ring (DVR) for HIV prevention
*/

define "Dapivirine vaginal ring DVR C.DE22":
  exists (Elements."Dapivirine vaginal ring DVR C.DE22" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVElements
/*
@dataElement: HIV.C.DE23 - CAB-LA
@activity: HIV.C3 Capture or update client history
@description: Long-acting injectable cabotegravir
*/

define "CAB-LA C.DE23":
  "Currently on PrEP" MS
  where MS.medication ~ Concepts."CAB-LA - HIV.C.DE23"
Logic Definition Library Name: HIVIndicatorElements
/*
@dataElement: HIV.C.DE23 - CAB-LA
@activity: HIV.C3 Capture or update client history
@description: Long-acting injectable cabotegravir
*/

define "CAB-LA C.DE23":
  exists (Elements."CAB-LA C.DE23" MS
  where MS.status = 'completed' and MS.effective.toInterval() during "Measurement Period")
Logic Definition Library Name: HIVIndicatorElements
define prep_product:
  List<String>{
    if "TDF + FTC C.DE18" or "TDF C.DE19" or "TDF + 3TC C.DE20" or "Other TDF-based regimen" then 'PREP Product Oral' else null,
    if "Dapivirine vaginal ring DVR C.DE22" then 'PREP Product long-acting device' else null,
    if "CAB-LA C.DE23" then 'PREP Product long-acting injectable' else null
  }
Logic Definition Library Name: HIVElements
/**
 * HIV Elements
 */

/* General Element Definitions */

// From Common

// Exposure to HIV
define Exposure_Occupational:
  exists (
    [Observation: Concepts."HIV exposure type"] O
    where O.status in { 'final', 'amended', 'corrected' }
    and exists(O.category OC where OC ~ ConceptsCustom."social-history")
    and O.value ~ Concepts."Occupational"
  )
Logic Definition Library Name: HIVElements
define Exposure_Non_Occupational_violent:
  exists (
    [Observation: Concepts."HIV exposure type"] O
    where O.status in { 'final', 'amended', 'corrected' }
    and exists(O.category OC where OC ~ ConceptsCustom."social-history")
    and O.value ~ Concepts."Non-occupational violent"
  )
Logic Definition Library Name: HIVElements
define Exposure_Non_Occupational_consensual_sex:
  exists (
    [Observation: Concepts."HIV exposure type"] O
    where O.status in { 'final', 'amended', 'corrected' }
    and exists(O.category OC where OC ~ ConceptsCustom."social-history")
    and O.value ~ Concepts."Non-occupational consensual sex"
  )
Logic Definition Library Name: HIVIndicatorElements
/*
 * Other Stratifiers
 */
define hiv_exposure_type:
  List<String>{
    if Elements.Exposure_Occupational then 'Occupational' else null,
    if Elements.Exposure_Non_Occupational_violent then 'Non-occupational violent' else null,
    if Elements.Exposure_Non_Occupational_consensual_sex then 'Non-occupational consensual sex' else null
  }
Logic Definition Library Name: HIVIND5Logic
//provider type not provided?

define "Stratification":
 HIE."By Administrative Gender Stratifier".code 
  + ':' + HIE."By Age Stratifier 3"
+ ':' + HIE."By Geographic Region Stratifier"
+ Combine(HIE.patientGroups, ':')
 + ':' + HIE."setting".code
+ Combine(HIE.prep_product, ':')
+ Combine(HIE."hiv_exposure_type", ':')
Logic Definition Library Name: HIVElements
/* End of PrEP for HIV prevention */

/*
@dataElement: HIV.C.DE77 - PEP for HIV prevention
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed post-exposure prophylaxis (PEP) for HIV prevention
*/

define "PEP for HIV prevention":
  [MedicationRequest] MR
      where MR.status = 'completed'
      and MR.intent = 'order'
      and MR.medication ~ Concepts."PEP for HIV prevention"
Logic Definition Library Name: HIVIndicatorElements
/* End of PrEP for HIV prevention */

/*
@dataElement: HIV.C.DE77 - PEP for HIV prevention
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed post-exposure prophylaxis (PEP) for HIV prevention
*/

define "PEP for HIV prevention":
  exists(Elements."PEP for HIV prevention" MR
    where MR.MedicationRequestPeriod() during "Measurement Period")
Logic Definition Library Name: HIVIND5Logic
define "Measure Population":
  HIE."PEP for HIV prevention"
Logic Definition Library Name: FHIRHelpers
define function ToString(value AdministrativeGender): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value string): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value AddressUse): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value ObservationStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToConcept(concept FHIR.CodeableConcept):
    if concept is null then
        null
    else
        System.Concept {
            codes: concept.coding C return ToCode(C),
            display: concept.text.value
        }
Logic Definition Library Name: FHIRHelpers
define function ToCode(coding FHIR.Coding):
    if coding is null then
        null
    else
        System.Code {
          code: coding.code.value,
          system: coding.system.value,
          version: coding.version.value,
          display: coding.display.value
        }
Logic Definition Library Name: FHIRHelpers
define function ToDateTime(value instant): value.value
Logic Definition Library Name: WHOCommon
/*
@description: Returns true if the given reference is to the given resource
@comment: Returns true if the `id` element of the given resource exactly equals the tail of the given reference.
NOTE: This function assumes resources from the same source server.
*/
define fluent function references(reference FHIR.Reference, resource FHIR.Resource):
  resource.id = Last(Split(reference.reference, '/'))
Logic Definition Library Name: FHIRHelpers
define function ToString(value MedicationStatementStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value MedicationRequestStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value MedicationRequestIntent): value.value
Logic Definition Library Name: HIVCommon
define fluent function MedicationRequestPeriod(Request MedicationRequest):
  Request R
    let
      dosage: singleton from R.dosageInstruction,
      doseAndRate: singleton from dosage.doseAndRate,
      doseRange: doseAndRate.dose as Range,
      doseQuantity: doseAndRate.dose as SimpleQuantity,
      dose: Coalesce(end of doseRange, doseQuantity),
      timing: dosage.timing,
      frequency: Coalesce(timing.repeat.frequencyMax, timing.repeat.frequency),
      period: System.Quantity { value: timing.repeat.period, unit: timing.repeat.periodUnit.value },
      dosesPerDay: Coalesce(ToDaily(FHIRHelpers.ToInteger(frequency), period), Count(timing.repeat.timeOfDay), 1.0),
      boundsPeriod: timing.repeat.bounds as Period,
      daysSupply: R.dispenseRequest.expectedSupplyDuration,
      quantity: R.dispenseRequest.quantity,
      refills: Coalesce(R.dispenseRequest.numberOfRepeatsAllowed, 0),
      startDate:
        Coalesce(
          start of boundsPeriod,
          start of R.dispenseRequest.validityPeriod,
          R.authoredOn
        )
    return
      if HasEnd(boundsPeriod) then
        Interval[startDate, end of boundsPeriod]
      else
        (
          Coalesce(daysSupply, quantity / (dose * dosesPerDay))
            * (1 + refills)
        ) durationInDays
          return Interval[startDate, startDate + durationInDays]
Logic Definition Library Name: FHIRHelpers
define function ToInterval(range FHIR.Range):
    if range is null then
        null
    else
        Interval[ToQuantity(range.low), ToQuantity(range.high)]
Logic Definition Library Name: FHIRHelpers
define function ToQuantity(quantity FHIR.Quantity):
    case
        when quantity is null then null
        when quantity.value is null then null
        when quantity.comparator is not null then
            Message(null, true, 'FHIRHelpers.ToQuantity.ComparatorQuantityNotSupported', 'Error', 'FHIR Quantity value has a comparator and cannot be converted to a System.Quantity value.')
        when quantity.system is null or quantity.system.value = 'http://unitsofmeasure.org'
              or quantity.system.value = 'http://hl7.org/fhirpath/CodeSystem/calendar-units' then
            System.Quantity { value: quantity.value.value, unit: ToCalendarUnit(Coalesce(quantity.code.value, quantity.unit.value, '1')) }
        else
            Message(null, true, 'FHIRHelpers.ToQuantity.InvalidFHIRQuantity', 'Error', 'Invalid FHIR Quantity code: ' & quantity.unit.value & ' (' & quantity.system.value & '|' & quantity.code.value & ')')
    end
Logic Definition Library Name: FHIRHelpers
define function ToCalendarUnit(unit System.String):
    case unit
        when 'ms' then 'millisecond'
        when 's' then 'second'
        when 'min' then 'minute'
        when 'h' then 'hour'
        when 'd' then 'day'
        when 'wk' then 'week'
        when 'mo' then 'month'
        when 'a' then 'year'
        else unit
    end
Logic Definition Library Name: FHIRHelpers
define function ToDecimal(value decimal): value.value
Logic Definition Library Name: HIVCommon
//System.Integer
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 null
  end
Logic Definition Library Name: FHIRHelpers
define function ToInteger(value integer): value.value
Logic Definition Library Name: FHIRHelpers
define function ToInterval(period FHIR.Period):
    if period is null then
        null
    else
        if period."start" is null then
            Interval(period."start".value, period."end".value]
        else
            Interval[period."start".value, period."end".value]
Logic Definition Library Name: FHIRHelpers
define function ToDateTime(value dateTime): value.value
Logic Definition Library Name: HIVCommon
define function "HasEnd"(period Interval<DateTime> ):
  not (end of period is null
    or end of period = maximum DateTime
)
Logic Definition Library Name: HIVIND5Logic
/*
 * NOTE: Modeled as a Continuous Variable measure because this is an estimated denominator proportion measure
 */

define function "Measure Observation"(Patient "Patient"):
  1
Generated using version 0.4.6 of the sample-content-ig Liquid templates