1 Reply Latest reply on Feb 8, 2015 9:03 AM by philmodjunk

    Creating a bunch of time records

    dsimonson

      Title

      Creating a bunch of time records

      Post

      In my anesthesia record solution, I need to create a bunch of time intervals based upon the initial anesthesia start time - both 15 minute and 5 minute intervals.  I use them to plot my data observations on the graphic record.

      For example, for the 15 minute intervals, if the anesthetist enters a start time of 10:00, I want to create a bunch of records (enough to cover a maximum of 10 hours, or 40) that have a field containing the start time incremented by 15 minutes.  These records also have a field showing the time block number (1 - 40).  

      I want these to update any time the user changes the start time, just in case they want to correct their original entry.  “I thought I started at 9:55, but then I realized it was 10:00”.  

      My first thought was to try to create 40 different fields, but I remembered Phil’s admonition about sequentially numbered fields.  So now I have a script that creates the 40 records (or, in the case of the 5-minute records, 120).  After the 40 records are created, the fields populated by the script are “surgery_case_time_15_minutes”, which is initially set to the nearest 15 minutes _prior_ to the start time, and then incremented by 900 seconds, and the “surgery_15_minute_period_#” which is just the record number.

       

                                                                                                                                                                                                                                                                                                                                                     
                     

      surgery_15_min_period_#

                     
                     

      surgery_case_time_15_minutes

                     
                     

      1

                     
                     

      10:00:00

                     
                     

      2

                     
                     

      10:15:00

                     
                     

      3

                     
                     

      10:30:00

                     
                     

      4

                     
                     

      10:45:00

                     
                     

      5

                     
                     

      11:00:00

                     

      Here is the script:

      Create Timed Records: Create 15 minute Time Records 

      #This creates the times across the top of the chart 

      Set Variable [ $AnesStartTime; Value:

      Case ( 

      Minute ( SURGERIES::time_anes_start ) <15; Hour ( SURGERIES::time_anes_start )&":00:00"; 

      Minute ( SURGERIES::time_anes_start ) >14 and Minute ( SURGERIES::time_anes_start ) <30; Hour ( SURGERIES:: 

      time_anes_start )&":15:00"; 

      Minute ( SURGERIES::time_anes_start ) >29 and Minute ( SURGERIES::time_anes_start ) <45; Hour ( SURGERIES:: 

      time_anes_start )&":30:00"; 

      Minute ( SURGERIES::time_anes_start ) >44 and Minute ( SURGERIES::time_anes_start )<60; Hour ( SURGERIES:: 

      time_anes_start )&":45:00"; 

      0) ] 

      Set Variable [ $Counter; Value:1 ]
      Set Variable [ $SurgeryId; Value:SURGERIES::_pk_surgery_id ]
      Go to Layout [ “surgeries_SURG_TIMES_15_MIN” (surgeries_SURG_TIMES_15_MIN) ] Loop 

      New Record/Request
       

      Set Field [ surgeries_SURG_TIMES_15_MIN::_fk_surgery_id; $SurgeryID ]

      Set Field [ surgeries_SURG_TIMES_15_MIN::surgery_15_min_period_#; $Counter ]
      Set Field [ surgeries_SURG_TIMES_15_MIN::surgery_case_time_15_minutes; $AnesStartTime ]
      Set Variable [ $AnesStartTime; Value:surgeries_SURG_TIMES_15_MIN::surgery_case_time_15_minutes +900 ]

      Set Variable [ $Counter; Value:$Counter+1 ]
      Exit Loop If [ $Counter = 40 ] 

      End Loop
      Go to Layout
      [ original layout ] 

      I have a similar script that updates these records should the user update the anesthesia time.  Is this the best way to do this?

      I am uploading a screenshot of my graphic record in Layout view.  Note the row at the top labeled "Time" followed by the corresponding fields.  

      Thanks for any help and advice.

      Dan

       

      Anesthesia_Record_3.jpg

        • 1. Re: Creating a bunch of time records
          philmodjunk

          Time and timestamp fields store their time or Date|Time values as an integer representing seconds, either the number of seconds since midnight or the number of seconds since Midnight on 12/31/0000..

          So a loop can create records with a specified time interval recorded in a field of type time or timestamp, by adding the desired time interval in seconds to the previous value. And if you record a start time in a parent record, the related records can compute a time or better, timestamp, from that start time using an unstored calculation field.

          The script for 15 minute intervals might look like this:

          #This script creates 5 related records with a 5 minute interval. Change the value in Exit Loop If to change the number of records created
          Set Variable [ $ParentID ; value: Parent::__pkParentID ]
          Loop
              Set Variable [$K ; value: $K + 1 ]
              Exit Loop If [ $K > 5 ]
              Set Variable [$Time ; value: $Time + 300 // 300 seconds = 5 minutes ]
              New Record/Request
              Set Field [Child::_fkParentID ; $ParentID ]
              Set Field [Child::Time ; $Time ]
          End Loop
          Go to Layout [original layout]

          A calculationField defined in Child with a TimeStamp result type referencing a TimeStamp field in Parent might look like this:

          Parent::StartTimeStamp + Time