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

2.4k Views Asked by At

I am facing the problem while converting the XML data into HL7 format. I am using C# .Net. I am generating the XML file but client is now expecting the data in HL7 format. I have tried a lot and seach on google but not much information is available

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>
1

There are 1 best solutions below

0
user2081514 On

As pointed out in the comments and the alternative question, the 100% .net way is to use nhapi. But for the amount of effort you would be looking at, you really should be looking at an HL7 Tool. They are comparatively cheap, and will save you huge amounts of time.

Here is how to do it in HL7 Soup. It allows you to write .net code as part of the transformation, but you'll see that you probably won't need to.

The first thing you need is an HL7 message that will be your target. Your client can probably provide this, but for the sake of demonstration, here is a simplified one from the HL7 Soup Samples.

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. HL7 Soup is also excellent at explaining what the message means.

Now that you have your Source and Destination messages, load HL7 Soup, and create a new receiver.

Create a new XML receiver

Then change the receiver type to a "directory scanner"

enter image description here

Now you just need to configure it to monitor a directory waiting for your xml file. Notice that I have placed your xml file in as the inbound template.

enter image description here

Ok, so now we have configured the importation of the xml, we need to configure the outbound HL7 message. I'll output that as a file too.

Add another activity to the workflow by clicking here.

Add and new activity

Now change this activity to a File Writer.

Change Activity to file writer

Now we need to configure the File Writer activity to output the 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. I've also put in the HL7 message to use as a template at the bottom.

HL7 File Writer config

Now all we need to do is create a mapping between the XML and the HL7 messages. 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 to HL7 Transformer

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.

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. 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.

XML to HL7 mappings

Once you have completed all the mappings just save the workflow and return to the main HL7 Soup screen, then start your workflow running.

enter image description here

Now every file you drop into your directory will be converted to HL7 and dropped into your new directory.