/** * Creates an instance that tests messages against whatever profiles they declare in * MSH-21. The ID declared in MSH-21 is evaluated in a way that the corresponding * profile file is expected to be BASEDIR/profiles/ID.xml. */ public ConformanceProfileRule() { super(); setDescription("Unknown segments found in message"); setSectionReference("HL7 2.5 section 2.12"); }
/** * @see ca.uhn.hl7v2.validation.MessageRule#test(ca.uhn.hl7v2.model.Message) */ public ValidationException[] apply(Message msg) { List<ValidationException> problems = new ArrayList<ValidationException>(); String[] ids = {myProfileID}; try { if (myProfileID == null) { ids = getDeclaredProfileIDs(msg); } for (String id : ids) { log.debug("Testing message against profile: {}", id); try { ValidationException[] shortList = testAgainstProfile(msg, id); log.debug("{} non-conformances", shortList.length); problems.addAll(Arrays.asList(shortList)); } catch (ProfileException e) { problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e)); } } } catch (HL7Exception e) { problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e)); } return problems.toArray(new ValidationException[problems.size()]); }
/** * Builds a {@link MessageRule} that evaluates the message against the Conformance Profile * referred to by the profileId parameter * * @param profileId conformance profile id (file name) * @return this instance to build more rules */ public MessageRuleBuilder conformance(String profileId) { return test(prepareRule(new ConformanceProfileRule(profileId))); }
private ValidationException[] testAgainstProfile(Message message, String id) throws ProfileException, HL7Exception { HL7Exception[] exceptions; HapiContext context = message.getParser().getHapiContext(); Validator validator = context.getConformanceValidator(); try { ProfileStore profileStore = context.getProfileStore(); String profileString = profileStore.getProfile(id); if (profileString != null) { RuntimeProfile profile = getProfile(profileString); exceptions = validator.validate(message, profile.getMessage()); } else { throw new ProfileException("Unable to find the profile " + id); } } catch (IOException e) { throw new ProfileException("Error retreiving profile " + id, e); } ValidationException[] result = new ValidationException[exceptions.length]; for (int i = 0; i < exceptions.length; i++) { result[i] = ValidationException.fromHL7Exception(exceptions[i]); } return result; }
/** * @see ca.uhn.hl7v2.validation.MessageRule#test(ca.uhn.hl7v2.model.Message) */ public ValidationException[] apply(Message msg) { List<ValidationException> problems = new ArrayList<ValidationException>(); String[] ids = {myProfileID}; try { if (myProfileID == null) { ids = getDeclaredProfileIDs(msg); } for (String id : ids) { log.debug("Testing message against profile: {}", id); try { ValidationException[] shortList = testAgainstProfile(msg, id); log.debug("{} non-conformances", shortList.length); problems.addAll(Arrays.asList(shortList)); } catch (ProfileException e) { problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e)); } } } catch (HL7Exception e) { problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e)); } return problems.toArray(new ValidationException[problems.size()]); }
/** * Builds a {@link MessageRule} that evaluates the message against the Conformance Profile * referred to by the profileId parameter * * @param profileId conformance profile id (file name) * @return this instance to build more rules */ public MessageRuleBuilder conformance(String profileId) { return test(prepareRule(new ConformanceProfileRule(profileId))); }
private ValidationException[] testAgainstProfile(Message message, String id) throws ProfileException, HL7Exception { HL7Exception[] exceptions; HapiContext context = message.getParser().getHapiContext(); Validator validator = context.getConformanceValidator(); try { ProfileStore profileStore = context.getProfileStore(); String profileString = profileStore.getProfile(id); if (profileString != null) { RuntimeProfile profile = getProfile(profileString); exceptions = validator.validate(message, profile.getMessage()); } else { throw new ProfileException("Unable to find the profile " + id); } } catch (IOException e) { throw new ProfileException("Error retreiving profile " + id, e); } ValidationException[] result = new ValidationException[exceptions.length]; for (int i = 0; i < exceptions.length; i++) { result[i] = ValidationException.fromHL7Exception(exceptions[i]); } return result; }
/** * Creates an instance that tests messages against whatever profiles they declare in * MSH-21. The ID declared in MSH-21 is evaluated in a way that the corresponding * profile file is expected to be BASEDIR/profiles/ID.xml. */ public ConformanceProfileRule() { super(); setDescription("Unknown segments found in message"); setSectionReference("HL7 2.5 section 2.12"); }