private void populateFully(Group theA01) throws HL7Exception { for (String nextName : theA01.getNames()) { if (nextName.equals("MSH")) { continue; } Structure nextStruct = theA01.get(nextName); if (nextStruct instanceof Segment) { Segment seg = (Segment) nextStruct; for (int i = 1; i <= seg.numFields(); i++) { populateFully(seg.getField(i, 0)); } } else { populateFully((Group) nextStruct); } } }
/** * 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 List<ValidationException> checkForExtraFields( Segment segment, List<Integer> allowedFields) { ArrayList<ValidationException> exList = new ArrayList<>(); for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(new Integer(i))) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { profileViolatedWhen( !isEmpty(rep), exList, FIELD_NOT_DEFINED_IN_PROFILE, i, segment.getName()); } } catch (HL7Exception he) { exList.add( new ValidationException("Problem testing against profile: " + he.getMessage())); } } } return exList; }