Skip to content
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 6 commits into from
Aug 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

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
yashrajbothra committed Aug 13, 2020
commit aef3b2ffcc7a00c7ee92aad4e33b4e9b65604060
183 changes: 183 additions & 0 deletions src/Services/LocationService.php
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
);
Copy link
Member

@bradymiller bradymiller Aug 14, 2020

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?

Copy link
Contributor Author

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 :)


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;
}
}