Top Banner
Shamil Nizamov Unofficial Mirth Connect v3.2 Developer’s Guide* * - Preview Version
27

Unofficial Mirth Connect v3 Developer's Guide

Jul 21, 2016

Download

Documents

Alex Ahmetov

This is a preview version. The full version is available at - http://mirthconnect.shamilpublishing.com This book introduces readers to version 3.x of Mirth Connect to the point that they are confident enough to start building their own healthcare data exchange interfaces. By implementing an imaginary Eligibility Query Service, this book covers some of the topics on XML schema and Schematron validation, XSL Transformation, database connection pool creation, acknowledgements implementation, Mirth Connect extensions implementation and sending objects via the ActiveMQ Message Broker.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Unofficial Mirth Connect v3 Developer's Guide

Shamil Nizamov

Unofficial Mirth Connect v3.2

Developer’s Guide*

* - Preview Version

Page 2: Unofficial Mirth Connect v3 Developer's Guide

Introduction 2

Copyright Page

Copyright © 2013-2015 by Shamil Nizamov

Cover image copyright © 2013 by Shamil Nizamov

All rights reserved. No part of the contents of this book may be reproduced or

transmitted in any form or by any means without the written permission of the author.

Mirth Connect is a trademark of Mirth Corporation. HL7 and Health Level Seven are

registered trademarks of Health Level Seven International. All other marks are property

of their respective owners.

Any rights not expressly granted herein are reserved.

The companies, organizations, products, domain names, email addresses, logos, people,

places, and/or data mentioned herein in examples are fictitious. No association with any

real company, organization, product, domain name, email address, logo, person, place,

or data is intended or should be inferred.

This book expresses the author’s views and opinions. The information contained in this

book is provided without any express, statutory, or implied warranties. The author, Mirth

Corporation, Health Level Seven International, resellers and distributors will NOT be held

liable for any damages caused or alleged to be caused either directly or indirectly by this

book.

This is a preview version of the book.

Page 3: Unofficial Mirth Connect v3 Developer's Guide

3 Introduction

Contents

PART 1 MIRTH CONNECT BASICS

Chapter 1 Getting Started ................................................................................................................. 15

Installation ........................................................................................................................ 15

Mirth Connect Administrator ........................................................................................... 16

Chapter 2 What is a Channel? ........................................................................................................... 18

Connectors ........................................................................................................................ 19

Filters ................................................................................................................................ 19

Transformers ..................................................................................................................... 20

Scripts................................................................................................................................ 21

Chapter 3 Creating a Channel ........................................................................................................... 23

Source Connector ............................................................................................................. 24

TMP, MSG and MESSAGE .................................................................................................. 25

Destination Connectors .................................................................................................... 27

Testing the Channel .......................................................................................................... 31

Global Map, Global Channel Map, Channel Map ............................................................. 34

Global Scripts .................................................................................................................... 36

Code Templates ................................................................................................................ 38

PART II GENERIC ELIGIBILITY SERVICE IMPLEMENTATION

Chapter 4 Generic Eligibility Service Introduction ........................................................................... 41

Eligibility Service Introduction .......................................................................................... 41

Scenario Overview ............................................................................................................ 42

Messages and Interactions Overview ............................................................................... 43

Eligibility Query Channels Overview ................................................................................. 44

Chapter 5 Query Sender Channel ..................................................................................................... 47

Summary Tab .................................................................................................................... 47

Source Connector ............................................................................................................. 49

Destinations Connector ................................................................................................... 49

Channel Implementation Verification .............................................................................. 53

Chapter 6 HL7v2 to HL7v3 Transformer Channel ............................................................................. 55

Page 4: Unofficial Mirth Connect v3 Developer's Guide

Introduction 4

Summary Tab .................................................................................................................... 55

Source Connector ............................................................................................................. 56

Destinations Connector ................................................................................................... 58

Code Templates ................................................................................................................ 64

Scripts................................................................................................................................ 65

Channel Implementation Verification .............................................................................. 66

Chapter 7 Data Logger Channel ........................................................................................................ 67

Summary Tab .................................................................................................................... 67

Source Connector ............................................................................................................. 68

Destinations Connector ................................................................................................... 69

Code Templates ................................................................................................................ 74

Global Scripts .................................................................................................................... 74

Channel Implementation Verification .............................................................................. 76

Chapter 8 HL7v3 Verification Channel .............................................................................................. 78

Summary Tab .................................................................................................................... 79

Source Connector ............................................................................................................. 79

Destinations Connector ................................................................................................... 82

Code Templates ................................................................................................................ 88

Global Scripts .................................................................................................................... 89

Scripts................................................................................................................................ 91

Channel Implementation Verification .............................................................................. 91

Chapter 9 Response Sender Channel ................................................................................................ 93

Summary Tab .................................................................................................................... 93

Source Connector ............................................................................................................. 94

Destinations Connector ................................................................................................... 96

Scripts................................................................................................................................ 99

Channel Implementation Verification ............................................................................ 100

Chapter 10 HL7v3 to HL7v2 Transformer Channel .......................................................................... 102

Summary Tab .................................................................................................................. 102

Source Connector ........................................................................................................... 103

Destinations Connector ................................................................................................. 103

Channel Implementation Verification ............................................................................ 106

Page 5: Unofficial Mirth Connect v3 Developer's Guide

5 Introduction

PART III ACKNOWLEDGEMENTS IMPLEMENTATION

Chapter 11 Acknowledgements Introduction .................................................................................. 109

Scenario Overview .......................................................................................................... 109

Acknowledgement Channels Overview .......................................................................... 110

Chapter 12 HL7v3 ACK Channel ........................................................................................................ 112

Summary Tab .................................................................................................................. 112

Source Connector ........................................................................................................... 113

Destinations Connector ................................................................................................. 113

Scripts.............................................................................................................................. 114

Chapter 13 HL7v3 Verification ACK Channel .................................................................................... 116

Destinations Connector ................................................................................................. 116

Code Templates .............................................................................................................. 119

Scripts.............................................................................................................................. 120

Source Connector ........................................................................................................... 121

Chapter 14 HL7v2 to HL7v3 Transformer ACK Channel .................................................................. 122

Destinations Connector ................................................................................................. 122

Code Templates .............................................................................................................. 125

Scripts.............................................................................................................................. 126

Source Connector ........................................................................................................... 127

Channel Implementation Verification ............................................................................ 128

Chapter 15 Query Sender ACK Channel ........................................................................................... 129

Destinations Connector ................................................................................................. 129

Source Connector ........................................................................................................... 131

Channel Implementation Verification ............................................................................ 133

PART IV ADVANCING IN MIRTH CONNECT

Chapter 16 Debugging JavaScript in Mirth Connect ........................................................................ 135

Built in Logger function .................................................................................................. 135

Rhino JavaScript Debugger in Standalone Mode ............................................................ 136

Rhino JavaScript Debugger in Embedded Mode............................................................. 137

Eclipse JSDT Debugger in Embedded Mode ................................................................... 142

Console Input .................................................................................................................. 145

Page 6: Unofficial Mirth Connect v3 Developer's Guide

Introduction 6

Chapter 17 Utilizing JMS (Java Message Service) ............................................................................ 147

Scenario Overview .......................................................................................................... 148

Sending Messages ........................................................................................................... 149

Sending Objects .............................................................................................................. 156

Channels Implementation Verification ........................................................................... 162

Chapter 18 Polling Web Services ..................................................................................................... 164

Scenario Overview .......................................................................................................... 164

Summary Tab .................................................................................................................. 165

Source Connector ........................................................................................................... 165

Destinations Connector ................................................................................................. 166

Channels Implementation Verification ........................................................................... 171

Chapter 19 Building Extensions ....................................................................................................... 173

Creating Templates ......................................................................................................... 175

Signing Extension ............................................................................................................ 180

Deploying Extension ....................................................................................................... 181

Extension Implementation Verification .......................................................................... 183

Book Resources ........................................................................................................................................ 186

PART V APPENDICES

A: Eligibility Query Request (QUCR_IN200101) Template .............................................. 188

B: Eligibility Query Results (QUCR_IN210101) Template ............................................... 189

C: MS Access Log Database Structure ............................................................................. 190

D: PostgreSQL Eligibility Database Structure .................................................................. 190

E: XSLT to transform from HL7v3 to HL7v2 ..................................................................... 191

F: JavaScriptTask.java ...................................................................................................... 193

G: Archives Content ........................................................................................................ 195

Page 7: Unofficial Mirth Connect v3 Developer's Guide

7 Introduction

This page is intentionally left blank

Page 8: Unofficial Mirth Connect v3 Developer's Guide

Introduction 8

Introduction

Introduction As Mirth Corporation says on their web-site, “Mirth Connect is the Swiss Army knife of

healthcare integration engines, specifically designed for HL7 message integration. It

provides the necessary tools for developing, testing, deploying, and monitoring interfaces.

And because it’s open source, you get all of the advantages of a large community of users

with commercial quality support.”

In addition, “The 2014 HL7 Interface Technology Survey Results” show that Mirth Connect

is one of the fastest growing healthcare messaging platforms due to its open source

paradigm, and robust functionality for HL7 messaging and X12 documents. Mirth

Connect also speeds up the development of interfaces for data exchange across different

formats and diverse healthcare systems environment.

This book describes version 3.x of Mirth Connect to the point that reader are confident

enough to start building their own healthcare data exchange interfaces and transforming

various versions of HL7 messages.

As you read this book, you will be implementing a fictitious Eligibility Query Service. Each

connection point (channel) is explained in a separate chapter, which in turn provides

step-by-step instructions on how to create and code data transformation rules.

This book is written using Mirth Connect 3.2.1.7650 version of the product.

Consequently, other releases may include new features, or features used in this book

may change or disappear. You may also notice some differences between screen shots

provided in the book and those you see when using Mirth Connect.

Who is this book for?

I wrote this book primarily for application developers and system integrators who have

found the online Mirth Connect documentation lacking and needed a guidebook that

explains things in a more detailed and organized way.

In a book of this size, I cannot cover every feature that Mirth Connect v3.x or previous

versions have; consequently, I assume you already have some familiarity with Mirth

Connect.

Page 9: Unofficial Mirth Connect v3 Developer's Guide

9 Introduction

Assumption

This book assumes that you are dealing with applications that use message-oriented

middleware products and expects that you have at least a minimal understanding of

Web service technologies including, but not limited to, XML, XML Schemas, XPath, XSL

Transformation and SOAP/WSDL.

Before you start reading this book, you should have a basic knowledge of JavaScript and

Java; MS Access and PostgreSQL databases from a database administrator perspective;

and are familiarity with operating system environment variables settings.

You should also have basic knowledge of HL7, the standard that is being used to

exchange healthcare data, both version 2 and version 3.

Who should not read this book?

As mentioned earlier, the purpose of this book is to provide the reader with a high-level

overview of the capabilities and features associated with Mirth Connect v3.2. This book is

not intended to be a step-by-step comprehensive guide or substitute of any kind to

original training and certification programs provided by Mirth Corporation (Quality

Systems, Inc.).

This book is also not a tutorial on a specific messaging or middleware technology

implementation. All examples included in this book are for illustrative purposes only. If

you are interested in learning more about a specific technology or product, please refer

to one of the many on-line resources.

This book does not cover any specific installation, configuration, deployment or

monitoring activities for system administrators.

Errata and Book Support

I have made every effort to ensure the accuracy of this book and its companion content.

If you find an error, please report through email - [email protected]

Warning and Disclaimer

The purpose of this book is to educate and entertain. Every effort has been made to

make this book as complete and as accurate as possible, but no warranty or fitness is

implied.

Page 10: Unofficial Mirth Connect v3 Developer's Guide

Introduction 10

The information is provided on an “as is” basis. The author shall have neither liability nor

responsibility to any person or entity with respect to any loss or damage caused, or

alleged to be caused, directly or indirectly by the information contained in this book or

from the use of software mentioned in this book. The information, methods and

techniques described by the author are based on his own experience. They may not work

for you and no recommendation is made to follow the same course of action. No

representation is made that following the advice in this book will work in your case.

The author is not an employee or representative of Mirth Corporation and never has

been, and author’s views and opinions are not necessarily those of Mirth Corporation.

This book is not based on trainings or certifications provided by Mirth Corporation.

This book contains links to third-party websites that are not under the control of the

author, and the author is not responsible for the content of any linked site. If you access

a third-party website mentioned in this book, then you do so at your own risk. The

author provides these links only as a convenience, and the inclusion of the link does not

imply that the author endorses or accepts any responsibility for the content of those

third-party sites.

Furthermore, this book contains information on the subject only up to the published

date.

Acknowledgements

Like most books, this guide has been a long time in the making. I would like to

acknowledge everyone who has assisted in this project. I could not have done this

without you.

Nathan Blakley and Elliot Freedman volunteered to review early versions of a few

chapters. Your feedback helped steer me in the right direction. I’d like to thank Philip

Helger in making an active contribution to the development of the open source

Schematron validator.

My biggest thanks go to Wayne Zafft and David Sanders, who were incredibly gracious

with their time and effort in reviewing the final version of the book.

Page 11: Unofficial Mirth Connect v3 Developer's Guide

11 Introduction

Roadmap

This book is divided into four parts:

Part 1 provides an introduction to Mirth Connect and a high-level overview of channels.

Chapter 1, Getting Started

Introduces Mirth Connect at a high level, and demonstrates how to download and

install Mirth Connect Server and Administrator.

Chapter 2, What is a Channel

Provides an overview of the channel architecture implemented in Mirth Connect. It

also covers a channel’s major components such as connectors, filters, transformers

and scripts.

Chapter 3, Creating a Channel

Walks the reader through the creation and configuration of a simple channel. It

covers some of the major points of the Mirth Connect channels implementation

model such as tmp and msg variables, different types of maps and their visibilities. It

also covers Global Scripts, channel scripts and Code Templates.

Part 2 focuses on the implementation of an imaginary but complete eligibility service.

Chapter 4, Generic Eligibility Service Introduction

Introduces the Eligibility Service as defined in the HL7v3 Normative Edition, presents

the implementation plan and walks through the required components.

Chapter 5, Query Sender Channel

Walks the reader through the implementation of the first channel in a chain that

serves as an interface to send HL7v2 Eligibility Query messages.

Chapter 6, HL7v2-HL7v3 Transformer Channel

Explains the implementation of a channel that plays the role of a conduit or broker.

The chapter shows how to establish a MLLP connection to other channels, how to

filter messages based on some criteria and transform messages from one format to

another using different techniques that Mirth Connect provides.

Chapter 7, Data Logger Channel

Page 12: Unofficial Mirth Connect v3 Developer's Guide

Introduction 12

Explains the implementation of a channel that uses a file and MS Access database as

destinations.

Chapter 8, HL7v3 Verification Channel

Walks the reader through the implementation of the XML Schema and Schematron

validators using external Java classes.

Chapter 9, Response Sender Channel

Provides insight into implementation of a database-facing channel that retrieves

data, forms the message and passes it along using a SOAP connector.

Chapter 10, HL7v3 to HL7v2 Transformer Channel

Concludes the implementation of the Eligibility service and provides a detailed

explanation on configuring the SOAP connector and XSL Transformation.

Part 3 is dedicated to the implementation of acknowledgements.

Chapter 11, Acknowledgements Introduction

Provides introduction and presents the implementation plan of a message

acknowledgement based on the Eligibility Service implemented in Part 2.

Chapter 12, HL7v3 ACK Channel

Explains how to create another interim channel that receives routed HL7v3 messages

and stores them in a file.

Chapter 13, HL7v3 Verification ACK Channel

Explains how to expand functionalities of the already existing channel to send HL7v3

MCCI acknowledgements.

Chapter 14, HL7v2 to HL7v3 Transformer ACK Channel

Explains how to expand functionalities of the already existing channel to send HL7v2

RSP^E45 acknowledgements back and intercept HL7v3 acknowledgements received

from other channels.

Chapter 15, Query Sender ACK Channel

Explains how to intercept HL7v2 acknowledgements received from one channel and

route them to another channel.

Page 13: Unofficial Mirth Connect v3 Developer's Guide

13 Introduction

Part 4 covers advanced topics.

Chapter 16, Debugging JavaScript in Mirth Connect

Provides an in-depth explanation of such important topics as debugging filters and

transformers JavaScript using built-in and external tools such as Rhino JavaScript

Debugger and Eclipse JSDT Debugger.

Chapter 17, Utilizing JMS (Java Message Service)

Introduces the JMS Sender and Listener connector configurations to pass messages

and objects through a Message Broker such as Apache ActiveMQ. Provides insight

into passing messages, and gives a detailed explanation of serialization /

deserialization techniques to pass Java objects via the Message Broker.

Chapter 18, Polling Web Services

Explains how to extend the functionality of the Web Server Sender connector to

periodically poll data from external service providers.

Chapter 19, Building Extensions

Provides an in-depth explanation of such confused topic as building the Mirth

Connect extension using the example of building a JSON Writer Destination

Connector.

Page 14: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 14

PART I – MIRTH CONNECT BASICS

Mirth Connect Basics

CHAPTER 1 Getting Started

CHAPTER 2 What is a Channel?

CHAPTER 3 Creating a Channel

Page 15: Unofficial Mirth Connect v3 Developer's Guide

15 PART I – MIRTH CONNECT BASICS

CHAPTER 1 Getting Started

Getting Started his chapter outlines the Mirth Connect basic installation procedure. All examples in

this book are based on the Windows version of Mirth Connect v3.2, available to

download at - http://www.mirthcorp.com/community/downloads

Make sure your computer meets minimum system requirements before you start:

Oracle JRE version 1.7 or higher;

1 GB of RAM is recommended;

A web browser.

Installation

There are two possible ways to install Mirth Connect based on what package you have

downloaded or what package is available on the website. In one case, the package is an

archive of all files and classes that you need to run Mirth Connect on your computer. You

simply unzip and copy the package to an appropriate folder, for example to the

C:\Program Files\Mirth Connect\. In the other case, there is a GUI based installer

that you just start and go through the steps in the installation wizard. The installation

process itself is quite straight forward.

In both cases what is installed are Mirth Connect Server, Mirth Connect Server Manager,

Mirth Connect Administrator and Mirth Connect Command Line Interface. During the

installation you have to decide which port will be used by the Mirth Connect Server. By

default it is 8080 for unsecure communication and 8443 for the SSL connection. You can

change it later using the Mirth Connect Server Manager.

To verify the installation:

Launch the Mirth Connect Server either through the Mirth Connect Server Manager

or the Mirth Connect Command Line;

Open the web browser and type localhost:8080 in the address bar;

Click the Access Secure Site button in Web Dashboard Sign In launch page;

Type admin for the user name and repeat admin as the password, click Sign in.

If you see the Dashboard statistics page with, most likely, no channels available, you have

successfully done the installation and ready to continue. If not, refer to Mirth Connect 3.0

T

Page 16: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 16

User Guide written by “the same Mirth technical experts who developed the software”

available at - http://info.mirth.com/Connect_Documentation_Download.html

Configuration

The Mirth Connect Server Manager can be used as a single point to launch Mirth

Connect Service, configure ports, allocated memories, and database connections.

However, a fully-fledged configuration description is beyond the scope of this book.

Here is only a recommended step is to add a path to the \custom-lib folder to the

operating system’s CLASSPATH environment variable. This is the folder where you put

your Java classes, libraries and other required files.

Versions 1 and 2 of Mirth Connect were using port 1099 for viewing statistics though the

JMX (Java Management Extensions) and RMI (Remote Method Invocation) interfaces.

This port is no longer used in version 3.x. Hence, if any of your applications or firewall is

utilizing ports 8080 or 8443 you can either change Mirth’s ports using Mirth Connect

Server Manager or manually modify the configuration file located in

\conf\mirth.properties. Don’t forget to restart the Mirth Connect Server or Service for

any changes to make effect.

Mirth Connect Administrator

The Mirth Connect Administrator is a Java application that is not explicitly installed on a

local computer by default in a distributed environment. It is downloaded from the Mirth

Connect Server. The reason for this is to ensure the Mirth Connect Administrator

matches version of the Mirth Connect Server.

To download the Mirth Connect Administrator:

Start Mirth Connect Server if it is not already running as a service;

Open the web browser;

Type localhost:8080 in the address bar;

Click Launch Mirth Connect Administrator in the Mirth Connect Administrator launch

page;

Click Ok to open the webstart.jnlp;

Type admin for the user name and repeat admin as the password in the Mirth

Connect Login pop-up window, then click Login.

If everything is done correctly, each time you login, you will see the Dashboard as the

initial screen. The Dashboard displays two information panels:

Page 17: Unofficial Mirth Connect v3 Developer's Guide

17 PART I – MIRTH CONNECT BASICS

Channels status and statistics - the number of messages Received, Filtered,

Queued, Sent, and Errored. The Dashboard Tasks area on the navigation bar on the

left side has menu items essential for developing channels such as Refresh, Send

Messages, and Remove All Messages. Same menu items can be accessed faster by

right clicking on a channel row.

Logs – Server Log, Connection Log and Global Maps. The Server Log is used a lot to

debug channels development. Double-clicking on a Server Log entry brings a pop-up

window where you can view and copy the entire log entry content. The Server Log is

stored by Mirth Connect Server in the database and therefore closing and opening

the Mirth Connect Administrator brings back all entries not previously explicitly

purged. To clear the Server Log click Clear Displayed Log under the Server Log or

Connection Log area.

Logging Level

Channel’s log level can be configured manually by changing \conf\log4j.properties

entries. Available options are: ERROR, WARN, INFO, DEBUG, and TRACE with DEBUG

selected by default. Log levels may be configured separately for filters, transformers,

postprocessors and other scripts that are explained later in this book.

FIGURE 1-1 Mirth Connect Administrator window by default

Familiarize yourself with other navigation items and tabs since this is the main tool used

to develop channels throughout this book.

Page 18: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 18

CHAPTER 2 What is a Channel?

What is a Channel? he Channel is an essential part of Mirth Connect and can be seen as one-to-many

abstract unidirectional pipes to decouple components from each other to transfer

healthcare data between two or more applications. The channel architecture

implemented in Mirth Connect can divide a large message processing task into a

sequence of smaller independent steps. This affords developers the flexibility for

dependency, maintenance and/or performance. Some of the processing tasks can even

be external to Mirth Connect and developed independently.

FIGURE 2-1 Mirth Connect abstract channel architecture

In general, each channel consists of inbound and outbound Connectors, Filters and

Transformers. The connector that receives inbound messages from the Sending

Application is called the Source. Similarly, the connector that sends outbound messages

is called the Destination. From the Source connector data is passed through the channel,

where filters and transformers perform operations on the data, for example, routing a

message to one or another Destination connector and transforming the data

representation. Deciding channel’s tasks is when wearing an analyst's hat comes into

play.

Before you create a new channel, you need to elicit the following requirements:

Type of Application the channel reads data from (Source connector type);

Type of Application the channel sends data to (Destination connector type);

Type and format of the inbound message;

Type and format of the outbound message(s);

T

Page 19: Unofficial Mirth Connect v3 Developer's Guide

19 PART I – MIRTH CONNECT BASICS

Mapping table(s) between inbound and outbound messages (Transformation).

Connectors

In terms of Enterprise Integration, the connector is a Message Endpoint that specifies a

particular way or, more accurately, a particular protocol Mirth Connect should use to

communicate with an external application or another Mirth Connect channel.

Mirth Connect supports sending and receiving messages over a variety of connectors

listed here in no particular order:

TCP/MLLP;

Database (MySQL, PostgreSQL, Oracle, Microsoft SQL Server, ODBC);

File (local file system and network shares);

PDF and RTF documents;

JMS;

HTTP (note that HTTPS is not supported in the free version);

SMTP;

SOAP (over HTTP).

The connector that receives the data is called a Reader, for example the MLLP Reader.

The connector that sends the data is called a Writer, the Database Writer is an example.

Connector types are configured under the Source and Destinations tabs of the channel,

which is explained later in this chapter. As should be obvious, some settings are common

across all connectors while others are unique to a specific connector type.

If you need a connector that is not shipped with the Mirth Connect installation package,

you can develop your own one (such as a custom HTTPS connector). Some templates

and developer’s level documentation for such development are in the chapter dedicated

to Mirth extensions.

Filters

In a real world scenario, when numerous applications and channels are connected, a

channel may receive messages from several sources and these messages may have to be

processed differently, based on the message type or other criteria.

There are two paradigms for solving this problem, a Router and a Filter:

Page 20: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 20

Router connects to multiple outbound channels. The key benefit of the Router is that

the decision criteria for the destination(s) of a message are maintained in a single

location.

Filter, this is what Mirth Connect uses, is built into a message processing mechanism

and is responsible for determining whether the message should be processed or not.

The Filter inspects message properties (segments or elements) without removing the

message from the message queue. If the message cannot be consumed by this

particular pipe, it is returned to the queue unchanged for another pipe to filter or

process.

Filters can be as simple as specific elements comparison against a hard coded value or as

complex as JavaScript scripts and external Java classes. Filters can also be omitted

allowing all messages to pass through. Some routing capabilities have been introduced

in Mirth Connect v3.1 by using a "destinationSet". If a destination is removed from the

destination set, this destination will not receive the message.

If a single channel needs to process more than one type of messages, you can create any

number of separate pipes – Destinations - and specify none, one or more filters for each

of them.

Transformers

More often than not, messages are sent between legacy systems, custom applications

and third-party solutions, each of which is built around a proprietary data model. Even

systems that claim to support a single standard may place specific requirements on data

format and content. If we could bring all legacy systems to a single format when a new

business requirement is proposed, we would avoid conversion issues. Unfortunately, for

most legacy systems, data format, content or data sequence changes are difficult and

risky, and simply not feasible.

How do we communicate data using different formats then? In Mirth Connect this is

done by a message Transformer that translates one data format into another. As a result,

a destination application expects to receive messages it understands which can be

processed and stored in the application’s internal data format.

Mirth Connect allows message translation to occur at different levels, and to chain

message transformers to achieve a required result.

Supported transformers are:

Page 21: Unofficial Mirth Connect v3 Developer's Guide

21 PART I – MIRTH CONNECT BASICS

Message Builder maps segments of the inbound message to segments in the

outbound message.

Mapper maps segments of the inbound message to internal Mirth Connect variables.

These variables may be used later.

External Script, as the name suggests, employs external JavaScripts to transform or

map the data.

XSLT Step utilizes the XSL transformation.

JavaScript, along with External Script, is where flexibility comes into play. Here any

type of (Rhino) Java Script and Java code can be used.

Scripts

Channels also support unique features called Scripts to enhance the message processing

logic. Scripts apply to a channel itself and all messages that are passing through.

These scripts are:

Deploy script is executed each time Mirth Connect Server starts or a channel is

redeployed. This is the best place to initialize variables or create class objects.

Attachment script deals with a message in a native format and allows extracting a

part of the message to store as an attachment or to irrevocably modify a message.

Preprocessor script also allows handling each message in a native format before

Mirth Connect starts translating it into the internal format, which is XML.

Filter & Transformer scripts are the main places where you handle the inbound and

outbound messages.

Response script, as the name suggests, handles the response sent by a destination.

Postprocessor script is executed after the message has been successfully sent.

Undeploy script is launched each time Mirth Connect Server stops. This is the place

to, for example, release memory that was allocated for the classes used by the

channel.

Scripts are performed in the following order:

1. Global Deploy script;

2. Deploy;

3. Attachment script;

4. Global Preprocessor script;

5. Preprocessor script;

6. Source connector Filters script;

7. Source connector Transformer script or mapping;

8. Destination 1 connector Filters script;

Page 22: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 22

9. Destination 1 connector Transformer script or mapping;

10. Destination N connector Filters script;

11. Destination N connector Transformer script or mapping;

12. Response 1 Transformer script or mapping;

13. Response N transformer script or mapping;

14. Postprocessor script;

15. Global Postprocessor script;

16. Undeploy;

17. Global Undeploy script.

Deploy and Undeploy scripts are performed only once, when a channel is deployed or

undeployed, respectively. It is important to note that Global Deploy and Deploy scripts

are also executed every time any channel is redeployed. Same with Undeploy and Global

Undeploy scripts, they are executed for every channel. All other scripts are performed

every time a message is sent through a channel or an acknowledgement is received.

Notice that the Global Preprocessor script is executed before the channel’s Preprocessor

script is executed. Similarly, after the channel’s Postprocessor script completes, the

Global Postprocessor script is run.

If channels operate in series, the Attachment Script of the first channel is the first to

perform. The Postprocessor Script of the same channel will be executed last, after all

other scripts in all consequent channels. (see Figure 2-2)

FIGURE 2-2 Scripts execution sequence

Next, we will explore each of these steps in detail.

Page 23: Unofficial Mirth Connect v3 Developer's Guide

23 PART I – MIRTH CONNECT BASICS

This is a preview edition of the book.

The complete version is available to download at

http://mirthconnect.shamilpublishing.com

Page 24: Unofficial Mirth Connect v3 Developer's Guide

PART I – MIRTH CONNECT BASICS 24

Book Resources

Book Resources Other titles you may be interested in:

Unofficial Developer's Guide to CCD on Mirth

Connect

This book introduces readers to version 3.x of Mirth

Connect to the point that they are confident enough

to start building their own healthcare data exchange

interfaces.

By implementing an imaginary CCD Builder Server,

this book covers topics on XSL Transformation,

acknowledgements implementation, XML schema and

Schematron validation. Each connection point

(channels and destinations) is explained in a separate

chapter, which in turn provides step-by-step

instructions on how to create and code data

transformation rules for ADT and ORU messages.

The book is available to download at –

http://ccdonmirth.shamilpublishing.com

Unofficial Developer's Guide to HL7v3 Basics

This book introduces readers to HL7 version 3 to the

point that they are confident enough to start building

their own healthcare data exchange interfaces. The

book provides clear and easy to use, step-by-step

guidance for learning the standard, with numerous

examples covering many topics.

This book may be interesting for those implementing

the Clinical Document Architecture (CDA) or HL7

Reference Information Model (aka RIM) based

solutions.

The book is available to download at –

http://hl7basics.shamilpublishing.com

Page 25: Unofficial Mirth Connect v3 Developer's Guide

APPENDICES

Appendices

A: Eligibility Query Request (QUCR_IN200101) Template

B: Eligibility Query Results (QUCR_IN210101) Template

C: MS Access Log Database Structure

D: PostgreSQL Eligibility Database Structure

E: XSLT to transform from HL7v3 to HL7v2

F: JavaScriptTask.java

G: Archives Content

There are five archives provided with this book each of which contains a complete set of

files required for Part II, Part III and Part IV implementations.

Eligibility.NoACK

Folder Files Comment

Channels Code Template.xml

Data Logger.xml

Global Script.xml

HL7v3 Verification.xml

Query Sender.xml

Response Sender.xml

v2-v3 Transformater.xml

v3-v2 Transformater.xml

Channels, code templates and

global scripts for Part II

implementation.

custom-lib /coreschemas

/schemas

/schematron

Custom-lib folder for Mirth Connect

Server installation.

DB PostgreSQL-Eligibility DB.sql

QBP_Log.accdb

PostgreSQL patients database

MS Access Log database

HL7v2\Samples QBP_E22_Request.hl7

RSP_E22_Error.hl7

RSP_E22_Success.hl7

HL7v2\Templates RSP-45_Template.hl7

HL7v2\XSLT QUCR-RSP.xslt

HL7v3 <intentionally skipped> Schemas for HL7v3 messages

HL7v3\-

Samples_Annotated

QUCR_IN200101UV01_Request_Annotated.xml

QUCR_IN210101UV01_Error_Annoteated.xml

Annotated Eligibility query response

and request messages

Page 26: Unofficial Mirth Connect v3 Developer's Guide

APPENDICES 26

QUCR_IN210101UV01_Success_Annotated.xml

HL7v3\Templates QUCR_IN200101_Template.xml

QUCR_IN210101_Template.xml

Eligibility query response and

request template messages with

empty fields

Eligibility.ACK-NACK

Folder Files Comment

Channels Code Template ACK.xml

Data Logger.xml

Global Script.xml

HL7v3 ACK.xml

HL7v3 Verification-ACK.xml

Query Sender ACK.xml

v2-v3 Transformer-ACK.xml

Channels, code templates and

global scripts for Part III

implementation.

custom-lib /coreschemas

/schemas

/schematron

Custom-lib folder for Mirth Connect

Server installation.

DB PostgreSQL-Eligibility DB.sql

QBP_Log.accdb

PostgreSQL patients database

MS Access Log database

HL7v2\Samples ACK-A01_Negative.hl7

ACK-A01_Positive.hl7

HL7v2 acknowledgement samples

HL7v3 <intentionally skipped> Schemas for HL7v3 messages

HL7v3\Samples MCCI_IN000002UV01.xml HL7v3 acknowledgement sample

HL7v3\-

Samples_Annotated

MCCI_IN000002UV01-Annotated.xml

HL7v2 acknowledgement sample

with annotations

HL7v3\Templates MCCI_IN000002_template.xml HL7v2 acknowledgement template

with empty fields

Eligibility.JMS

Folder Files Comment

Channels Code Template.xml

Data Logger JMS.xml

Data Logger RAW.xml

HL7v3 Verification JMS.xml

HL7v3 Verification RAW.xml

Query Sender JMS.xml

v2-v3 Transformer JMS.xml

v2-v3 Transformer RAW.xml

Channels, code templates and

global scripts for Part IV

implementation.

custom-lib faultmessage.jar Custom-lib folder for Mirth Connect

Server installation.

Debugging

Folder Files Comment

JSDT JavaScriptTask.java

Eclipse JSDT debugger in

embedded mode.

Page 27: Unofficial Mirth Connect v3 Developer's Guide

27 APPENDICES

Rhino Debugger JavaScriptTask.java Rhino JavaScript debugger in

embedded mode.

Polling.zip

Folder Files Comment

Channels Web Service Polling.xml Polling channel for Chapter 19

Extension.JSON

Folder Files Comment

Deploy json/lib/org-json.jar

json/destination.xml

json/json-client.jar

json/json-server.jar

json/json-shared.jar

JSON Writer destination connector

deployment package

jarsigner signjar.bat Batch file with command prompts

to sign JARs

Source\Client JSONWriter.java Client side extension template

Source\Server destination.xml

JSONDispatcher.java

JSONDispatcherProperties.java

JSONWriterService.java

Server side extension templates

Source\org.json JSONArray.java

JSONException.java

JSONObject.java

JSONString.java

JSONStringer.java

JSONTokener.java

JSONWriter.java

XML.java

XMLTokener.java

XML to JSON library source code