I’m trying to extract some field values from a grm object that I’ve created from a message object. I am creating the message object using msgcreate and msgread to get the message from a file. The file is len10 encoded and is well-formed; that is when I open the file in the Cloverleaf IDE testing tool the message is parsed correctly and I can see the paths to each of the fields. If I do a msgget on the message that is created, I see all of the raw data, no suprises yet.
I then create a grm object from the message object using grmcreate with the proper arguments. The problem I am having is that everytime I try to access a field from the PID segment using grmfetch, an empty datum is returned. Accessing fields from the MSH segment works as expected.
Creating a new message with grmencode and then using msgget on the new message shows that the new message is not the same as the original message. The grmencoded message has the MSH, EVN and PV1 segments but the EVN and PV1 segments have been corrupted. The rest of the segments are gone. I confirmed my suspicion that the two messages are in fact different by using string length on the output of msgget and the difference is an order of magnitude.
Here is the output of my hcitcl session that illustrates the problems, I’ve
hcitcl>package require libInsCheck
1.0
hcitcl>::libInsCheck::createFromFile one_adt.len
message7 grm1
hcitcl>msgget message7
MSH|^~&|xxxx|xxxx|||200704011349||ADT^A04|856F5BB9-7895-4FA2-AC52-DA5E3BA5ED16|P|2.4||1
EVN|A04|200704011349||CI|xxxx_xxxx|200704011341|226
PID|1|
PV1|1|
GT1|1|
IN1|1|
hcitcl>grmencode grm1
message8
hcitcl>msgget message8
MSH|^~&|SOARF|BMH1|||200704011349||ADT^A04|856F5BB9-7895-4FA2-A|P|2.4||1
EVN|A0|20||CI|B0D0_CSOLLER1|200704011341|226
PV1|A04
hcitcl>
Here is the code from my package that creates the message and grm objects from a len10 encoded file.
# Create a message/grm pair from a len10 encoded file.
proc ::libInsCheck::createFromFile {filename} {
# read the file
set msg [msgcreate]
set file [open $filename r]
msgread len10 $msg $file
close $file
# get the version and type
set data [msgget $msg]
set delim [string index $data 3]
set fields [split $data $delim]
set ver [lindex $fields 11]
set type [lindex $fields 8]
regsub -all {W} $type {_} type
# create the grm
set grm [grmcreate -msg $msg hl7 $ver {} $type]
return
}
Do yo have any clues as to what’s going on?
Thanks for reading this lengthy post and thanks for your help.
–dennis