Search in sources :

Example 11 with TimeType

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

the class FHIRPathEngine method compareTimeElements.

private Integer compareTimeElements(Base theL, Base theR, boolean theEquivalenceTest) {
    TimeType left = theL instanceof TimeType ? (TimeType) theL : new TimeType(theL.primitiveValue());
    TimeType right = theR instanceof TimeType ? (TimeType) theR : new TimeType(theR.primitiveValue());
    if (left.getHour() < right.getHour()) {
        return -1;
    } else if (left.getHour() > right.getHour()) {
        return 1;
    // hour is not a valid precision
    // } else if (dateLeft.getPrecision() == TemporalPrecisionEnum.YEAR && dateRight.getPrecision() == TemporalPrecisionEnum.YEAR) {
    // return 0;
    // } else if (dateLeft.getPrecision() == TemporalPrecisionEnum.HOUR || dateRight.getPrecision() == TemporalPrecisionEnum.HOUR) {
    // return null;
    }
    if (left.getMinute() < right.getMinute()) {
        return -1;
    } else if (left.getMinute() > right.getMinute()) {
        return 1;
    } else if (left.getPrecision() == TemporalPrecisionEnum.MINUTE && right.getPrecision() == TemporalPrecisionEnum.MINUTE) {
        return 0;
    } else if (left.getPrecision() == TemporalPrecisionEnum.MINUTE || right.getPrecision() == TemporalPrecisionEnum.MINUTE) {
        return null;
    }
    if (left.getSecond() < right.getSecond()) {
        return -1;
    } else if (left.getSecond() > right.getSecond()) {
        return 1;
    } else {
        return 0;
    }
}
Also used : TimeType(org.hl7.fhir.r5.model.TimeType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) BaseDateTimeType(org.hl7.fhir.r5.model.BaseDateTimeType)

Example 12 with TimeType

use of org.hl7.fhir.dstu2016may.model.TimeType 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)

Example 13 with TimeType

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

the class QuestionnaireValidator method checkTimeOption.

private void checkTimeOption(List<ValidationMessage> errors, Element answer, NodeStack stack, QuestionnaireWithContext qSrc, QuestionnaireItemComponent qItem, boolean openChoice) {
    Element v = answer.getNamedChild("valueTime");
    NodeStack ns = stack.push(v, -1, null, null);
    if (qItem.getAnswerOption().size() > 0) {
        List<TimeType> list = new ArrayList<TimeType>();
        for (QuestionnaireItemAnswerOptionComponent components : qItem.getAnswerOption()) {
            try {
                list.add(components.getValueTimeType());
            } catch (FHIRException e) {
            // If it's the wrong type, just keep going
            }
        }
        if (list.isEmpty() && !openChoice) {
            rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOOPTIONSTIME);
        } else {
            boolean found = false;
            for (TimeType item : list) {
                if (item.getValue().equals(v.primitiveValue())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                rule(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), found, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTIME, v.primitiveValue());
            }
        }
    } else
        hint(errors, IssueType.STRUCTURE, v.line(), v.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_TIMENOOPTIONS);
}
Also used : QuestionnaireItemAnswerOptionComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.r5.model.TimeType)

Example 14 with TimeType

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

the class FHIRPathEngine method processDateConstant.

private Base processDateConstant(Object appInfo, String value, ExpressionNode expr) throws PathEngineException {
    String date = null;
    String time = null;
    String tz = null;
    TemporalPrecisionEnum temp = null;
    if (value.startsWith("T")) {
        time = value.substring(1);
    } else if (!value.contains("T")) {
        date = value;
    } else {
        String[] p = value.split("T");
        date = p[0];
        if (p.length > 1) {
            time = p[1];
        }
    }
    if (time != null) {
        int i = time.indexOf("-");
        if (i == -1) {
            i = time.indexOf("+");
        }
        if (i == -1) {
            i = time.indexOf("Z");
        }
        if (i > -1) {
            tz = time.substring(i);
            time = time.substring(0, i);
        }
        if (time.length() == 2) {
            time = time + ":00:00";
            temp = TemporalPrecisionEnum.MINUTE;
        } else if (time.length() == 5) {
            temp = TemporalPrecisionEnum.MINUTE;
            time = time + ":00";
        } else if (time.contains(".")) {
            temp = TemporalPrecisionEnum.MILLI;
        } else {
            temp = TemporalPrecisionEnum.SECOND;
        }
    }
    if (date == null) {
        if (tz != null) {
            throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT, value);
        } else {
            TimeType tt = new TimeType(time);
            tt.setPrecision(temp);
            return tt.noExtensions();
        }
    } else if (time != null) {
        DateTimeType dt = new DateTimeType(date + "T" + time + (tz == null ? "" : tz));
        dt.setPrecision(temp);
        return dt.noExtensions();
    } else {
        return new DateType(date).noExtensions();
    }
}
Also used : BaseDateTimeType(org.hl7.fhir.r4b.model.BaseDateTimeType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) DateType(org.hl7.fhir.r4b.model.DateType) BaseDateTimeType(org.hl7.fhir.r4b.model.BaseDateTimeType) TimeType(org.hl7.fhir.r4b.model.TimeType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType)

Example 15 with TimeType

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

the class TimeTypeNullTest method testToString.

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

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)9 TimeType (org.hl7.fhir.r4b.model.TimeType)8 TimeType (org.hl7.fhir.r5.model.TimeType)6 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)5 TimeType (org.hl7.fhir.r4.model.TimeType)5 DateTimeType (org.hl7.fhir.r5.model.DateTimeType)5 DisplayName (org.junit.jupiter.api.DisplayName)5 Test (org.junit.jupiter.api.Test)5 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)3 DateType (org.hl7.fhir.r5.model.DateType)3 Test (org.junit.Test)3 TemporalPrecisionEnum (ca.uhn.fhir.model.api.TemporalPrecisionEnum)2 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)2 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)2 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)2 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)2 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)2 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)2 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)2 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)2