refs/refs/mends-on-fhir/whistle-mappings/synthea/whistle-functions/Drug_Exposure.wstl
lines 13–13
694 lines · wstl
1// 2021-03-22: Comment out MedicationStatement 2// 2022-07-01: added validityPeriod for MedicationRequest, Added meta.profile and corrected misspelled elements 4//----------------------------------------------------------------------------- 6//----------------------------------------------------------------------------- 7def Drug_Exposure(Drug_Exposure, required context) { 9 // Define Medication ID to be used as medicationReference and as id for the Medication resource 10 var medicationID: Id_Spaces_To_Dash($StrCat("med-", Drug_Exposure.drug_concept_id, "-",Drug_Exposure.drug_source_concept_id, "-", $Hash(Drug_Exposure.lot_number))) 12 // 32818 = EHR administration record 13 if (Drug_Exposure.drug_type_concept_id = "32818") { 14 // CVX = Vaccine Administered 15 if (Drug_Exposure.drug_source_vocabulary_id = "CVX") { 16 var resources[]: Drug_Exposure_Immunization(Drug_Exposure, context) 19 var resources[]: Drug_Exposure_MedicationAdministration(Drug_Exposure, context, medicationID) 24 if Drug_Exposure.drug_type_concept_id = "32833" { 25 var resources[]: Drug_Exposure_MedicationRequest(Drug_Exposure, context, medicationID) 28 // 32865 = Patient self-report 29 //if (Drug_Exposure.drug_type_concept_id = "32865") { 30 // var resources[]: Drug_Exposure_MedicationStatement(Drug_Exposure, context, medicationID) 33 // 32825 = EHR dispensing record 34 if (Drug_Exposure.drug_type_concept_id = "32825") { 35 var resources[]: Drug_Exposure_MedicationDispense(Drug_Exposure, context, medicationID) 38 // Always create a Medication Resource when drug_concept_id or drug_source_concept_id are ~= "0" and medicationID not empty 39 if (Drug_Exposure.drug_concept_id ~= "0" or (Drug_Exposure.drug_concept_id = "0" and Drug_Exposure.drug_source_concept_id ~= "0" and medicationID ~= "")) { 40 var resources[]: Drug_Exposure_Medication(Drug_Exposure, context, medicationID) 48//----------------------------------------------------------------------------- 49// Medication - FHIR US Core 50//----------------------------------------------------------------------------- 51def Drug_Exposure_Medication(Drug_Exposure, required context, required medicationID) { 53 // MedicationRequest Resource 54 resourceType: "Medication" 60 meta.profile[]: "http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication" 69 // identifier, 0..*, Identifier 70 identifier[0].use: "secondary"; 71 identifier[0].system: Code_System("HDC") 72 identifier[0].value: medicationID 74 // code,1..1,CodeableConcept 75 if (Drug_Exposure.drug_concept_id ~= "0") { 76 code.coding[]: CodingSelected(Code_System(Drug_Exposure.drug_concept_vocabulary_id), "", Drug_Exposure.drug_concept_code, Drug_Exposure.drug_concept_name, true) 78 if (Drug_Exposure.drug_concept_code ~= Drug_Exposure.drug_source_concept_code) { 79 code.coding[]: CodingSelected(Code_System(Drug_Exposure.drug_source_vocabulary_id), "", Drug_Exposure.drug_source_concept_code, Drug_Exposure.drug_source_concept_name, true) 82 if(Drug_Exposure.drug_source_concept_id ~= "0") { 83 code.coding[]: CodingSelected(Code_System(Drug_Exposure.drug_source_vocabulary_id), "", Drug_Exposure.drug_source_concept_code, Drug_Exposure.drug_source_concept_name, true) 92 // batch,0..1,BackboneElement 93 // lotNumber, 0..1, string 94 batch.lotNumber: Drug_Exposure.lot_number 99//----------------------------------------------------------------------------- 100// MedicationRequest - FHIR US Core 101//----------------------------------------------------------------------------- 102def Drug_Exposure_MedicationRequest(Drug_Exposure, required context, required medicationID) { 104 // MedicationRequest Resource 105 resourceType: "MedicationRequest" 108 id: Drug_Exposure.drug_exposure_id 111 meta.profile[]: "http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest" 118 modifierExtension: "" 120 // identifier, 0..*, Identifier 121 identifier[0].use: "secondary"; 122 identifier[0].system: Code_System("HDC") 123 identifier[0].value: Drug_Exposure.drug_exposure_id 125 // status, 1..1, code 126 if (Drug_Exposure.stop_reason) { 128 statusReason.text: Drug_Exposure.stop_reason 133 // intent, 1..1, code 140 reportedBoolean: false 142 // medication[x], 1..1 143 medicationReference: Reference("Medication", medicationID) 145 // subject, 1..1, Reference 146 if (Drug_Exposure.person_id) { 147 subject: Reference("Patient", Drug_Exposure.person_id) 150 // encounter, 0..1, Reference 151 if (Drug_Exposure.visit_occurrence_id) { 152 encounter: Reference("Encounter", Drug_Exposure.visit_occurrence_id) 155 supportingInformation: "" 157 // authoredOn, 0..1, dateTime 158 if context.config.output.phi = "yes" { 159 authoredOn: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 161 authoredOn: ReformatDatetime("2030-01-01") 164 // requester, 0..1, Reference 166 if(Drug_Exposure.provider_id) { 167 requester: Reference("Practitioner", Drug_Exposure.provider_id) 171 //if($IsNotNil(Drug_Exposure.provider_id)) { 172 // requester: Reference("Practitioner", Drug_Exposure.provider_id) 174 // requester: Reference("Practitioner", "NULL") 182 instantiatesCanonical: "" 186 courseOfTherapyType: "" 190 // dosageInstruction, 0..*, Dosage 192 // text, 0..1, string 193 if Drug_Exposure.sig { 194 dosageInstruction[0].text: Drug_Exposure.sig 197 // route, 0..1, CodeableConcept 198 dosageInstruction[0].route.text: Drug_Exposure.route_source_value 199 if(Drug_Exposure.route_concept_id and Drug_Exposure.route_concept_id ~= "0") { 200 dosageInstruction[0].route.coding[0].system: Code_System(Drug_Exposure.route_vocabulary_id) 201 dosageInstruction[0].route.coding[0].code: Drug_Exposure.route_concept_code 202 dosageInstruction[0].route.coding[0].display: Drug_Exposure.route_concept_name 205 if(Drug_Exposure.dose_unit_source_value ~= "*Unspecified") { 206 dosageInstruction[0].doseAndRate[0].doseQuantity.unit: Drug_Exposure.dose_unit_source_value 209 // dispenseRequest, 0..1, BackboneElement 210 if (Drug_Exposure.drug_exposure_start_date) { 211 if context.config.output.phi = "yes" { 212 dispenseRequest.validityPeriod.start: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 214 dispenseRequest.validityPeriod.start: ReformatDatetime("2030-01-01") 217 if (Drug_Exposure.drug_exposure_end_date) { 218 if context.config.output.phi = "yes" { 219 dispenseRequest.validityPeriod.end: ReformatDatetimeDate(Drug_Exposure.drug_exposure_end_datetime, Drug_Exposure.drug_exposure_end_date) 221 dispenseRequest.validityPeriod.end: ReformatDatetime("2030-01-01") 225 if(Drug_Exposure.refills) { 226 dispenseRequest.numberOfRepeatsAllowed: $ParseFloat(Drug_Exposure.refills) 229 if(Drug_Exposure.quantity) { 230 dispenseRequest.quantity.value: $ParseFloat(Drug_Exposure.quantity) 233 if(Drug_Exposure.days_supply) { 234 dispenseRequest.expectedSupplyDuration.value: $ParseFloat(Drug_Exposure.days_supply) 235 dispenseRequest.expectedSupplyDuration.code: "d" 236 dispenseRequest.expectedSupplyDuration.system: "http://unitsofmeasure.org" 240 priorPrescription: "" 247//----------------------------------------------------------------------------- 248// Immunization - FHIR US Core 249//----------------------------------------------------------------------------- 250def Drug_Exposure_Immunization(Drug_Exposure, required context) { 252 // Immunization Resource 253 resourceType: "Immunization" 256 id: Drug_Exposure.drug_exposure_id 259 meta.profile[]: "http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization" 266 modifierExtension: "" 268 // identifier, 0..*, Identifier 269 identifier[0].use: "secondary"; 270 identifier[0].system: Code_System("HDC") 271 identifier[0].value: Drug_Exposure.drug_exposure_id 273 // status, 1..1, code 274 if (Drug_Exposure.stop_reason) { 276 statusReason.text: Drug_Exposure.stop_reason 281 // vaccineCode, 1..1, CodeableConcept 282 vaccineCode.text: Drug_Exposure.drug_concept_name 283 vaccineCode.coding[]: Coding(Code_System(Drug_Exposure.drug_concept_vocabulary_id), "", Drug_Exposure.drug_concept_code, Drug_Exposure.drug_concept_name) 285 if (Drug_Exposure.drug_concept_code ~= Drug_Exposure.drug_source_concept_code) { 286 vaccineCode.coding[]: Coding(Code_System(Drug_Exposure.drug_source_vocabulary_id), "", Drug_Exposure.drug_source_concept_code, Drug_Exposure.drug_source_concept_name) 289 // patient, 1..1, Reference 290 if (Drug_Exposure.person_id) { 291 patient: Reference("Patient", Drug_Exposure.person_id) 294 // encounter, 0..1, Reference 295 if (Drug_Exposure.visit_occurrence_id) { 296 encounter: Reference("Encounter", Drug_Exposure.visit_occurrence_id) 299 // occurrence[x], 1..1 301 if context.config.output.phi = "yes" { 302 occurrenceDateTime: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 304 occurrenceDateTime: ReformatDatetime("2030-01-01") 309 // primarySource, 1..1, boolean 316 //lotNumber, 0..1, string 317 lotNumber: Drug_Exposure.lot_number 322 // route, 0..1, CodeableConcept 323 if Drug_Exposure.route_source_value { 324 route.text: Drug_Exposure.route_source_value 326 if(Drug_Exposure.route_concept_id and Drug_Exposure.route_concept_id ~= "0") { 327 route.coding[0].system: Code_System(Drug_Exposure.route_vocabulary_id) 328 route.coding[0].code: Drug_Exposure.route_concept_code 329 route.coding[0].display: Drug_Exposure.route_concept_name 332 // doseQuantity, 0..1, SimpleQuantity 333 if(Drug_Exposure.quantity) { 334 doseQuantity.value: $ParseFloat(Drug_Exposure.quantity) 336 doseQuantity.unit: Drug_Exposure.dose_unit_source_value 345 programEligibility: "" 352//----------------------------------------------------------------------------- 353// MedicationAdministration - FHIR Core 354//----------------------------------------------------------------------------- 355def Drug_Exposure_MedicationAdministration(Drug_Exposure, required context, required medicationID) { 357 // MedicationAdministration Resource 358 resourceType: "MedicationAdministration" 361 id: Drug_Exposure.drug_exposure_id 369 modifierExtension: "" 371 // identifier, 0..*, Identifier 372 identifier[0].use: "secondary"; 373 identifier[0].system: Code_System("HDC") 374 identifier[0].value: Drug_Exposure.drug_exposure_id 379 // status, 1..1, code 380 if (Drug_Exposure.stop_reason) { 382 statusReason.text: Drug_Exposure.stop_reason 384 if (Drug_Exposure.drug_exposure_end_date or Drug_Exposure.drug_exposure_end_datetime) { 387 status: "in-progress" 393 // medication[x], 1..1 394 medicationReference: Reference("Medication", medicationID) 396 // subject, 1..1, Reference 397 if (Drug_Exposure.person_id) { 398 subject: Reference("Patient", Drug_Exposure.person_id) 401 // context, 0..1, Reference 402 if (Drug_Exposure.visit_occurrence_id) { 403 context: Reference("Encounter", Drug_Exposure.visit_occurrence_id) 406 supportingInformation: "" 408 // effective[x], 1..1 409 if context.config.output.phi = "yes" { 410 if(Drug_Exposure.drug_exposure_start_date = Drug_Exposure.drug_exposure_end_date) { 411 effectiveDateTime: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 413 effectivePeriod.start: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 414 effectivePeriod.end: ReformatDatetimeDate(Drug_Exposure.drug_exposure_end_datetime, Drug_Exposure.drug_exposure_end_date) 417 if(Drug_Exposure.drug_exposure_start_date = Drug_Exposure.drug_exposure_end_date) { 418 effectiveDateTime: ReformatDatetime("2030-01-01") 420 effectivePeriod.start: ReformatDatetime("2030-01-01") 421 effectivePeriod.end: ReformatDatetime("2030-01-01") 425 // performer, 0..*, BackboneElement 426 // actor, 1..1, Reference(Practitioner) 427 performer[].actor: Reference("Practitioner", Drug_Exposure.provider_id) 435 // dosage, 0..1, BackboneElement 436 // text, 0..1, string 437 if Drug_Exposure.sig { 438 dosage.text: Drug_Exposure.sig 442 // route, 0..1, CodeableConcept 443 if Drug_Exposure.route_source_value { 444 dosage.route.text: Drug_Exposure.route_source_value 446 if( Drug_Exposure.route_concept_id and Drug_Exposure.route_concept_id ~= "0") { 447 var coding.system: Code_System(Drug_Exposure.route_vocabulary_id) 448 var coding.code: Drug_Exposure.route_concept_code 449 var coding.display: Drug_Exposure.route_concept_name 450 dosage.route.coding[]: coding 453 // dose, 0..1, SimpleQuantity 454 if(Drug_Exposure.quantity) { 455 dosage.dose.value: $ParseFloat(Drug_Exposure.quantity) 458 if Drug_Exposure.dose_unit_source_value { 459 dosage.dose.unit: Drug_Exposure.dose_unit_source_value 470//----------------------------------------------------------------------------- 471// MedicationDispense - FHIR Core 472//----------------------------------------------------------------------------- 473def Drug_Exposure_MedicationDispense(Drug_Exposure, required context, required medicationID) { 475 // MedicationDispense Resource 476 resourceType: "MedicationDispense" 479 id: Drug_Exposure.drug_exposure_id 487 modifierExtension: "" 489 // identifier, 0..*, Identifier 490 identifier[0].use: "secondary"; 491 identifier[0].system: Code_System("HDC") 492 identifier[0].value: Drug_Exposure.drug_exposure_id 496 // status, 1..1, code 497 if (Drug_Exposure.stop_reason) { 499 statusReason.text: Drug_Exposure.stop_reason 501 if (Drug_Exposure.drug_exposure_end_date or Drug_Exposure.drug_exposure_end_datetime) { 504 status: "in-progress" 510 // medication[x], 1..1 511 medicationReference: Reference("Medication", medicationID) 513 // subject, 1..1, Reference 514 if (Drug_Exposure.person_id) { 515 subject: Reference("Patient", Drug_Exposure.person_id) 518 // context, 0..1, Reference 519 if (Drug_Exposure.visit_occurrence_id) { 520 context: Reference("Encounter", Drug_Exposure.visit_occurrence_id) 523 supportingInformation: "" 525 // performer, 0..*, BackboneElement 526 // actor, 1..1, Reference(Practitioner) 527 performer[].actor: Reference("Practitioner", Drug_Exposure.provider_id) 530 authorizingPrescription: "" 533 // quantity 0..1, SimpleQuantity 534 if(Drug_Exposure.quantity) { 535 quantity.value: $ParseFloat(Drug_Exposure.quantity) 538 // daysSupply, 0..1, SimpleQuantity 539 if(Drug_Exposure.days_supply) { 540 daysSupply.value: $ParseFloat(Drug_Exposure.days_supply) 542 daysSupply.system: "http://unitsofmeasure.org" 547 // whenHandedOver, 0..1, dateTime 548 if context.config.output.phi = "yes" { 549 whenHandedOver: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 551 whenHandedOver: ReformatDatetime("2030-01-01") 558 // dosage, 0..1, BackboneElement 559 // text, 0..1, string 560 if Drug_Exposure.sig { 561 var dosage.text: Drug_Exposure.sig 565 // route, 0..1, CodeableConcept 566 if Drug_Exposure.route_source_value { 567 var dosage.route.text: Drug_Exposure.route_source_value 569 if(Drug_Exposure.route_concept_id and Drug_Exposure.route_concept_id ~= "0") { 571 var coding.system: Code_System(Drug_Exposure.route_vocabulary_id) 572 var coding.code: Drug_Exposure.route_concept_code 573 var coding.display: Drug_Exposure.route_concept_name 574 var dosage.route.coding[]: coding 577 if Drug_Exposure.dose_unit_source_value { 578 var dosage.doseAndRate[].doseQuantity.unit: Drug_Exposure.dose_unit_source_value 582 dosageInstruction[]: dosage 590//----------------------------------------------------------------------------- 591// MedicationStatement - FHIR Core 592// INCOMPLETE - Do Not Use 593//----------------------------------------------------------------------------- 594def DO_NOT_USE_Drug_Exposure_MedicationStatement(Drug_Exposure, required context, required medicationID) { 596 // MedicationStatement Resource 597 resourceType: "MedicationStatement" 600 id: Drug_Exposure.drug_exposure_id 602 // identifier, 0..*, Identifier 603 identifier[0].use: "secondary"; 604 identifier[0].system: Code_System("HDC") 605 identifier[0].value: Drug_Exposure.drug_exposure_id 610 // status, 1..1, code 611 if (Drug_Exposure.stop_reason) { 613 statusReason[0].text: Drug_Exposure.stop_reason 615 if (Drug_Exposure.drug_exposure_end_date or Drug_Exposure.drug_exposure_end_datetime) { 618 status: "in-progress" 622 // category, 0..1, CodeableConcept 623 category.text: "patientspecified" 624 category.coding[0].system: "http://hl7.org/fhir/ValueSet/medication-statement-category" 625 category.coding[0].code: "patientspecified" 626 category.coding[0].display: "Patient Specified" 627 category.coding[0].userSelected: true 629 // medication[x], 1..1 630 if (Drug_Exposure.lot_number) { 631 medicationReference: Reference("Medication", Drug_Exposure.drug_concept_id) 633 medicationCodeableConcept.coding[]: CodingSelected(Code_System(Drug_Exposure.drug_concept_vocabulary_id), "", Drug_Exposure.drug_concept_code, Drug_Exposure.drug_concept_name, true) 635 if (Drug_Exposure.drug_concept_code ~= Drug_Exposure.drug_source_concept_code) { 636 medicationCodeableConcept.coding[]: CodingSelected(Code_System(Drug_Exposure.drug_source_vocabulary_id), "", Drug_Exposure.drug_source_concept_code, Drug_Exposure.drug_source_concept_name, true) 641 // subject, 1..1, Reference 642 if (Drug_Exposure.person_id) { 643 subject: Reference("Patient", Drug_Exposure.person_id) 646 // context, 0..1, Reference 647 if (Drug_Exposure.visit_occurrence_id) { 648 context: Reference("Encounter", Drug_Exposure.visit_occurrence_id) 651 // effective[x], 1..1 652 effectiveDateTime: "" 653 if context.config.output.phi = "yes" { 654 effectivePeriod.start: ReformatDatetimeDate(Drug_Exposure.drug_exposure_start_datetime, Drug_Exposure.drug_exposure_start_date) 655 effectivePeriod.end: ReformatDatetimeDate(Drug_Exposure.drug_exposure_end_datetime, Drug_Exposure.drug_exposure_end_date) 657 effectivePeriod.start: ReformatDatetime("2030-01-01") 658 effectivePeriod.end: ReformatDatetime("2030-01-01") 663 // informationSource, 0..1, Reference 664 informationSource: Reference("Patient", Drug_Exposure.person_id) 665 informationSource.display: Drug_Exposure.person_id 666 informationSource.identifier.use: "secondary" 673 // dosage, 0..*, dosage 674 // text, 0..1, string 675 if Drug_Exposure.sig { 676 dosage[0].text: Drug_Exposure.sig 679 // route, 0..1, CodeableConcept 680 if Drug_Exposure.route_source_value { 681 dosage[0].route.text: Drug_Exposure.route_source_value 683 dosage[0].route.coding[0].system: Code_System(Drug_Exposure.route_vocabulary_id) 684 dosage[0].route.coding[0].code: Drug_Exposure.route_concept_code 685 dosage[0].route.coding[0].display: Drug_Exposure.route_concept_name 688 if (Drug_Exposure.quantity and Drug_Exposure.dose_unit_source_value) { 689 dosage[0].doseAndRate[0].doseQuantity.value: Drug_Exposure.quantity 690 dosage[0].doseAndRate[0].doseQuantity.unit: Drug_Exposure.dose_unit_source_value