|
| 1 | +define ObservationList: |
| 2 | + if InInitialPopulation then [Observation] else {} as List<Observation> |
| 3 | + |
| 4 | +// Return the value in the given system for the given Observation |
| 5 | +define function ObservationValueCode(observation FHIR.Observation, system_var String): |
| 6 | + (observation.value as CodeableConcept).coding.where(system = system_var).code.first() |
| 7 | + |
| 8 | +// Check to see if there are any Observation resources with the |
| 9 | +// given system/value pair. |
| 10 | +define function ExistsObservationValueCode(system_var String, code_var String): |
| 11 | + exists from [Observation] O |
| 12 | + where ObservationValueCode(O, system_var) = code_var |
| 13 | + |
| 14 | +// Return the value associated with the extension with the given URL for the given Observation |
| 15 | +define function BaseObservationExtensionValue(observation FHIR.Observation, url_var String): |
| 16 | + observation.extension.where(url = url_var).value |
| 17 | + |
| 18 | +// Return the value of the Observation extension with the given URL |
| 19 | +define function ObservationExtensionValue(observation FHIR.Observation, url_var String): |
| 20 | + SensibleString(BaseObservationExtensionValue(observation, url_var)) |
| 21 | + |
| 22 | +define function ExistsObservationExtensionValue(url_var String, value_var String): |
| 23 | + exists from [Observation] O |
| 24 | + where ObservationExtensionValue(O, url_var) = value_var |
| 25 | + |
| 26 | +// Return the pathogen type for the given Observation |
| 27 | +define function PathogenCode(observation FHIR.Observation): |
| 28 | + ObservationValueCode(observation, 'https://ecdc.amr/pathogen-codes') |
| 29 | + |
| 30 | +// Check to see if there are any Observation resources with the |
| 31 | +// given pathogen type. |
| 32 | +define function ExistsPathogenCode(code_var String): |
| 33 | + ExistsObservationValueCode('https://ecdc.amr/pathogen-codes', code_var) |
| 34 | + |
| 35 | +// Return the antibiotic type for the given Observation |
| 36 | +define function AntibioticCode(observation FHIR.Observation): |
| 37 | + ObservationValueCode(observation, 'https://ecdc.amr/antibiotic-codes') |
| 38 | + |
| 39 | +// Check to see if there are any Observation resources with the |
| 40 | +// given antibiotic type. |
| 41 | +define function ExistsAntibioticCode(code_var String): |
| 42 | + ExistsObservationValueCode('https://ecdc.amr/antibiotic-codes', code_var) |
| 43 | + |
| 44 | +// Return the resistance type for the given Observation |
| 45 | +define function SirCode(observation FHIR.Observation): |
| 46 | + ObservationValueCode(observation, 'https://ecdc.amr/sir-codes') |
| 47 | + |
| 48 | +// Check to see if there are any Observation resources with the |
| 49 | +// given resistance type. |
| 50 | +define function ExistsSirCode(code_var String): |
| 51 | + ExistsObservationValueCode('https://ecdc.amr/sir-codes', code_var) |
| 52 | + |
| 53 | +// Return the data source for the given Observation |
| 54 | +define function DataSource(observation FHIR.Observation): |
| 55 | + ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationDataSource') |
| 56 | + |
| 57 | +// Check to see if there are any Observation resources with the |
| 58 | +// given data source. |
| 59 | +define function ExistsDataSource(value_var String): |
| 60 | + ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationDataSource', value_var) |
| 61 | + |
| 62 | +// Return the isolate ID for the given Observation |
| 63 | +define function IsolateId(observation FHIR.Observation): |
| 64 | + ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationIsolateId') |
| 65 | + |
| 66 | +// Check to see if there are any Observation resources with the |
| 67 | +// given isolate ID. |
| 68 | +define function ExistsIsolateId(value_var String): |
| 69 | + ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationIsolateId', value_var) |
| 70 | + |
| 71 | +// Return the patient type for the given Observation |
| 72 | +define function PatientType(observation FHIR.Observation): |
| 73 | + ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationPatientType') |
| 74 | + |
| 75 | +// Check to see if there are any Observation resources with the |
| 76 | +// given patient type. |
| 77 | +define function ExistsPatientType(value_var String): |
| 78 | + ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationPatientType', value_var) |
| 79 | + |
| 80 | +// Return the reference guidelines SIR for the given Observation |
| 81 | +define function ReferenceGuidelinesSir(observation FHIR.Observation): |
| 82 | + ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationReferenceGuidelinesSIR') |
| 83 | + |
| 84 | +// Check to see if there are any Observation resources with the |
| 85 | +// given reference guidelines SIR. |
| 86 | +define function ExistsReferenceGuidelinesSir(value_var String): |
| 87 | + ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationReferenceGuidelinesSIR', value_var) |
| 88 | + |
| 89 | +// Return the reporting country for the given Observation |
| 90 | +define function ReportingCountry(observation FHIR.Observation): |
| 91 | + ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationReportingCountry') |
| 92 | + |
| 93 | +// Check to see if there are any Observation resources with the |
| 94 | +// given reporting country. |
| 95 | +define function ExistsReportingCountry(value_var String): |
| 96 | + ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationReportingCountry', value_var) |
| 97 | + |
| 98 | +// Return the year from the date used for statistics |
| 99 | +define function YearDateUsedForStatistics(observation FHIR.Observation): |
| 100 | + year from observation.issued |
| 101 | + |
| 102 | +// Return the month from the date used for statistics |
| 103 | +define function MonthDateUsedForStatistics(observation FHIR.Observation): |
| 104 | + month from observation.issued |
| 105 | + |
| 106 | +// Return the year-month from the date used for statistics |
| 107 | +define function YearMonthDateUsedForStatistics(observation FHIR.Observation): |
| 108 | + ToString(YearDateUsedForStatistics(observation)) + '-' + ToString(MonthDateUsedForStatistics(observation)) |
| 109 | + |
| 110 | +// Return the the date valid from |
| 111 | +define function DateValidFrom(observation FHIR.Observation): |
| 112 | + ToDate(observation.effective as dateTime) |
| 113 | + |
| 114 | +// Return the year from the date valid from |
| 115 | +define function YearDateValidFrom(observation FHIR.Observation): |
| 116 | + year from DateValidFrom(observation) |
| 117 | + |
| 118 | +// Return the month from the date valid from |
| 119 | +define function MonthDateValidFrom(observation FHIR.Observation): |
| 120 | + month from DateValidFrom(observation) |
| 121 | + |
| 122 | +// Return the year-month from the date valid from |
| 123 | +define function YearMonthDateValidFrom(observation FHIR.Observation): |
| 124 | + ToString(YearDateValidFrom(observation)) + '-' + ToString(MonthDateValidFrom(observation)) |
| 125 | + |
0 commit comments