Search in sources :

Example 81 with Base

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

the class FHIRPathEngine method processDateConstant.

private Base processDateConstant(Object appInfo, String value) throws PathEngineException {
    if (value.startsWith("T"))
        return new TimeType(value.substring(1));
    String v = value;
    if (v.length() > 10) {
        int i = v.substring(10).indexOf("-");
        if (i == -1)
            i = v.substring(10).indexOf("+");
        if (i == -1)
            i = v.substring(10).indexOf("Z");
        v = i == -1 ? value : v.substring(0, 10 + i);
    }
    if (v.length() > 10)
        return new DateTimeType(value);
    else
        return new DateType(value);
}
Also used : DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) DateType(org.hl7.fhir.dstu2.model.DateType) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) TimeType(org.hl7.fhir.dstu2.model.TimeType)

Example 82 with Base

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

the class FHIRPathEngine method funcToString.

private List<Base> funcToString(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    result.add(new StringType(convertToString(focus)));
    return result;
}
Also used : StringType(org.hl7.fhir.dstu2.model.StringType) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.dstu2.model.Base)

Example 83 with Base

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

the class FHIRPathEngine method funcAs.

private List<Base> funcAs(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    String tn = exp.getParameters().get(0).getName();
    for (Base b : focus) if (b.hasType(tn))
        result.add(b);
    return result;
}
Also used : ArrayList(java.util.ArrayList) Base(org.hl7.fhir.dstu2.model.Base)

Example 84 with Base

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

the class FHIRPathEngine method opDivideBy.

private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 0)
        throw new PathEngineException("Error performing /: left operand has no value");
    if (left.size() > 1)
        throw new PathEngineException("Error performing /: left operand has more than one value");
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType()));
    if (right.size() == 0)
        throw new PathEngineException("Error performing /: right operand has no value");
    if (right.size() > 1)
        throw new PathEngineException("Error performing /: right operand has more than one value");
    if (!right.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing /: 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", "decimal") && r.hasType("integer", "decimal")) {
        Decimal d1;
        try {
            d1 = new Decimal(l.primitiveValue());
            Decimal d2 = new Decimal(r.primitiveValue());
            result.add(new DecimalType(d1.divide(d2).asDecimal()));
        } catch (UcumException e) {
            throw new PathEngineException(e);
        }
    } else
        throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
    return result;
}
Also used : BigDecimal(java.math.BigDecimal) Decimal(org.fhir.ucum.Decimal) ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.dstu2.model.DecimalType) UcumException(org.fhir.ucum.UcumException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base)

Example 85 with Base

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

the class FHIRPathEngine method funcLength.

private List<Base> funcLength(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    if (focus.size() == 1) {
        String s = convertToString(focus.get(0));
        result.add(new IntegerType(s.length()));
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.dstu2.model.IntegerType) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.dstu2.model.Base)

Aggregations

ArrayList (java.util.ArrayList)324 FHIRException (org.hl7.fhir.exceptions.FHIRException)177 Base (org.hl7.fhir.r4b.model.Base)87 Base (org.hl7.fhir.r5.model.Base)87 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)76 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)70 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)66 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)64 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)55 NotImplementedException (org.apache.commons.lang3.NotImplementedException)47 Base (org.hl7.fhir.dstu2016may.model.Base)47 UcumException (org.fhir.ucum.UcumException)43 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)41 Base (org.hl7.fhir.dstu2.model.Base)40 BigDecimal (java.math.BigDecimal)39 IOException (java.io.IOException)37 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)34 FileOutputStream (java.io.FileOutputStream)29 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)28 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)28