Age at admission

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Age at admission

  • Creator
    Topic
  • #53140
    John Bass
    Participant

      I need to calculate the patient

    Viewing 3 reply threads
    • Author
      Replies
      • #76698
        Bob Schmid
        Participant

          OLDER code from sms tclproc outbound stack

          ….assumed you have retrieved the fields

          set DOB_trim [string range $DOB 0 7]

          set DOB_yy [string range $DOB_trim 0 3]

          set DOB_mm [string range $DOB_trim 4 5]

          set DOB_dd [string range $DOB_trim 6 7]

                if {$DOB > “”} {

                         set delim “^”

                         set birth_ccyy [string range $DOB 0 3]

                         set birth_mmdd [string range $DOB 4 7]

                         set current_date [fmtclock [getclock] %Y%m%d]  

                         set current_ccyy [string range $current_date 0 3]

                         set current_mmdd [string range $current_date 4 7]

                         set age [expr $current_ccyy – $birth_ccyy]

                         regsub {^0} $current_mmdd “” edit_current_mmdd

                         regsub {^0} $birth_mmdd “” edit_birth_mmdd

                         if  {“$edit_birth_mmdd” > “$edit_current_mmdd”} {

                             set age [expr $age – 1]

                         }

                         ###    # 2 year old  or greater

                         if {$age > “1”} {

                            set unit Y

                         } else {

                         ###  either 1 year or less

                                if {$age < "1"} {

                                   set age “patient age: < 1 yr."

                                   set unit “”

                                   set delim “”

                                } else {

                                       set age “1”

                                       set unit “Y”

                                       }

                                }

                         if {[cequal $unit “Y”]} {

                            set format_age “$age $unit”

                         } else {

                                set format_age $age

                                }

                      } else {

                             set format_age “”

                             }

        • #76699
          Robert Kersemakers
          Participant

            I have used a proc called ‘gc_calculateAge’ which was supplied with CL (could be from way back when with 3.7.1?). It’s in ‘gen_common_procs.tcl’.

            Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

          • #76700
            John Bass
            Participant

              Thanks for the sample code.  It got me pointed in the right direction.  As it turns out, all I need to do is calculate the patient’s age at admission in years.  Here’s the proc I came up with, I need to do some more testing but it seems to work correctly.  Thanks again!

              Code:


              ######################################################################
              # Name:         calc_age.tcl  
              # Purpose:      Calculate patient age at time of admission and
              #                  add OBX segment with calculated age in OBX-5
              #
              # Args:         tps keyedlist containing the following keys:
              #               MODE    run mode (”start”, “run” or “time”)
              #               MSGID   message handle
              #               ARGS    user-supplied arguments:
              #              
              #

              proc calc_age { args } {
                 global HciConnName

                 keylget args MODE mode        ;# Fetch mode argument
                 keylget args CONTEXT context  ;# Fetch context argument (where this proc is being called from)

                 set dispList {}               ;# default dispList to Nothing to return
                 
                 switch -exact — $mode {
                     start {
                         # Perform special init functions
                         # N.B.: there may or may not be a MSGID key in args
                     }
                     
                     run {
                         keylget args MSGID mh               ;# Fetch the MSGID
                         set msg [msgget $mh]                ;# Get the Message Handle

                         set outbuf {}
                         
                         # Now we need to determine our field and sub components
                         set field_sep [csubstr $msg 3 1]      ;# HL7 field separator
                         set sub_sep [csubstr $msg 4 1]        ;# HL7 subfield separator
                         set sub_sub_sep [csubstr $msg 7 1]    ;# HL7 sub-subfield separator
                         set rep_sep [csubstr $msg 5 1]
                         set outbuf {}
                         
                         set segmentList [split $msg r]
                         
                         # Get Date of Birth in PID-7
                         set pidLoc [lsearch -regexp $segmentList {^PID}]
                         if {$pidLoc == -1} {error “No PID segment!”}
                         set pidSeg [lindex $segmentList $pidLoc]
                         set pidFld [split $pidSeg $field_sep]
                         set pidFld_7 [lindex $pidFld 7]
                         if {$pidFld_7 > “”} {
                             set dob [string range $pidFld_7 0 7]
                             set dob_ccyy [string range $pidFld_7 0 3]
                             set dob_mmdd [string range $pidFld_7 4 7]
                         }
                         
                         # Get Admission Date in PV1-44
                         set pv1Loc [lsearch -regexp $segmentList {^PV1}]
                         if {$pv1Loc == -1} {error “No PV1 segment!”}
                         set pv1Seg [lindex $segmentList $pv1Loc]
                         set pv1Fld [split $pv1Seg $field_sep]
                         set pv1Fld_44 [lindex $pv1Fld 44]
                         if {$pv1Fld_44 > “”} {
                             set admit_date [string range $pv1Fld_44 0 7]
                             set admit_ccyy [string range $pv1Fld_44 0 3]
                             set admit_mmdd [string range $pv1Fld_44 4 7]
                             # Calculate age at admission in years
                             set age [expr $admit_ccyy – $dob_ccyy]
                             if {”$dob_mmdd” > “$admit_mmdd”} {
                               set age [expr $age – 1]
                             }
                             if {$age < "0"} {
                                 set age "0"
                             }

                      set unit "YEARS"

                         }
                         
                         foreach segment $segmentList {
                         if [cequal $segment ""] { continue }
                         append outbuf ${segment}r
                         set eventtype [csubstr $segment 0 3]
                         }
                         if {[cequal $eventtype "PV2"]} {
                         # Add OBX segment with age at admission
                         set addOBX "OBX|1|TX|||$age|$unit"
                         append outbuf ${addOBX}r
                         }

                         msgset $mh $outbuf
                         lappend dispList "CONTINUE $mh"
                         return $dispList
                         
                      }
                     
                     time {
                         # Timer-based processing
                         # N.B.: there may or may not be a MSGID key in args
                     }

                     shutdown {
                         # Doing some clean-up work
                     }

                     default {
                         error "Unknown mode '$mode' in calc_age.tcl"
                     }
                 }

              }

            • #76701
              David Speare
              Participant

                I am just using the below.  The output ends up being a decimal value, but I am just comparing the value to > or < 18.

                # The following function calculates the age in years

                proc Compute_Years {} {

                   upvar xlateId       xlateId

                 xlateInList   xlateInList

                 xlateInTypes  xlateInTypes

                 xlateInVals   xlateInVals

                 xlateOutList  xlateOutList

                 xlateOutTypes xlateOutTypes

                 xlateOutVals  xlateOutVals

                set inval [lindex $xlateInVals 0]

                set date1 [clock scan $inval]

                set date2 [clock seconds]

                set elapsedDays [expr {($date2 – $date1) / (60 * 60 * 24)}]

                set elapsedYears [expr {$elapsedDays / 365.25}]

                set xlateOutVals $elapsedYears

                }

            Viewing 3 reply threads
            • The forum ‘Cloverleaf’ is closed to new topics and replies.