I am trying to create a form that tracks how much time a patient is with a doctor.
Please see attached form. I cannot get the total time calculation button to work.
1) Set some document variable equal to the current time when you open the page.
(You must do this carefully, because the time will get reset if your providers put visits on hold and come back to them. My code below will make sure the time only gets placed into the doc variable if it did not already contain a value.)
{!if(DOCUMENT.TIMESTAMP<>"")then
DOCUMENT.TIME = TIMESTAMP()
endif}
2) Calculate the duration between now and the time the form was opened.
You will just need to convert a time from HH:MM:SS to a number of seconds for both NOW and THEN. Subtract this number of seconds and divide by 60 a few times to figure out how many hours, minutes, and seconds have gone by.
local time_now = TIMESTAMP()
//convert the timestamp to a large integer by
//multiplying hours times 60*60
//minutes times 60
//minutes times 1
//add them all together
//subtract duration = time_now - time_then
//convert duration to hours,mins,secs
//return the result
I am not looking for the time to be automatically populated based off when it was open. I am looking for button's to place the time when clicked within the form itself. The form may be opened multiple times before the patient is seen.
Creating a Runprocess button with
DOCUMENT.whatever=TIMESTAMP()
will do that.... Or for an obs you could do OBSNOW("obs",TIMESTAMP())
Also, I have a function to calculate the duration between two times. It takes two times in the form of HH:MM AM/PM and returns the number of hours,minutes between the two times. I can share it if thats what you need.
Ex:
duration("1:30 PM","2:45 PM") returns "1 hour,15 minutes"
jrea said:
Also, I have a function to calculate the duration between two times. It takes two times in the form of HH:MM AM/PM and returns the number of hours,minutes between the two times. I can share it if thats what you need.
Ex:
duration("1:30 PM","2:45 PM") returns "1 hour,15 minutes"
I
I would be very interested in this function if your willing to share 🙂
Christal Lash
I would be interested in this calculation if you would be willing to share. Thank you.
I would like this as well if you are willing to share.
This takes two timestamps made in a 24 hour period and calculates the time between. It returns it as minutes. DLG attached: Time Duration
drobinson,
That form is great but when I hit the button then put the document on hold the data disappears 🙁 any fixes for that?
So if you hit start at 12:30 PM and then stop at 1:24 PM it gives you a negative time. ????
Sorry uploaded wrong form. Let me take a look at the original. The other form uploaded was a non finished form that is being tweaked to be used as a stop watch down to the millisecond. Still a few bugs to work out on that one.
Try ver 2 now which you can find in the above post again. There was a minor bug in the code specific to the hour of 12 PM. PM was starting the seconds at 43200 and would take into count hours then minutes. When the hour happened to be 12 PM however it was basically saying 43200 + 43200 + M which equals more seconds than there is in a day which brought the number into neg value. Fixed it by checking to make sure the hour was not 12 PM before setting the seconds based on AM or PM. Also the original issue clearing should be taken care of as well. The original form was clearing the values set by the button pushes and fixed that by just not setting them to ="" on load.