Skip to content

Commit

Permalink
#441: depend on "XDS_VALIDATION_CP_1292" system property
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ohr committed Feb 19, 2024
1 parent 9f7eeca commit 7fd09f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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^^^^";
Expand Down

0 comments on commit 7fd09f5

Please sign in to comment.