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.ReferenceId;
22
23 import static org.apache.commons.lang3.StringUtils.isEmpty;
24 import static org.apache.commons.lang3.StringUtils.isNotEmpty;
25 import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isEmptyField;
26 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
27 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
28
29
30
31
32
33 public class CXiValidator implements ValueValidator {
34
35 @Override
36 public void validate(String hl7CX) throws XDSMetaDataException {
37 ReferenceId referenceId = Hl7v2Based.parse(hl7CX, ReferenceId.class);
38 metaDataAssert(referenceId != null, CX_NEEDS_ID);
39
40 CX cx = referenceId.getHapiObject();
41
42
43 metaDataAssert(isEmpty(cx.getCx2_CheckDigit().getValue()), CXI_TOO_MANY_COMPONENTS);
44 metaDataAssert(isEmpty(cx.getCx3_CheckDigitScheme().getValue()), CXI_TOO_MANY_COMPONENTS);
45 metaDataAssert(isEmptyField(cx.getCx6_AssigningFacility()), CXI_TOO_MANY_COMPONENTS);
46 metaDataAssert(isEmpty(cx.getCx7_EffectiveDate().getValue()), CXI_TOO_MANY_COMPONENTS);
47 metaDataAssert(isEmpty(cx.getCx8_ExpirationDate().getValue()), CXI_TOO_MANY_COMPONENTS);
48 metaDataAssert(isEmptyField(cx.getCx9_AssigningJurisdiction()), CXI_TOO_MANY_COMPONENTS);
49 metaDataAssert(isEmptyField(cx.getCx10_AssigningAgencyOrDepartment()), CXI_TOO_MANY_COMPONENTS);
50
51
52 metaDataAssert(isNotEmpty(cx.getCx1_IDNumber().getValue()), CX_NEEDS_ID, hl7CX);
53 metaDataAssert(isNotEmpty(cx.getCx5_IdentifierTypeCode().getValue()), CXI_NEEDS_ID_TYPE_CODE, hl7CX);
54
55 HD assigningAuthority = cx.getCx4_AssigningAuthority();
56 if (! isEmptyField(assigningAuthority)) {
57 boolean cx41filled = isNotEmpty(assigningAuthority.getHd1_NamespaceID().getValue());
58 boolean cx42filled = isNotEmpty(assigningAuthority.getHd2_UniversalID().getValue());
59 boolean cx43filled = isNotEmpty(assigningAuthority.getHd3_UniversalIDType().getValue());
60 metaDataAssert(cx41filled || (cx42filled && cx43filled), CXI_INCOMPLETE_ASSIGNING_AUTHORITY);
61 }
62 }
63
64 }