› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › breaking up batch text file to individual messages proc
If there is one HL7 message per line, then you can use the file/fileset-local protocol to read in each line as a message.
-- Max Drown (Infor)
Hi Max. Thank you for your reply. I have a text file with a lot of messages. Each message has an MSH, PID, OBR, and OBX segments. The receiving system cannot accept one large message with multiple MSH segments, so I need to send it as individual hl7 messages. I attached a sample of what the file looks like. Is there something that can be hard coded in the txt file that Cloverleaf knows to separate each message?
This will depend on how each segment/line and each message is terminated in the file.
If the file follows the HL/7 standard with hex 0d ending each segment and 0d0a ending each message then the default settings on the fileset protocol should work.
So using somethiing like hcihd from the command line get a hex dump of the file and figure out what the terminating characters are.
If they are not as descriibed as above, let us know. In some cases Tcl may be required.
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
Here’s a script that will split your file into messages. Set your protocol to read in the entire file (EOF). Place the proc into Inbound TPS. Test it well.
proc tps_fileset_split_file { args } {
[code]proc tps_fileset_split_file { args } {
-- Max Drown (Infor)
Thanks guys. I will test the proc this afternoon.
regsub -all {rMSH|} $file “nMSH|” file
This should probably be
regsub -all {rMSH|} $file “rnMSH|” file
There’s supposed to be a CR at the end of the last segment.
Good catch. That change will preserve the trailing carriage return on the last segment.
-- Max Drown (Infor)
Someone replied with another fix, but then deleted it. But, they were correct.
msgset $mh $msg
-- Max Drown (Infor)
Results from my test (the forum software auto replaces the carriage returns):
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002357^^^&ABCD&^^&ABC&|||||||||||||||74002357
OBR|||||||20150329132543|||||||||
OBX|1|ST|BLDPRSYS^BLOOD PRESURE SYSTOLIC^ABC||124|||||||||20150330134311
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002357^^^&ABCD&^^&ABC&|||||||||||||||74002357
OBR|||||||20150329132543|||||||||
OBX|1|ST|HRTRATE^HEART RATE^ABC||80|||||||||20150330134307
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002357^^^&ABCD&^^&ABC&|||||||||||||||74002357
OBR|||||||20150329132543|||||||||
OBX|1|ST|RESPR^RESPIRATORY RATE^ABC||18|||||||||20150330134318
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002394^^^&ABCD&^^&ABC&|||||||||||||||74002394
OBR|||||||20150329132543|||||||||
OBX|1|ST|BLDPRSYS^BLOOD PRESURE SYSTOLIC^ABC||124|||||||||20150330122020
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002394^^^&ABCD&^^&ABC&|||||||||||||||74002394
OBR|||||||20150329132543|||||||||
OBX|1|ST|HRTRATE^HEART RATE^ABC||80|||||||||20150330122015
MSH|^~&|HNAM|ABC|VISICU||20150331132543||ORU^R01|20150331132543|D|2.2
PID|||74002394^^^&ABCD&^^&ABC&|||||||||||||||74002394
OBR|||||||20150329132543|||||||||
OBX|1|ST|RESPR^RESPIRATORY RATE^ABC||18|||||||||20150330122030
-- Max Drown (Infor)