Revise FHIRPath API so hosts can evaluate expressions in custom functions

This commit is contained in:
Grahame Grieve 2023-10-23 10:24:54 +11:00
parent 1534a5b6eb
commit 40c996828a
22 changed files with 263 additions and 261 deletions

View File

@ -59,6 +59,7 @@ import org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FHIRConstant; import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FHIRConstant;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.ClassTypeInfo; import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.ClassTypeInfo;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.TypedElementDefinition; import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MergedList; import org.hl7.fhir.utilities.MergedList;
@ -150,9 +151,9 @@ public class FHIRPathEngine {
* @return the value of the reference (or null, if it's not valid, though can * @return the value of the reference (or null, if it's not valid, though can
* throw an exception if desired) * throw an exception if desired)
*/ */
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException; public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException;
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException; public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException;
/** /**
* when the .log() function is called * when the .log() function is called
@ -169,7 +170,7 @@ public class FHIRPathEngine {
* @param functionName * @param functionName
* @return null if the function is not known * @return null if the function is not known
*/ */
public FunctionDetails resolveFunction(String functionName); public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName);
/** /**
* Check the function parameters, and throw an error if they are incorrect, or * Check the function parameters, and throw an error if they are incorrect, or
@ -179,7 +180,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException; throws PathEngineException;
/** /**
@ -188,7 +189,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters); List<List<Base>> parameters);
/** /**
@ -200,14 +201,14 @@ public class FHIRPathEngine {
* @return * @return
* @throws FHIRException * @throws FHIRException
*/ */
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException; public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException;
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException; public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException;
/* /*
* return the value set referenced by the url, which has been used in memberOf() * return the value set referenced by the url, which has been used in memberOf()
*/ */
public ValueSet resolveValueSet(Object appContext, String url); public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url);
} }
/** /**
@ -1032,7 +1033,7 @@ public class FHIRPathEngine {
FunctionDetails details = null; FunctionDetails details = null;
if (f == null) { if (f == null) {
if (hostServices != null) { if (hostServices != null) {
details = hostServices.resolveFunction(result.getName()); details = hostServices.resolveFunction(this, result.getName());
} }
if (details == null) { if (details == null) {
throw lexer.error("The name " + result.getName() + " is not a valid function name"); throw lexer.error("The name " + result.getName() + " is not a valid function name");
@ -1473,7 +1474,7 @@ public class FHIRPathEngine {
work.addAll(work2); work.addAll(work2);
break; break;
case Constant: case Constant:
work.addAll(resolveConstant(context, exp.getConstant(), false, exp)); work.addAll(resolveConstant(context, exp.getConstant(), false, exp, true));
break; break;
case Group: case Group:
work2 = execute(context, focus, exp.getGroup(), atEntry); work2 = execute(context, focus, exp.getGroup(), atEntry);
@ -1563,7 +1564,7 @@ public class FHIRPathEngine {
} else if (atEntry && exp.getName().equals("$index")) { } else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer); result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) { } else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp)); result.update(executeContextType(context, exp.getName(), exp, false));
} else { } else {
for (String s : focus.getTypes()) { for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry)); result.update(executeType(s, exp, atEntry));
@ -1582,7 +1583,7 @@ public class FHIRPathEngine {
result.addType(TypeDetails.FP_Quantity); result.addType(TypeDetails.FP_Quantity);
break; break;
case Constant: case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp)); result.update(resolveConstantType(context, exp.getConstant(), exp, true));
break; break;
case Group: case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry)); result.update(executeType(context, focus, exp.getGroup(), atEntry));
@ -1612,8 +1613,7 @@ public class FHIRPathEngine {
return result; return result;
} }
private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext, private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext, ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
ExpressionNode expr) throws PathEngineException {
if (constant == null) { if (constant == null) {
return new ArrayList<Base>(); return new ArrayList<Base>();
} }
@ -1622,7 +1622,7 @@ public class FHIRPathEngine {
} }
FHIRConstant c = (FHIRConstant) constant; FHIRConstant c = (FHIRConstant) constant;
if (c.getValue().startsWith("%")) { if (c.getValue().startsWith("%")) {
return resolveConstant(context, c.getValue(), beforeContext, expr); return resolveConstant(context, c.getValue(), beforeContext, expr, explicitConstant);
} else if (c.getValue().startsWith("@")) { } else if (c.getValue().startsWith("@")) {
return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr))); return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr)));
} else { } else {
@ -1692,7 +1692,7 @@ public class FHIRPathEngine {
} }
} }
private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr) private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (s.equals("%sct")) { if (s.equals("%sct")) {
return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions())); return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions()));
@ -1726,7 +1726,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstant(context.appInfo, s.substring(1), beforeContext); return hostServices.resolveConstant(this, context.appInfo, s.substring(1), beforeContext, explicitConstant);
} }
} }
@ -2549,7 +2549,7 @@ public class FHIRPathEngine {
throws FHIRException { throws FHIRException {
boolean ans = false; boolean ans = false;
String url = right.get(0).primitiveValue(); String url = right.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url)
: worker.fetchResource(ValueSet.class, url); : worker.fetchResource(ValueSet.class, url);
if (vs != null) { if (vs != null) {
for (Base l : left) { for (Base l : left) {
@ -3079,7 +3079,7 @@ public class FHIRPathEngine {
return result; return result;
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr) private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (constant instanceof BooleanType) { if (constant instanceof BooleanType) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
@ -3090,7 +3090,7 @@ public class FHIRPathEngine {
} else if (constant instanceof Quantity) { } else if (constant instanceof Quantity) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity);
} else if (constant instanceof FHIRConstant) { } else if (constant instanceof FHIRConstant) {
return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr); return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr, explicitConstant);
} else if (constant == null) { } else if (constant == null) {
return new TypeDetails(CollectionStatus.SINGLETON); return new TypeDetails(CollectionStatus.SINGLETON);
} else { } else {
@ -3098,7 +3098,7 @@ public class FHIRPathEngine {
} }
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr) private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (s.startsWith("@")) { if (s.startsWith("@")) {
if (s.startsWith("@T")) { if (s.startsWith("@T")) {
@ -3137,7 +3137,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstantType(context.appInfo, s); return hostServices.resolveConstantType(this, context.appInfo, s, explicitConstant);
} }
} }
@ -3146,7 +3146,7 @@ public class FHIRPathEngine {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (atEntry && context.appInfo != null && hostServices != null) { if (atEntry && context.appInfo != null && hostServices != null) {
// we'll see if the name matches a constant known by the context. // we'll see if the name matches a constant known by the context.
List<Base> temp = hostServices.resolveConstant(context.appInfo, exp.getName(), true); List<Base> temp = hostServices.resolveConstant(this, context.appInfo, exp.getName(), true, false);
if (!temp.isEmpty()) { if (!temp.isEmpty()) {
result.addAll(temp); result.addAll(temp);
return result; return result;
@ -3177,7 +3177,7 @@ public class FHIRPathEngine {
// constant known by the context. // constant known by the context.
// (if the name does match, and the user wants to get the constant value, // (if the name does match, and the user wants to get the constant value,
// they'll have to try harder... // they'll have to try harder...
result.addAll(hostServices.resolveConstant(context.appInfo, exp.getName(), false)); result.addAll(hostServices.resolveConstant(this, context.appInfo, exp.getName(), false, false));
} }
return result; return result;
} }
@ -3186,12 +3186,12 @@ public class FHIRPathEngine {
return null; return null;
} }
private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr) private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException, DefinitionException { throws PathEngineException, DefinitionException {
if (hostServices == null) { if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference"); throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference");
} }
return hostServices.resolveConstantType(context.appInfo, name); return hostServices.resolveConstantType(this, context.appInfo, name, explicitConstant);
} }
private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry) private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry)
@ -3607,7 +3607,7 @@ public class FHIRPathEngine {
} }
case Custom: { case Custom: {
return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes); return hostServices.checkFunction(this, context.appInfo, exp.getName(), focus, paramTypes);
} }
default: default:
break; break;
@ -3932,7 +3932,7 @@ public class FHIRPathEngine {
for (ExpressionNode p : exp.getParameters()) { for (ExpressionNode p : exp.getParameters()) {
params.add(execute(context, focus, p, true)); params.add(execute(context, focus, p, true));
} }
return hostServices.executeFunction(context.appInfo, focus, exp.getName(), params); return hostServices.executeFunction(this, context.appInfo, focus, exp.getName(), params);
} }
default: default:
throw new Error("not Implemented yet"); throw new Error("not Implemented yet");
@ -4605,7 +4605,7 @@ public class FHIRPathEngine {
} }
String url = nl.get(0).primitiveValue(); String url = nl.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url)
: worker.fetchResource(ValueSet.class, url); : worker.fetchResource(ValueSet.class, url);
if (vs == null) { if (vs == null) {
return new ArrayList<Base>(); return new ArrayList<Base>();
@ -5210,7 +5210,7 @@ public class FHIRPathEngine {
} }
} else if (hostServices != null) { } else if (hostServices != null) {
try { try {
res = hostServices.resolveReference(context.appInfo, s, refContext); res = hostServices.resolveReference(this, context.appInfo, s, refContext);
} catch (Exception e) { } catch (Exception e) {
res = null; res = null;
} }
@ -5740,7 +5740,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else { } else {
String url = convertToString(execute(context, focus, expr.getParameters().get(0), true)); String url = convertToString(execute(context, focus, expr.getParameters().get(0), true));
result.add(new BooleanType(hostServices.conformsToProfile(context.appInfo, focus.get(0), url)).noExtensions()); result.add(new BooleanType(hostServices.conformsToProfile(this, context.appInfo, focus.get(0), url)).noExtensions());
} }
return result; return result;
} }

View File

@ -369,21 +369,21 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (ctxt.vars.containsKey(name)) if (ctxt.vars.containsKey(name))
return new ArrayList<>(Arrays.asList(ctxt.vars.get(name))); return new ArrayList<>(Arrays.asList(ctxt.vars.get(name)));
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
return externalHostServices.resolveConstant(ctxt.externalContext, name, beforeContext); return externalHostServices.resolveConstant(engine, ctxt.externalContext, name, beforeContext, explicitConstant);
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.resolveConstantType(ctxt.externalContext, name); return externalHostServices.resolveConstantType(engine, ctxt.externalContext, name, explicitConstant);
} }
@Override @Override
@ -394,51 +394,51 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
return externalHostServices.resolveFunction(functionName); return externalHostServices.resolveFunction(engine, functionName);
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.checkFunction(ctxt.externalContext, functionName, parameters); return externalHostServices.checkFunction(engine, ctxt.externalContext, functionName, focus, parameters);
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.executeFunction(ctxt.externalContext, focus, functionName, parameters); return externalHostServices.executeFunction(engine, ctxt.externalContext, focus, functionName, parameters);
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base base) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base base) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return resolveReference(ctxt.externalContext, url, base); return resolveReference(engine, ctxt.externalContext, url, base);
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return false; return false;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return conformsToProfile(ctxt.externalContext, item, url); return conformsToProfile(engine, ctxt.externalContext, item, url);
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (externalHostServices != null) if (externalHostServices != null)
return externalHostServices.resolveValueSet(ctxt.externalContext, url); return externalHostServices.resolveValueSet(engine, ctxt.externalContext, url);
else else
return engine.getWorker().fetchResource(ValueSet.class, url); return engine.getWorker().fetchResource(ValueSet.class, url);
} }

View File

@ -177,7 +177,7 @@ public class StructureMapUtilities {
private class FHIRPathHostServices implements IEvaluationContext { private class FHIRPathHostServices implements IEvaluationContext {
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
Variables vars = (Variables) appContext; Variables vars = (Variables) appContext;
Base res = vars.get(VariableMode.INPUT, name); Base res = vars.get(VariableMode.INPUT, name);
@ -190,7 +190,7 @@ public class StructureMapUtilities {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (!(appContext instanceof VariablesForProfiling)) if (!(appContext instanceof VariablesForProfiling))
throw new Error( throw new Error(
"Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)"); "Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)");
@ -207,31 +207,31 @@ public class StructureMapUtilities {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; // throw new Error("Not Implemented Yet"); return null; // throw new Error("Not Implemented Yet");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base base) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base base) throws FHIRException {
if (services == null) if (services == null)
return null; return null;
return services.resolveReference(appContext, url); return services.resolveReference(appContext, url);
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = worker.newValidator(); IResourceValidator val = worker.newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -245,7 +245,7 @@ public class StructureMapUtilities {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }

View File

@ -58,14 +58,14 @@ public class FHIRPathTests {
public class FHIRPathTestEvaluationServices implements IEvaluationContext { public class FHIRPathTestEvaluationServices implements IEvaluationContext {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element");
} }
@ -76,34 +76,34 @@ public class FHIRPathTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName "Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName
+ ")"); + ")");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base base) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base base) throws FHIRException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element");
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient"))
return true; return true;
if (url.equals("http://hl7.org/fhir/StructureDefinition/Person")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Person"))
@ -113,7 +113,7 @@ public class FHIRPathTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return TestingUtilities.context().fetchResource(ValueSet.class, url); return TestingUtilities.context().fetchResource(ValueSet.class, url);
} }
@ -323,7 +323,7 @@ public class FHIRPathTests {
final String DUMMY_CONSTANT_2 = "dummyConstant2"; final String DUMMY_CONSTANT_2 = "dummyConstant2";
fp.setHostServices(new FHIRPathTestEvaluationServices() { fp.setHostServices(new FHIRPathTestEvaluationServices() {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
return Arrays.asList(new StringType(DUMMY_CONSTANT_1).noExtensions(), return Arrays.asList(new StringType(DUMMY_CONSTANT_1).noExtensions(),

View File

@ -300,13 +300,13 @@ public class SnapShotGenerationTests {
// FHIRPath methods // FHIRPath methods
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@ -317,14 +317,14 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new FunctionDetails("Access a fixture defined in the testing context", 0, 1); return new FunctionDetails("Access a fixture defined in the testing context", 0, 1);
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.context().getResourceNamesAsSet()); return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.context().getResourceNamesAsSet());
@ -332,7 +332,7 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
if ("fixture".equals(functionName)) { if ("fixture".equals(functionName)) {
String id = fp.convertToString(parameters.get(0)); String id = fp.convertToString(parameters.get(0));
@ -348,13 +348,13 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base base) { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base base) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = TestingUtilities.context().newValidator(); IResourceValidator val = TestingUtilities.context().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -381,7 +381,7 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }

View File

@ -14,6 +14,7 @@ import java.util.Set;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException; import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r4b.utils.FHIRPathEngine;
import org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison; import org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison;
import org.hl7.fhir.r4b.comparison.ProfileComparer.ProfileComparison; import org.hl7.fhir.r4b.comparison.ProfileComparer.ProfileComparison;
import org.hl7.fhir.r4b.comparison.ResourceComparer.PlaceHolderComparison; import org.hl7.fhir.r4b.comparison.ResourceComparer.PlaceHolderComparison;
@ -231,7 +232,7 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Base> vars = (Map<String, Base>) appContext; Map<String, Base> vars = (Map<String, Base>) appContext;
List<Base> res = new ArrayList<>(); List<Base> res = new ArrayList<>();
@ -242,7 +243,7 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Base> vars = (Map<String, Base>) appContext; Map<String, Base> vars = (Map<String, Base>) appContext;
Base b = vars.get(name); Base b = vars.get(name);
@ -255,34 +256,34 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
return null; return null;
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
return null; return null;
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
return false; return false;
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return null; return null;
} }

View File

@ -152,9 +152,9 @@ public class FHIRPathEngine {
* @return the value of the reference (or null, if it's not valid, though can * @return the value of the reference (or null, if it's not valid, though can
* throw an exception if desired) * throw an exception if desired)
*/ */
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException; public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException;
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException; public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException;
/** /**
* when the .log() function is called * when the .log() function is called
@ -171,7 +171,7 @@ public class FHIRPathEngine {
* @param functionName * @param functionName
* @return null if the function is not known * @return null if the function is not known
*/ */
public FunctionDetails resolveFunction(String functionName); public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName);
/** /**
* Check the function parameters, and throw an error if they are incorrect, or * Check the function parameters, and throw an error if they are incorrect, or
@ -181,7 +181,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException; throws PathEngineException;
/** /**
@ -190,7 +190,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters); List<List<Base>> parameters);
/** /**
@ -202,14 +202,14 @@ public class FHIRPathEngine {
* @return * @return
* @throws FHIRException * @throws FHIRException
*/ */
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException; public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException;
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException; public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException;
/* /*
* return the value set referenced by the url, which has been used in memberOf() * return the value set referenced by the url, which has been used in memberOf()
*/ */
public ValueSet resolveValueSet(Object appContext, String url); public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url);
} }
/** /**
@ -1034,7 +1034,7 @@ public class FHIRPathEngine {
FunctionDetails details = null; FunctionDetails details = null;
if (f == null) { if (f == null) {
if (hostServices != null) { if (hostServices != null) {
details = hostServices.resolveFunction(result.getName()); details = hostServices.resolveFunction(this, result.getName());
} }
if (details == null) { if (details == null) {
throw lexer.error("The name " + result.getName() + " is not a valid function name"); throw lexer.error("The name " + result.getName() + " is not a valid function name");
@ -1474,7 +1474,7 @@ public class FHIRPathEngine {
work.addAll(work2); work.addAll(work2);
break; break;
case Constant: case Constant:
work.addAll(resolveConstant(context, exp.getConstant(), false, exp)); work.addAll(resolveConstant(context, exp.getConstant(), false, exp, true));
break; break;
case Group: case Group:
work2 = execute(context, focus, exp.getGroup(), atEntry); work2 = execute(context, focus, exp.getGroup(), atEntry);
@ -1564,7 +1564,7 @@ public class FHIRPathEngine {
} else if (atEntry && exp.getName().equals("$index")) { } else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer); result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) { } else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp)); result.update(executeContextType(context, exp.getName(), exp, false));
} else { } else {
for (String s : focus.getTypes()) { for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry)); result.update(executeType(s, exp, atEntry));
@ -1583,7 +1583,7 @@ public class FHIRPathEngine {
result.addType(TypeDetails.FP_Quantity); result.addType(TypeDetails.FP_Quantity);
break; break;
case Constant: case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp)); result.update(resolveConstantType(context, exp.getConstant(), exp, true));
break; break;
case Group: case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry)); result.update(executeType(context, focus, exp.getGroup(), atEntry));
@ -1614,7 +1614,7 @@ public class FHIRPathEngine {
} }
private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext, private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext,
ExpressionNode expr) throws PathEngineException { ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
if (constant == null) { if (constant == null) {
return new ArrayList<Base>(); return new ArrayList<Base>();
} }
@ -1623,7 +1623,7 @@ public class FHIRPathEngine {
} }
FHIRConstant c = (FHIRConstant) constant; FHIRConstant c = (FHIRConstant) constant;
if (c.getValue().startsWith("%")) { if (c.getValue().startsWith("%")) {
return resolveConstant(context, c.getValue(), beforeContext, expr); return resolveConstant(context, c.getValue(), beforeContext, expr, explicitConstant);
} else if (c.getValue().startsWith("@")) { } else if (c.getValue().startsWith("@")) {
return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr))); return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr)));
} else { } else {
@ -1693,7 +1693,7 @@ public class FHIRPathEngine {
} }
} }
private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr) private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (s.equals("%sct")) { if (s.equals("%sct")) {
return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions())); return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions()));
@ -1727,7 +1727,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstant(context.appInfo, s.substring(1), beforeContext); return hostServices.resolveConstant(this, context.appInfo, s.substring(1), beforeContext, explicitConstant);
} }
} }
@ -2550,7 +2550,7 @@ public class FHIRPathEngine {
throws FHIRException { throws FHIRException {
boolean ans = false; boolean ans = false;
String url = right.get(0).primitiveValue(); String url = right.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url)
: worker.fetchResource(ValueSet.class, url); : worker.fetchResource(ValueSet.class, url);
if (vs != null) { if (vs != null) {
for (Base l : left) { for (Base l : left) {
@ -3081,7 +3081,7 @@ public class FHIRPathEngine {
return result; return result;
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr) private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (constant instanceof BooleanType) { if (constant instanceof BooleanType) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
@ -3092,7 +3092,7 @@ public class FHIRPathEngine {
} else if (constant instanceof Quantity) { } else if (constant instanceof Quantity) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity);
} else if (constant instanceof FHIRConstant) { } else if (constant instanceof FHIRConstant) {
return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr); return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr, explicitConstant);
} else if (constant == null) { } else if (constant == null) {
return new TypeDetails(CollectionStatus.SINGLETON); return new TypeDetails(CollectionStatus.SINGLETON);
} else { } else {
@ -3100,7 +3100,7 @@ public class FHIRPathEngine {
} }
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr) private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
if (s.startsWith("@")) { if (s.startsWith("@")) {
if (s.startsWith("@T")) { if (s.startsWith("@T")) {
@ -3139,7 +3139,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstantType(context.appInfo, s); return hostServices.resolveConstantType(this, context.appInfo, s, explicitConstant);
} }
} }
@ -3148,7 +3148,7 @@ public class FHIRPathEngine {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (atEntry && context.appInfo != null && hostServices != null) { if (atEntry && context.appInfo != null && hostServices != null) {
// we'll see if the name matches a constant known by the context. // we'll see if the name matches a constant known by the context.
List<Base> temp = hostServices.resolveConstant(context.appInfo, exp.getName(), true); List<Base> temp = hostServices.resolveConstant(this, context.appInfo, exp.getName(), true, false);
if (!temp.isEmpty()) { if (!temp.isEmpty()) {
result.addAll(temp); result.addAll(temp);
return result; return result;
@ -3179,7 +3179,7 @@ public class FHIRPathEngine {
// constant known by the context. // constant known by the context.
// (if the name does match, and the user wants to get the constant value, // (if the name does match, and the user wants to get the constant value,
// they'll have to try harder... // they'll have to try harder...
result.addAll(hostServices.resolveConstant(context.appInfo, exp.getName(), false)); result.addAll(hostServices.resolveConstant(this, context.appInfo, exp.getName(), false, false));
} }
return result; return result;
} }
@ -3188,12 +3188,12 @@ public class FHIRPathEngine {
return null; return null;
} }
private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr) private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException, DefinitionException { throws PathEngineException, DefinitionException {
if (hostServices == null) { if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference"); throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference");
} }
return hostServices.resolveConstantType(context.appInfo, name); return hostServices.resolveConstantType(this, context.appInfo, name, explicitConstant);
} }
private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry) private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry)
@ -3609,7 +3609,7 @@ public class FHIRPathEngine {
} }
case Custom: { case Custom: {
return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes); return hostServices.checkFunction(this, context.appInfo, exp.getName(), focus, paramTypes);
} }
default: default:
break; break;
@ -3934,7 +3934,7 @@ public class FHIRPathEngine {
for (ExpressionNode p : exp.getParameters()) { for (ExpressionNode p : exp.getParameters()) {
params.add(execute(context, focus, p, true)); params.add(execute(context, focus, p, true));
} }
return hostServices.executeFunction(context.appInfo, focus, exp.getName(), params); return hostServices.executeFunction(this, context.appInfo, focus, exp.getName(), params);
} }
default: default:
throw new Error("not Implemented yet"); throw new Error("not Implemented yet");
@ -4607,7 +4607,7 @@ public class FHIRPathEngine {
} }
String url = nl.get(0).primitiveValue(); String url = nl.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url)
: worker.fetchResource(ValueSet.class, url); : worker.fetchResource(ValueSet.class, url);
if (vs == null) { if (vs == null) {
return new ArrayList<Base>(); return new ArrayList<Base>();
@ -5213,7 +5213,7 @@ public class FHIRPathEngine {
} }
} else if (hostServices != null) { } else if (hostServices != null) {
try { try {
res = hostServices.resolveReference(context.appInfo, s, refContext); res = hostServices.resolveReference(this, context.appInfo, s, refContext);
} catch (Exception e) { } catch (Exception e) {
res = null; res = null;
} }
@ -5743,7 +5743,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else { } else {
String url = convertToString(execute(context, focus, expr.getParameters().get(0), true)); String url = convertToString(execute(context, focus, expr.getParameters().get(0), true));
result.add(new BooleanType(hostServices.conformsToProfile(context.appInfo, focus.get(0), url)).noExtensions()); result.add(new BooleanType(hostServices.conformsToProfile(this, context.appInfo, focus.get(0), url)).noExtensions());
} }
return result; return result;
} }

View File

@ -738,7 +738,7 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (ctxt.loopVars.containsKey(name)) if (ctxt.loopVars.containsKey(name))
return new ArrayList<Base>(Arrays.asList(ctxt.loopVars.get(name))); return new ArrayList<Base>(Arrays.asList(ctxt.loopVars.get(name)));
@ -746,15 +746,15 @@ public class LiquidEngine implements IEvaluationContext {
return new ArrayList<Base>(Arrays.asList(ctxt.globalVars.get(name))); return new ArrayList<Base>(Arrays.asList(ctxt.globalVars.get(name)));
if (externalHostServices == null) if (externalHostServices == null)
return new ArrayList<Base>(); return new ArrayList<Base>();
return externalHostServices.resolveConstant(ctxt.externalContext, name, beforeContext); return externalHostServices.resolveConstant(engine, ctxt.externalContext, name, beforeContext, explicitConstant);
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.resolveConstantType(ctxt.externalContext, name); return externalHostServices.resolveConstantType(engine, ctxt.externalContext, name, explicitConstant);
} }
@Override @Override
@ -765,49 +765,49 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
return externalHostServices.resolveFunction(functionName); return externalHostServices.resolveFunction(engine, functionName);
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.checkFunction(ctxt.externalContext, functionName, parameters); return externalHostServices.checkFunction(engine, ctxt.externalContext, functionName, focus, parameters);
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.executeFunction(ctxt.externalContext, focus, functionName, parameters); return externalHostServices.executeFunction(engine, ctxt.externalContext, focus, functionName, parameters);
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return resolveReference(ctxt.externalContext, url, refContext); return resolveReference(engine, ctxt.externalContext, url, refContext);
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return false; return false;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return conformsToProfile(ctxt.externalContext, item, url); return conformsToProfile(engine, ctxt.externalContext, item, url);
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (externalHostServices != null) if (externalHostServices != null)
return externalHostServices.resolveValueSet(ctxt.externalContext, url); return externalHostServices.resolveValueSet(engine, ctxt.externalContext, url);
else else
return engine.getWorker().fetchResource(ValueSet.class, url); return engine.getWorker().fetchResource(ValueSet.class, url);
} }

View File

@ -24,7 +24,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
this.structureMapUtilities = structureMapUtilities; this.structureMapUtilities = structureMapUtilities;
} }
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
Variables vars = (Variables) appContext; Variables vars = (Variables) appContext;
Base res = vars.get(VariableMode.INPUT, name); Base res = vars.get(VariableMode.INPUT, name);
if (res == null) if (res == null)
@ -36,7 +36,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (!(appContext instanceof VariablesForProfiling)) if (!(appContext instanceof VariablesForProfiling))
throw new Error( throw new Error(
"Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)"); "Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)");
@ -53,24 +53,24 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; // throw new Error("Not Implemented Yet"); return null; // throw new Error("Not Implemented Yet");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
if (structureMapUtilities.getServices() == null) if (structureMapUtilities.getServices() == null)
return null; return null;
return structureMapUtilities.getServices().resolveReference(appContext, url); return structureMapUtilities.getServices().resolveReference(appContext, url);
@ -84,7 +84,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = structureMapUtilities.getWorker().newValidator(); IResourceValidator val = structureMapUtilities.getWorker().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -100,7 +100,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }

View File

@ -111,7 +111,7 @@ public class StructureMapUtilities {
private class FHIRPathHostServices implements IEvaluationContext { private class FHIRPathHostServices implements IEvaluationContext {
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
Variables vars = (Variables) appContext; Variables vars = (Variables) appContext;
List<Base> list = new ArrayList<Base>(); List<Base> list = new ArrayList<Base>();
@ -126,7 +126,7 @@ public class StructureMapUtilities {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (!(appContext instanceof VariablesForProfiling)) if (!(appContext instanceof VariablesForProfiling))
throw new Error( throw new Error(
"Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)"); "Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)");
@ -143,31 +143,31 @@ public class StructureMapUtilities {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; // throw new Error("Not Implemented Yet"); return null; // throw new Error("Not Implemented Yet");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base base) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base base) throws FHIRException {
if (services == null) if (services == null)
return null; return null;
return services.resolveReference(appContext, url); return services.resolveReference(appContext, url);
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = worker.newValidator(); IResourceValidator val = worker.newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -181,7 +181,7 @@ public class StructureMapUtilities {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }

View File

@ -44,14 +44,14 @@ public class FHIRPathTests {
public class FHIRPathTestEvaluationServices implements IEvaluationContext { public class FHIRPathTestEvaluationServices implements IEvaluationContext {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element");
} }
@ -62,34 +62,34 @@ public class FHIRPathTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName "Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName
+ ")"); + ")");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element"); "Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element");
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient"))
return true; return true;
if (url.equals("http://hl7.org/fhir/StructureDefinition/Person")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Person"))
@ -99,7 +99,7 @@ public class FHIRPathTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return TestingUtilities.context().fetchResource(ValueSet.class, url); return TestingUtilities.context().fetchResource(ValueSet.class, url);
} }
@ -310,7 +310,7 @@ public class FHIRPathTests {
final String DUMMY_CONSTANT_2 = "dummyConstant2"; final String DUMMY_CONSTANT_2 = "dummyConstant2";
fp.setHostServices(new FHIRPathTestEvaluationServices() { fp.setHostServices(new FHIRPathTestEvaluationServices() {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
return Arrays.asList(new StringType(DUMMY_CONSTANT_1).noExtensions(), return Arrays.asList(new StringType(DUMMY_CONSTANT_1).noExtensions(),

View File

@ -368,13 +368,13 @@ public class SnapShotGenerationTests {
// FHIRPath methods // FHIRPath methods
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant)
throws PathEngineException { throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@ -385,14 +385,14 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new FunctionDetails("Access a fixture defined in the testing context", 0, 1); return new FunctionDetails("Access a fixture defined in the testing context", 0, 1);
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters)
throws PathEngineException { throws PathEngineException {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.context().getResourceNamesAsSet()); return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.context().getResourceNamesAsSet());
@ -400,7 +400,7 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName,
List<List<Base>> parameters) { List<List<Base>> parameters) {
if ("fixture".equals(functionName)) { if ("fixture".equals(functionName)) {
String id = fp.convertToString(parameters.get(0)); String id = fp.convertToString(parameters.get(0));
@ -416,13 +416,13 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = TestingUtilities.context().newValidator(); IResourceValidator val = TestingUtilities.context().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -451,7 +451,7 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }

View File

@ -14,6 +14,7 @@ import java.util.Set;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException; import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison; import org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison;
import org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison; import org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison;
import org.hl7.fhir.r5.comparison.ResourceComparer.PlaceHolderComparison; import org.hl7.fhir.r5.comparison.ResourceComparer.PlaceHolderComparison;
@ -255,7 +256,7 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Base> vars = (Map<String, Base>) appContext; Map<String, Base> vars = (Map<String, Base>) appContext;
List<Base> res = new ArrayList<>(); List<Base> res = new ArrayList<>();
@ -266,7 +267,7 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Base> vars = (Map<String, Base>) appContext; Map<String, Base> vars = (Map<String, Base>) appContext;
Base b = vars.get(name); Base b = vars.get(name);
@ -279,32 +280,32 @@ public class ComparisonRenderer implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
return null; return null;
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
return null; return null;
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
return false; return false;
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return null; return null;
} }

View File

@ -153,8 +153,8 @@ public class FHIRPathEngine {
* @param beforeContext - whether this is being called before the name is resolved locally, or not * @param beforeContext - whether this is being called before the name is resolved locally, or not
* @return the value of the reference (or null, if it's not valid, though can throw an exception if desired) * @return the value of the reference (or null, if it's not valid, though can throw an exception if desired)
*/ */
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException; public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException;
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException; public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException;
/** /**
* when the .log() function is called * when the .log() function is called
@ -171,7 +171,7 @@ public class FHIRPathEngine {
* @param functionName * @param functionName
* @return null if the function is not known * @return null if the function is not known
*/ */
public FunctionDetails resolveFunction(String functionName); public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName);
/** /**
* Check the function parameters, and throw an error if they are incorrect, or return the type for the function * Check the function parameters, and throw an error if they are incorrect, or return the type for the function
@ -179,7 +179,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException; public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException;
/** /**
* @param appContext * @param appContext
@ -187,7 +187,7 @@ public class FHIRPathEngine {
* @param parameters * @param parameters
* @return * @return
*/ */
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters); public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters);
/** /**
* Implementation of resolve() function. Passed a string, return matching resource, if one is known - else null * Implementation of resolve() function. Passed a string, return matching resource, if one is known - else null
@ -196,14 +196,14 @@ public class FHIRPathEngine {
* @return * @return
* @throws FHIRException * @throws FHIRException
*/ */
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException; public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException;
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException; public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException;
/* /*
* return the value set referenced by the url, which has been used in memberOf() * return the value set referenced by the url, which has been used in memberOf()
*/ */
public ValueSet resolveValueSet(Object appContext, String url); public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url);
/** /**
* For the moment, there can only be one parameter if it's a type parameter * For the moment, there can only be one parameter if it's a type parameter
@ -1112,7 +1112,7 @@ public class FHIRPathEngine {
FunctionDetails details = null; FunctionDetails details = null;
if (f == null) { if (f == null) {
if (hostServices != null) { if (hostServices != null) {
details = hostServices.resolveFunction(result.getName()); details = hostServices.resolveFunction(this, result.getName());
} }
if (details == null) { if (details == null) {
throw lexer.error("The name "+result.getName()+" is not a valid function name"); throw lexer.error("The name "+result.getName()+" is not a valid function name");
@ -1536,7 +1536,7 @@ public class FHIRPathEngine {
} else if (atEntry && exp.getName().equals("$index")) { } else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer); result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) { } else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp)); result.update(executeContextType(context, exp.getName(), exp, false));
} else { } else {
for (String s : focus.getTypes()) { for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry, focus, elementDependencies)); result.update(executeType(s, exp, atEntry, focus, elementDependencies));
@ -1560,7 +1560,7 @@ public class FHIRPathEngine {
result.addType(TypeDetails.FP_Quantity); result.addType(TypeDetails.FP_Quantity);
break; break;
case Constant: case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp)); result.update(resolveConstantType(context, exp.getConstant(), exp, true));
break; break;
case Group: case Group:
result.update(executeType(context, focus, exp.getGroup(), elementDependencies, atEntry, canBeNone, exp)); result.update(executeType(context, focus, exp.getGroup(), elementDependencies, atEntry, canBeNone, exp));
@ -1612,7 +1612,7 @@ public class FHIRPathEngine {
} }
FHIRConstant c = (FHIRConstant) constant; FHIRConstant c = (FHIRConstant) constant;
if (c.getValue().startsWith("%")) { if (c.getValue().startsWith("%")) {
return resolveConstant(context, c.getValue(), beforeContext, expr); return resolveConstant(context, c.getValue(), beforeContext, expr, true);
} else if (c.getValue().startsWith("@")) { } else if (c.getValue().startsWith("@")) {
return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr))); return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr)));
} else { } else {
@ -1683,7 +1683,7 @@ public class FHIRPathEngine {
} }
private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr) throws PathEngineException { private List<Base> resolveConstant(ExecutionContext context, String s, boolean beforeContext, ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
if (s.equals("%sct")) { if (s.equals("%sct")) {
return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions())); return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions()));
} else if (s.equals("%loinc")) { } else if (s.equals("%loinc")) {
@ -1713,7 +1713,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstant(context.appInfo, s.substring(1), beforeContext); return hostServices.resolveConstant(this, context.appInfo, s.substring(1), beforeContext, explicitConstant);
} }
} }
@ -2532,7 +2532,7 @@ public class FHIRPathEngine {
private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException { private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
boolean ans = false; boolean ans = false;
String url = right.get(0).primitiveValue(); String url = right.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) : worker.fetchResource(ValueSet.class, url); ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url) : worker.fetchResource(ValueSet.class, url);
if (vs != null) { if (vs != null) {
for (Base l : left) { for (Base l : left) {
if (Utilities.existsInList(l.fhirType(), "code", "string", "uri")) { if (Utilities.existsInList(l.fhirType(), "code", "string", "uri")) {
@ -3031,7 +3031,7 @@ public class FHIRPathEngine {
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr) throws PathEngineException { private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
if (constant instanceof BooleanType) { if (constant instanceof BooleanType) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
} else if (constant instanceof IntegerType) { } else if (constant instanceof IntegerType) {
@ -3041,7 +3041,7 @@ public class FHIRPathEngine {
} else if (constant instanceof Quantity) { } else if (constant instanceof Quantity) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity);
} else if (constant instanceof FHIRConstant) { } else if (constant instanceof FHIRConstant) {
return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr); return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr, explicitConstant);
} else if (constant == null) { } else if (constant == null) {
return new TypeDetails(CollectionStatus.SINGLETON); return new TypeDetails(CollectionStatus.SINGLETON);
} else { } else {
@ -3049,7 +3049,7 @@ public class FHIRPathEngine {
} }
} }
private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr) throws PathEngineException { private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
if (s.startsWith("@")) { if (s.startsWith("@")) {
if (s.startsWith("@T")) { if (s.startsWith("@T")) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Time); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Time);
@ -3087,7 +3087,7 @@ public class FHIRPathEngine {
} else if (hostServices == null) { } else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s); throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else { } else {
return hostServices.resolveConstantType(context.appInfo, s); return hostServices.resolveConstantType(this, context.appInfo, s, explicitConstant);
} }
} }
@ -3095,7 +3095,7 @@ public class FHIRPathEngine {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (atEntry && context.appInfo != null && hostServices != null) { if (atEntry && context.appInfo != null && hostServices != null) {
// we'll see if the name matches a constant known by the context. // we'll see if the name matches a constant known by the context.
List<Base> temp = hostServices.resolveConstant(context.appInfo, exp.getName(), true); List<Base> temp = hostServices.resolveConstant(this, context.appInfo, exp.getName(), true, false);
if (!temp.isEmpty()) { if (!temp.isEmpty()) {
result.addAll(temp); result.addAll(temp);
return result; return result;
@ -3123,7 +3123,7 @@ public class FHIRPathEngine {
if (atEntry && context.appInfo != null && hostServices != null && result.isEmpty()) { if (atEntry && context.appInfo != null && hostServices != null && result.isEmpty()) {
// well, we didn't get a match on the name - we'll see if the name matches a constant known by the context. // well, we didn't get a match on the name - we'll see if the name matches a constant known by the context.
// (if the name does match, and the user wants to get the constant value, they'll have to try harder... // (if the name does match, and the user wants to get the constant value, they'll have to try harder...
result.addAll(hostServices.resolveConstant(context.appInfo, exp.getName(), false)); result.addAll(hostServices.resolveConstant(this, context.appInfo, exp.getName(), false, false));
} }
return result; return result;
} }
@ -3133,11 +3133,11 @@ public class FHIRPathEngine {
} }
private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr) throws PathEngineException, DefinitionException { private TypeDetails executeContextType(ExecutionTypeContext context, String name, ExpressionNode expr, boolean explicitConstant) throws PathEngineException, DefinitionException {
if (hostServices == null) { if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference"); throw makeException(expr, I18nConstants.FHIRPATH_HO_HOST_SERVICES, "Context Reference");
} }
return hostServices.resolveConstantType(context.appInfo, name); return hostServices.resolveConstantType(this, context.appInfo, name, explicitConstant);
} }
private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry, TypeDetails focus, Set<ElementDefinition> elementDependencies) throws PathEngineException, DefinitionException { private TypeDetails executeType(String type, ExpressionNode exp, boolean atEntry, TypeDetails focus, Set<ElementDefinition> elementDependencies) throws PathEngineException, DefinitionException {
@ -3585,7 +3585,7 @@ public class FHIRPathEngine {
} }
case Custom : { case Custom : {
return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes); return hostServices.checkFunction(this, context.appInfo,exp.getName(), focus, paramTypes);
} }
default: default:
break; break;
@ -3818,7 +3818,7 @@ public class FHIRPathEngine {
params.add(execute(context, focus, p, true)); params.add(execute(context, focus, p, true));
} }
} }
return hostServices.executeFunction(context.appInfo, focus, exp.getName(), params); return hostServices.executeFunction(this, context.appInfo, focus, exp.getName(), params);
} }
default: default:
throw new Error("not Implemented yet"); throw new Error("not Implemented yet");
@ -4481,7 +4481,7 @@ public class FHIRPathEngine {
} }
String url = nl.get(0).primitiveValue(); String url = nl.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) : worker.fetchResource(ValueSet.class, url); ValueSet vs = hostServices != null ? hostServices.resolveValueSet(this, context.appInfo, url) : worker.fetchResource(ValueSet.class, url);
if (vs == null) { if (vs == null) {
return new ArrayList<Base>(); return new ArrayList<Base>();
} }
@ -5108,7 +5108,7 @@ public class FHIRPathEngine {
} }
} else if (hostServices != null) { } else if (hostServices != null) {
try { try {
res = hostServices.resolveReference(context.appInfo, s, refContext); res = hostServices.resolveReference(this, context.appInfo, s, refContext);
} catch (Exception e) { } catch (Exception e) {
res = null; res = null;
} }
@ -5616,7 +5616,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else { } else {
String url = convertToString(execute(context, focus, expr.getParameters().get(0), true)); String url = convertToString(execute(context, focus, expr.getParameters().get(0), true));
result.add(new BooleanType(hostServices.conformsToProfile(context.appInfo, focus.get(0), url)).noExtensions()); result.add(new BooleanType(hostServices.conformsToProfile(this, context.appInfo, focus.get(0), url)).noExtensions());
} }
return result; return result;
} }

View File

@ -741,7 +741,7 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (ctxt.loopVars.containsKey(name)) if (ctxt.loopVars.containsKey(name))
return new ArrayList<Base>(Arrays.asList(ctxt.loopVars.get(name))); return new ArrayList<Base>(Arrays.asList(ctxt.loopVars.get(name)));
@ -749,15 +749,15 @@ public class LiquidEngine implements IEvaluationContext {
return new ArrayList<Base>(Arrays.asList(ctxt.globalVars.get(name))); return new ArrayList<Base>(Arrays.asList(ctxt.globalVars.get(name)));
if (externalHostServices == null) if (externalHostServices == null)
return new ArrayList<Base>(); return new ArrayList<Base>();
return externalHostServices.resolveConstant(ctxt.externalContext, name, beforeContext); return externalHostServices.resolveConstant(engine, ctxt.externalContext, name, beforeContext, explicitConstant);
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.resolveConstantType(ctxt.externalContext, name); return externalHostServices.resolveConstantType(engine, ctxt.externalContext, name, explicitConstant);
} }
@Override @Override
@ -768,49 +768,49 @@ public class LiquidEngine implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
return externalHostServices.resolveFunction(functionName); return externalHostServices.resolveFunction(engine, functionName);
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.checkFunction(ctxt.externalContext, functionName, parameters); return externalHostServices.checkFunction(engine, ctxt.externalContext, functionName, focus, parameters);
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return externalHostServices.executeFunction(ctxt.externalContext, focus, functionName, parameters); return externalHostServices.executeFunction(engine, ctxt.externalContext, focus, functionName, parameters);
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return null; return null;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return resolveReference(ctxt.externalContext, url, refContext); return resolveReference(engine, ctxt.externalContext, url, refContext);
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (externalHostServices == null) if (externalHostServices == null)
return false; return false;
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
return conformsToProfile(ctxt.externalContext, item, url); return conformsToProfile(engine, ctxt.externalContext, item, url);
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
LiquidEngineContext ctxt = (LiquidEngineContext) appContext; LiquidEngineContext ctxt = (LiquidEngineContext) appContext;
if (externalHostServices != null) if (externalHostServices != null)
return externalHostServices.resolveValueSet(ctxt.externalContext, url); return externalHostServices.resolveValueSet(engine, ctxt.externalContext, url);
else else
return engine.getWorker().fetchResource(ValueSet.class, url); return engine.getWorker().fetchResource(ValueSet.class, url);
} }

View File

@ -318,12 +318,12 @@ public class Runner implements IEvaluationContext {
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet: resolveConstant"); throw new Error("Not implemented yet: resolveConstant");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet: resolveConstantType"); throw new Error("Not implemented yet: resolveConstantType");
} }
@ -333,7 +333,7 @@ public class Runner implements IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
switch (functionName) { switch (functionName) {
case "getResourceKey" : return new FunctionDetails("Unique Key for resource", 0, 0); case "getResourceKey" : return new FunctionDetails("Unique Key for resource", 0, 0);
case "getReferenceKey" : return new FunctionDetails("Unique Key for resource that is the target of the reference", 0, 1); case "getReferenceKey" : return new FunctionDetails("Unique Key for resource that is the target of the reference", 0, 1);
@ -341,7 +341,7 @@ public class Runner implements IEvaluationContext {
} }
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
switch (functionName) { switch (functionName) {
case "getResourceKey" : return new TypeDetails(CollectionStatus.SINGLETON, "string"); case "getResourceKey" : return new TypeDetails(CollectionStatus.SINGLETON, "string");
case "getReferenceKey" : return new TypeDetails(CollectionStatus.SINGLETON, "string"); case "getReferenceKey" : return new TypeDetails(CollectionStatus.SINGLETON, "string");
@ -350,7 +350,7 @@ public class Runner implements IEvaluationContext {
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
switch (functionName) { switch (functionName) {
case "getResourceKey" : return executeResourceKey(focus); case "getResourceKey" : return executeResourceKey(focus);
case "getReferenceKey" : return executeReferenceKey(focus, parameters); case "getReferenceKey" : return executeReferenceKey(focus, parameters);
@ -420,17 +420,17 @@ public class Runner implements IEvaluationContext {
return null; return null;
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
throw new Error("Not implemented yet: resolveReference"); throw new Error("Not implemented yet: resolveReference");
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
throw new Error("Not implemented yet: conformsToProfile"); throw new Error("Not implemented yet: conformsToProfile");
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not implemented yet: resolveValueSet"); throw new Error("Not implemented yet: resolveValueSet");
} }
@Override @Override

View File

@ -24,7 +24,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
this.structureMapUtilities = structureMapUtilities; this.structureMapUtilities = structureMapUtilities;
} }
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
Variables vars = (Variables) appContext; Variables vars = (Variables) appContext;
Base res = vars.get(VariableMode.INPUT, name); Base res = vars.get(VariableMode.INPUT, name);
if (res == null) if (res == null)
@ -36,7 +36,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
if (!(appContext instanceof VariablesForProfiling)) if (!(appContext instanceof VariablesForProfiling))
throw new Error("Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)"); throw new Error("Internal Logic Error (wrong type '" + appContext.getClass().getName() + "' in resolveConstantType)");
VariablesForProfiling vars = (VariablesForProfiling) appContext; VariablesForProfiling vars = (VariablesForProfiling) appContext;
@ -52,22 +52,22 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; // throw new Error("Not Implemented Yet"); return null; // throw new Error("Not Implemented Yet");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
throw new Error("Not Implemented Yet"); throw new Error("Not Implemented Yet");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
if (structureMapUtilities.getServices() == null) if (structureMapUtilities.getServices() == null)
return null; return null;
return structureMapUtilities.getServices().resolveReference(appContext, url); return structureMapUtilities.getServices().resolveReference(appContext, url);
@ -81,7 +81,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = structureMapUtilities.getWorker().newValidator(); IResourceValidator val = structureMapUtilities.getWorker().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -96,7 +96,7 @@ public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return structureMapUtilities.getWorker().fetchResource(ValueSet.class, url); return structureMapUtilities.getWorker().fetchResource(ValueSet.class, url);
} }

View File

@ -46,12 +46,12 @@ public class FHIRPathTests {
public class FHIRPathTestEvaluationServices implements IEvaluationContext { public class FHIRPathTestEvaluationServices implements IEvaluationContext {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveConstant), when item is element");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveConstantType), when item is element");
} }
@ -61,27 +61,27 @@ public class FHIRPathTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName + ")"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveFunction), when item is element (for " + functionName + ")");
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.checkFunction), when item is element");
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.executeFunction), when item is element");
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) throws FHIRException {
throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathTestEvaluationServices.resolveReference), when item is element");
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Patient"))
return true; return true;
if (url.equals("http://hl7.org/fhir/StructureDefinition/Person")) if (url.equals("http://hl7.org/fhir/StructureDefinition/Person"))
@ -91,7 +91,7 @@ public class FHIRPathTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return TestingUtilities.getSharedWorkerContext().fetchResource(ValueSet.class, url); return TestingUtilities.getSharedWorkerContext().fetchResource(ValueSet.class, url);
} }
@ -291,7 +291,7 @@ public class FHIRPathTests {
final String DUMMY_CONSTANT_2 = "dummyConstant2"; final String DUMMY_CONSTANT_2 = "dummyConstant2";
fp.setHostServices(new FHIRPathTestEvaluationServices() { fp.setHostServices(new FHIRPathTestEvaluationServices() {
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
return Arrays.asList( return Arrays.asList(
new StringType(DUMMY_CONSTANT_1).noExtensions(), new StringType(DUMMY_CONSTANT_1).noExtensions(),

View File

@ -337,12 +337,12 @@ public class SnapShotGenerationTests {
// FHIRPath methods // FHIRPath methods
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@ -353,21 +353,21 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new FunctionDetails("Access a fixture defined in the testing context", 0, 1); return new FunctionDetails("Access a fixture defined in the testing context", 0, 1);
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.getSharedWorkerContext().getResourceNamesAsSet()); return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilities.getSharedWorkerContext().getResourceNamesAsSet());
return null; return null;
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
if ("fixture".equals(functionName)) { if ("fixture".equals(functionName)) {
String id = fp.convertToString(parameters.get(0)); String id = fp.convertToString(parameters.get(0));
Resource res = fetchFixture(id); Resource res = fetchFixture(id);
@ -382,13 +382,13 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = TestingUtilities.getSharedWorkerContext().newValidator(); IResourceValidator val = TestingUtilities.getSharedWorkerContext().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -416,7 +416,7 @@ public class SnapShotGenerationTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }

View File

@ -24,7 +24,7 @@ class FHIRPathHostServicesTest {
public void testrResolveValueSet() throws IOException, FHIRException { public void testrResolveValueSet() throws IOException, FHIRException {
StructureMapUtilities scu = new StructureMapUtilities(context); StructureMapUtilities scu = new StructureMapUtilities(context);
FHIRPathHostServices fphs = new FHIRPathHostServices(scu); FHIRPathHostServices fphs = new FHIRPathHostServices(scu);
ValueSet v = fphs.resolveValueSet(null, "http://hl7.org/fhir/ValueSet/FHIR-version"); ValueSet v = fphs.resolveValueSet(null, null, "http://hl7.org/fhir/ValueSet/FHIR-version");
Assertions.assertNotNull(v); Assertions.assertNotNull(v);
Assertions.assertEquals("http://hl7.org/fhir/ValueSet/FHIR-version", v.getUrl()); Assertions.assertEquals("http://hl7.org/fhir/ValueSet/FHIR-version", v.getUrl());
} }

View File

@ -316,12 +316,12 @@ public class SnapShotGenerationXTests {
// FHIRPath methods // FHIRPath methods
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }
@ -332,21 +332,21 @@ public class SnapShotGenerationXTests {
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new FunctionDetails("Access a fixture defined in the testing context", 0, 1); return new FunctionDetails("Access a fixture defined in the testing context", 0, 1);
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
if ("fixture".equals(functionName)) if ("fixture".equals(functionName))
return new TypeDetails(CollectionStatus.SINGLETON, UtilitiesXTests.context(version).getResourceNamesAsSet()); return new TypeDetails(CollectionStatus.SINGLETON, UtilitiesXTests.context(version).getResourceNamesAsSet());
return null; return null;
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
if ("fixture".equals(functionName)) { if ("fixture".equals(functionName)) {
String id = fp.convertToString(parameters.get(0)); String id = fp.convertToString(parameters.get(0));
Resource res = fetchFixture(id); Resource res = fetchFixture(id);
@ -361,13 +361,13 @@ public class SnapShotGenerationXTests {
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = UtilitiesXTests.context(version).newValidator(); IResourceValidator val = UtilitiesXTests.context(version).newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -393,7 +393,7 @@ public class SnapShotGenerationXTests {
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
throw new Error("Not implemented yet"); throw new Error("Not implemented yet");
} }

View File

@ -656,12 +656,12 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
} }
@Override @Override
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException { public List<Base> resolveConstant(FHIRPathEngine engine, Object appContext, String name, boolean beforeContext, boolean explicitConstant) throws PathEngineException {
return new ArrayList<Base>(); return new ArrayList<Base>();
} }
@Override @Override
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException { public TypeDetails resolveConstantType(FHIRPathEngine engine, Object appContext, String name, boolean explicitConstant) throws PathEngineException {
return null; return null;
} }
@ -671,22 +671,22 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
} }
@Override @Override
public FunctionDetails resolveFunction(String functionName) { public FunctionDetails resolveFunction(FHIRPathEngine engine, String functionName) {
return null; return null;
} }
@Override @Override
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException { public TypeDetails checkFunction(FHIRPathEngine engine, Object appContext, String functionName, TypeDetails focus, List<TypeDetails> parameters) throws PathEngineException {
return null; return null;
} }
@Override @Override
public List<Base> executeFunction(Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) { public List<Base> executeFunction(FHIRPathEngine engine, Object appContext, List<Base> focus, String functionName, List<List<Base>> parameters) {
return null; return null;
} }
@Override @Override
public Base resolveReference(Object appContext, String url, Base refContext) { public Base resolveReference(FHIRPathEngine engine, Object appContext, String url, Base refContext) {
if (url.equals("Patient/test")) if (url.equals("Patient/test"))
return new Patient(); return new Patient();
return null; return null;
@ -752,7 +752,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
} }
@Override @Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException { public boolean conformsToProfile(FHIRPathEngine engine, Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = vCurr.getContext().newValidator(); IResourceValidator val = vCurr.getContext().newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>(); List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) { if (item instanceof Resource) {
@ -766,7 +766,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
} }
@Override @Override
public ValueSet resolveValueSet(Object appContext, String url) { public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url) {
return vCurr.getContext().fetchResource(ValueSet.class, url); return vCurr.getContext().fetchResource(ValueSet.class, url);
} }