I have a form in VFE that I need to pull the values from the most recent encounter. Say a patient came in during November and was checked as having sleep apnea. Then that patient came in again during April and was not checked as having sleep apnea. As it stands right now, using LAST_SIGNED_OBS_VALUE will pull that the patient was checked with having sleep apnea in November. What I want is to have a Previous button that will look at the last encounter entered and pull ONLY the values that were checked or had a value in the edit box.
I have one mandatory field on the form, and I am using that observation's timestamp to tell what the latest encounter date is. I have a function that is supposed to be called when I click the Previous button that checks for the latest values. But for some reason the function is not being called, or I haven't written the code in the function properly.
Here is the function:
{fn GetPreviousValues(){
if (LAST_SIGNED_OBS_DATETIME("SLEEPAPNEA") == LAST_SIGNED_OBS_DATETIME("DATE15")) then
OBSNOW("SLEEPAPNEA") = "Sleep Apnea"
endif
}}
For the Previous button I have it set to RunProcess and then have the function call GetPreviousValues().
Any help will be much appreciated. Thanks!
You are setting the value to your obsterm incorrectly.
.
Assign value to obsterm like this:
OBSNOW(“SLEEPAPNEA”,“Sleep Apnea”)
You also might need to use this function: DURATIONDAYS(date1, date2)
.
Example code: I just updated this code after testing and fixing some issues. Sample form has a field for WEIGHT using this as my anchor obsterm that is updated every time, and six botox obsterms (for testing), and a button [Previous] with this function below. Works now.
To Test: Open an encounter for a previous date 03/09/2016. Update weight, and first two botox obs and sign. Then Open an encounter for a previous date 04/11/2016. Click [Previous], it pulls in the weight and first two botox obs. Now clear the first 2 botox obs and set values for the 3rd and 4th boxtox fields. Sign. Then Open an encounter for todays date, click the [Previous] button, will only pull in the weight and the 3rd and 4th Botox fields.
.
{fn fnDisplayPrevVisitUpdates() {
local Look4date1 = ""
local date2 = ""
local listFormObsNames = "#BOTOXUNIT13,#BOTOXUNIT14,#BOTOXUNIT15,#BOTOXUNIT16,#BOTOXUNIT17,#BOTOXUNIT18"
local thisObsName=""
local aryObs = getfield(listFormObsNames,",","")
local imax=size(aryObs)
local i=0
Look4date1 = LASTOBSDATE("WEIGHT")
//
for i=1, i<=imax, i=i+1 do
if LAST_SIGNED_OBS_VALUE(aryObs[i])<>"" then
date2 = LAST_SIGNED_OBS_DATE(aryObs[i])
//
//userok(date2 + " ?=" + Look4date1)
//
if DURATIONDAYS(Look4date1, date2) == 0 then
//You found an obsterm assigned on the SAME date as Look4date1
thisObsName = aryObs[i]
OBSNOW(thisObsName,OBSPREV(thisObsName))
//
//do whatever you need here with thisObsName
//[your code when you find an obsterm from the most recent visit]
else
// Skip, the obsterm was not assigned on the same date as your anchor obsterm
""
endif
//
OBSNOW("WEIGHT",OBSPREV("WEIGHT"))
//
else "" endif
endfor
}}
~ Beverly B
Thank you! This did the trick.
Updated the code in my answer after testing and fixing some issues. ~ Beverly B