3 namespace OpenEMR\RestControllers\FHIR
;
5 use OpenEMR\Services\FHIR\FhirValidationService
;
6 use OpenEMR\Services\FHIR\FhirOrganizationService
;
7 use OpenEMR\Services\FHIR\FhirResourcesService
;
8 use OpenEMR\RestControllers\RestControllerHelper
;
9 use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle\FHIRBundleEntry
;
10 use OpenEMR\Validators\ProcessingResult
;
12 require_once(__DIR__
. '/../../../_rest_config.php');
14 * FHIR Organization Service
16 * @coversDefaultClass OpenEMR\Services\FHIR\FhirOrganizationService
18 * @link http://www.open-emr.org
19 * @author Yash Bothra <yashrajbothra786@gmail.com>
20 * @copyright Copyright (c) 2020 Yash Bothra <yashrajbothra786@gmail.com>
21 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
24 class FhirOrganizationRestController
27 * @var FhirOrganizationService
29 private $fhirOrganizationService;
31 private $fhirValidationService;
33 public function __construct()
35 $this->fhirService
= new FhirResourcesService();
36 $this->fhirOrganizationService
= new FhirOrganizationService();
37 $this->fhirValidationService
= new FhirValidationService();
41 * Queries for FHIR organization resources using various search parameters.
42 * Search parameters include:
43 * - address (street, postal_code, city, country_code or state)
45 * - address-postalcode
50 * - telecom (email, phone)
51 * @return FHIR bundle with query results, if found
53 public function getAll($searchParams)
55 $processingResult = $this->fhirOrganizationService
->getAll($searchParams);
56 $bundleEntries = array();
57 // TODO: adunsulag why isn't this work done in the fhirService->createBundle?
58 foreach ($processingResult->getData() as $index => $searchResult) {
60 'fullUrl' => $GLOBALS['site_addr_oath'] . ($_SERVER['REDIRECT_URL'] ??
'') . '/' . $searchResult->getId(),
61 'resource' => $searchResult
63 $fhirBundleEntry = new FHIRBundleEntry($bundleEntry);
64 array_push($bundleEntries, $fhirBundleEntry);
66 $bundleSearchResult = $this->fhirService
->createBundle('Organization', $bundleEntries, false);
67 $searchResponseBody = RestControllerHelper
::responseHandler($bundleSearchResult, null, 200);
68 return $searchResponseBody;
73 * Queries for a single FHIR organization resource by FHIR id
74 * @param $fhirId The FHIR organization resource id (uuid)
75 * @returns 200 if the operation completes successfully
77 public function getOne($fhirId)
79 $processingResult = $this->fhirOrganizationService
->getOne($fhirId, true);
80 return RestControllerHelper
::handleFhirProcessingResult($processingResult, 200);
84 * Creates a new FHIR organization resource
85 * @param $fhirJson The FHIR organization resource
86 * @returns 201 if the resource is created, 400 if the resource is invalid
88 public function post($fhirJson)
90 $fhirValidationService = $this->fhirValidationService
->validate($fhirJson);
91 if (!empty($fhirValidationService)) {
92 return RestControllerHelper
::responseHandler($fhirValidationService, null, 400);
95 $processingResult = $this->fhirOrganizationService
->insert($fhirJson);
96 return RestControllerHelper
::handleFhirProcessingResult($processingResult, 201);
100 * Updates an existing FHIR organization resource
101 * @param $fhirId The FHIR organization resource id (uuid)
102 * @param $fhirJson The updated FHIR organization resource (complete resource)
103 * @returns 200 if the resource is created, 400 if the resource is invalid
105 public function patch($fhirId, $fhirJson)
107 $fhirValidationService = $this->fhirValidationService
->validate($fhirJson);
108 if (!empty($fhirValidationService)) {
109 return RestControllerHelper
::responseHandler($fhirValidationService, null, 400);
112 $processingResult = $this->fhirOrganizationService
->update($fhirId, $fhirJson);
113 return RestControllerHelper
::handleFhirProcessingResult($processingResult, 200);