3 * FhirPatientRestController
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;
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);
51 'name' => $search['name'],
52 'dob' => $search['birthdate']);
54 $searchResult = $this->patientService
->getAll($searchParam);
55 if ($searchResult === false) {
56 http_response_code(404);
60 foreach ($searchResult as $oept) {
61 $entryResource = $this->fhirService
->createPatientResource($oept['pid'], $oept, false);
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);