Continuous Integration & Deployment with Mirth Using Jenkins

This blog post is to provide a view on developing a continuous integration  and deployment using Mirth tool.

You can follow the below  provided steps to  do the same.

Scenario:

  • Often the codes have to be moved from one environment to another. From Staging to Testing and to Production  environment.
  • Manually moving the channels can be cumbersome and prone to human error. It is always advisable to automate this entire integration and deployment feature.

Steps to perform the Continuous Integration (CI):

  1. The source of truth here is repository be it Git Hub/Lab/Bitbucket or SVN. We need to create a webhook from the git repositories.
  2. Install Jenkins in the local system. You can follow a number of procedures online.
  3. Once jenkins is installed, we need to create  job in the jekins to perform this.

Follow the below steps to create job in jenkins:

  1. select New Item and click on freestyle project and click ok.
  2. In the General tab select Git Hub project and provide the git URL of your repository.
  3. In the source code management select Git
  4. In the Build Trigger area select “GitHub hook trigger for GITScm polling”.
  5. Click Save now and the changes will be saved.

If the above steps are completed then if any new code is pushed to your repository then it will be pulled by jenkins and the pulled code will appear on your folder location.

Continuous Integration Issues:

  • If you are using a public Git Hub repository then there will be a challenge involved in Git recognizing your local IP.
  • To overcome this issue, I made my local jenkins public by using Ngrok tool. you can download the tool from here
  • Once you download the tool, open the application and type ngrok.exe http “jenkinsportnumber” in the shell. This will make your  IP+jenkins port go public.
  • After the command is entered you can see that it gives a http url in the console. You can use that URL in the github webhook instead of mentioning localhost in it.

Testing:

Push any new code in the repository and check the jenkins Job and you can see the data is pulled and completed.

Happy Integrations!!!!!!!

Advertisements

Why PDF is complicated in Mirth

Visit www.hl7engine.com to know more

This blog is about why PDF is complicated in Mirth? and How we can Split PDF in Mirth?.

Splitting of PDF, PDF parsing is complicated in Mirth because of the libraries used to perform few actions in it.

Basically, in JAVA if you want to split a PDF or parse a PDF content or manipulate data of a PDF content you would use couple of famous Libraries such as

  1. PDF BOX from Apache
  2. iText library (Licensed from 7.1 Version)

If you are going to use the unlicensed stable version on iText Library then the best version is 5.5.1

Problem of using PDF library in Mirth:

By Default, Mirth already uses these two libraries by default for its other functionality.

For Example: Mirth uses PDF BOX v.1.8.4 for the pdf viewer extension. If you are using a new version of PDF BOX library and provide it in anywhere in custom library or other locations it wont work.

Because Mirth do not identify which version of the library it has to select. You can see these two libraries in the following location shown in the screenshot below:

How to use PDF Box Library:

The Best library you can use to perform multiple functionality of PDF is using Apache PDF BOX library.

First, Mirth wants to read the font of the PDF that is suppose to manipulate. To, do that we need to add another library called fontbox-1.8.4 inside C:\Program Files\Mirth Connect\extensions\doc\lib location.

Then add this library path  in destination.xml in C:\Program Files\Mirth Connect\extensions\doc as <library type=”SERVER” path=”lib/fontbox-1.8.4.jar” />

Another approach:

If you really do not want to use the PDF Viewer functionality in mirth.

You can disable that extension and provide later version (v2.5) of PDF BOX library in the same way mentioned above.

Note: Using the PDF BOX library outside without following the above approach will not work. It will always throw error.

Is Splitting PDF possible inside Mirth?

Yes, certainly possible.

There is a Java program already written using Apache PDF Box library function https://gist.github.com/actsasflinn/4516ae1c322447bdc2634fab9240d70c 

I used the same function and converted to Javascript. Here is a sample of that code which is converted to EX4JS

Code converted from Java to Javascript – Splitting PDF

var AnyValueOfYyourChoice = ”;

for(q=0;q<data.length;q++){

var pdPage = org.apache.pdfbox.pdmodel.PDPage();
var inputDocument = org.apache.pdfbox.pdmodel.PDDocument.loadNonSeq(new java.io.File(globalMap.get(‘pdfReaderFilePath’)+$(‘originalFilename’)),null);
var stripper = new org.apache.pdfbox.util.PDFTextStripper();
var outputDocument = new org.apache.pdfbox.pdmodel.PDDocument();
var uuid = UUIDGenerator.getUUID();
var page;

for (page = 1; page <= inputDocument.getNumberOfPages(); ++page) {

stripper.setStartPage(page);
stripper.setEndPage(page);
var text = stripper.getText(inputDocument);
var p = new java.util.regex.Pattern.compile(DataNeedToBeCheckedFor);
var m = p.matcher(text);
if(m.find()){
var pdPage = inputDocument.getDocumentCatalog().getAllPages().get(page – 1);
outputDocument.importPage(pdPage);
}
}
var output_file = new java.io.File(globalMap.get(‘newPdfReaderPath’) +$(‘fileNameDocType’)+’_’+AnyValueOfYyourChoice+”.pdf”);
outputDocument.save(output_file);
outputDocument.close();
inputDocument.close();
}

Create Automated Script for IT deployment

This is a hypothetical scenario:
Imagine a situation where you have developed all the channels required to build the interfaces, now you are going to move your channels to the production or any beta testing environment.

In this scenario you would want to make the channels to be imported to the mirth in specific environment. Imagine you don’t have an access to make this move. This will be permitted to be done only by the IT guys. In this scenario, the IT team will find it difficult to import the channels, as you cannot expect them to understand mirth.

The easier way for them to do is, you give a command to them they will execute the command and everything will start to work fine. i.e an import command via mirth command prompt like this:

import “Your-channel-available-folder\20180312\EAI-Deployment Script Generator.xml” force

But it will again be the manual process for the developers to do this manually. Imagine one day you have to send 4 to 5 channels to. In that case, you have to manually create this script and then send it. To overcome it, we can write one channel that will create a script for all the channels that is deployed today.

The logic behind this is that whatever is developed and tested today, only those channels will be moved to beta testing or prod. Based on that scenario, I have built the below code.

var currentDate = DateUtil.getCurrentDate(“yyyy-MM-dd”);
var currentYear = currentDate.substring(0, 4);
var currentMonth = currentDate.substring(5, 7);
var currentDay = currentDate.substring(8, 10);
var georgianMonth = parseInt(currentMonth) – 1;
var scriptBuilder = java.lang.StringBuilder();
var getScriptDate = DateUtil.getCurrentDate(“yyyyMMdd”);
// Initialize controller
var controller = com.mirth.connect.server.controllers.ControllerFactory.getFactory().createEngineController();
// Create Channel Deployed ID’s
var channels = ChannelUtil.getDeployedChannelIds().toArray();

for each(channel in channels) {

//https://svn.mirthcorp.com/connect/tags/3.4.1/server/src/com/mirth/connect/model/DashboardStatus.java

var dashboardStatus = controller.getChannelStatus(channel);
// Get Georgian date mapping from – https://docs.oracle.com/javase/7/docs/api/constant-values.html#java.util.Calendar.DATE

var fetchLastDeployedDay = dashboardStatus.getDeployedDate().get(5);
var fetchLastDeployedMonth = dashboardStatus.getDeployedDate().get(2);
var fetchLastDeployedYear = dashboardStatus.getDeployedDate().get(1);

if ((fetchLastDeployedYear == currentYear) && (fetchLastDeployedDay == currentDay) && (fetchLastDeployedMonth == georgianMonth)) {

var getDeployedChannelName = dashboardStatus.getName();
var deploymentScript = ‘import ‘ + ‘”‘ + $(‘Eai_qa_path’) + getScriptDate + ‘/’ + getDeployedChannelName + ‘.xml’ + ‘”‘ + ‘ force’;
var processedScript = deploymentScript.replace(/\//g, “\\”);

scriptBuilder.append(processedScript);
scriptBuilder.append(“\n”);

}

FileUtil.write(“C:/Labs/POC/Import_Export/test.txt”, false, scriptBuilder);
logger.debug(scriptBuilder);
}

Put this code in the javascript listener and make it to run for 24 hours. (i.e) for every 24 hours one import script will be generated based on the channels that were developed and tested today

Happy Automating!!!!

Blog at WordPress.com.

Up ↑