Hi,

you need a pipe after the 2.6 and separate the segments with \r. This works:

        public static void main(String[] args) {
                String msg =
"MSH|^~\\&|HUB||server||201010172015||ACK^W01^ACK|1234|P|2.6|\r"
                                + "MSA|AA|2468|\n";

                Parser p = new GenericParser();

                Message hapiMsg;
                try {
                        // The parse method performs the actual parsing
                        hapiMsg = p.parse(msg);
                } catch (EncodingNotSupportedException e) {
                        e.printStackTrace();
                        return;
                } catch (HL7Exception e) {
                        e.printStackTrace();
                        return;
                }
        }

=>

04.11.2010 09:31:59 ca.uhn.log.HapiLogImpl info
INFO: Instantiating msg of class ca.uhn.hl7v2.model.v26.message.ACK


regards
Christian



William Smith-12 wrote:
> 
> I have troubles to parse a string with HAPI (*HL7 v2.6*).
> 
> This is my code:
> 
> 
> public static void main(String[] args) {
>         String msg = "MSH|^~
> \\&|HUB||server||201010172015||ACK^W01^ACK|1234|P|2.6<cr>"
>                 + "MSA|AA|2468|<cr>";
> 
>          Parser p = new GenericParser();
> 
>         Message hapiMsg;
>         try {
>             // The parse method performs the actual parsing
>             hapiMsg = p.parse(msg);
>         } catch (EncodingNotSupportedException e) {
>             e.printStackTrace();
>             return;
>         } catch (HL7Exception e) {
>             e.printStackTrace();
>             return;
>         }
> 
> It throws a HL7Exception.
> 
> ------------------------------------------------------------------------------
> Achieve Improved Network Security with IP and DNS Reputation.
> Defend against bad network traffic, including botnets, malware, 
> phishing sites, and compromised hosts - saving your company time, 
> money, and embarrassment.   Learn More! 
> http://p.sf.net/sfu/hpdev2dev-nov
> _______________________________________________
> Hl7api-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hl7api-devel
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Parse-a-simple-message-HL7-v2.6-tp30125416p30129902.html
Sent from the hl7api-devel mailing list archive at Nabble.com.


------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to