-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All New FHIR Location Resource #3829
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aef3b2f
Added Standard Location Service
yashrajbothra ebfa2c5
Added Endpoints for Location Resource
yashrajbothra 67298c5
Updated Docs
yashrajbothra 9b8dc22
Fixes
yashrajbothra b6d8abe
Applied new UUID Mechanism
yashrajbothra a7f324e
Removed Multiple ID funtion
yashrajbothra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Added Standard Location Service
Signed-off-by: Yash Bothra <yashrajbothra786@gmail.com>
- Loading branch information
commit aef3b2ffcc7a00c7ee92aad4e33b4e9b65604060
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
|
||
/** | ||
* LocationService | ||
* | ||
* @package OpenEMR | ||
* @link http://www.open-emr.org | ||
* @author Yash Bothra <yashrajbothra786gmail.com> | ||
* @copyright Copyright (c) 2020 Yash Bothra <yashrajbothra786gmail.com> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
namespace OpenEMR\Services; | ||
|
||
use OpenEMR\Common\Uuid\UuidRegistry; | ||
use OpenEMR\Validators\BaseValidator; | ||
use OpenEMR\Validators\ProcessingResult; | ||
|
||
class LocationService extends BaseService | ||
{ | ||
private const PATIENT_TABLE = "patient_data"; | ||
private const PRACTITIONER_TABLE = "users"; | ||
private const FACILITY_TABLE = "facility"; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
(new UuidRegistry(['table_name' => self::PATIENT_TABLE]))->createMissingUuids(); | ||
(new UuidRegistry(['table_name' => self::PRACTITIONER_TABLE]))->createMissingUuids(); | ||
(new UuidRegistry(['table_name' => self::FACILITY_TABLE]))->createMissingUuids(); | ||
} | ||
|
||
/** | ||
* Returns a list of locations matching optional search criteria. | ||
* Search criteria is conveyed by array where key = field/column name, value = field value. | ||
* If no search criteria is provided, all records are returned. | ||
* | ||
* @param $search search array parameters | ||
* @param $isAndCondition specifies if AND condition is used for multiple criteria. Defaults to true. | ||
* @return ProcessingResult which contains validation messages, internal error messages, and the data | ||
* payload. | ||
*/ | ||
public function getAll($search = array(), $isAndCondition = true) | ||
{ | ||
$sqlBindArray = array(); | ||
|
||
$sql = 'SELECT location.* FROM | ||
(SELECT | ||
uuid, | ||
CONCAT(fname,"\'s Home") as name, | ||
street, | ||
city, | ||
postal_code, | ||
state, | ||
country_code, | ||
phone_cell as phone, | ||
null as fax, | ||
null as website, | ||
email from patient_data | ||
UNION SELECT | ||
uuid, | ||
name, | ||
street, | ||
city, | ||
postal_code, | ||
state, | ||
country_code, | ||
phone, | ||
fax, | ||
website, | ||
email from facility | ||
UNION SELECT | ||
uuid, | ||
CONCAT(fname,"\'s Home") as name, | ||
street, | ||
city, | ||
zip as postal_code, | ||
state, | ||
null as country_code, | ||
phone, | ||
fax, | ||
url as website, | ||
email from users) as location'; | ||
|
||
if (!empty($search)) { | ||
$sql .= ' WHERE '; | ||
$whereClauses = array(); | ||
foreach ($search as $fieldName => $fieldValue) { | ||
array_push($whereClauses, $fieldName . ' = ?'); | ||
array_push($sqlBindArray, $fieldValue); | ||
} | ||
$sqlCondition = ($isAndCondition == true) ? 'AND' : 'OR'; | ||
$sql .= implode(' ' . $sqlCondition . ' ', $whereClauses); | ||
} | ||
|
||
$statementResults = sqlStatement($sql, $sqlBindArray); | ||
|
||
$processingResult = new ProcessingResult(); | ||
while ($row = sqlFetchArray($statementResults)) { | ||
$row['uuid'] = UuidRegistry::uuidToString($row['uuid']); | ||
$processingResult->addData($row); | ||
} | ||
|
||
return $processingResult; | ||
} | ||
|
||
/** | ||
* Returns a single location record by id. | ||
* @param $uuid - The location uuid identifier in string format. | ||
* @return ProcessingResult which contains validation messages, internal error messages, and the data | ||
* payload. | ||
*/ | ||
public function getOne($uuid) | ||
{ | ||
$processingResult = new ProcessingResult(); | ||
|
||
$isValid = BaseValidator::validateIdMultiple( | ||
"uuid", | ||
array( | ||
self::FACILITY_TABLE, | ||
self::PRACTITIONER_TABLE, | ||
self::PATIENT_TABLE | ||
), | ||
$uuid, | ||
true | ||
); | ||
|
||
if ($isValid !== true) { | ||
$validationMessages = [ | ||
'uuid' => ["invalid or nonexisting value" => " value " . $uuid] | ||
]; | ||
$processingResult->setValidationMessages($validationMessages); | ||
return $processingResult; | ||
} | ||
|
||
$sql = 'SELECT location.* FROM | ||
(SELECT | ||
uuid, | ||
CONCAT(fname,"\'s Home") as name, | ||
street, | ||
city, | ||
postal_code, | ||
state, | ||
country_code, | ||
phone_cell as phone, | ||
null as fax, | ||
null as website, | ||
email from patient_data | ||
UNION SELECT | ||
uuid, | ||
name, | ||
street, | ||
city, | ||
postal_code, | ||
state, | ||
country_code, | ||
phone, | ||
fax, | ||
website, | ||
email from facility | ||
UNION SELECT | ||
uuid, | ||
CONCAT(fname,"\'s Home") as name, | ||
street, | ||
city, | ||
zip as postal_code, | ||
state, | ||
null as country_code, | ||
phone, | ||
fax, | ||
url as website, | ||
email from users) as location | ||
WHERE location.uuid=?'; | ||
|
||
$uuidBinary = UuidRegistry::uuidToBytes($uuid); | ||
$sqlResult = sqlQuery($sql, [$uuidBinary]); | ||
$sqlResult['uuid'] = UuidRegistry::uuidToString($sqlResult['uuid']); | ||
$processingResult->addData($sqlResult); | ||
return $processingResult; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this validating the correct table(s). Aren't the uuid's that you are searching with stored in the uuid_mapping table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, Also we don't need this Multiple Id function now :)