简体   繁体   English

如何在C#.Net中将XML文件转换为HL7格式

[英]How to convert XML file to HL7 format in C# .Net

I am facing the problem while converting the XML data into HL7 format. 在将XML数据转换为HL7格式时遇到了问题。 I am using C# .Net. 我正在使用C#.Net。 I am generating the XML file but client is now expecting the data in HL7 format. 我正在生成XML文件,但是客户端现在希望使用HL7格式的数据。 I have tried a lot and seach on google but not much information is available 我已经尝试了很多次并在Google上搜索过,但没有太多可用信息

The same file as below . 与下面相同的文件。

 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<LifeCarePatientResult>
  <PatientSettings>
    <PatientSetting Name="Identity">
      <Value>11212</Value>
    </PatientSetting>
    <PatientSetting Name="FirstName">
      <Value></Value>
    </PatientSetting>
    <PatientSetting Name="LastName">
      <Value></Value>
    </PatientSetting>
  </PatientSettings>
  <Measurement Id="86351403-af11-4986-bb26-2d2efa77db8e">
    <DateTime>2017-10-24 16:00:09</DateTime>
    <NoValue>18</NoValue>
    <Mode>SixSecond</Mode>
    <Instrument>030700364</Instrument>
    <Firmware>1D1B1D03</Firmware>
    <LifeCarePanelVersion>1.1.0.32000</LifeCarePanelVersion>
    <Sensor>25691</Sensor>
    <SequenceNumber>620</SequenceNumber>
    <TemperatureWarning>false</TemperatureWarning>
    <HumidityWarning>false</HumidityWarning>
    <FailTotal>0</FailTotal>
    <FailAboveMax_A10>0</FailAboveMax_A10>
    <FailBelowMin_A11>0</FailBelowMin_A11>
    <FailTooLongCount_A12>0</FailTooLongCount_A12>
    <FailDuringAnalysisCount_A13>0</FailDuringAnalysisCount_A13>
    <FailOther>0</FailOther>
  </Measurement>
</LifeCarePatientResult>

As pointed out in the comments and the alternative question, the 100% .net way is to use nhapi. 正如评论和替代问题中指出的那样,100%.net方法是使用nhapi。 But for the amount of effort you would be looking at, you really should be looking at an HL7 Tool. 但是,如果您要花费大量的精力,则实际上应该使用HL7工具。 They are comparatively cheap, and will save you huge amounts of time. 它们相对便宜,将为您节省大量时间。

Here is how to do it in HL7 Soup . 这是在HL7汤中做的方法 It allows you to write .net code as part of the transformation, but you'll see that you probably won't need to. 它允许您编写.net代码作为转换的一部分,但是您会发现您可能不需要这样做。

The first thing you need is an HL7 message that will be your target. 您需要的第一件事是将成为目标的HL7消息。 Your client can probably provide this, but for the sake of demonstration, here is a simplified one from the HL7 Soup Samples. 您的客户可能可以提供这一点,但是为了演示起见,这里是HL7汤样的简化版。

MSH|^~\\&|HL7Soup|Instance1|HL7Soup|Instance2|20060922162830|L674-200609221628310220|ORU^R01|ORU000016168|P|2.5.1|||AL |AL PID||75675|1478895^4^M10^PA||XTEST^PATIENT^||19591123| F|||||||||||||||||||||| ORC|RE|F4334|51013174200601|||||^|||||||||||||||| OBR|1|F4334|51013174200601|80048^BASIC METABOLIC PANEL|||20060922152300||||||||^^^^^|023901^PACLAB| ||||||^|CH|F|^^|^^^20060922162659^^GHA||^|||^^^^^^ ^^^^|^^^^^^^^^^|^^^^^^^^^^|^^^^^^^^^^|||||||||| OBX|1|NM|84295^SODIUM^GH|1|145|mmol/L|||||F|||20060922152300|GH

Understanding this message is beyond the scope of this answer, but if you are unsure, google "HL7 Tutorial", there are some helpful videos out there. 了解此消息超出了此答案的范围,但是如果您不确定google“ HL7教程”,那么这里有一些有用的视频。 HL7 Soup is also excellent at explaining what the message means. HL7汤还擅长于解释该消息的含义。

Now that you have your Source and Destination messages, load HL7 Soup, and create a new receiver. 现在您已经有了Source和Destination消息,加载HL7 Soup,并创建一个新的接收者。

创建一个新的XML接收器

Then change the receiver type to a "directory scanner" 然后将接收器类型更改为“目录扫描器”

在此处输入图片说明

Now you just need to configure it to monitor a directory waiting for your xml file. 现在,您只需要配置它以监视等待xml文件的目录。 Notice that I have placed your xml file in as the inbound template. 请注意,我已将您的xml文件作为入站模板放置在其中。

在此处输入图片说明

Ok, so now we have configured the importation of the xml, we need to configure the outbound HL7 message. 好的,现在我们已经配置了xml的导入,我们需要配置出站HL7消息。 I'll output that as a file too. 我也将其输出为文件。

Add another activity to the workflow by clicking here. 单击此处将另一个活动添加到工作流中。

添加和新活动

Now change this activity to a File Writer. 现在,将此活动更改为File Writer。

将活动更改为文件编写器

Now we need to configure the File Writer activity to output the HL7 File. 现在我们需要配置File Writer活动以输出HL7 File。 I've set it to write a file with the name c:\\Temp\\HL7File.HL7 , then also requested that it is moved to a different directory once it is written - moving it ensures a unique filename. 我已将其设置为写入名称为c:\\Temp\\HL7File.HL7 ,然后还要求写入后将其移动到其他目录-移动它可确保文件名唯一。 I've also put in the HL7 message to use as a template at the bottom. 我还将HL7消息用作底部的模板。

HL7 File Writer配置

Now all we need to do is create a mapping between the XML and the HL7 messages. 现在,我们要做的就是在XML和HL7消息之间创建一个映射。 Click the Edit Transformer (yellow arrow) in the image above. 单击上图中的“编辑变压器”(黄色箭头)。

Here is what you get. 这就是你得到的。 Two trees representing the source message and the destination message. 两棵树分别代表源消息和目标消息。

XML到HL7变压器

Now all you need to do is drag the source items across to their corresponding destination items one at a time to create your mapping. 现在,您要做的就是一次将源项目拖到其对应的目标项目上,以创建映射。 This video explains it in a bit more detail - Transforming HL7 data , but ultimately you end up with a mapping between your source and destination messages. 该视频更详细地说明了它- 转换HL7数据 ,但最终您最终将在源消息和目标消息之间建立映射。

Here's three of the fields mapped as an example, but you would do it for every value you want to map across. 这里以映射的三个字段为例,但是您要对要映射的每个值执行此操作。 Notice how the mapping is just an xpath statement that points to the Source value and an HL7 path pointing to the Destination. 请注意,映射如何只是指向Source值的xpath语句和指向Destination的HL7路径。 You can manually edit these to make the xpath exactly what you need for your message, such as looking for the items by XML attribute name. 您可以手动编辑这些内容,以使xpath完全符合您的消息所需,例如,按XML属性名称查找项目。

XML到HL7的映射

Once you have completed all the mappings just save the workflow and return to the main HL7 Soup screen, then start your workflow running. 完成所有映射后,只需保存工作流程并返回HL7 Soup主屏幕,然后开始运行工作流程。

在此处输入图片说明

Now every file you drop into your directory will be converted to HL7 and dropped into your new directory. 现在,您放到目录中的每个文件都将转换为HL7并放到新目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM