mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-12 07:44:43 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d3d9f52ea1
@ -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");
|
||||
|
@ -2,10 +2,7 @@ package org.hl7.fhir.r5.utils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
@ -41,20 +38,9 @@ import java.util.Map;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.model.BackboneElement;
|
||||
import org.hl7.fhir.r5.model.Base;
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.*;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleLinkComponent;
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.DomainResource;
|
||||
import org.hl7.fhir.r5.model.Element;
|
||||
import org.hl7.fhir.r5.model.ExpressionNode;
|
||||
import org.hl7.fhir.r5.model.IntegerType;
|
||||
import org.hl7.fhir.r5.model.Property;
|
||||
import org.hl7.fhir.r5.model.Reference;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.graphql.Argument;
|
||||
import org.hl7.fhir.utilities.graphql.Argument.ArgumentListStatus;
|
||||
@ -571,6 +557,10 @@ public class GraphQLEngine implements IGraphQLEngine {
|
||||
if (!isPrimitive(prop.getTypeCode()) && sel.getField().getName().startsWith("_"))
|
||||
throw new EGraphQLException("Unknown property "+sel.getField().getName()+" on "+source.fhirType());
|
||||
|
||||
if ("id".equals(prop.getName()) && context != null) {
|
||||
prop.getValues().set(0, new IdType(context.getIdPart()));
|
||||
}
|
||||
|
||||
List<Base> vl = filter(context, prop, sel.getField().getName(), sel.getField().getArguments(), prop.getValues(), sel.getField().getName().startsWith("_"));
|
||||
if (!vl.isEmpty())
|
||||
processValues(context, sel, prop, target, vl, sel.getField().getName().startsWith("_"), inheritedList, suffix);
|
||||
|
@ -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) {
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
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;
|
||||
@ -34,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>();
|
||||
|
||||
@ -44,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")) {
|
||||
@ -76,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();
|
||||
@ -101,7 +107,8 @@ public class FHIRMappingLanguageTests {
|
||||
new org.hl7.fhir.r5.elementmodel.XmlParser(context).compose(element, s, IParser.OutputStyle.PRETTY, null);
|
||||
context.dropResource(r);
|
||||
} catch (Exception e) {
|
||||
assertTrue(e.getMessage(), false);
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
if (output.endsWith("json")) {
|
||||
msg = CompareUtilities.checkJsonSrcIsSame(s.toString(), outputJson);
|
Loading…
x
Reference in New Issue
Block a user