Code for copying data from previous encounter

I’ve been building a new LBF and have noticed there is capability to “copy from last encounter” in the options.

I already have a custom form that I coded manually that I’d like to add this functionality to.

Can anyone point me to where in the codebase that functionality is handled so I can work out how to implement it for my own form?

For the record, my ideal setup would be to build a button onto my form that pulls in the data from the last encounter once clicked.

Any help would be appreciated!

Hi @BenFosterPsyD ,

I do have my own form as well. Here is how I copy the note from previous encounter:

} else {

    // Get the previous assessment value for this patient

$previous_assessment_sql = "SELECT assessment FROM form_enhanced 

WHERE pid = ? AND assessment IS NOT NULL AND assessment != '' 

ORDER BY date DESC, id DESC LIMIT 1";

$previous_result = sqlStatement($previous_assessment_sql, [$pid]);

if ($previous_row = sqlFetchArray($previous_result)) {

$saved_data = ['assessment' => $previous_row['assessment']];

    }

}

Thanks for that, it looks like a good starting point.

Do you only have your field called “assessment” pull previous data? I’m hoping to have this iterate over multiple fields in the form and it’d be rather cumbersome to write a separate snippet for each one.

Also, where in the code for your form did you put that else statement?

The form is about 3,500 lines long. I am pulling out assessments, previous diagnoses, and previous medications. It might be a lot of work but you only have to do it once.