I am trying to calculate elapsed time for a phone note - A PCMH 2014 requirement. I have 2 obsterms each with a time based on a 24 hour clock ie hh:mm .
Does anyone have any ideas on how to get and elapsed time?
Thanks in advance
Could you describe your workflow currently for populating those obs terms? does the staff member enter the time manually as 12:55 and 13:25 for a start and end time? if that is the case, you can simply convert both times into minutes and subtract the later time from the previous. this will give you an elapsed time in minutes, which can also be converted back into a 24 hour format.
let me know if you need help with the coding, or if your workflow is different than I described.
Thank you,
Dan
So I used a function to convert time stamped data into 24 hour time.
The idea was to put elapsed time into another obsterm.
Here is what I tried:
{fn call_time_hrs()
{local time1,time2,h1,h2,m1,m2,t1,t2,eh,em,et,r
time1==str(OBSNOW("TM PHONE #5"))
time2==str(OBSNOW("TM Phone #6"))
h1 = sub(Time1,1,2)
m1 = sub(Time1,4,2)
h2 = sub(Time2,1,2)
m2 = sub(Time2,4,2)
t1 = (h1 + (m1 / 60))
t2 = (h2 + (m2 / 60))
et= t2-t1
eh = truncate(et,0)
em = round((et - eh) * 60,0)
r = str(eh) + " hr " + str(em) + " min"
obsnow("TM Phone #8", str(r))}
}
Appreciate your input.
Your function works great! the only problem is a few errors in the code. I fixed the errors and here is the working code:
{fn call_time_hrs(){
local time1,time2,h1,h2,m1,m2,t1,t2,eh,em,et,r
time1 = OBSNOW("TM PHONE #5")
time2 = OBSNOW("TM Phone #6")
h1 = sub(Time1,1,2)
m1 = sub(Time1,4,2)
h2 = sub(Time2,1,2)
m2 = sub(Time2,4,2)
t1 = (h1 + (m1 / 60))
t2 = (h2 + (m2 / 60))
et= t2-t1
eh = truncate(et,0)
em = round((et - eh) * 60,0)
r = str(eh) + " hr " + str(em) + " min"
obsnow("TM Phone #8",r)
}}
The main issue was in your original code, you wrote:
time1==str(OBSNOW("TM PHONE #5"))
time2==str(OBSNOW("TM Phone #6"))
The double equals sign means compare time1 and time2 to the obsterms, and return true or false for if they are equal. I changed it to
time1 = OBSNOW("TM PHONE #5")
time2 = OBSNOW("TM Phone #6")
and it works great!
please let me know if you have any trouble using the function. I built a quick form to test the code and I can send it to you if there are any issues with copy/pasting from here.
Thank you,
Daniel Carpenter
Dan,
That is awesome. Thanks so much for your help.
I'm trying to find an OBS Term to record birth time, and time of a blood draw. Then will calculate age in hours (for infant bilirubin testing purposes). Is there an OBS term or way to format the entry for time based on hh:mm to one individual obs term? Any suggestions on the term name to use?