/** * 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 } }
/** Tests for extra components (ie any not defined in the profile) */ protected void checkExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) throws ProfileException { StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = PipeParser.encode(comp.getComponent(i), enc); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (DataTypeException de) { throw new ProfileException("Problem testing against profile", de); } } if (extra.length() > 0) { exList.add(new XElementPresentException( "The following components are not defined in the profile: " + extra.toString())); } }
/** Tests for extra components (ie any not defined in the profile) */ protected void checkExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) throws ProfileException { StringBuilder extra = new StringBuilder(); for (int i = numInProfile; i < comp.getComponents().length; i++) { try { String s = PipeParser.encode(comp.getComponent(i), enc); if (s.length() > 0) { extra.append(s).append(enc.getComponentSeparator()); } } catch (DataTypeException de) { throw new ProfileException("Problem testing against profile", de); } } if (extra.length() > 0) { exList.add(new XElementPresentException( "The following components are not defined in the profile: " + extra.toString())); } }
/** * Checks a group's children against a list of allowed structures for the group (ie those * mentioned in the profile with usage other than X). Returns a list of exceptions representing * structures that appear in the message but are not supposed to. */ protected void checkForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) throws ProfileException { for (String childName : group.getNames()) { if (!allowedStructures.contains(childName)) { try { for (Structure rep : group.getAll(childName)) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("The structure " + childName + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem checking profile", he); } } } }
/** * Checks a group's children against a list of allowed structures for the group (ie those * mentioned in the profile with usage other than X). Returns a list of exceptions representing * structures that appear in the message but are not supposed to. */ protected void checkForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) throws ProfileException { for (String childName : group.getNames()) { if (!allowedStructures.contains(childName)) { try { for (Structure rep : group.getAll(childName)) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("The structure " + childName + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem checking profile", he); } } } }
/** * Checks a segment against a list of allowed fields (ie those mentioned in the profile with * usage other than X). Returns a list of exceptions representing field that appear but are not * supposed to. * * @param allowedFields an array of Integers containing field #s of allowed fields */ protected void checkForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) throws ProfileException { for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(i)) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem testing against profile", he); } } } }
/** * Checks a segment against a list of allowed fields (ie those mentioned in the profile with * usage other than X). Returns a list of exceptions representing field that appear but are not * supposed to. * * @param allowedFields an array of Integers containing field #s of allowed fields */ protected void checkForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) throws ProfileException { for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(i)) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem testing against profile", he); } } } }