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 static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
19 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.*;
20 import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isEmptyField;
21 import static org.apache.commons.lang3.StringUtils.*;
22
23 import ca.uhn.hl7v2.model.v25.datatype.HD;
24 import ca.uhn.hl7v2.model.v25.datatype.XON;
25 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
26 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization;
27
28
29
30
31
32 public class XONValidator implements ValueValidator {
33 private static final OIDValidator OID_VALIDATOR = new OIDValidator();
34 private static final HDValidator HD_VALIDATOR = new HDValidator();
35
36 @Override
37 public void validate(String hl7XON) throws XDSMetaDataException {
38 Organization organization = Hl7v2Based.parse(hl7XON, Organization.class);
39 metaDataAssert(organization != null, ORGANIZATION_NAME_MISSING, hl7XON);
40
41 XON xon = organization.getHapiObject();
42 metaDataAssert(isNotEmpty(xon.getXon1_OrganizationName().getValue()), ORGANIZATION_NAME_MISSING, hl7XON);
43
44 HD hd = xon.getXon6_AssigningAuthority();
45 if (isEmptyField(hd)) {
46 String idNumber = xon.getXon10_OrganizationIdentifier().getValue();
47 if (isNotEmpty(idNumber)) {
48 OID_VALIDATOR.validate(idNumber);
49 }
50 } else {
51 HD_VALIDATOR.validate(hd, hl7XON);
52 }
53
54 metaDataAssert(countMatches(hl7XON, "^") <= 9, ORGANIZATION_TOO_MANY_COMPONENTS);
55 metaDataAssert(isEmpty(xon.getXon2_OrganizationNameTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
56 metaDataAssert(isEmpty(xon.getXon3_IDNumber().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
57 metaDataAssert(isEmpty(xon.getXon4_CheckDigit().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
58 metaDataAssert(isEmpty(xon.getXon5_CheckDigitScheme().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
59 metaDataAssert(isEmpty(xon.getXon7_IdentifierTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
60 metaDataAssert(isEmptyField(xon.getXon8_AssigningFacility()), ORGANIZATION_TOO_MANY_COMPONENTS);
61 metaDataAssert(isEmpty(xon.getXon9_NameRepresentationCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
62 }
63 }