jquery updates
[openemr.git] / rest_controllers / FhirPatientRestController.php
blob67c8adeb581d1490398dcb6957d4e1f5190660e4
1 <?php
2 /**
3 * FhirPatientRestController
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Jerry Padgett <sjpadgett@gmail.com>
8 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\RestControllers;
15 use OpenEMR\Services\PatientService;
16 use OpenEMR\Services\FhirResourcesService;
17 use OpenEMR\RestControllers\RestControllerHelper;
18 use HL7\FHIR\STU3\FHIRResource\FHIRBundle\FHIRBundleEntry;
20 class FhirPatientRestController
22 private $patientService;
23 private $fhirService;
25 public function __construct($pid)
27 $this->patientService = new PatientService();
28 $this->patientService->setPid($pid);
29 $this->fhirService = new FhirResourcesService();
32 // implement put post in future
34 public function getOne()
36 $oept = $this->patientService->getOne();
37 $pid = $this->patientService->getPid();
38 $patientResource = $this->fhirService->createPatientResource($pid, $oept, false);
40 return RestControllerHelper::responseHandler($patientResource, null, 200);
43 public function getAll($search)
45 $resourceURL = \RestConfig::$REST_FULL_URL;
46 if (strpos($resourceURL, '?') > 0) {
47 $resourceURL = strstr($resourceURL, '?', true);
50 $searchParam = array(
51 'name' => $search['name'],
52 'dob' => $search['birthdate']);
54 $searchResult = $this->patientService->getAll($searchParam);
55 if ($searchResult === false) {
56 http_response_code(404);
57 exit;
59 $entries = array();
60 foreach ($searchResult as $oept) {
61 $entryResource = $this->fhirService->createPatientResource($oept['pid'], $oept, false);
62 $entry = array(
63 'fullUrl' => $resourceURL . "/" . $oept['pid'],
64 'resource' => $entryResource
66 $entries[] = new FHIRBundleEntry($entry);
68 $searchResult = $this->fhirService->createBundle('Patient', $entries, false);
69 return RestControllerHelper::responseHandler($searchResult, null, 200);