Using getAll() function in PatientService.php to search for patients

I am attempting to use the getAll() function in PatientService.php to search for patients. I can search for patients, but I am not sure how to handle or process the result. Here is my code:

<?php
	if (php_sapi_name() !== 'cli') {
	    exit;
	}
	set_time_limit(0);

	session_name("OpenEMR");
	$ignoreAuth = true;
	$fake_register_globals = false;
	$sanitize_all_escapes = true;
	$_SESSION['site'] = 'default';
	$_SESSION['site_id'] = 'default';
	$_SERVER['HTTP_HOST'] = 'localhost';
	require_once __DIR__.'/interface/globals.php';

	use OpenEMR\Services\PatientService;
    $patient = array(
		"fname" => "mista",
		"lname" => "wintas"
	);
	
	echo 'Begin SQL test';
	$patientService = new PatientService();
	$search_patient = $patientService->getAll($patient);
	var_dump($search_patient["data"]);
	if ($search_patient['fname']) {
		echo "found patient";
	} else {
		echo "patient not found";
	}
?>

Specifically, I am just trying to test whether or not an affirmative result is returned or not; ie, if the patient exists in the database.

Looking at the results that is returned using a var_dump is looks like this:

object(OpenEMR\Validators\ProcessingResult)#315 (3) {
  ["validationMessages":"OpenEMR\Validators\ProcessingResult":private]=>
  array(0) {
  }
  ["internalErrors":"OpenEMR\Validators\ProcessingResult":private]=>
  array(0) {
  }
  ["data":"OpenEMR\Validators\ProcessingResult":private]=>
  array(1) {
    [0]=>
    array(27) {
      ["id"]=>
      string(6) "234324"
      ["pid"]=>
      string(6) "23423"
      ["uuid"]=>
      string(36) "93ae3cc7-64f6-342432-8dc0-2342342"
      ["pubpid"]=>
      string(18) "3423 / NS:wrw"
      ["title"]=>
      string(0) ""
      ["fname"]=>
      string(8) "jane"
      ["mname"]=>
      string(0) ""
      ["lname"]=>
      string(8) "doe"
      ["ss"]=>
      string(1) " "
      ["street"]=>
      string(19) "2774 Wintas Rd."
      ["postal_code"]=>
      string(5) "23423"
      ["city"]=>
      string(7) "any town"
      ["state"]=>
      string(0) ""
      ["county"]=>
      string(0) ""
      ["country_code"]=>
      string(0) ""
      ["drivers_license"]=>
      string(0) ""
      ["contact_relationship"]=>
      string(0) ""
      ["phone_contact"]=>
      string(0) ""
      ["phone_home"]=>
      string(1) " "
      ["phone_biz"]=>
      string(0) ""
      ["phone_cell"]=>
      string(12) "555-555-1212"
      ["email"]=>
      string(0) ""
      ["DOB"]=>
      string(10) "1877-08-24"
      ["sex"]=>
      string(6) "Female"
      ["race"]=>
      string(0) ""
      ["ethnicity"]=>
      string(0) ""
      ["status"]=>
      string(0) ""
    }
  }
}

Looking at the object type this appears to be a patient object and an associative array, but Iā€™m tried all manner of $search_patient['fname'] or $search_patient[0] to no avail.

Any info appreciated!

hi @lumbee, use $search_patient->getdata();

1 Like

Thank you! For posterity accessing a specific element looks like:

    $patientService = new PatientService();
	$search_patient = $patientService->getAll($patient);
	$patient = $search_patient->getdata();
	var_dump($patient[0]['fname']);