Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023 10 gg code gen #1469

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
* Update ViewDefinition validator for change (alias -> name)
* Fix for NPE validating sql-on-fhir ViewDefinition
* Fix for index out of bounds error when extension uses itself
* Fix issue where .resolve() in FHIRPath didn't work with URL values (and fix typo in i18n system)
* Implement FHIRPath slice() function in validator

## Other code changes

* Breaking API Change: Revise FHIRPath API so hosts can evaluate expressions in custom functions
* Add package use tracking to FHIR cache for validator.fhir.org
* Support for instance-name and instance-description in IG publisher
* Element.removeExtension (support for instance-name and instance-description extensions in IG publisher)
* Split terminology service tests
* Hack for wrong URLs in subscriptions backport
* Remove dependencies for unused UI experiment
* More improvements to profile code generation
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -245,4 +246,7 @@ else if (n1 instanceof JsonPrimitive) {
return null;
}

public static boolean runningAsSurefire() {
return "true".equals(System.getProperty("runningAsSurefire") != null ? System.getProperty("runningAsSurefire").toLowerCase(Locale.ENGLISH) : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -245,4 +246,8 @@ else if (n1 instanceof JsonPrimitive) {
return null;
}

public static boolean runningAsSurefire() {
return "true".equals(System.getProperty("runningAsSurefire") != null ? System.getProperty("runningAsSurefire").toLowerCase(Locale.ENGLISH) : "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -276,5 +277,7 @@ else if (n1 instanceof JsonNull) {
return null;
}


public static boolean runningAsSurefire() {
return "true".equals(System.getProperty("runningAsSurefire") != null ? System.getProperty("runningAsSurefire").toLowerCase(Locale.ENGLISH) : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -528,4 +529,7 @@ public static String loadTestResource(String... paths) throws IOException {
}
}

public static boolean runningAsSurefire() {
return "true".equals(System.getProperty("runningAsSurefire") != null ? System.getProperty("runningAsSurefire").toLowerCase(Locale.ENGLISH) : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FHIRConstant;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.ClassTypeInfo;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.TypedElementDefinition;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MergedList;
Expand Down Expand Up @@ -150,9 +151,9 @@ public interface IEvaluationContext {
* @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
Expand All @@ -169,7 +170,7 @@ public interface IEvaluationContext {
* @param functionName
* @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
Expand All @@ -179,7 +180,7 @@ public interface IEvaluationContext {
* @param parameters
* @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;

/**
Expand All @@ -188,7 +189,7 @@ public TypeDetails checkFunction(Object appContext, String functionName, List<Ty
* @param parameters
* @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);

/**
Expand All @@ -200,14 +201,14 @@ public List<Base> executeFunction(Object appContext, List<Base> focus, String fu
* @return
* @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()
*/
public ValueSet resolveValueSet(Object appContext, String url);
public ValueSet resolveValueSet(FHIRPathEngine engine, Object appContext, String url);
}

/**
Expand Down Expand Up @@ -1032,7 +1033,7 @@ private ExpressionNode parseExpression(FHIRLexer lexer, boolean proximal) throws
FunctionDetails details = null;
if (f == null) {
if (hostServices != null) {
details = hostServices.resolveFunction(result.getName());
details = hostServices.resolveFunction(this, result.getName());
}
if (details == null) {
throw lexer.error("The name " + result.getName() + " is not a valid function name");
Expand Down Expand Up @@ -1473,7 +1474,7 @@ private List<Base> execute(ExecutionContext context, List<Base> focus, Expressio
work.addAll(work2);
break;
case Constant:
work.addAll(resolveConstant(context, exp.getConstant(), false, exp));
work.addAll(resolveConstant(context, exp.getConstant(), false, exp, true));
break;
case Group:
work2 = execute(context, focus, exp.getGroup(), atEntry);
Expand Down Expand Up @@ -1563,7 +1564,7 @@ private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus,
} else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp));
result.update(executeContextType(context, exp.getName(), exp, false));
} else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
Expand All @@ -1582,7 +1583,7 @@ private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus,
result.addType(TypeDetails.FP_Quantity);
break;
case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp));
result.update(resolveConstantType(context, exp.getConstant(), exp, true));
break;
case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry));
Expand Down Expand Up @@ -1612,8 +1613,7 @@ private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus,
return result;
}

private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext,
ExpressionNode expr) throws PathEngineException {
private List<Base> resolveConstant(ExecutionContext context, Base constant, boolean beforeContext, ExpressionNode expr, boolean explicitConstant) throws PathEngineException {
if (constant == null) {
return new ArrayList<Base>();
}
Expand All @@ -1622,7 +1622,7 @@ private List<Base> resolveConstant(ExecutionContext context, Base constant, bool
}
FHIRConstant c = (FHIRConstant) constant;
if (c.getValue().startsWith("%")) {
return resolveConstant(context, c.getValue(), beforeContext, expr);
return resolveConstant(context, c.getValue(), beforeContext, expr, explicitConstant);
} else if (c.getValue().startsWith("@")) {
return new ArrayList<Base>(Arrays.asList(processDateConstant(context.appInfo, c.getValue().substring(1), expr)));
} else {
Expand Down Expand Up @@ -1692,7 +1692,7 @@ private Base processDateConstant(Object appInfo, String value, ExpressionNode ex
}
}

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 {
if (s.equals("%sct")) {
return new ArrayList<Base>(Arrays.asList(new StringType("http://snomed.info/sct").noExtensions()));
Expand Down Expand Up @@ -1726,7 +1726,7 @@ private List<Base> resolveConstant(ExecutionContext context, String s, boolean b
} else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else {
return hostServices.resolveConstant(context.appInfo, s.substring(1), beforeContext);
return hostServices.resolveConstant(this, context.appInfo, s.substring(1), beforeContext, explicitConstant);
}
}

Expand Down Expand Up @@ -2549,7 +2549,7 @@ private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Ba
throws FHIRException {
boolean ans = false;
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);
if (vs != null) {
for (Base l : left) {
Expand Down Expand Up @@ -3079,7 +3079,7 @@ private List<Base> opMod(List<Base> left, List<Base> right, ExpressionNode expr)
return result;
}

private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr)
private TypeDetails resolveConstantType(ExecutionTypeContext context, Base constant, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException {
if (constant instanceof BooleanType) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
Expand All @@ -3090,15 +3090,15 @@ private TypeDetails resolveConstantType(ExecutionTypeContext context, Base const
} else if (constant instanceof Quantity) {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Quantity);
} else if (constant instanceof FHIRConstant) {
return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr);
return resolveConstantType(context, ((FHIRConstant) constant).getValue(), expr, explicitConstant);
} else if (constant == null) {
return new TypeDetails(CollectionStatus.SINGLETON);
} else {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String);
}
}

private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr)
private TypeDetails resolveConstantType(ExecutionTypeContext context, String s, ExpressionNode expr, boolean explicitConstant)
throws PathEngineException {
if (s.startsWith("@")) {
if (s.startsWith("@T")) {
Expand Down Expand Up @@ -3137,7 +3137,7 @@ private TypeDetails resolveConstantType(ExecutionTypeContext context, String s,
} else if (hostServices == null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONSTANT, s);
} else {
return hostServices.resolveConstantType(context.appInfo, s);
return hostServices.resolveConstantType(this, context.appInfo, s, explicitConstant);
}
}

Expand All @@ -3146,7 +3146,7 @@ private List<Base> execute(ExecutionContext context, Base item, ExpressionNode e
List<Base> result = new ArrayList<Base>();
if (atEntry && context.appInfo != null && hostServices != null) {
// 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()) {
result.addAll(temp);
return result;
Expand Down Expand Up @@ -3177,7 +3177,7 @@ private List<Base> execute(ExecutionContext context, Base item, ExpressionNode e
// 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...
result.addAll(hostServices.resolveConstant(context.appInfo, exp.getName(), false));
result.addAll(hostServices.resolveConstant(this, context.appInfo, exp.getName(), false, false));
}
return result;
}
Expand All @@ -3186,12 +3186,12 @@ private String getParent(String rn) {
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 {
if (hostServices == null) {
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)
Expand Down Expand Up @@ -3607,7 +3607,7 @@ private TypeDetails evaluateFunctionType(ExecutionTypeContext context, TypeDetai
}

case Custom: {
return hostServices.checkFunction(context.appInfo, exp.getName(), paramTypes);
return hostServices.checkFunction(this, context.appInfo, exp.getName(), focus, paramTypes);
}
default:
break;
Expand Down Expand Up @@ -3932,7 +3932,7 @@ private List<Base> evaluateFunction(ExecutionContext context, List<Base> focus,
for (ExpressionNode p : exp.getParameters()) {
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:
throw new Error("not Implemented yet");
Expand Down Expand Up @@ -4605,7 +4605,7 @@ private List<Base> funcMemberOf(ExecutionContext context, List<Base> focus, Expr
}

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);
if (vs == null) {
return new ArrayList<Base>();
Expand Down Expand Up @@ -5210,7 +5210,7 @@ private List<Base> funcResolve(ExecutionContext context, List<Base> focus, Expre
}
} else if (hostServices != null) {
try {
res = hostServices.resolveReference(context.appInfo, s, refContext);
res = hostServices.resolveReference(this, context.appInfo, s, refContext);
} catch (Exception e) {
res = null;
}
Expand Down Expand Up @@ -5740,7 +5740,7 @@ private List<Base> funcConformsTo(ExecutionContext context, List<Base> focus, Ex
result.add(new BooleanType(false).noExtensions());
} else {
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;
}
Expand Down
Loading