Search in sources :

Example 56 with BooleanType

use of org.hl7.fhir.dstu2.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcContains.

private List<Base> funcContains(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> result = new ArrayList<Base>();
    String sw = convertToString(execute(context, baseToList(context.thisItem), exp.getParameters().get(0), true));
    if (focus.size() != 1) {
        result.add(new BooleanType(false).noExtensions());
    } else if (Utilities.noString(sw)) {
        result.add(new BooleanType(true).noExtensions());
    } else {
        String st = convertToString(focus.get(0));
        if (Utilities.noString(st)) {
            result.add(new BooleanType(false).noExtensions());
        } else {
            result.add(new BooleanType(st.contains(sw)).noExtensions());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 57 with BooleanType

use of org.hl7.fhir.dstu2.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcExists.

private List<Base> funcExists(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    boolean empty = true;
    List<Base> pc = new ArrayList<Base>();
    for (Base f : focus) {
        if (exp.getParameters().size() == 1) {
            pc.clear();
            pc.add(f);
            Equality v = asBool(execute(changeThis(context, f), pc, exp.getParameters().get(0), true), exp);
            if (v == Equality.True) {
                empty = false;
            }
        } else if (!f.isEmpty()) {
            empty = false;
        }
    }
    result.add(new BooleanType(!empty).noExtensions());
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 58 with BooleanType

use of org.hl7.fhir.dstu2.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcEndsWith.

private List<Base> funcEndsWith(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() == 0) {
        result.add(new BooleanType(false).noExtensions());
    } else if (Utilities.noString(sw)) {
        result.add(new BooleanType(true).noExtensions());
    } else {
        if (focus.size() == 1 && !Utilities.noString(sw)) {
            result.add(new BooleanType(convertToString(focus.get(0)).endsWith(sw)).noExtensions());
        } else {
            result.add(new BooleanType(false).noExtensions());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) Base(org.hl7.fhir.r5.model.Base)

Example 59 with BooleanType

use of org.hl7.fhir.dstu2.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcAllTrue.

private List<Base> funcAllTrue(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.True) {
                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.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) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r5.model.Base)

Example 60 with BooleanType

use of org.hl7.fhir.dstu2.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class CodeSystemUtilities method setNotSelectable.

public static void setNotSelectable(CodeSystem cs, ConceptDefinitionComponent concept) throws FHIRFormatError {
    defineNotSelectableProperty(cs);
    ConceptPropertyComponent p = getProperty(concept, "notSelectable");
    if (p != null)
        p.setValue(new BooleanType(true));
    else
        concept.addProperty().setCode("notSelectable").setValue(new BooleanType(true));
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) BooleanType(org.hl7.fhir.r5.model.BooleanType)

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