1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.modules.cda;
17
18 import java.util.Map;
19
20 import org.openehealth.ipf.commons.core.modules.api.ValidationException;
21 import org.openehealth.ipf.commons.core.modules.api.Validator;
22 import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
23 import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
24 import org.openhealthtools.mdht.uml.cda.util.CDAUtil.ValidationHandler;
25
26
27
28
29
30
31
32
33 public class CDAR2Validator implements Validator<ClinicalDocument, Map<Object, Object>> {
34
35
36 @Override
37 public void validate(ClinicalDocument doc, Map<Object, Object> context) {
38 boolean isValid = CDAUtil.validate(doc, retrieveValidationHandler(context));
39 if (! isValid) {
40 throw new ValidationException("Clinical Document not valid!");
41 }
42 }
43
44
45
46
47
48
49
50
51 private ValidationHandler retrieveValidationHandler(Map<Object, Object> context) {
52 if (context != null) {
53 ValidationHandler handler = (ValidationHandler) context.get(ValidationHandler.class);
54 if (handler != null) {
55 return handler;
56 }
57 }
58 return new DefaultValidationHandler();
59 }
60
61 }