Search in sources :

Example 91 with ResourceDefn

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

the class ExampleAdorner method getState.

@Override
public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref, XhtmlGeneratorAdornerState state, Element node) throws Exception {
    if (state == null) {
        if (node == null)
            return new ExampleAdornerState(State.Unknown, "", null, "", "");
        else if (definitions.hasResource(node.getLocalName()))
            return new ExampleAdornerState(State.Element, node.getLocalName(), definitions.getResourceByName(node.getLocalName()).getRoot(), "", "");
        else
            return new ExampleAdornerState(State.Unknown, "", null, "", "");
    } else {
        ExampleAdornerState s = (ExampleAdornerState) state;
        if (s.getState() == State.Element) {
            if (s.definition == null) {
                System.out.println("??");
            }
            if (// account for extra element
            s.definition != null && "Resource".equals(s.definition.typeCode()) && (s.getPath().endsWith(".entry.resource") || s.getPath().endsWith(".contained")) && definitions.isResource(node.getNodeName()))
                return new ExampleAdornerState(State.Element, s.getPath(), definitions.getResourceByName(node.getNodeName()).getRoot(), "", "");
            String p = s.getPath() + "." + node.getNodeName();
            ElementDefn e = s.getDefinition().getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
            if (e == null && definitions.hasElementDefn(s.getDefinition().typeCodeNoParams())) {
                // well, we see if it's inherited...
                ElementDefn t = definitions.getElementDefn(s.getDefinition().typeCodeNoParams());
                while (t != null && e == null) {
                    e = t.getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
                    if (e != null)
                        p = t.getName() + "." + e.getName();
                    else if (definitions.hasElementDefn(t.typeCodeNoParams()))
                        t = definitions.getElementDefn(t.typeCodeNoParams());
                    else
                        t = null;
                }
            } else if (e != null)
                p = s.getPath() + "." + e.getName();
            if (e == null)
                return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
            if (!e.isBaseResourceElement() && e.typeCode().contains("Reference") && !e.typeCode().contains("CodeableReference"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else if (!e.isBaseResourceElement() && e.typeCode().contains("canonical"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else if (!e.isBaseResourceElement() && e.typeCode().equals("uri"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else
                return new ExampleAdornerState(State.Element, p, e, "", "");
        } else if (s.getState() == State.Reference) {
            if (node.getLocalName().equals("reference")) {
                String type = extractType(node.getAttribute("value"));
                String id = extractId(node.getAttribute("value"), type);
                if (id == null)
                    return new ExampleAdornerState(State.Element, s.getPath() + ".reference", null, "", "");
                ResourceDefn r = definitions.getResourceByName(type);
                if (r == null)
                    throw new Exception("unable to find type " + type);
                for (Example e : r.getExamples()) {
                    if (id.equals(e.getId()))
                        if (Utilities.noString(e.getIg())) {
                            return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html\">", "</a>");
                        } else {
                            ImplementationGuideDefn ig = definitions.getIgs().get(e.getIg());
                            return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + ig.getPrefix() + e.getTitle() + ".xml.html\">", "</a>");
                        }
                    if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("feed")) {
                        List<Element> entries = new ArrayList<Element>();
                        XMLUtil.getNamedChildren(e.getXml().getDocumentElement(), "entry", entries);
                        String url = "http://hl7.org/fhir/" + type + "/" + id;
                        for (Element c : entries) {
                            String t = XMLUtil.getNamedChild(c, "id").getAttribute("value");
                            if (url.equals(t))
                                return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html#" + id + "\">", "</a>");
                        }
                    }
                }
                return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<font color=\"red\">", "</font>");
            } else
                return new ExampleAdornerState(State.Reference, s.getPath(), s.getDefinition(), "", "");
        } else
            // else
            return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
    }
}
Also used : Example(org.hl7.fhir.definitions.model.Example) Element(org.w3c.dom.Element) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) List(java.util.List) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 92 with ResourceDefn

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

the class PageProcessor method produceProfiles.

private String produceProfiles(ResourceDefn resource) {
    int count = 0;
    Map<String, CSPair> map = new HashMap<String, CSPair>();
    for (Profile ap : resource.getConformancePackages()) {
        for (ConstraintStructure cs : ap.getProfiles()) {
            if (coversResource(cs, resource.getName()))
                map.put(cs.getTitle(), new CSPair(ap, cs));
        }
    }
    for (Profile ap : definitions.getPackList()) {
        for (ConstraintStructure cs : ap.getProfiles()) {
            if (coversResource(cs, resource.getName()))
                map.put(cs.getTitle(), new CSPair(ap, cs));
        }
    }
    StringBuilder b = new StringBuilder();
    for (String s : sorted(map.keySet())) {
        CSPair cs = map.get(s);
        ImplementationGuideDefn ig = definitions.getIgs().get(cs.p.getCategory());
        if (ig == null) {
            throw new FHIRException("The profile " + cs.cs.getId() + " is not registered in an IG");
        }
        count++;
        b.append("  <tr>\r\n");
        String ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.cs.getId() + ".html";
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.cs.getTitle())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.p.getDescription())).append("</td>\r\n");
        ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.p.getId().toLowerCase() + ".html";
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.p.getTitle())).append("</a></td>\r\n");
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        return "<p>No Profiles defined for this resource</p>";
    return "<table class=\"list\">\r\n" + " <tr><td><b>Profile</b></td><td><b>Description</b></td><td><b>Context</b></td></tr>\r\n" + b.toString() + "</table>\r\n";
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile)

Example 93 with ResourceDefn

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

the class PageProcessor method genChoiceElementsJson.

public String genChoiceElementsJson() throws Exception {
    StringBuilder b = new StringBuilder();
    for (String s : sorted(definitions.getTypes().keySet())) {
        ElementDefn t = definitions.getTypes().get(s);
        buildChoiceElementList(b, s, t);
    }
    for (String s : sorted(definitions.getResources().keySet())) {
        ResourceDefn t = definitions.getResources().get(s);
        buildChoiceElementList(b, s, t.getRoot());
    }
    return "{\r\n  \"elements\" : {\r\n" + b.toString() + "\r\n  }\r\n}\r\n";
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 94 with ResourceDefn

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

the class PageProcessor method genLogicalAnalysis.

private String genLogicalAnalysis(ResourceDefn logical, String genlevel) throws FHIRException, IOException {
    IniFile ini = new IniFile(Utilities.path(getFolders().srcDir, logical.getName(), logical.getName() + "-tasks.ini"));
    String url = logical.getMappingUrl();
    Map<ElementDefn, StringBuilder> bm = new HashMap<>();
    List<ElementDefn> elements = new ArrayList<ElementDefn>();
    listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
    for (ElementDefn e : elements) {
        StringBuilder b2 = new StringBuilder();
        bm.put(e, b2);
    }
    boolean any = false;
    for (String s : sorted(definitions.getResources().keySet())) {
        ResourceDefn rd = definitions.getResourceByName(s);
        StructureDefinition sd = rd.getProfile();
        String code = null;
        for (StructureDefinitionMappingComponent m : sd.getMapping()) {
            if (m.getUri().equals(url))
                code = m.getIdentity();
        }
        if (code != null) {
            if (hasLogicalMapping(sd, logical, code)) {
                any = true;
                for (ElementDefn e : elements) {
                    StringBuilder b2 = bm.get(e);
                    populateLogicalMappingColumn(null, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, b2, ini, e.getPath());
                }
            }
        }
    }
    if (any) {
        StringBuilder bx = new StringBuilder();
        bx.append("<a name=\"mappings\"></a><h3>Mappings</h3>\r\n");
        bx.append("<table class=\"grid\">\r\n");
        for (ElementDefn e : elements) {
            if (logical.getRoot().getElements().contains(e)) {
                bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getPath() + "</a></b></td></tr>\r\n");
            } else {
                bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getPath() + "</a></b></td></tr>\r\n");
            }
            bx.append("<tr><td colspan=\"6\">" + e.getPath() + " : " + e.typeCode() + " [" + e.describeCardinality() + "]</td></tr>\r\n");
            bx.append("<tr><td>Resource</td><td>Matches</td><td>Issues</td><td>Tasks</td><td>Status</td><td>Notes</td></tr>\r\n");
            bx.append(bm.get(e).toString());
        }
        bx.append("</table>\r\n");
        return bx.toString();
    } else
        return "";
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) IniFile(org.hl7.fhir.utilities.IniFile) HashMap(java.util.HashMap) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 95 with ResourceDefn

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

the class PageProcessor method genScList.

private String genScList(String path) throws Exception {
    ResourceDefn r = definitions.getResourceByName(path.substring(0, path.indexOf(".")));
    if (r == null)
        throw new Exception("Unable to process sclist (1): " + path);
    ElementDefn e = r.getRoot().getElementByName(definitions, path.substring(path.indexOf(".") + 1), true, false);
    if (e == null)
        throw new Exception("Unable to process sclist (2): " + path);
    if (e.typeCode().equals("boolean"))
        return "true | false";
    else {
        StringBuilder b = new StringBuilder();
        boolean first = true;
        for (ConceptSetComponent inc : e.getBinding().getValueSet().getCompose().getInclude()) {
            CodeSystem cs = definitions.getCodeSystems().get(inc.getSystem());
            if (cs != null) {
                for (ConceptDefinitionComponent cc : cs.getConcept()) {
                    if (first)
                        first = false;
                    else
                        b.append(" | ");
                    b.append("<span title=\"" + cc.getDisplay() + ": " + Utilities.escapeXml(cc.getDefinition()) + "\">" + cc.getCode() + "</span>");
                }
            }
        }
        return b.toString();
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14