Search in sources :

Example 46 with Reference

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

the class SpreadSheetReloader method parseType.

private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
    ed.getType().clear();
    ed.setContentReferenceElement(null);
    if (ed.getPath().equals("Resource.id")) {
        ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
    } else {
        if (Utilities.noString(value)) {
            if (ed.getPath().contains(".")) {
                ed.addType().setCode("BackboneElement");
            }
        } else if (value.startsWith("#")) {
            ed.setContentReference(value);
        } else {
            List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
            for (TypeRef tr : tl) {
                TypeRefComponent t = ed.addType().setCode(tr.getName());
                if ("SimpleQuantity".equals(t.getCode())) {
                    t.setCode("Quantity");
                    t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
                }
                for (String p : tr.getParams()) {
                    if (p.equals("Definition")) {
                        t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
                    } else {
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    }
                }
                if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
                    t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
                }
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) BooleanType(org.hl7.fhir.r5.model.BooleanType) List(java.util.List) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) UriType(org.hl7.fhir.r5.model.UriType)

Example 47 with Reference

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

the class PatternFinder method sortRefs.

private String sortRefs(ElementDefn focus) {
    List<String> s = new ArrayList<>();
    for (TypeRef t : focus.getTypes()) {
        if ("Reference".equals(t.getName())) {
            for (String p : t.getParams()) {
                if (definitions.hasLogicalModel(p))
                    s.addAll(definitions.getLogicalModel(p).getImplementations());
                else
                    s.add(p);
            }
        }
    }
    Collections.sort(s);
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (String n : s) b.append(n);
    return b.toString();
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 48 with Reference

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

the class SvgGenerator method drawClass.

private ClassItem drawClass(XMLWriter xml, ElementDefn e, boolean isRoot, ResourceDefn resource, boolean link, String path, DefinedCode primitive, StandardsStatus status) throws Exception {
    ClassItem item = classes.get(e);
    String tn = e.getName();
    if (!definitions.hasPrimitiveType(tn) && !tn.equals("xhtml")) {
        tn = Utilities.capitalize(tn);
    }
    ResourceDefn r = definitions.hasResource(tn) ? definitions.getResourceByName(tn) : null;
    if (r == null) {
        r = definitions.getBaseResources().get(tn);
    }
    xml.attribute("id", "n" + (++nc));
    xml.enter("g");
    xml.attribute("x", Double.toString(item.left));
    xml.attribute("y", Double.toString(item.top));
    xml.attribute("rx", "4");
    xml.attribute("ry", "4");
    xml.attribute("width", Double.toString(item.width));
    xml.attribute("height", Double.toString(item.height));
    xml.attribute("filter", "url(#shadow" + id + ")");
    if (r != null) {
        xml.attribute("style", "fill:" + r.getStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = r.getStatus();
    } else if (e == null || e.getStandardsStatus() == null)
        xml.attribute("style", "fill:" + (status == null ? "#ffffff" : status.getColorSvg()) + ";stroke:black;stroke-width:1");
    else {
        xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = e.getStandardsStatus();
    }
    if (!makeTargets)
        xml.attribute("id", "n" + (++nc));
    else
        xml.attribute("id", item.getId());
    xml.element("rect", null);
    xml.attribute("x1", Double.toString(item.left));
    xml.attribute("y1", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("x2", Double.toString(item.left + item.width));
    xml.attribute("y2", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("style", "stroke:dimgrey;stroke-width:1");
    xml.attribute("id", "n" + (++nc));
    xml.element("line", null);
    xml.attribute("x", Double.toString(item.left + item.width / 2));
    xml.attribute("y", Double.toString(item.top + HEADER_HEIGHT));
    xml.attribute("fill", "black");
    if (isRoot)
        xml.attribute("class", "diagram-class-title  diagram-class-resource");
    else
        xml.attribute("class", "diagram-class-title");
    if (link) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.attribute("xlink:href", makeRel(definitions.getSrcFile(tn) + ".html#" + tn));
        xml.attribute("id", "n" + (++nc));
        xml.enter("a");
        xml.text(tn);
        xml.exit("a");
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (isRoot) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.text(tn);
        if (Utilities.noString(e.typeCode())) {
            xml.text(" \u00ABResource\u00BB");
        } else {
            xml.attribute("class", "diagram-class-title-link");
            xml.enter("tspan");
            xml.text(" (");
            if ("Logical".equals(e.typeCode()))
                xml.attribute("xlink:href", prefix + definitions.getBaseLink());
            else
                xml.attribute("xlink:href", prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode());
            xml.attribute("class", "diagram-class-reference");
            xml.attribute("id", "n" + (++nc));
            xml.attribute("style", "font-style: italic");
            if ("Logical".equals(e.typeCode())) {
                xml.element("a", "Base");
            } else {
                xml.element("a", e.typeCode());
            }
            xml.text(")");
            xml.exit("tspan");
        }
        if ("Logical".equals(e.typeCode())) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#pattern"));
            xml.enter("a");
            xml.text("«Pattern»");
            xml.exit("a");
        }
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (e.hasStatedType()) {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", e.getStatedType());
    } else {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", tn);
    }
    if (attributes) {
        if (primitive != null) {
            if (primitive instanceof PrimitiveType)
                addValueAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT, getXsi(primitive).split("\\|"));
        } else {
            int i = 0;
            for (ElementDefn c : e.getElements()) {
                if (isAttribute(c)) {
                    i++;
                    addAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i, c, path, LINE_HEIGHT, item.width);
                    String[] texts = textForAttribute(c);
                    i = i + texts.length - 1;
                }
            }
        }
    }
    xml.exit("g");
    if (attributes) {
        for (ElementDefn c : e.getElements()) {
            if (!isAttribute(c)) {
                if (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@")) {
                    links.add(new Link(item, drawClass(xml, c, false, resource, false, path + "." + c.getName(), null, status), LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                } else {
                    ClassItem target = getItemForPath(resource, c.typeCode().substring(1));
                    links.add(new Link(item, target, LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                }
            }
        }
    }
    return item;
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 49 with Reference

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

the class TerminologyNotesGenerator method describeBinding.

public static String describeBinding(String prefix, ElementDefinitionBindingComponent def, PageProcessor page) throws Exception {
    if (!def.hasValueSet())
        return def.getDescription();
    String ref = def.getValueSet();
    ValueSet vs = page.getValueSets().get(ref);
    if (vs != null) {
        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
        return def.getDescription() + "<br/>" + conf(def) + "<a href=\"" + (Utilities.isAbsoluteUrl(pp) ? "" : prefix) + pp.replace(File.separatorChar, '/') + "\">" + vs.present() + "</a>" + confTail(def);
    }
    if (ref.startsWith("http:") || ref.startsWith("https:"))
        return def.getDescription() + "<br/>" + conf(def) + " <a href=\"" + ref + "\">" + ref + "</a>" + confTail(def);
    else
        return def.getDescription() + "<br/>" + conf(def) + " ?? Broken Reference to " + ref + " ??" + confTail(def);
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 50 with Reference

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

the class TerminologyNotesGenerator method gen.

private void gen(String prefix, Map<BindingSpecification, List<CDUsage>> txusages2) throws Exception {
    List<BindingSpecification> cds = new ArrayList<BindingSpecification>();
    cds.addAll(txusages.keySet());
    if (cds.size() == 0)
        return;
    Collections.sort(cds, new MyCompare());
    if (noHeader)
        write("<p>\r\n<b>Terminology Bindings</b>\r\n</p>\r\n");
    else
        write("<h3>\r\nTerminology Bindings\r\n</h3>\r\n");
    // 1. new form
    write("<table class=\"grid\">\r\n");
    write(" <tr><th>Path</th><th>Definition</th><th>Type</th><th>Reference</th></tr>\r\n");
    for (BindingSpecification cd : cds) {
        String path;
        List<CDUsage> list = txusages.get(cd);
        for (int i = 2; i < list.size(); i++) {
            if (!matchesTypes(list.get(i).element.typeCodeNoParams(), list.get(1).element.typeCodeNoParams()))
                throw new Exception("Mixed types on one concept domain in one type - not yet supported by the build process for binding " + cd.getName() + " (" + list.get(i).element.typeCode() + " vs " + list.get(1).element.typeCode() + ")");
        }
        String name = cd.getValueSet() != null ? cd.getValueSet().present() : cd.getName();
        write(" <tr><td valign=\"top\" title=\"" + name + "\">");
        boolean first = true;
        for (int i = 1; i < list.size(); i++) {
            if (!first)
                write("<br/>");
            first = false;
            write(list.get(i).path);
        }
        write(" </td>");
        write("<td valign=\"top\">" + Utilities.escapeXml(cd.getDefinition()) + "</td>");
        if (cd.getBinding() == BindingMethod.Unbound)
            write("<td>Unknown</td><td valign=\"top\">No details provided yet</td>");
        else {
            if (cd.hasMax()) {
                ValueSet vs = cd.getMaxValueSet();
                if (vs == null) {
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + cd.getMaxReference() + "\">" + cd.getMaxReference() + "</a></td>");
                } else {
                    String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a></td>");
                }
            } else
                write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a></td>");
            write("<td valign=\"top\">");
            if (cd.getBinding() == BindingSpecification.BindingMethod.Special) {
                if (name.equals("MessageEvent"))
                    write("<a href=\"" + prefix + "valueset-message-events.html\">Message Events</a>");
                else if (name.equals("ResourceType"))
                    write("<a href=\"" + prefix + "valueset-resource-types.html\">Resource Types</a>");
                else if (name.equals("DataType"))
                    write("<a href=\"" + prefix + "valueset-data-types.html\">Data Types</a>");
                else if (name.equals("FHIRDefinedType"))
                    write("<a href=\"" + prefix + "valueset-defined-types.html\">Defined Types</a>");
                else if (name.equals("FHIRAllTypes"))
                    write("<a href=\"" + prefix + "valueset-all-types.html\">All Types</a>");
                else
                    throw new Exception("Unknown special type " + name);
            } else if (cd.getValueSet() != null) {
                ValueSet vs = cd.getValueSet();
                String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                if (pp == null)
                    throw new Exception("unknown path on " + cd.getReference());
                write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a><!-- b -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.ValueSet) {
                if (Utilities.noString(cd.getReference()))
                    write("??");
                else if (cd.getReference().startsWith("valueset-"))
                    write("<a href=\"" + prefix + cd.getReference() + ".html\">http://hl7.org/fhir/ValueSet/" + cd.getReference().substring(9) + "</a><!-- a -->");
                else if (cd.getReference().startsWith("http://hl7.org/fhir")) {
                    if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v3-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        if (pp == null)
                            throw new Exception("unknown path on " + cd.getReference());
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- b -->");
                    } else if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- c -->");
                    } else if (cd.getReference().startsWith("http://hl7.org/fhir/ValueSet/")) {
                        String ref = getBindingLink(cd);
                        write("<a href=\"" + prefix + ref + "\">" + cd.getReference() + "</a><!-- d -->");
                    // BindingSpecification bs1 = page.getDefinitions().getBindingByURL(cd.getReference());
                    // if (bs1 != null)
                    // write("<a href=\""+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    // else
                    // write("<a href=\"valueset-"+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    } else
                        throw new Exception("Internal reference " + cd.getReference() + " not handled yet");
                } else if (cd.getReference().startsWith("http:"))
                    write("<a href=\"" + cd.getReference() + "\">" + cd.getReference() + "</a><!-- e -->");
                else
                    write("<a href=\"" + prefix + "valueset-" + cd.getReference() + ".html\">http://hl7.org/fhir/" + cd.getReference() + "</a><!-- e -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.CodeList) {
                write("<a href=\"" + prefix + "valueset-" + cd.getReference().substring(1) + ".html\">http://hl7.org/fhir/" + cd.getReference().substring(1) + "</a><!-- f -->");
            }
            write("</td>");
        }
        write(" </tr>\r\n");
    }
    write("</table>\r\n<p> </p>\r\n");
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Reference (org.hl7.fhir.r4.model.Reference)363 Test (org.junit.Test)251 ArrayList (java.util.ArrayList)190 Reference (org.hl7.fhir.dstu3.model.Reference)156 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)91 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)85 Resource (org.hl7.fhir.r4.model.Resource)85 Test (org.junit.jupiter.api.Test)85 Bundle (org.hl7.fhir.r4.model.Bundle)82 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)80 Coding (org.hl7.fhir.r4.model.Coding)76 Observation (org.hl7.fhir.r4.model.Observation)69 FHIRException (org.hl7.fhir.exceptions.FHIRException)67 Date (java.util.Date)62 Identifier (org.hl7.fhir.r4.model.Identifier)58 List (java.util.List)57 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)49 Encounter (org.hl7.fhir.r4.model.Encounter)48 HashMap (java.util.HashMap)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)44