Search in sources :

Example 56 with Element

use of org.hl7.fhir.r4b.model.Element in project kindling by HL7.

the class ProfileGenerator method produceOpParam.

private void produceOpParam(String path, List<OperationDefinitionParameterComponent> opd, OperationParameter p, OperationParameterUse defUse) throws Exception {
    OperationDefinitionParameterComponent pp = new OperationDefinitionParameterComponent();
    pp.setName(p.getName());
    if (path.contains("."))
        pp.setUse(defUse);
    else if (p.getUse().equals("in"))
        pp.setUse(OperationParameterUse.IN);
    else if (p.getUse().equals("out"))
        pp.setUse(OperationParameterUse.OUT);
    else
        // but this is validated elsewhere
        throw new Exception("Unable to determine parameter use: " + p.getUse() + " at " + path + "." + p.getName());
    pp.setDocumentation(preProcessMarkdown(p.getDoc(), "Operation Parameter Doco"));
    pp.setMin(p.getMin());
    pp.setMax(p.getMax());
    if (p.getBs() != null) {
        if (p.getBs().hasMax())
            throw new Error("Max binding not handled yet");
        pp.setBinding(new OperationDefinitionParameterBindingComponent().setStrength(p.getBs().getStrength()).setValueSet(buildValueSetReference(p.getBs())));
        if (!Utilities.noString(p.getBinding().getName())) {
            pp.getBinding().addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", new StringType(p.getBinding().getName()));
        }
    }
    if (!Utilities.noString(p.getProfile())) {
        pp.addTargetProfile(p.getProfile());
    }
    opd.add(pp);
    if (p.getFhirType().equals("Tuple")) {
        for (OperationParameter part : p.getParts()) {
            produceOpParam(path + "." + p.getName(), pp.getPart(), part, pp.getUse());
        }
    } else {
        List<TypeRef> trs = new TypeParser(version.toCode()).parse(p.getFhirType(), false, null, null, false);
        if (trs.size() > 1) {
            if (p.getSearchType() != null)
                pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
            pp.setType(Enumerations.FHIRAllTypes.fromCode("Element"));
            for (TypeRef tr : trs) {
                pp.addExtension(ToolingExtensions.EXT_ALLOWED_TYPE, new UriType(tr.getName()));
                if (tr.getParams().size() > 0)
                    throw new Error("Multiple types for an operation parameter, where one is a reference, is not supported by the build tools");
            }
        } else {
            TypeRef tr = trs.get(0);
            if (definitions.getConstraints().containsKey(tr.getName())) {
                ProfiledType pt = definitions.getConstraints().get(tr.getName());
                pp.setType(Enumerations.FHIRAllTypes.fromCode(pt.getBaseType().equals("*") ? "Type" : pt.getBaseType()));
                pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
            } else {
                if (p.getSearchType() != null)
                    pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
                pp.setType(Enumerations.FHIRAllTypes.fromCode(tr.getName().equals("*") ? "Type" : tr.getName()));
                if (tr.getParams().size() == 1 && !tr.getParams().get(0).equals("Any"))
                    pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + tr.getParams().get(0));
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) StringType(org.hl7.fhir.r5.model.StringType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) OperationDefinitionParameterBindingComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent) UriType(org.hl7.fhir.r5.model.UriType)

Example 57 with Element

use of org.hl7.fhir.r4b.model.Element in project kindling by HL7.

the class DictHTMLGenerator method invariants.

// 
// 
// for (String id : ids) {
// ElementDefinitionConstraintComponent inv = getConstraint(constraints, id);
// s.append("<tr><td><b title=\"Formal Invariant Identifier\">"+inv.getId()+"</b></td><td>"+presentLevel(inv)+"</td><td>(base)</td><td>"+Utilities.escapeXml(inv.getHuman())+"</td><td><span style=\"font-family: Courier New, monospace\">"+Utilities.escapeXml(inv.getExpression())+"</span>");
// if (inv.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice"))
// s.append("<br/>This is (only) a best practice guideline because: <blockquote>"+page.processMarkdown("best practice guideline", inv.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice-explanation"), prefix)+"</blockquote>");
// s.append("</td></tr>");
// }
// }
private String invariants(Map<String, Invariant> invariants, List<Invariant> stated) throws Exception {
    List<String> done = new ArrayList<String>();
    StringBuilder s = new StringBuilder();
    if (invariants.size() + stated.size() > 0) {
        s.append("<table class=\"dict\">\r\n");
        if (invariants.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Defined on this element</b></td></tr>\r\n");
            List<String> ids = new ArrayList<String>();
            for (String id : invariants.keySet()) ids.add(id);
            Collections.sort(ids, new ConstraintsSorter());
            for (String i : ids) {
                Invariant inv = invariants.get(i);
                done.add(inv.getId());
                s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>");
                if (!Utilities.noString(inv.getExplanation()))
                    s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>");
                s.append("</td></tr>");
            }
        }
        if (stated.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Affect this element</b></td></tr>\r\n");
            boolean b = false;
            for (Invariant id : stated) {
                if (!done.contains(id.getId())) {
                    s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + id.getId() + "</b></td><td>" + presentLevel(id) + "</td><td>" + Utilities.escapeXml(id.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(id.getExpression()) + "</span>");
                    if (!Utilities.noString(id.getExplanation()))
                        s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", id.getExplanation(), prefix) + "</blockquote>");
                    s.append("</td></tr>");
                }
            }
        }
        s.append("</table>\r\n");
    }
    return s.toString();
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList)

Example 58 with Element

use of org.hl7.fhir.r4b.model.Element in project kindling by HL7.

the class DictHTMLGenerator method describeType.

private String describeType(ElementDefn e) throws Exception {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    if (e.typeCode().startsWith("@")) {
        b.append("<a href=\"#" + e.typeCode().substring(1) + "\">See " + e.typeCode().substring(1) + "</a>");
    } else {
        for (TypeRef t : e.getTypes()) {
            if (!first)
                b.append("|");
            String tn = t.getName();
            if (tn.equals("Type"))
                tn = "Element";
            if (tn.equals("*"))
                b.append("<a href=\"" + prefix + "datatypes.html#open\">*</a>");
            else
                b.append("<a href=\"" + prefix + typeLink(tn) + "\">" + tn + "</a>");
            if (t.hasParams()) {
                b.append("(");
                boolean firstp = true;
                for (String p : t.getParams()) {
                    if (!firstp)
                        b.append(" | ");
                    firstp = false;
                    if (definitions.hasLogicalModel(p)) {
                        b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>[");
                        boolean firstpn = true;
                        for (String pn : definitions.getLogicalModel(p).getImplementations()) {
                            if (!firstpn)
                                b.append(", ");
                            firstpn = false;
                            b.append("<a href=\"" + prefix + typeLink(pn) + "\">" + pn + "</a>");
                        }
                        b.append("]");
                    } else {
                        b.append("<a href=\"" + prefix + typeLink(p) + "\">" + p + "</a>");
                    }
                }
                b.append(")");
            }
            first = false;
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Example 59 with Element

use of org.hl7.fhir.r4b.model.Element in project kindling by HL7.

the class DictHTMLGenerator method generateSlicing.

private void generateSlicing(StructureDefinition profile, ElementDefinitionSlicingComponent slicing) throws IOException {
    StringBuilder b = new StringBuilder();
    if (slicing.getOrdered())
        b.append("<li>ordered</li>");
    else
        b.append("<li>unordered</li>");
    if (slicing.hasRules())
        b.append("<li>" + slicing.getRules().getDisplay() + "</li>");
    if (!slicing.getDiscriminator().isEmpty()) {
        b.append("<li>discriminators: ");
        boolean first = true;
        for (ElementDefinitionSlicingDiscriminatorComponent s : slicing.getDiscriminator()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append(s.getType().toCode() + ":" + s.getPath());
        }
        b.append("</li>");
    }
    tableRowNE("Slicing", "profiling.html#slicing", "This element introduces a set of slices. The slicing rules are: <ul> " + b.toString() + "</ul>");
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 60 with Element

use of org.hl7.fhir.r4b.model.Element in project kindling by HL7.

the class FhirTurtleGenerator method processTypes.

private void processTypes(String baseResourceName, FHIRResource baseResource, ElementDefn td, String predicateBase, boolean innerIsBackbone) throws Exception {
    for (ElementDefn ed : td.getElements()) {
        String predicateName = predicateBase + "." + (ed.getName().endsWith("[x]") ? ed.getName().substring(0, ed.getName().length() - 3) : ed.getName());
        FHIRResource predicateResource;
        if (ed.getName().endsWith("[x]")) {
            predicateResource = fact.fhir_objectProperty(predicateName);
            // Choice entry
            if (ed.typeCode().equals("*")) {
                // Wild card -- any element works (probably should be more restrictive but...)
                Resource targetResource = RDFNamespace.FHIR.resourceRef("Element");
                baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, targetResource, ed.getMinCardinality(), ed.getMaxCardinality()));
                predicateResource.domain(baseResource);
                predicateResource.range(targetResource);
            } else {
                // Create a restriction on the union of possible types
                List<Resource> typeOpts = new ArrayList<Resource>();
                for (TypeRef tr : ed.getTypes()) {
                    // TODO: Figure out how to get the type reference code
                    String trName = tr.getName();
                    if (trName.equals("SimpleQuantity"))
                        trName = "Quantity";
                    String qualifiedPredicateName = predicateName + Utilities.capitalize(trName);
                    Resource targetRes = fact.fhir_class(tr.getName()).resource;
                    FHIRResource qualifiedPredicate = fact.fhir_objectProperty(qualifiedPredicateName, predicateResource.resource).domain(baseResource).range(targetRes);
                    typeOpts.add(fact.fhir_cardinality_restriction(qualifiedPredicate.resource, targetRes, ed.getMinCardinality(), ed.getMaxCardinality()));
                }
                baseResource.restriction(fact.fhir_union(typeOpts));
            }
        } else {
            FHIRResource baseDef;
            if (ed.getTypes().isEmpty()) {
                predicateResource = fact.fhir_objectProperty(predicateName);
                String targetClassName = mapComponentName(baseResourceName, ed.getDeclaredTypeName());
                baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition());
                processTypes(targetClassName, baseDef, ed, predicateName, innerIsBackbone);
            } else {
                TypeRef targetType = ed.getTypes().get(0);
                String targetName = targetType.getName();
                if (targetName.startsWith("@")) {
                    // Link to earlier definition
                    ElementDefn targetRef = getElementForPath(targetName.substring(1));
                    String targetRefName = targetRef.getName();
                    String targetClassName = baseResourceName + Character.toUpperCase(targetRefName.charAt(0)) + targetRefName.substring(1);
                    baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition()).addTitle(ed.getShortDefn());
                    if (!processing.contains(targetRefName)) {
                        processing.add(targetRefName);
                        processTypes(targetClassName, baseDef, targetRef, predicateName, innerIsBackbone);
                        processing.remove(targetRefName);
                    }
                } else {
                    // A placeholder entry.  The rest of the information will be supplied elsewhere
                    baseDef = fact.fhir_class(targetName);
                }
                // XHTML the exception, in that the html doesn't derive from Primitive
                if (targetName.equals("xhtml"))
                    predicateResource = fact.fhir_dataProperty(predicateName);
                else
                    predicateResource = fact.fhir_objectProperty(predicateName);
            }
            predicateResource.addTitle(ed.getShortDefn()).addDefinition(ed.getDefinition()).domain(baseResource);
            baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, baseDef.resource, ed.getMinCardinality(), ed.getMaxCardinality()));
            predicateResource.range(baseDef.resource);
            if (!Utilities.noString(ed.getW5()))
                predicateResource.addObjectProperty(RDFS.subPropertyOf, RDFNamespace.W5.resourceRef(ed.getW5()));
        }
    }
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) Resource(org.apache.jena.rdf.model.Resource) FHIRResource(org.hl7.fhir.rdf.FHIRResource) ArrayList(java.util.ArrayList)

Aggregations

Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)659 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)488 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)486 ArrayList (java.util.ArrayList)240 FHIRException (org.hl7.fhir.exceptions.FHIRException)162 Element (org.hl7.fhir.r5.elementmodel.Element)98 IOException (java.io.IOException)97 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)91 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)84 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)84 Element (org.w3c.dom.Element)74 JsonElement (com.google.gson.JsonElement)62 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)61 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)60 HashSet (java.util.HashSet)53 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)49 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)48 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)47 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)46 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)43