简体   繁体   中英

How do i access the information in an hl7 message parsed with nHapi

I am learning how to use nHapi. As many have pointed out, there's not much documentation. Following this doc I've been able to parse a message using the library. But I can't figure out how to access that message using an object model (which is what I really want nHapi to do). Essentially, I want to take an HL7 message as a string and access it using the object model, in the same way that LINQ to SQL takes a database record and lets you access it as an object. I found Parsing an HL7 without a priori messageType knowledge , but it seems to be about something else because the code in the post returns a string instead of an HL7 object (like I need). In the documentation I linked to above they seem to access the parts of a message using a "query"--but I can't find the materials to query IMessages in the library.

Here is the code I'm using, with a line showing what I want to do...

Imports NHapi.Base Imports NHapi.Base.Parser Imports NHapi.Base.Model

Module Module1

Sub Main()

    Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3|QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
    Dim myPipeParser As PipeParser = New PipeParser()
    Dim myImsg As IMessage = myPipeParser.Parse(msg)
    Dim msgType As String = myImsg.GetStructureName
    Dim mySendingFacilityName As String = myImsg.getSendingFacility()  //this is what I want

End Sub

Remember with HL7 messages that each segment has to end with a line return.

Also, you'll want to parse the message back to its actual type in order for the object model to be fully populated correctly (notice that when I used myPipeParser.Parse it was cast back to a QRY_R02 message type from the NHapi.Model.V23 Library). So the code should look something like this:

Imports NHapi.Model.V23.Message
Imports NHapi.Base.Parser
Imports NHapi.Base
Module Module1

Sub Main()
    Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3" & vbNewLine & _
    "QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
    Dim myPipeParser As PipeParser = New PipeParser()
    Dim myImsg As QRY_R02 = myPipeParser.Parse(msg)
    Dim msgType As String = myImsg.GetStructureName
    Dim mySendingFacilityName As String = myImsg.MSH.SendingFacility.NamespaceID.Value
    Console.WriteLine(mySendingFacilityName)
    Console.ReadLine()

End Sub

End Module

I know it was a very long time ago, however I was looking for this resource very recently and found that there is nearly no documentation on how to use this API. And excellent source of examples can be found in the test part of source code in the project NHapi.NUnit. Sources can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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