zoukankan      html  css  js  c++  java
  • Converting HL7 to XML

    Introduction

    For those of us unfortunate enough to have to deal with it, HL7 is a commonly encountered language used by medical systems to communicate with each other. It is what someone dreamed up way back when before XML was invented. Indeed, the most recent version of HL7 is XML. However, for those of us that still have to use older systems, it's an unwieldy and unfriendly language to deal with; message components are delimited using carriage returns, pipe symbols, tildes, and ampersands.

    Since most applications use XML for data exchange, and XML is much nicer to deal with anyway, it would be helpful if there were an HL7 to XML conversion library that was freely available. Sadly, despite scouring the web, I have not found a (free) class or utility that can easily be integrated into applications. There are a few Java libraries, and one well known (excellent) commercial application, but nothing free and easy to use.

    This article is v1 of my attempt at creating such a library. Please feel free to use and extend it - and most importantly, fix any bugs I've missed.

     

    Using the code

    A very simple HL7 message looks something like this:

    MSH|^~\&|||||20080925161613||ADT^A05||P|2.6

    This class and method simply produces an XML representation of the same message. Note that this class isn't nearly clever enough to know what type of HL7 message it is converting - it merely creates an XML version of it. The point is that you can then use XPath to retrieve the segment you want to use since you know its location. The HL7 above returned by this method would look like this:

    <HL7Message>
        <MSH>
            <MSH.0>MSH</MSH.0>
            <MSH.1>^~\&amp;</MSH.1>
            <MSH.2/>
            <MSH.3/>
            <MSH.4/>
            <MSH.5/>
            <MSH.6>20080925161613</MSH.6>
            <MSH.7/>
            <MSH.8>
                <MSH.8.0>ADT</MSH.8.0>
                <MSH.8.1>A05</MSH.8.1>
            </MSH.8>
            <MSH.9/>
            <MSH.10>P</MSH.10>
            <MSH.11>2.6</MSH.11>
        </MSH>
    </HL7Message>

    It's a static class which returns an XML string (as a string; it could easily be modified to return an XmlDocument instead).

     

    Using the class

    string sHL7asXml = HL7ToXmlConverter.ConvertToXml(myHL7string);

    The full class looks like this:

  • 相关阅读:
    bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
    bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛【二分+贪心】
    bzoj 3401: [Usaco2009 Mar]Look Up 仰望【单调栈】
    bzoj 1652: [Usaco2006 Feb]Treats for the Cows【区间dp】
    bzoj 1718: [Usaco2006 Jan] Redundant Paths 分离的路径【tarjan】
    bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店【高精度+完全背包】
    洛谷 P3121 [USACO15FEB]审查(黄金)Censoring (Gold) 【AC自动机+栈】
    bzoj 3942: [Usaco2015 Feb]Censoring【kmp+栈】
    bzoj 1578: [Usaco2009 Feb]Stock Market 股票市场【背包】
    性能优化一大推
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1769377.html
Copyright © 2011-2022 走看看