Search in sources :

Example 1 with Presentation

use of uk.nhs.adaptors.scr.models.xml.Presentation in project summary-care-record-api by NHSDigital.

the class CompositionMapper method setPresentation.

private static void setPresentation(GpSummary gpSummary, Composition composition) throws FhirMappingException {
    if (!composition.hasSection()) {
        throw new FhirMappingException("Missing mandatory Composition.section");
    }
    Presentation presentation = new Presentation();
    var htmlDocument = createNewDocument("html", "xhtml:NPfIT:PresentationText");
    var bodyNode = htmlDocument.createElement("body");
    htmlDocument.getDocumentElement().appendChild(bodyNode);
    for (Composition.SectionComponent section : composition.getSection()) {
        var h2Node = htmlDocument.createElement("h2");
        h2Node.setAttribute("id", section.getCode().getCodingFirstRep().getCode());
        h2Node.appendChild(htmlDocument.createTextNode(section.getTitle()));
        bodyNode.appendChild(h2Node);
        var divDocument = parseDocument(section.getText().getDiv().getValueAsString());
        removeEmptyNodes(divDocument);
        var divChildNodes = divDocument.getDocumentElement().getChildNodes();
        for (int i = 0; i < divChildNodes.getLength(); i++) {
            bodyNode.appendChild(htmlDocument.importNode(divChildNodes.item(i), true));
        }
    }
    presentation.setPresentationId(randomUUID());
    presentation.setPresentationText(serialize(htmlDocument));
    gpSummary.setPresentation(presentation);
}
Also used : Composition(org.hl7.fhir.r4.model.Composition) Presentation(uk.nhs.adaptors.scr.models.xml.Presentation) FhirMappingException(uk.nhs.adaptors.scr.exceptions.FhirMappingException)

Aggregations

Composition (org.hl7.fhir.r4.model.Composition)1 FhirMappingException (uk.nhs.adaptors.scr.exceptions.FhirMappingException)1 Presentation (uk.nhs.adaptors.scr.models.xml.Presentation)1