dump db version
[openemr.git] / rest_controllers / FhirPatientRestController.php
blob57e9cf05a30199735b26b1973ec587d20ca664c2
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 = 'patient-' . $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']
55 $searchResult = $this->patientService->getAll($searchParam);
56 if ($searchResult === false) {
57 http_response_code(404);
58 exit;
60 $entries = array();
61 foreach ($searchResult as $oept) {
62 $entryResource = $this->fhirService->createPatientResource($oept['pid'], $oept, false);
63 $entry = array(
64 'fullUrl' => $resourceURL . "/" . $oept['pid'],
65 'resource' => $entryResource
67 $entries[] = new FHIRBundleEntry($entry);
69 $searchResult = $this->fhirService->createBundle('Patient', $entries, false);
70 return RestControllerHelper::responseHandler($searchResult, null, 200);