[英]How do i access the information in an hl7 message parsed with nHapi
I am learning how to use nHapi. 我正在学习如何使用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).
但我无法弄清楚如何使用对象模型访问该消息(这是我真正想要的nHapi)。 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.
本质上,我想将HL7消息作为字符串并使用对象模型访问它,就像LINQ to SQL获取数据库记录并允许您作为对象访问它一样。 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).
我发现没有先验的messageType知识解析HL7 ,但它似乎是关于别的东西,因为帖子中的代码返回一个字符串而不是HL7对象(就像我需要的那样)。 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.
在我上面链接的文档中,他们似乎使用“查询”访问消息的各个部分 - 但我找不到在库中查询IMessages的材料。
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 进口NHapi.Base进口NHapi.Base.Parser进口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. 请记住HL7消息,每个段必须以换行结束。
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). 此外,您需要将消息解析回其实际类型,以便正确填充对象模型(请注意,当我使用myPipeParser.Parse时,它会从NHapi.Model转换回QRY_R02消息类型。 V23图书馆)。 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. 我知道这是很久以前的事了,不过我最近一直在寻找这个资源,并且发现几乎没有关于如何使用这个API的文档。 And excellent source of examples can be found in the test part of source code in the project NHapi.NUnit.
在项目NHapi.NUnit的源代码的测试部分中可以找到优秀的示例源。 Sources can be found here
来源可以在这里找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.