I don't know what I am doing wrong here. I have tried a combination of things (see below) but I cannot get this to work. I want the OBSPREV to populate if it is less than 1 day old. We have an intake process that pulls this data in from a tablet. The below has been also been tried in a form with just these values and no other code as well.
the below code seems to work however the last value (BP DIASTOLIC) appears no matter what. So I tried removing the code to the BP DIASTOLIC and then the next last value populated instead (BP SYSTOLIC) and so on and so forth
{
if OBSPREV("WEIGHT") <> "" AND OBSNOW("WEIGHT") == "" AND (DURATIONDAYS(LASTOBSDATE("WEIGHT"),STR(._TODAYSDATE))<2)
then OBSNOW("WEIGHT",OBSPREV("WEIGHT"))
ELSE ""
ENDIF
}
{
if OBSPREV("HEIGHT") <> "" AND OBSNOW("HEIGHT") == "" AND (DURATIONDAYS(LASTOBSDATE("HEIGHT"),STR(._TODAYSDATE))<2)
then OBSNOW("HEIGHT",OBSPREV("HEIGHT"))
ELSE ""
ENDIF
}
{
if OBSPREV("BP SYSTOLIC") <> "" AND OBSNOW("BP SYSTOLIC") == "" AND (DURATIONDAYS(LASTOBSDATE("BP SYSTOLIC"),STR(._TODAYSDATE))<2)
then OBSNOW("BP SYSTOLIC",OBSPREV("BP SYSTOLIC"))
ELSE ""
ENDIF
}
{
if OBSPREV("BP DIASTOLIC") <> "" AND OBSNOW("BP DIASTOLIC") == "" AND (DURATIONDAYS(LASTOBSDATE("BP SYSTOLIC"),STR(._TODAYSDATE))<2)
then OBSNOW("BP DIASTOLIC",OBSPREV("BP DIASTOLIC"))
ELSE ""
ENDIF
}
I tried the below code and had the same result (only pasted the last one for reading sake)
{
if (DURATIONDAYS(LASTOBSDATE("BP DIASTOLIC"),STR(._TODAYSDATE))>2) or OBSNOW("BP DIASTOLIC")<>""
then ""
ELSE OBSNOW("BP DIASTOLIC",OBSPREV("BP DIASTOLIC"))
ENDIF
}
I then tried the below code and instead of the last obs value populating, the first one did!
{
if OBSPREV("WEIGHT") <> "" AND OBSNOW("WEIGHT") == "" AND (DURATIONDAYS(LASTOBSDATE("WEIGHT"),STR(._TODAYSDATE))<2)
then OBSNOW("WEIGHT",OBSPREV("WEIGHT"))
and if OBSPREV("HEIGHT") <> "" AND OBSNOW("HEIGHT") == "" AND (DURATIONDAYS(LASTOBSDATE("HEIGHT"),STR(._TODAYSDATE))<2)
then OBSNOW("HEIGHT",OBSPREV("HEIGHT"))
and if OBSPREV("BP SYSTOLIC") <> "" AND OBSNOW("BP SYSTOLIC") == "" AND (DURATIONDAYS(LASTOBSDATE("BP SYSTOLIC"),STR(._TODAYSDATE))<2) then OBSNOW("BP SYSTOLIC",OBSPREV("BP SYSTOLIC")) and if (DURATIONDAYS(LASTOBSDATE("BP DIASTOLIC"),STR(._TODAYSDATE))>2) or OBSNOW("BP DIASTOLIC")<>""
then ""
ELSE OBSNOW("BP DIASTOLIC",OBSPREV("BP DIASTOLIC"))
ENDIF ENDIF ENDIF ENDIF
}
I'm at a loss...
Have the obs terms been signed?
not in the requested time frame. It actually works fine but either the first or the last obsterm is always populated depending on which way way I go with the programming.
How are you displaying this, or are you running this in the background to save data to OBS terms without displaying anything?
Do you want to be looking at the LASTOBSDATE of (SYSTOLIC) in the DIASTOLIC if statement? I don't know why that would affect the previous if statement if you were to remove it, but it may be causing other unforeseen problems.
Also, have you tried breaking each if statement into its independent parts and making sure each comparison runs alone? Make sure they each work, then put them together and test piece by piece.
Sorry if that sounds obvious. I find pretty often that I get so focused on solving complex, multi step processes that I forget to look at the simple parts first to make sure they work on their own.
I am running these on the right side of the VFE form. I have run them independently, if I run just one by itself it will appear. If I run two by themselves, only the second one appears. If I run three by themselves, only the third one appears, and so on and so fourth.
no, i do not want the systolic and diastolic mixing, nor do they.
if OBSPREV("BP DIASTOLIC") "" AND OBSNOW("BP DIASTOLIC") == "" AND (DURATIONDAYS(LASTOBSDATE("BP SYSTOLIC"),STR(._TODAYSDATE))<2)
I just noticed that and wondered if that was part of the problem. I don't think that should affect the others, but it might affect this one.
When you say you want the OBSPREV to populate if it's less than a day old, where is it populating? In a data display, an edit field, the value itself?
oh gotcha, either way... it doesn't explain my problem. I had the issue with or without that in it.
Scott,
What exactly are you looking for here? Can you also clarify what is meant by 'less than 1 day old'? Is a day 24 hours or physical date? If the latter, then can you detail when the value has been signed - before or after the current update has been initiated? With additional detail, I might be able to help.
24hr period. The value could have been signed in 2014, it still shows up. I'm not sure how else I can put this.
I have 4 fields that I want to populate if their values have been entered within the last 24hrs, A B C & D.
if OBSPREV("A") "" AND OBSNOW("A") == "" AND (DURATIONDAYS(LASTOBSDATE("A"),STR(._TODAYSDATE))<2)
then OBSNOW("A",OBSPREV("A"))
If I enter them, independent of one another, in on the right side of the VFE form, not quite sure if it has a name, the last one's value will show up no matter how long ago it was entered or signed.
{A}
{B}
{C}
{D}
now if I put them all together the fist value shows up no matter how long ago it was entered or signed.
{A and B and C and D}
does that make sense?
You might want to use a function to do this. You could get creative and rewrite the function to loop though a list of obsterms to reduce the MEL footprint. The code below is the basic framework.
Function call examples:
{fnDispLast24Hr("BP SYSTOLIC")}
{fnDispLast24Hr("BP DIASTOLIC")}
The function:
{! fn fnDispLast24Hr(strObs)
{
local retStr = ""
if last_signed_obs_value(strObs) <> "" and obsnow(strObs) == "" then
if DURATIONDAYS(last_signed_obs_date(strObs),STR(._TODAYSDATE)) <= 2 then
obsnow(strObs,last_signed_obs_value(strObs))
else ""
endif
else ""
endif
return ""
}
}
Let me know if this isn't what you are looking for. 🙂
I couldn't get that function to work. I tried a few versions of it, I believe it has something to do with (strObs), if I remove local retStr="" and return "" and change StrObs to the actual obs it seems to work. thoughts?
As far as I can tell, it works. I don't think we need the local variable or the return statement, but here's what I have that works:
This was in a button, which I used to fire the function:
<code>{
dispLast24Hr("REFCM")
}</code>
<code>{
!fn dispLast24Hr(strObs) {
local retStr = ""
if last_signed_obs_value(strObs) <> "" and obsnow(strObs) == "" then
if DURATIONDAYS(last_signed_obs_date(strObs),STR(._TODAYSDATE)) <= 2 then
obsnow(strObs,last_signed_obs_value(strObs))
userok("Yes!")
else
OBSNOW(strObs, "Test No Option")
userok("No...")
endif
else
""
endif
}
}
</code>
I put the useroks in there to make sure it was working, to track where in the code we were, and to see what the outcomes were. I also put the OBSNOW with a value assignment in the "else" statement so in case nothing showed up, I could check the Clinical List Changes and see if the value of that OBS actually changed.
Does this help?