forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AllergyIntolerance Resource & GET methods FHIR (openemr#3334)
* Implemented Post and Put for FHIR * Update _rest_routes.inc.php * Added routes for Patient Put & Post * Search by address, phone, gender * Psr2 fixes * Psr2 fixes * Psr2 again * Organization resource with getAll function * Psr2 fixes * Updated naming conventions * Psr2 fixes * AllergyIntolerance Resource with GET methods * Small fixes * small fix * some fixes * Few Fixes * Small fixes
- Loading branch information
1 parent
e48b36a
commit 54fac8e
Showing
3 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/RestControllers/FHIR/FhirAllergyIntoleranceRestController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace OpenEMR\RestControllers\FHIR; | ||
|
||
use OpenEMR\Services\FHIR\FhirAllergyIntoleranceService; | ||
use OpenEMR\Services\FHIR\FhirResourcesService; | ||
use OpenEMR\RestControllers\RestControllerHelper; | ||
use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle\FHIRBundleEntry; | ||
|
||
class FhirAllergyIntoleranceRestController | ||
{ | ||
private $fhirAllergyIntoleranceService; | ||
private $fhirService; | ||
|
||
public function __construct($id) | ||
{ | ||
$this->fhirAllergyIntoleranceService = new FhirAllergyIntoleranceService(); | ||
$this->fhirAllergyIntoleranceService->setId($id); | ||
$this->fhirService = new FhirResourcesService(); | ||
} | ||
|
||
public function getAll($search) | ||
{ | ||
$result = $this->fhirAllergyIntoleranceService->getAll(array('patient' => $search['patient'])); | ||
if ($result === false) { | ||
http_response_code(404); | ||
exit; | ||
} | ||
$entries = array(); | ||
$resourceURL = \RestConfig::$REST_FULL_URL; | ||
foreach ($result as $allergy) { | ||
$entryResource = $this->fhirAllergyIntoleranceService->createAllergyIntoleranceResource( | ||
$allergy['id'], | ||
$allergy, | ||
false | ||
); | ||
$entry = array( | ||
'fullUrl' => $resourceURL . "/" . $allergy['id'], | ||
'resource' => $entryResource | ||
); | ||
$entries[] = new FHIRBundleEntry($entry); | ||
} | ||
$result = $this->fhirService->createBundle('AllergyIntolerance', $entries, false); | ||
return RestControllerHelper::responseHandler($result, null, 200); | ||
} | ||
|
||
public function getOne($id) | ||
{ | ||
$result = $this->fhirAllergyIntoleranceService->getOne($id); | ||
if ($result) { | ||
$resource = $this->fhirAllergyIntoleranceService->createAllergyIntoleranceResource( | ||
$result['id'], | ||
$result, | ||
false | ||
); | ||
$statusCode = 200; | ||
} else { | ||
$statusCode = 404; | ||
$resource = $this->fhirValidate->operationOutcomeResourceService( | ||
'error', | ||
'invalid', | ||
false, | ||
"Resource Id $id does not exist" | ||
); | ||
} | ||
|
||
return RestControllerHelper::responseHandler($resource, null, $statusCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?php | ||
|
||
namespace OpenEMR\Services\FHIR; | ||
|
||
use OpenEMR\FHIR\R4\FHIRDomainResource\FHIRAllergyIntolerance; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRAllergyIntoleranceCategory; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRAllergyIntoleranceCriticality; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRAllergyIntoleranceType; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRAnnotation; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRCodeableConcept; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRCoding; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRDateTime; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRId; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRMeta; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRReference; | ||
use OpenEMR\FHIR\R4\FHIRElement\FHIRUrl; | ||
use OpenEMR\FHIR\R4\FHIRResource\FHIRAllergyIntolerance\FHIRAllergyIntoleranceReaction; | ||
use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle; | ||
use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle\FHIRBundleLink; | ||
use OpenEMR\FHIR\R4\PHPFHIRResponseParser; | ||
use OpenEMR\Services\ListService; | ||
|
||
class FhirAllergyIntoleranceService | ||
{ | ||
|
||
private $id; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getAll($search) | ||
{ | ||
$SQL = "SELECT id, | ||
date as recorded_date, | ||
type, | ||
subtype, | ||
title, | ||
begdate, | ||
enddate, | ||
returndate, | ||
referredby, | ||
extrainfo, | ||
diagnosis, | ||
pid, | ||
outcome, | ||
reaction, | ||
severity_al | ||
FROM lists | ||
WHERE type = 'allergy'"; | ||
|
||
if (isset($search['patient'])) | ||
$SQL .= " AND pid = ?;"; | ||
|
||
$allergyIntolerenceresults = sqlStatement($SQL, $search['patient']); | ||
$results = array(); | ||
while ($row = sqlFetchArray($allergyIntolerenceresults)) { | ||
$codeSQL = "SELECT dx_code | ||
FROM icd10_dx_order_code | ||
WHERE short_desc = ?;"; | ||
$code = sqlQuery($codeSQL, array($row['reaction'])); | ||
$row['code'] = $code['dx_code']; | ||
array_push($results, $row); | ||
} | ||
return $results; | ||
} | ||
|
||
public function getOne($id) | ||
{ | ||
$SQL = "SELECT id, | ||
date as recorded_date, | ||
type, | ||
subtype, | ||
title, | ||
begdate, | ||
enddate, | ||
returndate, | ||
referredby, | ||
extrainfo, | ||
diagnosis, | ||
pid, | ||
outcome, | ||
reaction, | ||
severity_al | ||
FROM lists | ||
WHERE type = 'allergy' | ||
AND id = ?;"; | ||
|
||
$sqlResult = sqlStatement($SQL, $id); | ||
$result = sqlFetchArray($sqlResult); | ||
$codeSQL = "SELECT dx_code | ||
FROM icd10_dx_order_code | ||
WHERE short_desc = ?;"; | ||
|
||
$code = sqlQuery($codeSQL, array($result['reaction'])); | ||
$result['code'] = $code['dx_code']; | ||
return $result; | ||
} | ||
|
||
public function createAllergyIntoleranceResource($id = '', $data = '', $encode = true) | ||
{ | ||
$typeCoding = new FHIRCoding(); | ||
$typeCoding->setSystem("http:https://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"); | ||
$typeCoding->setCode($data['type']); | ||
$typeCoding->setDisplay(ucwords($data['type'])); | ||
$type = new FHIRAllergyIntoleranceType(); | ||
$type->setValue($typeCoding); | ||
|
||
$onSetDateTime = new FHIRDateTime(); | ||
$onSetDateTime->setValue($data['begdate']); | ||
|
||
$recordedDate = new FHIRDateTime(); | ||
$recordedDate->setValue($data['recorded_date']); | ||
|
||
$clinicalStatus = ''; | ||
if ($data['outcome'] == '1' && isset($data['enddate'])) | ||
$clinicalStatus = "resolved"; | ||
else if (!isset($data['enddate'])) | ||
$clinicalStatus = "active"; | ||
else | ||
$clinicalStatus = "inactive"; | ||
$clinicalStatusCoding = new FHIRCoding(); | ||
$clinicalStatusCoding->setSystem("http:https://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"); | ||
$clinicalStatusCoding->setCode($clinicalStatus); | ||
$clinicalStatusCoding->setDisplay($clinicalStatus); | ||
|
||
$categoryCoding = new FHIRCoding(); | ||
$categoryCoding->setSystem("http:https://hl7.org/fhir/allergy-intolerance-category"); | ||
$categoryCoding->setCode("medication"); | ||
$categoryCoding->setDisplay("Medication"); | ||
$category = new FHIRAllergyIntoleranceCategory(); | ||
$category->setValue($categoryCoding); | ||
|
||
$criticalityCoding = new FHIRCoding(); | ||
$criticality = new FHIRAllergyIntoleranceCriticality(); | ||
if (isset($data['severity_al'])) { | ||
$severityToCriticalityCode = array( | ||
"mild" => "low", | ||
"moderate" => "high", | ||
"severe" => "unable-to-assess" | ||
); | ||
$severityToCriticalityDisplay = array( | ||
"mild" => "Low Risk", | ||
"moderate" => "High Risk", | ||
"severe" => "Unable to Assess Risk" | ||
); | ||
$criticalityCoding->setSystem("http:https://hl7.org/fhir/allergy-intolerance-criticality"); | ||
$criticalityCoding->setCode($severityToCriticalityCode[strtolower($data['severity_al'])]); | ||
$criticalityCoding->setDisplay($severityToCriticalityDisplay[strtolower($data['severity_al'])]); | ||
$criticality->setValue($criticalityCoding); | ||
} | ||
else { | ||
$criticalityCoding->setSystem("http:https://terminology.hl7.org/CodeSystem/data-absent-reason"); | ||
$criticalityCoding->setCode("unknown"); | ||
$criticalityCoding->setDisplay("Unknown"); | ||
$criticality->setValue($criticalityCoding); | ||
} | ||
|
||
$patient = new FHIRReference(); | ||
$patient->setReference('Patient/'.$data['pid']); | ||
|
||
$recorder = new FHIRReference(); | ||
$recorder->setReference('Practitioner/'.$data['referredby']); | ||
|
||
$asserter = new FHIRReference(); | ||
$asserter->setReference('Patient/'.$data['pid']); | ||
|
||
$note = new FHIRAnnotation(); | ||
$note->setText($data['extrainfo']); | ||
|
||
$lastOccurrence = new FHIRDateTime(); | ||
$lastOccurrence->setValue($data['returndate']); | ||
|
||
$manifestation = new FHIRCoding(); | ||
$manifestation->setSystem("http:https://hl7.org/fhir/sid/icd-10-cm"); | ||
$manifestation->setCode($data['code']); | ||
$manifestation->setDisplay($data['reaction']); | ||
|
||
$description = $data['comments']; | ||
|
||
$reaction = new FHIRAllergyIntoleranceReaction(); | ||
$reaction->addManifestation($manifestation->jsonSerialize()); | ||
$reaction->setDescription($description); | ||
$reaction->setOnset($data['begdate']); | ||
$severityCoding = new FHIRCoding(); | ||
if (isset($data['severity_al'])) { | ||
$severityCoding->setSystem("http:https://hl7.org/fhir/reaction-event-severity"); | ||
$severityCoding->setCode($data['severity_al']); | ||
$severityCoding->setDisplay(ucwords($data['severity_al'])); | ||
$reaction->setSeverity($severityCoding); | ||
} | ||
else { | ||
$severityCoding->setSystem("http:https://terminology.hl7.org/CodeSystem/data-absent-reason"); | ||
$severityCoding->setCode("unknown"); | ||
$severityCoding->setDisplay("Unknown"); | ||
$reaction->setSeverity($severityCoding); | ||
} | ||
|
||
$resource = new FHIRAllergyIntolerance(); | ||
$resource->setClinicalStatus($clinicalStatusCoding); | ||
$resource->setType($type); | ||
$resource->addCategory($category); | ||
$resource->setOnsetDateTime($onSetDateTime); | ||
$resource->setRecordedDate($recordedDate); | ||
$resource->setCriticality($criticality); | ||
$resource->setPatient($patient); | ||
$resource->setRecorder($recorder); | ||
$resource->setAsserter($asserter); | ||
$resource->setLastOccurrence($lastOccurrence); | ||
$resource->addNote($note); | ||
$resource->addReaction($reaction); | ||
if ($encode) { | ||
return json_encode($resource); | ||
} else { | ||
return $resource; | ||
} | ||
} | ||
} |