Search in sources :

Example 66 with BooleanType

use of org.hl7.fhir.dstu2.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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PropertyMatcher(org.hl7.fhir.r5.model.Property.PropertyMatcher) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 67 with BooleanType

use of org.hl7.fhir.dstu2.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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PropertyMatcher(org.hl7.fhir.r5.model.Property.PropertyMatcher) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 68 with BooleanType

use of org.hl7.fhir.dstu2.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;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 69 with BooleanType

use of org.hl7.fhir.dstu2.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;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r5.model.Base)

Example 70 with BooleanType

use of org.hl7.fhir.dstu2.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);
}
Also used : Enumeration(org.hl7.fhir.r5.model.Enumeration) StringType(org.hl7.fhir.r5.model.StringType) Reference(org.hl7.fhir.r5.model.Reference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Quantity(org.hl7.fhir.r5.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.r5.model.TimeType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) UriType(org.hl7.fhir.r5.model.UriType) IntegerType(org.hl7.fhir.r5.model.IntegerType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) Coding(org.hl7.fhir.r5.model.Coding) DecimalType(org.hl7.fhir.r5.model.DecimalType) DateType(org.hl7.fhir.r5.model.DateType)

Aggregations

ArrayList (java.util.ArrayList)59 BooleanType (org.hl7.fhir.r5.model.BooleanType)38 BooleanType (org.hl7.fhir.r4.model.BooleanType)37 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 BooleanType (org.hl7.fhir.r4b.model.BooleanType)27 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)18 Base (org.hl7.fhir.r5.model.Base)17 Test (org.junit.Test)16 StringType (org.hl7.fhir.r4.model.StringType)15 Base (org.hl7.fhir.r4b.model.Base)15 BooleanType (org.hl7.fhir.dstu2016may.model.BooleanType)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)11 Base (org.hl7.fhir.dstu2.model.Base)10 StringType (org.hl7.fhir.dstu3.model.StringType)10 StringType (org.hl7.fhir.r5.model.StringType)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 Coding (org.hl7.fhir.r4.model.Coding)9