Openemr fhir search (#4349)
[openemr.git] / src / RestControllers / FHIR / FhirDiagnosticReportRestController.php
blob8be5b1778216c90d3d6a2716fffe257d57638e89
1 <?php
3 /**
4 * FhirDiagnosticReportRestController.php
5 * @package openemr
6 * @link http://www.open-emr.org
7 * @author Stephen Nielson <stephen@nielson.org>
8 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 namespace OpenEMR\RestControllers\FHIR;
14 use OpenEMR\Services\FHIR\FhirResourcesService;
15 use OpenEMR\RestControllers\RestControllerHelper;
16 use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle\FHIRBundleEntry;
17 use OpenEMR\Validators\ProcessingResult;
19 class FhirDiagnosticReportRestController
21 private $fhirService;
23 public function __construct()
25 $this->fhirService = new FhirResourcesService();
28 /**
29 * Queries for a single FHIR location resource by FHIR id
30 * @param $fhirId The FHIR location resource id (uuid)
31 * @param $puuidBind - Optional variable to only allow visibility of the patient with this puuid.
32 * @returns 200 if the operation completes successfully
34 public function getOne($fhirId, $puuidBind = null)
36 $processingResult = new ProcessingResult(); // return nothing for now
37 return RestControllerHelper::handleFhirProcessingResult($processingResult, 200);
40 /**
41 * Queries for FHIR location resources using various search parameters.
42 * @param $puuidBind - Optional variable to only allow visibility of the patient with this puuid.
43 * @return FHIR bundle with query results, if found
45 public function getAll($searchParams, $puuidBind = null)
47 $processingResult = new ProcessingResult(); // return nothing for now
48 $bundleEntries = array();
49 foreach ($processingResult->getData() as $index => $searchResult) {
50 $bundleEntry = [
51 'fullUrl' => $GLOBALS['site_addr_oath'] . ($_SERVER['REDIRECT_URL'] ?? '') . '/' . $searchResult->getId(),
52 'resource' => $searchResult
54 $fhirBundleEntry = new FHIRBundleEntry($bundleEntry);
55 array_push($bundleEntries, $fhirBundleEntry);
57 $bundleSearchResult = $this->fhirService->createBundle('CarePlan', $bundleEntries, false);
58 $searchResponseBody = RestControllerHelper::responseHandler($bundleSearchResult, null, 200);
59 return $searchResponseBody;