• 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:

  • 相关阅读:
    html中的块级元素、行内元素
    ptyhon_opencv 图像的基本操作
    正则表达式总结 2017.1.6
    HashMap 中的 entrySet()使用方法 2016.12.28
    (转)Redis持久化的几种方式
    负数与二进制换转方法
    (转)2019JAVA面试题附答案(长期更新)
    Java后端技术面试汇总(第一套)
    (转)Dubbo服务暴露过程源码分析
    Dubbo消费方服务调用过程源码分析
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1769377.html
Copyright © 2020-2023  润新知