Skip to content

Commit

Permalink
feat: Fixes openemr#6851,openemr#6849,openemr#6827 api changes. (open…
Browse files Browse the repository at this point in the history
…emr#6852)

* Fixes openemr#6851,openemr#6849,openemr#6827 api changes.

Fixes openemr#6851 change sort order of title field
Fixes openemr#6849 add extension url lookup FHIR utility method
Fixes openemr#6827 add patient provider/general practitioner to apis

* Fix test condition if provider_uuid is missing
  • Loading branch information
adunsulag authored Sep 13, 2023
1 parent 8d7286f commit 2415f81
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/Services/FHIR/FhirPatientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function loadSearchParameters()
// core FHIR required fields for now
'_id' => $this->getPatientContextSearchField(),
'identifier' => new FhirSearchParameterDefinition('identifier', SearchFieldType::TOKEN, ['ss', 'pubpid']),
'name' => new FhirSearchParameterDefinition('name', SearchFieldType::STRING, ['title', 'fname', 'mname', 'lname']),
'name' => new FhirSearchParameterDefinition('name', SearchFieldType::STRING, ['fname', 'mname', 'lname', 'title']),
'birthdate' => new FhirSearchParameterDefinition('birthdate', SearchFieldType::DATE, ['DOB']),
'gender' => new FhirSearchParameterDefinition('gender', SearchFieldType::TOKEN, [self::FIELD_NAME_GENDER]),
'address' => new FhirSearchParameterDefinition(
Expand Down Expand Up @@ -143,7 +143,8 @@ protected function loadSearchParameters()
'given' => new FhirSearchParameterDefinition('given', SearchFieldType::STRING, ['fname', 'mname']),
'phone' => new FhirSearchParameterDefinition('phone', SearchFieldType::TOKEN, ['phone_home', 'phone_biz', 'phone_cell']),
'telecom' => new FhirSearchParameterDefinition('telecom', SearchFieldType::TOKEN, ['email', 'phone_home', 'phone_biz', 'phone_cell']),
'_lastUpdated' => new FhirSearchParameterDefinition('_lastUpdated', SearchFieldType::DATETIME, ['date'])
'_lastUpdated' => new FhirSearchParameterDefinition('_lastUpdated', SearchFieldType::DATETIME, ['date']),
'generalPractitioner' => new FhirSearchParameterDefinition('generalPractitioner', SearchFieldType::REFERENCE, ['provider_uuid'])
];
}

Expand Down Expand Up @@ -184,6 +185,7 @@ public function parseOpenEMRRecord($dataRecord = array(), $encode = false)
$this->parseOpenEMRSocialSecurityRecord($patientResource, $dataRecord['ss']);
$this->parseOpenEMRPublicPatientIdentifier($patientResource, $dataRecord['pubpid']);
$this->parseOpenEMRCommunicationRecord($patientResource, $dataRecord['language']);
$this->parseOpenEMRGeneralPractitioner($patientResource, $dataRecord);


if ($encode) {
Expand Down Expand Up @@ -458,6 +460,13 @@ private function parseOpenEMRCommunicationRecord(FHIRPatient $patientResource, $
}
}

private function parseOpenEMRGeneralPractitioner(FHIRPatient $patientResource, array $dataRecord)
{
if (!empty($dataRecord['provider_uuid'])) {
$patientResource->addGeneralPractitioner(UtilsService::createRelativeReference('Practitioner', $dataRecord['provider_uuid']));
}
}

private function createIdentifier($use, $system, $code, $systemUri, $value): FHIRIdentifier
{
$identifier = new FHIRIdentifier();
Expand Down Expand Up @@ -580,6 +589,13 @@ public function parseFhirResource(FHIRDomainResource $fhirResource)
}
}

if (!empty($fhirResource->getGeneralPractitioner())) {
$providerReference = UtilsService::parseReference($fhirResource->getGeneralPractitioner()[0]);
if (!empty($providerReference) && $providerReference['resourceType'] === 'Practitioner' && $providerReference['localResource']) {
$data['provider_uuid'] = $providerReference['uuid'];
}
}

return $data;
}

Expand Down
13 changes: 9 additions & 4 deletions src/Services/FHIR/FhirServiceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,23 @@ abstract class FhirServiceBase implements IResourceSearchableService, IResourceR

public function __construct($fhirApiURL = null)
{
$this->fhirApiURL = $fhirApiURL;
$params = $this->loadSearchParameters();
$this->resourceSearchParameters = is_array($params) ? $params : [];
$searchFieldFactory = new FHIRSearchFieldFactory($this->resourceSearchParameters);
$this->setSearchFieldFactory($searchFieldFactory);
$this->setFhirApiUrl($fhirApiURL);
}

public function setFhirApiUrl($fhirApiURL)
{
// anything using a 'reference' search field MUST have a URL resolver to handle the reference translation
// so if we have the api url we are going to create our resolver.
if (!empty($fhirApiURL)) {
$searchFieldFactory = $this->getSearchFieldFactory();
$urlResolver = new FhirUrlResolver($fhirApiURL);
$searchFieldFactory->setFhirUrlResolver($urlResolver);
}
$this->setSearchFieldFactory($searchFieldFactory);
$this->fhirApiURL = $fhirApiURL;
}

/**
Expand Down Expand Up @@ -120,7 +125,7 @@ abstract public function parseFhirResource(FHIRDomainResource $fhirResource);
/**
* Inserts a FHIR resource into the system.
* @param $fhirResource The FHIR resource
* @return The OpenEMR Service Result
* @return ProcessingResult The OpenEMR Service Result
*/
public function insert(FHIRDomainResource $fhirResource): ProcessingResult
{
Expand All @@ -130,7 +135,7 @@ public function insert(FHIRDomainResource $fhirResource): ProcessingResult

/**
* Inserts an OpenEMR record into the sytem.
* @return The OpenEMR processing result.
* @return ProcessingResult The OpenEMR processing result.
*/
abstract protected function insertOpenEMRRecord($openEmrRecord);

Expand Down
11 changes: 11 additions & 0 deletions src/Services/FHIR/UtilsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ public static function createDataMissingExtension()
return $outerExtension;
}

public static function getExtensionsByUrl($url, $object)
{
if (method_exists($object, 'getExtension')) {
$extensions = $object->getExtension();
return array_filter($extensions, function ($extension) use ($url) {
return $extension->getUrl() == $url;
});
}
return [];
}

public static function createContactPoint($value, $system, $use): FHIRContactPoint
{
$fhirContactPoint = new FHIRContactPoint();
Expand Down
11 changes: 11 additions & 0 deletions src/Services/PatientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ protected function createResultRecordFromDatabaseResult($record)
$record['patient_history_uuid'] = UuidRegistry::uuidToString($record['patient_history_uuid']);
}

if (!empty($record['provider_uuid'])) {
$record['provider_uuid'] = UuidRegistry::uuidToString($record['provider_uuid']);
}

return $record;
}

Expand Down Expand Up @@ -388,6 +392,7 @@ public function search($search, $isAndCondition = true, SearchQueryConfig $confi
,previous_name_suffix
,previous_name_enddate
,patient_additional_addresses.*
,provider_uuid
";
$sql = "
FROM patient_data
Expand All @@ -406,6 +411,12 @@ public function search($search, $isAndCondition = true, SearchQueryConfig $confi
,uuid AS patient_history_uuid
FROM patient_history
) patient_history ON patient_data.pid = patient_history.patient_history_pid
LEFT JOIN (
select
id AS provider_id
,uuid AS provider_uuid
FROM users
) provider ON patient_data.providerID = provider.provider_id
LEFT JOIN (
SELECT
contact.id AS contact_address_contact_id
Expand Down

0 comments on commit 2415f81

Please sign in to comment.