Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Conditional transform using Javascript

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

  • Conditional transform using Javascript

    I'm trying to receive a file based HL7 and update on of its segments based on the content of another segment. It works if there is a single set of OBR and OBX segments. It fails if there are more than one set of them. How do I specify that if ANY of them contain the specified value, then carry out the transform?



    I've searched the forums some, but I've yet to find someone doing what I'm trying to do.

    Attached are the channel, as well as a pre and post sample message.

    Thanks in advance for any guidance.

    Bob
    Code:
    <com.webreach.mirth.model.Channel>
      <id>55cfed31-5fc8-4914-8cea-bbe41d84754b</id>
      <name>quest inbound</name>
      <description>Bring in file-based labs messages, set Dr. X to practice 0014, all others to 0015</description>
      <enabled>true</enabled>
      <version>1.6.1.2750</version>
      <revision>16</revision>
      <sourceConnector>
        <name>sourceConnector</name>
        <properties>
          <property name="sortAttribute">date</property>
          <property name="pollingType">interval</property>
          <property name="pollingFrequency">1000</property>
          <property name="binary">0</property>
          <property name="processBatchFiles">0</property>
          <property name="DataType">File Reader</property>
          <property name="fileAge">0</property>
          <property name="moveToPattern">${ORIGINALNAME}${SYSTIME}</property>
          <property name="charsetEncoding">DEFAULT_ENCODING</property>
          <property name="checkFileAge">0</property>
          <property name="autoDelete">0</property>
          <property name="host">d:/nextgenemr/mirth/labs_inbound/quest/</property>
          <property name="fileFilter">*.*</property>
          <property name="moveToDirectory">d:/nextgenemr/mirth/processed/quest/</property>
        </properties>
        <transformer>
          <steps>
            <com.webreach.mirth.model.Step>
              <sequenceNumber>0</sequenceNumber>
              <name>New Step</name>
              <script>if (msg['OBR']['OBR.16']['OBR.16.1'].toString() == "I05976"«»){
    msg['MSH']['MSH.4']['MSH.4.2'] = '0014';
    }
    else {
    msg['MSH']['MSH.4']['MSH.4.2'] = '0015';
    }
    hl7_xml = msg;</script>
              <type>JavaScript</type>
              <data class="map">
                <entry>
                  <string>Script</string>
                  <string>if (msg['OBR']['OBR.16']['OBR.16.1'].toString() == "I05976"«»){
    msg['MSH']['MSH.4']['MSH.4.2'] = '0014';
    }
    else {
    msg['MSH']['MSH.4']['MSH.4.2'] = '0015';
    }
    hl7_xml = msg;</string>
                </entry>
              </data>
            </com.webreach.mirth.model.Step>
          </steps>
          <inboundTemplate></inboundTemplate>
          <outboundTemplate></outboundTemplate>
          <inboundProtocol>HL7V2</inboundProtocol>
          <outboundProtocol>HL7V2</outboundProtocol>
          <inboundProperties/>
          <outboundProperties/>
        </transformer>
        <filter>
          <rules/>
        </filter>
        <transportName>File Reader</transportName>
        <mode>SOURCE</mode>
        <enabled>true</enabled>
      </sourceConnector>
      <destinationConnectors>
        <com.webreach.mirth.model.Connector>
          <name>Destination 1</name>
          <properties>
            <property name="charsetEncoding">DEFAULT_ENCODING</property>
            <property name="outputAppend">0</property>
            <property name="DataType">File Writer</property>
            <property name="outputPattern">${ORIGINALNAME}</property>
            <property name="template">${message.encodedData}</property>
            <property name="host">D:/nextgenemr/mirth/outgoing/quest</property>
            <property name="binary">0</property>
          </properties>
          <transformer>
            <steps/>
            <inboundTemplate></inboundTemplate>
            <outboundTemplate></outboundTemplate>
            <inboundProtocol>HL7V2</inboundProtocol>
            <outboundProtocol>HL7V2</outboundProtocol>
            <inboundProperties/>
            <outboundProperties/>
          </transformer>
          <filter>
            <rules/>
          </filter>
          <transportName>File Writer</transportName>
          <mode>DESTINATION</mode>
          <enabled>true</enabled>
        </com.webreach.mirth.model.Connector>
      </destinationConnectors>
      <properties>
        <property name="synchronous">true</property>
        <property name="removeNamespace">true</property>
        <property name="transactional">false</property>
        <property name="initialState">started</property>
        <property name="dont_store_filtered">false</property>
        <property name="error_messages_only">false</property>
        <property name="max_message_age">60</property>
        <property name="store_messages">true</property>
        <property name="encryptData">false</property>
      </properties>
      <preprocessingScript>// Modify the message variable below to pre process data
    return message;</preprocessingScript>
      <postprocessingScript>// This script executes once after a message has been processed
    return;</postprocessingScript>
      <deployScript>// This script executes once when the mule engine is started
    // You only have access to the globalMap here to persist data
    return;</deployScript>
      <shutdownScript>// This script executes once when the mule engine is stopped
    // You only have access to the globalMap here to persist data
    return;</shutdownScript>
    </com.webreach.mirth.model.Channel>

    (partial) input message:
    MSH|^~&||SKB||7193976|200801221430|TOPNET2NEON|ORU ^R01||P|2.3|||||
    PID|1|AL807413F|322707|977845111|XTEST^105540femal e^^^^||19710320|M|||```````||4047895096|||||^^^^^| 578945714||||||||
    ORC|RE|977845111|AL807413F
    OBR|1|977845111||^^^10045^CULTURE, STOOL (CAMPYLOBACTER, SALMONELLA/SHIGELLA)^|||200801151459||^|||||200801152321|T|I0 5976^TESTER^HENRY^Y^^^^^^||977845111||^^^4475^CULT URE, CAMPYLOBACTER^|AT^The Laboratory^123 Main Street^THIS TOWN^GA^43215^THE LAB DOCTOR, MD|200801221400|||F|||||||
    OBX|1|TX|^^^75400287^CULTURE^||SEE NOTE||||||F|||200801221400|AT|
    NTE|1|R|
    NTE|2|R| CULTURE, CAMPYLOBACTER
    NTE|3|R|
    NTE|4|R| MICRO NUMBER: 80039042
    NTE|5|R| TEST STATUS: FINAL
    NTE|6|R| SPECIMEN SOURCE: STOOL
    NTE|7|R| SPECIMEN COMMENTS: ADEQUATE
    NTE|8|R| RESULT: NO ENTERIC CAMPYLOBACTER ISOLATED
    NTE|9||
    NTE|10||Test Performed at:
    NTE|11||The Laboratory
    NTE|12||123 Main Street
    NTE|13||THIS TOWN,GA 43215 THE LAB DOCTOR, MD
    OBR|1|977845111||^^^37212^CLOSTRIDIUM DIFFICILE TOXIN A AND B, EIA^|||200801151459||^|||||200801152321|T|I05976^T ESTER^HENRY^Y^^^^^^||977845111||^^|AT^The Laboratory^123 Main Street^THIS TOWN^GA^43215^THE LAB DOCTOR, MD|200801221400|||F|||||||
    OBX|1|TX|^^^75400383^RESULT:^||SEE NOTE||||||F|||200801221400|AT|
    NTE|1|R|
    NTE|2|R| CLOSTRIDIUM DIFFICILE TOXIN A AND B, EIA
    NTE|3|R|
    NTE|4|R| MICRO NUMBER: 80039043
    NTE|5|R| TEST STATUS: FINAL
    NTE|6|R| SPECIMEN SOURCE: STOOL

    (partial) output message:

    MSH|^~&||SKB^0015||7193976|200801221430|TOPNET2NEO N|ORU^R01||P|2.3|||||
    PID|1|AL807413F|322707|977845111|XTEST^105540femal e^^^^||19710320|M|||```````||4047895096|||||^^^^^| 578945714||||||||
    ORC|RE|977845111|AL807413F
    OBR|1|977845111||^^^10045^CULTURE, STOOL (CAMPYLOBACTER, SALMONELLA/SHIGELLA)^|||200801151459||^|||||200801152321|T|I0 5976^TESTER^HENRY^Y^^^^^^||977845111||^^^4475^CULT URE, CAMPYLOBACTER^|AT^The Laboratory^123 Main Street^THIS TOWN^GA^43215^THE LAB DOCTOR, MD|200801221400|||F|||||||
    OBX|1|TX|^^^75400287^CULTURE^||SEE NOTE||||||F|||200801221400|AT|
    ...

    Post edited by: bobneumann, at: 01/28/2008 12:45

  • #2
    Re:Conditional transform using Javascript

    This can be achieved using a JavaSript step instead a Mapper.

    In the JS step, you'll have to search all the msg['OBR'][i]['OBR.16']['OBR.16.1'] fields (i: 0 to msg['OBR'].length())

    Comment


    • #3
      Re:Conditional transform using Javascript

      I stumbled through the forum some more and found the answer. If there are multiple obr's, you have to either choose which OBR/OBX segment to read, or loop through them. In my case, any of the obr's will do, so instead of this

      Code:
      if (msg['OBR']['OBR.16']['OBR.16.1'].toString()
      I include a "[0]" to specify that the script should examine only the first obr instance:

      Code:
      if (msg['OBR']['OBR.16']['OBR.16.1'][0].toString()
      Thanks again,

      Bob

      Comment


      • #4
        Re:Conditional transform using Javascript

        I have a similar javascript step in my transform.

        if (msg['PV1']['PV1.2'].toString() == "E") {
        msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM ED";
        } else {
        msg['PV1']['PV1.3']['PV1.3.4'] = "WITHAM MEM";
        }

        The tranformed message tab has the correct fields populated, but the encoded message does not have the PV1.3.4 field populated. Do you know why this code does not work properly?

        Thanks!

        Post edited by: pfrey, at: 02/20/2008 09:52

        Comment

        Working...
        X