Search in sources :

Example 71 with TypeRefComponent

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

the class StructureDefinitionSpreadsheetGenerator method itemList.

private String itemList(List l) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < l.size(); i++) {
        Object o = l.get(i);
        String val = "";
        if (o instanceof StringType) {
            val = ((StringType) o).getValue();
        } else if (o instanceof UriType) {
            val = ((UriType) o).getValue();
        } else if (o instanceof IdType) {
            val = ((IdType) o).getValue();
        } else if (o instanceof Enumeration<?>) {
            val = o.toString();
        } else if (o instanceof TypeRefComponent) {
            TypeRefComponent t = (TypeRefComponent) o;
            val = t.getWorkingCode();
            if (val == null)
                val = "";
            if (val.startsWith("http://hl7.org/fhir/StructureDefinition/"))
                val = val.substring(40);
            if (t.hasTargetProfile())
                val = val + "(" + canonicalList(t.getTargetProfile()) + ")";
            if (t.hasProfile())
                val = val + " {" + canonicalList(t.getProfile()) + "}";
            if (t.hasAggregation())
                val = val + " <<" + aggList(t.getAggregation()) + ">>";
        } else if (o instanceof Coding) {
            Coding t = (Coding) o;
            val = (t.getSystem() == null ? "" : t.getSystem()) + (t.getCode() == null ? "" : "#" + t.getCode()) + (t.getDisplay() == null ? "" : " (" + t.getDisplay() + ")");
        } else if (o instanceof ElementDefinitionConstraintComponent) {
            ElementDefinitionConstraintComponent c = (ElementDefinitionConstraintComponent) o;
            val = c.getKey() + ":" + c.getHuman() + " {" + c.getExpression() + "}";
        } else if (o instanceof ElementDefinitionSlicingDiscriminatorComponent) {
            ElementDefinitionSlicingDiscriminatorComponent c = (ElementDefinitionSlicingDiscriminatorComponent) o;
            val = c.getType().toCode() + ":" + c.getPath() + "}";
        } else {
            val = o.toString();
            val = val.substring(val.indexOf("[") + 1);
            val = val.substring(0, val.indexOf("]"));
        }
        s = s.append(val);
        if (i == 0)
            s.append("\n");
    }
    return s.toString();
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.r5.model.StringType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) Coding(org.hl7.fhir.r5.model.Coding) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) UriType(org.hl7.fhir.r5.model.UriType) IdType(org.hl7.fhir.r5.model.IdType)

Example 72 with TypeRefComponent

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

the class QuestionnaireBuilder method selectTypes.

private void selectTypes(StructureDefinition profile, QuestionnaireItemComponent sub, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> source, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> dest) throws FHIRFormatError {
    List<QuestionnaireResponse.QuestionnaireResponseItemComponent> temp = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
        temp.add(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) source.remove(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) {
        // it should be empty
        assert (g.getItem().size() == 0);
        QuestionnaireResponse.QuestionnaireResponseItemComponent q = g.addItem();
        q.setLinkId(g.getLinkId() + "._type");
        q.setText("type");
        Coding cc = new Coding();
        QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
        a.setValue(cc);
        if (t.getCode().equals("Reference") && t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
            cc.setCode(t.getTargetProfile().substring(40));
            cc.setSystem("http://hl7.org/fhir/resource-types");
        } else {
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasTargetProfile())
                ps = pu.getProfile(profile, t.getTargetProfile());
            else if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile());
            if (ps != null) {
                cc.setCode(t.getProfile());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        // 1st: create the subgroup
        QuestionnaireResponse.QuestionnaireResponseItemComponent subg = a.addItem();
        dest.add(subg);
        subg.setLinkId(sub.getLinkId());
        subg.setText(sub.getText());
        subg.setUserData("object", g.getUserData("object"));
    }
}
Also used : QuestionnaireResponseItemAnswerComponent(org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Coding(org.hl7.fhir.dstu3.model.Coding) ProfileUtilities(org.hl7.fhir.dstu3.conformance.ProfileUtilities) Element(org.hl7.fhir.dstu3.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.dstu3.model.QuestionnaireResponse)

Example 73 with TypeRefComponent

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

the class FHIRPathEngine method getChildTypesByName.

private void getChildTypesByName(String type, String name, TypeDetails result) throws PathEngineException, DefinitionException {
    if (Utilities.noString(type))
        throw new PathEngineException("No type provided in BuildToolPathEvaluator.getChildTypesByName");
    if (type.equals("http://hl7.org/fhir/StructureDefinition/xhtml"))
        return;
    String url = null;
    if (type.contains("#")) {
        url = type.substring(0, type.indexOf("#"));
    } else {
        url = type;
    }
    String tail = "";
    StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
    if (sd == null)
        // this really is an error, because we can only get to here if the internal infrastrucgture is wrong
        throw new DefinitionException("Unknown type " + type);
    List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
    ElementDefinitionMatch m = null;
    if (type.contains("#"))
        m = getElementDefinition(sd, type.substring(type.indexOf("#") + 1), false);
    if (m != null && hasDataType(m.definition)) {
        if (m.fixedType != null) {
            StructureDefinition dt = worker.fetchTypeDefinition(m.fixedType);
            if (dt == null)
                throw new DefinitionException("unknown data type " + m.fixedType);
            sdl.add(dt);
        } else
            for (TypeRefComponent t : m.definition.getType()) {
                StructureDefinition dt = worker.fetchTypeDefinition(t.getCode());
                if (dt == null)
                    throw new DefinitionException("unknown data type " + t.getCode());
                sdl.add(dt);
            }
    } else {
        sdl.add(sd);
        if (type.contains("#")) {
            tail = type.substring(type.indexOf("#") + 1);
            tail = tail.substring(tail.indexOf("."));
        }
    }
    for (StructureDefinition sdi : sdl) {
        String path = sdi.getSnapshot().getElement().get(0).getPath() + tail + ".";
        if (name.equals("**")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.hasCode() && t.getCodeElement().hasValue()) {
                            String tn = null;
                            if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                                tn = sdi.getType() + "#" + ed.getPath();
                            else
                                tn = t.getCode();
                            if (t.getCode().equals("Resource")) {
                                for (String rn : worker.getResourceNames()) {
                                    if (!result.hasType(worker, rn)) {
                                        getChildTypesByName(result.addType(rn), "**", result);
                                    }
                                }
                            } else if (!result.hasType(worker, tn)) {
                                getChildTypesByName(result.addType(tn), "**", result);
                            }
                        }
                    }
            }
        } else if (name.equals("*")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path) && !ed.getPath().substring(path.length()).contains("."))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            result.addType(sdi.getType() + "#" + ed.getPath());
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            result.addType(t.getCode());
                    }
            }
        } else {
            path = sdi.getSnapshot().getElement().get(0).getPath() + tail + "." + name;
            ElementDefinitionMatch ed = getElementDefinition(sdi, path, false);
            if (ed != null) {
                if (!Utilities.noString(ed.getFixedType()))
                    result.addType(ed.getFixedType());
                else
                    for (TypeRefComponent t : ed.getDefinition().getType()) {
                        if (Utilities.noString(t.getCode()))
                            // throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
                            break;
                        ProfiledType pt = null;
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            pt = new ProfiledType(sdi.getUrl() + "#" + path);
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            pt = new ProfiledType(t.getCode());
                        if (pt != null) {
                            if (t.hasProfile())
                                pt.addProfile(t.getProfile());
                            if (ed.getDefinition().hasBinding())
                                pt.addBinding(ed.getDefinition().getBinding());
                            result.addType(pt);
                        }
                    }
            }
        }
    }
}
Also used : ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

Example 74 with TypeRefComponent

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

the class DefinitionNavigator method loadTypedChildren.

private void loadTypedChildren(TypeRefComponent type) throws DefinitionException {
    typeOfChildren = null;
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, type.hasProfile() ? type.getProfile() : type.getCode());
    if (sd != null) {
        DefinitionNavigator dn = new DefinitionNavigator(context, sd, 0, path, names, sd.getType());
        typeChildren = dn.children();
    } else
        throw new DefinitionException("Unable to find definition for " + type.getCode() + (type.hasProfile() ? "(" + type.getProfile() + ")" : ""));
    typeOfChildren = type;
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 75 with TypeRefComponent

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

the class StructureDefinitionSpreadsheetGenerator method itemList.

private String itemList(List l) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < l.size(); i++) {
        Object o = l.get(i);
        String val = "";
        if (o instanceof StringType) {
            val = ((StringType) o).getValue();
        } else if (o instanceof UriType) {
            val = ((UriType) o).getValue();
        } else if (o instanceof IdType) {
            val = ((IdType) o).getValue();
        } else if (o instanceof Enumeration<?>) {
            val = o.toString();
        } else if (o instanceof TypeRefComponent) {
            TypeRefComponent t = (TypeRefComponent) o;
            val = t.getWorkingCode();
            if (val == null)
                val = "";
            if (val.startsWith("http://hl7.org/fhir/StructureDefinition/"))
                val = val.substring(40);
            if (t.hasTargetProfile())
                val = val + "(" + canonicalList(t.getTargetProfile()) + ")";
            if (t.hasProfile())
                val = val + " {" + canonicalList(t.getProfile()) + "}";
            if (t.hasAggregation())
                val = val + " <<" + aggList(t.getAggregation()) + ">>";
        } else if (o instanceof Coding) {
            Coding t = (Coding) o;
            val = (t.getSystem() == null ? "" : t.getSystem()) + (t.getCode() == null ? "" : "#" + t.getCode()) + (t.getDisplay() == null ? "" : " (" + t.getDisplay() + ")");
        } else if (o instanceof ElementDefinitionConstraintComponent) {
            ElementDefinitionConstraintComponent c = (ElementDefinitionConstraintComponent) o;
            val = c.getKey() + ":" + c.getHuman() + " {" + c.getExpression() + "}";
        } else if (o instanceof ElementDefinitionSlicingDiscriminatorComponent) {
            ElementDefinitionSlicingDiscriminatorComponent c = (ElementDefinitionSlicingDiscriminatorComponent) o;
            val = c.getType().toCode() + ":" + c.getPath() + "}";
        } else {
            val = o.toString();
            val = val.substring(val.indexOf("[") + 1);
            val = val.substring(0, val.indexOf("]"));
        }
        s = s.append(val);
        if (i == 0)
            s.append("\n");
    }
    return s.toString();
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.r4b.model.StringType) TypeRefComponent(org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent) Coding(org.hl7.fhir.r4b.model.Coding) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) UriType(org.hl7.fhir.r4b.model.UriType) IdType(org.hl7.fhir.r4b.model.IdType)

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