Hi Folks,

Today we will see how to connect Mirthconncect with MongoDB a NoSql database, primarily built to store flat file formats. This is really important as the healthcare standards are fast developing and we are in the need to store the data from a RDBMS format to this flat-file format.

In the future blogs I will also Show you manipulate FHIR data in the Mirthconnect and how to connect MongoDB. FHIR and Mirthconnect to provide a unique solution with the fast growing FHIR capability.

Let’s start.

Pre-requisite:  – Chrome application either POSTMAN or DHC client.
                         –  Mirth latest 3.4

MongoDB jar :  We need to download the MongoDB jar file to get this work in Mirth. Go to this link  Download 2.11.1/ I was using this version It is stable version of driver, and download mongo-java-driver-2.11.1.jar

Source : Set your source to FHIR Listener.

For this you need to have the FHIR extension available in the mirth. Please click here to download the FHIR library for Mirth.

Source Transformer:
  In the source transformer we are going to get the incoming data and parse the contents. Consider that we are going to get the incoming FHIR data in the JSON format and parse it’s content.

Right click on the source transformer and choose Javascript. Type the following code in the transformer area.

Var jsonData = connectorMessage.getRawData();

var parseData = JSON.parse(jsonData)// parsed Data contents


var status = parseData.text.status;


var resource= parseData.resourceType;


var identity = parseData.id;


var sex = parseData.gender;


var dob = parseData.birthDate;


logger.info(status+” “+resource+” “+identity+” “+sex+” “+dob);channelMap.put(‘statusDetail’,status);

Destination :I have created 2 destinations here.

Destination 1:
HTTP sender.
URL : http://spark-dstu2.furore.com/fhir/Patient/spark13
Method : GET

Go to edit Response tab on the left side right click to create a new step name it as your convenience I have named it ResponseMessage and type the following code in the transformer area.

var ResponseMessage = response.getMessage();

logger.info(“ResponseMessage : “+ResponseMessage);

channelMap.put(“resposne”,ResponseMessage);  


Destination 2 :
Javascript Writer
select tick on wait for previous destination
In the Javascript writer text area, provide the following code.

try{

var mongoClient = new Packages.com.mongodb.MongoClient(“localhost”,27017);

var db = mongoClient.getDB(“FHIRtest”);

var col = db.getCollection(“SampleFHIR”);

logger.info(“Colection Data : “+col);

var cursor = col.find();

while(cursor.hasNext())

{

logger.info(“Inside Collection : “+cursor.next());

}
}catch(e){}


MongoDB:

 considering you are using windows navigate to the MongoDB latest is 3.2 release. Navigate to the last folder bin, inside bin directory open and run mongod.exe this will let the MongoDB to open the 27017 port.  Now open Mongo.exe

 That will open the MongoDB  shell. Type the following queries for more information.

– Create a DB
show dbs
;

use FHIRtest

type db;

you should get FHIRtest

– Create a Collection

db.createCollection(“SampleFHIR”);

type show collections;

you should get SampleFHIR


– Insert a data

db.SampleFHIR.insertOne({“Data”:”PatientInfo- GETtest”});

type db.SampleFHIR.find();

you should get the following detail{ “_id” : ObjectId(“57c45d8403114b848da5b516”), “Data” : “PatientInfo- GETtest”}


– Now you have a channel whose source can parse the incoming JSON message and get its content.
– One destination can get the data from a FHIR test server and print it
– Another destination that will get the data from the MongoDB database.

Make the source listener to listen to unblocking port I have configured a 666 port.

Deploy the channel and send a sample JSON data in the POSTMAN application. I have used the JSON data where I have parseData.text.status; Object in it. You can create your own JSON or if you want to get a realistic FHIR data please find the examples here.


JSON data:

{“resourceType”: “Patient”,“id”: “example”,“text”: {“status”: “generated”},“active”: true,“gender”: “male”,“_gender”: {“fhir_comments”: [”   use FHIR code system for male / female   “]},“birthDate”: “1974-12-25”,“deceasedBoolean”: false,“managingOrganization”: {“reference”: “Organization/1”}}


Deploy the channel and pass the above JSON message and if everything goes well you will get the output in the Mirth logger as seen in the below picture.




In Java:In Java goto eclipse IDE, deploy the Jar file file stated above and type the following code. This code will get the data from the MongoDB and will also insert the data to the MongoDB. Once the code is completed without error right click to run the java application

package com.fhir;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
public class FhirConnector {
public static void main(String[] args){
try{
MongoClient mongoClient = new MongoClient(“localhost”, 27017);
         DB db = mongoClient.getDB(“FHIRtest”);
         System.out.println(“- Database: ” + db);
       
         DBCollection col = db.getCollection(“SampleFHIR”);
         System.out.println(“- Collections: ” + col);
       
         BasicDBObject document = new BasicDBObject();
         document.put(“database”, “mkyongDB”);
         document.put(“table”, “hosting”);
       
         BasicDBObject documentDetail = new BasicDBObject();
         documentDetail.put(“records”, 99);
         documentDetail.put(“index”, “vps_index1”);
         documentDetail.put(“active”, “true”);
       
         document.put(“detail”, documentDetail);
       
         col.insert(document);
         System.out.println(“Inserted into DB”);
         DBCursor cursor = col.find();
         while(cursor.hasNext()) {
             System.out.println(cursor.next());
         }
}catch(IOException e){
throw new RuntimeException(e);
}
}
}

In the Next blog we will look how to insert the parsed data from the incoming FHIR into MongoDB . Also we have got the XML data from the FHIR test server. We will try to manipulate this incoming message and post a new FHIR message to the testing server and see it in the browser for its working.


Leave a Comment