Пример #1
0
 /**
  * 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;
 }
Пример #2
0
  protected List<ValidationException> testSegment(Segment segment, SegmentType profile) {
    List<ValidationException> exList = new ArrayList<>();
    List<Integer> allowedFields = new ArrayList<>();
    int i = 1;
    for (SegmentType.Field field : profile.getFields()) {
      UsageInfo usage = new UsageInfo(field);
      // only test a field in detail if it isn't X
      if (!usage.disallowed()) {
        allowedFields.add(i);

        // see which instances have content
        try {
          Collection<Type> nonEmptyFields = nonEmptyField(segment.getField(i));
          exList.addAll(testCardinality(nonEmptyFields.size(), usage));

          // test field instances with content
          if (validateChildren) {
            for (Type type : nonEmptyFields) {
              boolean escape = true; // escape field value when checking length
              if (profile.getName().equalsIgnoreCase("MSH") && i < 3) {
                escape = false;
              }
              List<ValidationException> childExceptions = testField(type, field, escape);
              for (ValidationException ex : childExceptions) {
                ex.setFieldPosition(i);
              }
              exList.addAll(childExceptions);
            }
          }
        } catch (HL7Exception he) {
          profileNotHL7Compliant(exList, FIELD_NOT_FOUND, i);
        }
      }
      ++i;
    }
    // complain about X fields with content
    exList.addAll(checkForExtraFields(segment, allowedFields));

    for (ValidationException ex : exList) {
      ex.setSegmentName(profile.getName());
    }
    return exList;
  }