Search in sources :

Example 96 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class CodeSystemRenderer method generateCodeSystemContent.

private boolean generateCodeSystemContent(XhtmlNode x, CodeSystem cs, boolean hasExtensions, List<UsedConceptMap> maps) throws FHIRFormatError, DefinitionException, IOException {
    XhtmlNode p = x.para();
    if (cs.getContent() == CodeSystemContentMode.COMPLETE)
        p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines the following codes", cs.getUrl()) + ":");
    else if (cs.getContent() == CodeSystemContentMode.EXAMPLE)
        p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines some example codes", cs.getUrl()) + ":");
    else if (cs.getContent() == CodeSystemContentMode.FRAGMENT)
        p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines many codes, of which the following are a subset", cs.getUrl()) + ":");
    else if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
        p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system %s defines many codes, but they are not represented here", cs.getUrl()));
        return false;
    }
    XhtmlNode t = x.table("codes");
    boolean definitions = false;
    boolean commentS = false;
    boolean deprecated = false;
    boolean display = false;
    boolean hierarchy = false;
    boolean version = false;
    boolean ignoreStatus = false;
    boolean isSupplement = cs.getContent() == CodeSystemContentMode.SUPPLEMENT;
    List<PropertyComponent> properties = new ArrayList<>();
    for (PropertyComponent cp : cs.getProperty()) {
        if (showPropertyInTable(cp)) {
            boolean exists = false;
            for (ConceptDefinitionComponent c : cs.getConcept()) {
                exists = exists || conceptsHaveProperty(c, cp);
            }
            if (exists) {
                properties.add(cp);
                if ("status".equals(cp.getCode())) {
                    ignoreStatus = true;
                }
            }
        }
    }
    for (ConceptDefinitionComponent c : cs.getConcept()) {
        commentS = commentS || conceptsHaveComments(c);
        deprecated = deprecated || conceptsHaveDeprecated(cs, c, ignoreStatus);
        display = display || conceptsHaveDisplay(c);
        version = version || conceptsHaveVersion(c);
        hierarchy = hierarchy || c.hasConcept();
        definitions = definitions || conceptsHaveDefinition(c);
    }
    CodeSystemNavigator csNav = new CodeSystemNavigator(cs);
    hierarchy = hierarchy || csNav.isRestructure();
    List<String> langs = new ArrayList<>();
    addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, false), maps);
    for (ConceptDefinitionComponent c : csNav.getConcepts(null)) {
        hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs, isSupplement) || hasExtensions;
    }
    if (langs.size() > 0) {
        Collections.sort(langs);
        x.para().b().tx("Additional Language Displays");
        t = x.table("codes");
        XhtmlNode tr = t.tr();
        tr.td().b().tx("Code");
        for (String lang : langs) tr.td().b().addText(describeLang(lang));
        for (ConceptDefinitionComponent c : cs.getConcept()) {
            addLanguageRow(c, t, langs);
        }
    }
    return hasExtensions;
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent) PropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.PropertyComponent) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) ArrayList(java.util.ArrayList) CodeSystemNavigator(org.hl7.fhir.r4b.terminologies.CodeSystemUtilities.CodeSystemNavigator) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 97 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class CompartmentDefinitionRenderer method render.

public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
    StringBuilder in = new StringBuilder();
    StringBuilder out = new StringBuilder();
    for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
        CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
        if (!cc.hasParam()) {
            out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
        } else if (!rules.equals("{def}")) {
            for (StringType p : cc.getParam()) rules.append(p.asStringValue());
            in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
        }
    }
    XhtmlNode xn;
    xn = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.r4b.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.r4b.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 98 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
    if (context.isAddGeneratedNarrativeHeader()) {
        x.para().b().tx("Generated Narrative");
    }
    if (context.isTechnicalMode()) {
        renderResourceHeader(r, x);
    }
    try {
        StructureDefinition sd = r.getDefinition();
        if (sd == null) {
            throw new FHIRException("Cannot find definition for " + r.fhirType());
        } else {
            ElementDefinition ed = sd.getSnapshot().getElement().get(0);
            containedIds.clear();
            hasExtensions = false;
            generateByProfile(r, sd, r.root(), sd.getSnapshot().getElement(), ed, context.getProfileUtilities().getChildList(sd, ed), x, r.fhirType(), context.isTechnicalMode(), 0);
        }
    } catch (Exception e) {
        System.out.println("Error Generating Narrative for " + r.fhirType() + "/" + r.getId() + ": " + e.getMessage());
        e.printStackTrace();
        x.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    return hasExtensions;
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 99 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method splitExtensions.

private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
    List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
    Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
    for (PropertyWrapper p : children) if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
        // we're going to split these up, and create a property for each url
        if (p.hasValues()) {
            for (BaseWrapper v : p.getValues()) {
                Extension ex = (Extension) v.getBase();
                String url = ex.getUrl();
                StructureDefinition ed = getContext().getWorker().fetchResource(StructureDefinition.class, url);
                if (ed == null) {
                    if (xverManager == null) {
                        xverManager = new XVerExtensionManager(context.getWorker());
                    }
                    if (xverManager.matchingUrl(url) && xverManager.status(url) == XVerExtensionStatus.Valid) {
                        ed = xverManager.makeDefinition(url);
                        getContext().getWorker().generateSnapshot(ed);
                        getContext().getWorker().cacheResource(ed);
                    }
                }
                if (p.getName().equals("modifierExtension") && ed == null) {
                    throw new DefinitionException("Unknown modifier extension " + url);
                }
                PropertyWrapper pe = map.get(p.getName() + "[" + url + "]");
                if (pe == null) {
                    if (ed == null) {
                        if (url.startsWith("http://hl7.org/fhir") && !url.startsWith("http://hl7.org/fhir/us")) {
                            throw new DefinitionException("unknown extension " + url);
                        }
                        // System.out.println("unknown extension "+url);
                        pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex), null);
                    } else {
                        ElementDefinition def = ed.getSnapshot().getElement().get(0);
                        pe = new PropertyWrapperDirect(this.context, new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex), ed.getSnapshot().getElementFirstRep());
                        ((PropertyWrapperDirect) pe).getWrapped().setStructure(ed);
                    }
                    results.add(pe);
                } else
                    pe.getValues().add(v);
            }
        }
    } else
        results.add(p);
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PropertyWrapperDirect(org.hl7.fhir.r4b.renderers.utils.DirectWrappers.PropertyWrapperDirect) PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) Extension(org.hl7.fhir.r4b.model.Extension) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) XVerExtensionManager(org.hl7.fhir.r4b.utils.XVerExtensionManager) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Property(org.hl7.fhir.r4b.model.Property)

Example 100 with DefinitionException

use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method getChildrenForPath.

private List<ElementDefinition> getChildrenForPath(List<ElementDefinition> elements, String path) throws DefinitionException {
    // do we need to do a name reference substitution?
    for (ElementDefinition e : elements) {
        if (e.getPath().equals(path) && e.hasContentReference()) {
            String ref = e.getContentReference();
            ElementDefinition t = null;
            // now, resolve the name
            for (ElementDefinition e1 : elements) {
                if (ref.equals("#" + e1.getId()))
                    t = e1;
            }
            if (t == null)
                throw new DefinitionException("Unable to resolve content reference " + ref + " trying to resolve " + path);
            path = t.getPath();
            break;
        }
    }
    List<ElementDefinition> results = new ArrayList<ElementDefinition>();
    for (ElementDefinition e : elements) {
        if (e.getPath().startsWith(path + ".") && !e.getPath().substring(path.length() + 1).contains("."))
            results.add(e);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)186 ArrayList (java.util.ArrayList)99 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)91 FHIRException (org.hl7.fhir.exceptions.FHIRException)50 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)32 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)29 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)29 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)28 IOException (java.io.IOException)27 HashMap (java.util.HashMap)24 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)23 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)20 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)17 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)17 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)16 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)14 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)12