/**
  * Check if expected error (XDSPatientIdDoesNotMatch) is returned if an Association references two
  * XDSObjects with different patientId's.
  *
  * @throws Exception
  */
 @Test
 public void checkErrorPatIdDoesntMatch() throws Exception {
   log.info(
       "\n############################# TEST: check error PatId doesn't Match  ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   RegistryObjectType obj =
       (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   XDSTestUtil.setExternalIdentifierValue(
       obj.getExternalIdentifier(),
       XDSConstants.UUID_XDSDocumentEntry_patientId,
       "test1234_2^^^&1.2.3.45.4.3.2.1&ISO");
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check Unknown PID");
 }
 @Test
 public void checkErrorMergedPatId() throws Exception {
   log.info(
       "\n############################# TEST: check merged PatId ############################");
   String mergedPID = XDSTestUtil.TEST_PID_MERGED + XDSTestUtil.TEST_ISSUER;
   session.linkPatient(mergedPID, XDSTestUtil.TEST_PID_1 + XDSTestUtil.TEST_ISSUER);
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   RegistryObjectType obj =
       (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   XDSTestUtil.setExternalIdentifierValue(
       obj.getExternalIdentifier(), XDSConstants.UUID_XDSDocumentEntry_patientId, mergedPID);
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check merged PID");
   session.linkPatient(mergedPID, null);
 }
  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute (coded
   * as ExternalIdentifier with identificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: patientId, uniqueId XDSFolder: patientId, uniqueId XDSSubmissionSet:
   * patientId, uniqueId, sourceId
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingExternalIdentifier() throws Exception {
    log.info(
        "\n############################# TEST: check missing ExternalIdentifier ##################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_patientId, XDSConstants.UUID_XDSDocumentEntry_uniqueId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in XDSDocument");
    // Folder
    checkRequiredExternalIdentifiers(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_patientId, XDSConstants.UUID_XDSFolder_uniqueId},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in Folder");
    // SubmissionSet
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSSubmissionSet_patientId,
          XDSConstants.UUID_XDSSubmissionSet_uniqueId,
          XDSConstants.UUID_XDSSubmissionSet_sourceId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }
  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute coded as
   * Slot is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: creationTime, hash, repositoryUniqueId, size, sourcePatientId and
   * languageCode XDSSubmissionSet: submissionTime
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingSlot() throws Exception {
    log.info(
        "\n############################# TEST: check missing slot ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // XDSDocument
    checkRequiredSlots(
        req,
        new String[] {
          XDSConstants.SLOT_NAME_CREATION_TIME,
          XDSConstants.SLOT_NAME_REPOSITORY_UNIQUE_ID,
          XDSConstants.SLOT_NAME_SIZE,
          XDSConstants.SLOT_NAME_HASH,
          XDSConstants.SLOT_NAME_SOURCE_PATIENT_ID,
          XDSConstants.SLOT_NAME_LANGUAGE_CODE
        },
        req.getRegistryObjectList().getIdentifiable().get(0).getValue().getSlot(),
        "Check missing Slots in XDSDocument");
    // SubmissionSet
    checkRequiredSlots(
        req,
        new String[] {XDSConstants.SLOT_NAME_SUBMISSION_TIME},
        req.getRegistryObjectList().getIdentifiable().get(2).getValue().getSlot(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }
 @After
 public void clearDB() {
   if (testCount == NUMBER_OF_TEST_METHODS) {
     XDSTestUtil.clearDB(testSession, log);
   } else {
     testSession.removeAllIdentifiables("urn:uuid:aabbccdd-bdda");
   }
 }
 @Deployment
 public static WebArchive createDeployment() {
   return XDSTestUtil.createDeploymentArchive(CheckErrorsTest.class)
       .add(
           new FileAsset(
               new File(
                   "src/test/resources/org/dcm4chee/xds2/registry/ws/" + TEST_METADATA_FILENAME)),
           "WEB-INF/classes/org/dcm4chee/xds2/registry/ws/" + TEST_METADATA_FILENAME);
 }
 private void checkRequiredCodes(
     SubmitObjectsRequest req, String[] codeTypes, List<ClassificationType> cl, String prefix) {
   List<ClassificationType> codes;
   for (int i = 0; i < codeTypes.length; i++) {
     codes = XDSTestUtil.removeCode(cl, codeTypes[i]);
     doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
     cl.addAll(codes);
   }
 }
 private void checkRequiredSlots(
     SubmitObjectsRequest req, String[] slotNames, List<SlotType1> slots, String prefix) {
   SlotType1 slot;
   for (int i = 0; i < slotNames.length; i++) {
     slot = XDSTestUtil.removeSlot(slots, slotNames[i]);
     doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
     slots.add(slot);
   }
 }
 private void checkRequiredExternalIdentifiers(
     SubmitObjectsRequest req,
     String[] required,
     List<ExternalIdentifierType> eis,
     String prefix) {
   for (int i = 0; i < required.length; i++) {
     ExternalIdentifierType ei = XDSTestUtil.removeExternalIdentifier(eis, required[i]);
     doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
     eis.add(ei);
   }
 }
Example #10
0
 @Test
 public void checkMissingMimeType() throws Exception {
   log.info(
       "\n############################# TEST: missing mimeType in DocumentEntry  ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   ExtrinsicObjectType doc =
       (ExtrinsicObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   doc.setMimeType("");
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Check missing mimeType");
 }
Example #11
0
 @Test
 public void checkErrorUnknownPatId() throws Exception {
   log.info(
       "\n############################# TEST: check unknown PatId ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   List<JAXBElement<? extends IdentifiableType>> objList =
       req.getRegistryObjectList().getIdentifiable();
   RegistryObjectType obj = (RegistryObjectType) objList.get(0).getValue();
   String unknownPID = "11111^^^&1.2.3&ISO";
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(0).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSDocumentEntry_patientId,
       unknownPID);
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(1).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSFolder_patientId,
       unknownPID);
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(2).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSSubmissionSet_patientId,
       unknownPID);
   doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_UNKNOWN_PATID, "Check Unknown PID");
 }
Example #12
0
  @Test
  public void checkMissingEntryUUID() throws Exception {
    log.info(
        "\n############################# TEST: missing entryUUID (RegistryObject.id) ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(0).getValue(),
        "Check Missing EntryUUID of XDSDocument");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(1).getValue(),
        "Check Missing EntryUUID of Folder");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(2).getValue(),
        "Check Missing EntryUUID of SubmissionSet");

    AuditTestManager.expectNumberOfMessages(3);
  }
Example #13
0
  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required code attribute
   * (coded as Classification with classificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: confidentialityCode, formatCode, healthCareFacilityTypeCode,
   * practiceSettingCode, typeCode XDSFolder: codeList XDSSubmissionSet: contentTypeCode
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingCode() throws Exception {
    log.info(
        "\n############################# TEST: check missing code ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredCodes(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_classCode,
          XDSConstants.UUID_XDSDocumentEntry_confidentialityCode,
          XDSConstants.UUID_XDSDocumentEntry_formatCode,
          XDSConstants.UUID_XDSDocumentEntry_healthCareFacilityTypeCode,
          XDSConstants.UUID_XDSDocumentEntry_practiceSettingCode,
          XDSConstants.UUID_XDSDocumentEntry_typeCode
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getClassification(),
        "Check missing Code in XDSDocument");
    // Folder
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_codeList},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getClassification(),
        "Check missing Code in Folder");
    // SubmissionSet
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSSubmissionSet_contentTypeCode},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getClassification(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(8);
  }
Example #14
0
 @Before
 public void prepare() {
   if (testCount++ == 0) {
     XDSTestUtil.prepareTests(session, log);
   }
 }
Example #15
0
/** @author Franz Willer <*****@*****.**> */
@RunWith(Arquillian.class)
public class CheckErrorsTest {
  private static final int NUMBER_OF_TEST_METHODS =
      XDSTestUtil.getNumberOfTestMethods(CheckErrorsTest.class);
  private static int testCount = 0;

  private static final String TEST_METADATA_FILENAME = "CreateFolderWithDocument.xml";

  private static final Logger log = LoggerFactory.getLogger(CheckErrorsTest.class);

  @Deployment
  public static WebArchive createDeployment() {
    return XDSTestUtil.createDeploymentArchive(CheckErrorsTest.class)
        .add(
            new FileAsset(
                new File(
                    "src/test/resources/org/dcm4chee/xds2/registry/ws/" + TEST_METADATA_FILENAME)),
            "WEB-INF/classes/org/dcm4chee/xds2/registry/ws/" + TEST_METADATA_FILENAME);
  }

  @EJB private XdsRegistryBeanForTesting session;

  @EJB private XDSRegistryTestBeanI testSession;

  // Audit logger	testing
  @Before
  public void prepareAuditLogger() {
    AuditTestManager.prepareAuditLogger();
  }

  @After
  public void checkAudits() {
    AuditTestManager.checkAudits();
  }

  @Before
  public void prepare() {
    if (testCount++ == 0) {
      XDSTestUtil.prepareTests(session, log);
    }
  }

  @After
  public void clearDB() {
    if (testCount == NUMBER_OF_TEST_METHODS) {
      XDSTestUtil.clearDB(testSession, log);
    } else {
      testSession.removeAllIdentifiables("urn:uuid:aabbccdd-bdda");
    }
  }

  @Test
  public void checkErrorUnknownPatId() throws Exception {
    log.info(
        "\n############################# TEST: check unknown PatId ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    List<JAXBElement<? extends IdentifiableType>> objList =
        req.getRegistryObjectList().getIdentifiable();
    RegistryObjectType obj = (RegistryObjectType) objList.get(0).getValue();
    String unknownPID = "11111^^^&1.2.3&ISO";
    XDSTestUtil.setExternalIdentifierValue(
        ((RegistryObjectType) objList.get(0).getValue()).getExternalIdentifier(),
        XDSConstants.UUID_XDSDocumentEntry_patientId,
        unknownPID);
    XDSTestUtil.setExternalIdentifierValue(
        ((RegistryObjectType) objList.get(1).getValue()).getExternalIdentifier(),
        XDSConstants.UUID_XDSFolder_patientId,
        unknownPID);
    XDSTestUtil.setExternalIdentifierValue(
        ((RegistryObjectType) objList.get(2).getValue()).getExternalIdentifier(),
        XDSConstants.UUID_XDSSubmissionSet_patientId,
        unknownPID);
    doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_UNKNOWN_PATID, "Check Unknown PID");
  }

  @Test
  public void checkErrorMergedPatId() throws Exception {
    log.info(
        "\n############################# TEST: check merged PatId ############################");
    String mergedPID = XDSTestUtil.TEST_PID_MERGED + XDSTestUtil.TEST_ISSUER;
    session.linkPatient(mergedPID, XDSTestUtil.TEST_PID_1 + XDSTestUtil.TEST_ISSUER);
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    RegistryObjectType obj =
        (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
    XDSTestUtil.setExternalIdentifierValue(
        obj.getExternalIdentifier(), XDSConstants.UUID_XDSDocumentEntry_patientId, mergedPID);
    doRegisterDocumentAndCheckError(
        req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check merged PID");
    session.linkPatient(mergedPID, null);
  }
  /**
   * Check if expected error (XDSPatientIdDoesNotMatch) is returned if an Association references two
   * XDSObjects with different patientId's.
   *
   * @throws Exception
   */
  @Test
  public void checkErrorPatIdDoesntMatch() throws Exception {
    log.info(
        "\n############################# TEST: check error PatId doesn't Match  ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    RegistryObjectType obj =
        (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
    XDSTestUtil.setExternalIdentifierValue(
        obj.getExternalIdentifier(),
        XDSConstants.UUID_XDSDocumentEntry_patientId,
        "test1234_2^^^&1.2.3.45.4.3.2.1&ISO");
    doRegisterDocumentAndCheckError(
        req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check Unknown PID");
  }

  @Test
  public void checkMissingEntryUUID() throws Exception {
    log.info(
        "\n############################# TEST: missing entryUUID (RegistryObject.id) ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(0).getValue(),
        "Check Missing EntryUUID of XDSDocument");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(1).getValue(),
        "Check Missing EntryUUID of Folder");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(2).getValue(),
        "Check Missing EntryUUID of SubmissionSet");

    AuditTestManager.expectNumberOfMessages(3);
  }

  @Test
  public void checkMissingMimeType() throws Exception {
    log.info(
        "\n############################# TEST: missing mimeType in DocumentEntry  ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    ExtrinsicObjectType doc =
        (ExtrinsicObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
    doc.setMimeType("");
    doRegisterDocumentAndCheckError(
        req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Check missing mimeType");
  }

  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute coded as
   * Slot is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: creationTime, hash, repositoryUniqueId, size, sourcePatientId and
   * languageCode XDSSubmissionSet: submissionTime
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingSlot() throws Exception {
    log.info(
        "\n############################# TEST: check missing slot ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // XDSDocument
    checkRequiredSlots(
        req,
        new String[] {
          XDSConstants.SLOT_NAME_CREATION_TIME,
          XDSConstants.SLOT_NAME_REPOSITORY_UNIQUE_ID,
          XDSConstants.SLOT_NAME_SIZE,
          XDSConstants.SLOT_NAME_HASH,
          XDSConstants.SLOT_NAME_SOURCE_PATIENT_ID,
          XDSConstants.SLOT_NAME_LANGUAGE_CODE
        },
        req.getRegistryObjectList().getIdentifiable().get(0).getValue().getSlot(),
        "Check missing Slots in XDSDocument");
    // SubmissionSet
    checkRequiredSlots(
        req,
        new String[] {XDSConstants.SLOT_NAME_SUBMISSION_TIME},
        req.getRegistryObjectList().getIdentifiable().get(2).getValue().getSlot(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }

  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required code attribute
   * (coded as Classification with classificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: confidentialityCode, formatCode, healthCareFacilityTypeCode,
   * practiceSettingCode, typeCode XDSFolder: codeList XDSSubmissionSet: contentTypeCode
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingCode() throws Exception {
    log.info(
        "\n############################# TEST: check missing code ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredCodes(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_classCode,
          XDSConstants.UUID_XDSDocumentEntry_confidentialityCode,
          XDSConstants.UUID_XDSDocumentEntry_formatCode,
          XDSConstants.UUID_XDSDocumentEntry_healthCareFacilityTypeCode,
          XDSConstants.UUID_XDSDocumentEntry_practiceSettingCode,
          XDSConstants.UUID_XDSDocumentEntry_typeCode
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getClassification(),
        "Check missing Code in XDSDocument");
    // Folder
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_codeList},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getClassification(),
        "Check missing Code in Folder");
    // SubmissionSet
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSSubmissionSet_contentTypeCode},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getClassification(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(8);
  }

  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute (coded
   * as ExternalIdentifier with identificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: patientId, uniqueId XDSFolder: patientId, uniqueId XDSSubmissionSet:
   * patientId, uniqueId, sourceId
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingExternalIdentifier() throws Exception {
    log.info(
        "\n############################# TEST: check missing ExternalIdentifier ##################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_patientId, XDSConstants.UUID_XDSDocumentEntry_uniqueId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in XDSDocument");
    // Folder
    checkRequiredExternalIdentifiers(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_patientId, XDSConstants.UUID_XDSFolder_uniqueId},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in Folder");
    // SubmissionSet
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSSubmissionSet_patientId,
          XDSConstants.UUID_XDSSubmissionSet_uniqueId,
          XDSConstants.UUID_XDSSubmissionSet_sourceId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }

  private void doRegisterDocumentAndCheckError(
      SubmitObjectsRequest req, String errorCode, String prefix) {
    RegistryResponseType rsp = null;
    try {
      rsp = session.documentRegistryRegisterDocumentSetB(req);
    } catch (Exception x) {
      fail(prefix + ": Register document failed unexpected! Error:" + x);
    }
    if (!XDSConstants.XDS_B_STATUS_FAILURE.equals(rsp.getStatus())) {
      fail(prefix + ": Register document should fail with error code:" + errorCode);
    }
    String error = rsp.getRegistryErrorList().getRegistryError().get(0).getErrorCode();
    assertEquals(prefix + ": Error code:", errorCode, error);
  }

  private void checkRequiredSlots(
      SubmitObjectsRequest req, String[] slotNames, List<SlotType1> slots, String prefix) {
    SlotType1 slot;
    for (int i = 0; i < slotNames.length; i++) {
      slot = XDSTestUtil.removeSlot(slots, slotNames[i]);
      doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
      slots.add(slot);
    }
  }

  private void checkRequiredCodes(
      SubmitObjectsRequest req, String[] codeTypes, List<ClassificationType> cl, String prefix) {
    List<ClassificationType> codes;
    for (int i = 0; i < codeTypes.length; i++) {
      codes = XDSTestUtil.removeCode(cl, codeTypes[i]);
      doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
      cl.addAll(codes);
    }
  }

  private void checkRequiredExternalIdentifiers(
      SubmitObjectsRequest req,
      String[] required,
      List<ExternalIdentifierType> eis,
      String prefix) {
    for (int i = 0; i < required.length; i++) {
      ExternalIdentifierType ei = XDSTestUtil.removeExternalIdentifier(eis, required[i]);
      doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
      eis.add(ei);
    }
  }

  private void checkEntryUUID(SubmitObjectsRequest req, IdentifiableType obj, String prefix) {
    String id = obj.getId();
    obj.setId("");
    doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, prefix);
    obj.setId(id);
  }
}