From ac33590b960006a51f825b9daed3a48a911aa71a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 29 Aug 2023 17:34:03 +0200 Subject: [PATCH] #1412 - fix out of memory issues --- .../hl7/fhir/dstu3/utils/FHIRPathEngine.java | 121 ++-------- .../dstu3/utils/FHIRPathUtilityClasses.java | 110 +++++++++ .../dstu3/utils/StructureMapUtilities.java | 1 + .../dstu3/test/SnapShotGenerationTests.java | 1 + .../org/hl7/fhir/r4/utils/FHIRPathEngine.java | 194 +--------------- .../fhir/r4/utils/FHIRPathUtilityClasses.java | 210 ++++++++++++++++++ .../org/hl7/fhir/r4/utils/LiquidEngine.java | 1 + .../fhir/r4/utils/StructureMapUtilities.java | 1 + .../org/hl7/fhir/r4/test/FHIRPathTests.java | 1 + .../fhir/r4/test/SnapShotGenerationTests.java | 1 + .../r4b/comparison/ComparisonRenderer.java | 1 + .../hl7/fhir/r4b/utils/FHIRPathEngine.java | 188 +--------------- .../r4b/utils/FHIRPathUtilityClasses.java | 198 +++++++++++++++++ .../org/hl7/fhir/r4b/utils/LiquidEngine.java | 1 + .../structuremap/FFHIRPathHostServices.java | 1 + .../structuremap/StructureMapUtilities.java | 1 + .../org/hl7/fhir/r4b/test/FHIRPathTests.java | 1 + .../r4b/test/SnapShotGenerationTests.java | 1 + .../r5/comparison/ComparisonRenderer.java | 1 + .../org/hl7/fhir/r5/utils/FHIRPathEngine.java | 180 +-------------- .../fhir/r5/utils/FHIRPathUtilityClasses.java | 192 ++++++++++++++++ .../org/hl7/fhir/r5/utils/LiquidEngine.java | 1 + .../structuremap/FFHIRPathHostServices.java | 1 + .../org/hl7/fhir/r5/test/FHIRPathTests.java | 1 + .../fhir/r5/test/SnapShotGenerationTests.java | 1 + .../instance/InstanceValidator.java | 3 +- .../tests/SnapShotGenerationXTests.java | 1 + .../validation/tests/ValidationTests.java | 1 + 28 files changed, 772 insertions(+), 643 deletions(-) create mode 100644 org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathUtilityClasses.java create mode 100644 org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathUtilityClasses.java create mode 100644 org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathUtilityClasses.java create mode 100644 org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathUtilityClasses.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 8f67fa63f..9996374c2 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 @@ -37,7 +37,9 @@ import org.hl7.fhir.dstu3.model.TimeType; import org.hl7.fhir.dstu3.model.TypeDetails; import org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType; import org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException; -import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails; +import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails; +import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.ExecutionContext; +import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.ExecutionTypeContext; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.PathEngineException; @@ -93,27 +95,7 @@ public class FHIRPathEngine { // if the fhir path expressions are allowed to use constants beyond those defined in the specification // the application can implement them by providing a constant resolver public interface IEvaluationContext { - public class FunctionDetails { - private String description; - private int minParameters; - private int maxParameters; - public FunctionDetails(String description, int minParameters, int maxParameters) { - super(); - this.description = description; - this.minParameters = minParameters; - this.maxParameters = maxParameters; - } - public String getDescription() { - return description; - } - public int getMinParameters() { - return minParameters; - } - public int getMaxParameters() { - return maxParameters; - } - - } + /** * A constant reference - e.g. a reference to a name that must be resolved in context. @@ -554,63 +536,6 @@ public class FHIRPathEngine { return ""; } - private class ExecutionContext { - private Object appInfo; - private Base resource; - private Base context; - private Base thisItem; - private Map aliases; - - public ExecutionContext(Object appInfo, Base resource, Base context, Map aliases, Base thisItem) { - this.appInfo = appInfo; - this.context = context; - this.resource = resource; - this.aliases = aliases; - this.thisItem = thisItem; - } - public Base getResource() { - return resource; - } - public Base getThisItem() { - return thisItem; - } - public void addAlias(String name, List focus) throws FHIRException { - if (aliases == null) - aliases = new HashMap(); - else - aliases = new HashMap(aliases); // clone it, since it's going to change - if (focus.size() > 1) - throw new FHIRException("Attempt to alias a collection, not a singleton"); - aliases.put(name, focus.size() == 0 ? null : focus.get(0)); - } - public Base getAlias(String name) { - return aliases == null ? null : aliases.get(name); - } - } - - private class ExecutionTypeContext { - private Object appInfo; - private String resource; - private String context; - private TypeDetails thisItem; - - - public ExecutionTypeContext(Object appInfo, String resource, String context, TypeDetails thisItem) { - super(); - this.appInfo = appInfo; - this.resource = resource; - this.context = context; - this.thisItem = thisItem; - - } - public String getResource() { - return resource; - } - public TypeDetails getThisItem() { - return thisItem; - } - } - private ExpressionNode parseExpression(FHIRLexer lexer, boolean proximal) throws FHIRLexerException { ExpressionNode result = new ExpressionNode(lexer.nextId()); SourceLocation c = lexer.getCurrentStartLocation(); @@ -1048,7 +973,7 @@ public class FHIRPathEngine { } else if (constant.startsWith("%")) { return resolveConstant(context, constant); } else if (constant.startsWith("@")) { - return processDateConstant(context.appInfo, constant.substring(1)); + return processDateConstant(context.getAppInfo(), constant.substring(1)); } else { return new StringType(constant); } @@ -1081,11 +1006,11 @@ public class FHIRPathEngine { else if (s.equals("%ucum")) return new StringType("http://unitsofmeasure.org"); else if (s.equals("%resource")) { - if (context.resource == null) + if (context.getResource() == null) throw new PathEngineException("Cannot use %resource in this context"); - return context.resource; + return context.getResource(); } else if (s.equals("%context")) { - return context.context; + return context.getContext(); } else if (s.equals("%us-zip")) return new StringType("[0-9]{5}(-[0-9]{4}){0,1}"); else if (s.startsWith("%\"vs-")) @@ -1097,7 +1022,7 @@ public class FHIRPathEngine { else if (hostServices == null) throw new PathEngineException("Unknown fixed constant '"+s+"'"); else - return hostServices.resolveConstant(context.appInfo, s.substring(1)); + return hostServices.resolveConstant(context.getAppInfo(), s.substring(1)); } @@ -1776,11 +1701,11 @@ public class FHIRPathEngine { else if (s.equals("%ucum")) return new TypeDetails(CollectionStatus.SINGLETON, "string"); else if (s.equals("%resource")) { - if (context.resource == null) + if (context.getResource() == null) throw new PathEngineException("%resource cannot be used in this context"); - return new TypeDetails(CollectionStatus.SINGLETON, context.resource); + return new TypeDetails(CollectionStatus.SINGLETON, context.getResource()); } else if (s.equals("%context")) { - return new TypeDetails(CollectionStatus.SINGLETON, context.context); + return new TypeDetails(CollectionStatus.SINGLETON, context.getContext()); } else if (s.equals("%map-codes")) return new TypeDetails(CollectionStatus.SINGLETON, "string"); else if (s.equals("%us-zip")) @@ -1794,7 +1719,7 @@ public class FHIRPathEngine { else if (hostServices == null) throw new PathEngineException("Unknown fixed constant type for '"+s+"'"); else - return hostServices.resolveConstantType(context.appInfo, s); + return hostServices.resolveConstantType(context.getAppInfo(), s); } private List execute(ExecutionContext context, Base item, ExpressionNode exp, boolean atEntry) throws FHIRException { @@ -1804,8 +1729,8 @@ public class FHIRPathEngine { result.add(item); } else getChildrenByName(item, exp.getName(), result); - if (result.size() == 0 && atEntry && context.appInfo != null) { - Base temp = hostServices.resolveConstant(context.appInfo, exp.getName()); + if (result.size() == 0 && atEntry && context.getAppInfo() != null) { + Base temp = hostServices.resolveConstant(context.getAppInfo(), exp.getName()); if (temp != null) { result.add(temp); } @@ -1816,7 +1741,7 @@ public class FHIRPathEngine { private TypeDetails executeContextType(ExecutionTypeContext context, String name) throws PathEngineException, DefinitionException { if (hostServices == null) throw new PathEngineException("Unable to resolve context reference since no host services are provided"); - return hostServices.resolveConstantType(context.appInfo, name); + return hostServices.resolveConstantType(context.getAppInfo(), name); } private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException { @@ -2003,7 +1928,7 @@ public class FHIRPathEngine { checkParamTypes(exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, "string")); return focus; case Custom : { - return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes); + return hostServices.checkFunction(context.getAppInfo(), exp.getName(), paramTypes); } default: break; @@ -2120,7 +2045,7 @@ public class FHIRPathEngine { List> params = new ArrayList>(); for (ExpressionNode p : exp.getParameters()) params.add(execute(context, focus, p, true)); - return hostServices.executeFunction(context.appInfo, exp.getName(), params); + return hostServices.executeFunction(context.getAppInfo(), exp.getName(), params); } default: throw new Error("not Implemented yet"); @@ -2181,11 +2106,11 @@ public class FHIRPathEngine { private ExecutionContext changeThis(ExecutionContext context, Base newThis) { - return new ExecutionContext(context.appInfo, context.resource, context.context, context.aliases, newThis); + return new ExecutionContext(context.getAppInfo(), context.getResource(), context.getContext(), context.getAliases(), newThis); } private ExecutionTypeContext changeThis(ExecutionTypeContext context, TypeDetails newThis) { - return new ExecutionTypeContext(context.appInfo, context.resource, context.context, newThis); + return new ExecutionTypeContext(context.getAppInfo(), context.getResource(), context.getContext(), newThis); } @@ -2467,13 +2392,13 @@ public class FHIRPathEngine { } Base res = null; if (s.startsWith("#")) { - Property p = context.resource.getChildByName("contained"); + Property p = context.getResource().getChildByName("contained"); for (Base c : p.getValues()) { if (s.equals(c.getIdBase())) res = c; } } else if (hostServices != null) { - res = hostServices.resolveReference(context.appInfo, s); + res = hostServices.resolveReference(context.getAppInfo(), s); } if (res != null) result.add(res); @@ -2699,7 +2624,7 @@ public class FHIRPathEngine { return makeBoolean(!convertToBoolean(focus)); } - public class ElementDefinitionMatch { + private class ElementDefinitionMatch { private ElementDefinition definition; private String fixedType; public ElementDefinitionMatch(ElementDefinition definition, String fixedType) { diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathUtilityClasses.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathUtilityClasses.java new file mode 100644 index 000000000..e5179143a --- /dev/null +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/FHIRPathUtilityClasses.java @@ -0,0 +1,110 @@ +package org.hl7.fhir.dstu3.utils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hl7.fhir.dstu3.model.Base; +import org.hl7.fhir.dstu3.model.TypeDetails; +import org.hl7.fhir.exceptions.FHIRException; + +public class FHIRPathUtilityClasses { + + + public static class ExecutionContext { + private Object appInfo; + private Base resource; + private Base context; + private Base thisItem; + private Map aliases; + + public ExecutionContext(Object appInfo, Base resource, Base context, Map aliases, Base thisItem) { + this.appInfo = appInfo; + this.context = context; + this.resource = resource; + this.aliases = aliases; + this.thisItem = thisItem; + } + public Base getResource() { + return resource; + } + public Base getThisItem() { + return thisItem; + } + public void addAlias(String name, List focus) throws FHIRException { + if (aliases == null) + aliases = new HashMap(); + else + aliases = new HashMap(aliases); // clone it, since it's going to change + if (focus.size() > 1) + throw new FHIRException("Attempt to alias a collection, not a singleton"); + aliases.put(name, focus.size() == 0 ? null : focus.get(0)); + } + public Base getAlias(String name) { + return aliases == null ? null : aliases.get(name); + } + public Object getAppInfo() { + return appInfo; + } + public Base getContext() { + return context; + } + public Map getAliases() { + return aliases; + } + + } + + public static class ExecutionTypeContext { + private Object appInfo; + private String resource; + private String context; + private TypeDetails thisItem; + + + public ExecutionTypeContext(Object appInfo, String resource, String context, TypeDetails thisItem) { + super(); + this.appInfo = appInfo; + this.resource = resource; + this.context = context; + this.thisItem = thisItem; + + } + public String getResource() { + return resource; + } + public TypeDetails getThisItem() { + return thisItem; + } + public Object getAppInfo() { + return appInfo; + } + public String getContext() { + return context; + } + + + } + + public static class FunctionDetails { + private String description; + private int minParameters; + private int maxParameters; + public FunctionDetails(String description, int minParameters, int maxParameters) { + super(); + this.description = description; + this.minParameters = minParameters; + this.maxParameters = maxParameters; + } + public String getDescription() { + return description; + } + public int getMinParameters() { + return minParameters; + } + public int getMaxParameters() { + return maxParameters; + } + + } +} diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/StructureMapUtilities.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/StructureMapUtilities.java index d257940ef..5232b7e00 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/StructureMapUtilities.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/StructureMapUtilities.java @@ -108,6 +108,7 @@ import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome; import org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException; import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/test/SnapShotGenerationTests.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/test/SnapShotGenerationTests.java index 673d9a448..079c37021 100644 --- a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/test/SnapShotGenerationTests.java @@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.test.support.TestingUtilities; import org.hl7.fhir.dstu3.utils.CodingUtilities; import org.hl7.fhir.dstu3.utils.FHIRPathEngine; import org.hl7.fhir.dstu3.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.dstu3.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java index 79f115983..69421eb4e 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java @@ -56,7 +56,10 @@ import org.hl7.fhir.r4.model.TypeDetails; import org.hl7.fhir.r4.model.TypeDetails.ProfiledType; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException; -import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FHIRConstant; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.ClassTypeInfo; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.TypedElementDefinition; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.MergedList; import org.hl7.fhir.utilities.MergedList.MergeNode; @@ -110,167 +113,6 @@ public class FHIRPathEngine { private enum Equality { Null, True, False } - - private class FHIRConstant extends Base { - - private static final long serialVersionUID = -8933773658248269439L; - private String value; - - public FHIRConstant(String value) { - this.value = value; - } - - @Override - public String fhirType() { - return "%constant"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public String getValue() { - return value; - } - - @Override - public String primitiveValue() { - return value; - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - - } - - private class ClassTypeInfo extends Base { - private static final long serialVersionUID = 4909223114071029317L; - private Base instance; - - public ClassTypeInfo(Base instance) { - super(); - this.instance = instance; - } - - @Override - public String fhirType() { - return "ClassInfo"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { - if (name.equals("name")) { - return new Base[] { new StringType(getName()) }; - } else if (name.equals("namespace")) { - return new Base[] { new StringType(getNamespace()) }; - } else { - return super.getProperty(hash, name, checkValid); - } - } - - private String getNamespace() { - if ((instance instanceof Resource)) { - return "FHIR"; - } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { - return "System"; - } else { - return "FHIR"; - } - } - - private String getName() { - if ((instance instanceof Resource)) { - return instance.fhirType(); - } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { - return Utilities.capitalize(instance.fhirType()); - } else { - return instance.fhirType(); - } - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - - } - - public static class TypedElementDefinition { - private ElementDefinition element; - private String type; - private StructureDefinition src; - - public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) { - super(); - this.element = element; - this.type = type; - this.src = src; - } - - public TypedElementDefinition(ElementDefinition element) { - super(); - this.element = element; - } - - public ElementDefinition getElement() { - return element; - } - - public String getType() { - return type; - } - - public List getTypes() { - List res = new ArrayList(); - for (TypeRefComponent tr : element.getType()) { - if (type == null || type.equals(tr.getCode())) { - res.add(tr); - } - } - return res; - } - - public boolean hasType(String tn) { - if (type != null) { - return tn.equals(type); - } else { - for (TypeRefComponent t : element.getType()) { - if (tn.equals(t.getCode())) { - return true; - } - } - return false; - } - } - - public StructureDefinition getSrc() { - return src; - } - } - private IWorkerContext worker; private IEvaluationContext hostServices; private StringBuilder log = new StringBuilder(); @@ -292,31 +134,7 @@ public class FHIRPathEngine { // defined in the specification // the application can implement them by providing a constant resolver public interface IEvaluationContext { - public class FunctionDetails { - private String description; - private int minParameters; - private int maxParameters; - - public FunctionDetails(String description, int minParameters, int maxParameters) { - super(); - this.description = description; - this.minParameters = minParameters; - this.maxParameters = maxParameters; - } - - public String getDescription() { - return description; - } - - public int getMinParameters() { - return minParameters; - } - - public int getMaxParameters() { - return maxParameters; - } - - } + /** * A constant reference - e.g. a reference to a name that must be resolved in @@ -6129,7 +5947,7 @@ public class FHIRPathEngine { return result; } - public class ElementDefinitionMatch { + private class ElementDefinitionMatch { private ElementDefinition definition; private String fixedType; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathUtilityClasses.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathUtilityClasses.java new file mode 100644 index 000000000..cdac06e64 --- /dev/null +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathUtilityClasses.java @@ -0,0 +1,210 @@ +package org.hl7.fhir.r4.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4.model.Base; +import org.hl7.fhir.r4.model.Element; +import org.hl7.fhir.r4.model.ElementDefinition; +import org.hl7.fhir.r4.model.IntegerType; +import org.hl7.fhir.r4.model.Property; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.StructureDefinition; +import org.hl7.fhir.r4.model.TypeDetails; +import org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.i18n.I18nConstants; + +public class FHIRPathUtilityClasses { + + + public static class FHIRConstant extends Base { + + private static final long serialVersionUID = -8933773658248269439L; + private String value; + + public FHIRConstant(String value) { + this.value = value; + } + + @Override + public String fhirType() { + return "%constant"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public String getValue() { + return value; + } + + @Override + public String primitiveValue() { + return value; + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + + } + + public static class ClassTypeInfo extends Base { + private static final long serialVersionUID = 4909223114071029317L; + private Base instance; + + public ClassTypeInfo(Base instance) { + super(); + this.instance = instance; + } + + @Override + public String fhirType() { + return "ClassInfo"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { + if (name.equals("name")) { + return new Base[] { new StringType(getName()) }; + } else if (name.equals("namespace")) { + return new Base[] { new StringType(getNamespace()) }; + } else { + return super.getProperty(hash, name, checkValid); + } + } + + private String getNamespace() { + if ((instance instanceof Resource)) { + return "FHIR"; + } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { + return "System"; + } else { + return "FHIR"; + } + } + + private String getName() { + if ((instance instanceof Resource)) { + return instance.fhirType(); + } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { + return Utilities.capitalize(instance.fhirType()); + } else { + return instance.fhirType(); + } + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + + } + + public static class TypedElementDefinition { + private ElementDefinition element; + private String type; + private StructureDefinition src; + + public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) { + super(); + this.element = element; + this.type = type; + this.src = src; + } + + public TypedElementDefinition(ElementDefinition element) { + super(); + this.element = element; + } + + public ElementDefinition getElement() { + return element; + } + + public String getType() { + return type; + } + + public List getTypes() { + List res = new ArrayList(); + for (TypeRefComponent tr : element.getType()) { + if (type == null || type.equals(tr.getCode())) { + res.add(tr); + } + } + return res; + } + + public boolean hasType(String tn) { + if (type != null) { + return tn.equals(type); + } else { + for (TypeRefComponent t : element.getType()) { + if (tn.equals(t.getCode())) { + return true; + } + } + return false; + } + } + + public StructureDefinition getSrc() { + return src; + } + } + + public static class FunctionDetails { + private String description; + private int minParameters; + private int maxParameters; + + public FunctionDetails(String description, int minParameters, int maxParameters) { + super(); + this.description = description; + this.minParameters = minParameters; + this.maxParameters = maxParameters; + } + + public String getDescription() { + return description; + } + + public int getMinParameters() { + return minParameters; + } + + public int getMaxParameters() { + return maxParameters; + } + + } +} diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/LiquidEngine.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/LiquidEngine.java index c0b63cdba..eb73998a9 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/LiquidEngine.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/LiquidEngine.java @@ -46,6 +46,7 @@ import org.hl7.fhir.r4.model.TypeDetails; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.utils.FHIRPathEngine.ExpressionNodeWithOffset; import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; public class LiquidEngine implements IEvaluationContext { diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/StructureMapUtilities.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/StructureMapUtilities.java index f278907e1..2b23ea5f8 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/StructureMapUtilities.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/StructureMapUtilities.java @@ -114,6 +114,7 @@ import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome; import org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException; import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.TerminologyServiceOptions; diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/FHIRPathTests.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/FHIRPathTests.java index 5af220df8..51e3105ab 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/FHIRPathTests.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/FHIRPathTests.java @@ -34,6 +34,7 @@ import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.test.utils.TestingUtilities; import org.hl7.fhir.r4.utils.FHIRPathEngine; import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xml.XMLUtil; import org.junit.jupiter.api.Assertions; diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java index 4487a47c4..3077c83e2 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java @@ -33,6 +33,7 @@ import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.test.utils.TestingUtilities; import org.hl7.fhir.r4.utils.FHIRPathEngine; import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4.utils.NarrativeGenerator; import org.hl7.fhir.r4.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.Utilities; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/comparison/ComparisonRenderer.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/comparison/ComparisonRenderer.java index 90a4d9e47..4a355f1b6 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/comparison/ComparisonRenderer.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/comparison/ComparisonRenderer.java @@ -31,6 +31,7 @@ import org.hl7.fhir.r4b.model.Tuple; import org.hl7.fhir.r4b.model.TypeDetails; import org.hl7.fhir.r4b.model.ValueSet; import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4b.utils.LiquidEngine; import org.hl7.fhir.r4b.utils.LiquidEngine.LiquidDocument; import org.hl7.fhir.utilities.TextFile; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathEngine.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathEngine.java index 589b8585f..008741ad3 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathEngine.java @@ -57,7 +57,10 @@ import org.hl7.fhir.r4b.model.TypeDetails; import org.hl7.fhir.r4b.model.TypeDetails.ProfiledType; import org.hl7.fhir.r4b.model.ValueSet; import org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException; -import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FHIRConstant; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.ClassTypeInfo; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.TypedElementDefinition; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.MergedList; import org.hl7.fhir.utilities.MergedList.MergeNode; @@ -112,160 +115,6 @@ public class FHIRPathEngine { Null, True, False } - private class FHIRConstant extends Base { - - private static final long serialVersionUID = -8933773658248269439L; - private String value; - - public FHIRConstant(String value) { - this.value = value; - } - - @Override - public String fhirType() { - return "%constant"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public String getValue() { - return value; - } - - @Override - public String primitiveValue() { - return value; - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - } - - private class ClassTypeInfo extends Base { - private static final long serialVersionUID = 4909223114071029317L; - private Base instance; - - public ClassTypeInfo(Base instance) { - super(); - this.instance = instance; - } - - @Override - public String fhirType() { - return "ClassInfo"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { - if (name.equals("name")) { - return new Base[] { new StringType(getName()) }; - } else if (name.equals("namespace")) { - return new Base[] { new StringType(getNamespace()) }; - } else { - return super.getProperty(hash, name, checkValid); - } - } - - private String getNamespace() { - if ((instance instanceof Resource)) { - return "FHIR"; - } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { - return "System"; - } else { - return "FHIR"; - } - } - - private String getName() { - if ((instance instanceof Resource)) { - return instance.fhirType(); - } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { - return Utilities.capitalize(instance.fhirType()); - } else { - return instance.fhirType(); - } - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - - } - - public static class TypedElementDefinition { - private ElementDefinition element; - private String type; - - public TypedElementDefinition(ElementDefinition element, String type) { - super(); - this.element = element; - this.type = type; - } - - public TypedElementDefinition(ElementDefinition element) { - super(); - this.element = element; - } - - public ElementDefinition getElement() { - return element; - } - - public String getType() { - return type; - } - - public List getTypes() { - List res = new ArrayList(); - for (TypeRefComponent tr : element.getType()) { - if (type == null || type.equals(tr.getCode())) { - res.add(tr); - } - } - return res; - } - - public boolean hasType(String tn) { - if (type != null) { - return tn.equals(type); - } else { - for (TypeRefComponent t : element.getType()) { - if (tn.equals(t.getCode())) { - return true; - } - } - return false; - } - } - - } - private IWorkerContext worker; private IEvaluationContext hostServices; private StringBuilder log = new StringBuilder(); @@ -288,32 +137,7 @@ public class FHIRPathEngine { // defined in the specification // the application can implement them by providing a constant resolver public interface IEvaluationContext { - public class FunctionDetails { - private String description; - private int minParameters; - private int maxParameters; - - public FunctionDetails(String description, int minParameters, int maxParameters) { - super(); - this.description = description; - this.minParameters = minParameters; - this.maxParameters = maxParameters; - } - - public String getDescription() { - return description; - } - - public int getMinParameters() { - return minParameters; - } - - public int getMaxParameters() { - return maxParameters; - } - - } - + /** * A constant reference - e.g. a reference to a name that must be resolved in * context. The % will be removed from the constant name before this is invoked. @@ -6126,7 +5950,7 @@ public class FHIRPathEngine { return result; } - public class ElementDefinitionMatch { + private class ElementDefinitionMatch { private ElementDefinition definition; private String fixedType; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathUtilityClasses.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathUtilityClasses.java new file mode 100644 index 000000000..eda08e382 --- /dev/null +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/FHIRPathUtilityClasses.java @@ -0,0 +1,198 @@ +package org.hl7.fhir.r4b.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4b.model.Base; +import org.hl7.fhir.r4b.model.Element; +import org.hl7.fhir.r4b.model.ElementDefinition; +import org.hl7.fhir.r4b.model.Property; +import org.hl7.fhir.r4b.model.Resource; +import org.hl7.fhir.r4b.model.StringType; +import org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent; +import org.hl7.fhir.utilities.Utilities; + +public class FHIRPathUtilityClasses { + + public static class FHIRConstant extends Base { + + private static final long serialVersionUID = -8933773658248269439L; + private String value; + + public FHIRConstant(String value) { + this.value = value; + } + + @Override + public String fhirType() { + return "%constant"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public String getValue() { + return value; + } + + @Override + public String primitiveValue() { + return value; + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + } + + public static class ClassTypeInfo extends Base { + private static final long serialVersionUID = 4909223114071029317L; + private Base instance; + + public ClassTypeInfo(Base instance) { + super(); + this.instance = instance; + } + + @Override + public String fhirType() { + return "ClassInfo"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { + if (name.equals("name")) { + return new Base[] { new StringType(getName()) }; + } else if (name.equals("namespace")) { + return new Base[] { new StringType(getNamespace()) }; + } else { + return super.getProperty(hash, name, checkValid); + } + } + + private String getNamespace() { + if ((instance instanceof Resource)) { + return "FHIR"; + } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { + return "System"; + } else { + return "FHIR"; + } + } + + private String getName() { + if ((instance instanceof Resource)) { + return instance.fhirType(); + } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { + return Utilities.capitalize(instance.fhirType()); + } else { + return instance.fhirType(); + } + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + + } + + public static class TypedElementDefinition { + private ElementDefinition element; + private String type; + + public TypedElementDefinition(ElementDefinition element, String type) { + super(); + this.element = element; + this.type = type; + } + + public TypedElementDefinition(ElementDefinition element) { + super(); + this.element = element; + } + + public ElementDefinition getElement() { + return element; + } + + public String getType() { + return type; + } + + public List getTypes() { + List res = new ArrayList(); + for (TypeRefComponent tr : element.getType()) { + if (type == null || type.equals(tr.getCode())) { + res.add(tr); + } + } + return res; + } + + public boolean hasType(String tn) { + if (type != null) { + return tn.equals(type); + } else { + for (TypeRefComponent t : element.getType()) { + if (tn.equals(t.getCode())) { + return true; + } + } + return false; + } + } + + } + + public static class FunctionDetails { + private String description; + private int minParameters; + private int maxParameters; + + public FunctionDetails(String description, int minParameters, int maxParameters) { + super(); + this.description = description; + this.minParameters = minParameters; + this.maxParameters = maxParameters; + } + + public String getDescription() { + return description; + } + + public int getMinParameters() { + return minParameters; + } + + public int getMaxParameters() { + return maxParameters; + } + + } + +} diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/LiquidEngine.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/LiquidEngine.java index 831edd7ef..5a94f53af 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/LiquidEngine.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/LiquidEngine.java @@ -49,6 +49,7 @@ import org.hl7.fhir.r4b.model.TypeDetails; import org.hl7.fhir.r4b.model.ValueSet; import org.hl7.fhir.r4b.utils.FHIRPathEngine.ExpressionNodeWithOffset; import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.xhtml.NodeType; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/FFHIRPathHostServices.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/FFHIRPathHostServices.java index 6f5c0a7fa..63c940793 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/FFHIRPathHostServices.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/FFHIRPathHostServices.java @@ -9,6 +9,7 @@ import org.hl7.fhir.r4b.model.Resource; import org.hl7.fhir.r4b.model.TypeDetails; import org.hl7.fhir.r4b.model.ValueSet; import org.hl7.fhir.r4b.utils.FHIRPathEngine; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4b.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/StructureMapUtilities.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/StructureMapUtilities.java index c5151a7ee..18176909d 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/StructureMapUtilities.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/structuremap/StructureMapUtilities.java @@ -68,6 +68,7 @@ import org.hl7.fhir.r4b.utils.FHIRLexer; import org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException; import org.hl7.fhir.r4b.utils.FHIRPathEngine; import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4b.utils.ToolingExtensions; import org.hl7.fhir.r4b.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/FHIRPathTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/FHIRPathTests.java index 52c41b345..b600f79e1 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/FHIRPathTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/FHIRPathTests.java @@ -18,6 +18,7 @@ import org.hl7.fhir.r4b.test.FHIRPathTests.TestResultType; import org.hl7.fhir.r4b.test.utils.TestingUtilities; import org.hl7.fhir.r4b.utils.FHIRPathEngine; import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xml.XMLUtil; import org.junit.jupiter.api.Assertions; diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java index 88e96144f..6ef70764f 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java @@ -39,6 +39,7 @@ import org.hl7.fhir.r4b.model.ValueSet; import org.hl7.fhir.r4b.test.utils.TestingUtilities; import org.hl7.fhir.r4b.utils.FHIRPathEngine; import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r4b.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4b.utils.validation.IResourceValidator; import org.hl7.fhir.r4b.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java index 19c5cca2a..254b09ba5 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java @@ -30,6 +30,7 @@ import org.hl7.fhir.r5.model.Tuple; import org.hl7.fhir.r5.model.TypeDetails; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.utils.LiquidEngine; import org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument; import org.hl7.fhir.utilities.TextFile; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index 26a617f6e..d0c15d638 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -61,7 +61,10 @@ import org.hl7.fhir.r5.model.TypeDetails; import org.hl7.fhir.r5.model.TypeDetails.ProfiledType; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException; -import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FHIRConstant; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.ClassTypeInfo; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.TypedElementDefinition; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.MarkDownProcessor; import org.hl7.fhir.utilities.MergedList; @@ -115,157 +118,7 @@ import ca.uhn.fhir.util.ElementUtil; public class FHIRPathEngine { private enum Equality { Null, True, False } - - private class FHIRConstant extends Base { - - private static final long serialVersionUID = -8933773658248269439L; - private String value; - - public FHIRConstant(String value) { - this.value = value; - } - - @Override - public String fhirType() { - return "%constant"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public String getValue() { - return value; - } - - @Override - public String primitiveValue() { - return value; - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - } - - private class ClassTypeInfo extends Base { - private static final long serialVersionUID = 4909223114071029317L; - private Base instance; - - public ClassTypeInfo(Base instance) { - super(); - this.instance = instance; - } - - @Override - public String fhirType() { - return "ClassInfo"; - } - - @Override - protected void listChildren(List result) { - } - - @Override - public String getIdBase() { - return null; - } - - @Override - public void setIdBase(String value) { - } - - public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { - if (name.equals("name")) { - return new Base[]{new StringType(getName())}; - } else if (name.equals("namespace")) { - return new Base[]{new StringType(getNamespace())}; - } else { - return super.getProperty(hash, name, checkValid); - } - } - - private String getNamespace() { - if ((instance instanceof Resource)) { - return "FHIR"; - } else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) { - return "System"; - } else { - return "FHIR"; - } - } - - private String getName() { - if ((instance instanceof Resource)) { - return instance.fhirType(); - } else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) { - return Utilities.capitalize(instance.fhirType()); - } else { - return instance.fhirType(); - } - } - - @Override - public Base copy() { - throw new Error("Not Implemented"); - } - } - - public static class TypedElementDefinition { - private ElementDefinition element; - private String type; - private StructureDefinition src; - public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) { - super(); - this.element = element; - this.type = type; - this.src = src; - } - public TypedElementDefinition(ElementDefinition element) { - super(); - this.element = element; - } - public ElementDefinition getElement() { - return element; - } - public String getType() { - return type; - } - public List getTypes() { - List res = new ArrayList(); - for (TypeRefComponent tr : element.getType()) { - if (type == null || type.equals(tr.getCode())) { - res.add(tr); - } - } - return res; - } - public boolean hasType(String tn) { - if (type != null) { - return tn.equals(type); - } else { - for (TypeRefComponent t : element.getType()) { - if (tn.equals(t.getCode())) { - return true; - } - } - return false; - } - } - public StructureDefinition getSrc() { - return src; - } - } + private IWorkerContext worker; private IEvaluationContext hostServices; private StringBuilder log = new StringBuilder(); @@ -286,27 +139,6 @@ public class FHIRPathEngine { // if the fhir path expressions are allowed to use constants beyond those defined in the specification // the application can implement them by providing a constant resolver public interface IEvaluationContext { - public class FunctionDetails { - private String description; - private int minParameters; - private int maxParameters; - public FunctionDetails(String description, int minParameters, int maxParameters) { - super(); - this.description = description; - this.minParameters = minParameters; - this.maxParameters = maxParameters; - } - public String getDescription() { - return description; - } - public int getMinParameters() { - return minParameters; - } - public int getMaxParameters() { - return maxParameters; - } - - } /** * A constant reference - e.g. a reference to a name that must be resolved in context. @@ -5909,7 +5741,7 @@ public class FHIRPathEngine { return result; } - public class ElementDefinitionMatch { + private class ElementDefinitionMatch { private ElementDefinition definition; private ElementDefinition sourceDefinition; // if there was a content reference private String fixedType; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathUtilityClasses.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathUtilityClasses.java new file mode 100644 index 000000000..6867a38f0 --- /dev/null +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathUtilityClasses.java @@ -0,0 +1,192 @@ +package org.hl7.fhir.r5.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r5.model.Base; +import org.hl7.fhir.r5.model.Element; +import org.hl7.fhir.r5.model.ElementDefinition; +import org.hl7.fhir.r5.model.Property; +import org.hl7.fhir.r5.model.Resource; +import org.hl7.fhir.r5.model.StringType; +import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; +import org.hl7.fhir.utilities.Utilities; + +public class FHIRPathUtilityClasses { + + public static class FHIRConstant extends Base { + + private static final long serialVersionUID = -8933773658248269439L; + private String value; + + public FHIRConstant(String value) { + this.value = value; + } + + @Override + public String fhirType() { + return "%constant"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public String getValue() { + return value; + } + + @Override + public String primitiveValue() { + return value; + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + } + + public static class ClassTypeInfo extends Base { + private static final long serialVersionUID = 4909223114071029317L; + private Base instance; + + public ClassTypeInfo(Base instance) { + super(); + this.instance = instance; + } + + @Override + public String fhirType() { + return "ClassInfo"; + } + + @Override + protected void listChildren(List result) { + } + + @Override + public String getIdBase() { + return null; + } + + @Override + public void setIdBase(String value) { + } + + public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { + if (name.equals("name")) { + return new Base[]{new StringType(getName())}; + } else if (name.equals("namespace")) { + return new Base[]{new StringType(getNamespace())}; + } else { + return super.getProperty(hash, name, checkValid); + } + } + + private String getNamespace() { + if ((instance instanceof Resource)) { + return "FHIR"; + } else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) { + return "System"; + } else { + return "FHIR"; + } + } + + private String getName() { + if ((instance instanceof Resource)) { + return instance.fhirType(); + } else if (!(instance instanceof Element) || ((Element)instance).isDisallowExtensions()) { + return Utilities.capitalize(instance.fhirType()); + } else { + return instance.fhirType(); + } + } + + @Override + public Base copy() { + throw new Error("Not Implemented"); + } + } + + public static class TypedElementDefinition { + private ElementDefinition element; + private String type; + private StructureDefinition src; + public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) { + super(); + this.element = element; + this.type = type; + this.src = src; + } + public TypedElementDefinition(ElementDefinition element) { + super(); + this.element = element; + } + public ElementDefinition getElement() { + return element; + } + public String getType() { + return type; + } + public List getTypes() { + List res = new ArrayList(); + for (TypeRefComponent tr : element.getType()) { + if (type == null || type.equals(tr.getCode())) { + res.add(tr); + } + } + return res; + } + public boolean hasType(String tn) { + if (type != null) { + return tn.equals(type); + } else { + for (TypeRefComponent t : element.getType()) { + if (tn.equals(t.getCode())) { + return true; + } + } + return false; + } + } + public StructureDefinition getSrc() { + return src; + } + } + + + public static class FunctionDetails { + private String description; + private int minParameters; + private int maxParameters; + public FunctionDetails(String description, int minParameters, int maxParameters) { + super(); + this.description = description; + this.minParameters = minParameters; + this.maxParameters = maxParameters; + } + public String getDescription() { + return description; + } + public int getMinParameters() { + return minParameters; + } + public int getMaxParameters() { + return maxParameters; + } + + } +} diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/LiquidEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/LiquidEngine.java index 95221f649..66b6b6967 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/LiquidEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/LiquidEngine.java @@ -46,6 +46,7 @@ import org.hl7.fhir.r5.model.TypeDetails; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.FHIRPathEngine.ExpressionNodeWithOffset; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.xhtml.NodeType; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/FFHIRPathHostServices.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/FFHIRPathHostServices.java index 409465f71..deecf2a4e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/FFHIRPathHostServices.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/FFHIRPathHostServices.java @@ -9,6 +9,7 @@ import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.TypeDetails; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.FHIRPathEngine; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java index d803ae08d..3ac2574b3 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java @@ -20,6 +20,7 @@ import org.hl7.fhir.r5.model.*; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xml.XMLUtil; import org.junit.jupiter.api.Assertions; diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java index acca61071..bd299d30f 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java @@ -40,6 +40,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.r5.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.Utilities; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index fc8374758..14b4afc05 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -155,7 +155,8 @@ import org.hl7.fhir.r5.utils.BuildExtensions; import org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; -import org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.TypedElementDefinition; import org.hl7.fhir.r5.utils.ResourceUtilities; import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.XVerExtensionManager; diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java index 2c3f2d201..48ee30723 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/SnapShotGenerationXTests.java @@ -37,6 +37,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.utils.validation.IResourceValidator; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage; diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java index 9602ffeb4..8548922ab 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java @@ -52,6 +52,7 @@ import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.utils.OperationOutcomeUtilities; import org.hl7.fhir.r5.utils.validation.BundleValidationRule; import org.hl7.fhir.r5.utils.validation.IResourceValidator;