Announcement

Collapse
No announcement yet.

Delete OBR and OBX if OBX doesn't contain a value

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

  • Delete OBR and OBX if OBX doesn't contain a value

    I am looking to delete the OBR and OBX if a certain value is not present in the OBX segment. The problem comes into play that their might be multiple OBR segments within the message so I don't want to delete all of the OBR messages just the one that does not contain the appropriate values in the corresponding OBX segments.

    Something like this:

    for(var i=0;i<msg['OBX'].length();i++ ){
    if (msg['OBX'][i]['OBX.3']['OBX.3.1'].toString() == "DELETE")
    {
    delete msg['OBX'][i];
    i--;
    }
    }

    Now I just need to delete the OBR and corresponding OBX segments that do contain "DELETE". If the OBX does NOT contain DELETE, then I want to keep the OBR and OBX.

  • #2
    Is the OBX/OBR relationship a 1 to 1?

    Comment


    • #3
      Not necessarily. Here is an example:

      OBR|1|01220430^67747641^LAB|0108:C00035R^67747641^ LAB^010814:C35|BMP^Basic Metabolic Panel^L^BMP^G^300.0025^N/A^CHEM^Chemistry^Chem^C^N/A|R|201401080523|201401080523||
      OBX|1|NM|DELETE^Sodium^L^NA^T^300.0100^Sodium Level^CHEM^Chemistry^Chem^C|1.1|^135|mmol/L|133-148|N||A^S|F|||201401080634|
      OBX|2|NM|DELETE^Potassium^L^K^T^300.0150^Potassium Level^CHEM^Chemistry^Chem^C|1.2|^4.0|mmol/L|3.5-5.1|N||A^S|F|||201401080634|
      OBX|3|NM|DELETE^Chloride^L^CL^T^300.0200^Chloride Level^CHEM^Chemistry^Chem^C|1.3|^105|mmol/L|98-112|N||A^S|F|||201401080634|
      OBX|4|NM|DELETE^Carbon Dioxide^L^CO2^T^300.0250^Carbon Dioxide Level^CHEM^Chemistry^Chem^C|1.4|^24|mmol/L|21-33|N||A^S|F|||201401080634|
      OBX|5|NM|DELETE^Anion Gap^L^GAP^T^300.0300^Anion Gap^CHEM^Chemistry^Chem^C|1.5|^6|mmol/L|0-19|N||A^S|F|||201401080634|
      OBX|6|NM|DELETE^Blood Urea Nitrogen^L^BUN^T^300.0350^Blood Urea Nitrogen^CHEM^Chemistry^Chem^C|1.6|^25|mg/dL|8-22|H||A^S|F|||201401080634|
      OBX|7|NM|DELETE^Creatinine^L^CREAT^T^300.0400^Crea tinine^CHEM^Chemistry^Chem^C|1.7|^0.36|mg/dL|0.64-1.20|L||A^S|F|||201401080634|
      OBX|8|NM|DELETE^Glomerular Filtration Rate^L^GFR^T^300.0425^Glomerular Filtration Rate Calc^CHEM^Chemistry^Chem^C|1.8|^297||mL/min/1.73m2|N||A^S|F|||201401080634|
      OBX|9|NM|DELETE^Bun/Creatinine Ratio^L^BUN/CREAT RATIO^T^300.0450^BUN/Creatinine Ratio^CHEM^Chemistry^Chem^C|1.9|^69.4||12.0-20.0|H||A^S|F|||201401080634|
      OBX|10|NM|DELETE^Glucose^L^GLU^T^300.0500^Glucose Level^CHEM^Chemistry^Chem^C|1.10|^202|mg/dL|70-110|H||A^S|F|||201401080634|
      OBX|11|NM|DELETE^Osmolality,Calculated^L^OSMO,CALC ^T^300.2000^Calculated Osmolality^CHEM^Chemistry^Chem^C|1.11|^279.1|mos/kg|275-295|N||A^S|F|||201401080634|
      OBX|12|NM|DELETE^Calcium^L^CA^T^300.2200^Calcium Level^CHEM^Chemistry^Chem^C|1.12|^8.5|mg/dL|8.4-10.7|N||A^S|F|||201401080634|
      OBX|13|ST|DELETE^Hemolysis Index^L^Hemolysis Index^T^300.8310^Chemistry Specimen Hemolysis^CHEM^Chemistry^Chem^C|1.13|0^No Hemolysis|||N||A^S|F|||201401080634|
      OBR|2|01220430^67747641^LAB|0108:C00035R^67747641^ LAB^010814:C35|PHOS^Phosphorus^L^PHOS^T^300.4260^P hosphorus Level^CHEM^Chemistry^Chem^C^Phosphorus Level|R|201401080523|201401080523|
      OBX|1|NM|PHOS^Phosphorus^L^PHOS^T^300.4260^Phospho rus Level^CHEM^Chemistry^Chem^C|2.1|^1.1|mg/dL|2.5-4.6|LL||A^S|F|||201401080637|
      OBR|3|01220430^67747641^LAB|0108:C00035R^67747641^ LAB^010814:C35|MG^Magnesium^L^MG^G^300.4269^N/A^CHEM^Chemistry^Chem^C^N/A|R|201401080523|201401080523|
      OBX|1|NM|DELETE^Magnesium^L^MG^T^300.4270^Magnesiu m Level^CHEM^Chemistry^Chem^C|3.1|^1.9|mg/dL|1.8-2.5|N||A^S|F|||201401080634|
      Level^CHEM^Chemistry^Chem^C|3.1|^1.9|mg/dL|1.8-2.5|N||A^S|F|||201401080634|

      In this example you can see that the OBR(1) and OBR(3) should be delete since all of their segments contains DELETE in the OBX3.1. However, if the OBR(1) had ANY value in the OBX that did not contain DELETE, then that OBR and OBX record should not be deleted.

      Does that make sense?

      Comment


      • #4
        So, if you had an OBR that had 6 OBXs and 5 said delete, you would delete the 5 OBXs but keep the one OBX and the OBR?

        Comment


        • #5
          Cory,

          That is correct.

          Comment


          • #6
            And will you ever have an OBR without and OBX?

            Comment


            • #7
              No I don't believe that I will.

              Comment


              • #8
                This should give you a start...

                for each (obx in msg.OBX)
                {
                if(obx['OBX.3']['OBX.3.1'].toString() = 'DELETE'
                {
                delete obx;
                }
                }
                var previousSegment = ‘’;
                var obrCount = 0;
                for each (seg in msg.segment)
                {
                if(previousSegment == ‘OBR’ and seg.segmentName != ‘OBX’)
                {
                delete msg[‘OBR’][--obrCount];//accounts for ) base and decrements for missing OBR(may not need)
                }
                If(seg.segmentName == ‘OBR’)
                {
                obrCount++;
                }
                previousSegment = seg.segmentName;
                }

                Comment


                • #9
                  Cory,

                  This doesn't appear to be deleting the OBR segments. I was wondering if there is another way we could tackle this. Since the initial code is going to be deleting the OBX segments, is there a way that we can say if the segment after the OBR is not an OBX then delete the previous OBR message.
                  Last edited by lukekrouse; 01-11-2014, 12:31 PM.

                  Comment


                  • #10
                    There is a typo in Cory's code: obx['OBX.3']['OBX.3.1'].toString() = 'DELETE' that needs to be "==" not "=".

                    His general approach is correct.

                    EDIT - Misread the code. Step through and delete your OBXs. Then step through and look for places where you have one OBR following another, if you do delete the first OBR.
                    Last edited by jbartels; 01-13-2014, 08:22 AM.
                    Jon Bartels

                    Zen is hiring!!!!
                    http://consultzen.com/careers/
                    Talented healthcare IT professionals wanted. Engineers to sales to management.
                    Good benefits, great working environment, genuinely interesting work.

                    Comment


                    • #11
                      Cory,

                      Here is my code and I have attached a sample message. I had to make a change to the if statement since the DELETE is no longer going to be sent.

                      for each (obx in msg.OBX)
                      {
                      if (msg['OBX.8']['OBX.8.1'].toString() != "HH" && msg['OBX.8']['OBX.8.1'].toString() != "LL")
                      {
                      delete obx;
                      }
                      }
                      var previousSegment = '';
                      var obrCount = 0;
                      for each (seg in msg.segment)
                      {
                      if(previousSegment == 'OBR' && seg.segmentName != 'OBX')
                      {
                      delete msg['OBR'][--obrCount];//accounts for ) base and decrements for missing OBR(may not need)
                      }
                      If(seg.segmentName == 'OBR')
                      {
                      obrCount++;
                      }
                      previousSegment = seg.segmentName;
                      }
                      Attached Files
                      Last edited by lukekrouse; 01-13-2014, 08:14 AM.

                      Comment


                      • #12
                        Luke - Add some debugging statements to output the message.

                        Put one after the loop that deletes the OBXs, are the correct OBXs deleted?

                        Put one after the loop that deletes the OBRs. are the correct OBRs deleted?

                        This will narrow down where the problem is.
                        Jon Bartels

                        Zen is hiring!!!!
                        http://consultzen.com/careers/
                        Talented healthcare IT professionals wanted. Engineers to sales to management.
                        Good benefits, great working environment, genuinely interesting work.

                        Comment


                        • #13
                          Jon,

                          The correct OBX's are being deleted, the only outstanding item is deleting the OBR segments.

                          This section is not working.

                          var previousSegment = '';
                          var obrCount = 0;
                          for each (seg in msg.segment)
                          {
                          if(previousSegment == 'OBR' && seg.segmentName != 'OBX')
                          {
                          delete msg['OBR'][--obrCount];//accounts for ) base and decrements for missing OBR(may not need)
                          }
                          If(seg.segmentName == 'OBR')
                          {
                          obrCount++;
                          }
                          previousSegment = seg.segmentName;
                          }

                          Comment


                          • #14
                            I am not getting a value for msg.segment.

                            [2014-01-13 13:49:40,607] DEBUG (transformer:?): Seg:

                            Comment

                            Working...
                            X