I am supposed to convert HL7 message to XML format using NHApi in (C#, .net). I somehow understood this code which does the same using HApi in Java. I want the same code for NHApi in C#,.net
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.v22.message.ADT_A01;
import ca.uhn.hl7v2.model.v22.segment.MSH;
import ca.uhn.hl7v2.parser.EncodingNotSupportedException;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.XMLParser;
/**
public class ExampleParseMessages {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws HL7Exception {
String msg = "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01||P|2.2\r"
+ .......";
HapiContext context = new DefaultHapiContext();
Parser p = context.getGenericParser();
Message hapiMsg;
try{
hapiMsg=p.parse(msg);
}
catch(EncodingNotSupportedException e){
e.printStackTrace();
return;
}
catch(HL7Exception e){
e.printStackTrace();
return;
}
ADT_A01 adtMsg = (ADT_A01)hapiMsg;
MSH msh = adtMsg.getMSH();
String msgType = msh.getMessageType().getMessageType().getValue();
String msgTrigger=msh.getMessageType().getTriggerEvent().getValue();
System.out.println(msgType + " " + msgTrigger);
XMLParser parser = context.getXMLParser();
String encodedMessage =parser.encode(adtMsg);
System.out.println("Printing XML Encoded Message:");
System.out.println(encodedMessage);
}
}
I want to turn this code to NHAPI code in c#.net.
but cant find the replacement for the code snippet:XMLParser parser = context.getXMLParser();
String encodedMessage =parser.encode(adtMsg);
Please help.
Any help is appreciated.