Announcement

Collapse
No announcement yet.

Delete a specific string of text in a HL7 field

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

  • Delete a specific string of text in a HL7 field

    Hi Guys,


    In the destination section I am updating the PID.3.4 but also need to delete a specific string of text in PID.3.1.

    Below is the source message I need to clear the text '_STG' from PID.3.1. Any suggestions?

    Source Message:
    MSH|^~\&|SpeechReport|G2|||20210720064453.2044||OR U^R01^ORU_R01|c26b66b1-33d8-4627-9b61-48cc59c96205||2.4 PID|||789_STG^^^MRN^MRN~NHS1234^^^NHS^NHS||PATIENT 2^FAKE||19860818|M|||...^^^^^^^^RJ7MRN
    OBR|1|21H00890002|21H00890002|HIST|||||||||||||||| ||20210720064442|||F|||||||Admin&SOL Administrator|Admin&SOL Administrator
    OBX|1|FT|21H00890002|#DDCLIN|test|||N|||F

    To Be Message:
    MSH|^~\&|SpeechReport|G2|||20210720064453.2044||OR U^R01^ORU_R01|c26b66b1-33d8-4627-9b61-48cc59c96205||2.4
    PID|||789^^^RJ7MRN^MRN~NHS1234^^^NHS^NHS||PATIENT 2^FAKE||19860818|M|||...^^^^^^^^RJ7MRN
    OBR|1|21H00890002|21H00890002|HIST|||||||||||||||| ||20210720064442|||F|||||||Admin&SOL Administrator|Admin&SOL Administrator
    OBX|1|FT|21H00890002|#DDCLIN|test|||N|||F

    Code for the replacement only:
    for (var PatientListIteration=0; PatientListIteration < msg['PID']['PID.11'].length(); PatientListIteration++) {
    if ( msg['PID']['PID.11'][PatientListIteration]['PID.11.9'].toString() == "RJ7MRN") {
    tmp['PID']['PID.3'][PatientListIteration]['PID.3.4'] = "RJ7MRN"
    }
    }

    Thanks in advance

  • #2
    msg['PID']['PID.3'][0]['PID.3.1'] = msg['PID']['PID.3'][0]['PID.3.1'].toString().split('_')[0]
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      Thanks Pacmano

      I included the line in in my code to loop through all iterations of PID 3 and make a text change and it works great.

      One thing though and its unliley this will happen in a source message but if an extra tilde is sent with no further dets (ID, Assign Auth, ID Type Code) the route errors. Odd this happens, I thought Mirth would just ignore it in when it came to proccessing.

      Sample message
      Code:
      MSH|^~\&|Winpath|Winpath|SpeechReport|G2|202107231041||ORM^O01|47176|T|2.4|1||AL|NE
      PID|||286988_RAX^^^MRN^MRN~XXXX^^^XX^XX~||ZZZTEST^BABY||19920512|M|||GARDEN FLAT^92 WELLS ROAD^BATH^^BA2 3AR^GBR|||||||||||J^Asian Pakistani
      ORC|NW|21H00890010|||||||202107231041 OBR|1|21H00890010|21H00890010|HIST
      Code:
      var i = msg['PID']['PID.3'].length();
      inbound=msg['PID']['PID.3']['PID.3.1'].toString();
      
      while(i--)
      {
        if (inbound.indexOf("_RAX") >= 0) {
          outbound = msg['PID']['PID.3']['PID.3.1'][i] = msg['PID']['PID.3']['PID.3.1'][i].toString().split('_')[0]
        }
      }
      Last edited by agermano; 07-27-2021, 06:28 PM.

      Comment


      • #4
        You are putting your index on the PID.3.1 component instead of the PID.3 field. While there are 3 occurrences of PID.3, there are only two occurrences of PID.3.1. Accessing an XMLList by index will return undefined if there are not that many elements in the list (and in this code, .toString() will complain that it can't be called on undefined.)

        You appear to have changed you requirements from your original post, but here's something else that might help.

        Code:
        for (var pid3 in msg['PID']['PID.3']) {
          if (pid3['PID.3.4'].toString() == 'MRN') {
            pid3['PID.3.1'] = pid3['PID.3.1'].toString().split('_')[0];
            pid3['PID.3.4'] = 'RJ7MRN';
          }
        }

        Comment

        Working...
        X