diff --git a/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidator.java b/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidator.java index 58c02decb2..b2811d9911 100644 --- a/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidator.java +++ b/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidator.java @@ -15,13 +15,18 @@ */ package org.openehealth.ipf.commons.ihe.xds.core.validate; +import org.apache.commons.lang3.BooleanUtils; import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based; import org.openehealth.ipf.commons.ihe.xds.core.metadata.ReferenceId; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isEmptyField; -import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*; +import static org.openehealth.ipf.commons.ihe.xds.core.validate.HL7ValidationUtils.isNotEmptyField; +import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CXI_INCOMPLETE_ASSIGNING_AUTHORITY; +import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CXI_NEEDS_ID_TYPE_CODE; +import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CXI_TOO_MANY_COMPONENTS; +import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.CX_NEEDS_ID; import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert; /** @@ -30,6 +35,9 @@ */ public class CXiValidator implements ValueValidator { + private static final String XDS_VALIDATION_CP_1292_PROPERTY = "XDS_VALIDATION_CP_1292"; + private static final HDValidator HD_VALIDATOR = new HDValidator(); + @Override public void validate(String hl7CX) throws XDSMetaDataException { var referenceId = Hl7v2Based.parse(hl7CX, ReferenceId.class); @@ -40,7 +48,11 @@ public void validate(String hl7CX) throws XDSMetaDataException { // prohibited fields metaDataAssert(isEmpty(cx.getCx2_CheckDigit().getValue()), CXI_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(cx.getCx3_CheckDigitScheme().getValue()), CXI_TOO_MANY_COMPONENTS); - metaDataAssert(isEmptyField(cx.getCx6_AssigningFacility()), CXI_TOO_MANY_COMPONENTS); + if (isCP1292ValidationEnabled() && isNotEmptyField(cx.getCx6_AssigningFacility())) { + HD_VALIDATOR.validate(cx.getCx6_AssigningFacility(), hl7CX); + } else { + metaDataAssert(isEmptyField(cx.getCx6_AssigningFacility()), CXI_TOO_MANY_COMPONENTS); + } metaDataAssert(isEmpty(cx.getCx7_EffectiveDate().getValue()), CXI_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(cx.getCx8_ExpirationDate().getValue()), CXI_TOO_MANY_COMPONENTS); metaDataAssert(isEmptyField(cx.getCx9_AssigningJurisdiction()), CXI_TOO_MANY_COMPONENTS); @@ -59,4 +71,9 @@ public void validate(String hl7CX) throws XDSMetaDataException { } } + private static boolean isCP1292ValidationEnabled() { + String cp1292Value = System.getProperty(XDS_VALIDATION_CP_1292_PROPERTY, "false"); + return BooleanUtils.toBoolean(cp1292Value); + } + } diff --git a/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidatorTest.java b/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidatorTest.java index 029238e4d4..9bc1cabf98 100644 --- a/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidatorTest.java +++ b/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/validate/CXiValidatorTest.java @@ -34,6 +34,24 @@ public void testValidateGoodCases() throws XDSMetaDataException { validator.validate("11379^^^ABCD^urn:ihe:iti:xds:2013:uniqueId^^^^"); } + @Test + public void testValidateCp1292() throws XDSMetaDataException { + String value = "11379^^^ABCD^urn:ihe:iti:xds:2013:uniqueId^&1.3.6.1.4.1.21367.2017.2.6.19&ISO^"; + String invalidCx6value = "11379^^^ABCD^urn:ihe:iti:xds:2013:uniqueId^&1.3.6.1.4.1.21367.2017.2.6.19&SORYSO^"; + String propertyName = "XDS_VALIDATION_CP_1292"; + System.setProperty(propertyName, "1"); + validator.validate(value); + assertFails(invalidCx6value); + System.setProperty(propertyName, "true"); + validator.validate(value); + assertFails(invalidCx6value); + System.setProperty(propertyName, "false"); + assertFails(value); + System.setProperty(propertyName, "0"); + assertFails(value); + System.clearProperty(propertyName); + } + @Test public void testValidateBadCase() throws XDSMetaDataException { assertFails(""); @@ -43,6 +61,7 @@ public void testValidateBadCase() throws XDSMetaDataException { assertFails("^^^&1.3.6367.3.7&ISO^urn:ihe:iti:xds:2013:uniqueId^^^"); assertFails("11379^^^&1.3.6367.3.7&ISO^urn:ihe:iti:xds:2013:uniqueId^wrong"); assertFails("11379^^^&1.3.6367.3.7&ISO^^^"); + assertFails("11379^^^&1.3.6367.3.7&ISO^^&urn:oid:1.3.6.1.4.1.21367.2017.2.6.19&ISO^"); } private static void assertFails(String value) {