use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcMatches.
private List<Base> funcMatches(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true));
if (focus.size() == 1 && !Utilities.noString(sw)) {
String st = convertToString(focus.get(0));
if (Utilities.noString(st)) {
result.add(new BooleanType(false).noExtensions());
} else {
Pattern p = Pattern.compile("(?s)" + sw);
Matcher m = p.matcher(st);
boolean ok = m.find();
result.add(new BooleanType(ok).noExtensions());
}
} else {
result.add(new BooleanType(false).noExtensions());
}
return result;
}
use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcMatchesFull.
private List<Base> funcMatchesFull(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true));
if (focus.size() == 1 && !Utilities.noString(sw)) {
String st = convertToString(focus.get(0));
if (Utilities.noString(st)) {
result.add(new BooleanType(false).noExtensions());
} else {
Pattern p = Pattern.compile("(?s)" + sw);
Matcher m = p.matcher(st);
boolean ok = m.matches();
result.add(new BooleanType(ok).noExtensions());
}
} else {
result.add(new BooleanType(false).noExtensions());
}
return result;
}
use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcAll.
private List<Base> funcAll(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
if (exp.getParameters().size() == 1) {
List<Base> pc = new ArrayList<Base>();
boolean all = true;
for (Base item : focus) {
pc.clear();
pc.add(item);
Equality eq = asBool(execute(changeThis(context, item), pc, exp.getParameters().get(0), true), exp);
if (eq != Equality.True) {
all = false;
break;
}
}
result.add(new BooleanType(all).noExtensions());
} else {
// (exp.getParameters().size() == 0) {
boolean all = true;
for (Base item : focus) {
Equality eq = asBool(item, true);
if (eq != Equality.True) {
all = false;
break;
}
}
result.add(new BooleanType(all).noExtensions());
}
return result;
}
use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcAllFalse.
private List<Base> funcAllFalse(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
if (exp.getParameters().size() == 1) {
boolean all = true;
List<Base> pc = new ArrayList<Base>();
for (Base item : focus) {
pc.clear();
pc.add(item);
List<Base> res = execute(context, pc, exp.getParameters().get(0), true);
Equality v = asBool(res, exp);
if (v != Equality.False) {
all = false;
break;
}
}
result.add(new BooleanType(all).noExtensions());
} else {
boolean all = true;
for (Base item : focus) {
if (!canConvertToBoolean(item)) {
throw new FHIRException("Unable to convert '" + convertToString(item) + "' to a boolean");
}
Equality v = asBool(item, true);
if (v != Equality.False) {
all = false;
break;
}
}
result.add(new BooleanType(all).noExtensions());
}
return result;
}
use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method convertType.
@SuppressWarnings("unchecked")
private DataType convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
switch(af) {
// simple cases
case BOOLEAN:
if (value instanceof BooleanType)
return (DataType) value;
break;
case DECIMAL:
if (value instanceof DecimalType)
return (DataType) value;
break;
case INTEGER:
if (value instanceof IntegerType)
return (DataType) value;
break;
case DATE:
if (value instanceof DateType)
return (DataType) value;
break;
case DATETIME:
if (value instanceof DateTimeType)
return (DataType) value;
break;
case TIME:
if (value instanceof TimeType)
return (DataType) value;
break;
case STRING:
if (value instanceof StringType)
return (DataType) value;
else if (value instanceof UriType)
return new StringType(((UriType) value).asStringValue());
break;
case TEXT:
if (value instanceof StringType)
return (DataType) value;
break;
case QUANTITY:
if (value instanceof Quantity)
return (DataType) value;
break;
// ? QuestionnaireItemTypeAttachment: ...?
case CODING:
if (value instanceof Coding)
return (DataType) value;
else if (value instanceof Enumeration) {
Coding cc = new Coding();
cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
} else if (value instanceof StringType) {
Coding cc = new Coding();
cc.setCode(((StringType) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
}
break;
case REFERENCE:
if (value instanceof Reference)
return (DataType) value;
else if (value instanceof StringType) {
Reference r = new Reference();
r.setReference(((StringType) value).asStringValue());
}
break;
default:
break;
}
throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
Aggregations