Help starting Tcl script to account for AIP seg not in every message

Clovertech Forums Cloverleaf Help starting Tcl script to account for AIP seg not in every message

  • Creator
    Topic
  • #119064
    William Kostok Jr
    Participant

      Still very new to Tcl, I’m tasked with adding to an existing script by moving an AIP.3.6 field to the AIP.3.7 field. I’ve noticed that not every message contains an AIP.3.6 field. So the script would only apply if the message has an AIP seg. And if that AIP.3.6 has a value before moving to AIP.3.7.

      I know an if/else statement is needed here. Just not quite sure how to implement that.

      Below is what I started on taking apart the message and replacing AIP.3.7 with the value in AIP.3.6.

      } elseif [cequal $stype AIP] {
      set aipflds [split $seg $fldsep]
      set aip_3 [lindex $aipflds 3]
      set aip_3flds [split $aip_3 $subfldsep]
      set aip_3_6 [lindex $aip_3flds 5]
      set aip_3_7 [lindex $aip_3flds 6]
      set aip_3_7fld [lreplace $aip_3_7 0 0 $aip_3_6]

      Any help would be appreciated.

      Thank you!

    Viewing 1 reply thread
    • Author
      Replies
      • #119065
        David Barr
        Participant

          Are you replacing all components in AIP-3.7 with the AIP-3.6 value or just the first component?

          • #119067
            William Kostok Jr
            Participant

              Yes. Whatever is in AIP.3.6 needs to go to AIP.3.7. If AIP.3.6 has a value in the field.

          • #119068
            David Barr
            Participant

              Something like this would probably work.

              } elseif { $stype eq “AIP” } {
              set aipflds [split $seg $fldsep]
              set aip_3 [lindex $aipflds 3]
              set aip_3flds [split $aip_3 $subfldsep]
              set aip_3_6 [lindex $aip_3flds 5]
              if { $aip_3_6 ne “” } {
              set aip_3flds [lreplace $aipflds 6 6 $aip_3_6]
              set aip_3 [join $aip_3flds $subfldsep]
              set aipflds [lreplace $aipflds 3 3 $aip_3]
              set seg [join $aipflds $fldsep]
              }

              We’ve got a library that we use for updating messages. If I were writing this code for our site, I would do something like this:

              set aip_3_6 [hl7::get_field hl7 AIP.3.6]
              if { $aip_3_6 ne “” } {
              hl7::set_field hl7 AIP.3.7 $api_3_6
              }

          Viewing 1 reply thread
          • You must be logged in to reply to this topic.