Ejemplo n.º 1
0
  /**
   * Tests the group (or message) against a list of profile descriptions that are either a {@link
   * org.openehealth.ipf.gazelle.validation.core.stub.SegmentType} or a {@link
   * org.openehealth.ipf.gazelle.validation.core.stub.HL7V2XStaticDef.SegGroup}.
   *
   * @param group current message/group element
   * @param profile available profile objcts to test the element against
   * @return a list with identified violations against the profile(s)
   */
  protected List<ValidationException> testGroup(Group group, List<Object> profile) {
    List<ValidationException> exList = new ArrayList<>();
    List<String> allowedStructures = new ArrayList<>();

    for (Object struct : profile) {
      UsageInfo usage = new UsageInfo(struct);

      if (!usage.disallowed()) {
        allowedStructures.add(usage.name);

        try {
          List<Structure> nonEmptyStructures = nonEmptyStructure(group.getAll(usage.name));
          exList.addAll(testCardinality(nonEmptyStructures.size(), usage));

          // test children on instances with content
          if (validateChildren) {
            for (Structure structure : nonEmptyStructures) {
              exList.addAll(testStructure(structure, struct));
            }
          }
        } catch (HL7Exception he) {
          profileNotHL7Compliant(exList, PROFILE_STRUCTURE_NOT_EXIST_IN_JAVA_CLASS, usage.name);
        }
      }
    }

    // complain about X structures that have content
    exList.addAll(checkForExtraStructures(group, allowedStructures));
    return exList;
  }
Ejemplo n.º 2
0
 /**
  * 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 List<ValidationException> checkForExtraStructures(
     Group group, List<String> allowedStructures) {
   List<ValidationException> exList = new ArrayList<>();
   for (String childName : group.getNames()) {
     if (!allowedStructures.contains(childName)) {
       try {
         for (Structure rep : group.getAll(childName)) {
           profileViolatedWhen(!isEmpty(rep), exList, STRUCTURE_NOT_DEFINED_IN_PROFILE, childName);
         }
       } catch (HL7Exception he) {
         exList.add(new ValidationException("Problem checking profile:" + he.getMessage()));
       }
     }
   }
   return exList;
 }
  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);
      }
    }
  }