Search in sources :

Example 31 with TimeType

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

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, AnswerFormat af, ValueSet vs, String path) throws FHIRException {
    switch(af) {
        // simple cases
        case BOOLEAN:
            if (value instanceof BooleanType)
                return (Type) value;
        case DECIMAL:
            if (value instanceof DecimalType)
                return (Type) value;
        case INTEGER:
            if (value instanceof IntegerType)
                return (Type) value;
        case DATE:
            if (value instanceof DateType)
                return (Type) value;
        case DATETIME:
            if (value instanceof DateTimeType)
                return (Type) value;
        case INSTANT:
            if (value instanceof InstantType)
                return (Type) value;
        case TIME:
            if (value instanceof TimeType)
                return (Type) value;
        case STRING:
            if (value instanceof StringType)
                return (Type) value;
            else if (value instanceof UriType)
                return new StringType(((UriType) value).asStringValue());
        case TEXT:
            if (value instanceof StringType)
                return (Type) value;
        case QUANTITY:
            if (value instanceof Quantity)
                return (Type) value;
        // ? AnswerFormatAttachment: ...?
        case CHOICE:
        case OPENCHOICE:
            if (value instanceof Coding)
                return (Type) 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;
            }
        case REFERENCE:
            if (value instanceof Reference)
                return (Type) value;
            else if (value instanceof StringType) {
                Reference r = new Reference();
                r.setReference(((StringType) value).asStringValue());
            }
    }
    throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
Also used : Enumeration(org.hl7.fhir.dstu2.model.Enumeration) StringType(org.hl7.fhir.dstu2.model.StringType) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Quantity(org.hl7.fhir.dstu2.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) TimeType(org.hl7.fhir.dstu2.model.TimeType) UriType(org.hl7.fhir.dstu2.model.UriType) IntegerType(org.hl7.fhir.dstu2.model.IntegerType) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) Coding(org.hl7.fhir.dstu2.model.Coding) DecimalType(org.hl7.fhir.dstu2.model.DecimalType) InstantType(org.hl7.fhir.dstu2.model.InstantType) DateType(org.hl7.fhir.dstu2.model.DateType)

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