Add tests for evaluate transforms using json StructureMap (#807)
* Add tests for evaluate transforms using json StructureMap Fixes issues/802 * Reduce test chatter, fix missing ',' in EVALUATE render Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
parent
cd7142faa1
commit
8a8bbb7308
|
@ -31,7 +31,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
|
|||
@Test
|
||||
public void testParseRuleName() throws IOException, FHIRException {
|
||||
StructureMapUtilities scu = new StructureMapUtilities(context, this);
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "fml", "ActivityDefinition.map");
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "ActivityDefinition.map");
|
||||
StructureMap structureMap = scu.parse(fileMap, "ActivityDefinition3To4");
|
||||
|
||||
// StructureMap/ActivityDefinition3to4: StructureMap.group[3].rule[2].name error id value '"expression"' is not valid
|
||||
|
@ -59,7 +59,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
|
|||
@Test
|
||||
public void testSyntax() throws IOException, FHIRException {
|
||||
StructureMapUtilities scu = new StructureMapUtilities(context, this);
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "fml", "syntax.map");
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map");
|
||||
System.out.println(fileMap);
|
||||
|
||||
StructureMap structureMap = scu.parse(fileMap, "Syntax");
|
||||
|
|
|
@ -338,18 +338,19 @@ public class StructureMapUtilities {
|
|||
for (int i = 0; i < indent; i++)
|
||||
b.append(' ');
|
||||
boolean canBeAbbreviated = checkisSimple(r);
|
||||
|
||||
boolean first = true;
|
||||
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
b.append(", ");
|
||||
renderSource(b, rs, canBeAbbreviated);
|
||||
{
|
||||
boolean first = true;
|
||||
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
b.append(", ");
|
||||
renderSource(b, rs, canBeAbbreviated);
|
||||
}
|
||||
}
|
||||
if (r.getTarget().size() > 1) {
|
||||
b.append(" -> ");
|
||||
first = true;
|
||||
boolean first = true;
|
||||
for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
|
||||
if (first)
|
||||
first = false;
|
||||
|
@ -379,7 +380,7 @@ public class StructureMapUtilities {
|
|||
} else {
|
||||
if (r.hasDependent()) {
|
||||
b.append(" then ");
|
||||
first = true;
|
||||
boolean first = true;
|
||||
for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) {
|
||||
if (first)
|
||||
first = false;
|
||||
|
@ -524,6 +525,7 @@ public class StructureMapUtilities {
|
|||
b.append(rt.getTransform().toCode());
|
||||
b.append("(");
|
||||
b.append(((IdType) rt.getParameter().get(0).getValue()).asStringValue());
|
||||
b.append(", ");
|
||||
b.append(((StringType) rt.getParameter().get(1).getValue()).asStringValue());
|
||||
b.append(")");
|
||||
} else {
|
||||
|
@ -1679,7 +1681,7 @@ public class StructureMapUtilities {
|
|||
case EVALUATE:
|
||||
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
|
||||
if (expr == null) {
|
||||
expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()));
|
||||
expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()));
|
||||
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
|
||||
}
|
||||
List<Base> v = fpe.evaluate(vars, null, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr);
|
||||
|
|
|
@ -31,7 +31,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
|
|||
@Test
|
||||
public void testParseRuleName() throws IOException, FHIRException {
|
||||
StructureMapUtilities scu = new StructureMapUtilities(context, this);
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "fml", "ActivityDefinition.map");
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "ActivityDefinition.map");
|
||||
StructureMap structureMap = scu.parse(fileMap, "ActivityDefinition3To4");
|
||||
|
||||
// StructureMap/ActivityDefinition3to4: StructureMap.group[3].rule[2].name error id value '"expression"' is not valid
|
||||
|
@ -59,7 +59,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
|
|||
@Test
|
||||
public void testSyntax() throws IOException, FHIRException {
|
||||
StructureMapUtilities scu = new StructureMapUtilities(context, this);
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "fml", "syntax.map");
|
||||
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map");
|
||||
System.out.println(fileMap);
|
||||
|
||||
StructureMap structureMap = scu.parse(fileMap, "Syntax");
|
||||
|
@ -71,6 +71,8 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
|
|||
assertSerializeDeserialize(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package org.hl7.fhir.r5.test;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -35,7 +32,7 @@ import org.w3c.dom.Document;
|
|||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class FHIRMappingLanguageTests {
|
||||
public class StructureMappingTests {
|
||||
|
||||
private List<Resource> outputs = new ArrayList<Resource>();
|
||||
|
||||
|
@ -45,7 +42,7 @@ public class FHIRMappingLanguageTests {
|
|||
|
||||
public static Stream<Arguments> data()
|
||||
throws FileNotFoundException, IOException, ParserConfigurationException, SAXException {
|
||||
Document tests = XMLUtil.parseToDom(TestingUtilities.loadTestResource("r5", "fml", "manifest.xml"));
|
||||
Document tests = XMLUtil.parseToDom(TestingUtilities.loadTestResource("r5", "structure-mapping", "manifest.xml"));
|
||||
Element test = XMLUtil.getFirstChild(tests.getDocumentElement());
|
||||
List<Arguments> objects = new ArrayList<>();
|
||||
while (test != null && test.getNodeName().equals("test")) {
|
||||
|
@ -77,22 +74,30 @@ public class FHIRMappingLanguageTests {
|
|||
context.setValidatorFactory(new InstanceValidatorFactory());
|
||||
}
|
||||
}
|
||||
|
||||
private StructureMap loadStructureMap(String map) throws Exception {
|
||||
String stringMap = TestingUtilities.loadTestResource("r5", "structure-mapping", map);
|
||||
if (map.endsWith(".json")) {
|
||||
return (StructureMap) new org.hl7.fhir.r5.formats.JsonParser().parse(stringMap);
|
||||
} else if (map.endsWith(".map")) {
|
||||
return new StructureMapUtilities(context).parse(stringMap, map);
|
||||
}
|
||||
throw new Exception("File extension for StuctureMap is not a recognized type (should be one of: '.map', '.json')");
|
||||
}
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@MethodSource("data")
|
||||
public void test(String name, String source, String map, String output) throws Exception {
|
||||
|
||||
byte[] byteSource = TestingUtilities.loadTestResourceBytes("r5", "fml", source);
|
||||
String stringMap = TestingUtilities.loadTestResource("r5", "fml", map);
|
||||
String outputJson = TestingUtilities.loadTestResource("r5", "fml", output);
|
||||
String fileOutputRes = TestingUtilities.tempFile("fml", output) + ".out";
|
||||
String fileOutputResOrig = TestingUtilities.tempFile("fml", output) + ".orig.out";
|
||||
byte[] byteSource = TestingUtilities.loadTestResourceBytes("r5", "structure-mapping", source);
|
||||
|
||||
String outputJson = TestingUtilities.loadTestResource("r5", "structure-mapping", output);
|
||||
String fileOutputRes = TestingUtilities.tempFile("structure-mapping", output) + ".out";
|
||||
String fileOutputResOrig = TestingUtilities.tempFile("structure-mapping", output) + ".orig.out";
|
||||
ByteArrayOutputStream s = null;
|
||||
outputs.clear();
|
||||
|
||||
String msg = null;
|
||||
try {
|
||||
StructureMap r = new StructureMapUtilities(context).parse(stringMap, map);
|
||||
StructureMap r = loadStructureMap(map);
|
||||
context.cacheResource(r);
|
||||
org.hl7.fhir.r5.elementmodel.Element element = validationEngine.transform(byteSource, FhirFormat.JSON, r.getUrl());
|
||||
s = new ByteArrayOutputStream();
|
Loading…
Reference in New Issue