Convert multiple messages into one

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Convert multiple messages into one

  • Creator
    Topic
  • #55046
    Robin Starkes
    Participant

      The sending systems are sending multiple message with one FT1 segment per patient.

      The receiving system wants one message per patient with multiple FT1 segments.

      The sending systems can not change how that send DFT messages.

      I have know idea where to begin to accomplish this, any and all assistance is appreciated.

      Example:

      MSH|^~&|TEST|TEST2|||20160323100000||DFT^P03|1342186|P|2.3.1

      EVN|P03|20160323100000

      PID|||99-99-99||testTest^Bob||19340101|M|||2657 Somewhere rd^^Sometown^PA^88888||5553331111|||||999999999|123456789

      PV1|||^^^TEST2^^11||||ABCDEFG^Doctor^Test

      FT1||||20160323000000|20160323000000|CG|29580|||1.0||||||||||ABCDEFG^Doctor^Test|||||29580

      MSH|^~&|TEST|TEST2|||20160323100000||DFT^P03|1342187|P|2.3.1

      EVN|P03|20160323100000

      PID|||99-99-99||testTest^Bob||19340101|M|||2657 Somewhere rd^^Sometown^PA^88888||5553331111|||||999999999|123456789

      PV1|||^^^TEST2^^11||||ABCDEFG^Doctor^Test

      FT1||||20160323000000|20160323000000|CG|97597|||1.0||||||||||ABCDEFG^Doctor^Test|||||97597

      MSH|^~&|TEST|TEST2|||20160323100000||DFT^P03|1342188|P|2.3.1

      EVN|P03|20160323100000

      PID|||99-99-99||testTest^Bob||19340101|M|||2657 Somewhere rd^^Sometown^PA^88888||5553331111|||||999999999|123456789

      PV1|||^^^TEST2^^11||||ABCDEFG^Doctor^Test

      FT1||||20160323000000|20160323000000|CG|17250|||1.0||||||||||ABCDEFG^Doctor^Test|||||17250

      Would like to have:

      MSH|^~&|TEST|TEST2|||20160323100000||DFT^P03|1342188|P|2.3.1

      EVN|P03|20160323100000

      PID|||99-99-99||testTest^Bob||19340101|M|||2657 Somewhere rd^^Sometown^PA^88888||5553331111|||||999999999|123456789

      PV1|||^^^TEST2^^11||||ABCDEFG^Doctor^Test

      FT1||||20160323000000|20160323000000|CG|29580|||1.0||||||||||ABCDEFG^Doctor^Test|||||29580

      FT1||||20160323000000|20160323000000|CG|97597|||1.0||||||||||ABCDEFG^Doctor^Test|||||97597

      FT1||||20160323000000|20160323000000|CG|17250|||1.0||||||||||ABCDEFG^Doctor^Test|||||17250

    Viewing 6 reply threads
    • Author
      Replies
      • #83900
        Russ Ross
        Participant

          Are the charges coming in a daily batch file or a continuous real-time feed?

          Russ Ross
          RussRoss318@gmail.com

        • #83901
          Robin Starkes
          Participant

            They are coming in a daily batch file.

          • #83902
            Tony Benitz
            Participant

              Given that you get a daily batch file that contains multiple records for multiple individuals, you are going to have to read through the file and do a patient sort first.

              So.. First step is to read the and break it out by patient

              I would create a FILE for each patient, if it is new, add the header info

              Issue here is the visit information (Patient Account).. so you might want to use the actual billing information to create the file of charges.

              Then you have several files, one for each account, that has all the billing information (FT1 segments) there were encountered in the batch file.

              Then take this collection of files through your process for final delivery to the target system..

              Kind of klugie but you only have the tools that are provided and you need to parse the first file and pull the matches to build the final file and cloverleaf has issues with look ahead.. single message at a time, thus the pre-parse and build a collection of files.

              Good luck, sounds like a fun one.

            • #83903
              David Barr
              Participant

                You shouldn’t have to create temporary files for this. Write a TPS proc that takes the file in as one message, and do a msgcopy/msgset of the original file for each account replacing the original message with a message that contains only a single patient.

                The first step would probably be to msgget the data out of the original message, then msgset the contents of that message to an empty string (to lower the overhead of msgcopy). The next step would probably be to split the big message into individual messages and store them in a TCL list. Then you can iterate through the list, figure out the account number for that message, and use an array that is indexed by the account number to store the output message for that account. Check the array before you store the message. If there’s already a message there for that account, just append the FT1 segment to it and update the array. If there’s no message in the array then create a new one that’s a copy of the item in the list that you’re iterating over. After you’re done with this step, you loop through all the keys in the array, look up the message by each key, do a msgcopy of the original message and a msgset with the message for each account.

                You need to include the original message and all your copies in the disposition list. The original should have a KILL disposition and the copies should have a CONTINUE disposition.

              • #83904
                David Barr
                Participant

                  You can try this and see if it works. If you use this then you’ll need the HL7 library.

                  Code:

                         run {
                             # ‘run’ mode always has a MSGID; fetch and process it
                             keylget args MSGID mh
                             package require hl7
                             set segs [split [msgget $mh] r]
                             msgset $mh “”
                             set prev -1
                             foreach loc “[lsearch -all -regexp $segs {^MSH}] end” {
                                 if { $prev >= 0 } {
                                     set msg2 [join [lrange $segs $prev $loc-1] r]r
                                     set hl7 [hl7::parse_msg $msg2]
                                     set acct [hl7::get_field hl7 PID.18]
                                     if { [info exists out($acct)] } {
                                         set out($acct) “$out($acct)[hl7::get_field hl7 FT1]r”
                                     } else {
                                         set out($acct) $msg2
                                     }
                                 }
                                 set prev $loc
                             }
                             foreach key [array names out] {
                                 set mh2 [msgcopy $mh]
                                 msgset $mh2 $out($key)
                                 lappend dispList “CONTINUE $mh2”
                             }
                             lappend dispList “KILL $mh”
                         }

                • #83905
                  Charlie Bursell
                  Participant

                    Can we assume all messages are separated by a new line and all segments are separated by a carriage return?    If not, how?

                  • #83906
                    Charlie Bursell
                    Participant

                      If my assumptions are correct here is a quick and dirty I came up with.

                      BTW I am not a big fan of HL7 library since it parses the message over and over.   Just my opinion but whatever works for you.

                             run {

                                 # Message handle

                                 keylget args MSGID mh

                                 # Assume we are passed the entire file

                                 set data [msgget $mh]

                                 # First thing is to get a list of all MRNs (PID.3)

                                 # Note the full match is in full and just ID is in ID

                                 # Also just get one iteration of each MRN

                                 set MRNList “”

                                 foreach {full ID} [regexp -all -inline — {PID|||(.*?)|} $data] {

                                     if {[lsearch -exact $MRNList $ID] < 0} {lappend MRNList $ID}

                                 }

                                 # Now go get the group of all messages with same MRN and make it one

                                 # First define the regular expression to use

                                 set exp {^MSH.*?$MRN.*$}

                                 # Get each group and store in array

                                 set num 1

                                 foreach MRN $MRNList {

                                     set lst [regexp -all -inline -line [subst $exp] $data]

                                     set msgArray($num) $lst

                                     incr num

                                 }

                                 # since we will copy this message handle a lot and the file

                                 # could be large get rid of the data so we don’t copy each time

                                 msgset $mh “”

                                 # Always KILL orginal

                                 lappend dispList “KILL $mh”

                                 # Now process each message group in turn

                                 foreach num [lsort -integer [array names msgArray]] {

                                     set msgList $msgArray($num)

                                     # use first message as base

                                     set base [string trim [lvarpop msgList] r]

                                     # make sure base ends with CR

                                     append base r

                                     # now append each remaining FT1

                                     # Split into segments

                                     set segs [split $msgList r]

                                     foreach ft1 [lsearch -all -inline -regexp $segs {^FT1}] {

                                         append base $ft1r

                                     }

                                     echo nn$base

                                     # do message copy and set message

                                     set nmh [msgcopy $mh]

                                     msgset $nmh $base

                                     lappend dispList “CONTINUE $nmh”

                                 }

                                 return $dispList

                             }

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