Announcement

Collapse
No announcement yet.

Force Segments to Appear in Specific Order (HL7 v2)

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

  • Force Segments to Appear in Specific Order (HL7 v2)

    I'm seeking some input regarding headers for batch files. I have the output messages pretty darn close to exactly what I want. However, the FHS and BHS segments are being created after the bulk of the HL7 message (but oddly before the Z segment). The footer, or BTS segment, is behaving how I want.
    I'd appreciate another set of eyes on this and maybe a tip for how to handle the ordering of the segments? How can I use Mirth Connect to make sure the segments are in the order I require?
    It's supposed to be:
    FHS
    BHS
    MSH
    *then rest of HL7 message
    BTS

    but instead it's
    MSH
    All other segments in msg
    FHS
    BHS


    The javascript is below, for reference.
    How do I get FHS and BHS segments to be before MSH?

    Thank you!
    ***********************
    var dateTdy,strdate,strDt,strMn,strHr,strMin,strSec, mshCount = 0;

    dateTdy = new Date();
    strdate = dateTdy.getFullYear().toString();
    if (dateTdy.getDate() < 10)
    strDt = "0"+dateTdy.getDate();
    else
    strDt = dateTdy.getDate().toString();
    if (dateTdy.getMonth() < 9)
    strMn = "0"+(dateTdy.getMonth()+1);
    else
    strMn = (dateTdy.getMonth()+1).toString();
    if (dateTdy.getHours() < 9)
    strHr = "0"+dateTdy.getHours();
    else
    strHr = dateTdy.getHours();
    if (dateTdy.getMinutes() < 9)
    strMin = "0"+dateTdy.getMinutes();
    else
    strMin = dateTdy.getMinutes();
    if (dateTdy.getSeconds() < 9)
    strSec = "0"+dateTdy.getSeconds();
    else
    strSec = dateTdy.getSeconds();

    //FHS
    msg['FHS']['FHS.7']['FHS.7.1'] = strdate+strMn+strDt+strHr+strMin+"."+strSec;
    msg['FHS']['FHS.9']['FHS.9.1'] = sourceMap.get('originalFilename');

    //BHS
    msg['BHS']['BHS.7']['BHS.7.1'] = strdate+strMn+strDt+strHr+strMin+"."+strSec;
    msg['BHS']['BHS.10']['BHS.10.1'] = "";



    //MSH Segment
    msg['MSH']['MSH.3']['MSH.3.1'] = validate('provhealthor', '', new Array());
    msg['MSH']['MSH.4']['MSH.4.1'] = validate('', '', new Array());
    msg['MSH']['MSH.5']['MSH.5.1'] = validate('RPM_PROVHEALTHOR_ADT', '', new Array());
    msg['MSH']['MSH.6']['MSH.6.1'] = validate('', '', new Array());
    msg['MSH']['MSH.7']['MSH.7.1'] = msg['MSH']['MSH.7']['MSH.7.1'].toString();
    msg['MSH']['MSH.8']['MSH.8.1'] = validate('', '', new Array());
    //msg['MSH']['MSH.9'] = this component doesn't need to be changed.
    msg['MSH']['MSH.7']['MSH.7.1'] = msg['MSH']['MSH.7']['MSH.7.1'].toString();
    msg['MSH']['MSH.10']['MSH.10.1'] = msg['MSH']['MSH.10']['MSH.10.1'].toString();
    msg['MSH']['MSH.11']['MSH.11.1'] = validate('P', '', new Array());
    msg['MSH']['MSH.12']['MSH.12.1'] = validate('2.3.1', '', new Array());

    // EVN Segment - not present in source message. Creating it in outbound message here:
    createSegmentAfter('EVN', msg['MSH']);
    msg['EVN']['EVN.1']['EVN.1.1'] = msg['MSH']['MSH.9']['MSH.9.2'].toString();

    //No Changes to PID segment.

    //PV1 Segment.
    //msg['PV1']['PV1.46']['PV1.46.1'] = msg['PV1']['PV1.46']['PV1.46.1'].toString();
    if(msg['PV1']['PV1.45']['PV1.45.1'].toString().length == 0)
    msg['PV1']['PV1.45']['PV1.45.1'] = '';


    //PV1-7 added because carets were being sent in some messages so now they will be copied.
    if(msg['PV1']['PV1.7']['PV1.7.1'].toString().length == 0)
    msg['PV1']['PV1.7']['PV1.7.1'] = '^^^^^^^^';



    //No Changes to DG1 segment.

    //IN1 Segment
    for each (var in1 in msg.IN1) {
    in1['IN1.3']['IN1.3.1'] = ''; //Clear IN1-3.1
    in1['IN1.9']['IN1.9.1'] = ''; //Clear IN1-9.1
    in1['IN1.19']['IN1.19.7'] = ''; //Clear IN1-19.7
    in1['IN1.19']['IN1.19.8'] = ''; //Clear IN1-19.8
    in1['IN1.19']['IN1.19.9'] = ''; //Clear IN1-19.9
    in1['IN1.35']['IN1.35.1'] = ''; //Clear IN1-35.1
    in1['IN1.36']['IN1.36.1'] = ''; //Clear IN1-36.1
    in1['IN1.42']['IN1.42.1'] = ''; //Clear IN1-42.1
    in1['IN1.44']['IN1.44.6'] = ''; //Clear IN1-44.6
    in1['IN1.47']['IN1.47.1'] = ''; //Clear IN1-47.1

    }

    // ZXA Segment - no present in source message.
    //ZXA Segment
    if(msg['PV1']['PV1.39']['PV1.39.1'].toString().length > 0) {
    msg['ZXA']['ZXA.1']['ZXA.1.1'] = '1';
    msg['ZXA']['ZXA.2']['ZXA.2.1'] = '50';
    msg['ZXA']['ZXA.2']['ZXA.2.2'] = msg['PV1']['PV1.39']['PV1.39.1'].toString();
    }

    //BTS segment
    for each (segMSH in msg.MSH) {
    mshCount++;
    }

    msg['BTS']['BTS.1'] = "" + mshCount;
    msg['BTS']['BTS.3'] = "";

  • #2
    I saw a suggestion to use message outbound templates (http://www.mirthcorp.com/community/f...=segment+order).

    I hope that isn't the best solution because it's processing about a message a second and there are 800 "messages" in the sample batch file, which is taken from PROD.

    Comment


    • #3
      and this older tidbit as well

      http://www.mirthcorp.com/community/f...ead.php?t=7865

      Comment


      • #4
        @Agermano helped me solve this on the slack channel!

        Comment

        Working...
        X