Help, I need to get latest vitals and age to use them on a custom document template

Situation
I am doing a document template that is a custom report, it gets data from many LBF forms, some DEM and HIS fields as well.
But I don’t know how to get patient’s latest vital (weight and BMI).

Any advise? I believe I have to update download_template.php (/interface/patient_file/download_template.php), maybe add some additional substitutions on doSubs for example {PatientAge}{VIT:latestWeight} {VIT:BMI}.
I know PatientAge can be calculated based on todays date and DOB, maybe we can record patientAge in vitals, that way we can track vitals as a timeseries related to its patient.
There is another code that may help (here it is calculated patientAge) interface/forms/vitals/report.php this may help to solve this need, but I don’t know how to?

OpenEMR Version
I’m using OpenEMR version 7.0.1

Browser:
I’m using: Chrome

Operating System
I’m using: Ubuntu 22.04

Search
Did you search the forum for similar questions? Yes!

Logs
Did you check the logs?
Was there anything pertinent in them?
Please paste them here (surround with three backticks (```) for readability.
You can also turn on User Debugging under Administration->Globals->Logging User Debugging Options=>All

Any update on this? I have the same issues.

Hi @Gerry_Mike_Palisoc @Marco_Meza
As far as I know the only way to get the latest vitals for a patient is to query the OpenEMR database at the moment they’re needed, for the largest value in the datetime column for the VS you’re interested in.
So maybe you could do the query just before the form is created and stick the data in field(s) the template can read with its {tags}?
Good luck!

  • HT

I find a way to add fields to download_template.

For example, if you need patient age in reference to a specific encounter date, or patient weight, BMI, or providers full name, for a selected encounter, you can add this block to function doSubs($s)

elseif (keySearch($s, '{PatientAge}')) {
    // Calculate patient age as selected encounter date
    $dob = strtotime($ptrow['DOB']); // Convert date of birth to timestamp
    $dos = strtotime(substr($enrow['date'], 0, 10)); // Convert current visit date to timestamp
    
    if ($dob !== false && $dos !== false) {
        $age = date_diff(date_create('@' . $dob), date_create('@' . $dos))->y; // Calculate age
        $s = keyReplace($s, dataFixup($age, xl('Age')));
    }
} elseif (keySearch($s, '{PatientWeight}')) {
    if (isset($vitalsrow['weight'])) {
        $weight = intval($vitalsrow['weight']);
        $s = keyReplace($s, dataFixup($weight, xl('Weight')))
    }
} elseif (keySearch($s, '{PatientBMI}')) {
    if (isset($vitalsrow['BMI'])) {
        $bmi = $vitalsrow['BMI'];
        $s = keyReplace($s, dataFixup($bmi, xl('BMI')));
    }
} elseif (keySearch($s, '{EncounterProviderName}')) {
    if (isset($providerEncounterrow['fname'])) {
        $providerFullName = $providerEncounterrow['fname'] . ' ' . $providerEncounterrow['lname'];
        $s = keyReplace($s, dataFixup($providerFullName, xl('Provider Full Name')));
    }
}
1 Like

This would make for a great place where events can be used and a module can add in custom keys. Or a git pull request to contribute to the core codebase.

2 Likes

Also can use the portal templates where there are many more tags available and the may render themselves created from portal dashboard and access in Documents: