Search in sources :

Example 96 with TypeRefComponent

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

the class Property method getChildProperties.

protected List<Property> getChildProperties(String elementName, String statedType) throws FHIRException {
    ElementDefinition ed = definition;
    StructureDefinition sd = structure;
    List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
    String url = null;
    if (children.isEmpty() || isElementWithOnlyExtension(ed, children)) {
        // ok, find the right definitions
        String t = null;
        if (ed.getType().size() == 1)
            t = ed.getType().get(0).getWorkingCode();
        else if (ed.getType().size() == 0)
            throw new Error("types == 0, and no children found on " + getDefinition().getPath());
        else {
            t = ed.getType().get(0).getWorkingCode();
            boolean all = true;
            for (TypeRefComponent tr : ed.getType()) {
                if (!tr.getWorkingCode().equals(t)) {
                    all = false;
                    break;
                }
            }
            if (!all) {
                // ok, it's polymorphic
                if (ed.hasRepresentation(PropertyRepresentation.TYPEATTR)) {
                    t = statedType;
                    if (t == null && ToolingExtensions.hasExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype"))
                        t = ToolingExtensions.readStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype");
                    boolean ok = false;
                    for (TypeRefComponent tr : ed.getType()) {
                        if (tr.getWorkingCode().equals(t))
                            ok = true;
                        if (Utilities.isAbsoluteUrl(tr.getWorkingCode())) {
                            StructureDefinition sdt = context.fetchResource(StructureDefinition.class, tr.getWorkingCode());
                            if (sdt != null && sdt.getType().equals(t)) {
                                url = tr.getWorkingCode();
                                ok = true;
                            }
                        }
                        if (ok)
                            break;
                    }
                    if (!ok)
                        throw new DefinitionException("Type '" + t + "' is not an acceptable type for '" + elementName + "' on property " + definition.getPath());
                } else {
                    t = elementName.substring(tail(ed.getPath()).length() - 3);
                    if (isPrimitive(lowFirst(t)))
                        t = lowFirst(t);
                }
            }
        }
        if (!"xhtml".equals(t)) {
            for (TypeRefComponent aType : ed.getType()) {
                if (aType.getWorkingCode().equals(t)) {
                    if (aType.hasProfile()) {
                        assert aType.getProfile().size() == 1;
                        url = aType.getProfile().get(0).getValue();
                    } else {
                        url = ProfileUtilities.sdNs(t, context.getOverrideVersionNs());
                    }
                    break;
                }
            }
            if (url == null)
                throw new FHIRException("Unable to find type " + t + " for element " + elementName + " with path " + ed.getPath());
            sd = context.fetchResource(StructureDefinition.class, url);
            if (sd == null)
                throw new DefinitionException("Unable to find type '" + t + "' for name '" + elementName + "' on property " + definition.getPath());
            children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
        }
    }
    List<Property> properties = new ArrayList<Property>();
    for (ElementDefinition child : children) {
        properties.add(new Property(context, child, sd));
    }
    return properties;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 97 with TypeRefComponent

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

the class StructureMapUtilities method analyseSource.

private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws FHIRException {
    VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
    if (var == null)
        throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
    PropertyWithType prop = var.getProperty();
    boolean optional = false;
    boolean repeating = false;
    if (src.hasCondition()) {
        optional = true;
    }
    if (src.hasElement()) {
        Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement());
        if (element == null)
            throw new FHIRException("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
        if (element.getDefinition().getMin() == 0)
            optional = true;
        if (element.getDefinition().getMax().equals("*"))
            repeating = true;
        VariablesForProfiling result = vars.copy(optional, repeating);
        TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
        for (TypeRefComponent tr : element.getDefinition().getType()) {
            if (!tr.hasCode())
                throw new Error("Rule \"" + ruleId + "\": Element has no type");
            ProfiledType pt = new ProfiledType(tr.getWorkingCode());
            if (tr.hasProfile())
                pt.addProfiles(tr.getProfile());
            if (element.getDefinition().hasBinding())
                pt.addBinding(element.getDefinition().getBinding());
            type.addType(pt);
        }
        td.addText(prop.getPath() + "." + src.getElement());
        if (src.hasVariable())
            result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
        return result;
    } else {
        // ditto!
        td.addText(prop.getPath());
        return vars.copy(optional, repeating);
    }
}
Also used : TypeDetails(org.hl7.fhir.r4.model.TypeDetails) ProfiledType(org.hl7.fhir.r4.model.TypeDetails.ProfiledType) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r4.elementmodel.Property)

Example 98 with TypeRefComponent

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

the class QuestionnaireBuilder method isPrimitive.

private boolean isPrimitive(TypeRefComponent t) {
    String code = t.getWorkingCode();
    StructureDefinition sd = context.fetchTypeDefinition(code);
    return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition)

Example 99 with TypeRefComponent

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

the class QuestionnaireBuilder method buildQuestion.

private void buildQuestion(QuestionnaireItemComponent group, StructureDefinition profile, ElementDefinition element, String path, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, List<ElementDefinition> parents) throws FHIRException {
    group.setLinkId(path);
    // in this context, we don't have any concepts to mark...
    // prefix with name?
    group.setText(element.getShort());
    group.setRequired(element.getMin() > 0);
    if (element.getMin() > 0)
        ToolingExtensions.addMin(group, element.getMin());
    group.setRepeats(!element.getMax().equals('1'));
    if (!element.getMax().equals("*"))
        ToolingExtensions.addMax(group, Integer.parseInt(element.getMax()));
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) {
        ag.setLinkId(group.getLinkId());
        ag.setText(group.getText());
    }
    if (!Utilities.noString(element.getComment()))
        ToolingExtensions.addFlyOver(group, element.getDefinition() + " " + element.getComment());
    else
        ToolingExtensions.addFlyOver(group, element.getDefinition());
    if (element.getType().size() > 1 || element.getType().get(0).getWorkingCode().equals("*")) {
        List<TypeRefComponent> types = expandTypeList(element.getType());
        Questionnaire.QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.CHOICE, element.getPath(), "_type", "type", null, makeTypeList(profile, types, element.getPath()));
        for (TypeRefComponent t : types) {
            Questionnaire.QuestionnaireItemComponent sub = q.addItem();
            sub.setType(QuestionnaireItemType.GROUP);
            sub.setLinkId(element.getPath() + "._" + t.getUserData("text"));
            sub.setText((String) t.getUserData("text"));
            // always optional, never repeats
            List<QuestionnaireResponse.QuestionnaireResponseItemComponent> selected = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
            selectTypes(profile, sub, t, answerGroups, selected);
            processDataType(profile, sub, element, element.getPath() + "._" + t.getUserData("text"), t, selected, parents);
        }
    } else
        // now we have to build the question panel for each different data type
        processDataType(profile, group, element, element.getPath(), element.getType().get(0), answerGroups, parents);
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)

Example 100 with TypeRefComponent

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

the class QuestionnaireBuilder method makeTypeList.

private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
    ValueSet vs = new ValueSet();
    vs.setName("Type options for " + path);
    vs.setDescription(vs.present());
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExpansion(new ValueSetExpansionComponent());
    vs.getExpansion().setIdentifier(Factory.createUUID());
    vs.getExpansion().setTimestampElement(DateTimeType.now());
    for (TypeRefComponent t : types) {
        if (t.hasTarget()) {
            for (UriType u : t.getTargetProfile()) {
                if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue().substring(40));
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                    cc.setDisplay(cc.getCode());
                }
            }
        } else if (!t.hasProfile()) {
            ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
            cc.setCode(t.getWorkingCode());
            cc.setDisplay(t.getWorkingCode());
            cc.setSystem("http://hl7.org/fhir/data-types");
        } else
            for (UriType u : t.getProfile()) {
                ProfileUtilities pu = new ProfileUtilities(context, null, null);
                StructureDefinition ps = pu.getProfile(profile, u.getValue());
                if (ps != null) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue());
                    cc.setDisplay(ps.getType());
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                }
            }
    }
    return vs;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriType(org.hl7.fhir.r4.model.UriType)

Aggregations

TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)71 ArrayList (java.util.ArrayList)57 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)47 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)43 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)37 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)31 TypeRefComponent (org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent)30 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 TypeRefComponent (org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent)24 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)19 HashSet (java.util.HashSet)18 TypeRefComponent (org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent)18 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)18 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)17 UriType (org.hl7.fhir.r5.model.UriType)15 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)14 List (java.util.List)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)12 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)12