Share via


C# hL7 MESSAGE STRING

Question

Friday, December 12, 2014 1:20 PM

hi all
i create an app. to received HL7 message from blood test Device
i got a test like this

L|1|N
H|\&|||XP-300^00-10^^^^A3135^AP807129||||||||E1394-97
P|1
O|1||^^ 154216^A|^^^^WBC\^^^RBC\^^^HGB\^^^HCT\^^^MCV\^^^MCH\^^^MCHC\^^^PLT\^^^LYM%\^^^MXD%\^^^NEUT%\^^^LYM#\^^^MXD#\^^^NEUT#\^^^RDW-SD\^^^RDW-CV\^^^PDW\^^^MPV\^^^P-LCR\^^^PCT|||||||N||||||||||||||F
R|1|^^^^WBC^1| 12.1|10*3/uL||N|||| ||20141211055630
R|2|^^^^RBC^1| 4.53|10*6/uL||N|||| ||20141211055630
R|3|^^^^HGB^1| 13.8|g/dL||N|||| ||20141211055630
R|4|^^^^HCT^1| 39.5|%||N|||| ||20141211055630
R|5|^^^^MCV^1| 87.2|fL||N|||| ||20141211055630
R|6|^^^^MCH^1| 30.5|pg||N|||| ||20141211055630
R|7|^^^^MCHC^1| 34.9|g/dL||N|||| ||20141211055630
R|8|^^^^PLT^1| 459|10*3/uL||H|||| ||20141211055630
R|9|^^^^LYM%^1| 16.5|%||N|||| ||20141211055630
R|10|^^^^MXD%^1| 4.4|%||N|||| ||20141211055630
R|11|^^^^NEUT%^1| 79.1|%||N|||| ||20141211055630
R|12|^^^^LYM#^1| 2.0|10*3/uL||N|||| ||20141211055630
R|13|^^^^MXD#^1| 0.5|10*3/uL||N|||| ||20141211055630
R|14|^^^^NEUT#^1| 9.6|10*3/uL||N|||| ||20141211055630
R|15|^^^^RDW-SD^1| 44.7|fL||N|||| ||20141211055630
R|16|^^^^RDW-CV^1| 12.8|%||N|||| ||20141211055630
R|17|^^^^PDW^1| 10.4|fL||N|||| ||20141211055630
R|18|^^^^MPV^1| 8.8|fL||L|||| ||20141211055630
R|19|^^^^P-LCR^1| 16.1|%||N|||| ||20141211055630
R|20|^^^^PCT^1| 0.40|%||H|||| ||20141211055630

**i need to manage this message to insert each parameter in its filed in db (SQL server)
by useing c# > so any idea for this**

All replies (6)

Friday, December 12, 2014 1:39 PM ✅Answered

You might want to consider using a library to handle this.

I've used both NHapi in a variety of applications for parsing (and building) HL7 Messages. It's a .NET port of the HAPI project which basically does the same thing but was written in Java. The documentation leaves a bit to be desired, but if you dig around through the HAPI site and search a bit more online, you should find plenty of examples for reading your messages.

You can also use the HL7Lib class that is available on the open-source HL7 Analyst project found here. Just download the project, reference the HL7Lib.dll within your project and you should be able to parse a string into an HL7 message using just a single line :

HL7Lib.Base.Message hl7Message = new HL7Lib.Base.Message(yourHl7String);

Wednesday, December 17, 2014 9:09 PM ✅Answered

I'm not currently around a development machine to test it, but if memory serves after parsing an HL7 message, you should be able to drill down into all of the various components (e.g OBR, OBX, etc) and access individual fields or values similar to what appears to be a result value shown in your example.

I would recommend trying it out on a few example messages and drilling down into the result using the Visual Stufo debugger to see if you discover anything. I believe there's also a tool out there called HL7 Analyst that allows you to import HL7 messages and it'll populate all of the availabe fields (using this can make it easier in knowing where to look within your code).


Friday, December 12, 2014 1:35 PM

You can read the file line by line; next you can split the records on the pipe sign. I assume that anything before the line starting with R|1| is some kind of generic information (the lines starting with L, H, P and O). Once you have a record split, you can insert it into the database.

As your question is broad, I leave it with this. If you need more details, you need to be more specific. :-)


Friday, December 12, 2014 1:45 PM

And guess what; after posting I did some digging and found http://msdn.microsoft.com/en-us/library/ee409289.aspx ; might be a starting point.


Wednesday, December 17, 2014 6:28 PM

thanks for all your replays 

dear 

Rion

i can parse this message with HL7Lib is there any example . to get the value of parameter for example 

WBC=12.1 10*3/uL N

..

.

.

n

thanks for all again


Thursday, December 18, 2014 5:57 AM

Thanks again Dear Rion

i want to know how to get test parameter value from Hl7 segment component ......

can i get for example PLT from OBR or OBX or any other Hl7 component 

....looking forward to hear from you