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.CX;
19 import ca.uhn.hl7v2.model.v25.datatype.HD;
20 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
21 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
22
23 import static org.apache.commons.lang3.StringUtils.*;
24 import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isEmptyField;
25 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CX_NEEDS_ID;
26 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CX_TOO_MANY_COMPONENTS;
27 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
28
29
30
31
32
33 public class CXValidator implements ValueValidator {
34 private static final HDValidator HD_VALIDATOR = new HDValidator();
35
36 private final boolean assigningAuthorityRequired;
37
38 public CXValidator(boolean assigningAuthorityRequired) {
39 this.assigningAuthorityRequired = assigningAuthorityRequired;
40 }
41
42
43 @Override
44 public void validate(String hl7CX) throws XDSMetaDataException {
45 Identifiable identifiable = Hl7v2Based.parse(hl7CX, Identifiable.class);
46 metaDataAssert(identifiable != null, CX_NEEDS_ID);
47
48 CX cx = identifiable.getHapiObject();
49
50
51 metaDataAssert(isEmpty(cx.getCx2_CheckDigit().getValue()), CX_TOO_MANY_COMPONENTS);
52 metaDataAssert(isEmpty(cx.getCx3_CheckDigitScheme().getValue()), CX_TOO_MANY_COMPONENTS);
53 metaDataAssert(isEmpty(cx.getCx5_IdentifierTypeCode().getValue()), CX_TOO_MANY_COMPONENTS);
54 metaDataAssert(isEmptyField(cx.getCx6_AssigningFacility()), CX_TOO_MANY_COMPONENTS);
55 metaDataAssert(isEmpty(cx.getCx7_EffectiveDate().getValue()), CX_TOO_MANY_COMPONENTS);
56 metaDataAssert(isEmpty(cx.getCx8_ExpirationDate().getValue()), CX_TOO_MANY_COMPONENTS);
57 metaDataAssert(isEmptyField(cx.getCx9_AssigningJurisdiction()), CX_TOO_MANY_COMPONENTS);
58 metaDataAssert(isEmptyField(cx.getCx10_AssigningAgencyOrDepartment()), CX_TOO_MANY_COMPONENTS);
59
60
61 metaDataAssert(isNotEmpty(cx.getCx1_IDNumber().getValue()), CX_NEEDS_ID, hl7CX);
62
63 HD assigningAuthority = cx.getCx4_AssigningAuthority();
64 if (assigningAuthorityRequired || (! isEmptyField(assigningAuthority))) {
65 HD_VALIDATOR.validate(assigningAuthority, hl7CX);
66 }
67 }
68 }