Search in sources :

Example 51 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class LiquidRenderer method render.

@Override
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    LiquidEngine engine = new LiquidEngine(context.getWorker(), context.getServices());
    XhtmlNode xn;
    try {
        engine.setIncludeResolver(new LiquidRendererIncludeResolver(context));
        LiquidDocument doc = engine.parse(liquidTemplate, "template");
        String html = engine.evaluate(doc, r, rcontext);
        xn = new XhtmlParser().parseFragment(html);
        if (!x.getName().equals("div"))
            throw new FHIRException("Error in template: Root element is not 'div'");
    } catch (FHIRException | IOException e) {
        xn = new XhtmlNode(NodeType.Element, "div");
        xn.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
    }
    x.getChildNodes().addAll(xn.getChildNodes());
    return true;
}
Also used : LiquidDocument(org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) IOException(java.io.IOException) LiquidEngine(org.hl7.fhir.r5.utils.LiquidEngine) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 52 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project kindling by HL7.

the class PageProcessor method genExample.

private String genExample(Example example, int headerLevelContext, String genlevel) throws IOException, EOperationOutcome, FHIRException {
    String xml = XMLUtil.elementToString(example.getXml().getDocumentElement());
    Resource res = new XmlParser().parse(xml);
    if (!(res instanceof DomainResource))
        return "";
    DomainResource dr = (DomainResource) res;
    if (!dr.hasText() || !dr.getText().hasDiv()) {
        RenderingContext lrc = rc.copy().setHeaderLevelContext(headerLevelContext);
        RendererFactory.factory(dr, lrc).render(dr);
    }
    return new XhtmlComposer(XhtmlComposer.HTML).compose(dr.getText().getDiv());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) DomainResource(org.hl7.fhir.r5.model.DomainResource) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 53 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project kindling by HL7.

the class Publisher method buildConceptMap.

private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
    ConceptMap cm = new ConceptMap();
    cm.setUserData("path", "sc-" + vs.getUserString("path"));
    cm.setUserData("resource-definition", rd);
    cm.setId("sc-" + vs.getId());
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setVersion(page.getVersion().toCode());
    cm.setName(vs.getName() + "CanonicalMap");
    cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setDate(vs.getDate());
    cm.setPublisher(vs.getPublisher());
    cm.addContact(vs.getContactFirstRep());
    cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
    cm.setSource(new CanonicalType(vs.getUrl()));
    cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
    List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
    List<String> self = page.getDefinitions().getStatusCodes().get(path);
    ConceptMapGroupComponent grp = cm.addGroup();
    grp.setTarget("http://hl7.org/fhir/resource-status");
    grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
    for (int i = 0; i < self.size(); i++) {
        if (!Utilities.noString(self.get(i))) {
            String cc = canonical.get(i);
            String sc = self.get(i);
            SourceElementComponent e = grp.addElement();
            e.setCode(sc);
            TargetElementComponent t = e.addTarget();
            t.setCode(cc);
            t.setRelationship(ConceptMapRelationship.EQUIVALENT);
        }
    }
    if (!grp.hasElement())
        return null;
    page.getConceptMaps().see(cm, page.packageInfo());
    statusCodeConceptMaps.add(cm);
    return cm;
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 54 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method renderDocument.

private boolean renderDocument(XhtmlNode x, ResourceWrapper b, List<BaseWrapper> entries) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
    // from the spec:
    // 
    // When the document is presented for human consumption, applications SHOULD present the collated narrative portions in order:
    // * The subject resource Narrative
    // * The Composition resource Narrative
    // * The section.text Narratives
    ResourceWrapper comp = (ResourceWrapper) entries.get(0).getChildByName("resource").getAsResource();
    ResourceWrapper subject = resolveReference(entries, comp.get("subject"));
    if (subject != null) {
        if (subject.hasNarrative()) {
            x.addChildren(subject.getNarrative());
        } else {
            RendererFactory.factory(subject, context).render(x, subject);
        }
    }
    x.hr();
    if (comp.hasNarrative()) {
        x.addChildren(comp.getNarrative());
        x.hr();
    }
    List<BaseWrapper> sections = comp.children("section");
    for (BaseWrapper section : sections) {
        addSection(x, section, 2, false);
    }
    return false;
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)

Example 55 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method render.

@Override
public boolean render(XhtmlNode x, ResourceWrapper b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    List<BaseWrapper> entries = b.children("entry");
    if ("document".equals(b.get("type").primitiveValue())) {
        if (entries.isEmpty() || (entries.get(0).has("resource") && !"Composition".equals(entries.get(0).get("resource").fhirType())))
            throw new FHIRException("Invalid document '" + b.getId() + "' - first entry is not a Composition ('" + entries.get(0).get("resource").fhirType() + "')");
        return renderDocument(x, b, entries);
    } else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) {
    // nothing
    } else {
        XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
        root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.get("type").primitiveValue()));
        int i = 0;
        for (BaseWrapper be : entries) {
            i++;
            if (be.has("fullUrl")) {
                root.an(makeInternalBundleLink(be.get("fullUrl").primitiveValue()));
            }
            if (be.has("resource") && be.getChildByName("resource").getValues().get(0).has("id")) {
                root.an(be.get("resource").fhirType() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
            }
            root.hr();
            if (be.has("fullUrl")) {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.get("fullUrl").primitiveValue()));
            } else {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
            }
            // renderResponse(root, be.getResponse());
            if (be.has("resource")) {
                root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.get("resource").fhirType()));
                ResourceWrapper rw = be.getChildByName("resource").getAsResource();
                XhtmlNode xn = rw.getNarrative();
                if (xn == null || xn.isEmpty()) {
                    ResourceRenderer rr = RendererFactory.factory(rw, context);
                    try {
                        xn = rr.render(rw);
                    } catch (Exception e) {
                        xn = new XhtmlNode();
                        xn.para().b().tx("Exception generating narrative: " + e.getMessage());
                    }
                }
                root.blockquote().addChildren(xn);
            }
        }
    }
    return false;
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) FHIRException(org.hl7.fhir.exceptions.FHIRException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)52 FHIRException (org.hl7.fhir.exceptions.FHIRException)38 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)37 ArrayList (java.util.ArrayList)35 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)14 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 FileOutputStream (java.io.FileOutputStream)10 Test (org.junit.jupiter.api.Test)10 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 DomainResource (org.hl7.fhir.r5.model.DomainResource)7 DomainResource (org.hl7.fhir.r4b.model.DomainResource)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)6 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)6 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5