Our team at Queensland Health in Australia is growing, and our usage of this incredibly helpful API grows with it.
As we have delved deeper into the usage of HAPI listener applications we have structured our set of custom messages to try to facilitate a couple of the features we are implementing. Recently we have encountered a circumstance where we would appreciate some clarification. When we build a custom message we try to 'uplift' the definition to version 2.4 regardless of what the vendor message says it uses. In an effort to have a HAPI listener 'automagically' pick up our implementations we use code as shown in the example below. Please excuse the fact that I have pasted the text of the code, our mail gateway does not much like us trying to send out .zip files that contain code. The example has tests that can be made to fail or succeed based upon the dependency libraries you configure. We would like to reach a point where including 'unused' dependencies can be avoided, (the ca.uhn.hl7v2.model.231 set in this example), and wonder if there is a feature we have overlooked that enables this. We would also like to understand when using the packageNames = {"ca.uhn.hl7v2.model.v24", "hapi.test"} seen in the code below, if a definition of a message "ADT_A01" exists in both libraries why it is we have to put our definitions last to get them to be picked up. Code follows: Custom message definition (much cut down just for this example): package hapi.test.message; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.AbstractMessage; import ca.uhn.hl7v2.model.v24.segment.MSH; import ca.uhn.hl7v2.parser.DefaultModelClassFactory; import ca.uhn.hl7v2.parser.ModelClassFactory; public class ADT_A01 extends AbstractMessage { private static final ModelClassFactory DEFAULT_MODEL_CLASS_FACTORY = new DefaultModelClassFactory(); public ADT_A01() throws HL7Exception { this(DEFAULT_MODEL_CLASS_FACTORY); } public ADT_A01(ModelClassFactory modelClassFactory) throws HL7Exception { super(modelClassFactory); this.addSegments(); } private void addSegments() throws HL7Exception { Class<MSH> addMsh = MSH.class; this.add(addMsh, true, false); } public MSH getMSH() throws HL7Exception { return (MSH) get("MSH"); } } Demonstration of success/failure with these tests: package hapi.test; import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.Varies; import ca.uhn.hl7v2.model.v24.message.ACK; import ca.uhn.hl7v2.parser.CustomModelClassFactory; import ca.uhn.hl7v2.parser.GenericParser; import ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder; import hapi.test.message.ADT_A01; import org.junit.Test; import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertTrue; public class ADT_A01Test { private static final HapiContext HAPI_CONTEXT = createHapiContext(); private static final String ADT_A01_HL7_EXPLICIT = "MSH|^~\\&|ABCD|123|||20150101000000||ADT^A01^ADT_A01|1234|P|2.3.1\r"; private static final String ADT_A01_HL7_IMPLICIT = "MSH|^~\\&|ABCD|123|||20150101000000||ADT^A01|1234|P|2.3.1\r"; private static CustomModelClassFactory getCustomModelClassFactory() { Map<String, String[]> hl7VersionPackageNamesMap = new HashMap<String, String[]>(); String[] packageNames = {"ca.uhn.hl7v2.model.v24", "hapi.test"}; hl7VersionPackageNamesMap.put("2.3", packageNames); hl7VersionPackageNamesMap.put("2.3.1", packageNames); hl7VersionPackageNamesMap.put("2.4", packageNames); return new CustomModelClassFactory(hl7VersionPackageNamesMap); } private static HapiContext createHapiContext() { System.setProperty(Varies.DEFAULT_OBX2_TYPE_PROP, "ST"); System.setProperty(Varies.INVALID_OBX2_TYPE_PROP, "ST"); HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setModelClassFactory(getCustomModelClassFactory()); hapiContext.setValidationRuleBuilder(new NoValidationBuilder()); hapiContext.getParserConfiguration().setAllowUnknownVersions(true); return hapiContext; } /** * This test passes without hapi-structures-v231 as a project dependency. * * @throws Exception */ @Test public void testHAPICanParseExplicitADT_A01() throws Exception { GenericParser genericParser = new GenericParser(HAPI_CONTEXT); Message adt_a01 = genericParser.parse(ADT_A01_HL7_EXPLICIT); assertTrue("HAPI parsed HL7 to custom ADT_A01 message", adt_a01 instanceof ADT_A01); Message ack = adt_a01.generateACK(); assertTrue("Custom ADT_A01 message generates a v24 ACK", ack instanceof ACK); } /** * This test will only pass with hapi-structures-v231 as a project dependency. * <p/> * ca.uhn.hl7v2.HL7Exception: No map found for version V231. Only the following are available: [V24] * <p/> * Uncomment the hapi-structures-v231 dependency in build.gradle to fix this unit test. * * @throws Exception */ @Test public void testHAPICanParseImplicitADT_A01() throws Exception { GenericParser genericParser = new GenericParser(HAPI_CONTEXT); Message adt_a01 = genericParser.parse(ADT_A01_HL7_IMPLICIT); assertTrue("HAPI parsed HL7 to custom ADT_A01 message", adt_a01 instanceof ADT_A01); Message ack = adt_a01.generateACK(); assertTrue("Custom ADT_A01 message generates a v24 ACK", ack instanceof ACK); } } Build.gradle showing dependencies, with comments on changes to change the results. apply plugin: 'java' sourceCompatibility = 1.5 targetCompatibility = 1.5 repositories { mavenCentral() } dependencies { def hapiVersion = '2.2' compile 'ca.uhn.hapi:hapi-base:' + hapiVersion compile 'ca.uhn.hapi:hapi-structures-v24:' + hapiVersion // Uncommenting the following line fixes the testHAPICanParseImplicitADT_A01 unit test //compile 'ca.uhn.hapi:hapi-structures-v231:' + hapiVersion testCompile 'junit:junit:4.+' } Thanks for your help, and thanks again for the API. We have recently tried out the FHIR 1.0 library at a FHIR connectathon, and found we were not alone in using it, and that it saved us a lot of time getting underway. Ian Vowles Senior Systems Integrator Department of Health Queensland Australia ******************************************************************************** This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error. Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters. If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender by telephone collect on Australia +61 1800 198 175 or by return email. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced. If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited. Although Queensland Health takes all reasonable steps to ensure this email does not contain malicious software, Queensland Health does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email. Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government. ********************************************************************************** ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Hl7api-devel mailing list Hl7api-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hl7api-devel