diff --git a/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/metadata/XdsHl7v2Renderer.java b/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/metadata/XdsHl7v2Renderer.java index 01bfccc8be..b0a20958f2 100644 --- a/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/metadata/XdsHl7v2Renderer.java +++ b/commons/ihe/xds/src/main/java/org/openehealth/ipf/commons/ihe/xds/core/metadata/XdsHl7v2Renderer.java @@ -23,6 +23,7 @@ import ca.uhn.hl7v2.parser.EncodingCharacters; import ca.uhn.hl7v2.parser.Escaping; import lombok.SneakyThrows; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import java.util.*; @@ -35,6 +36,8 @@ */ public abstract class XdsHl7v2Renderer { + static final String XDS_VALIDATION_CP_1292_PROPERTY = "XDS_VALIDATION_CP_1292"; + /** * Encoding characters for HL7 v2 messages. */ @@ -78,7 +81,11 @@ private static void addInclusion( static { addInclusion(CE.class, null, 1, 3); addInclusion(CX.class, Identifiable.class, 1, 4); - addInclusion(CX.class, ReferenceId.class, 1, 4, 5, 6); + if (isCP1292ValidationEnabled()) { + addInclusion(CX.class, ReferenceId.class, 1, 4, 5, 6); + } else { + addInclusion(CX.class, ReferenceId.class, 1, 4, 5); + } addInclusion(HD.class, AssigningAuthority.class, 2, 3); addInclusion(HD.class, CXiAssigningAuthority.class, 1, 2, 3); addInclusion(HD.class, Identifiable.class, 2, 3); @@ -87,6 +94,10 @@ private static void addInclusion( addInclusion(XTN.class, null, 2, 3, 4, 5, 6, 7, 8, 12); } + private static boolean isCP1292ValidationEnabled() { + String cp1292Value = System.getProperty(XDS_VALIDATION_CP_1292_PROPERTY, "false"); + return BooleanUtils.toBoolean(cp1292Value); + } private XdsHl7v2Renderer() { throw new IllegalStateException("cannot instantiate helper class"); diff --git a/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/transform/hl7/XdsHl7v2RenderingTest.java b/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/transform/hl7/XdsHl7v2RenderingTest.java index c2ae0ca21f..e8205b4ca5 100644 --- a/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/transform/hl7/XdsHl7v2RenderingTest.java +++ b/commons/ihe/xds/src/test/java/org/openehealth/ipf/commons/ihe/xds/core/transform/hl7/XdsHl7v2RenderingTest.java @@ -66,10 +66,26 @@ public void testReferenceIdRendering() { assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId1)); var cx2 = "1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015^&&^^"; var referenceId2 = Hl7v2Based.parse(cx2, ReferenceId.class); - assertEquals("1^^^41&42&43^51^&1.2.40.0.34.3.1.2.99.1000001&ISO", Hl7v2Based.render(referenceId2)); + assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId2)); assertEquals("1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015", Hl7v2Based.rawRender(referenceId2)); } + @Test + public void testReferenceIdRenderingCp1292() { + System.setProperty("XDS_VALIDATION_CP_1292", "true"); + try { + var cx1 = "1^2^3^41&42&43&44&45&46^51&52^^^&&^^"; + var referenceId1 = Hl7v2Based.parse(cx1, ReferenceId.class); + assertEquals("1^^^41&42&43^51", Hl7v2Based.render(referenceId1)); + var cx2 = "1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015^&&^^"; + var referenceId2 = Hl7v2Based.parse(cx2, ReferenceId.class); + assertEquals("1^^^41&42&43^51^&1.2.40.0.34.3.1.2.99.1000001&ISO", Hl7v2Based.render(referenceId2)); + assertEquals("1^2^3^41&42&43&44&45&46^51&52^&1.2.40.0.34.3.1.2.99.1000001&ISO^2015", Hl7v2Based.rawRender(referenceId2)); + } finally { + System.clearProperty("XDS_VALIDATION_CP_1292"); + } + } + @Test public void testEmptyAssignignAuthority() { var cx = "1^^^ABCD^^^^";