Announcement

Collapse
No announcement yet.

How to copy OBX value only if it matches string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to copy OBX value only if it matches string

    I'm not even sure where to start with this one.

    I want to find the bold text, wherever it may be present within any OBX, then copy it into the PID segment. It will always be in OBX-5, but which iteration of OBX is unknown.

    This string will only appear in an OBX once, and will always follow the "Enc.#:" string. My initial thought was to copy the entire "Enc.#:ABC1234567890" string based on "Enc.#:" being present, then copy it and trim it with use of substring. But...how can I first capture it? Normally I'd work backwards piece by piece, then combine my code steps, but the first step to capture this value is already stumping me.
    OBX|1|TX|||Pt Name:LAST,FIRST MIDDLE|
    OBX|2|TX|||DOB:01/01/2000|
    OBX|3|TX|||MR#: M001234554 / LR#: F00000001234 / Enc.#:ABC1234567890|
    OBX|4|TX|||Encounter Date: 01/01/2021|

  • #2
    Present in the same place in some OBX? Or anywhere in an OBX? Paste a full message also so people helping you don't have to create their own to solve your problem.

    Also, always the third component (using / as the separator)?

    I would likely use agermano's excellent xFilter function, see https://github.com/nextgenhealthcare...ter%20XMLLists - search that that on this forum to find some examples.
    Last edited by pacmano; 07-20-2021, 11:52 AM.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Want to find "ABC1234567890" in whichever OBX-5 it may be present in. That could be OBX|3 like this example, but could be OBX|4 in the next message. I'll ultimately place it into PID18, but once I can figure out the "capture" part I believe I should have the rest.

      edit: I see you added a link & recommended reading. Thanks, I will look into that!


      Code:
      MSH|^~\&||LOC|||20210716142300||MDM^T02|456454 5|P |2.3||||||
      PID|||M003875197||LAST^FIRST^MIDDLE||123 MAIN ST|F|||||||||TB000123123||123-55-6666||
      PV1|||LOC^^^LOC||||||||||||||||PVT000123123||||| ||||||||||||||||||||20201119||
      ORC|RE|LOC|
      OBR||LOC||^^||||||||||||^^||||||202002040910|||S| |^^^|||||PROVIDERLAST^TEST^MD|
      OBX|1|TX|||Pt Name: |
      OBX|2|TX|||DOB:|
      OBX|3|TX|||MR#: M003875197/ L#: TB000123123/ Enc.#:ABC1234567890|
      OBX|4|TX|||Encounter Date: |
      OBX|5|TX|||Report: |
      OBX|6|TX||||
      OBX|7|TX|||Encounter Number|
      OBX|8|TX|||ABC1234567890|
      OBX|9|TX||| |
      OBX|10|TX|||Patient Visit Type|
      OBX|11|TX|||Patient Status: Established Patient|
      OBX|12|TX||| |
      OBX|13|TX|||Chief Complaint|
      OBX|14|TX|||Chief complaint: blood in stool|
      OBX|15|TX||| |
      OBX|16|TX|||Allergies|
      OBX|17|TX|||Allergies: |
      OBX|18|TX|||Coded Allergies: |
      OBX|19|TX||| No Known Allergies (Verified , 2/15/06)|
      OBX|20|TX||| |
      OBX|21|TX|||Vitals|
      OBX|22|TX|||Vitals: |
      OBX|23|TX||| Height 5 ft 4.00 in / 162.56 cm|
      OBX|24|TX||| Weight 222 lbs 3.579 oz / 100.80 kg|
      OBX|25|TX||| BSA 2.18 m2|
      OBX|26|TX||| BMI 38.1 kg/m2|
      OBX|27|TX||| Temperature 97.3 F / 36.28 C - Temporal|
      OBX|28|TX||| Pulse 83|
      OBX|29|TX||| Respirations 16|
      OBX|30|TX||| Blood Pressure 145/96 Sitting, Left Arm|
      OBX|31|TX||| Pulse Oximetry 97%|
      OBX|32|TX||| |
      OBX|33|TX|||Electronically signed by: Luong,Jennifer DO STF|
      OBX|34|TX|||Report sign date and time: 02/04/20 1133|
      OBX|35|TX||| |
      OBX|36|TX||| |
      OBX|37|TX|||Cosigner |
      OBX|38|TX|||Electronically co-signed by: |
      OBX|39|TX|||Co-sign date and time: |

      Comment


      • #4
        Something like this works also:

        PHP Code:
        for each (var obx in msg.OBX) {
         if (
        obx['OBX.5']['OBX.5.1'].toString().indexOf('Enc.#') > ) {
         
        msg['PID']['PID.2']['PID.2.1'] = obx['OBX.5']['OBX.5.1'].toString().split('/')[2].trim();
         }

        Results in:

        MSH|^~\&||LOC|||20210716142300||MDM^T02|456454 5|P |2.3||||||
        PID||Enc.#:ABC1234567890|M003875197||LAST^FIRST^MI DDLE||123 MAIN ST|F|||||||||TB000123123||123-55-6666||
        PV1|||LOC^^^LOC||||||||||||||||PVT000123123||||| ||||||||||||||||||||20201119||
        ORC|RE|LOC|
        OBR||LOC||^^||||||||||||^^||||||202002040910|||S| |^^^|||||PROVIDERLAST^TEST^MD|
        OBX|1|TX|||Pt Name: | OBX|2|TX|||DOB:|
        OBX|3|TX|||MR#: M003875197/ L#: TB000123123/ Enc.#:ABC1234567890|
        OBX|4|TX|||Encounter Date: |
        OBX|5|TX|||Report:
        ..... |
        Last edited by pacmano; 07-20-2021, 12:40 PM.
        Diridium Technologies, Inc.
        https://diridium.com

        Comment


        • #5
          Originally posted by pacmano View Post
          Something like this works also:

          PHP Code:
          for each (var obx in msg.OBX) {
          if (
          obx['OBX.5']['OBX.5.1'].toString().indexOf('Enc.#') > ) {
          msg['PID']['PID.2']['PID.2.1'] = obx['OBX.5']['OBX.5.1'].toString().split('/')[2].trim();
          }

          Results in:
          Wow, that works perfectly to pull that whole string! Thank you.

          I ultimately need to eliminate the "Enc.#:" from my PID output, and I was able to do this by using Substring trim to pull what I wanted out of what your code produced. I'd like to understand that code since I feel there should be a cleaner way to do that. I read up a bit about Javascript splits and see what you did (thanks for the schooling).

          Is using the Substring function the only way to further trim the "found" result that your code produced, or is there a cleaner way to do so? I'm happy how I have it working, but if I can learn futher I'd love to.
          Last edited by Ozz; 07-20-2021, 03:03 PM.

          Comment


          • #6
            .split just splits a string on the specified character, in this case a “/“. The split returns an array with an index that starts at 0. “[2]” grabs the third element in the array. .trim just removes spaces.
            Diridium Technologies, Inc.
            https://diridium.com

            Comment


            • #7
              split just splits a string on the specified character, in this case a “/“. The split returns an array with an index that starts at 0. “[2]” grabs the third element in the array. .trim just removes spaces.
              Diridium Technologies, Inc.
              https://diridium.com

              Comment


              • #8
                Originally posted by pacmano View Post
                split just splits a string on the specified character, in this case a “/“. The split returns an array with an index that starts at 0. “[2]” grabs the third element in the array. .trim just removes spaces.
                Of course, almost as soon as I sent my reply I came across another tutorial page which explained that. I tried to edit my post quick so you didn't type it all up for nothing, but at least your explanation was more succinct

                Comment


                • #9
                  Instead of using Substring(), I also got it working by changing the split character(s) to "Enc.#:", and the array to [1]. This produced exactly what I wanted, same as trimming with Substring. I figured this was one tiny step cleaner and can't hurt.


                  Code:
                  (var obx in msg.OBX)
                  {if (obx['OBX.5']['OBX.5.1'].toString().indexOf('Enc.#') > 0 )
                  {
                  msg['PID']['PID.18']['PID.18.1'] =obx['OBX.5']['OBX.5.1'].toString().replace('','').split('Enc.#:')[1];
                  }}

                  Comment


                  • #10
                    Not sure what your replace is doing there, probably not needed at all. But your way overall is cleaner, nice work.

                    You will likely find parsing file names will be very similar, e.g. split on the period, then some separator in the file name and so on.
                    Diridium Technologies, Inc.
                    https://diridium.com

                    Comment


                    • #11
                      Originally posted by pacmano View Post
                      Not sure what your replace is doing there, probably not needed at all. But your way overall is cleaner, nice work.

                      You will likely find parsing file names will be very similar, e.g. split on the period, then some separator in the file name and so on.
                      That's what happens when you copy field code to save 20 seconds, and miss editing it completely good catch!

                      I can see this function coming in handy down the road for sure.

                      Comment

                      Working...
                      X