forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding/Upgrading Organization Resource (openemr#3662)
* Changing Function Names Signed-off-by: Yash Bothra <[email protected]> * Added UUID to Facility Signed-off-by: Yash Bothra <[email protected]> * Upgraded Standard Facility Endpoints Signed-off-by: Yash Bothra <[email protected]> * Upgraded FHIR Organization Endpoints with Tests Signed-off-by: Yash Bothra <[email protected]> * Some More Upgrades Signed-off-by: Yash Bothra <[email protected]> * Some Fixes Signed-off-by: Yash Bothra <[email protected]> * Added CLIA and Fax in FHIR Signed-off-by: Yash Bothra <[email protected]> * Fixture fix Signed-off-by: Yash Bothra <[email protected]>
- Loading branch information
1 parent
c33cc92
commit 87d6093
Showing
31 changed files
with
1,886 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,70 +7,105 @@ | |
use OpenEMR\Services\FHIR\FhirResourcesService; | ||
use OpenEMR\RestControllers\RestControllerHelper; | ||
use OpenEMR\FHIR\R4\FHIRResource\FHIRBundle\FHIRBundleEntry; | ||
use OpenEMR\Validators\ProcessingResult; | ||
|
||
require_once(__DIR__ . '/../../../_rest_config.php'); | ||
/** | ||
* FHIR Organization Service | ||
* | ||
* @coversDefaultClass OpenEMR\Services\FHIR\FhirOrganizationService | ||
* @package OpenEMR | ||
* @link http:https://www.open-emr.org | ||
* @author Yash Bothra <[email protected]> | ||
* @copyright Copyright (c) 2020 Yash Bothra <[email protected]> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
* | ||
*/ | ||
class FhirOrganizationRestController | ||
{ | ||
private $fhirOrganizationService; | ||
private $fhirService; | ||
private $fhirValidationService; | ||
|
||
public function __construct($pid) | ||
public function __construct() | ||
{ | ||
$this->fhirOrganizationService = new FhirOrganizationService(); | ||
$this->fhirOrganizationService->setId($pid); | ||
$this->fhirService = new FhirResourcesService(); | ||
$this->fhirOrganizationService = new FhirOrganizationService(); | ||
$this->fhirValidationService = new FhirValidationService(); | ||
} | ||
|
||
public function getAll($search) | ||
/** | ||
* Queries for FHIR organization resources using various search parameters. | ||
* Search parameters include: | ||
* - address (street, postal_code, city, country_code or state) | ||
* - address-city | ||
* - address-postalcode | ||
* - address-state | ||
* - name | ||
* - phone (work) | ||
* - telecom (email, phone) | ||
* @return FHIR bundle with query results, if found | ||
*/ | ||
public function getAll($searchParams) | ||
{ | ||
$result = $this->fhirOrganizationService->getAll(); | ||
if (!$result) { | ||
$statusCode = 400; | ||
$result = $this->fhirValidationService->operationOutcomeResourceService( | ||
'error', | ||
'invalid', | ||
false, | ||
"Invalid Parameter" | ||
); | ||
} else { | ||
$statusCode = 200; | ||
$entries = array(); | ||
foreach ($result as $org) { | ||
$entryResource = $this->fhirOrganizationService->createOrganizationResource( | ||
$org['id'], | ||
$org, | ||
false, | ||
$org['code'], | ||
$org['display'] | ||
); | ||
$entry = array( | ||
'fullUrl' => $resourceURL . "/" . $org['id'], | ||
'resource' => $entryResource | ||
); | ||
$entries[] = new FHIRBundleEntry($entry); | ||
} | ||
$result = $this->fhirService->createBundle('Organization', $entries, false); | ||
$processingResult = $this->fhirOrganizationService->getAll($searchParams); | ||
$bundleEntries = array(); | ||
foreach ($processingResult->getData() as $index => $searchResult) { | ||
$bundleEntry = [ | ||
'fullUrl' => \RestConfig::$REST_FULL_URL . '/' . $searchResult->getId(), | ||
'resource' => $searchResult | ||
]; | ||
$fhirBundleEntry = new FHIRBundleEntry($bundleEntry); | ||
array_push($bundleEntries, $fhirBundleEntry); | ||
} | ||
return RestControllerHelper::responseHandler($result, null, $statusCode); | ||
$bundleSearchResult = $this->fhirService->createBundle('Organization', $bundleEntries, false); | ||
$searchResponseBody = RestControllerHelper::responseHandler($bundleSearchResult, null, 200); | ||
return $searchResponseBody; | ||
} | ||
|
||
|
||
/** | ||
* Queries for a single FHIR organization resource by FHIR id | ||
* @param $fhirId The FHIR organization resource id (uuid) | ||
* @returns 200 if the operation completes successfully | ||
*/ | ||
public function getOne($fhirId) | ||
{ | ||
$processingResult = $this->fhirOrganizationService->getOne($fhirId, true); | ||
return RestControllerHelper::handleProcessingResult($processingResult, 200); | ||
} | ||
|
||
/** | ||
* Creates a new FHIR organization resource | ||
* @param $fhirJson The FHIR organization resource | ||
* @returns 201 if the resource is created, 400 if the resource is invalid | ||
*/ | ||
public function post($fhirJson) | ||
{ | ||
$fhirValidationService = $this->fhirValidationService->validate($fhirJson); | ||
if (!empty($fhirValidationService)) { | ||
return RestControllerHelper::responseHandler($fhirValidationService, null, 400); | ||
} | ||
|
||
$processingResult = $this->fhirOrganizationService->insert($fhirJson); | ||
return RestControllerHelper::handleProcessingResult($processingResult, 201); | ||
} | ||
|
||
public function getOne($oid) | ||
/** | ||
* Updates an existing FHIR organization resource | ||
* @param $fhirId The FHIR organization resource id (uuid) | ||
* @param $fhirJson The updated FHIR organization resource (complete resource) | ||
* @returns 200 if the resource is created, 400 if the resource is invalid | ||
*/ | ||
public function patch($fhirId, $fhirJson) | ||
{ | ||
$result = $this->fhirOrganizationService->getOne($oid); | ||
if ($result) { | ||
$resource = $this->fhirOrganizationService->createOrganizationResource($result['id'], $result, false, $result['code'], $result['display']); | ||
$statusCode = 200; | ||
} else { | ||
$statusCode = 404; | ||
$resource = $this->fhirValidationService->operationOutcomeResourceService( | ||
'error', | ||
'invalid', | ||
false, | ||
"Resource Id $pid does not exist" | ||
); | ||
$fhirValidationService = $this->fhirValidationService->validate($fhirJson); | ||
if (!empty($fhirValidationService)) { | ||
return RestControllerHelper::responseHandler($fhirValidationService, null, 400); | ||
} | ||
|
||
return RestControllerHelper::responseHandler($resource, null, $statusCode); | ||
$processingResult = $this->fhirOrganizationService->update($fhirId, $fhirJson); | ||
return RestControllerHelper::handleProcessingResult($processingResult, 200); | ||
} | ||
} |
Oops, something went wrong.