Here are more details. I have a web service that carries HL7 - XML
formatted messaged in payload, I need to extract that XML String
Palyload, parse it with XML parser, convert into ER7 format and set back
into payload of webservice response object.
I tried printing of original Payload and I can see the whitespaces in
payload.
protected HialEnvelopeType TransformToER7(HialEnvelopeType LabResults)
throws HL7Exception, java.lang.Exception
{
String encodedMessage = null;
String payload = null;
Message ER7Msg = null;
payload = LabResults.getMessageControl().getPayload();
XMLParser parseXML = new DefaultXMLParser();
parseXML.setValidationContext(getValidation());
PipeParser pipeParser = new PipeParser();
pipeParser.setValidationContext(getNoValidation());
ER7Msg = parseXML.parse(payload);
ER7Msg.setValidationContext(getValidation());
encodedMessage = pipeParser.encode(ER7Msg);
LabResults.getMessageControl().setPayload(encodedMessage);
return LabResults;
}
public NoValidation getValidation (){
NoValidation noValidation = new NoValidation();
Iterator iter =
noValidation.getPrimitiveRuleBindings().listIterator();
while(iter.hasNext()){
RuleBinding rule = (RuleBinding)iter.next();
iter.remove();
}
return noValidation;
}
________________________________
From: Cameron Freiner [mailto:[email protected]]
Sent: Wednesday, May 06, 2009 9:41 AM
To: Qaiser, Mohammed
Cc: Lynch, David
Subject: Re: [HAPI-devel] XML to ER7 conversion using pipeParser.encode
That should have done it.. Can you send me a bit more info, sample of
xmlString, etc.. ? Perhaps a simple class, unit test that demonstrates
exactly what you are trying to do and how it fails?
On Wed, May 6, 2009 at 10:31 AM, Qaiser, Mohammed
<[email protected]> wrote:
Hi Cameron,
Thanks for your response, I tried changing code as follow but did not
help with PipeParser.encode, However MyValidation trick helped me with
PipeParser.parser but do not have any effect on PipeParser.encode. In
below code, I called a method getMyValidation() in
setValidationContext, which instantiate NoValidation and remove all the
rule from it before setting it into setValidationContext.
XMLParser parseXML = new DefaultXMLParser();
parseXML.setValidationContext(getMyValidation());
PipeParser pipeParser = new PipeParser();
pipeParser.setValidationContext(getMyValidation());
Message ER7Msg = parseXML.parse(XMLString);
ER7Msg.setValidationContext(getMyValidation());
encodedMessage = pipeParser.encode(ER7Msg );
public NoValidation getMyValidation(){
NoValidation noValidation = new NoValidation();
Iterator iter =
noValidation.getPrimitiveRuleBindings().listIterator();
while(iter.hasNext()){
RuleBinding rule = (RuleBinding)iter.next();
iter.remove();
}
return noValidation;
}
________________________________
From: Cameron Freiner [mailto:[email protected]]
Sent: Wednesday, May 06, 2009 9:19 AM
To: Qaiser, Mohammed
Cc: [email protected]
Subject: Re: [HAPI-devel] XML to ER7 conversion using pipeParser.encode
In your NoValidation Validation Context there are the following lines..
ca.uhn.hl7v2.validation.Rule trim = new TrimLeadingWhitespace();
getPrimitiveRuleBindings().add(new RuleBinding("*", "FT",
trim));
getPrimitiveRuleBindings().add(new RuleBinding("*", "ST",
trim));
getPrimitiveRuleBindings().add(new RuleBinding("*", "TX",
trim));
you need to create a new ValidationContext that implements
ValidationContextImpl for your projects that doesn't trim the data types
you don't want trimmed..
public class MyValidation extends ValidationContextImpl
{
public MyValidation()
{
}
}
And change your code to ..
XMLParser parseXML = new DefaultXMLParser();
parseXML.setValidationContext(
new MyValidation());
PipeParser pipeParser = new PipeParser();
pipeParser.setValidationContext(new NoValidation());
Message ER7Msg = parseXML.parse(XMLString);
ER7Msg.setValidationContext(new MyValidation());
encodedMessage = pipeParser.encode(ER7Msg );
This should fix your problem..
On Wed, May 6, 2009 at 9:43 AM, mq_cgi <[email protected]> wrote:
Hi There,
I am trying to convert HL7 - XML message to HL7 - ER7 format. However
after
conversion all whitespace are getting trimed off, which is part of the
original XML message. In source code below, PipeParser.encode(ER7Msg) is
the
one who is triming all whitespaces. Is there a way I can still retain
all
whitespace in encodedMessage?
XMLParser parseXML = new DefaultXMLParser();
parseXML.setValidationContext(new NoValidation());
PipeParser pipeParser = new PipeParser();
pipeParser.setValidationContext(new NoValidation());
Message ER7Msg = parseXML.parse(XMLString);
ER7Msg.setValidationContext(new NoValidation());
encodedMessage = pipeParser.encode(ER7Msg );
--
View this message in context:
http://www.nabble.com/XML-to-ER7-conversion-using-pipeParser.encode-tp23
399607p23399607.html
Sent from the hl7api-devel mailing list archive at Nabble.com.
------------------------------------------------------------------------
------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks
to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel