我希望使用HL7项目的C#和.NET版本来验证nHapi 2.3标准消息:
https://github.com/duaneedwards/nHapi
我已经下载了dll,并将NHapi.Base.dll和NHapi.Model.V23.dll添加到我的项目中。
我知道我应该使用:
NHapi.Base.validation.MessageValidator但是我不知道应该如何配置IValidationContext theContext才能检查2.3版本。
此外,我找不到任何适合它的API文档。
有人能帮上忙吗?
发布于 2018-05-22 17:52:16
验证消息的方法被嵌入到解析器中。特定规则的实现有意留给实现者(以提高灵活性)。您需要做的是创建新的上下文:
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-04-11 05:52:50
甚至我也在寻找一些使用NHapi验证HL7 V2消息的解决方案,但找不到任何好的文章。因此,我决定通过NHapi对象模块来查看任何有用的信息来验证结构,我找到了一些东西。
NHapi HL7 v2 IMessage是使用IType接口实现的,它有一个名为ExtraComponent的属性。NHapi解析器不会对无效结构抛出任何异常,但会填充ExtraComponent属性。因此,如果你发现ExtraComponent.numComponents()大于0,那么你的消息就有结构问题。
我已经用C#写了一个验证器代码。你可以从github下载。
https://stackoverflow.com/questions/33196187
复制相似问题