Search in sources :

Example 76 with BooleanType

use of org.hl7.fhir.dstu2016may.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.r4b.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r4b.model.Base)

Example 77 with BooleanType

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

the class FHIRPathEngine method funcSupersetOf.

private List<Base> funcSupersetOf(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> target = execute(context, focus, exp.getParameters().get(0), true);
    boolean valid = true;
    for (Base item : target) {
        boolean found = false;
        for (Base t : focus) {
            if (Base.compareDeep(item, t, false)) {
                found = true;
                break;
            }
        }
        if (!found) {
            valid = false;
            break;
        }
    }
    List<Base> result = new ArrayList<Base>();
    result.add(new BooleanType(valid).noExtensions());
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r4b.model.BooleanType) Base(org.hl7.fhir.r4b.model.Base)

Example 78 with BooleanType

use of org.hl7.fhir.dstu2016may.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.r4b.model.BooleanType) Base(org.hl7.fhir.r4b.model.Base)

Example 79 with BooleanType

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

the class BooleanTypeNullTest method testToString.

@Test
@DisplayName("Test null value toString()")
void testToString() {
    BooleanType nullBoolean = new BooleanType();
    System.out.println("Value -> " + nullBoolean);
}
Also used : BooleanType(org.hl7.fhir.r4b.model.BooleanType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 80 with BooleanType

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

the class BooleanTypeNullTest method equalsDeep.

@Test
@DisplayName("Test null value equalsDeep()")
void equalsDeep() {
    BooleanType nullBoolean = new BooleanType();
    BooleanType validBoolean = new BooleanType("false");
    Assertions.assertFalse(nullBoolean.equalsDeep(validBoolean));
}
Also used : BooleanType(org.hl7.fhir.r4b.model.BooleanType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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