简体   繁体   English

NET的C#和nHapi验证HL7

[英]Validate HL7 with C# and nHapi for .NET

I'm looking to validate an HL7 2.3 standard message using C# and .NET version of nHapi project: 我正在使用nHapi项目的C#和.NET版本验证HL7 2.3标准消息:

https://github.com/duaneedwards/nHapi https://github.com/duaneedwards/nHapi

I've downloaded the dll's and added to my project both NHapi.Base.dll and NHapi.Model.V23.dll. 我已经下载了dll并将NHapi.Base.dll和NHapi.Model.V23.dll添加到我的项目中。

I know I should use: 我知道我应该使用:

NHapi.Base.validation.MessageValidator

But I can't figure out how IValidationContext theContext should be configured in order to check 2.3 version. 但是我不知道应该如何配置IValidationContext theContext以便检查2.3版本。

In addition, I can't find any appropriate API docs for it. 另外,我找不到适合它的任何API文档。

Can someone assist? 有人可以协助吗?

Methods to validate the message are embedded into the parser. 验证消息的方法嵌入到解析器中。 The Implementation of specific rules was intentionally left to implementers (to improve the flexibility). 具体规则的实施有意留给实施者(以提高灵活性)。 What you need to do is to create the new context: 您需要做的是创建新的上下文:

public class CustomContext : DefaultValidationContext //:IValidationContext
{
    //Define the rules and rule Bindings
}

public class Rule1 : IMessageRule
{
    //Check whatever you want in the fully parsed message
    //For example, check for the mandatory segment, groups cardinalities etc.
}

then 然后

PipeParser p = new PipeParser();
CustomContext myContext = new CustomContext();
p.ValidationContext = myContext;

This is a good starting point: NHapi Documentation 这是一个很好的起点: NHapi文档

Even I was looking for some solution to validate HL7 V2 messages using NHapi and could not find any good articles. 甚至我也在寻找某种使用NHapi验证HL7 V2消息的解决方案,但找不到任何好的文章。 So I decided to go through the NHapi object module to see any helpful information to validate the structure and I found something. 因此,我决定遍历NHapi对象模块以查看任何有用的信息以验证结构,并发现了一些东西。

The NHapi HL7 v2 IMessage is implemented using IType interface and it has a property called ExtraComponent . NHapi HL7 v2 IMessage是使用IType接口实现的,并且具有名为ExtraComponent的属性。 NHapi parser does not throw any exceptions on invalid structure but populates the ExtraComponent property. NHapi解析器不会在无效结构上引发任何异常,但会填充ExtraComponent属性。 So if you find ExtraComponent.numComponents() to be more than 0 then you have structural issues on the message. 因此,如果您发现ExtraComponent.numComponents()大于0,则消息上会出现结构性问题。

I have written a validator code in C#. 我已经用C#编写了验证器代码。 You can download it from github. 您可以从github下载它。

https://github.com/shivkumarhaldikar/NHapiValidatator https://github.com/shivkumarhaldikar/NHapiValidatator

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

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