Question about keyed lists

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Question about keyed lists

  • Creator
    Topic
  • #54060
    Mike Keys
    Participant

      Is it possible to take multiplie keyed list item pairs passed in the user args with the same label names and write those to an array?

      For example, I’ve been dabbling with writing to some code to define user args containing the segment and field and the subfield with which to keep data (consecutive, of course). My proc uses a simple lreplace to replace the field in question with the new list data. My user args might look like this:

      {EVN 5} {EVNSUB {0 1 2}}

      {PID {3 4}} {PIDSUB 0}

      {PID 5} {PIDSUB {0 1 2 3}}

      The problem is that the keylget command, in the case of the PID & PIDSUB is only getting the last pair of each {PID 5} {PIDSUB {0 1 2 3}}.

      If I can write the values of these lists to an array, I’m thinking I could have multiple args with the same labels. Otherwise, I will have to call the proc multiple times with a unique keyed list in each one.

    Viewing 12 reply threads
    • Author
      Replies
      • #80029

        I don’t see why not. When you read the args into the list, tcl just treats the items like strings. You can loop across them or whatever you want. It’s not until you actually use the key commands that tcl treats it like a keyed list. Think of the args as strings of curly braces and letters.

        You could also try to build yourself more complex data structures. Nested keyed lists for example.

        -- Max Drown (Infor)

      • #80030
        Charlie Bursell
        Participant

          If you are on 6.0+ look at the dict commands

        • #80031
          Mike Keys
          Participant

            Would you guys have an example of how I can loop across the keylget function?

          • #80032

            Using this as an example:

            {EVN 5} {EVNSUB {0 1 2}}

            {PID {3 4}} {PIDSUB 0}

            {PID 5} {PIDSUB {0 1 2 3}}

            Code:

            lappend argsList {EVN 5} {EVNSUB {0 1 2}} {PID {3 4}} {PIDSUB 0} {PID 5} {PIDSUB {0 1 2 3}}

            foreach {type detail} $argsList {
               echo type: $type, detail: $detail
            }

            -- Max Drown (Infor)

          • #80033
            Mike Keys
            Participant

              What I want to do is treat each line of arguments as the input to make my changes. The keylget function only gets the last line.

              Can you use the keylget function with an index?

            • #80034

              I don’t really understand what you need to do. Can you provide more detail?

              -- Max Drown (Infor)

            • #80035
              James Cobane
              Participant

                You could treat each line as a separate key and assign your arguments as the value for that key.  Then use keylkeys to return the list of keys (ARG1, ARG2, ARG3) to loop through to obtain your argument list and loop through your code; i.e.

                {ARG1 {{EVN 5} {EVNSUB {0 1 2}}}} {ARG2 {{PID {3 4}} {PIDSUB 0}}} {ARG3 {{PID 5} {PIDSUB {0 1 2 3}}}}

                Jim Cobane

                Henry Ford Health

              • #80036
                Rob Lindsey
                Participant

                  I have programming that I use to be able to move HL7 fields around within a message and only use the    keylget    to get the arguments.  Below is a sample arg.

                  {MOVE { {PID-2^3 PID-2^0} {OBR-4^3 OBR-4^0} {ORC-22 ORC-19} } }

                  #            would move the data from PID-2 subfield 3 to PID-2 subfield 0

                  #            would move the data from OBR-4 subfield 3 to OBR-4 subfield 0

                  #            would move the data from ORC-22 to ORC-19

                  I then just treat everything as a list.

                  Rob

                • #80037
                  Mike Keys
                  Participant

                    Got it working!

                  • #80038
                    Charlie Bursell
                    Participant

                      Huh?  For a keyed list:

                      foreach key [keylkeys klst] {

                           set x [keylget klst $key]

                           do something

                      }

                      Why make it so complex?

                    • #80039
                      Mike Keys
                      Participant

                        Charlie, I talke to Jim Kosloskey and he informed me that I needed the extra set of curly braces around each set of list items. By doing so, I could loop on each “set” of arguments and then do the keylget stuff.

                        For example, my arguments now look like this:

                        {{SEGNAME EVN} {FIELD 5} {SUBFIELD {0 1 2}}}

                        {{SEGNAME PID} {FIELD {2 3}} {SUBFIELD 0}}

                        {{SEGNAME PID} {FIELD 5} {SUBFIELD {0 1 2}}}

                        {{SEGNAME NK1} {FIELD 2} {SUBFIELD {0 1 2}}}

                        {{SEGNAME PV1} {FIELD {7 17}} {REPSUB 8} {REPCOND {Doctor Nbr}}}

                        {{SEGNAME PV1} {FIELD {7 17}} {SUBFIELD 0}}

                        {{SEGNAME PID} {FIELD 11} {REPSUB 6} {REPCOND {home}}}

                        {{SEGNAME PID} {FIELD 13} {REPSUB 1} {REPCOND {Home}}}

                        The arguments indicate which subfield(s) and/or field repetitions to keep. It’s still evolving, but it works now.

                      • #80040
                        Charlie Bursell
                        Participant

                          Whatever works but I would never pass that many arguments.  It makes for a maintenance nigtmare for those coming behind.  I am more in favor of specific procs for specific tasks.  It would be much faster for me coming behind you to write my own proc than to try to figure out the arguments needed to this

                          If I really did need that many arguments I would prefer and ini file.  At least I could comment that

                          BUT!  Everyone has an opinion.  What works for me may not work for you or vice versa

                        • #80041
                          Mike Keys
                          Participant

                            Charlie, this was just an example of some of the arguments I was working with to test. Ideally, this would only be used for a couple of argument sets to help clear up annoying fields.

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