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;
17
18 import ca.uhn.hl7v2.model.v25.datatype.HD;
19 import ca.uhn.hl7v2.model.v25.datatype.XCN;
20 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
21 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Person;
22
23 import static org.apache.commons.lang3.StringUtils.isNotEmpty;
24 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.PERSON_MISSING_NAME_AND_ID;
25 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.PERSON_HD_MISSING;
26 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
27 import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isEmptyField;
28 import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isNotEmptyField;
29
30
31
32
33
34 public class XCNValidator implements ValueValidator {
35 private static final HDValidator HD_VALIDATOR = new HDValidator();
36
37 @Override
38 public void validate(String hl7xcn) throws XDSMetaDataException {
39 Person person = Hl7v2Based.parse(hl7xcn, Person.class);
40 metaDataAssert(person != null, PERSON_MISSING_NAME_AND_ID, hl7xcn);
41
42 XCN xcn = person.getHapiObject();
43 metaDataAssert(
44 isNotEmpty(xcn.getXcn1_IDNumber().getValue()) ||
45 isNotEmpty(xcn.getXcn2_FamilyName().getFn1_Surname().getValue()),
46 PERSON_MISSING_NAME_AND_ID, hl7xcn);
47
48
49
50 HD hd = xcn.getXcn9_AssigningAuthority();
51 boolean condition = !isNotEmpty(xcn.getXcn1_IDNumber().getValue()) || isNotEmptyField(hd);
52 metaDataAssert(condition, PERSON_HD_MISSING, hl7xcn);
53
54 if (! isEmptyField(hd)) {
55 HD_VALIDATOR.validate(hd, hl7xcn);
56 }
57 }
58 }