Connect MongoDB with Mirth
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 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){}
That will open the MongoDB shell. Type the following queries for more information.
show dbs;
use FHIRtest
type db;
you should get FHIRtest
– Create a Collection
db.createCollection(“SampleFHIR”);
type show collections;
you should get SampleFHIR
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.
{“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”}}
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