Skip to content

Commit

Permalink
Merge pull request openemr#6385 from DiscoverAndChange/bug-openemr-fi…
Browse files Browse the repository at this point in the history
…x-6384-encounter-location

Fix encounter location to provide facility data
  • Loading branch information
adunsulag committed Apr 22, 2023
2 parents b0187dd + ad8c89a commit 2a2a310
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/Services/FHIR/FhirLocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,33 @@ protected function searchForOpenEMRRecords($openEMRSearchParameters): Processing
// even though its not a patient compartment issue we still don't want certain location data such as clinician home addresses
// being returned... or other patient locations... Wierd that its not in the patient compartment
if (!empty($this->patientUuid)) {
// when we are patient bound we only want facility data returned or return just that patient's information.
$patientType = new CompositeSearchField('patient-type', [], false);
// if there is no uuid search field this becomes
// (table_uuid = ? and type = 'patient') OR (type = 'facility')
// if there is an uuid search field this becomes:
// (table_uuid = ? and type = 'patient' and uuid = ?) OR (type = 'facility' AND uuid = ?)

$patientType = new CompositeSearchField('patient-type', [], true);
// patient id is the target_uuid, the uuid column is the mapped 'Location' resource in FHIR
$patientType->addChild(new TokenSearchField('table_uuid', [new TokenSearchValue($this->patientUuid, null, true)]));
$patientType->addChild(new TokenSearchField('type', [new TokenSearchValue(LocationService::TYPE_FACILITY)]));
$openEMRSearchParameters['patient-type'] = $patientType;
$patientType->addChild(new TokenSearchField('type', [new TokenSearchValue(LocationService::TYPE_PATIENT)]));

$facilityType = new CompositeSearchField('facility-type', [], true);
$facilityType->addChild(new TokenSearchField('type', [new TokenSearchValue(LocationService::TYPE_FACILITY)]));

if (!empty($openEMRSearchParameters['uuid'])) {
// id must match the patient type as well
$patientType->addChild($openEMRSearchParameters['uuid']);

// or id must match the facility location
$facilityType->addChild($openEMRSearchParameters['uuid']);
unset($openEMRSearchParameters['uuid']);
}

// if we are patient bound we want to make sure we grab only patient locations or facility locations
$patientFacilityType = new CompositeSearchField('patient-facility-type', [], false);
$patientFacilityType->addChild($facilityType);
$patientFacilityType->addChild($patientType);
$openEMRSearchParameters['patient-facility-type'] = $patientFacilityType;
}
return $this->locationService->getAll($openEMRSearchParameters, false);
}
Expand Down

0 comments on commit 2a2a310

Please sign in to comment.