1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.validate.responses;
17
18 import org.openehealth.ipf.commons.core.modules.api.Validator;
19 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectContainer;
20 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLQueryResponse;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryObject;
22 import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
23 import org.openehealth.ipf.commons.ihe.xds.core.metadata.ObjectReference;
24 import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
25 import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
26 import org.openehealth.ipf.commons.ihe.xds.core.validate.requests.ObjectContainerValidator;
27
28 import java.util.List;
29
30 import static org.apache.commons.lang3.Validate.notNull;
31 import static org.openehealth.ipf.commons.ihe.xds.XDS.Interactions.ITI_51;
32 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.DOC_ENTRY_PATIENT_ID_EXTERNAL_ID;
33 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.FOLDER_CLASS_NODE;
34 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.FOLDER_PATIENT_ID_EXTERNAL_ID;
35 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.SUBMISSION_SET_CLASS_NODE;
36 import static org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary.SUBMISSION_SET_PATIENT_ID_EXTERNAL_ID;
37 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.MISSING_OBJ_REF;
38 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.RESULT_NOT_SINGLE_PATIENT;
39 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
40
41
42
43
44
45 public class QueryResponseValidator implements Validator<EbXMLQueryResponse, ValidationProfile> {
46 private final RegistryResponseValidator regResponseValidator = new RegistryResponseValidator();
47 private final ObjectContainerValidator objectContainerValidator = new ObjectContainerValidator();
48
49 @Override
50 public void validate(EbXMLQueryResponse response, ValidationProfile profile) {
51 notNull(response, "response cannot be null");
52
53 regResponseValidator.validate(response, profile);
54 objectContainerValidator.validate(response, profile);
55
56 List<ObjectReference> references = response.getReferences();
57 for (ObjectReference objRef : references) {
58 metaDataAssert(objRef.getId() != null, MISSING_OBJ_REF);
59 }
60
61 if (profile != ITI_51) {
62 validatePatientIdsAreIdentical(response);
63 }
64 }
65
66 private void validatePatientIdsAreIdentical(EbXMLObjectContainer container) throws XDSMetaDataException {
67 String patientId = checkForMultiplePatientIds(null, SUBMISSION_SET_PATIENT_ID_EXTERNAL_ID,
68 container.getRegistryPackages(SUBMISSION_SET_CLASS_NODE));
69
70 patientId = checkForMultiplePatientIds(patientId, DOC_ENTRY_PATIENT_ID_EXTERNAL_ID,
71 container.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND));
72
73 checkForMultiplePatientIds(patientId, FOLDER_PATIENT_ID_EXTERNAL_ID,
74 container.getRegistryPackages(FOLDER_CLASS_NODE));
75 }
76
77 private String checkForMultiplePatientIds(String patientId, String id, List<? extends EbXMLRegistryObject> entries) {
78 for (EbXMLRegistryObject entry : entries) {
79 String patientIdEntry = entry.getExternalIdentifierValue(id);
80 patientId = patientId == null ? patientIdEntry : patientId;
81 metaDataAssert(patientId.equals(patientIdEntry), RESULT_NOT_SINGLE_PATIENT);
82 }
83 return patientId;
84 }
85
86 }