From 2415f81f85a95c6697e24d37929b87935448e526 Mon Sep 17 00:00:00 2001 From: Stephen Nielson Date: Wed, 13 Sep 2023 07:53:59 -0400 Subject: [PATCH] feat: Fixes #6851,#6849,#6827 api changes. (#6852) * Fixes #6851,#6849,#6827 api changes. Fixes #6851 change sort order of title field Fixes #6849 add extension url lookup FHIR utility method Fixes #6827 add patient provider/general practitioner to apis * Fix test condition if provider_uuid is missing --- src/Services/FHIR/FhirPatientService.php | 20 ++++++++++++++++++-- src/Services/FHIR/FhirServiceBase.php | 13 +++++++++---- src/Services/FHIR/UtilsService.php | 11 +++++++++++ src/Services/PatientService.php | 11 +++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Services/FHIR/FhirPatientService.php b/src/Services/FHIR/FhirPatientService.php index ae67d36e5..3a2acc225 100644 --- a/src/Services/FHIR/FhirPatientService.php +++ b/src/Services/FHIR/FhirPatientService.php @@ -108,7 +108,7 @@ class FhirPatientService extends FhirServiceBase implements IFhirExportableResou // 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( @@ -143,7 +143,8 @@ class FhirPatientService extends FhirServiceBase implements IFhirExportableResou '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']) ]; } @@ -184,6 +185,7 @@ class FhirPatientService extends FhirServiceBase implements IFhirExportableResou $this->parseOpenEMRSocialSecurityRecord($patientResource, $dataRecord['ss']); $this->parseOpenEMRPublicPatientIdentifier($patientResource, $dataRecord['pubpid']); $this->parseOpenEMRCommunicationRecord($patientResource, $dataRecord['language']); + $this->parseOpenEMRGeneralPractitioner($patientResource, $dataRecord); if ($encode) { @@ -458,6 +460,13 @@ class FhirPatientService extends FhirServiceBase implements IFhirExportableResou } } + 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(); @@ -580,6 +589,13 @@ class FhirPatientService extends FhirServiceBase implements IFhirExportableResou } } + 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; } diff --git a/src/Services/FHIR/FhirServiceBase.php b/src/Services/FHIR/FhirServiceBase.php index 1478b938f..197850680 100644 --- a/src/Services/FHIR/FhirServiceBase.php +++ b/src/Services/FHIR/FhirServiceBase.php @@ -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; } /** @@ -120,7 +125,7 @@ abstract class FhirServiceBase implements IResourceSearchableService, IResourceR /** * 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 { @@ -130,7 +135,7 @@ abstract class FhirServiceBase implements IResourceSearchableService, IResourceR /** * Inserts an OpenEMR record into the sytem. - * @return The OpenEMR processing result. + * @return ProcessingResult The OpenEMR processing result. */ abstract protected function insertOpenEMRRecord($openEmrRecord); diff --git a/src/Services/FHIR/UtilsService.php b/src/Services/FHIR/UtilsService.php index 1b7cbf014..28eac5d55 100644 --- a/src/Services/FHIR/UtilsService.php +++ b/src/Services/FHIR/UtilsService.php @@ -160,6 +160,17 @@ class UtilsService 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(); diff --git a/src/Services/PatientService.php b/src/Services/PatientService.php index ee6e3b37e..f03d2b816 100644 --- a/src/Services/PatientService.php +++ b/src/Services/PatientService.php @@ -325,6 +325,10 @@ class PatientService extends BaseService $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; } @@ -388,6 +392,7 @@ class PatientService extends BaseService ,previous_name_suffix ,previous_name_enddate ,patient_additional_addresses.* + ,provider_uuid "; $sql = " FROM patient_data @@ -407,6 +412,12 @@ class PatientService extends BaseService 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 ,contact.foreign_id AS contact_address_patient_id -- 2.11.4.GIT