[英]HAPI HL7 Validation throws Exceptions
我正在研究打算用於HL7消息驗證的Java端點。 我有一個運行的基本應用程序,它使用標准HAPI HL7驗證示例的變體。 如果我輸入了有效消息,則會收到“成功”響應。 如果我傳遞了無效的消息,我仍然會收到“成功”響應。
我得到錯誤響應的唯一方法是,如果HL7格式錯誤,並且PipeParser引發異常。 在這種情況下,它會被捕獲在catch塊中。
我想看看的是,如果我傳遞了一條無效消息,表明該消息實際上已經過驗證並返回所有驗證錯誤。 但是我從來沒有真正看到過任何驗證。 它要么解析要么崩潰嘗試解析。
我在這里想念什么?
HapiContext context = new DefaultHapiContext();
ValidationContext validationContext = ValidationContextFactory.defaultValidation();
context.setValidationContext(validationContext);
try
{
context.getParserConfiguration().setUnexpectedSegmentBehaviour(UnexpectedSegmentBehaviourEnum.THROW_HL7_EXCEPTION);
Message messageValidationResults = context.getPipeParser().parse(hl7Message);
SimpleValidationExceptionHandler handler = new SimpleValidationExceptionHandler(context);
handler.setMinimumSeverityToCollect(Severity.INFO);
Validator<Boolean> validator = context.getMessageValidator();
if (!validator.validate(messageValidationResults, handler))
{
if (handler.getExceptions().size() == 0)
{
hl7ValidationResult = "SUCCESS - Message Validated Successfully";
}
else
{
hl7ValidationResult = "ERROR - Found " + handler.getExceptions().size() + " problems\n\n";
for (Exception e : handler.getExceptions())
{
hl7ValidationResult += (e.getClass().getSimpleName() + " - " + e.getMessage()) + "\n";
}
}
}
}
catch (Exception e)
{
hl7ValidationResult = "ERROR - " + e.getMessage();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString();
hl7ValidationResult += "\n\n" + sStackTrace;
}
如果您認為不正確,請忽略答案,我停止使用HL7,但是在我的舊項目中,我發現了這一點,也許它可以幫助您找到問題的解決方案:
{
DefaultValidationBuilder builder = new DefaultValidationBuilder() {
private static final long serialVersionUID = 1L;
@Override
protected void configure() {
super.configure();
forVersion(Version.V26);
}
};
HapiContext context = new DefaultHapiContext();
context.setValidationRuleBuilder(builder);
PipeParser hapiParser = context.getPipeParser();
try {
hapiParser.parse(hl7Message);
} catch (ca.uhn.hl7v2.HL7Exception e) {
// String error, String language, String requisitionNumber, String controlId, String processinId, String senderApplication, String senderFacility
errors.add(new HL7ValidationError(
"HAPI Validator error found: " + e.getMessage(),
extractor.accessPatientDirectly().getLanguage(),
extractor.accessPatientDirectly().getRequisitionNumber(),
extractor.accessPatientDirectly().getControlID(),
"",
extractor.accessPatientDirectly().getSenderApplication(),
extractor.accessPatientDirectly().getSenderFacility())
);
log.debug("HAPI Validator error found: " + e.getMessage());
}
try {
context.close();
}
catch (Exception ex) {
log.debug("Unable to close HapiContext(): " + ex.getMessage());
}
}
基本上我使用了hapiParser.parse(hl7Message); 並捕獲HL7Exception
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.