Skip to content

Commit

Permalink
#430: enable CP-ITI-1292 validation of CXi
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Stanojevic committed Oct 31, 2023
1 parent 3e9f1ac commit f6bbc19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand All @@ -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) {
Expand Down

0 comments on commit f6bbc19

Please sign in to comment.