Thank you Ian. It's working with a few rearrangements of the classes.
From: Ian Vowles [mailto:[email protected]]
Sent: Tuesday, December 22, 2015 3:16 PM
To: [email protected]
Subject: Re: [HAPI-devel] Custom Model Classes
Following up on the example of our ORMIS message I posted earlier, I added an
implementation called ORM_Q01. Code basically exactly the same as the ORU_R01
posted earlier (see below)
I then added a test case to our test class (see further below), and
successfully got an implementation of the custom message.
As noted before, the package structure is critical, the message, group and
segment packages must have all the relevant bits set up to make this strategy
work. Any shortcuts are likely to cause problems.
Hope this helps
Ian
---- The ORM_Q01 message, which extends our custom ORU---
package au.gov.qld.health.sit.hl7.ormis.message;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.parser.ModelClassFactory;
/**
* Enable HAPI to generate an ORU^R01 message implementation of ORMIS_ORU
* based on the values of MSH-9-1 and MSH-9-2.
*/
public class ORM_Q01 extends ORMIS_ORU {
public ORM_Q01(ModelClassFactory factory) throws HL7Exception {
super(factory);
}
}
--- The test case which gets our ORU custom implementation in one test, and the
new ORM_Q01 as another example ---
package au.gov.qld.health.sit.hl7.ormis;
import au.gov.qld.health.sit.hl7.ormis.message.ORU_R01;
import au.gov.qld.health.sit.hl7.ormis.message.ORM_Q01;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Varies;
import ca.uhn.hl7v2.parser.CustomModelClassFactory;
import ca.uhn.hl7v2.parser.GenericParser;
import ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class CustomMessageParseTest {
private static final HapiContext HAPI_CONTEXT = createHapiContext();
private static final String MSH_FOR_ORU_R01 =
"MSH|^~\\&|MSH-3|MSH-4|MSH-5.1^MSH-5.2|MSH-6|20130605000036|MSH-8|ORU^R01|MSH-10|P|2.3|MSH-13|MSH-14|MSH-15|MSH-16|MSH-17|MSH-18|MSH-19";
private static final String MSH_FOR_ORM_Q01 =
"MSH|^~\\&|MSH-3|MSH-4|MSH-5.1^MSH-5.2|MSH-6|20130605000036|MSH-8|ORM^Q01|MSH-10|P|2.3|MSH-13|MSH-14|MSH-15|MSH-16|MSH-17|MSH-18|MSH-19";
@Test
public void testParseCustomORU_R01Message() throws HL7Exception {
Message message = new
GenericParser(HAPI_CONTEXT).parse(MSH_FOR_ORU_R01);
assertTrue("Parse custom ORU_R01 message", message instanceof ORU_R01);
}
@Test
public void testParseCustomORU_Q01Message() throws HL7Exception {
Message message = new
GenericParser(HAPI_CONTEXT).parse(MSH_FOR_ORM_Q01);
assertTrue("Parse custom ORU_Q01 message", message instanceof ORM_Q01);
}
private static HapiContext createHapiContext() {
System.setProperty(Varies.DEFAULT_OBX2_TYPE_PROP, "ST");
System.setProperty(Varies.INVALID_OBX2_TYPE_PROP, "ST");
HapiContext hapiContext = new DefaultHapiContext();
Map<String, String[]> hl7VersionPackageNamesMap = new HashMap<String,
String[]>();
String[] packageNames = {"ca.uhn.hl7v2.model.v24",
"au.gov.qld.health.sit.hl7.ormis"};
hl7VersionPackageNamesMap.put("2.3", packageNames);
hl7VersionPackageNamesMap.put("2.3.1", packageNames);
hl7VersionPackageNamesMap.put("2.4", packageNames);
hapiContext.setModelClassFactory(new
CustomModelClassFactory(hl7VersionPackageNamesMap));
hapiContext.setValidationRuleBuilder(new NoValidationBuilder());
return hapiContext;
}
}
From: Davies, Brian [mailto:[email protected]]
Sent: Wednesday, 23 December 2015 1:39 AM
To:
[email protected]<mailto:[email protected]>
Subject: Re: [HAPI-devel] Custom Model Classes
Forgot to include the exception:
RDS_R06is called!!!!!!!
Exception in thread "main" java.lang.ClassCastException:
ca.uhn.hl7v2.model.GenericSegment cannot be cast to
com.mckn.mms.lds.hl7.zxx.custommodel.v25.group.PFG
at
com.mckn.mms.lds.hl7.zxx.custommodelv25.message.RDS_R06.getPFG(RDS_R06.java:67)
at
com.mpls.lds.hl7.zxx.custommodel.v25.message.TestMessageCreation.testParseCustomRDS_R06Message(TestMessageCreation.java:46)
at
com.mpls.lds.hl7.zxx.custommodel.v25.message.TestMessageCreation.main(TestMessageCreation.java:88)
From: Davies, Brian [mailto:[email protected]]
Sent: Tuesday, December 22, 2015 9:36 AM
To:
[email protected]<mailto:[email protected]>
Subject: [HAPI-devel] Custom Model Classes
Hi All,
It seems to me that the custom model classes simply do not recognize the
AbstractGroup types even when one tries to forcefully load the group from the
custom model. I think Christian is absolutely right that the eventmap is the
solution known to work for this issue. The problem for me however is that that
solution seems rather extreme. Unfortunately, the message type I am trying to
create is not a standard type.
Here is a case in point. The code snippet below is actually in a package
xxx.xxx.<version>.<type> but it seems only the eventmap is able to recognize
all types
package com.mckn.mms.lds.hl7.zxx.custommodel.v25.group
public class PFG extends AbstractGroup {
private static final long serialVersionUID = -5950843839679571210L;
public PFG(Group parent, ModelClassFactory factory) {
super(parent, factory);
try {
init();
} catch (HL7Exception e) {
log.error("Unexpected error creating PFG.", e);
}
}
......
package com.mckn.mms.lds.hl7.zxx.custommodel.v25.group
public PFG getPFG(){
//An attempt to load
ModelClassFactory cfm = new CustomModelClassFactory(
"com.mckn.mms.lds.hl7.zxx.custommodel");
Class c=null;
try {
c = cfm.getTypeClass("PFG", "2.5");
} catch (HL7Exception e) {
return null;
}
return (PFG)super.getTyped("PFG", c);
}
I have tried all the recommendations so far, except for the eventmap solution,
but with no success. Unfortunately, there is not enough information showing an
instance of creating a completely new message type implementation from scratch.
Has anyone got a working solution to this problem?
********************************************************************************
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.
**********************************************************************************
------------------------------------------------------------------------------
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel