Search in sources :

Example 6 with Composition

use of org.hl7.fhir.r5.model.Composition 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)

Example 7 with Composition

use of org.hl7.fhir.r5.model.Composition in project integration-adaptor-111 by nhsconnect.

the class CompositionMapper method mapComposition.

public Composition mapComposition(POCDMT000002UK01ClinicalDocument1 clinicalDocument, Encounter encounter, List<CarePlan> carePlans, List<QuestionnaireResponse> questionnaireResponseList, ReferralRequest referralRequest, List<PractitionerRole> practitionerRoles) {
    Composition composition = new Composition();
    composition.setIdElement(resourceUtil.newRandomUuid());
    Identifier docIdentifier = new Identifier();
    docIdentifier.setUse(USUAL);
    docIdentifier.setValue(clinicalDocument.getSetId().getRoot());
    composition.setTitle(COMPOSITION_TITLE).setType(createCodeableConcept()).setStatus(FINAL).setEncounter(resourceUtil.createReference(encounter)).setSubject(encounter.getSubject()).setDateElement(DateUtil.parse(clinicalDocument.getEffectiveTime().getValue())).setIdentifier(docIdentifier);
    if (clinicalDocument.getConfidentialityCode().isSetCode()) {
        composition.setConfidentiality(Composition.DocumentConfidentiality.valueOf(clinicalDocument.getConfidentialityCode().getCode()));
    }
    if (isNotEmpty(clinicalDocument.getRelatedDocumentArray()) && clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).isSetRoot()) {
        Identifier relatedDocIdentifier = new Identifier();
        relatedDocIdentifier.setUse(USUAL);
        relatedDocIdentifier.setValue(clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).getRoot());
        composition.addRelatesTo().setCode(Composition.DocumentRelationshipType.REPLACES).setTarget(relatedDocIdentifier);
    }
    practitionerRoles.stream().forEach(it -> composition.addAuthor(it.getPractitioner()));
    if (clinicalDocument.getComponent().isSetStructuredBody()) {
        for (POCDMT000002UK01Component3 component3 : clinicalDocument.getComponent().getStructuredBody().getComponentArray()) {
            SectionComponent sectionComponent = new SectionComponent();
            addSectionChildren(sectionComponent, component3.getSection());
            composition.addSection(sectionComponent);
        }
    }
    for (CarePlan carePlan : carePlans) {
        composition.addSection(buildSectionComponentFromResource(carePlan));
    }
    if (!referralRequest.isEmpty()) {
        composition.addSection(buildSectionComponentFromResource(referralRequest));
    }
    if (questionnaireResponseList != null) {
        addPathwaysToSection(composition, questionnaireResponseList);
    }
    return composition;
}
Also used : Composition(org.hl7.fhir.dstu3.model.Composition) CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Identifier(org.hl7.fhir.dstu3.model.Identifier) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) SectionComponent(org.hl7.fhir.dstu3.model.Composition.SectionComponent)

Example 8 with Composition

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

the class NarrativeGenerator method generateDocumentNarrative.

public XhtmlNode generateDocumentNarrative(Bundle feed) {
    /*
     When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
     * The Composition resource
     * The Subject resource
     * Resources referenced in the section.content
     */
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    Composition comp = (Composition) feed.getEntry().get(0).getResource();
    root.getChildNodes().add(comp.getText().getDiv());
    Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
    if (subject != null && subject instanceof DomainResource) {
        root.addTag("hr");
        root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
    }
    List<SectionComponent> sections = comp.getSection();
    renderSections(feed, root, sections, 1);
    return root;
}
Also used : Composition(org.hl7.fhir.dstu2.model.Composition) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) SectionComponent(org.hl7.fhir.dstu2.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 9 with Composition

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

the class RdfParser method composeComposition.

protected void composeComposition(Complex parent, String parentType, String name, Composition element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Composition", name, element, index);
    if (element.hasIdentifier())
        composeIdentifier(t, "Composition", "identifier", element.getIdentifier(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "Composition", "status", element.getStatusElement(), -1);
    if (element.hasType())
        composeCodeableConcept(t, "Composition", "type", element.getType(), -1);
    if (element.hasClass_())
        composeCodeableConcept(t, "Composition", "class", element.getClass_(), -1);
    if (element.hasSubject())
        composeReference(t, "Composition", "subject", element.getSubject(), -1);
    if (element.hasEncounter())
        composeReference(t, "Composition", "encounter", element.getEncounter(), -1);
    if (element.hasDateElement())
        composeDateTime(t, "Composition", "date", element.getDateElement(), -1);
    for (int i = 0; i < element.getAuthor().size(); i++) composeReference(t, "Composition", "author", element.getAuthor().get(i), i);
    if (element.hasTitleElement())
        composeString(t, "Composition", "title", element.getTitleElement(), -1);
    if (element.hasConfidentialityElement())
        composeEnum(t, "Composition", "confidentiality", element.getConfidentialityElement(), -1);
    for (int i = 0; i < element.getAttester().size(); i++) composeCompositionCompositionAttesterComponent(t, "Composition", "attester", element.getAttester().get(i), i);
    if (element.hasCustodian())
        composeReference(t, "Composition", "custodian", element.getCustodian(), -1);
    for (int i = 0; i < element.getRelatesTo().size(); i++) composeCompositionCompositionRelatesToComponent(t, "Composition", "relatesTo", element.getRelatesTo().get(i), i);
    for (int i = 0; i < element.getEvent().size(); i++) composeCompositionCompositionEventComponent(t, "Composition", "event", element.getEvent().get(i), i);
    for (int i = 0; i < element.getSection().size(); i++) composeCompositionSectionComponent(t, "Composition", "section", element.getSection().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 10 with Composition

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

the class RdfParser method composeCompositionSectionComponent.

protected void composeCompositionSectionComponent(Complex parent, String parentType, String name, Composition.SectionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "section", name, element, index);
    if (element.hasTitleElement())
        composeString(t, "Composition", "title", element.getTitleElement(), -1);
    if (element.hasCode())
        composeCodeableConcept(t, "Composition", "code", element.getCode(), -1);
    if (element.hasText())
        composeNarrative(t, "Composition", "text", element.getText(), -1);
    if (element.hasModeElement())
        composeEnum(t, "Composition", "mode", element.getModeElement(), -1);
    if (element.hasOrderedBy())
        composeCodeableConcept(t, "Composition", "orderedBy", element.getOrderedBy(), -1);
    for (int i = 0; i < element.getEntry().size(); i++) composeReference(t, "Composition", "entry", element.getEntry().get(i), i);
    if (element.hasEmptyReason())
        composeCodeableConcept(t, "Composition", "emptyReason", element.getEmptyReason(), -1);
    for (int i = 0; i < element.getSection().size(); i++) composeCompositionSectionComponent(t, "Composition", "section", element.getSection().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

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