Creating OBX Segments from Text

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Creating OBX Segments from Text

  • Creator
    Topic
  • #53604
    Jon Melin
    Participant

      Hello,

      I am having trouble building some iterating OBX segments from a single OBX segment. I have a large clump of data for a report coming in on a single OBX5 and I need to take every break (coming in as  .br ) and move that to it’s own iteration of OBX5.

      Now I am decent with manipulating the iterations but I cannot find a way to look for the next .br since they will vary in length. How can I search for a a specific combination and grab what’s between the current one and the next one and create and OBX, and repeat.

      Here is a small sample of what’s coming inbound:

      1(0).1(0).1(0).OBX(0).#5(0).[0]  :>Service Location: Hospital Medicine.brDATE OF ADMISSION:  04/05/2013.  .br\.brDATE OF DISCHARGE:  04/09/2013..br\.brADMISSION DIAGNOSIS:.br1.  Intrauterine pregnancy, postdates..br\.brDISCHARGE DIAGNOSES:.br

      I need it to look like:

      2(0).OBX(0).#1(0).[0]  :  >1< 2(0).OBX(0).#2(0).[0]  :  >TX< 2(0).OBX(0).#5(0).[0]  :  >DATE OF ADMISSION:  04/05/2013.  < 2(0).OBX(0).#11(0).[0]  :  >P< 2(0).OBX(1).#1(0).[0]  :  >2< 2(0).OBX(1).#2(0).[0]  :  >TX< 2(0).OBX(1).#11(0).[0]  :  >P< 2(0).OBX(2).#1(0).[0]  :  >3< 2(0).OBX(2).#2(0).[0]  :  >TX< 2(0).OBX(2).#5(0).[0]  :  >DATE OF DISCHARGE:  04/09/2013.< 2(0).OBX(2).#11(0).[0]  :  >P< 2(0).OBX(3).#1(0).[0]  :  >4< 2(0).OBX(3).#2(0).[0]  :  >TX< 2(0).OBX(3).#11(0).[0]  :  >P< 2(0).OBX(4).#1(0).[0]  :  >5< 2(0).OBX(4).#2(0).[0]  :  >TX< 2(0).OBX(4).#5(0).[0]  :  >ADMISSION DIAGNOSIS:< 2(0).OBX(4).#11(0).[0]  :  >P< 2(0).OBX(5).#1(0).[0]  :  >6< 2(0).OBX(5).#2(0).[0]  :  >TX< 2(0).OBX(5).#5(0).[0]  :  >1.  Intrauterine pregnancy, postdates.< 2(0).OBX(5).#11(0).[0]  :  >P< 2(0).OBX(6).#1(0).[0]  :  >7< 2(0).OBX(6).#2(0).[0]  :  >TX< Thank you in advance, Jon

    Viewing 3 reply threads
    • Author
      Replies
      • #78262
        Jim Kosloskey
        Participant

          John,

          You will need some Tcl to do this. As far as I know there is nothing intrinsic in Xlate which will accomplish this.

          The way we do this is with a couple of procs.

          The first proc breaks text into a list by a delimiter (like you have).

          The second proc pops one element at a time off of the list an puts the element into a temp variable and the remainder of the list into another temp variable.

          The second proc is used inside a list ITERATE which uses a technique to control the number of loops.

          Then the List ITERATE counter is used in the outbound OBX pathing to point to the wanted OBX group repetition.

          Sounds more complicated than it is.

          email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

        • #78263
          Levy Lazarre
          Participant

            Hello, Jon

            There are three different ways this problem can be approached:

            1. Do all the work in the Xlate (the most complicated solution).

            2. Use a small pre-Xlate tps to replace all .br in the message with the repetition character “~”. This allows to do field iteration on OBX.5 in the Xlate and place each token in their own new OBX segment (medium complexity).

            3. I found that the simplest solution is to use a pre-Xlate tps to do all the work (creating the new OBX segments and properly maintaining the sequence number). Nothing needs to be done in the Xlate.

            The following script, pre-Xlate, should do what you are trying to accomplish:

            tpsSplitOBX_br.tcl

            Code:



            ######################################################################
            # Name: tpsSplitOBX_br
            #
            # Purpose: Split an OBX segment into multiple OBX, based on the presence of
            #         line breaks (.br) in the OBX segment. Each line will be placed in
            #         its own new OBX segment and the sequence of OBX segments will be maintained.
            #
            #         Other OBX segments with no embedded .br may come before and after the affected
            #         OBX segment, so the OBX sequence must be readjusted accordingly.
            #
            # UPoC type: tps
            #
            # Use:              Pre-Xlate
            # Args: tps keyedlist containing the following keys:
            #       MODE    run mode (”start”, “run” or “time”)
            #       MSGID   message handle
            #       ARGS    user-supplied arguments:
            #               None
            #
            # Returns: tps disposition list:
            #          CONTINUE
            #
            proc tpsSplitOBX_br { args } {
               keylget args MODE mode               ;# Fetch mode
               
               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 msg [msgget $mh]
                       set segmentList [split $msg r]
                       
                       # Get the field separator
                       set fldSep [string index $msg 3]
                       
                       set newmsg {}       ;# Buffer to contain the modified messsage
                       set obxCount 0      ;# To keep track of the OBX segments
                       set tokensList {}   ;# To keep track of the OBX pieces
                       
                       foreach segment $segmentList {
                           set segmentType [string range $segment 0 2]
                           
                           switch -exact — $segmentType {
                               “OBX” {
                                   # The only segment to do manipulations on
                                   # Break the segment in a list of fields
                                   set OBXflds [split $segment $fldSep]
                                   
                                   # To avoid lreplace errors, make sure the list has
                                   # at least 5 elements by appending empty elements until
                                   # it does.
                                   
                                   while {[llength $OBXflds] >>OBX.5: $OBX5 <<>>new OBX.5: $newOBX5 <<>> $tokensList <<<
                                   # Iterate over the list and place each token in its own OBX segment,
                                   # while maintaining the proper sequencing
                                   
                                   foreach token $tokensList {
                                       incr obxCount
                                       # Place the count in OBX.1 and the token in OBX.5
                                       set OBXflds [lreplace $OBXflds 1 1 $obxCount]
                                       set OBXflds [lreplace $OBXflds 5 5 $token]
                                       
                                       # Put the OBX segment back together
                                       set segment [join $OBXflds $fldSep]
                                       # echo "Modified OBX segment: $segment"
                                       # Add the segment to the new message
                                       lappend newmsg $segment
                                   }
                                   
                               }
                               
                               default {
                                   # Any other segment we just pass as is,
                                   # skipping empty segments
                                   
                                   if {![string equal $segmentType ""]} {
                                       lappend newmsg $segment
                                   }
                               }
                           }
                       }
                       
                       set newmsg [join $newmsg "r"]
                       
                       # Put modified message in message handle
                       
                       msgset $mh $newmsg
                       lappend dispList "CONTINUE $mh"
                   }
                   
                   time {
                       # Timer-based processing
                       # N.B.: there may or may not be a MSGID key in args
                   }
                   
                   shutdown {
                       # Doing some clean-up work
                   }
               }
               
               return $dispList
            }

            I hope this helps.

          • #78264
            Robert Milfajt
            Participant

              I did something similar where I had to take NTE’s following OBXs and add as discrete OBX for each .br within the NTE.  I was able to do it all within a Xlate with just a couple of TCL fragments.  Here is a screen shot of the Xlate, and then the code in the two copy statements.  The trick is to keep track of all your counters, and use the cool list iterate that I got from another post a while back.  Good luck…

              Code from first copy (before list Iterate)

              Code:

              set NTE3 [lindex $xlateInVals 0]
              set NTE3 [string map {\.br\ ~} $NTE3]
              set nte_list [split $NTE3 “~”]
              set num_vals [llength $nte_list]
              set xlateOutVals [list $nte_list $num_vals]

              Code from copy within list Iterate

              Code:

              set nte_list [lindex $xlateInVals 0]
              set s9 [lindex $xlateInVals 1]
              set obx5 [lindex $nte_list $s9]
              incr s9
              set xlateOutVals [list $obx5 $s9]

              Robert Milfajt
              Northwestern Medicine
              Chicago, IL

            • #78265
              Jon Melin
              Participant

                Thanks everyone for the help. I will let you know which solution I end up using. These are all great suggestions.

                I appreciate the help as always.

                Thank you,

                Jon

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