3 namespace OpenEMR\Services\FHIR
;
5 use OpenEMR\FHIR\R4\FHIRDomainResource\FHIRMedication
;
6 use OpenEMR\FHIR\R4\FHIRElement\FHIRCodeableConcept
;
7 use OpenEMR\FHIR\R4\FHIRElement\FHIRCoding
;
8 use OpenEMR\FHIR\R4\FHIRElement\FHIRDateTime
;
9 use OpenEMR\FHIR\R4\FHIRElement\FHIRId
;
10 use OpenEMR\FHIR\R4\FHIRResource\FHIRMedication\FHIRMedicationBatch
;
11 use OpenEMR\Services\DrugService
;
12 use OpenEMR\Services\FHIR\FhirServiceBase
;
15 * FHIR Medication Service
17 * @coversDefaultClass OpenEMR\Services\FHIR\FhirMedicationService
19 * @link http://www.open-emr.org
20 * @author Yash Bothra <yashrajbothra786gmail.com>
21 * @copyright Copyright (c) 2020 Yash Bothra <yashrajbothra786gmail.com>
22 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
24 class FhirMedicationService
extends FhirServiceBase
27 * @var MedicationService
29 private $medicationService;
31 public function __construct()
33 parent
::__construct();
34 $this->medicationService
= new DrugService();
38 * Returns an array mapping FHIR Medication Resource search parameters to OpenEMR Medication search parameters
40 * @return array The search parameters
42 protected function loadSearchParameters()
48 * Parses an OpenEMR medication record, returning the equivalent FHIR Medication Resource
50 * @param array $dataRecord The source OpenEMR data record
51 * @param boolean $encode Indicates if the returned resource is encoded into a string. Defaults to false.
52 * @return FHIRMedication
54 public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
56 $medicationResource = new FHIRMedication();
58 $meta = array('versionId' => '1', 'lastUpdated' => gmdate('c'));
59 $medicationResource->setMeta($meta);
62 $id->setValue($dataRecord['uuid']);
63 $medicationResource->setId($id);
65 if ($dataRecord['active'] == '1') {
66 $medicationResource->setStatus("active");
68 $medicationResource->setStatus("inactive");
71 if (!empty($dataRecord['drug_code'])) {
72 $medicationCoding = new FHIRCoding();
73 $medicationCode = new FHIRCodeableConcept();
74 foreach ($dataRecord['drug_code'] as $code => $display) {
75 $medicationCoding->setSystem("http://www.nlm.nih.gov/research/umls/rxnorm");
76 $medicationCoding->setCode($code);
77 $medicationCoding->setDisplay($display);
78 $medicationCode->addCoding($medicationCoding);
80 $medicationResource->setCode($medicationCode);
83 //alternative for switch case
84 list($formDisplay, $formCode) = [
85 '1' => ['suspension', 'C60928'],
86 '2' => ['tablet', 'C42998'],
87 '3' => ['capsule', 'C25158'],
88 '4' => ['solution', 'C42986'],
89 '5' => ['tsp', 'C48544'],
90 '6' => ['ml', 'C28254'],
91 '7' => ['units', 'C44278'],
92 '8' => ['inhalation', 'C42944'],
93 '9' => ['gtts(drops)', 'C48491'],
94 '10' => ['cream', 'C28944'],
95 '11' => ['ointment', 'C42966'],
96 '12' => ['puff', 'C42944']
97 ][$dataRecord['form']] ??
['', ''];
99 if (!empty($formCode)) {
100 $form = new FHIRCodeableConcept();
101 $formCoding = new FHIRCoding();
102 $formCoding->setSystem("http://ncimeta.nci.nih.gov");
103 $formCoding->setCode($formCode);
104 $formCoding->setDisplay($formDisplay);
105 $form->addCoding($formCoding);
108 if (isset($dataRecord['expiration']) ||
isset($dataRecord['expiration'])) {
109 $batch = new FHIRMedicationBatch();
110 if (isset($dataRecord['expiration'])) {
111 $expirationDate = new FHIRDateTime();
112 $expirationDate->setValue($dataRecord['expiration']);
113 $batch->setExpirationDate($expirationDate);
115 if (isset($dataRecord['lot_number'])) {
116 $batch->setLotNumber($dataRecord['lot_number']);
118 $medicationResource->setBatch($batch);
122 return json_encode($medicationResource);
124 return $medicationResource;
129 * Performs a FHIR Condition Resource lookup by FHIR Resource ID
131 * @param $fhirResourceId //The OpenEMR record's FHIR Condition Resource ID.
133 public function getOne($fhirResourceId, $puuidBind = null)
135 $processingResult = $this->medicationService
->getOne($fhirResourceId, true);
136 if (!$processingResult->hasErrors()) {
137 if (count($processingResult->getData()) > 0) {
138 $openEmrRecord = $processingResult->getData()[0];
139 $fhirRecord = $this->parseOpenEMRRecord($openEmrRecord);
140 $processingResult->setData([]);
141 $processingResult->addData($fhirRecord);
144 return $processingResult;
148 * Searches for OpenEMR records using OpenEMR search parameters
150 * @param array openEMRSearchParameters OpenEMR search fields
151 * @param $puuidBind - NOT USED
152 * @return ProcessingResult
154 public function searchForOpenEMRRecords($openEMRSearchParameters, $puuidBind = null)
156 return $this->medicationService
->getAll($openEMRSearchParameters, false, true);
159 public function parseFhirResource($fhirResource = array())
161 // TODO: If Required in Future
164 public function insertOpenEMRRecord($openEmrRecord)
166 // TODO: If Required in Future
169 public function updateOpenEMRRecord($fhirResourceId, $updatedOpenEMRRecord)
171 // TODO: If Required in Future
173 public function createProvenanceResource($dataRecord = array(), $encode = false)
175 // TODO: If Required in Future