From: James A. <ja...@ja...> - 2014-07-22 01:49:14
|
Hi Ian, I was able to recreate this, and it's a bug all right. I'll put a fix in, but I was able to work around it in the current version of HAPI by using a newly created parser that had validation disabled. The following snippet (which is kind of weird but does demonstrate a workaround..) works for me: ADT_AXX msg = new ADT_AXX(); String message = "MSH|^~\\&|NES|NINTENDO|AGNEW|CORNERCUBICLE|20010101000000||ADT^A01|Q123456789T123456789X123456|P|2.3\r\n" + "PID|2||123456789|0123456789^AA^^JP|BROS^MARIO^^^^||19850101000000|M|||123 FAKE STREET^MARIO \\T\\ LUIGI BROS PLACE^TOADSTOOL KINGDOM^NES^A1B2C3^JP^HOME^^1234|1234|(555)555-0123^HOME^JP:1234567|||S|MSH|12345678|||||||0|||||N\r\n" ; msg.parse(message); msg.addNonstandardSegment("ZZZ"); GenericSegment zzz = (GenericSegment) msg.get("ZZZ"); zzz.parse("ZZZ|1|2"); DefaultHapiContext ctx = new DefaultHapiContext(); ctx.setValidationContext(new ValidationContextImpl()); String out = ctx.getPipeParser().encode(msg); ourLog.info(out); Cheers, James On Mon, Jul 21, 2014 at 7:37 PM, Ian Vowles <Ian...@he...> wrote: > In the current transformation I am working on I thought I would try using > the ADT_AXX superstructure, since multiple ADT types need to be handled. > Some complexity was present, given that the inbound has several > Z-Segments, which I have built definitions for, and the outbound has one of > a different structure to the inbounds. > > Snippets from the code dealing with them are shown below. The hl7In > mentioned is of ADT_AXX type. > > ADT_AXX hl7Out = new ADT_AXX(); > hl7Out.setValidationContext(new NoValidation()); > ZPX zpxIn = new ZPX(hl7In.getParent(), > hl7In.getModelClassFactory()); > ZVX zvxIn = new ZVX(hl7In.getParent(), > hl7In.getModelClassFactory()); > GenericSegment zSeg; > try { > zSeg = (GenericSegment) hl7In.getINSURANCE().get("ZPX"); > zpxIn.parse(zSeg.encode()); > } catch (HL7Exception ex) { > // Problem finding zpx leave it empty > } > try { > zSeg = (GenericSegment) hl7In.getINSURANCE().get("ZVX"); > zvxIn.parse(zSeg.encode()); > } catch (HL7Exception ex) { > // Problem finding zvx, leave it empty > } > > hl7Out.addNonstandardSegment("ZPD"); > GenericSegment zpdGen = (GenericSegment) hl7Out.get("ZPD"); > ZpdEdis zpdOut = new ZpdEdis(hl7Out.getParent(), > hl7Out.getModelClassFactory()); > SegmentTranslation.processZpd(zpxIn, hl7In.getPV1(), zvxIn, > zpdOut); > zpdGen.parse(zpdOut.encode()); > > All of this works very nicely, and all was proceeding through test cases > for different message types with me reviewing the content of a > .printstructure(). > I got a nasty surprise when I finally came to .encode() the result: > > java.lang.NullPointerException > at > java.util.Collections$UnmodifiableCollection.<init>(Collections.java:994) > at > java.util.Collections$UnmodifiableSet.<init>(Collections.java:1066) > at java.util.Collections.unmodifiableSet(Collections.java:1056) > at > ca.uhn.hl7v2.model.AbstractSuperMessage.getStructuresWhichChildAppliesTo(AbstractSuperMessage.java:78) > at > ca.uhn.hl7v2.validation.builder.support.OnlyAllowableSegmentsInSuperstructureRule.checkStructure(OnlyAllowableSegmentsInSuperstructureRule.java:71) > at > ca.uhn.hl7v2.validation.builder.support.OnlyAllowableSegmentsInSuperstructureRule.apply(OnlyAllowableSegmentsInSuperstructureRule.java:55) > at > ca.uhn.hl7v2.validation.builder.support.OnlyAllowableSegmentsInSuperstructureRule.apply(OnlyAllowableSegmentsInSuperstructureRule.java:46) > at > ca.uhn.hl7v2.validation.AbstractValidator.testMessageRules(AbstractValidator.java:98) > at > ca.uhn.hl7v2.validation.AbstractValidator.validate(AbstractValidator.java:82) > at > ca.uhn.hl7v2.parser.Parser.assertMessageValidates(Parser.java:611) > at ca.uhn.hl7v2.parser.Parser.encode(Parser.java:275) > at ca.uhn.hl7v2.parser.PipeParser.encode(PipeParser.java:1003) > at > ca.uhn.hl7v2.model.AbstractMessage.encode(AbstractMessage.java:207) > at > au.gov.qld.health.sit.transform.hl7.HbcisNormAdtTxEdisTest.testTransformA01(HbcisNormAdtTxEdisTest.java:81) > > Doing a .setValidationContext(new NoVAlidation) on the result message does > not prevent the error. > > Is there anything I can do to enable this result to .encode()? The > prinstructure() shows everything exactly as I want it. > > Thanks > Ian > > > ******************************************************************************** > 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. > > ********************************************************************************** > > > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Hl7api-devel mailing list > Hl7...@li... > https://lists.sourceforge.net/lists/listinfo/hl7api-devel > |