1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.hl7v3;
17
18 import lombok.Getter;
19 import org.openehealth.ipf.commons.xml.CombinedXmlValidationProfile;
20
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24
25
26
27
28 public class Hl7v3ValidationProfile implements CombinedXmlValidationProfile {
29
30 public static final String DEFAULT_XSD = "";
31 public static final String GAZELLE_PIXPDQV3_SCHEMATRON = "/schematron/gazelle-pixpdqv3.sch.xml";
32
33 static class Row {
34 private static final String HL7V3_SCHEMAS_PATH = "/schema/HL7V3/NE2008/multicacheschemas/";
35
36 @Getter final String rootElementName;
37 @Getter final String xsdPath;
38 @Getter final String schematronPath;
39 @Getter final String schematronPhase;
40
41 Row(String rootElementName, String xsdPath, String schematronPath) {
42 this.rootElementName = rootElementName;
43 if (DEFAULT_XSD.equals(xsdPath)) {
44 int pos1 = rootElementName.indexOf('_');
45 int pos2 = rootElementName.indexOf('_', pos1 + 1);
46 String documentName = (pos2 > 0) ? rootElementName.substring(0, pos2) : rootElementName;
47 this.xsdPath = HL7V3_SCHEMAS_PATH + documentName + ".xsd";
48 } else {
49 this.xsdPath = xsdPath.startsWith("/") ? xsdPath : HL7V3_SCHEMAS_PATH + xsdPath;
50 }
51 this.schematronPath = schematronPath;
52 this.schematronPhase = GAZELLE_PIXPDQV3_SCHEMATRON.equals(schematronPath) ? rootElementName : null;
53 }
54 }
55
56
57 private final Map<String, Row> map;
58
59 public Hl7v3ValidationProfile(Row... rows) {
60 map = new HashMap<>(rows.length);
61 for (Row row : rows) {
62 map.put(row.rootElementName, row);
63 }
64 }
65
66
67 @Override
68 public boolean isValidRootElement(String rootElementName) {
69 return map.containsKey(rootElementName);
70 }
71
72 @Override
73 public String getXsdPath(String rootElementName) {
74 return map.get(rootElementName).getXsdPath();
75 }
76
77 @Override
78 public String getSchematronPath(String rootElementName) {
79 return map.get(rootElementName).getSchematronPath();
80 }
81
82 @Override
83 public Map<String, Object> getCustomSchematronParameters(String rootElementName) {
84 String phase = map.get(rootElementName).getSchematronPhase();
85 return (phase != null) ? Collections.singletonMap("phase", phase) : null;
86 }
87
88 }