Tuesday, February 12, 2008

HL7 v3.0 message handling.

Health Level 7 (http://www.hl7.org/) has released version 3.0 for quite a while back, and I have to work on its message handling and integration with health care applications. The new version completely focuses on XML based messages. The Normative Edition comes with a good load of xsds (XML Schema Definition); one for each message type and believe me there are tons of xsds. The message structure has got very much readable and easy to parse using any language which has good xml parser as compared to version 2.x.
The best approach which I can think of for now, is using the xsds do generate classes. I tried to use XSD.exe from the Visual Studio 2005 Tools, but I was unable to fix the reference types. The xsd.exe tool does not take into account the referenced schema definitions, and so I was not able to auto-generate class from those xsd, but when I get that done then I have no big headache. Once the classes are generated, we can just use XmlSerializer class to DeSerialize the xml-message directly to the class and then access the respective properties. Looks simple?

I tried the same trick within a test application which has "shiporder.xml" and "shiporder.xsd", these files were taken from w3c :)
http://www.w3schools.com/schema/schema_example.asp

I created the class using xsd.exe from VS.NET tools, which created "shiporder.cs" for me:
cmd>> xsd shiporder.xsd /c

Then I build a simple and sweet standalone application to test it.
//code c#
using System.IO;
using System.Xml.Serialization;
namespace XSDTest
{
class Program
{
static void Main(string[] args)
{
XmlSerializer serial = new XmlSerializer(typeof(shiporder)); // shiporder.cs
TextReader reader = new StreamReader("shiporder.xml");
shiporder so = (shiporder) serial.Deserialize(reader); // this is how you directly get the data back.
}
}
}
//end code

I hope I will be able to resolve the reference schemas in the HL7 xsds, and then build the classes out of it in near future, till then try out other possible methods :)

-Bugs

0 Comments:

Post a Comment

<< Home