protected void checkConstantValue(String value, String encoded, List<HL7Exception> exList) { // check constant value if (value != null && value.length() > 0) { if (!encoded.equals(value)) exList.add(new ProfileNotFollowedException("'" + encoded + "' doesn't equal constant value of '" + value + "'")); } }
protected void checkConstantValue(String value, String encoded, List<HL7Exception> exList) { // check constant value if (value != null && value.length() > 0) { if (!encoded.equals(value)) exList.add(new ProfileNotFollowedException("'" + encoded + "' doesn't equal constant value of '" + value + "'")); } }
protected void checkLength(long length, String name, String encoded, List<HL7Exception> exList) { // check length if (encoded.length() > length) exList.add(new ProfileNotFollowedException("The type " + name + " has length " + encoded.length() + " which exceeds max of " + length)); }
protected void checkLength(long length, String name, String encoded, List<HL7Exception> exList) { // check length if (encoded.length() > length) exList.add(new ProfileNotFollowedException("The type " + name + " has length " + encoded.length() + " which exceeds max of " + length)); }
/** * Checks cardinality and creates an appropriate exception if out of bounds. The usage code is * needed because if min cardinality is > 0, the min # of reps is only required if the usage * code is 'R' (see HL7 v2.5 section 2.12.6.4). * * @param reps the number of reps * @param min the minimum number of reps * @param max the maximum number of reps (-1 means *) * @param usage the usage code * @param name the name of the repeating structure (used in exception msg) * @return null if cardinality OK, exception otherwise */ protected HL7Exception testCardinality(int reps, int min, int max, String usage, String name, List<HL7Exception> exList) { HL7Exception e = null; if (reps < min && usage.equalsIgnoreCase("R")) { e = new ProfileNotFollowedException(name + " must have at least " + min + " repetitions (has " + reps + ")"); } else if (max > 0 && reps > max) { e = new ProfileNotFollowedException(name + " must have no more than " + max + " repetitions (has " + reps + ")"); } if (e != null) exList.add(e); return e; }
/** * Checks cardinality and creates an appropriate exception if out of bounds. The usage code is * needed because if min cardinality is > 0, the min # of reps is only required if the usage * code is 'R' (see HL7 v2.5 section 2.12.6.4). * * @param reps the number of reps * @param min the minimum number of reps * @param max the maximum number of reps (-1 means *) * @param usage the usage code * @param name the name of the repeating structure (used in exception msg) * @return null if cardinality OK, exception otherwise */ protected HL7Exception testCardinality(int reps, int min, int max, String usage, String name, List<HL7Exception> exList) { HL7Exception e = null; if (reps < min && usage.equalsIgnoreCase("R")) { e = new ProfileNotFollowedException(name + " must have at least " + min + " repetitions (has " + reps + ")"); } else if (max > 0 && reps > max) { e = new ProfileNotFollowedException(name + " must have no more than " + max + " repetitions (has " + reps + ")"); } if (e != null) exList.add(e); return e; }
/** * Tests whether the given type falls within a maximum length. * * @return null of OK, an HL7Exception otherwise */ public HL7Exception testLength(Type type, int maxLength) { HL7Exception e = null; String encoded = PipeParser.encode(type, this.enc); if (encoded.length() > maxLength) { e = new ProfileNotFollowedException("Length of " + encoded.length() + " exceeds maximum of " + maxLength); } return e; }
/** * Tests whether the given type falls within a maximum length. * * @return null of OK, an HL7Exception otherwise */ public HL7Exception testLength(Type type, int maxLength) { HL7Exception e = null; String encoded = PipeParser.encode(type, this.enc); if (encoded.length() > maxLength) { e = new ProfileNotFollowedException("Length of " + encoded.length() + " exceeds maximum of " + maxLength); } return e; }
protected void checkMessageType(String msgType, StaticDef profile, List<HL7Exception> exList) throws HL7Exception { if (!msgType.equals(profile.getMsgType())) { HL7Exception e = new ProfileNotFollowedException("Message type " + msgType + " doesn't match profile type of " + profile.getMsgType()); exList.add(e); } }
protected void checkMessageStructure(String msgStruct, StaticDef profile, List<HL7Exception> exList) { if (msgStruct == null || !msgStruct.equals(profile.getMsgStructID())) { HL7Exception e = new ProfileNotFollowedException("Message structure " + msgStruct + " doesn't match profile type of " + profile.getMsgStructID()); exList.add(e); } }
protected void checkMessageType(String msgType, StaticDef profile, List<HL7Exception> exList) throws HL7Exception { if (!msgType.equals(profile.getMsgType())) { HL7Exception e = new ProfileNotFollowedException("Message type " + msgType + " doesn't match profile type of " + profile.getMsgType()); exList.add(e); } }
protected void checkMessageStructure(String msgStruct, StaticDef profile, List<HL7Exception> exList) { if (msgStruct == null || !msgStruct.equals(profile.getMsgStructID())) { HL7Exception e = new ProfileNotFollowedException("Message structure " + msgStruct + " doesn't match profile type of " + profile.getMsgStructID()); exList.add(e); } }
protected void checkEventType(String evType, StaticDef profile, List<HL7Exception> exList) throws HL7Exception { if (!evType.equals(profile.getEventType()) && !profile.getEventType().equalsIgnoreCase("ALL")) { HL7Exception e = new ProfileNotFollowedException("Event type " + evType + " doesn't match profile type of " + profile.getEventType()); exList.add(e); } }
protected void checkEventType(String evType, StaticDef profile, List<HL7Exception> exList) throws HL7Exception { if (!evType.equals(profile.getEventType()) && !profile.getEventType().equalsIgnoreCase("ALL")) { HL7Exception e = new ProfileNotFollowedException("Event type " + evType + " doesn't match profile type of " + profile.getEventType()); exList.add(e); } }
/** * Tests an element against the corresponding usage code. The element is required in its encoded * form. * * @param encoded the pipe-encoded message element * @param usage the usage code (e.g. "CE") * @param name the name of the element (for use in exception messages) * @return null if there is no problem, an HL7Exception otherwise */ protected void testUsage(String encoded, String usage, String name, List<HL7Exception> exList) { if (usage.equalsIgnoreCase("R")) { if (encoded.length() == 0) exList.add(new ProfileNotFollowedException("Required element " + name + " is missing")); } else if (usage.equalsIgnoreCase("RE")) { // can't test anything } else if (usage.equalsIgnoreCase("O")) { // can't test anything } else if (usage.equalsIgnoreCase("C")) { // can't test anything yet -- wait for condition syntax in v2.6 } else if (usage.equalsIgnoreCase("CE")) { // can't test anything } else if (usage.equalsIgnoreCase("X")) { if (encoded.length() > 0) exList.add(new XElementPresentException("Element \"" + name + "\" is present but specified as not used (X)")); } else if (usage.equalsIgnoreCase("B")) { // can't test anything } }
/** * Tests an element against the corresponding usage code. The element is required in its encoded * form. * * @param encoded the pipe-encoded message element * @param usage the usage code (e.g. "CE") * @param name the name of the element (for use in exception messages) * @return null if there is no problem, an HL7Exception otherwise */ protected void testUsage(String encoded, String usage, String name, List<HL7Exception> exList) { if (usage.equalsIgnoreCase("R")) { if (encoded.length() == 0) exList.add(new ProfileNotFollowedException("Required element " + name + " is missing")); } else if (usage.equalsIgnoreCase("RE")) { // can't test anything } else if (usage.equalsIgnoreCase("O")) { // can't test anything } else if (usage.equalsIgnoreCase("C")) { // can't test anything yet -- wait for condition syntax in v2.6 } else if (usage.equalsIgnoreCase("CE")) { // can't test anything } else if (usage.equalsIgnoreCase("X")) { if (encoded.length() > 0) exList.add(new XElementPresentException("Element \"" + name + "\" is present but specified as not used (X)")); } else if (usage.equalsIgnoreCase("B")) { // can't test anything } }
protected void testValueAgainstTable(String profileID, String codeSystem, String value, List<HL7Exception> exList) { CodeStore store = codeStore; if (codeStore == null) { store = getHapiContext().getCodeStoreRegistry().getCodeStore(profileID, codeSystem); } if (store == null) { log.info( "Not checking value {}: no code store was found for profile {} code system {}", new Object[] { value, profileID, codeSystem }); } else { if (!store.knowsCodes(codeSystem)) { log.warn("Not checking value {}: Don't have a table for code system {}", value, codeSystem); } else if (!store.isValidCode(codeSystem, value)) { exList.add(new ProfileNotFollowedException("Code '" + value + "' not found in table " + codeSystem + ", profile " + profileID)); } } }
protected void testValueAgainstTable(String profileID, String codeSystem, String value, List<HL7Exception> exList) { CodeStore store = codeStore; if (codeStore == null) { store = getHapiContext().getCodeStoreRegistry().getCodeStore(profileID, codeSystem); } if (store == null) { log.info( "Not checking value {}: no code store was found for profile {} code system {}", new Object[] { value, profileID, codeSystem }); } else { if (!store.knowsCodes(codeSystem)) { log.warn("Not checking value {}: Don't have a table for code system {}", value, codeSystem); } else if (!store.isValidCode(codeSystem, value)) { exList.add(new ProfileNotFollowedException("Code '" + value + "' not found in table " + codeSystem + ", profile " + profileID)); } } }
protected List<HL7Exception> doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); exList.addAll(testType(type, profile, null, profileID)); // test children if (profile.getSubComponents() > 0 && !profile.getUsage().equals("X") && (!type.isEmpty())) { if (Composite.class.isAssignableFrom(type.getClass())) { Composite comp = (Composite) type; if (theValidateChildren) { for (int i = 1; i <= profile.getSubComponents(); i++) { SubComponent childProfile = profile.getSubComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(testType(child, childProfile, null, profileID)); } catch (DataTypeException de) { exList.add(new ProfileNotHL7CompliantException( "More subcomponents in profile than allowed in message: " + de.getMessage())); } } } checkExtraComponents(comp, profile.getSubComponents(), exList); } else { exList.add(new ProfileNotFollowedException("A component has primitive type " + type.getClass().getName() + " but the profile defines subcomponents")); } } return exList; }
protected List<HL7Exception> doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); exList.addAll(testType(type, profile, null, profileID)); // test children if (profile.getSubComponents() > 0 && !profile.getUsage().equals("X") && (!type.isEmpty())) { if (Composite.class.isAssignableFrom(type.getClass())) { Composite comp = (Composite) type; if (theValidateChildren) { for (int i = 1; i <= profile.getSubComponents(); i++) { SubComponent childProfile = profile.getSubComponent(i); try { Type child = comp.getComponent(i - 1); exList.addAll(testType(child, childProfile, null, profileID)); } catch (DataTypeException de) { exList.add(new ProfileNotHL7CompliantException( "More subcomponents in profile than allowed in message: " + de.getMessage())); } } } checkExtraComponents(comp, profile.getSubComponents(), exList); } else { exList.add(new ProfileNotFollowedException("A component has primitive type " + type.getClass().getName() + " but the profile defines subcomponents")); } } return exList; }