Search in sources :

Example 21 with Composition

use of org.hl7.fhir.r4.model.Composition in project org.hl7.fhir.core by hapifhir.

the class BundleRenderer method render.

public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    if (b.getType() == BundleType.DOCUMENT) {
        if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) {
            throw new FHIRException("Invalid document - first entry is not a Composition");
        }
        XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
        renderDocument(x, b);
        return x;
    } else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
        return null;
    } else {
        XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
        root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.getType().toCode()));
        int i = 0;
        for (BundleEntryComponent be : b.getEntry()) {
            i++;
            if (be.hasFullUrl())
                root.an(makeInternalBundleLink(be.getFullUrl()));
            if (be.hasResource() && be.getResource().hasId())
                root.an(be.getResource().getResourceType().name() + "_" + be.getResource().getId());
            root.hr();
            if (be.hasFullUrl()) {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.getFullUrl()));
            } else {
                root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
            }
            if (be.hasRequest())
                renderRequest(root, be.getRequest());
            if (be.hasSearch())
                renderSearch(root, be.getSearch());
            if (be.hasResponse())
                renderResponse(root, be.getResponse());
            if (be.hasResource()) {
                root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.getResource().fhirType()));
                if (be.hasResource()) {
                    XhtmlNode xn = null;
                    if (be.getResource() instanceof DomainResource) {
                        DomainResource dr = (DomainResource) be.getResource();
                        xn = dr.getText().getDiv();
                    }
                    if (xn == null || xn.isEmpty()) {
                        ResourceRenderer rr = RendererFactory.factory(be.getResource(), context);
                        try {
                            xn = rr.build(be.getResource());
                        } catch (Exception e) {
                            xn = makeExceptionXhtml(e, "generating narrative");
                        }
                    }
                    root.blockquote().para().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
                }
            }
        }
        return root;
    }
}
Also used : Composition(org.hl7.fhir.r5.model.Composition) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) DomainResource(org.hl7.fhir.r5.model.DomainResource) 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)

Example 22 with Composition

use of org.hl7.fhir.r4.model.Composition 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().para().addChildren(xn);
            }
        }
    }
    return false;
}
Also used : ResourceWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper) BaseWrapper(org.hl7.fhir.r5.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)

Example 23 with Composition

use of org.hl7.fhir.r4.model.Composition in project org.hl7.fhir.core by hapifhir.

the class BundleValidator method validateDocumentReference.

public void validateDocumentReference(List<ValidationMessage> errors, List<Element> entries, Element composition, NodeStack stack, String fullUrl, String id, boolean repeats, String propName, String title) {
    if (repeats) {
        List<Element> list = new ArrayList<>();
        composition.getNamedChildren(propName, list);
        int i = 1;
        for (Element elem : list) {
            validateBundleReference(errors, entries, elem, title + "." + propName, stack.push(elem, i, null, null), fullUrl, "Composition", id);
            i++;
        }
    } else {
        Element elem = composition.getNamedChild(propName);
        if (elem != null) {
            validateBundleReference(errors, entries, elem, title + "." + propName, stack.push(elem, -1, null, null), fullUrl, "Composition", id);
        }
    }
}
Also used : IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList)

Example 24 with Composition

use of org.hl7.fhir.r4.model.Composition in project fhir-bridge by ehrbase.

the class BloodPressureCompositionConverter method mapKategorie.

private void mapKategorie(BlutdruckComposition composition, Observation resource) {
    List<BlutdruckKategorieElement> list = new ArrayList<>();
    for (CodeableConcept category : resource.getCategory()) {
        for (Coding coding : category.getCoding()) {
            BlutdruckKategorieElement blutdruckKategorieElement = new BlutdruckKategorieElement();
            blutdruckKategorieElement.setValue(coding.getCode());
            list.add(blutdruckKategorieElement);
        }
    }
    composition.setKategorie(list);
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) BlutdruckKategorieElement(org.ehrbase.fhirbridge.ehr.opt.blutdruckcomposition.definition.BlutdruckKategorieElement) ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 25 with Composition

use of org.hl7.fhir.r4.model.Composition in project fhir-bridge by ehrbase.

the class SarsCov2KnownExposureCompositionConverter method mapKategorie.

private void mapKategorie(SARSCoV2ExpositionComposition composition, Observation resource) {
    List<SarsCov2ExpositionKategorieElement> list = new ArrayList<>();
    for (CodeableConcept category : resource.getCategory()) {
        for (Coding coding : category.getCoding()) {
            SarsCov2ExpositionKategorieElement sarsCov2ExpositionKategorieElement = new SarsCov2ExpositionKategorieElement();
            sarsCov2ExpositionKategorieElement.setValue(coding.getCode());
            list.add(sarsCov2ExpositionKategorieElement);
        }
    }
    composition.setKategorie(list);
}
Also used : SarsCov2ExpositionKategorieElement(org.ehrbase.fhirbridge.ehr.opt.sarscov2expositioncomposition.definition.SarsCov2ExpositionKategorieElement) Coding(org.hl7.fhir.r4.model.Coding) ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

ArrayList (java.util.ArrayList)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)12 Coding (org.hl7.fhir.r4.model.Coding)8 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)7 Composition (org.hl7.fhir.r4.model.Composition)6 IOException (java.io.IOException)5 Composition (org.hl7.fhir.dstu3.model.Composition)5 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)5 Reference (org.hl7.fhir.r4.model.Reference)5 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Encounter (org.hl7.fhir.dstu3.model.Encounter)3 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 Map (java.util.Map)2