Announcement

Collapse
No announcement yet.

Trying to convert OBX Segments to NTE Segments for vendor

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

  • Trying to convert OBX Segments to NTE Segments for vendor

    Would appreciate some help with my attempt to convert a Lab Result OBX Segments with certain value (ILDATE) to be NTE segments.

    I'm writing a transformer step to convert 3 OBX Segments to begin with NTE keeping all the OBX values but just replacing the "OBX" with "NTE" at the beginning of each OBX segment. This is at the request of our vendor. Once I convert the OBX segments to NTE , I want to delete the 3 OBX segments . The 3 OBX Segments are valued with "ILDATE" in the OBX.3.1 field. I want to keep the 4th OBX segment in the output , the 4th OBX segment is valued with the test name of "GENTAMICIN" in the OBX.3.2 field.

    I would not normally do this type of conversion.

    Below is my attached transformer code. I also included the Test Lab ORU Result with a before transformed look and after transformed. I would appreciate anyone's help in finding the correct way to do this. Thanks in advance.


    Below is the "before" its transformed Lab Result :

    MSH|^~\&|LA01|ST02A||ST02A|202005271435|RESULTR01O UT|ORU^R01^ORU_R01|033833|P|2.5.1|||AL|NE|UNITED STATES
    SFT|Allscripts Corporation.^L|17.0.3.0|Allscripts Lab|LabLink||199911160030
    PID|1||01190569^^^A^MR~01147406^^^ST02^PI~20115000 05^^^A^AN||KING^EMRB^^^^^L||198902200000|M|||||||| ||2011500005|||||||||||||||202005250100|ST02A
    PV1|1|O|KROP^KROP|CL|||53764^BOOTH^ROBERT^^^^^^LA0 1^L^^^LA01^LA01_Facility^^^^^^^||||||||||53764^BOO TH^ROBERT^^^^^^LA01^L^^^LA01^LA01_Facility^^^^^^^| LCO||||||||||||||||||||||||||202004240952|20200424 2359
    ORC|RE|2013200023^LA01|2013200023^LA01|R201320006^ LA01|CM||1^^^202005111039^^R||202005111440|||61656 ^HINCH^BRYAN^T^^^^^LA01^L^^^LA01^LA01_Facility^^^^ ^^^MD|MCO|^WPN^PH^^^419^3835614~^ASN^FX^^^^9419383 5618~^BPN^BP^^^800^4528980|202005111440|^^LA01|KCC S1^KINGSTON CAR CENTER SYLVANIA FLOOR 1^L||||UNIVERSITY OF TOLEDO MEDICAL CENTER^L^^^^CLIA^CLIA^^A^36D0655927|3000 ARLINGTON AVE.^^Toledo^OH^43614^UNITED STATES^B|^WPN^PH^^^419^3833470
    OBR|1|2013200023^LA01|2013200023^LA01|31557^GENTAM ICIN RANDOM IL^LA01^3664-0^Gentamicin\S\random:MCnc:Pt:Ser/Plas:Qn^LN|R||202005111039||||L||See Results|202005111440|1&BLOOD^^^^^RED IL&Vacutainer red top; no additive 7 ml, IL|61656^HINCH^BRYAN^T^^^^^LA01^L^^^LA01^LA01_Faci lity^^^^^^^MD|^WPN^PH^^^419^3835614~^ASN^FX^^^^941 93835618~^BPN^BP^^^800^4528980|||||202005271435||I L|F||1^^^202005111039^^R
    TQ1|1|1|||||202005111039||R^R^L
    OBX|1|TX|ILDATE^IL^LA01|1|Test Performed by Mercy Laboratories 2222 Cherry St. Toledo, OH 43608||||||F|||202005111039|IL^MERCY LABORATORIES||||202005111440||||MERCY LABORATORIES^L^^^^^|2222 Cherry St^^Toledo^OH^43608^USA^B
    OBX|2|TX|ILDATE^IL^LA01|2|(419) 251.8383 - Released 05/11/2020 13:30||||||F|||202005111039|IL^MERCY LABORATORIES||||202005111440||||MERCY LABORATORIES^L^^^^^|2222 Cherry St^^Toledo^OH^43608^USA^B
    OBX|3|TX|ILDATE^IL^LA01|3|||||||F|||202005111039|I L^MERCY LABORATORIES||||202005111440||||MERCY LABORATORIES^L^^^^^|2222 Cherry St^^Toledo^OH^43608^USA^B
    OBX|4|NM|GENT^GENTAMICIN^LA01|1|2|ug/mL^ug/mL^L|||||F|||202005111039|IL^MERCY LABORATORIES||||202005111440||||MERCY LABORATORIES^L^^^^^|2222 Cherry St^^Toledo^OH^43608^USA^B
    NTE|1|L||RE
    NTE|2|L|Reference Ranges|RE
    NTE|3|L|Peak: 5 - 10|RE
    NTE|4|L|Trough: 0 - 2|RE
    SPM|1|^2013200023&LA01||1^BLOOD^L^119297000^Blood specimen (specimen)^SCT||||||||7.0^|||||202005111039|202005 111440|||||||||RED IL^Vacutainer red top; no additive 7 ml, IL^L
    ZOM|1||||8051120001||||||IL||||||8051120001|1|H|.0 ||202005111041|||||||86133||||||||||S||||||2013200 023^LA01|||||F||||||IL CHEM|I|D|||GENTAMICIN RANDOM||||||||||^^MRO|LCO|N|199911160030||||119297 000^Blood specimen (specimen)~7.0|IF&DELETE)&INTERFACE (DO&NOT&&&&&LA01||||||||||||||||||||||||||||^^LA01 |||||||||||||||||||||||||||||||N|N|||||||||N
    ZCA|||KCCS1|||||||||||||||||||||||||||||||||||||01 147406^^^ST02^PI|||test|$ReleaseId: 17.0.3.0$|$Id: pwic.pad, 238480, 2019-04-30 17:06:09$;$ReleaseId: 17.0.3.0$;$StView: rel1|$Date$||||198902200500+0000|EST5EDT||||KCCS1^ KINGSTON CAR CENTER SYLVANIA FLOOR 1|||||KCCS1^KINGSTON ROOMS 100-132|KCCS1^KINGSTON CAR CENTER SYLVANIA FLOOR 1^SF|||||||||||||||UNIVERSITY OF TOLEDO MEDICAL CENTER~3000 ARLINGTON AVE.^^Toledo^OH^43614^UNITED STATES~36D0655927~419-383-3470

    Below is the "after" transformed Lab Result :

    MSH|^~\&|LA01|ST02A||KCCS1|202005271435|RESULTR01O UT|ORU^R01^ORU_R01|033833|P|2.5.1|||AL|NE|UNITED STATES
    PID|1||01190569^^^A^MR~01147406^^^ST02^PI~20115000 05^^^A^AN||KING^EMRB^^^^^L||198902200000|M|||||||| ||2011500005|||||||||||||||202005250100|ST02A
    PV1|1|O|KROP^KROP|CL|||53764^BOOTH^ROBERT^^^^^^LA0 1^L^^^LA01^LA01_Facility^^^^^^^||||||||||53764^BOO TH^ROBERT^^^^^^LA01^L^^^LA01^LA01_Facility^^^^^^^| LCO||||||||||||||||||||||||||202004240952|20200424 2359
    ORC|RE|2013200023^LA01|2013200023^LA01|R201320006^ LA01|CM||1^^^202005111039^^R||202005111440|||61656 ^HINCH^BRYAN^T^^^^^LA01^L^^^LA01^LA01_Facility^^^^ ^^^MD|MCO|^WPN^PH^^^419^3835614~^ASN^FX^^^^9419383 5618~^BPN^BP^^^800^4528980|202005111440|^^LA01|KCC S1^KINGSTON CAR CENTER SYLVANIA FLOOR 1^L||||UNIVERSITY OF TOLEDO MEDICAL CENTER^L^^^^CLIA^CLIA^^A^36D0655927|3000 ARLINGTON AVE.^^Toledo^OH^43614^UNITED STATES^B|^WPN^PH^^^419^3833470
    OBR|1|R201320006^LA01|2013200023^LA01|31557^GENTAM ICIN RANDOM IL^LA01^3664-0^Gentamicin\S\random:MCnc:Pt:Ser/Plas:Qn^LN|R||202005111039||||L||See Results|202005111440|1&BLOOD^^^^^RED IL&Vacutainer red top; no additive 7 ml, IL|61656^HINCH^BRYAN^T^^^^^LA01^L^^^LA01^LA01_Faci lity^^^^^^^MD| |||||202005271435||IL|F||1^^^202005111039^^R
    TQ1|1|1|||||202005111039||R^R^L
    NTE|undefined|undefined|undefined
    NTE|undefined|undefined|undefined
    NTE|undefined|undefined|undefined

    NTE|undefined|undefined|undefined
    OBX|4|NM|GENT^GENTAMICIN^LA01|1|2|ug/mL^ug/mL^L|||||F|||202005111039|IL^MERCY LABORATORIES||||202005111440||||MERCY LABORATORIES^L^^^^^|2222 Cherry St^^Toledo^OH^43608^USA^B
    NTE|1|L||RE
    NTE|2|L|Reference Ranges|RE
    NTE|3|L|Peak: 5 - 10|RE
    NTE|4|L|Trough: 0 - 2|RE
    SPM|1|^2013200023&LA01||1^BLOOD^L^119297000^Blood specimen (specimen)^SCT||||||||7.0^|||||202005111039|202005 111440|||||||||RED IL^Vacutainer red top; no additive 7 ml, IL^L
    ZOM|1||||8051120001||||||IL||||||8051120001|1|H|.0 ||202005111041|||||||86133||||||||||S||||||2013200 023^LA01|||||F||||||IL CHEM|I|D|||GENTAMICIN RANDOM||||||||||^^MRO|LCO|N|199911160030||||119297 000^Blood specimen (specimen)~7.0|IF&DELETE)&INTERFACE (DO&NOT&&&&&LA01||||||||||||||||||||||||||||^^LA01 |||||||||||||||||||||||||||||||N|N|||||||||N
    ZCA|||KCCS1|||||||||||||||||||||||||||||||||||||01 147406^^^ST02^PI|||test|$ReleaseId: 17.0.3.0$|$Id: pwic.pad, 238480, 2019-04-30 17:06:09$;$ReleaseId: 17.0.3.0$;$StView: rel1|$Date$||||198902200500+0000|EST5EDT||||KCCS1^ KINGSTON CAR CENTER SYLVANIA FLOOR 1|||||KCCS1^KINGSTON ROOMS 100-132|KCCS1^KINGSTON CAR CENTER SYLVANIA FLOOR 1^SF|||||||||||||||UNIVERSITY OF TOLEDO MEDICAL CENTER~3000 ARLINGTON AVE.^^Toledo^OH^43614^UNITED STATES~36D0655927~419-383-3470

    The 3 Bolded NTE segments above I would like to be NTE Segments with the 3 OBX segments that are valued with ILDATE in the OBX.3.1 field in the before HL7 message.
    I just want 3 NTE segments that look like this below :

    "NTE|1|TX|ILDATE^IL^LA01|1|Test Performed by Mercy Laboratories 2222 Cherry St. Toledo, OH 43608||||||F|||202005111039|IL^MERCY LABORATORIES||||202005111440||||MERCY
    Attached Files

  • #2
    Wanted to look at your code but instead heeded my antivirus warning and didn't open the attachment. With that, hoping the code below will be beneficial. It loops thru OBXs, creates corresponding NTEs, maps the child fields then deletes the OBXs.

    Code:
    for (var x = 0; x < msg.OBX.length(); x++) {
      var nte = <NTE/>;
      for (var y = 1; y < msg.OBX[x].children().length() + 1; y++) {
        nte['NTE.' + y] = msg.OBX[x]['OBX.' + y]
      }
      msg.insertChildAfter(msg.OBX[x], nte)
    }
    delete msg.OBX
    If you're only satisfying one downstream vendor, a better option might be this in your preprocessor script
    Code:
    message = message.replace(/\rNTE/g, "\rOBX")
    return message;
    ...compliments of flyerman from the below but w/the segments reversed.
    https://forums.mirthproject.io/forum...o-obx-segments
    Last edited by jkrebs; 05-28-2020, 05:14 PM.

    Comment


    • #3
      Just realized you want to keep the fourth OBX, so made the corrections.
      Code:
      //loop OBXs
      for (var x = 0; x < msg.OBX.length()-1; x++) {
        var nte = <NTE/>;
        for (var y = 1; y < msg.OBX[x].children().length() + 1; y++) {
          nte['NTE.' + y] = msg.OBX[x]['OBX.' + y]
        }
        msg.insertChildAfter(msg.OBX[x], nte)
      } 
      
      //delete all but last OBX
      var end = msg.OBX.length()-2
      for (var z = end; z >= 0; z--) {
        delete msg.OBX[z]
      }
      Last edited by jkrebs; 05-29-2020, 05:45 AM.

      Comment


      • #4
        I realize you said you need help in finding the correct way, and this is not the correct way, but it does work.

        Code:
        for each (var obx in msg.OBX) {
            if (obx['OBX.3']['OBX.3.1'].toString() == 'ILDATE') {
                obx.setName('NTE');
            }
        }
        If you have any other transformer steps, I would do this at the very end, because it only renames the segment, and not all of the fields, but the mirth parser still allows it, i.e. you would have to access the fields like msg['NTE']['OBX.3'] after renaming the segment.

        For the "correct" way, jkrebs had the right idea about making sure the fields were also named correctly, but you have to go down to the component and sub-component level, as well as handle repetitions for a full implementation. There's actually already a code template for this called renameField.

        Combining my quick and dirty solution with the one jkrebs gave, and using the code template would look something like this.

        Code:
        for each (var obx in msg.OBX) {
            if (obx['OBX.3']['OBX.3.1'].toString() == 'ILDATE') {
                var nte = <NTE/>;
                for each (var child in obx.*) {
                    nte.appendChild(renameField(child, child.localName().replace('OBX', 'NTE')));
                }
                // replace obx with nte
                obx.parent().children()[obx.childIndex()] = nte;
            }
        }
        Last edited by agermano; 05-28-2020, 05:53 PM.

        Comment


        • #5
          Thanks agermano for both the dirty and the corrections. Most helpful to me going forward...

          Comment


          • #6
            jkrebs The preprocessor solution you shared is also a good idea if the channel design allows for it. The code is shorter, for sure. You could do this to still incorporate the check for OBX.3.1, using a positive lookahead.

            Code:
            return message.replace(/\rOBX(?=\|(?:[^|]*\|){2}ILDATE[|^])/g, '\rNTE')
            Last edited by agermano; 05-28-2020, 06:25 PM.

            Comment


            • #7
              Code:
              return message.replace(/\rOBX(?=\|(?:[^|]*\|){2}ILDATE[|^])/g, '\rNTE')
              One line of code in the right place. That's just plain cool! I'll be looking for an opportunity to use it. Thanks again for sharing...

              Comment


              • #8
                Thanks for your code suggestions JKrebs and Agermano,

                I'm put the logic that Agermano suggested but I'm am seeing an error around the RenameField piece. So I think I missed something .

                Below is the error that I received:
                ERROR MESSAGE: Error evaluating transformer
                com.mirth.connect.server.MirthJavascriptTransforme rException:
                CHANNEL: a_HLab_CM251_ORM_ORU_STORAGE_FEEDER
                CONNECTOR: ewOpenText_HLAB_Results_ORUHtcpOut
                SCRIPT SOURCE: TRANSFORMER
                SOURCE CODE:
                388: if (obx['OBX.3']['OBX.3.1'].toString() == 'ILDATE') {
                389: var nte = <NTE/>;
                390: var renameField;
                391:
                392: for each (var child in obx.*) {
                393: nte.appendChild(renameField(child, child.localName().replace('OBX', 'NTE')));
                394: }
                395: // replace obx with nte
                396: obx.parent().children()[obx.childIndex()] = nte;
                397: }
                LINE NUMBER: 393
                DETAILS: TypeError: [email protected] is not a function, it is undefined.



                Here is the logic below that I put in place , maybe I missed something ? I put the var RenameField in because I recieved an error saying RenameField was not defined.

                * OBX Segment
                */
                if (seg.name().toString() == "OBX") {


                // if (seg.name().toString() == "OBX" &&
                // msg['OBX'][OBXIndex]['OBX.3']['OBX.3.1'].toString() == "ILDATE") {
                // var outputNTE = <NTE/>;
                //
                //
                //
                // outputNTE['NTE.1']['NTE.1.1'] = outputNTE01;
                // outputNTE['NTE.2']['NTE.2.1'] = outputNTE02;
                // outputNTE['NTE.3']['NTE.3.1'] = outputNTE03;
                // tmp.appendChild(outputNTE);
                // delete tmp['OBX'][OBXIndex];

                for each (var obx in msg.OBX) {
                if (obx['OBX.3']['OBX.3.1'].toString() == 'ILDATE') {
                var nte = <NTE/>;
                var renameField;

                for each (var child in obx.*) {
                nte.appendChild(renameField(child, child.localName().replace('OBX', 'NTE')));
                }
                // replace obx with nte
                obx.parent().children()[obx.childIndex()] = nte;
                }



                }

                // OBXIndex++;
                tmp.appendChild(seg);
                }

                Comment


                • #9
                  I made renameField a link, but maybe that wasn't obvious. You'll need to go here https://github.com/nextgenhealthcare...%20HL7%20Field

                  And import that code template and assign it to your channel in order to use the function. If you've never used code templates before, I suggest taking a look at the section in the user guide.

                  Comment

                  Working...
                  X