View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.validate.requests;
17  
18  import org.openehealth.ipf.commons.core.modules.api.Validator;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRetrieveImagingDocumentSetRequest;
20  import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
21  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveSeries;
22  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveStudy;
23  import org.openehealth.ipf.commons.ihe.xds.core.validate.HomeCommunityIdValidator;
24  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
25  
26  import java.util.List;
27  
28  import static org.apache.commons.lang3.StringUtils.isNotEmpty;
29  import static org.apache.commons.lang3.Validate.notNull;
30  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.DOC_ID_MUST_BE_SPECIFIED;
31  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.REPO_ID_MUST_BE_SPECIFIED;
32  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.SERIES_INSTANCE_UID_MUST_BE_SPECIFIED;
33  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.STUDY_INSTANCE_UID_MUST_BE_SPECIFIED;
34  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.TRANSFER_SYNTAX_UID_LIST_MUST_BE_SPECIFIED;
35  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
36  
37  /**
38   * Validates a {@link EbXMLRetrieveImagingDocumentSetRequest}.
39   *
40   * @author Clay Sebourn
41   */
42  public class RetrieveImagingDocumentSetRequestValidator implements Validator<EbXMLRetrieveImagingDocumentSetRequest, ValidationProfile> {
43      private final HomeCommunityIdValidator hcValidator = new HomeCommunityIdValidator(true);
44  
45      @Override
46      public void validate(EbXMLRetrieveImagingDocumentSetRequest request, ValidationProfile profile) {
47          notNull(request, "request cannot be null");
48  
49          for (RetrieveStudy retrieveStudy : request.getRetrieveStudies()) {
50              String studyInstanceUID = retrieveStudy.getStudyInstanceUID();
51              metaDataAssert(isNotEmpty(studyInstanceUID), STUDY_INSTANCE_UID_MUST_BE_SPECIFIED);
52  
53              List<String> transferSyntaxUIDList = request.getTransferSyntaxUIDList();
54              metaDataAssert(transferSyntaxUIDList != null && !transferSyntaxUIDList.isEmpty(), TRANSFER_SYNTAX_UID_LIST_MUST_BE_SPECIFIED);
55  
56              for (RetrieveSeries retrieveSeries : retrieveStudy.getRetrieveSerieses()) {
57                  String seriesInstanceUID = retrieveSeries.getSeriesInstanceUID();
58                  metaDataAssert(isNotEmpty(seriesInstanceUID), SERIES_INSTANCE_UID_MUST_BE_SPECIFIED);
59  
60                  for (DocumentReference document : retrieveSeries.getDocuments()) {
61                      //todo: Eliminate this duplicate code from DocumentRequest?
62                      String repoId = document.getRepositoryUniqueId();
63                      metaDataAssert(isNotEmpty(repoId), REPO_ID_MUST_BE_SPECIFIED);
64  
65                      String docId = document.getDocumentUniqueId();
66                      metaDataAssert(isNotEmpty(docId), DOC_ID_MUST_BE_SPECIFIED);
67  
68                      if (profile.getInteractionProfile().requiresHomeCommunityId()) {
69                          hcValidator.validate(document.getHomeCommunityId());
70                      }
71                  }
72              }
73          }
74      }
75  }