PATH MER Indicators
0.1.0 - STU1 International flag

PATH MER Indicators, published by PATH. This is not an authorized publication; it is the continuous build for version 0.1.0). This version is based on the current content of https://github.com/PATH-Global-Health/MERindicators and changes regularly. See the Directory of published versions

Library: KenyaEMRStratifiers (Experimental)

Official URL: https://path-global-health.github.io/MERindicators/Library/KenyaEMRStratifiers Version: 0.1.0
Draft as of 2023-10-19 Computable Name: KenyaEMRStratifiers

KenyaEMRStratifiers

Related Artifacts

depends-onhttp://hl7.org/fhir/Library/FHIR-ModelInfo|4.0.1
depends-onhttp://hl7.org/fhir/Library/FHIRHelpers|4.0.1
depends-onFHIRCommon (version 4.0.1)
depends-onKenyaEMRConcepts
depends-onhttp://ohie.org/CodeSystem/kemr-periods

Parameters

Measurement Periodin01Period
Patientout01Patient
Sexout01string
Age Groupout01Coding
Age Group/Sexout01string
Last Locationout01string
OpenMRS Locationout0*string
Last serviceProviderout0*string
Location Deuxout01Resource
Locationout01Resource
Debug locationout01string
Age Group/Sex/Locationout01string
Age Group/Sex/Location TXCURRout01string
Age Group/Sex/Location Case Switchout01string

Data Requirements

Type: Encounter (Encounter)
Type: Patient (Patient)
Type: Encounter (Encounter)
Type: Encounter (Encounter)

Contents

text/cql

library KenyaEMRStratifiers version '0.1.0'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'
include FHIRCommon version '4.0.1' called FC

include KenyaEMRConcepts called Cx


codesystem "KEMR Periods": 'http://ohie.org/CodeSystem/kemr-periods'
code "<1": '<1' from "KEMR Periods" display '<1'
code "1-9": '1-9' from "KEMR Periods" display '1-9'
code "10-14": '10-14' from "KEMR Periods" display '10-14'
code "15-19": '15-19' from "KEMR Periods" display '15-19'
code "20-24": '20-24' from "KEMR Periods" display '20-24'
code "25+": '25+' from "KEMR Periods" display '25+'


parameter "Measurement Period" Interval<DateTime> default Interval[@2023-04-01T00:00:00.0, @2023-06-30T00:00:00.0]


context Patient


define "Sex":
  Patient.gender.value


define "Age Group":
  case
    when AgeInYearsAt(start of "Measurement Period") in Interval[0, 1) then "<1"
    when AgeInYearsAt(start of "Measurement Period") in Interval[1, 9) then "1-9"
    when AgeInYearsAt(start of "Measurement Period") in Interval[10, 14) then "10-14"
    when AgeInYearsAt(start of "Measurement Period") in Interval[15, 19) then "15-19"
    when AgeInYearsAt(start of "Measurement Period") in Interval[20, 24) then "20-24"
    when AgeInYearsAt(start of "Measurement Period") in Interval[25, null] then "25+"
    else null
  end


define "Age Group/Sex":
  "Age Group".code + ':' + "Sex"


define "Last Location":
  Last([Encounter] E
    return singleton from (E.location L
      return L.location.reference
    ).value
  )


// http://fhir.openmrs.org/ext/patient/identifier#location

define "OpenMRS Location":
  [Patient] P
    // this url is in the ig, but is not correct: 'http://fhir.openmrs.org/core/StructureDefinition/omrs-patient-identifier-location'}
    where singleton from {P.identifier.extension[0].url ~ 'http://fhir.openmrs.org/ext/patient/identifier'}
    or singleton from {P.identifier.extension[0].url ~ 'http://fhir.openmrs.org/ext/patient/identifier#location'}
    // or singleton from {P.identifier.extension[1].url ~ 'http://fhir.openmrs.org/ext/patient/identifier'}
    // or singleton from {P.identifier.extension[1].url ~ 'http://fhir.openmrs.org/ext/patient/identifier#location'}
    return singleton from {P.identifier.extension[0].value.reference.value}


define "Last serviceProvider":
  // Some of the Synthea encounters do not have a serviceProvider, so this can return nothing
  // Filter out those that are null, then take the last
  [Encounter] E
    where E.serviceProvider is not null
  return Last([Encounter]).serviceProvider.reference.value


// if..then..else
define "Location Deux":
  if "Last Location" is not null then ("Last Location")
  else if "Last serviceProvider" is not null then ("Last serviceProvider")
  else if "OpenMRS Location" is not null then ("OpenMRS Location")
  else null


define "Location":
  case
    // location identifier on patient
    when "OpenMRS Location" is not null then ("OpenMRS Location")
    // then location of last encounter
    when "Last Location" is not null then ("Last Location")
    // then organization of last encounter
    when "Last serviceProvider" is not null then ("Last serviceProvider")
    else null
  end


define "Debug location": 
  Combine({ "Location", "Sex"}, ':')


define "Age Group/Sex/Location":
  "Age Group".code & ':' & "Sex" & ':' & "Location"


define "Age Group/Sex/Location TXCURR":
  "Age Group".code + ':' + "Sex" + ':' + "Location"


define "Age Group/Sex/Location Case Switch":
  "Age Group".code + ':' + "Sex" + ':' + "Location"

Content not shown - (application/elm+xml, size = 95Kb)

Content not shown - (application/elm+json, size = 177Kb)