use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genCardinality.
private Cell genCardinality(HierarchicalTableGenerator gen, ElementDefinition definition, Row row, boolean hasDef, UnusedTracker tracker, ElementDefinition fallback) {
IntegerType min = !hasDef ? new IntegerType() : definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
StringType max = !hasDef ? new StringType() : definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
if (min.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
if (base.hasMinElement()) {
min = base.getMinElement().copy();
min.setUserData(DERIVATION_EQUALS, true);
}
}
if (max.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
if (base.hasMaxElement()) {
max = base.getMaxElement().copy();
max.setUserData(DERIVATION_EQUALS, true);
}
}
if (min.isEmpty() && fallback != null)
min = fallback.getMinElement();
if (max.isEmpty() && fallback != null)
max = fallback.getMaxElement();
if (!max.isEmpty())
tracker.used = !max.getValue().equals("0");
Cell cell = gen.new Cell(null, null, null, null, null);
row.getCells().add(cell);
if (!min.isEmpty() || !max.isEmpty()) {
cell.addPiece(checkForNoChange(min, gen.new Piece(null, !min.hasValue() ? "" : Integer.toString(min.getValue()), null)));
cell.addPiece(checkForNoChange(min, max, gen.new Piece(null, "..", null)));
cell.addPiece(checkForNoChange(max, gen.new Piece(null, !max.hasValue() ? "" : max.getValue(), null)));
}
return cell;
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method execute.
private List<Base> execute(ExecutionContext context, List<Base> focus, ExpressionNode exp, boolean atEntry) throws FHIRException {
// System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
List<Base> work = new ArrayList<Base>();
switch(exp.getKind()) {
case Unary:
work.add(new IntegerType(0));
break;
case Name:
if (atEntry && exp.getName().equals("$this")) {
work.add(context.getThisItem());
} else if (atEntry && exp.getName().equals("$total")) {
work.addAll(context.getTotal());
} else if (atEntry && exp.getName().equals("$index")) {
work.add(context.getIndex());
} else {
for (Base item : focus) {
List<Base> outcome = execute(context, item, exp, atEntry);
for (Base base : outcome) {
if (base != null) {
work.add(base);
}
}
}
}
break;
case Function:
List<Base> work2 = evaluateFunction(context, focus, exp);
work.addAll(work2);
break;
case Constant:
work.addAll(resolveConstant(context, exp.getConstant(), false, exp));
break;
case Group:
work2 = execute(context, focus, exp.getGroup(), atEntry);
work.addAll(work2);
}
if (exp.getInner() != null) {
work = execute(context, work, exp.getInner(), false);
}
if (exp.isProximal() && exp.getOperation() != null) {
ExpressionNode next = exp.getOpNext();
ExpressionNode last = exp;
while (next != null) {
List<Base> work2 = preOperate(work, last.getOperation(), exp);
if (work2 != null) {
work = work2;
} else if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As) {
work2 = executeTypeName(context, focus, next, false);
work = operate(context, work, last.getOperation(), work2, last);
} else {
work2 = execute(context, focus, next, true);
work = operate(context, work, last.getOperation(), work2, last);
// System.out.println("Result of {'"+last.toString()+" "+last.getOperation().toCode()+" "+next.toString()+"'}: "+focus.toString());
}
last = next;
next = next.getOpNext();
}
}
// System.out.println("Result of {'"+exp.toString()+"'}: "+work.toString());
return work;
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcFloor.
private List<Base> funcFloor(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
if (focus.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "floor", focus.size());
}
Base base = focus.get(0);
List<Base> result = new ArrayList<Base>();
if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
Double d = Double.parseDouble(base.primitiveValue());
try {
result.add(new IntegerType((int) Math.floor(d)));
} catch (Exception e) {
// just return nothing
}
} else {
makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "floor", "(focus)", base.fhirType(), "integer or decimal");
}
return result;
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcTruncate.
private List<Base> funcTruncate(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
if (focus.size() != 1) {
throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "truncate", focus.size());
}
Base base = focus.get(0);
List<Base> result = new ArrayList<Base>();
if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
String s = base.primitiveValue();
if (s.contains(".")) {
s = s.substring(0, s.indexOf("."));
}
result.add(new IntegerType(s));
} else {
makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "sqrt", "(focus)", base.fhirType(), "integer or decimal");
}
return result;
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opPlus.
private List<Base> opPlus(List<Base> left, List<Base> right, ExpressionNode expr) throws PathEngineException {
if (left.size() == 0 || right.size() == 0) {
return new ArrayList<Base>();
}
if (left.size() > 1) {
throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_PLURAL, "+");
}
if (!left.get(0).isPrimitive()) {
throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_WRONG_TYPE, "+", left.get(0).fhirType());
}
if (right.size() > 1) {
throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_PLURAL, "+");
}
if (!right.get(0).isPrimitive() && !((left.get(0).isDateTime() || "0".equals(left.get(0).primitiveValue()) || left.get(0).hasType("Quantity")) && right.get(0).hasType("Quantity"))) {
throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_WRONG_TYPE, "+", right.get(0).fhirType());
}
List<Base> result = new ArrayList<Base>();
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING)) {
result.add(new StringType(l.primitiveValue() + r.primitiveValue()));
} else 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()).add(new BigDecimal(r.primitiveValue()))));
} else if (l.isDateTime() && r.hasType("Quantity")) {
result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, false, expr));
} else {
throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "+", left.get(0).fhirType(), right.get(0).fhirType());
}
return result;
}
Aggregations