Dev Advice Needed: How to display previous encounter data of a form

I am working on creating custom forms for my clinic. I would like to know how to retrieve data of a form from the previous encounter of a patient. I have been trying something like this just to access any data from the database (in this case for the current patient) in the new.php file of the form, but I’m not having much luck. I will keep playing around with this and figure out a way to get the data. Any suggestions are welcome. If necessary, I will establish my own database connection and get the data that way.

(This fails … working on enabling debug messages in PHP to figure out the problem)

if (is_numeric($pid)) {
    $result = getPatientData($pid, "fname,lname");
    echo 'true';
}

The issue was that I needed to include patient.inc
I know that I’m getting a lot of great help with this. Thank you! I’m just continuing to explore form development so that I improve my knowledge and contribute more.