Add toBase64 & fromBase64 to FHIRPath
This commit is contained in:
parent
970c28bb26
commit
ba505a800e
|
@ -72,8 +72,9 @@ public class ExpressionNode {
|
|||
Empty, Not, Exists, SubsetOf, SupersetOf, IsDistinct, Distinct, Count, Where, Select, All, Repeat, Aggregate, Item /*implicit from name[]*/, As, Is, Single,
|
||||
First, Last, Tail, Skip, Take, Union, Combine, Intersect, Exclude, Iif, Upper, Lower, ToChars, IndexOf, Substring, StartsWith, EndsWith, Matches, ReplaceMatches, Contains, Replace, Length,
|
||||
Children, Descendants, MemberOf, Trace, Check, Today, Now, Resolve, Extension, AllFalse, AnyFalse, AllTrue, AnyTrue,
|
||||
HasValue, AliasAs, Alias, HtmlChecks, OfType, Type,
|
||||
ConvertsToBoolean, ConvertsToInteger, ConvertsToString, ConvertsToDecimal, ConvertsToQuantity, ConvertsToDateTime, ConvertsToTime, ToBoolean, ToInteger, ToString, ToDecimal, ToQuantity, ToDateTime, ToTime, ConformsTo;
|
||||
HasValue, OfType, Type, ConvertsToBoolean, ConvertsToInteger, ConvertsToString, ConvertsToDecimal, ConvertsToQuantity, ConvertsToDateTime, ConvertsToTime, ToBoolean, ToInteger, ToString, ToDecimal, ToQuantity, ToDateTime, ToTime, ConformsTo,
|
||||
// Local extensions to FHIRPath
|
||||
HtmlChecks, AliasAs, Alias, fromBase64, toBase64;
|
||||
|
||||
public static Function fromCode(String name) {
|
||||
if (name.equals("empty")) return Function.Empty;
|
||||
|
@ -133,6 +134,8 @@ public class ExpressionNode {
|
|||
if (name.equals("aliasAs")) return Function.AliasAs;
|
||||
if (name.equals("htmlChecks")) return Function.HtmlChecks;
|
||||
if (name.equals("htmlchecks")) return Function.HtmlChecks; // support change of care from R3
|
||||
if (name.equals("fromBase64")) return Function.fromBase64;
|
||||
if (name.equals("toBase64")) return Function.toBase64;
|
||||
if (name.equals("ofType")) return Function.OfType;
|
||||
if (name.equals("type")) return Function.Type;
|
||||
if (name.equals("toInteger")) return Function.ToInteger;
|
||||
|
@ -209,6 +212,8 @@ public class ExpressionNode {
|
|||
case HasValue : return "hasValue";
|
||||
case Alias : return "alias";
|
||||
case AliasAs : return "aliasAs";
|
||||
case fromBase64 : return "fromBase64";
|
||||
case toBase64 : return "toBase64";
|
||||
case HtmlChecks : return "htmlChecks";
|
||||
case OfType : return "ofType";
|
||||
case Type : return "type";
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.fhir.ucum.Decimal;
|
||||
import org.fhir.ucum.Pair;
|
||||
|
@ -1146,6 +1147,8 @@ public class FHIRPathEngine {
|
|||
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 fromBase64: return checkParamCount(lexer, location, exp, 0);
|
||||
case toBase64: return checkParamCount(lexer, location, exp, 0);
|
||||
case HtmlChecks: return checkParamCount(lexer, location, exp, 0);
|
||||
case ToInteger: return checkParamCount(lexer, location, exp, 0);
|
||||
case ToDecimal: return checkParamCount(lexer, location, exp, 0);
|
||||
|
@ -2644,6 +2647,10 @@ public class FHIRPathEngine {
|
|||
case AliasAs :
|
||||
checkParamTypes(exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String));
|
||||
return focus;
|
||||
case fromBase64:
|
||||
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String);
|
||||
case toBase64:
|
||||
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_String);
|
||||
case ToInteger : {
|
||||
checkContextPrimitive(focus, "toInteger", true);
|
||||
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Integer);
|
||||
|
@ -2818,6 +2825,8 @@ public class FHIRPathEngine {
|
|||
case AllTrue: return funcAllTrue(context, focus, exp);
|
||||
case HasValue : return funcHasValue(context, focus, exp);
|
||||
case AliasAs : return funcAliasAs(context, focus, exp);
|
||||
case fromBase64 : return funcFromBase64(context, focus, exp);
|
||||
case toBase64 : return funcToBase64(context, focus, exp);
|
||||
case Alias : return funcAlias(context, focus, exp);
|
||||
case HtmlChecks : return funcHtmlChecks(context, focus, exp);
|
||||
case ToInteger : return funcToInteger(context, focus, exp);
|
||||
|
@ -2846,7 +2855,27 @@ public class FHIRPathEngine {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Base> funcAliasAs(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
|
||||
private List<Base> funcToBase64(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
|
||||
List<Base> result = new ArrayList<Base>();
|
||||
if (focus.size() == 1) {
|
||||
String s = convertToString(focus.get(0));
|
||||
result.add(new StringType(Base64.encodeBase64String(s.getBytes())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<Base> funcFromBase64(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
|
||||
List<Base> result = new ArrayList<Base>();
|
||||
if (focus.size() == 1) {
|
||||
String s = convertToString(focus.get(0));
|
||||
result.add(new StringType(new String(Base64.decodeBase64(s))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<Base> funcAliasAs(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
|
||||
List<Base> nl = execute(context, focus, exp.getParameters().get(0), true);
|
||||
String name = nl.get(0).primitiveValue();
|
||||
context.addAlias(name, focus);
|
||||
|
|
Loading…
Reference in New Issue