Search in sources :

Example 26 with ProfiledType

use of org.hl7.fhir.definitions.model.ProfiledType in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseTransform.

private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
    switch(tgt.getTransform()) {
        case CREATE:
            String p = getParamString(vars, tgt.getParameter().get(0));
            return new TypeDetails(CollectionStatus.SINGLETON, p);
        case COPY:
            return getParam(vars, tgt.getParameter().get(0));
        case EVALUATE:
            ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
            if (expr == null) {
                expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
                tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
            }
            return fpe.check(vars, null, expr);
        case TRANSLATE:
            return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
        case CC:
            ProfiledType res = new ProfiledType("CodeableConcept");
            if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
                TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).getProperty().getTypes();
                if (td != null && td.hasBinding())
                    // todo: do we need to check that there's no implicit translation her? I don't think we do...
                    res.addBinding(td.getBinding());
            }
            return new TypeDetails(CollectionStatus.SINGLETON, res);
        case C:
            return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
        case QTY:
            return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
        case REFERENCE:
            VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
            if (vrs == null)
                throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
            String profile = vrs.getProperty().getProfileProperty().getStructure().getUrl();
            TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
            td.addType("Reference", profile);
            return td;
        default:
            throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
    }
}
Also used : ProfiledType(org.hl7.fhir.r5.model.TypeDetails.ProfiledType) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 27 with ProfiledType

use of org.hl7.fhir.definitions.model.ProfiledType in project kindling by HL7.

the class ProfileGenerator method defineElement.

/**
 * note: snapshot implies that we are generating a resource or a data type; for other profiles, the snapshot is generated elsewhere
 * @param isInterface
 */
private ElementDefinition defineElement(Profile ap, StructureDefinition p, List<ElementDefinition> elements, ElementDefn e, String path, Set<String> slices, List<SliceHandle> parentSlices, SnapShotMode snapshot, boolean root, String defType, String inheritedType, boolean defaults) throws Exception {
    boolean handleDiscriminator = true;
    if (!Utilities.noString(e.getProfileName()) && !e.getDiscriminator().isEmpty() && !slices.contains(path)) {
        handleDiscriminator = false;
        // hey, we jumped straight into the slices with setting up the slicing (allowed in the spreadsheets, but not otherwise)
        ElementDefinition slicer = new ElementDefinition();
        elements.add(slicer);
        slicer.setId(path);
        slicer.setPath(path);
        processDiscriminator(e, path, slicer);
        if (e.getMaxCardinality() != null)
            slicer.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
        slices.add(path);
    }
    // todo for task 12259
    // if (ap != null) {
    // String base = isImplicitTypeConstraint(path);
    // if (base != null) {
    // ElementDefinition typeConstrainer = new ElementDefinition(ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    // elements.add(typeConstrainer);
    // typeConstrainer.setId(base);
    // typeConstrainer.setPath(base);
    // String type = path.substring(base.length()-3);
    // if (definitions.hasPrimitiveType(Utilities.uncapitalize(type)))
    // type = Utilities.uncapitalize(type);
    // typeConstrainer.addType().setCode(type);
    // }
    // }
    ElementDefinition ce = new ElementDefinition(defaults, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    elements.add(ce);
    if (e.getStandardsStatus() != null)
        ToolingExtensions.setStandardsStatus(ce, e.getStandardsStatus(), e.getNormativeVersion());
    ce.setId(path);
    ce.setPath(path);
    if (e.isXmlAttribute())
        ce.addRepresentation(PropertyRepresentation.XMLATTR);
    List<SliceHandle> myParents = new ArrayList<ProfileGenerator.SliceHandle>();
    myParents.addAll(parentSlices);
    // which holds Slicing information)
    if (e.hasDescriminator() || !Utilities.noString(e.getProfileName())) {
        if (e.getDiscriminator().size() > 0 && !slices.contains(path) && handleDiscriminator) {
            processDiscriminator(e, path, ce);
            slices.add(path);
        }
        if (!Utilities.noString(e.getProfileName())) {
            SliceHandle hnd = new SliceHandle();
            // though this it not used?
            hnd.name = path;
            myParents.add(hnd);
            if (path.contains(".")) {
                // We don't want a slice name on the root
                ce.setSliceName(e.getProfileName());
                ce.setId(ce.getId() + ":" + e.getProfileName());
            }
        }
    }
    if (e.isTranslatable()) {
        ce.addExtension(BuildExtensions.EXT_TRANSLATABLE, new BooleanType(true));
    }
    if (Utilities.existsInList(ce.getPath(), "Element.extension", "DomainResource.extension", "DomainResource.modifierExtension") && !ce.hasSlicing() && !ce.hasSliceName()) {
        ce.getSlicing().setDescription("Extensions are always sliced by (at least) url").setRules(SlicingRules.OPEN).addDiscriminator().setType(DiscriminatorType.VALUE).setPath("url");
    }
    if (!Utilities.noString(inheritedType) && snapshot != SnapShotMode.None) {
        ElementDefn inh = definitions.getElementDefn(inheritedType);
        buildDefinitionFromElement(path, ce, inh, ap, p, inheritedType, definitions.getBaseResources().containsKey(inheritedType) && definitions.getBaseResources().get(inheritedType).isInterface());
    } else if (path.contains(".") && Utilities.noString(e.typeCode()) && snapshot != SnapShotMode.None) {
        addElementConstraints(defType, ce);
    }
    buildDefinitionFromElement(path, ce, e, ap, p, null, false);
    if (!Utilities.noString(e.getStatedType())) {
        ToolingExtensions.addStringExtension(ce, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", e.getStatedType());
    }
    if (e.isNoBindingAllowed()) {
        ToolingExtensions.addBooleanExtension(ce, BuildExtensions.EXT_NO_BINDING, true);
    }
    if (!root) {
        if (e.typeCode().startsWith("@")) {
            ce.setContentReference("#" + getIdForPath(elements, e.typeCode().substring(1)));
        } else if (Utilities.existsInList(path, "Element.id", "Extension.url") || path.endsWith(".id")) {
            TypeRefComponent tr = ce.addType();
            tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (j)");
            tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
            if (path.equals("Extension.url")) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "uri");
            } else if (p.getKind() == StructureDefinitionKind.RESOURCE) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "id");
            } else {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
            }
        } else {
            List<TypeRef> expandedTypes = new ArrayList<TypeRef>();
            for (TypeRef t : e.getTypes()) {
                // Expand any Resource(A|B|C) references
                if (t.hasParams() && !Utilities.existsInList(t.getName(), "Reference", "canonical", "CodeableReference")) {
                    throw new Exception("Only resource types can specify parameters.  Path " + path + " in profile " + p.getName());
                }
                if (t.getParams().size() > 1) {
                    if (t.getProfile() != null && t.getParams().size() != 1) {
                        throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path + " in profile " + p.getName());
                    }
                    for (String param : t.getParams()) {
                        if (definitions.hasLogicalModel(param)) {
                            for (String pn : definitions.getLogicalModel(param).getImplementations()) {
                                TypeRef childType = new TypeRef(t.getName());
                                childType.getParams().add(pn);
                                childType.getAggregations().addAll(t.getAggregations());
                                expandedTypes.add(childType);
                            }
                        } else {
                            TypeRef childType = new TypeRef(t.getName());
                            childType.getParams().add(param);
                            childType.getAggregations().addAll(t.getAggregations());
                            expandedTypes.add(childType);
                        }
                    }
                } else if (t.isWildcardType()) {
                    // this list is filled out manually because it may be running before the types referred to have been loaded
                    for (String n : TypesUtilities.wildcardTypes(version.toString())) expandedTypes.add(new TypeRef(n));
                } else if (!t.getName().startsWith("=")) {
                    if (definitions.isLoaded() && (!definitions.hasResource(t.getName()) && !definitions.hasType(t.getName()) && !definitions.hasElementDefn(t.getName()) && !definitions.getBaseResources().containsKey(t.getName()) && !t.getName().equals("xhtml"))) {
                        throw new Exception("Bad Type '" + t.getName() + "' at " + path + " in profile " + p.getUrl());
                    }
                    expandedTypes.add(t);
                }
            }
            if (expandedTypes.isEmpty()) {
                if (defType != null)
                    ce.addType().setCode(defType);
            } else
                for (TypeRef t : expandedTypes) {
                    String profile = null;
                    String tc = null;
                    if (definitions.getConstraints().containsKey(t.getName())) {
                        ProfiledType pt = definitions.getConstraints().get(t.getName());
                        tc = pt.getBaseType();
                        profile = "http://hl7.org/fhir/StructureDefinition/" + pt.getName();
                    } else {
                        tc = t.getName();
                        profile = t.getProfile();
                    }
                    TypeRefComponent type = ce.getType(tc);
                    if (profile == null && t.hasParams()) {
                        profile = t.getParams().get(0);
                    }
                    if (t.getPatterns() != null) {
                        for (String s : t.getPatterns()) {
                            type.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-pattern", new CanonicalType("http://hl7.org/fhir/StructureDefinition/" + s));
                        }
                    }
                    if (profile != null) {
                        if (type.getWorkingCode().equals("Extension")) {
                            // check that the extension is being used correctly:
                            StructureDefinition ext = context.getExtensionStructure(null, profile);
                            if (ext == null) {
                                throw new Exception("Unable to resolve extension definition: " + profile);
                            }
                            boolean srcMod = ext.getSnapshot().getElement().get(0).getIsModifier();
                            boolean tgtMod = e.isModifier();
                            if (srcMod && !tgtMod)
                                throw new Exception("The extension '" + profile + "' is a modifier extension, but is being used as if it is not a modifier extension");
                            if (!srcMod && tgtMod)
                                throw new Exception("The extension '" + profile + "' is not a modifier extension, but is being used as if it is a modifier extension");
                        }
                        List<String> pr = new ArrayList<>();
                        if (profile.startsWith("http:") || profile.startsWith("#")) {
                            pr.add(profile);
                        } else if (definitions.hasLogicalModel(profile)) {
                            for (String pn : definitions.getLogicalModel(profile).getImplementations()) pr.add("http://hl7.org/fhir/StructureDefinition/" + pn);
                        } else
                            pr.add("http://hl7.org/fhir/StructureDefinition/" + (profile.equals("Any") ? "Resource" : profile));
                        if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference")) {
                            for (String pn : pr) {
                                type.addTargetProfile(pn);
                                if (e.hasHierarchy())
                                    ToolingExtensions.addBooleanExtension(type, ToolingExtensions.EXT_HIERARCHY, e.getHierarchy());
                            }
                        } else
                            for (String pn : pr) {
                                type.addProfile(pn);
                            }
                    }
                    for (String aggregation : t.getAggregations()) {
                        type.addAggregation(AggregationMode.fromCode(aggregation));
                    }
                }
        }
    }
    String w5 = translateW5(e.getW5());
    if (w5 != null)
        addMapping(p, ce, "http://hl7.org/fhir/fivews", w5, ap);
    if (e.isTranslatable())
        ce.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-translatable", new BooleanType(true));
    if (!Utilities.noString(e.getOrderMeaning()))
        ce.setOrderMeaning(e.getOrderMeaning());
    if (e.hasBinding()) {
        ce.setBinding(generateBinding(e.getBinding()));
    }
    if (snapshot != SnapShotMode.None && !e.getElements().isEmpty()) {
    // makeExtensionSlice("extension", p, c, e, path);
    // if (snapshot == SnapShotMode.Resource) {
    // makeExtensionSlice("modifierExtension", p, c, e, path);
    // if (!path.contains(".")) {
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("Resource").getRoot().getElementByName("language")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("text")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("contained")));
    // }
    // }
    }
    if (defaults)
        ce.makeBase();
    Set<String> containedSlices = new HashSet<String>();
    if (snapshot != SnapShotMode.None) {
        if (!root && Utilities.noString(e.typeCode())) {
            if (snapshot == SnapShotMode.Resource)
                defineAncestorElements("BackboneElement", path, snapshot, containedSlices, p, elements, defType, defaults);
            else
                defineAncestorElements("Element", path, snapshot, containedSlices, p, elements, defType, defaults);
        } else if (root && !Utilities.noString(e.typeCode()))
            defineAncestorElements(e.typeCode(), path, snapshot, containedSlices, p, elements, defType, defaults);
    }
    for (ElementDefn child : e.getElements()) defineElement(ap, p, elements, child, path + "." + child.getName(), containedSlices, myParents, snapshot, false, defType, null, defaults);
    return ce;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) List(java.util.List) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet)

Example 28 with ProfiledType

use of org.hl7.fhir.definitions.model.ProfiledType in project kindling by HL7.

the class ResourceDependencyGenerator method genElement.

protected Row genElement(ElementDefn e, HierarchicalTableGenerator gen, boolean resource, String path, boolean isProfile, String prefix, RenderMode mode, boolean isRoot) throws Exception {
    Row row = gen.new Row();
    row.setAnchor(path);
    // 1. Name
    Cell gc = gen.new Cell(null, dictLinks() ? pageName + "#" + path.replace("[", "_").replace("]", "_") : null, e.getName(), path + " : " + e.getDefinition(), null);
    row.getCells().add(gc);
    if (e.getStandardsStatus() != null) {
        gc.addPiece(gen.new Piece(null, " ", null));
        gc.addStyledText("Publication Status = " + e.getStandardsStatus().toDisplay(), e.getStandardsStatus().getAbbrev(), "black", e.getStandardsStatus().getColor(), prefix + "versions.html#std-process", true);
    }
    Cell dc;
    if (resource) {
        // card.
        row.getCells().add(gen.new Cell());
        row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        if (Utilities.noString(e.typeCode())) {
            row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else {
            // type
            row.getCells().add(gen.new Cell(null, prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode(), e.typeCode(), null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
        }
    } else {
        if (!e.getElements().isEmpty()) {
            // card.
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            if (mode == RenderMode.RESOURCE)
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackboneElement", null, null));
            else if (e.getName().equals("Element"))
                row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
            else
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "Element", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else if (e.getTypes().size() == 1) {
            // card.
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            String t = e.getTypes().get(0).getName();
            Cell c;
            if (t.startsWith("@")) {
                row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
                row.getCells().add(c = gen.new Cell("see ", "#" + t.substring(1), t.substring(t.lastIndexOf(".") + 1), t.substring(1), null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
            } else if (t.equals("Reference") || t.equals("canonical")) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                row.getCells().add(c = gen.new Cell());
                c.getPieces().add(gen.new Piece(prefix + "references.html", t, null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                for (String rt : e.getTypes().get(0).getParams()) {
                    if (definitions.hasLogicalModel(rt)) {
                        for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                            if (!first)
                                c.getPieces().add(gen.new Piece(null, " | ", null));
                            c.getPieces().add(gen.new Piece(prefix + findPage(rtn) + ".html", rtn, null));
                            first = false;
                        }
                    } else {
                        if (!first)
                            c.getPieces().add(gen.new Piece(null, " | ", null));
                        if (first && isProfile && e.getTypes().get(0).getProfile() != null)
                            c.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
                        else
                            c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                        first = false;
                    }
                }
                c.getPieces().add(gen.new Piece(null, ")", null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                for (String rt : e.getTypes().get(0).getParams()) if (definitions.hasLogicalModel(rt)) {
                    for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                        addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rtn);
                    }
                } else
                    addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rt);
            } else if (definitions.getPrimitives().containsKey(t)) {
                row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                row.getCells().add(c = gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), e.typeCode());
            } else {
                if (t.equals("Extension"))
                    row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION);
                else
                    row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                row.getCells().add(c = gen.new Cell(null, prefix + definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), t);
            }
        } else {
            row.getCells().add(gen.new Cell(null, null, e.describeCardinality(), null, null));
            row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
            row.getCells().add(gen.new Cell(null, null, "", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        }
    }
    if (e.hasBinding() && e.getBinding() != null && e.getBinding().getBinding() != BindingMethod.Unbound && (e.getBinding().getStrength() == BindingStrength.REQUIRED || e.getBinding().getStrength() == BindingStrength.EXTENSIBLE)) {
        addBindingToAnalysis(gen, row, dc, e.getBinding().getStrength() == BindingStrength.REQUIRED, e.getStandardsStatus(), e.getBinding());
    // if (cc.getPieces().size() == 1)
    // cc.addPiece(gen.new Piece("br"));
    // cc.getPieces().add(gen.new Piece(getBindingLink(prefix, e), e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().getName() : e.getBinding().getName(),
    // e.getBinding().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, " (", null));
    // BindingSpecification b = e.getBinding();
    // if (b.hasMax() ) {
    // cc.getPieces().add(gen.new Piece(prefix+"terminologies.html#"+b.getStrength().toCode(), b.getStrength().getDisplay(),  b.getStrength().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, " but limited to ", null));
    // ValueSet vs = b.getMaxValueSet();
    // cc.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.getName(), null));
    // }  else
    // cc.getPieces().add(gen.new Piece(prefix+"terminologies.html#"+b.getStrength().toCode(), b.getStrength().getDisplay(),  b.getStrength().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, ")", null));
    }
    if (e.getTypes().size() > 1) {
        // create a child for each choice
        for (TypeRef tr : e.getTypes()) {
            Row choicerow = gen.new Row();
            String t = tr.getName();
            if (t.equals("Reference")) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", "Reference"), null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                Cell c = gen.new Cell();
                choicerow.getCells().add(c);
                c.getPieces().add(gen.new Piece(prefix + "references.html", "Reference", null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                List<String> tt = new ArrayList<>();
                for (String rt : tr.getParams()) {
                    if (definitions.hasLogicalModel(rt))
                        tt.addAll(definitions.getLogicalModel(rt).getImplementations());
                    else
                        tt.add(rt);
                }
                Collections.sort(tt);
                for (String rt : tt) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                for (String rt : tt) addTypeToAnalysis(gen, choicerow, dc, true, e.getStandardsStatus(), rt);
            } else if (definitions.getPrimitives().containsKey(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getPrimitives().get(t).getDefinition(), null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                choicerow.getCells().add(gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } else if (definitions.getConstraints().containsKey(t)) {
                ProfiledType pt = definitions.getConstraints().get(t);
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(pt.getBaseType())), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } else {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            }
            row.getSubRows().add(choicerow);
        }
    } else
        for (ElementDefn c : e.getElements()) row.getSubRows().add(genElement(c, gen, false, path + '.' + c.getName(), isProfile, prefix, mode, false));
    return row;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 29 with ProfiledType

use of org.hl7.fhir.definitions.model.ProfiledType in project kindling by HL7.

the class TableGenerator method genElement.

protected Row genElement(ElementDefn e, HierarchicalTableGenerator gen, boolean resource, String path, boolean isProfile, String prefix, RenderMode mode, boolean isRoot, StandardsStatus rootStatus, boolean isAbstract, boolean isInterface) throws Exception {
    Row row = gen.new Row();
    row.setAnchor(path);
    boolean isProfiledExtension = isProfile && (e.getName().equals("extension") || e.getName().equals("modifierExtension"));
    row.getCells().add(gen.new Cell(null, dictLinks() ? pageName + "#" + path.replace("[", "_").replace("]", "_") : null, e.getName(), path + " : " + e.getDefinition(), null));
    Cell gc = gen.new Cell();
    row.getCells().add(gc);
    if (e.hasMustSupport() && e.isMustSupport()) {
        gc.addStyledText("This element must be supported", "S", "white", "red", prefix + "conformance-rules.html#mustSupport", false);
    }
    if (e.isModifier()) {
        gc.addStyledText("This element is a modifier element", "?!", null, null, prefix + "conformance-rules.html#isModifier", false);
    }
    if (e.isSummary()) {
        gc.addStyledText("This element is included in summaries", "\u03A3", null, null, prefix + "elementdefinition-definitions.html#ElementDefinition.isSummary", false);
    }
    if (!isRoot && (!e.getInvariants().isEmpty() || !e.getStatedInvariants().isEmpty())) {
        gc.addStyledText("This element has or is affected by some invariants", "I", null, null, prefix + "conformance-rules.html#constraints", false);
    }
    if (isInterface) {
        gc.addStyledText("This is an abstract type", "«A»", null, null, prefix + "uml.html#abstract", false);
    } else if (isAbstract) {
        gc.addStyledText("This is an interface resource", "«I»", null, null, prefix + "uml.html#interface", false);
    }
    if (rootStatus != null)
        gc.addStyledText("Standards Status = " + rootStatus.toDisplay(), rootStatus.getAbbrev(), "black", rootStatus.getColor(), prefix + "versions.html#std-process", true);
    else if (e.getStandardsStatus() != null)
        gc.addStyledText("Standards Status = " + e.getStandardsStatus().toDisplay(), e.getStandardsStatus().getAbbrev(), "black", e.getStandardsStatus().getColor(), prefix + "versions.html#std-process", true);
    if (resource) {
        row.getCells().add(gen.new Cell());
        row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        if (Utilities.noString(e.typeCode()))
            row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
        else if ("Logical".equals(e.typeCode()))
            row.getCells().add(gen.new Cell(null, prefix + "structuredefinition.html#logical", e.typeCode(), null, null));
        else if ("Base".equals(e.typeCode()))
            row.getCells().add(gen.new Cell(null, prefix + definitions.getSrcFile("Base") + ".html#" + e.typeCode(), e.typeCode(), null, null));
        else
            row.getCells().add(gen.new Cell(null, prefix + e.typeCode().toLowerCase() + ".html", e.typeCode(), null, null));
    // todo: base elements
    } else {
        if (!e.getElements().isEmpty()) {
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            if (mode == RenderMode.RESOURCE)
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackboneElement", null, null));
            else if (e.getName().equals("Type"))
                row.getCells().add(gen.new Cell(null, null, "", null, null));
            else if (e.getName().equals("Element")) {
                if (version.isR4B()) {
                    row.getCells().add(gen.new Cell(null, prefix + definitions.getElementLink(), "Element", null, null));
                } else {
                    row.getCells().add(gen.new Cell(null, prefix + definitions.getBaseLink(), "Base", null, null));
                }
            } else if (e.typeCode().equals("BackboneElement"))
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackBoneElement", null, null));
            else
                row.getCells().add(gen.new Cell(null, prefix + definitions.getElementLink(), "Element", null, null));
        } else if (e.getTypes().size() == 1) {
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            String t = e.getTypes().get(0).getName();
            Cell c;
            if (t.startsWith("@")) {
                row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
                c = gen.new Cell("see ", "#" + t.substring(1), t.substring(t.lastIndexOf(".") + 1), t.substring(1), null);
            } else if (isReference(t)) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                c = gen.new Cell();
                if (ADD_REFERENCE_TO_TABLE) {
                    c.getPieces().add(gen.new Piece(prefix + definitions.getSrcFile(t) + ".html#" + t, t, null));
                    c.getPieces().add(gen.new Piece(null, "(", null));
                }
                boolean first = true;
                for (String rt : e.getTypes().get(0).getParams()) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    if (first && isProfile && e.getTypes().get(0).getProfile() != null)
                        c.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
                    else
                        c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                if (ADD_REFERENCE_TO_TABLE)
                    c.getPieces().add(gen.new Piece(null, ")", null));
            } else if (definitions.getPrimitives().containsKey(t)) {
                row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                c = gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null);
            } else {
                if (t.equals("Extension"))
                    row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION);
                else
                    row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                c = gen.new Cell(null, prefix + definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null);
            }
            row.getCells().add(c);
        } else {
            row.getCells().add(gen.new Cell(null, null, isRoot ? "" : e.describeCardinality(), null, null));
            row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
            row.getCells().add(gen.new Cell(null, null, "", null, null));
        }
    }
    Cell cc = gen.new Cell(null, e.getShortDefn() != null && Utilities.isURL(e.getShortDefn()) ? e.getShortDefn() : null, e.getShortDefn(), null, null);
    row.getCells().add(cc);
    // constraints
    if (isProfiledExtension) {
        cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
    }
    if (e.hasBinding() && e.getBinding() != null && e.getBinding().getBinding() != BindingMethod.Unbound) {
        if (cc.getPieces().size() == 1)
            cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(getBindingLink(prefix, e), e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().present() : e.getBinding().getName(), e.getBinding().getDefinition()));
        cc.getPieces().add(gen.new Piece(null, " (", null));
        BindingSpecification b = e.getBinding();
        if (b.hasMax()) {
            cc.getPieces().add(gen.new Piece(prefix + "terminologies.html#" + b.getStrength().toCode(), b.getStrength().getDisplay(), b.getStrength().getDefinition()));
            cc.getPieces().add(gen.new Piece(null, " but limited to ", null));
            ValueSet vs = b.getMaxValueSet();
            if (vs == null)
                cc.getPieces().add(gen.new Piece(b.getMaxReference(), b.getMaxReference(), null));
            else
                cc.getPieces().add(gen.new Piece(vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path"), vs.getName(), null));
        } else
            cc.getPieces().add(gen.new Piece(prefix + "terminologies.html#" + b.getStrength().toCode(), b.getStrength().getDisplay(), b.getStrength().getDefinition()));
        cc.getPieces().add(gen.new Piece(null, ")", null));
    }
    List<String> invs = new ArrayList<String>(e.getInvariants().keySet());
    Collections.sort(invs, new ConstraintsSorter());
    for (String name : invs) {
        Invariant inv = e.getInvariants().get(name);
        cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, "+ " + presentLevel(inv) + ": " + inv.getEnglish(), inv.getId()).setStyle("font-style: italic"));
    }
    if (e.unbounded() && !isRoot) {
        if (cc.getPieces().size() > 0)
            cc.addPiece(gen.new Piece("br"));
        if (Utilities.noString(e.getOrderMeaning())) {
        // don't show this, this it's important: cc.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
        } else {
            cc.getPieces().add(gen.new Piece(null, "This repeating element order: " + e.getOrderMeaning(), null));
        }
    }
    if (isRoot && !Utilities.noString(e.typeCode()) && !"Logical".equals(e.typeCode())) {
        List<ElementDefn> ancestors = new ArrayList<ElementDefn>();
        ElementDefn f = definitions.getElementDefn(e.typeCode());
        while (f != null) {
            ancestors.add(0, f);
            f = Utilities.noString(f.typeCode()) || "Logical".equals(f.typeCode()) ? null : definitions.getElementDefn(f.typeCode());
        }
        cc.getPieces().add(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, "Elements defined in Ancestors: ", null));
        boolean first = true;
        for (ElementDefn fi : ancestors) {
            for (ElementDefn fc : fi.getElements()) {
                if (first)
                    first = false;
                else
                    cc.getPieces().add(gen.new Piece(null, ", ", null));
                cc.getPieces().add(gen.new Piece(definitions.getSrcFile(fi.getName()) + ".html#" + fi.getName(), fc.getName(), fc.getDefinition()));
            }
        }
    }
    if (mode == RenderMode.LOGICAL) {
        String logical = e.getMappings().get("http://hl7.org/fhir/logical");
        Cell c = gen.new Cell();
        row.getCells().add(c);
        if (logical != null)
            presentLogicalMapping(gen, c, logical, prefix);
    }
    if (e.getTypes().size() > 1) {
        // create a child for each choice
        for (TypeRef tr : e.getTypes()) {
            Row choicerow = gen.new Row();
            String t = tr.getName();
            if (isReference(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                Cell c = gen.new Cell();
                choicerow.getCells().add(c);
                if (ADD_REFERENCE_TO_TABLE) {
                    if (tr.getName().equals("canonical"))
                        c.getPieces().add(gen.new Piece(prefix + "datatypes.html#canonical", "canonical", null));
                    else
                        c.getPieces().add(gen.new Piece(prefix + "references.html#Reference", "Reference", null));
                    c.getPieces().add(gen.new Piece(null, "(", null));
                }
                boolean first = true;
                for (String rt : tr.getParams()) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                if (ADD_REFERENCE_TO_TABLE)
                    c.getPieces().add(gen.new Piece(null, ")", null));
            } else if (definitions.getPrimitives().containsKey(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getPrimitives().get(t).getDefinition(), null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                choicerow.getCells().add(gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
            } else if (definitions.getConstraints().containsKey(t)) {
                ProfiledType pt = definitions.getConstraints().get(t);
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(pt.getBaseType())), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
            } else {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
            }
            choicerow.getCells().add(gen.new Cell());
            // choicerow.getCells().add(gen.new Cell());
            row.getSubRows().add(choicerow);
        }
    } else
        for (ElementDefn c : e.getElements()) {
            row.getSubRows().add(genElement(c, gen, false, path + '.' + c.getName(), isProfile, prefix, mode, false, null, false, false));
        }
    return row;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 30 with ProfiledType

use of org.hl7.fhir.definitions.model.ProfiledType in project kindling by HL7.

the class JsonSpecGenerator method writeTypeLinks.

/*
  private String docPrefix(int widthSoFar, int indent, ElementDefinition elem) {
    if (widthSoFar + (elem.getShort() == null ? 0 : elem.getShort().length())+8+elem.getPath().length() > 105) {
      String ret = "\r\n  ";
      for (int i = 0; i < indent+2; i++)
        ret = ret + " ";

      return ret;
    }
    else
      return "";
  }
  */
private int writeTypeLinks(ElementDefn elem, int indent, TypeRef t) throws Exception {
    write(" <span style=\"color: darkgreen\">");
    int i = 0;
    // this is wrong if the type is an attribute, but the wrapping concern shouldn't apply in this case, so this is ok
    int w = indent + 12 + elem.getName().length();
    // for (TypeRef t : elem.getTypes()) {
    if (i > 0) {
        write("|");
        w++;
    }
    if (w + t.getName().length() > 80) {
        throw new Error("this sholdn't happen");
    // write("\r\n  ");
    // for (int j = 0; j < indent; j++)
    // write(" ");
    // w = indent+2;
    }
    // again, could be wrong if this is an extension, but then it won't wrap
    w = w + t.getName().length();
    if (t.isXhtml() || t.getName().equals("list"))
        write(t.getName());
    else if (t.getName().equals("Extension") && t.getParams().size() == 0 && !Utilities.noString(t.getProfile()))
        write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
    else if (definitions.getConstraints().containsKey(t.getName())) {
        ProfiledType pt = definitions.getConstraints().get(t.getName());
        write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
        w = w + pt.getBaseType().length() + 2;
        write("(<a style=\"color:navy\" href=\"" + prefix + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
    } else
        write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
    if (t.hasParams()) {
        write("(");
        boolean firstp = true;
        List<String> ap = new ArrayList<>();
        for (String p : t.getParams()) {
            if (definitions.hasLogicalModel(p))
                ap.addAll(definitions.getLogicalModel(p).getImplementations());
            else
                ap.add(p);
        }
        Collections.sort(ap);
        for (String p : ap) {
            if (!firstp) {
                write("|");
                w++;
            }
            // again, p.length() could be wrong if this is an extension, but then it won't wrap
            if (w + p.length() > 80) {
                write("\r\n  ");
                for (int j = 0; j < indent; j++) write(" ");
                w = indent + 2;
            }
            w = w + p.length();
            // TODO: Display action and/or profile information
            if (p.equals("Any")) {
                write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
            } else if (isReference(t.getName()) && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
                write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
            else
                write("<a href=\"" + prefix + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
            firstp = false;
        }
        write(")");
        w++;
    }
    i++;
    // }
    write("</span>");
    return w;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) ArrayList(java.util.ArrayList)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)19 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)14 ArrayList (java.util.ArrayList)11 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)9 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 TypeRef (org.hl7.fhir.definitions.model.TypeRef)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 IOException (java.io.IOException)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 URISyntaxException (java.net.URISyntaxException)4 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4b.model.TypeDetails.ProfiledType)4 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)4 ProfiledType (org.hl7.fhir.r5.model.TypeDetails.ProfiledType)4 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 List (java.util.List)3 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)3