Using the insertEncounter method to create a new encounter

I am trying to use the insertEncounter method in src/Services/EncounterService.php to create a new encounter for a patient.

Here is my code:

//create patient
	$patient = array("fname" => "Marky", "lname" => "Locklear", "DOB" => "09/05/1972", "home_phone" => "");
	$new_patient = $patientService->databaseInsert($patient);

	$data = array("date" => "08/23/2021", "reason" => "locklear test");

	//create encounter
	$new_encounter = $encounterService->insertEncounter($new_patient['pid'], $data);

When I run this I get the error “Patient UUID is invalid”. Is there some other id I could be using? I tried using the uuid instead but get a the error “Patient UUID must be a valid UUID (valid format)”.

Thanks in advance.

good question @lumbee, @adunsulag, could you verify that we should be calling uuidToBytes here when the encounter validator is passing in true?

So the patient databaseInsert returns the UUID in binary and the encounter service expects the uuid to be a string. I’d rather we send back the patient uuid as a string on the insert of the PatientService. It looks that that is what we do in the insert() method and updatePatientData() method (the downside is that those return a ProcessingResult object).

1 Like

could we put this into the databaseInsert function and optionally change the signature to include $uuidAsString = false?

if ($results) {
            // return the uuid as a string for friendly result set to use with encounter service
            $data['uuid'] = UuidRegistry::uuidToString($data['uuid']);
            return $data;
        } else {
            return false;
        }

For posterity, required fields also need pc_catid and class_code. Here is my updated script that includes uuidToString.

//create patient
	$patient = array("fname" => "Marky", "lname" => "Locklear", "DOB" => "09/05/1972",     "home_phone" => "");
    $new_patient = $patientService->databaseInsert($patient);

//create encounter
	$data = array("date" => "08/23/2021", "reason" => "locklear test", "pc_catid" => 10, "class_code" => "AMB");
	$new_encounter = $encounterService->insertEncounter(UuidRegistry::uuidToString($new_patient['uuid']), $data);