use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method executeType.
private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
TypeDetails result = new TypeDetails(null);
switch(exp.getKind()) {
case Name:
if (atEntry && exp.getName().equals("$this")) {
result.update(context.getThisItem());
} else if (atEntry && exp.getName().equals("$total")) {
result.update(anything(CollectionStatus.UNORDERED));
} else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp));
} else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes()) {
throw makeException(exp, I18nConstants.FHIRPATH_UNKNOWN_NAME, exp.getName(), focus.describe());
}
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Unary:
result.addType(TypeDetails.FP_Integer);
result.addType(TypeDetails.FP_Decimal);
result.addType(TypeDetails.FP_Quantity);
break;
case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp));
break;
case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry));
}
exp.setTypes(result);
if (exp.getInner() != null) {
result = executeType(context, result, exp.getInner(), false);
}
if (exp.isProximal() && exp.getOperation() != null) {
ExpressionNode next = exp.getOpNext();
ExpressionNode last = exp;
while (next != null) {
TypeDetails work;
if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As) {
work = executeTypeName(context, focus, next, atEntry);
} else {
work = executeType(context, focus, next, atEntry);
}
result = operateTypes(result, last.getOperation(), work, last);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class XhtmlParser method parseLiteral.
private void parseLiteral(StringBuilder s) throws IOException, FHIRFormatError {
// UInt16 w;
readChar();
String c = readUntil(";&'\"><");
if (c.isEmpty())
throw new FHIRFormatError("Invalid literal declaration following text: " + s);
else if (c.charAt(0) == '#') {
if (isInteger(c.substring(1), 10))
s.append((char) Integer.parseInt(c.substring(1)));
else if (c.charAt(1) == 'x' && isInteger(c.substring(2), 16))
s.append((char) Integer.parseInt(c.substring(2), 16));
} else if (entities.containsKey(c)) {
s.append(entities.get(c));
// what's going on here?
// the contents that follow already existed, and then I added the routine to populate the entities
// which was generated from other code. The code that follows is probably redundant, but I haven't
// cross checked it. some is welcome to do so... (GG 8-Nov 2021)
} else if (c.equals("apos"))
s.append('\'');
else if (c.equals("quot"))
s.append('"');
else if (c.equals("nbsp"))
s.append(XhtmlNode.NBSP);
else if (c.equals("amp"))
s.append('&');
else if (c.equals("lsquo"))
// right single quotation, U+2019 ISOnum
s.append((char) 8216);
else if (c.equals("rsquo"))
// right single quotation, U+2019 ISOnum
s.append((char) 8217);
else if (c.equals("gt"))
s.append('>');
else if (c.equals("lt"))
s.append('<');
else if (c.equals("copy"))
s.append((char) 169);
else if (c.equals("reg"))
s.append((char) 174);
else if (c.equals("sect"))
s.append((char) 0xA7);
else if (c.equals("fnof"))
// latin small f with hook = function = florin, U+0192 ISOtech -->
s.append((char) 402);
else if (c.equals("Alpha"))
// greek capital letter alpha, U+0391
s.append((char) 913);
else if (c.equals("Beta"))
// greek capital letter beta, U+0392
s.append((char) 914);
else if (c.equals("Gamma"))
// greek capital letter gamma, U+0393 ISOgrk3
s.append((char) 915);
else if (c.equals("Delta"))
// greek capital letter delta, U+0394 ISOgrk3
s.append((char) 916);
else if (c.equals("Epsilon"))
// greek capital letter epsilon, U+0395
s.append((char) 917);
else if (c.equals("Zeta"))
// greek capital letter zeta, U+0396
s.append((char) 918);
else if (c.equals("Eta"))
// greek capital letter eta, U+0397
s.append((char) 919);
else if (c.equals("Theta"))
// greek capital letter theta, U+0398 ISOgrk3
s.append((char) 920);
else if (c.equals("Iota"))
// greek capital letter iota, U+0399
s.append((char) 921);
else if (c.equals("Kappa"))
// greek capital letter kappa, U+039A
s.append((char) 922);
else if (c.equals("Lambda"))
// greek capital letter lambda, U+039B ISOgrk3
s.append((char) 923);
else if (c.equals("Mu"))
// greek capital letter mu, U+039C
s.append((char) 924);
else if (c.equals("Nu"))
// greek capital letter nu, U+039D
s.append((char) 925);
else if (c.equals("Xi"))
// greek capital letter xi, U+039E ISOgrk3
s.append((char) 926);
else if (c.equals("Omicron"))
// greek capital letter omicron, U+039F
s.append((char) 927);
else if (c.equals("Pi"))
// greek capital letter pi, U+03A0 ISOgrk3
s.append((char) 928);
else if (c.equals("Rho"))
// greek capital letter rho, U+03A1
s.append((char) 929);
else if (c.equals("Sigma"))
// greek capital letter sigma, U+03A3 ISOgrk3
s.append((char) 931);
else if (c.equals("Tau"))
// greek capital letter tau, U+03A4
s.append((char) 932);
else if (c.equals("Upsilon"))
// greek capital letter upsilon, U+03A5 ISOgrk3
s.append((char) 933);
else if (c.equals("Phi"))
// greek capital letter phi, U+03A6 ISOgrk3
s.append((char) 934);
else if (c.equals("Chi"))
// greek capital letter chi, U+03A7
s.append((char) 935);
else if (c.equals("Psi"))
// greek capital letter psi, U+03A8 ISOgrk3
s.append((char) 936);
else if (c.equals("Omega"))
// greek capital letter omega, U+03A9 ISOgrk3
s.append((char) 937);
else if (c.equals("alpha"))
// greek small letter alpha, U+03B1 ISOgrk3
s.append((char) 945);
else if (c.equals("beta"))
// greek small letter beta, U+03B2 ISOgrk3
s.append((char) 946);
else if (c.equals("gamma"))
// greek small letter gamma, U+03B3 ISOgrk3
s.append((char) 947);
else if (c.equals("delta"))
// greek small letter delta, U+03B4 ISOgrk3
s.append((char) 948);
else if (c.equals("epsilon"))
// greek small letter epsilon, U+03B5 ISOgrk3
s.append((char) 949);
else if (c.equals("zeta"))
// greek small letter zeta, U+03B6 ISOgrk3
s.append((char) 950);
else if (c.equals("eta"))
// greek small letter eta, U+03B7 ISOgrk3
s.append((char) 951);
else if (c.equals("theta"))
// greek small letter theta, U+03B8 ISOgrk3
s.append((char) 952);
else if (c.equals("iota"))
// greek small letter iota, U+03B9 ISOgrk3
s.append((char) 953);
else if (c.equals("kappa"))
// greek small letter kappa, U+03BA ISOgrk3
s.append((char) 954);
else if (c.equals("lambda"))
// greek small letter lambda, U+03BB ISOgrk3
s.append((char) 955);
else if (c.equals("mu"))
// greek small letter mu, U+03BC ISOgrk3
s.append((char) 956);
else if (c.equals("nu"))
// greek small letter nu, U+03BD ISOgrk3
s.append((char) 957);
else if (c.equals("xi"))
// greek small letter xi, U+03BE ISOgrk3
s.append((char) 958);
else if (c.equals("omicron"))
// greek small letter omicron, U+03BF NEW
s.append((char) 959);
else if (c.equals("pi"))
// greek small letter pi, U+03C0 ISOgrk3
s.append((char) 960);
else if (c.equals("rho"))
// greek small letter rho, U+03C1 ISOgrk3
s.append((char) 961);
else if (c.equals("sigmaf"))
// greek small letter final sigma, U+03C2 ISOgrk3
s.append((char) 962);
else if (c.equals("sigma"))
// greek small letter sigma, U+03C3 ISOgrk3
s.append((char) 963);
else if (c.equals("tau"))
// greek small letter tau, U+03C4 ISOgrk3
s.append((char) 964);
else if (c.equals("upsilon"))
// greek small letter upsilon, U+03C5 ISOgrk3
s.append((char) 965);
else if (c.equals("phi"))
// greek small letter phi, U+03C6 ISOgrk3
s.append((char) 966);
else if (c.equals("chi"))
// greek small letter chi, U+03C7 ISOgrk3
s.append((char) 967);
else if (c.equals("psi"))
// greek small letter psi, U+03C8 ISOgrk3
s.append((char) 968);
else if (c.equals("omega"))
// greek small letter omega, U+03C9 ISOgrk3
s.append((char) 969);
else if (c.equals("thetasym"))
// greek small letter theta symbol, U+03D1 NEW
s.append((char) 977);
else if (c.equals("upsih"))
// greek upsilon with hook symbol, U+03D2 NEW
s.append((char) 978);
else if (c.equals("piv"))
// greek pi symbol, U+03D6 ISOgrk3
s.append((char) 982);
else if (c.equals("bull"))
// bullet = black small circle, U+2022 ISOpub
s.append((char) 8226);
else if (c.equals("hellip"))
// horizontal ellipsis = three dot leader, U+2026 ISOpub
s.append((char) 8230);
else if (c.equals("prime"))
// prime = minutes = feet, U+2032 ISOtech
s.append((char) 8242);
else if (c.equals("Prime"))
// double prime = seconds = inches, U+2033 ISOtech
s.append((char) 8243);
else if (c.equals("oline"))
// overline = spacing overscore, U+203E NEW
s.append((char) 8254);
else if (c.equals("frasl"))
// fraction slash, U+2044 NEW
s.append((char) 8260);
else if (c.equals("weierp"))
// script capital P = power set = Weierstrass p, U+2118 ISOamso
s.append((char) 8472);
else if (c.equals("image"))
// blackletter capital I = imaginary part, U+2111 ISOamso
s.append((char) 8465);
else if (c.equals("real"))
// blackletter capital R = real part symbol, U+211C ISOamso
s.append((char) 8476);
else if (c.equals("trade"))
// trade mark sign, U+2122 ISOnum
s.append((char) 8482);
else if (c.equals("alefsym"))
// alef symbol = first transfinite cardinal, U+2135 NEW
s.append((char) 8501);
else if (c.equals("larr"))
// leftwards arrow, U+2190 ISOnum
s.append((char) 8592);
else if (c.equals("uarr"))
// upwards arrow, U+2191 ISOnum
s.append((char) 8593);
else if (c.equals("rarr"))
// rightwards arrow, U+2192 ISOnum
s.append((char) 8594);
else if (c.equals("darr"))
// downwards arrow, U+2193 ISOnum
s.append((char) 8595);
else if (c.equals("harr"))
// left right arrow, U+2194 ISOamsa
s.append((char) 8596);
else if (c.equals("crarr"))
// downwards arrow with corner leftwards = carriage return, U+21B5 NEW
s.append((char) 8629);
else if (c.equals("lArr"))
// leftwards double arrow, U+21D0 ISOtech
s.append((char) 8656);
else if (c.equals("uArr"))
// upwards double arrow, U+21D1 ISOamsa
s.append((char) 8657);
else if (c.equals("rArr"))
// rightwards double arrow, U+21D2 ISOtech
s.append((char) 8658);
else if (c.equals("dArr"))
// downwards double arrow, U+21D3 ISOamsa
s.append((char) 8659);
else if (c.equals("hArr"))
// left right double arrow, U+21D4 ISOamsa
s.append((char) 8660);
else if (c.equals("forall"))
// for all, U+2200 ISOtech
s.append((char) 8704);
else if (c.equals("part"))
// partial differential, U+2202 ISOtech
s.append((char) 8706);
else if (c.equals("exist"))
// there exists, U+2203 ISOtech
s.append((char) 8707);
else if (c.equals("empty"))
// empty set = null set = diameter, U+2205 ISOamso
s.append((char) 8709);
else if (c.equals("nabla"))
// nabla = backward difference, U+2207 ISOtech
s.append((char) 8711);
else if (c.equals("isin"))
// element of, U+2208 ISOtech
s.append((char) 8712);
else if (c.equals("notin"))
// not an element of, U+2209 ISOtech
s.append((char) 8713);
else if (c.equals("ni"))
// contains as member, U+220B ISOtech
s.append((char) 8715);
else if (c.equals("prod"))
// n-ary product = product sign, U+220F ISOamsb
s.append((char) 8719);
else if (c.equals("sum"))
// n-ary sumation, U+2211 ISOamsb
s.append((char) 8721);
else if (c.equals("minus"))
// minus sign, U+2212 ISOtech
s.append((char) 8722);
else if (c.equals("lowast"))
// asterisk operator, U+2217 ISOtech
s.append((char) 8727);
else if (c.equals("radic"))
// square root = radical sign, U+221A ISOtech
s.append((char) 8730);
else if (c.equals("prop"))
// proportional to, U+221D ISOtech
s.append((char) 8733);
else if (c.equals("infin"))
// infinity, U+221E ISOtech -->
s.append((char) 8734);
else if (c.equals("ang"))
// angle, U+2220 ISOamso
s.append((char) 8736);
else if (c.equals("and"))
// logical and = wedge, U+2227 ISOtech
s.append((char) 8743);
else if (c.equals("or"))
// logical or = vee, U+2228 ISOtech
s.append((char) 8744);
else if (c.equals("cap"))
// intersection = cap, U+2229 ISOtech
s.append((char) 8745);
else if (c.equals("cup"))
// union = cup, U+222A ISOtech
s.append((char) 8746);
else if (c.equals("int"))
// integral, U+222B ISOtech
s.append((char) 8747);
else if (c.equals("there4"))
// therefore, U+2234 ISOtech
s.append((char) 8756);
else if (c.equals("sim"))
// tilde operator = varies with = similar t U+223C ISOtech
s.append((char) 8764);
else if (c.equals("cong"))
// approximately equal to, U+2245 ISOtec
s.append((char) 8773);
else if (c.equals("asymp"))
// almost equal to = asymptotic to, U+2248 ISOamsr
s.append((char) 8776);
else if (c.equals("ne"))
// not equal to, U+2260 ISOtech
s.append((char) 8800);
else if (c.equals("equiv"))
// identical to, U+2261 ISOtech
s.append((char) 8801);
else if (c.equals("le"))
// less-than or equal to, U+2264 ISOtech
s.append((char) 8804);
else if (c.equals("ge"))
// greater-than or equal to, U+2265 ISOtech
s.append((char) 8805);
else if (c.equals("sub"))
// subset of, U+2282 ISOtech
s.append((char) 8834);
else if (c.equals("sup"))
// superset of, U+2283 ISOtech
s.append((char) 8835);
else if (c.equals("nsub"))
// not a subset of, U+2284 ISOamsn
s.append((char) 8836);
else if (c.equals("sube"))
// subset of or equal to, U+2286 ISOtech
s.append((char) 8838);
else if (c.equals("supe"))
// superset of or equal to, U+2287 ISOtech
s.append((char) 8839);
else if (c.equals("oplus"))
// circled plus = direct sum, U+2295 ISOamsb
s.append((char) 8853);
else if (c.equals("otimes"))
// circled times = vector product, U+2297 ISOamsb -->
s.append((char) 8855);
else if (c.equals("perp"))
// up tack = orthogonal to = perpendicular, U+22A5 ISOtech
s.append((char) 8869);
else if (c.equals("sdot"))
// dot operator, U+22C5 ISOamsb
s.append((char) 8901);
else if (c.equals("lceil"))
// left ceiling = apl upstile, U+2308 ISOamsc
s.append((char) 8968);
else if (c.equals("rceil"))
// right ceiling, U+2309 ISOamsc
s.append((char) 8969);
else if (c.equals("lfloor"))
// left floor = apl downstile, U+230A ISOamsc
s.append((char) 8970);
else if (c.equals("rfloor"))
// right floor, U+230B ISOamsc
s.append((char) 8971);
else if (c.equals("lang"))
// left-pointing angle bracket = bra, U+2329 ISOtech
s.append((char) 9001);
else if (c.equals("rang"))
// right-pointing angle bracket = ket, U+232A ISOtech
s.append((char) 9002);
else if (c.equals("loz"))
// lozenge, U+25CA ISOpub
s.append((char) 9674);
else if (c.equals("spades"))
// black spade suit, U+2660 ISOpub
s.append((char) 9824);
else if (c.equals("clubs"))
// black club suit = shamrock, U+2663 ISOpub
s.append((char) 9827);
else if (c.equals("hearts"))
// black heart suit = valentine, U+2665 ISOpub
s.append((char) 9829);
else if (c.equals("diams"))
// black diamond suit, U+2666 ISOpub --
s.append((char) 9830);
else if (c.equals("ndash"))
s.append((char) 8211);
else if (c.equals("mdash"))
s.append((char) 8212);
else if (c.equals("ldquo"))
s.append((char) 8221);
else if (c.equals("rdquo"))
s.append((char) 201D);
else if (c.equals("frac14"))
s.append((char) 188);
else if (!mustBeWellFormed) {
// we guess that this is an accidentally unescaped &
s.append("&" + c);
} else {
throw new FHIRFormatError("unable to parse character reference '" + c + "'' (last text = '" + lastText + "'" + descLoc());
}
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project pathling by aehrc.
the class ReverseResolveFunction method invoke.
@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
checkUserInput(input.getInput() instanceof ResourcePath, "Input to " + NAME + " function must be a resource: " + input.getInput().getExpression());
final ResourcePath inputPath = (ResourcePath) input.getInput();
final String expression = NamedFunction.expressionFromInput(input, NAME);
checkUserInput(input.getArguments().size() == 1, "reverseResolve function accepts a single argument: " + expression);
final FhirPath argument = input.getArguments().get(0);
checkUserInput(argument instanceof ReferencePath, "Argument to reverseResolve function must be a Reference: " + argument.getExpression());
final ReferencePath referencePath = (ReferencePath) argument;
// Check that the input type is one of the possible types specified by the argument.
final Set<ResourceType> argumentTypes = ((ReferencePath) argument).getResourceTypes();
final ResourceType inputType = inputPath.getResourceType();
checkUserInput(argumentTypes.contains(inputType), "Reference in argument to reverseResolve does not support input resource type: " + expression);
// Do a left outer join from the input to the argument dataset using the reference field in the
// argument.
final Column joinCondition = referencePath.getResourceEquality(inputPath);
final Dataset<Row> dataset = join(referencePath.getDataset(), inputPath.getDataset(), joinCondition, JoinType.RIGHT_OUTER);
// Check the argument for information about the current resource that it originated from - if it
// is not present, reverse reference resolution will not be possible.
final NonLiteralPath nonLiteralArgument = (NonLiteralPath) argument;
checkUserInput(nonLiteralArgument.getCurrentResource().isPresent(), "Argument to reverseResolve must be an element that is navigable from a " + "target resource type: " + expression);
final ResourcePath currentResource = nonLiteralArgument.getCurrentResource().get();
final Optional<Column> thisColumn = inputPath.getThisColumn();
// TODO: Consider removing in the future once we separate ordering from element ID.
// Create an synthetic element ID column for reverse resolved resources.
final Column currentResourceValue = currentResource.getValueColumn();
final WindowSpec windowSpec = Window.partitionBy(inputPath.getIdColumn(), inputPath.getOrderingColumn()).orderBy(currentResourceValue);
// row_number() is 1-based, and we use 0-based indexes - thus (minus(1)).
final Column currentResourceIndex = when(currentResourceValue.isNull(), lit(null)).otherwise(row_number().over(windowSpec).minus(lit(1)));
// We need to add the synthetic EID column to the parser context so that it can be used within
// joins in certain situations, e.g. extract.
final Column syntheticEid = inputPath.expandEid(currentResourceIndex);
final DatasetWithColumn datasetWithEid = QueryHelpers.createColumn(dataset, syntheticEid);
input.getContext().getNodeIdColumns().putIfAbsent(expression, datasetWithEid.getColumn());
final ResourcePath result = currentResource.copy(expression, datasetWithEid.getDataset(), inputPath.getIdColumn(), Optional.of(syntheticEid), currentResource.getValueColumn(), false, thisColumn);
result.setCurrentResource(currentResource);
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project bunsen by cerner.
the class ConceptMaps method getConceptMap.
/**
* Returns the concept map with the given uri and version, or null if there is no such map.
*
* @param uri the uri of the map to return
* @param version the version of the map to return
* @return the specified concept map.
*/
public ConceptMap getConceptMap(String uri, String version) {
// Load the concept maps, which may contain zero items
// if the map does not exist.
// Typecast necessary to placate the Java compiler calling this Scala function.
ConceptMap[] maps = (ConceptMap[]) this.conceptMaps.filter(functions.col("url").equalTo(lit(uri)).and(functions.col("version").equalTo(lit(version)))).head(1);
if (maps.length == 0) {
return null;
} else {
ConceptMap map = maps[0];
Dataset<Mapping> filteredMappings = getMappings(uri, version);
addToConceptMap(map, filteredMappings);
return map;
}
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project bunsen by cerner.
the class ValueSets method getValueSet.
/**
* Returns the value set with the given uri and version, or null if there is no such value set.
*
* @param uri the uri of the value set to return
* @param version the version of the value set to return
* @return the specified value set.
*/
public ValueSet getValueSet(String uri, String version) {
// Load the value sets, which may contain zero items if the value set does not exist
// Typecast necessary to placate the Java compiler calling this Scala function
ValueSet[] valueSets = (ValueSet[]) this.valueSets.filter(col("url").equalTo(lit(uri)).and(col("version").equalTo(lit(version)))).head(1);
if (valueSets.length == 0) {
return null;
} else {
ValueSet valueSet = valueSets[0];
Dataset<Value> filteredValues = getValues(uri, version);
addToValueSet(valueSet, filteredValues);
return valueSet;
}
}
Aggregations