use of org.hl7.fhir.r4.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeDecimal.
protected void composeDecimal(Complex parent, String parentType, String name, DecimalType value, int index) {
if (value == null)
return;
Complex t = parent.predicate("fhir:" + parentType + "." + name);
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
composeElement(t, parentType, name, value, index);
}
use of org.hl7.fhir.r4.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method buildFixedExpression.
private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
DataType fixed = criteriaElement.getFixed();
if (fixed instanceof CodeableConcept) {
CodeableConcept cc = (CodeableConcept) fixed;
expression.append(" and ");
buildCodeableConceptExpression(ed, expression, discriminator, cc);
} else if (fixed instanceof Identifier) {
Identifier ii = (Identifier) fixed;
expression.append(" and ");
buildIdentifierExpression(ed, expression, discriminator, ii);
} else if (fixed instanceof Coding) {
Coding c = (Coding) fixed;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else {
expression.append(" and (");
if (fixed instanceof StringType) {
Gson gson = new Gson();
String json = gson.toJson((StringType) fixed);
String escapedString = json.substring(json.indexOf(":") + 2);
escapedString = escapedString.substring(0, escapedString.indexOf(",\"myStringValue") - 1);
expression.append("'" + escapedString + "'");
} else if (fixed instanceof UriType) {
expression.append("'" + ((UriType) fixed).asStringValue() + "'");
} else if (fixed instanceof IntegerType) {
expression.append(((IntegerType) fixed).asStringValue());
} else if (fixed instanceof DecimalType) {
expression.append(((IntegerType) fixed).asStringValue());
} else if (fixed instanceof BooleanType) {
expression.append(((BooleanType) fixed).asStringValue());
} else
throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_VALUE_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), fixed.getClass().getName()));
expression.append(" in " + discriminator + ")");
}
}
use of org.hl7.fhir.r4.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method buildPattternExpression.
private void buildPattternExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
DataType pattern = criteriaElement.getPattern();
if (pattern instanceof CodeableConcept) {
CodeableConcept cc = (CodeableConcept) pattern;
expression.append(" and ");
buildCodeableConceptExpression(ed, expression, discriminator, cc);
} else if (pattern instanceof Coding) {
Coding c = (Coding) pattern;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else if (pattern instanceof BooleanType || pattern instanceof IntegerType || pattern instanceof DecimalType) {
expression.append(" and ");
buildPrimitiveExpression(ed, expression, discriminator, pattern, false);
} else if (pattern instanceof PrimitiveType) {
expression.append(" and ");
buildPrimitiveExpression(ed, expression, discriminator, pattern, true);
} else if (pattern instanceof Identifier) {
Identifier ii = (Identifier) pattern;
expression.append(" and ");
buildIdentifierExpression(ed, expression, discriminator, ii);
} else if (pattern instanceof HumanName) {
HumanName name = (HumanName) pattern;
expression.append(" and ");
buildHumanNameExpression(ed, expression, discriminator, name);
} else if (pattern instanceof Address) {
Address add = (Address) pattern;
expression.append(" and ");
buildAddressExpression(ed, expression, discriminator, add);
} else {
throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_PATTERN_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), pattern.fhirType()));
}
}
use of org.hl7.fhir.r4.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opMinus.
private List<Base> opMinus(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 0)
throw new PathEngineException("Error performing -: left operand has no value");
if (left.size() > 1)
throw new PathEngineException("Error performing -: left operand has more than one value");
if (!left.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType()));
if (right.size() == 0)
throw new PathEngineException("Error performing -: right operand has no value");
if (right.size() > 1)
throw new PathEngineException("Error performing -: right operand has more than one value");
if (!right.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing -: right operand has the wrong type (%s)", right.get(0).fhirType()));
List<Base> result = new ArrayList<Base>();
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("integer") && r.hasType("integer"))
result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) - Integer.parseInt(r.primitiveValue())));
else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
result.add(new DecimalType(new BigDecimal(l.primitiveValue()).subtract(new BigDecimal(r.primitiveValue()))));
else
throw new PathEngineException(String.format("Error performing -: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
return result;
}
use of org.hl7.fhir.r4.model.DecimalType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method parseExpression.
private ExpressionNode parseExpression(FHIRLexer lexer, boolean proximal) throws FHIRLexerException {
ExpressionNode result = new ExpressionNode(lexer.nextId());
ExpressionNode wrapper = null;
SourceLocation c = lexer.getCurrentStartLocation();
result.setStart(lexer.getCurrentLocation());
// so we back correct for both +/- and as part of a numeric constant below.
if (Utilities.existsInList(lexer.getCurrent(), "-", "+")) {
wrapper = new ExpressionNode(lexer.nextId());
wrapper.setKind(Kind.Unary);
wrapper.setOperation(ExpressionNode.Operation.fromCode(lexer.take()));
wrapper.setProximal(proximal);
}
if (lexer.isConstant()) {
boolean isString = lexer.isStringConstant();
if (!isString && (lexer.getCurrent().startsWith("-") || lexer.getCurrent().startsWith("+"))) {
// the grammar says that this is a unary operation; it affects the correct processing order of the inner operations
wrapper = new ExpressionNode(lexer.nextId());
wrapper.setKind(Kind.Unary);
wrapper.setOperation(ExpressionNode.Operation.fromCode(lexer.getCurrent().substring(0, 1)));
wrapper.setProximal(proximal);
lexer.setCurrent(lexer.getCurrent().substring(1));
}
result.setConstant(processConstant(lexer));
result.setKind(Kind.Constant);
if (!isString && !lexer.done() && (result.getConstant() instanceof IntegerType || result.getConstant() instanceof DecimalType) && (lexer.isStringConstant() || lexer.hasToken("year", "years", "month", "months", "week", "weeks", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds", "millisecond", "milliseconds"))) {
// it's a quantity
String ucum = null;
if (lexer.hasToken("year", "years", "month", "months", "week", "weeks", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds", "millisecond", "milliseconds")) {
String s = lexer.take();
if (s.equals("year") || s.equals("years"))
ucum = "a";
else if (s.equals("month") || s.equals("months"))
ucum = "mo";
else if (s.equals("week") || s.equals("weeks"))
ucum = "wk";
else if (s.equals("day") || s.equals("days"))
ucum = "d";
else if (s.equals("hour") || s.equals("hours"))
ucum = "h";
else if (s.equals("minute") || s.equals("minutes"))
ucum = "min";
else if (s.equals("second") || s.equals("seconds"))
ucum = "s";
else
// (s.equals("millisecond") || s.equals("milliseconds"))
ucum = "ms";
} else
ucum = lexer.readConstant("units");
result.setConstant(new Quantity().setValue(new BigDecimal(result.getConstant().primitiveValue())).setSystem("http://unitsofmeasure.org").setCode(ucum));
}
result.setEnd(lexer.getCurrentLocation());
} else if ("(".equals(lexer.getCurrent())) {
lexer.next();
result.setKind(Kind.Group);
result.setGroup(parseExpression(lexer, true));
if (!")".equals(lexer.getCurrent()))
throw lexer.error("Found " + lexer.getCurrent() + " expecting a \")\"");
result.setEnd(lexer.getCurrentLocation());
lexer.next();
} else {
if (!lexer.isToken() && !lexer.getCurrent().startsWith("`"))
throw lexer.error("Found " + lexer.getCurrent() + " expecting a token name");
if (lexer.isFixedName())
result.setName(lexer.readFixedName("Path Name"));
else
result.setName(lexer.take());
result.setEnd(lexer.getCurrentLocation());
if (!result.checkName())
throw lexer.error("Found " + result.getName() + " expecting a valid token name");
if ("(".equals(lexer.getCurrent())) {
Function f = Function.fromCode(result.getName());
FunctionDetails details = null;
if (f == null) {
if (hostServices != null)
details = hostServices.resolveFunction(result.getName());
if (details == null)
throw lexer.error("The name " + result.getName() + " is not a valid function name");
f = Function.Custom;
}
result.setKind(Kind.Function);
result.setFunction(f);
lexer.next();
while (!")".equals(lexer.getCurrent())) {
result.getParameters().add(parseExpression(lexer, true));
if (",".equals(lexer.getCurrent()))
lexer.next();
else if (!")".equals(lexer.getCurrent()))
throw lexer.error("The token " + lexer.getCurrent() + " is not expected here - either a \",\" or a \")\" expected");
}
result.setEnd(lexer.getCurrentLocation());
lexer.next();
checkParameters(lexer, c, result, details);
} else
result.setKind(Kind.Name);
}
ExpressionNode focus = result;
if ("[".equals(lexer.getCurrent())) {
lexer.next();
ExpressionNode item = new ExpressionNode(lexer.nextId());
item.setKind(Kind.Function);
item.setFunction(ExpressionNode.Function.Item);
item.getParameters().add(parseExpression(lexer, true));
if (!lexer.getCurrent().equals("]"))
throw lexer.error("The token " + lexer.getCurrent() + " is not expected here - a \"]\" expected");
lexer.next();
result.setInner(item);
focus = item;
}
if (".".equals(lexer.getCurrent())) {
lexer.next();
focus.setInner(parseExpression(lexer, false));
}
result.setProximal(proximal);
if (proximal) {
while (lexer.isOp()) {
focus.setOperation(ExpressionNode.Operation.fromCode(lexer.getCurrent()));
focus.setOpStart(lexer.getCurrentStartLocation());
focus.setOpEnd(lexer.getCurrentLocation());
lexer.next();
focus.setOpNext(parseExpression(lexer, false));
focus = focus.getOpNext();
}
result = organisePrecedence(lexer, result);
}
if (wrapper != null) {
wrapper.setOpNext(result);
result.setProximal(false);
result = wrapper;
}
return result;
}
Aggregations