From 0664e5601d92e178dc9047bfac2bbc8457b0ff10 Mon Sep 17 00:00:00 2001 From: Brian Postlethwaite Date: Wed, 17 Apr 2024 10:38:25 +1000 Subject: [PATCH] Remove the alias/aliasAs custom functions from R4/r4b (use standard defineVariable now) --- .../hl7/fhir/r4/fhirpath/ExpressionNode.java | 10 +-- .../hl7/fhir/r4/fhirpath/FHIRPathEngine.java | 68 ++---------------- .../hl7/fhir/r4b/fhirpath/ExpressionNode.java | 10 +-- .../hl7/fhir/r4b/fhirpath/FHIRPathEngine.java | 70 +++---------------- 4 files changed, 18 insertions(+), 140 deletions(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/ExpressionNode.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/ExpressionNode.java index 66977c737..e2cacc528 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/ExpressionNode.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/ExpressionNode.java @@ -60,7 +60,7 @@ public class ExpressionNode { Encode, Decode, Escape, Unescape, Trim, Split, Join, LowBoundary, HighBoundary, Precision, // Local extensions to FHIRPath - HtmlChecks1, HtmlChecks2, AliasAs, Alias, Comparable; + HtmlChecks1, HtmlChecks2, Comparable; public static Function fromCode(String name) { if (name.equals("empty")) @@ -171,10 +171,6 @@ public class ExpressionNode { return Function.AnyTrue; if (name.equals("hasValue")) return Function.HasValue; - if (name.equals("alias")) - return Function.Alias; - if (name.equals("aliasAs")) - return Function.AliasAs; if (name.equals("htmlChecks")) return Function.HtmlChecks1; if (name.equals("htmlchecks")) @@ -373,10 +369,6 @@ public class ExpressionNode { return "anyTrue"; case HasValue: return "hasValue"; - case Alias: - return "alias"; - case AliasAs: - return "aliasAs"; case Encode: return "encode"; case Decode: diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/FHIRPathEngine.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/FHIRPathEngine.java index c91f19dae..91c3f4624 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/FHIRPathEngine.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/fhirpath/FHIRPathEngine.java @@ -604,7 +604,7 @@ public class FHIRPathEngine { } log = new StringBuilder(); return execute(new ExecutionContext(null, base != null && base.isResource() ? base : null, - base != null && base.isResource() ? base : null, base, null, base), list, ExpressionNode, true); + base != null && base.isResource() ? base : null, base, base), list, ExpressionNode, true); } /** @@ -623,7 +623,7 @@ public class FHIRPathEngine { } log = new StringBuilder(); return execute( - new ExecutionContext(null, base.isResource() ? base : null, base.isResource() ? base : null, base, null, base), + new ExecutionContext(null, base.isResource() ? base : null, base.isResource() ? base : null, base, base), list, exp, true); } @@ -642,7 +642,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, ExpressionNode, true); } @@ -661,7 +661,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, expressionNode, true); } @@ -681,7 +681,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, exp, true); + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, exp, true); } /** @@ -848,16 +848,13 @@ public class FHIRPathEngine { private Base context; private Base thisItem; private List total; - private Map aliases; private int index; - public ExecutionContext(Object appInfo, Base resource, Base rootResource, Base context, Map aliases, - Base thisItem) { + public ExecutionContext(Object appInfo, Base resource, Base rootResource, Base context, Base thisItem) { this.appInfo = appInfo; this.context = context; this.focusResource = resource; this.rootResource = rootResource; - this.aliases = aliases; this.thisItem = thisItem; this.index = 0; } @@ -886,22 +883,6 @@ public class FHIRPathEngine { return new IntegerType(index); } - public void addAlias(String name, List focus) throws FHIRException { - if (aliases == null) { - aliases = new HashMap(); - } else { - aliases = new HashMap(aliases); // clone it, since it's going to change - } - if (focus.size() > 1) { - throw makeException(null, I18nConstants.FHIRPATH_ALIAS_COLLECTION); - } - aliases.put(name, focus.size() == 0 ? null : focus.get(0)); - } - - public Base getAlias(String name) { - return aliases == null ? null : aliases.get(name); - } - public ExecutionContext setIndex(int i) { index = i; return this; @@ -1353,10 +1334,6 @@ public class FHIRPathEngine { return checkParamCount(lexer, location, exp, 0); case HasValue: return checkParamCount(lexer, location, exp, 0); - case Alias: - return checkParamCount(lexer, location, exp, 1); - case AliasAs: - return checkParamCount(lexer, location, exp, 1); case Encode: return checkParamCount(lexer, location, exp, 1); case Decode: @@ -3466,14 +3443,6 @@ public class FHIRPathEngine { return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); case Comparable: return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); - case Alias: - checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, - new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); - return anything(CollectionStatus.SINGLETON); - case AliasAs: - checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, - new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); - return focus; case Encode: checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); @@ -3851,8 +3820,6 @@ public class FHIRPathEngine { return funcAllTrue(context, focus, exp); case HasValue: return funcHasValue(context, focus, exp); - case AliasAs: - return funcAliasAs(context, focus, exp); case Encode: return funcEncode(context, focus, exp); case Decode: @@ -3867,8 +3834,6 @@ public class FHIRPathEngine { return funcSplit(context, focus, exp); case Join: return funcJoin(context, focus, exp); - case Alias: - return funcAlias(context, focus, exp); case HtmlChecks1: return funcHtmlChecks1(context, focus, exp); case HtmlChecks2: @@ -4417,24 +4382,6 @@ public class FHIRPathEngine { return result; } - private List funcAliasAs(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { - List nl = execute(context, focus, exp.getParameters().get(0), true); - String name = nl.get(0).primitiveValue(); - context.addAlias(name, focus); - return focus; - } - - private List funcAlias(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { - List nl = execute(context, focus, exp.getParameters().get(0), true); - String name = nl.get(0).primitiveValue(); - List res = new ArrayList(); - Base b = context.getAlias(name); - if (b != null) { - res.add(b); - } - return res; - } - private List funcHtmlChecks1(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { // todo: actually check the HTML @@ -4585,8 +4532,7 @@ public class FHIRPathEngine { } private ExecutionContext changeThis(ExecutionContext context, Base newThis) { - return new ExecutionContext(context.appInfo, context.focusResource, context.rootResource, context.context, - context.aliases, newThis); + return new ExecutionContext(context.appInfo, context.focusResource, context.rootResource, context.context, newThis); } private ExecutionTypeContext changeThis(ExecutionTypeContext context, TypeDetails newThis) { diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/ExpressionNode.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/ExpressionNode.java index d79e026ce..fe5d54c2e 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/ExpressionNode.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/ExpressionNode.java @@ -60,7 +60,7 @@ public class ExpressionNode { Encode, Decode, Escape, Unescape, Trim, Split, Join, LowBoundary, HighBoundary, Precision, // Local extensions to FHIRPath - HtmlChecks1, HtmlChecks2, AliasAs, Alias, Comparable; + HtmlChecks1, HtmlChecks2, Comparable; public static Function fromCode(String name) { if (name.equals("empty")) @@ -171,10 +171,6 @@ public class ExpressionNode { return Function.AnyTrue; if (name.equals("hasValue")) return Function.HasValue; - if (name.equals("alias")) - return Function.Alias; - if (name.equals("aliasAs")) - return Function.AliasAs; if (name.equals("htmlChecks")) return Function.HtmlChecks1; if (name.equals("htmlchecks")) @@ -373,10 +369,6 @@ public class ExpressionNode { return "anyTrue"; case HasValue: return "hasValue"; - case Alias: - return "alias"; - case AliasAs: - return "aliasAs"; case Encode: return "encode"; case Decode: diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/FHIRPathEngine.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/FHIRPathEngine.java index 81fe330f8..589753c7a 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/FHIRPathEngine.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/fhirpath/FHIRPathEngine.java @@ -605,7 +605,7 @@ public class FHIRPathEngine { } log = new StringBuilder(); return execute(new ExecutionContext(null, base != null && base.isResource() ? base : null, - base != null && base.isResource() ? base : null, base, null, base), list, ExpressionNode, true); + base != null && base.isResource() ? base : null, base, base), list, ExpressionNode, true); } /** @@ -624,7 +624,7 @@ public class FHIRPathEngine { } log = new StringBuilder(); return execute( - new ExecutionContext(null, base.isResource() ? base : null, base.isResource() ? base : null, base, null, base), + new ExecutionContext(null, base.isResource() ? base : null, base.isResource() ? base : null, base, base), list, exp, true); } @@ -643,7 +643,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, ExpressionNode, true); } @@ -662,7 +662,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, expressionNode, true); } @@ -682,7 +682,7 @@ public class FHIRPathEngine { list.add(base); } log = new StringBuilder(); - return execute(new ExecutionContext(appContext, focusResource, rootResource, base, null, base), list, exp, true); + return execute(new ExecutionContext(appContext, focusResource, rootResource, base, base), list, exp, true); } /** @@ -849,16 +849,13 @@ public class FHIRPathEngine { private Base context; private Base thisItem; private List total; - private Map aliases; private int index; - public ExecutionContext(Object appInfo, Base resource, Base rootResource, Base context, Map aliases, - Base thisItem) { + public ExecutionContext(Object appInfo, Base resource, Base rootResource, Base context, Base thisItem) { this.appInfo = appInfo; this.context = context; this.focusResource = resource; this.rootResource = rootResource; - this.aliases = aliases; this.thisItem = thisItem; this.index = 0; } @@ -887,22 +884,6 @@ public class FHIRPathEngine { return new IntegerType(index); } - public void addAlias(String name, List focus) throws FHIRException { - if (aliases == null) { - aliases = new HashMap(); - } else { - aliases = new HashMap(aliases); // clone it, since it's going to change - } - if (focus.size() > 1) { - throw makeException(null, I18nConstants.FHIRPATH_ALIAS_COLLECTION); - } - aliases.put(name, focus.size() == 0 ? null : focus.get(0)); - } - - public Base getAlias(String name) { - return aliases == null ? null : aliases.get(name); - } - public ExecutionContext setIndex(int i) { index = i; return this; @@ -1353,10 +1334,6 @@ public class FHIRPathEngine { return checkParamCount(lexer, location, exp, 0); case HasValue: return checkParamCount(lexer, location, exp, 0); - case Alias: - return checkParamCount(lexer, location, exp, 1); - case AliasAs: - return checkParamCount(lexer, location, exp, 1); case Encode: return checkParamCount(lexer, location, exp, 1); case Decode: @@ -3468,14 +3445,6 @@ public class FHIRPathEngine { return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); case Comparable: return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); - case Alias: - checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, - new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); - return anything(CollectionStatus.SINGLETON); - case AliasAs: - checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, - new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); - return focus; case Encode: checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String)); @@ -3853,8 +3822,6 @@ public class FHIRPathEngine { return funcAllTrue(context, focus, exp); case HasValue: return funcHasValue(context, focus, exp); - case AliasAs: - return funcAliasAs(context, focus, exp); case Encode: return funcEncode(context, focus, exp); case Decode: @@ -3869,8 +3836,6 @@ public class FHIRPathEngine { return funcSplit(context, focus, exp); case Join: return funcJoin(context, focus, exp); - case Alias: - return funcAlias(context, focus, exp); case HtmlChecks1: return funcHtmlChecks1(context, focus, exp); case HtmlChecks2: @@ -4427,24 +4392,6 @@ public class FHIRPathEngine { return result; } - private List funcAliasAs(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { - List nl = execute(context, focus, exp.getParameters().get(0), true); - String name = nl.get(0).primitiveValue(); - context.addAlias(name, focus); - return focus; - } - - private List funcAlias(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { - List nl = execute(context, focus, exp.getParameters().get(0), true); - String name = nl.get(0).primitiveValue(); - List res = new ArrayList(); - Base b = context.getAlias(name); - if (b != null) { - res.add(b); - } - return res; - } - private List funcHtmlChecks1(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { // todo: actually check the HTML @@ -4587,8 +4534,9 @@ public class FHIRPathEngine { } private ExecutionContext changeThis(ExecutionContext context, Base newThis) { - return new ExecutionContext(context.appInfo, context.focusResource, context.rootResource, context.context, - context.aliases, newThis); + ExecutionContext newContext = new ExecutionContext(context.appInfo, context.focusResource, context.rootResource, context.context, + newThis); + return newContext; } private ExecutionTypeContext changeThis(ExecutionTypeContext context, TypeDetails newThis) {