Sleep method in Mirth

There are situations where in you will configure your source connector as “Database Reader”.
Assuming you define a polling frequency of 10seconds.

Now at the source transformer level, you write several lines of java script code to interact further with data values fetched from the query defined at source connector level.
This may crash the Database server, as the polling frequency is pretty less and it fires the query immediately because you have defined them at the connector level.

You can save yourself in many ways, but I feel this sounds more suitable to implement a delay as the very first transformer (Step 1 among all your steps).

Below is the java script code; can be embedded into any source transformer in Mirth.

function dummySleep(delay)
{
//channelMap.put("Beforetime", new Date().getTime().toString());
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
//channelMap.put("aftertime", new Date().getTime().toString());
}

Important HL7 Segement

======= MSH =======
3 – Sending Application
4 – Sending facility
5 – Receiving App
6 – Receiving Facility
7 – Date time of msg
9.1 – Msg Type
92. – Msg Event
10 – Msg Control Id
11 – Msg Processing Id
12- HL7 Version

======= PID =======
3.1 – InternalId
5.1 – Patient Last Name
5.2 – First Name
8.1 – M/F
11.1 – 11.5 – Pat Address
18.1 – Pat Acc Number
19.1 – Pat SSN

======= GT1=======
3.1 – Insured Last Name
3.2 – First Name
81. – DOB

======= DG1 =======
3.1 – ICD Code

======= OBR =======
2.1 – Placer Order No. (Accession Id)
3.1 – Filler Order No. (Accession Id)
4.1 – Claim Order Code
4.2 – Claim Or Cod desc
7.1 – Requested Dt
10.1 – Run By
14.1 – Sampel received dt
16.1 – Extrnl Phy Id (NPI)
22.1 – Result date time
25.1 – Status

======= OBX =======
3.1 Result Code
3.2 Result description
5.1 Result Value
6.1 Res Unit
11.1 – Res Status
14.1 – Rest date time

======= IN1 =======
3.2 – Payer id
4.1 – Payer Name
5.1 – 5.5 – Payer Add
8.1 – Grp No.
15.1 – Payer Type
16.1 – Insured Last Name
17.1 – Relation
36.1 – Policy No.

Quest and Mirth – 2

Already I wrote how to send an ORM file to Quest lab. Please refer this link – Quest and Mirth – 1
Now I am going to write here how to get/receive a result file (ORU) from Quest Lab.

You may have a different requirements, but as per my need I have created 2 channels for just getting the result and processing them within our system

1. 1st Channel Name : Quest-Results Import
2. Configuration Source:     
   Connector Type : JavaScript Reader
We need to define a timeline to trigger the java script code. Based on this pulling mechanism, your mirth request will be triggered to hit the Quest server for getting the result from them. Coz as I belive, once you send an order to Quest lab, they are not going to convey you that when did they upload the result. Hence we need to automate the process.

In javascript editor box write any valid java script code otherwise leaving it blank will throw you an error. like var app = “Quest”;

3. Configuration Destination:    
Connector Type : SOAP Sender
WSDL Path: https://<UserName>:<Password>@cert.hub.care360.com:443/resultsHub/observations/hl7?wsdl
Service Endpoint URI : https://<UserName>:<Password>@cert.hub.care360.com:443/resultsHub/observations/hl7
Send Response To : Quest Result WS  [This is your 2nd Channle – why? – You will come to know]
User Persistence QueueS : No
Method : GetHL7Results
Now you need to fill up the parameters to above method carefully under “Method” block in Mirth

> Click on string endDate – right side under value fill null
> int maxMessages = 1
> startDate = null
> rest you can leave them blank

Using above method you will get the result from Quest which will be sent to the 2nd channel. But Quest sends you an encoded ORU file (not the plain HL7 ORU file). Hence our target is to decode it and get the right HL7 ORU file.

4. 2nd Channel Name : Quest-Results-WS-Decoder
5. Configuration Source: channel reader ( from 1st channel )
Use the tranformation as below:

//This transformer reads the encoded result message, decodes it, convert it into string and writes to a file.
var qstORUmsg = new XML(msg);
//var qstORUmsgSize = qstORUmsg.*::Body.*::getHL7ResultsResponse.*::result.*::HL7Messages.*.length().toString();
var qstORUmsgSize = qstORUmsg.*::Body.*::getHL7ResultsResponse.*::result.*::HL7Messages.*::HL7Message.length().toString();

//channelMap.put('qstORUmsgSize',qstORUmsgSize);
var encoded = "", decoded = "", finalMsg = "", msgfileId  = "";
for(var i=0; i &lt; qstORUmsgSize; i++){
 encoded = qstORUmsg.*::Body.*::getHL7ResultsResponse.*::result.*::HL7Messages.*::HL7Message[i].*::['message'].toString();
 decoded = FileUtil.decode(encoded);
 finalMsg = Packages.java.lang.String(decoded);
 msgfileId = UUIDGenerator.getUUID();//DateUtil.getCurrentDate("hhmmss.SSS");
 FileUtil.write('C:/MedLink_IX/Quest/Results_Test/Decoded/'+msgfileId+'.hl7', false, finalMsg); 
}

This will be writing each HL7 ORU message into a file with unique name.

5. Message template to be used

Inbound Message Template – If you need the explanation of this envelope please let me know – rajesh4it@gmail.com

  <env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <env:Body>
                    <m:getHL7ResultsResponse>
                                <result>
                                              <HL7Messages>
                                                              <HL7Message>
                                                                          <controlId xsi:type="xsd:string">00000000000001043797</controlId>
                                                                          <message xsi:type="xsd:base64Binary">AnythingHere1</message>
                                                                </HL7Message>
                                                              <HL7Message>
                                                                          <controlId xsi:type="xsd:string">00000000000001066486</controlId>
                                                                          <message xsi:type="xsd:base64Binary">AnythingHere2</message>
                                                                </HL7Message>
                                                </HL7Messages>
                                                <isMore xsi:type="xsd:boolean">false</isMore>
                                                <requestId xsi:type="xsd:string">721fac9e0a801e0c112d96f02a978781</requestId>
                                  </result>
                      </m:getHL7ResultsResponse>
          </env:Body>
  </env:Envelope>

Outbound Message Template:
Keep a valide HL7 message of ORU type. [MSH, PID, PV1 …..]
6. Configuration Destination:  
Channel Writer (Dummy destination for WS Decoder) – as you already got the file using FileUtil.write

Quest and Mirth – 1

Using Mirth for Quest lab, I felt the most difficult thing in Mirth. It took me long to finalize the things. Basically we have been given two works for Quest:
1. Sending an order file (HL7-ORM) to Quest lab
2. Receving the result file (HL7-ORU) from Quest lab.

I will be dealing them into two different posts.
This post is for sending the order file to Quest lab.
 
Mirth Version : 1.8 ( Mirth 2.0 will have a slight different approach)

To note here :
Note#1. Quest expected the order file using WSDL. Hence you need to use SOAP sender as destination to send the ORM file to Quest.
Note#2. Quest expects an encoded message. [Dont send a plain HL7 message]

Lets create a channel in Mirth:
1. Channel Name : Quest-Order
2. Configuring Source : Source can be anything which provides a ORM to Mirth engine. Say its a file reader from D:/Quest/Orders/In
  Because of Note#2, we must use a transformer to encode the message.
  Use a JavaScript transformer at source level with below code to it:
 

  var encodedMsg = FileUtil.encode(messageObject.getRawData().getBytes());
  channelMap.put("EncodedMsg", encodedMsg);
 

    
3. Configuring Destination : Destionation
    Connector Type : SOAP Sender

    While implementing, Quest will be sending you the WSDL URL (or just a web url) and you may get an implementation guide as well. Its huge and will take a lot time to understand and crack the things according to your need. If they dont send you need to ask them.
   
    Irrespective what you get the URL you need to modify it in below manner to fit right with Mirth. Once you choose SOAP Sender under destination fill the things as below:
   
    a) WSDL Path : https://<UserName>:<Password>@cert.hub.care360.com/orders/service?wsdl
    b) Service Endpoint URI : https://<UserName>:<Password>@cert.hub.care360.com:443/orders/service [This will be filled automatically – But I think modify it as I mentioned here]
        SOAP Action URI : Leave blank
    c) Click on “Get Methods” – this should show you all the methods defined in above WSDL
        Select the “SubmitOrder”
    d) Select YES for Generate Envelope
    e) Modify the generated XML as below – Just one change I did under tag  <hl7Order>${EncodedMsg}</hl7Order> – Putting your endcoded variable

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
  <submitOrder xmlns="http://medplus.com/orders">
    <order xmlns="java:com.medplus.serviceHub.orders.webservice">
      <hl7Order>${EncodedMsg}</hl7Order>
    </order>
  </submitOrder>
</soap:Body>
</soap:Envelope>