Here is my code:
######################################################################
# Name: tps_sqlite_update
#
# Purpose:
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “time”)
# MSGID message handle
#
# Returns: tps disposition list:
#
#
proc tps_sqlite_update { args } {
keylget args MODE mode ;# Fetch mode
global HciConnName
set procName “tps_sqlite_update”
set dispList {} ;# 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 {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
set msgtext [msgget $mh]
set fieldsep [crange $msgtext 3 3]
set subfieldsep [crange $msgtext 4 4]
set segments [split $msgtext “r”]
set date_time [clock format [clock scan now] -format %Y%m%d%H%M%S]
echo date_time: $date_time
foreach seg $segments {
if {[cequal [crange $seg 0 2] “MSH”]} {
# this segment (seg) is MSH
# get the field data
set data [split $seg $fieldsep]
set field [lindex $data 8]
set data [split $field $subfieldsep]
set triggerType [lindex $data 0]
set triggerEvent [lindex $data 1]
echo triggerType: $triggerType
echo triggerEvent: $triggerEvent
} elseif {[cequal [crange $seg 0 2] “PID”]} {
# this segment (seg) is PID
set data [split $seg $fieldsep]
set mrn [lindex $data 3]
echo mrn : $mrn
set patientAccount [lindex $data 18]
echo patientAccount: $patientAccount
set patientLName [lindex [split [lindex $data 5] $subfieldsep] 0]
echo patientLName: $patientLName
set patientFName [lindex [split [lindex $data 5] $subfieldsep] 1]
echo patientFName: $patientFName
set patientMName [lindex [split [lindex $data 5] $subfieldsep] 2]
echo patientMName: $patientMName
set dob [lindex $data 7]
echo dob : $dob
set gender [lindex $data 8]
echo gender : $gender
set ssn [lindex $data 19]
echo ssn : $ssn
} elseif {[cequal [crange $seg 0 2] “PV1″]} {
# this segment (seg) is PV1
set data [split $seg $fieldsep]
set patientType [lindex $data 2]
echo patientType: $patientType
set patientAdmitDate [lindex $data 44]
echo patientAdmitDate: $patientAdmitDate
set patientDischargeDate [lindex $data 45]
echo patientDischargeDate: $patientDischargeDate
}
}
#############################################################################################################
#
# The below starts the database stuff
#
#############################################################################################################
set db /home/hci/sql_test.db
[code]######################################################################
# Name: tps_sqlite_update
#
# Purpose:
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “time”)
# MSGID message handle
#
# Returns: tps disposition list:
#
#
proc tps_sqlite_update { args } {
keylget args MODE mode ;# Fetch mode
global HciConnName
set procName “tps_sqlite_update”
set dispList {} ;# 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 {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
set msgtext [msgget $mh]
set fieldsep [crange $msgtext 3 3]
set subfieldsep [crange $msgtext 4 4]
set segments [split $msgtext “r”]
set date_time [clock format [clock scan now] -format %Y%m%d%H%M%S]
echo date_time: $date_time
foreach seg $segments {
if {[cequal [crange $seg 0 2] “MSH”]} {
# this segment (seg) is MSH
# get the field data
set data [split $seg $fieldsep]
set field [lindex $data 8]
set data [split $field $subfieldsep]
set triggerType [lindex $data 0]
set triggerEvent [lindex $data 1]
echo triggerType: $triggerType
echo triggerEvent: $triggerEvent
} elseif {[cequal [crange $seg 0 2] “PID”]} {
# this segment (seg) is PID
set data [split $seg $fieldsep]
set mrn [lindex $data 3]
echo mrn : $mrn
set patientAccount [lindex $data 18]
echo patientAccount: $patientAccount
set patientLName [lindex [split [lindex $data 5] $subfieldsep] 0]
echo patientLName: $patientLName
set patientFName [lindex [split [lindex $data 5] $subfieldsep] 1]
echo patientFName: $patientFName
set patientMName [lindex [split [lindex $data 5] $subfieldsep] 2]
echo patientMName: $patientMName
set dob [lindex $data 7]
echo dob : $dob
set gender [lindex $data 8]
echo gender : $gender
set ssn [lindex $data 19]
echo ssn : $ssn
} elseif {[cequal [crange $seg 0 2] “PV1″]} {
# this segment (seg) is PV1
set data [split $seg $fieldsep]
set patientType [lindex $data 2]
echo patientType: $patientType
set patientAdmitDate [lindex $data 44]
echo patientAdmitDate: $patientAdmitDate
set patientDischargeDate [lindex $data 45]
echo patientDischargeDate: $patientDischargeDate
}
}
#############################################################################################################
#
# The below starts the database stuff
#
#############################################################################################################
set db /home/hci/sql_test.db