From 5cc8dd7974dc479ee711ae66b9a7a4a02d4375ed Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 23 Feb 2022 19:02:45 -0500 Subject: [PATCH 1/4] Fix incorrect fromCode for R4/DSTU2 --- .../src/main/java/org/hl7/fhir/r4/model/FhirPublication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/FhirPublication.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/FhirPublication.java index bc8dfe581..6ccf8fd4b 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/FhirPublication.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/FhirPublication.java @@ -49,7 +49,7 @@ public enum FhirPublication { R4; public static FhirPublication fromCode(String v) { - if (VersionUtilities.isR4Ver(v)) + if (VersionUtilities.isR2Ver(v)) return FhirPublication.DSTU2; if ("1.0".equals(v)) return FhirPublication.DSTU2; From 474fc014c426137a0454b60051c64f34e8bb7b0c Mon Sep 17 00:00:00 2001 From: Mark Iantorno Date: Fri, 25 Feb 2022 02:36:33 +0000 Subject: [PATCH 2/4] Updating test case dependency to v1.1.90 ***NO_CI*** --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0c6484eb3..8645fc553 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.4.0 - 1.1.89 + 1.1.90 5.7.1 1.7.1 3.0.0-M5 From baac4ac1a8ac581b41d84833a7a39debe1dea1f6 Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 25 Feb 2022 11:25:27 -0500 Subject: [PATCH 3/4] Fix + initial test --- .../hl7/fhir/dstu3/utils/FHIRPathEngine.java | 2 +- .../hl7/fhir/dstu3/utils/FhirPathTests.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathEngine.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathEngine.java index 7794fc858..54191747f 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathEngine.java @@ -2219,7 +2219,7 @@ public class FHIRPathEngine { if (!Utilities.noString(f)) { - if (exp.getParameters().size() != 2) { + if (exp.getParameters().size() == 2) { String t = convertToString(execute(context, focus, exp.getParameters().get(0), true)); String r = convertToString(execute(context, focus, exp.getParameters().get(1), true)); diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java new file mode 100644 index 000000000..800668cc6 --- /dev/null +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java @@ -0,0 +1,49 @@ +package org.hl7.fhir.dstu3.utils; + + +import org.hl7.fhir.dstu3.context.IWorkerContext; +import org.hl7.fhir.dstu3.model.Base; +import org.hl7.fhir.dstu3.model.ExpressionNode; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class FhirPathTests { + + @Mock + IWorkerContext iWorkerContext; + + @Mock + Object appContext; + + @Mock + Base resource; + + @Mock + Base base; + + @Test + public void testFuncReplaceParamSize() { + FHIRPathEngine engine = Mockito.spy(new FHIRPathEngine(iWorkerContext)); + + ExpressionNode expressionNode = new ExpressionNode(0); + expressionNode.setKind(ExpressionNode.Kind.Function); + expressionNode.setFunction(ExpressionNode.Function.Replace); + + ExpressionNode expressionNodeB = new ExpressionNode(1); + expressionNodeB.setKind(ExpressionNode.Kind.Function); + expressionNodeB.setFunction(ExpressionNode.Function.Empty); + + ExpressionNode expressionNodeC = new ExpressionNode(2); + expressionNodeC.setKind(ExpressionNode.Kind.Function); + expressionNodeC.setFunction(ExpressionNode.Function.Empty); + + expressionNode.getParameters().add(expressionNodeB); + expressionNode.getParameters().add(expressionNodeC); + engine.evaluate(appContext, resource, base, expressionNode); + + } +} \ No newline at end of file From f2e9f1247be9e581a3580303db7b5c22bb13b442 Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 25 Feb 2022 13:11:24 -0500 Subject: [PATCH 4/4] Add assertions to test case --- .../org/hl7/fhir/dstu3/utils/FhirPathTests.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java index 800668cc6..f595e238a 100644 --- a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathTests.java @@ -1,15 +1,22 @@ package org.hl7.fhir.dstu3.utils; - import org.hl7.fhir.dstu3.context.IWorkerContext; import org.hl7.fhir.dstu3.model.Base; import org.hl7.fhir.dstu3.model.ExpressionNode; +import org.hl7.fhir.dstu3.model.StringType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; + @ExtendWith(MockitoExtension.class) public class FhirPathTests { @@ -43,7 +50,12 @@ public class FhirPathTests { expressionNode.getParameters().add(expressionNodeB); expressionNode.getParameters().add(expressionNodeC); - engine.evaluate(appContext, resource, base, expressionNode); + List result = engine.evaluate(appContext, resource, base, expressionNode); + assertEquals(1, result.size()); + Base onlyResult = result.get(0); + assertTrue(onlyResult instanceof StringType); + assertEquals("base", ((StringType)result.get(0)).asStringValue()); + Mockito.verify(engine, times(2)).convertToString(any()); } } \ No newline at end of file