1

我正在寻找使用 C# 和 .NET 版本的 nHapi 项目验证 HL7 2.3 标准消息:

https://github.com/duaneedwards/nHapi

我已经下载了 dll 并将 NHapi.Base.dll 和 NHapi.Model.V23.dll 添加到我的项目中。

我知道我应该使用:

NHapi.Base.validation.MessageValidator

但我不知道应该如何配置 IValidationContext theContext 以检查 2.3 版本。

此外,我找不到任何合适的 API 文档。

有人可以帮忙吗?

4

2 回答 2

1

验证消息的方法嵌入到解析器中。具体规则的实施有意留给实施者(以提高灵活性)。您需要做的是创建新的上下文:

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

然后

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

这是一个很好的起点:NHapi Documentation

于 2018-05-22T09:52:15.520 回答
0

Even I was looking for some solution to validate HL7 V2 messages using NHapi and could not find any good articles. So I decided to go through the NHapi object module to see any helpful information to validate the structure and I found something.

The NHapi HL7 v2 IMessage is implemented using IType interface and it has a property called ExtraComponent. NHapi parser does not throw any exceptions on invalid structure but populates the ExtraComponent property. So if you find ExtraComponent.numComponents() to be more than 0 then you have structural issues on the message.

I have written a validator code in C#. You can download it from github.

https://github.com/shivkumarhaldikar/NHapiValidatator

于 2018-04-10T21:52:49.880 回答