Format Command in an xlate tcl fragment %-40s

Homepage Clovertech Forums Cloverleaf Format Command in an xlate tcl fragment %-40s

  • Creator
    Topic
  • #109405
    Lawrence Nelson
    Participant

    In an XLATE –

    I’m passing a variable that could be 2 to 35 characters long > outbound to OBX:3.0

    I need OBX:30.0 to be 40 characters long everytime regardless of the variable length

    In the xlate COPY action – I’m using this tcl frag which has no effect on the output.

    set xlateOutVals [format %-40s $xlateInVals ]

    Any thoughts on what I’m doing wrong or missing?

    • This topic was modified 5 years, 3 months ago by Rob Abbott.

    Lawrence Nelson
    System Architect - MaineHealth IT

Viewing 11 reply threads
  • Author
    Replies
    • #109410
      Rob Abbott
      Keymaster

      Moved this out of the archives to active forums.

      The leading or trailing spaces may be being truncated when the data is encoded to HL7. Try surrounding the format in double quotes:

      set xlateOutVals “[format %-40s $xlateInVals]”

      Rob Abbott
      Cloverleaf Emeritus

    • #109414
      Lawrence Nelson
      Participant

      I added this and found no change –

      set xlateOutVals “[format %-20s $xlateInVals %-40s ]”

      Lawrence Nelson
      System Architect - MaineHealth IT

    • #109415
      Lawrence Nelson
      Participant

      Sorry wrong example – should’ve been this

      set xlateOutVals “[format %-40s $xlateInVals]”

      Lawrence Nelson
      System Architect - MaineHealth IT

    • #109419
      Rob Abbott
      Keymaster

      the leading / trailing spaces are being truncated when the data is encoded to HL7. Please open a support case to investigate this further.

      Rob Abbott
      Cloverleaf Emeritus

    • #109420
      James Nelson
      Participant

      This works:
      set xlateOutVals

        ]]

        • This reply was modified 5 years, 3 months ago by James Nelson.
        • This reply was modified 5 years, 3 months ago by James Nelson.
        • This reply was modified 5 years, 3 months ago by James Nelson.
        • This reply was modified 5 years, 3 months ago by James Nelson.
        • This reply was modified 5 years, 3 months ago by James Nelson.
      1. #109426
        James Nelson
        Participant

        Forget it…

        • This reply was modified 5 years, 3 months ago by James Nelson. Reason: Forum software keeps mangling my code
      2. #109473
        Lawrence Nelson
        Participant

        This actually does work – but not the way I want

        set xlateOutVals [format “%040s” $xlateInVals ]

        Where in “%040s” the zero betweent the percent and the 4 pads out zeros’

        Which results in
        >||ST|0000000000000000000000000000Levofloxacin|2|

        So the current issue is that a space or the – character should do the same thing with spacing (so it would be right justified and that does not appear to be honored in the scheme of things.

        Lawrence Nelson
        System Architect - MaineHealth IT

      3. #109474
        James Nelson
        Participant

        Ok, trying again

        This code snippet works:
        [code]
        set xlateOutVals [list [format %-40s [lindex $xlateOutVals 0]]]
        [/code]

        You can validate it with this:
        [code]
        hcitcl>set xlateOutVals [list abcdefghijklmnopqrstuvwxyz]
        abcdefghijklmnopqrstuvwxyz
        hcitcl>set xlateOutVals [list [format %-40s [lindex $xlateOutVals 0]]]
        {abcdefghijklmnopqrstuvwxyz }
        hcitcl>string length [lindex $xlateOutVals 0]
        40
        hcitcl>
        [/code]

        If that still doesn’t work in your Xlate, make sure your variant allows for 40 characters in that field/component.

        • This reply was modified 5 years, 3 months ago by James Nelson.
        • This reply was modified 5 years, 3 months ago by James Nelson.
      4. #109475
        Lawrence Nelson
        Participant

        Ok – so in case anyone else looks at this –

        I did get this to work with an xltp instead

        *********************************************************************************************

        ######################################################################
        # Name: format_OBX3
        # Purpose: <description>
        # UPoC type: xltp
        ######################################################################

        proc format_OBX3 {} {
        upvar xlateId xlateId \
        xlateInList xlateInList \
        xlateInTypes xlateInTypes \
        xlateInVals xlateInVals \
        xlateOutList xlateOutList \
        xlateOutTypes xlateOutTypes \
        xlateOutVals xlateOutVals \
        xlateConstType xlateConstType \
        xlateConfigFileName xlateConfigFileName

        set inVal [lindex $xlateInVals 0]
        set outVal “”
        set outVal [ format %-40s $inVal ]

        set xlateOutVals

          Lawrence Nelson
          System Architect - MaineHealth IT

        1. #109479
          Lawrence Nelson
          Participant

          An also confirming Rob’s work – this works as well

          set xlateOutVals

            ]]

            1(0).1(2).3(0).OBX(0) : >||ST|Ampicillin |2|S|mcg/mL||0|||F||||C<
            1(0).1(2).3(0).OBX(1) : >||ST|Gentamicin |2|S|mcg/mL||0|||F||||C<
            1(0).1(2).3(0).OBX(2) : >||ST|Levofloxacin |2|S|mcg/mL||0|||F||||C<
            1(0).1(2).3(0).OBX(3) : >||ST|Moxifloxacin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(4) : >||ST|Nitrofurantoin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(5) : >||ST|Oxacillin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(6) : >||ST|Penicillin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(7) : >||ST|Quinupristin+Dalfopristin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(8) : >||ST|Rifampin |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(9) : >||ST|Tetracycline |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(10) : >||ST|Trimethoprim+Sulfamethoxazole |2|R|mcg/mL||2|||F||||C<
            1(0).1(2).3(0).OBX(11) : >||ST|Vancomycin

            Lawrence Nelson
            System Architect - MaineHealth IT

          1. #109485
            Jim Kosloskey
            Participant

            Just wondering if the STRING Action xlateStrPadLeft function would not work as well thus no Tcl coding needed?

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          2. #109493
            Rob Abbott
            Keymaster

            James – when you post code put it in angle bracket “code” tags, that should protect you from any BBCode formatting.

            Rob Abbott
            Cloverleaf Emeritus

            • #109517
              James Nelson
              Participant

              Thanks, Rob! I did finally figure that out. I was trying to use the CODE button on the Forum page to do that and obviously that didn’t work. 🙂

        Viewing 11 reply threads
        • You must be logged in to reply to this topic.

        Forum Statistics

        Registered Users
        5,117
        Forums
        28
        Topics
        9,292
        Replies
        34,432
        Topic Tags
        286
        Empty Topic Tags
        10