use of org.hl7.fhir.dstu2016may.model.Base in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcSelect.
private List<Base> funcSelect(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
List<Base> result = new ArrayList<Base>();
List<Base> pc = new ArrayList<Base>();
for (Base item : focus) {
pc.clear();
pc.add(item);
result.addAll(execute(changeThis(context, item), pc, exp.getParameters().get(0), true));
}
return result;
}
use of org.hl7.fhir.dstu2016may.model.Base in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opLessOrEqual.
private List<Base> opLessOrEqual(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("string") && r.hasType("string"))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
return makeBoolean(new Double(l.primitiveValue()) <= new Double(r.primitiveValue()));
else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
else if ((l.hasType("time")) && (r.hasType("time")))
return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
} else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
List<Base> lUnits = left.get(0).listChildrenByName("unit");
String lunit = lUnits.size() == 1 ? lUnits.get(0).primitiveValue() : null;
List<Base> rUnits = right.get(0).listChildrenByName("unit");
String runit = rUnits.size() == 1 ? rUnits.get(0).primitiveValue() : null;
if ((lunit == null && runit == null) || lunit.equals(runit)) {
return opLessOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
} else {
throw new PathEngineException("Canonical Comparison isn't done yet");
}
}
return new ArrayList<Base>();
}
use of org.hl7.fhir.dstu2016may.model.Base in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method convertToString.
/**
* worker routine for converting a set of objects to a string representation
*
* @param items - result from @evaluate
* @return
*/
public String convertToString(List<Base> items) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (Base item : items) {
if (first)
first = false;
else
b.append(',');
b.append(convertToString(item));
}
return b.toString();
}
use of org.hl7.fhir.dstu2016may.model.Base in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opMod.
private List<Base> opMod(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 0)
throw new PathEngineException("Error performing mod: left operand has no value");
if (left.size() > 1)
throw new PathEngineException("Error performing mod: left operand has more than one value");
if (!left.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing mod: left operand has the wrong type (%s)", left.get(0).fhirType()));
if (right.size() == 0)
throw new PathEngineException("Error performing mod: right operand has no value");
if (right.size() > 1)
throw new PathEngineException("Error performing mod: right operand has more than one value");
if (!right.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing mod: 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")) {
Decimal d1;
try {
d1 = new Decimal(l.primitiveValue());
Decimal d2 = new Decimal(r.primitiveValue());
result.add(new DecimalType(d1.modulo(d2).asDecimal()));
} catch (UcumException e) {
throw new PathEngineException(e);
}
} else
throw new PathEngineException(String.format("Error performing mod: 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.dstu2016may.model.Base in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcWhere.
private List<Base> funcWhere(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
List<Base> result = new ArrayList<Base>();
List<Base> pc = new ArrayList<Base>();
for (Base item : focus) {
pc.clear();
pc.add(item);
if (convertToBoolean(execute(changeThis(context, item), pc, exp.getParameters().get(0), true)))
result.add(item);
}
return result;
}
Aggregations