Custom adaptations on standard HL7 messages with NHapi

It just occurred to me that I need to revisit a post I've written back in 2010. In this post I solved a problem with a HL7 implementation by downloading the NHapi source and edit it.

Recently I posted a solution on implementing Z segtments (custom segments). Of course, implementing a custom message and register it to the NHapi parser is the way to do this. Changing the source (and creating a custom build of NHapi) will require you to do this over and over when implementing newer versions of NHapi. By custom implementing the message, there is no need to.

It's easy. Let's take the problem of the original 2010 post. This is a small change in the PID segment of the HL7 version 2.3 implementation. Now do the following:

Add a directory, for example named "Custom", to you solution. This directory will also be the namespace of the custom implementations. Later we will register the namespace so the parser will be able to find it. The custom implementations need to follow the structure of the NHapi HL7 version assemblies. So custom segments need to be in a Segment directory and custom messages need to go in a Message directory.

Get you hands on the NHapi source (here) and copy the PID.cs class from the version 2.3 project of NHapi to the sub-dir "Segment" in the directory "Custom". Change the namespace of the class to the namespace of your solution/project: namespace YourProject.Custom.Segment. Of course by adding a version in the namespace you will be able to implement different classes for different versions.

Change the PID.cs class according to the solution provided in the 2010 post. So change the line:

this.add(typeof(CX), false, 1, 12, new System.Object[]{message}, "Alternate Patient ID");
this.add(typeof(CX), false, 10, 12, new System.Object[]{message}, "Alternate Patient ID");

Now that the custom implementations are added, this custom HL7 package needs to be registered to become known to the parser. In the application configuration you need to add this.

<?xml version="1.0"?>
        <section name="Hl7PackageCollection" type="NHapi.Base.Model.Configuration.HL7PackageConfigurationSection, NHapi.Base" />
        <HL7Package name="YourProject.Custom." version="2.3" />

This way you won't have any problems with future NHapi versions. And, of course, by changing the configuration you will be able to turn the custom implementation on or off depending on the production environment. This is a good practice then running the software in different environment.

Add comment

Security code

Share this post
FaceBook  Twitter  


Latest comments