Search in sources :

Example 31 with Enumeration

use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, QuestionnaireItemType 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;
        // ? QuestionnaireItemTypeAttachment: ...?
        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.dstu2016may.model.Enumeration) StringType(org.hl7.fhir.dstu2016may.model.StringType) Reference(org.hl7.fhir.dstu2016may.model.Reference) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) Quantity(org.hl7.fhir.dstu2016may.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) DateTimeType(org.hl7.fhir.dstu2016may.model.DateTimeType) TimeType(org.hl7.fhir.dstu2016may.model.TimeType) UriType(org.hl7.fhir.dstu2016may.model.UriType) IntegerType(org.hl7.fhir.dstu2016may.model.IntegerType) DateTimeType(org.hl7.fhir.dstu2016may.model.DateTimeType) Coding(org.hl7.fhir.dstu2016may.model.Coding) DecimalType(org.hl7.fhir.dstu2016may.model.DecimalType) InstantType(org.hl7.fhir.dstu2016may.model.InstantType) DateType(org.hl7.fhir.dstu2016may.model.DateType)

Example 32 with Enumeration

use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.

the class SearchParameter method setProperty.

@Override
public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("url")) {
        // UriType
        this.url = castToUri(value);
    } else if (name.equals("version")) {
        // StringType
        this.version = castToString(value);
    } else if (name.equals("name")) {
        // StringType
        this.name = castToString(value);
    } else if (name.equals("status")) {
        value = new PublicationStatusEnumFactory().fromType(castToCode(value));
        // Enumeration<PublicationStatus>
        this.status = (Enumeration) value;
    } else if (name.equals("experimental")) {
        // BooleanType
        this.experimental = castToBoolean(value);
    } else if (name.equals("date")) {
        // DateTimeType
        this.date = castToDateTime(value);
    } else if (name.equals("publisher")) {
        // StringType
        this.publisher = castToString(value);
    } else if (name.equals("contact")) {
        this.getContact().add(castToContactDetail(value));
    } else if (name.equals("useContext")) {
        this.getUseContext().add(castToUsageContext(value));
    } else if (name.equals("jurisdiction")) {
        this.getJurisdiction().add(castToCodeableConcept(value));
    } else if (name.equals("purpose")) {
        // MarkdownType
        this.purpose = castToMarkdown(value);
    } else if (name.equals("code")) {
        // CodeType
        this.code = castToCode(value);
    } else if (name.equals("base")) {
        this.getBase().add(castToCode(value));
    } else if (name.equals("type")) {
        value = new SearchParamTypeEnumFactory().fromType(castToCode(value));
        // Enumeration<SearchParamType>
        this.type = (Enumeration) value;
    } else if (name.equals("derivedFrom")) {
        // UriType
        this.derivedFrom = castToUri(value);
    } else if (name.equals("description")) {
        // MarkdownType
        this.description = castToMarkdown(value);
    } else if (name.equals("expression")) {
        // StringType
        this.expression = castToString(value);
    } else if (name.equals("xpath")) {
        // StringType
        this.xpath = castToString(value);
    } else if (name.equals("xpathUsage")) {
        value = new XPathUsageTypeEnumFactory().fromType(castToCode(value));
        // Enumeration<XPathUsageType>
        this.xpathUsage = (Enumeration) value;
    } else if (name.equals("target")) {
        this.getTarget().add(castToCode(value));
    } else if (name.equals("comparator")) {
        value = new SearchComparatorEnumFactory().fromType(castToCode(value));
        this.getComparator().add((Enumeration) value);
    } else if (name.equals("modifier")) {
        value = new SearchModifierCodeEnumFactory().fromType(castToCode(value));
        this.getModifier().add((Enumeration) value);
    } else if (name.equals("chain")) {
        this.getChain().add(castToString(value));
    } else if (name.equals("component")) {
        this.getComponent().add((SearchParameterComponentComponent) value);
    } else
        return super.setProperty(name, value);
    return value;
}
Also used : PublicationStatusEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory) SearchParamTypeEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.SearchParamTypeEnumFactory)

Example 33 with Enumeration

use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.

the class FamilyMemberHistory method setProperty.

@Override
public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("identifier")) {
        this.getIdentifier().add(castToIdentifier(value));
    } else if (name.equals("definition")) {
        this.getDefinition().add(castToReference(value));
    } else if (name.equals("status")) {
        value = new FamilyHistoryStatusEnumFactory().fromType(castToCode(value));
        // Enumeration<FamilyHistoryStatus>
        this.status = (Enumeration) value;
    } else if (name.equals("notDone")) {
        // BooleanType
        this.notDone = castToBoolean(value);
    } else if (name.equals("notDoneReason")) {
        // CodeableConcept
        this.notDoneReason = castToCodeableConcept(value);
    } else if (name.equals("patient")) {
        // Reference
        this.patient = castToReference(value);
    } else if (name.equals("date")) {
        // DateTimeType
        this.date = castToDateTime(value);
    } else if (name.equals("name")) {
        // StringType
        this.name = castToString(value);
    } else if (name.equals("relationship")) {
        // CodeableConcept
        this.relationship = castToCodeableConcept(value);
    } else if (name.equals("gender")) {
        value = new AdministrativeGenderEnumFactory().fromType(castToCode(value));
        // Enumeration<AdministrativeGender>
        this.gender = (Enumeration) value;
    } else if (name.equals("born[x]")) {
        // Type
        this.born = castToType(value);
    } else if (name.equals("age[x]")) {
        // Type
        this.age = castToType(value);
    } else if (name.equals("estimatedAge")) {
        // BooleanType
        this.estimatedAge = castToBoolean(value);
    } else if (name.equals("deceased[x]")) {
        // Type
        this.deceased = castToType(value);
    } else if (name.equals("reasonCode")) {
        this.getReasonCode().add(castToCodeableConcept(value));
    } else if (name.equals("reasonReference")) {
        this.getReasonReference().add(castToReference(value));
    } else if (name.equals("note")) {
        this.getNote().add(castToAnnotation(value));
    } else if (name.equals("condition")) {
        this.getCondition().add((FamilyMemberHistoryConditionComponent) value);
    } else
        return super.setProperty(name, value);
    return value;
}
Also used : AdministrativeGenderEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGenderEnumFactory)

Example 34 with Enumeration

use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, QuestionnaireItemType 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 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;
        // ? QuestionnaireItemTypeAttachment: ...?
        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.dstu3.model.Enumeration) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Quantity(org.hl7.fhir.dstu3.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.dstu3.model.TimeType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) UriType(org.hl7.fhir.dstu3.model.UriType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Coding(org.hl7.fhir.dstu3.model.Coding) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) DateType(org.hl7.fhir.dstu3.model.DateType)

Example 35 with Enumeration

use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method addQuestion.

private QuestionnaireItemComponent addQuestion(QuestionnaireItemComponent group, QuestionnaireItemType af, String path, String id, String name, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, ValueSet vs) throws FHIRException {
    QuestionnaireItemComponent result = group.addItem();
    if (vs != null) {
        result.setOptions(new Reference());
        if (vs.getExpansion() == null) {
            result.getOptions().setReference(vs.getUrl());
            ToolingExtensions.addControl(result, "lookup");
        } else {
            if (Utilities.noString(vs.getId())) {
                vs.setId(nextId("vs"));
                questionnaire.getContained().add(vs);
                vsCache.put(vs.getUrl(), vs.getId());
                vs.setText(null);
                vs.setCompose(null);
                vs.getContact().clear();
                vs.setPublisherElement(null);
                vs.setCopyrightElement(null);
            }
            result.getOptions().setReference("#" + vs.getId());
        }
    }
    result.setLinkId(path + '.' + id);
    result.setText(name);
    result.setType(af);
    result.setRequired(false);
    result.setRepeats(false);
    if (id.endsWith("/1"))
        id = id.substring(0, id.length() - 2);
    if (answerGroups != null) {
        for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) {
            List<Base> children = new ArrayList<Base>();
            QuestionnaireResponse.QuestionnaireResponseItemComponent aq = null;
            Element obj = (Element) ag.getUserData("object");
            if (isPrimitive((TypeRefComponent) obj))
                children.add(obj);
            else if (obj instanceof Enumeration) {
                String value = ((Enumeration) obj).toString();
                children.add(new StringType(value));
            } else
                children = obj.listChildrenByName(id);
            for (Base child : children) {
                if (child != null) {
                    if (aq == null) {
                        aq = ag.addItem();
                        aq.setLinkId(result.getLinkId());
                        aq.setText(result.getText());
                    }
                    aq.addAnswer().setValue(convertType(child, af, vs, result.getLinkId()));
                }
            }
        }
    }
    return result;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) Element(org.hl7.fhir.dstu3.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse) Base(org.hl7.fhir.dstu3.model.Base)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)14 ArrayList (java.util.ArrayList)11 NotImplementedException (org.apache.commons.lang3.NotImplementedException)11 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 StringType (org.hl7.fhir.r5.model.StringType)7 ConformanceResourceStatusEnumFactory (org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatusEnumFactory)6 Enumeration (org.hl7.fhir.dstu3.model.Enumeration)6 Enumeration (org.hl7.fhir.r4.model.Enumeration)6 StringType (org.hl7.fhir.r4b.model.StringType)6 Enumeration (org.hl7.fhir.r5.model.Enumeration)6 UriType (org.hl7.fhir.r5.model.UriType)6 Base64 (org.apache.commons.codec.binary.Base64)5 PublicationStatusEnumFactory (org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory)5 StringType (org.hl7.fhir.dstu3.model.StringType)5 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)4 Reference (org.hl7.fhir.dstu2.model.Reference)4 StringType (org.hl7.fhir.dstu2.model.StringType)4 Patient (org.hl7.fhir.r4.model.Patient)4