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);
}
Aggregations