dss/src/main/java/gov/samhsa/c2s/dss/service/document/redact/impl/postredactionlevel/DocumentCleanupForNoEntryAndNoSection.java
private void cleanUpSectionComponentsWithNoEntries(Document xmlDocument, String documentType)
            throws DocumentAccessorException {
        // Find all empty sections
        final List<Node> emptySectionComponents = documentAccessor.getNodeListAsStream(
                xmlDocument, XPATH_SECTION_COMPONENT_WITH_NO_ENTRY).collect(toList());
        // Find the required sections out of the empty sections
        final List<Node> requiredButEmptySectionComponents = emptySectionComponents.stream()
                .filter(node -> isRequired(node, documentType))
                .collect(toList());
        // Remove the empty sections that are not required
        emptySectionComponents.stream()
                .filter(section -> !requiredButEmptySectionComponents.contains(section))
                .forEach(this::nullSafeRemove);
        // Set @nullFlavor=NI and add "No information" text on required but empty sections
        requiredButEmptySectionComponents.stream()
                .flatMap(this::componentToSection)
                .peek(section -> section.getAttributes().setNamedItem(createNullFlavorNIAttribute(xmlDocument)))
                .flatMap(this::sectionToText)
                .forEach(text -> {
                    nullSafeRemoveChildNodes(text);
                    Node textNode = createTextNode(xmlDocument, "No information");
                    text.appendChild(textNode);
                });
    }
/**
     * Clean up section components with no entries.
     *
     * @param xmlDocument the xml document
     * @throws DocumentAccessorException the document accessor exception
     */
Clean up section components with no entries.
@param xmlDocument the xml document
@throws DocumentAccessorException the document accessor exception
Clean up section components with no entries . @param xmlDocument the xml document @throws DocumentAccessorException the document accessor exception
private void cleanUpSectionComponentsWithNoEntries(Document xmlDocument, String documentType)
            throws DocumentAccessorException {
        final List<Node> emptySectionComponents = documentAccessor.getNodeListAsStream(
                xmlDocument, XPATH_SECTION_COMPONENT_WITH_NO_ENTRY).collect(toList());
        final List<Node> requiredButEmptySectionComponents = emptySectionComponents.stream()
                .filter(node -> isRequired(node, documentType))
                .collect(toList());
        emptySectionComponents.stream()
                .filter(section -> !requiredButEmptySectionComponents.contains(section))
                .forEach(this::nullSafeRemove);
        requiredButEmptySectionComponents.stream()
                .flatMap(this::componentToSection)
                .peek(section -> section.getAttributes().setNamedItem(createNullFlavorNIAttribute(xmlDocument)))
                .flatMap(this::sectionToText)
                .forEach(text -> {
                    nullSafeRemoveChildNodes(text);
                    Node textNode = createTextNode(xmlDocument, "No information");
                    text.appendChild(textNode);
                });
    }
private void cleanUpSectionComponentsWithNoEntries ( Document xmlDocument , String documentType ) throws DocumentAccessorException { final List < Node > emptySectionComponents = documentAccessor . getNodeListAsStream ( xmlDocument , XPATH_SECTION_COMPONENT_WITH_NO_ENTRY ) . collect ( toList ( ) ) ; final List < Node > requiredButEmptySectionComponents = emptySectionComponents . stream ( ) . filter ( node -> isRequired ( node , documentType ) ) . collect ( toList ( ) ) ; emptySectionComponents . stream ( ) . filter ( section -> ! requiredButEmptySectionComponents . contains ( section ) ) . forEach ( this :: nullSafeRemove ) ; requiredButEmptySectionComponents . stream ( ) . flatMap ( this :: componentToSection ) . peek ( section -> section . getAttributes ( ) . setNamedItem ( createNullFlavorNIAttribute ( xmlDocument ) ) ) . flatMap ( this :: sectionToText ) . forEach ( text -> { nullSafeRemoveChildNodes ( text ) ; Node textNode = createTextNode ( xmlDocument , "No information" ) ; text . appendChild ( textNode ) ; } ) ; }
Clean up section components with no entries.
Clean up section components with no entries .
// Find all empty sections // Find the required sections out of the empty sections // Remove the empty sections that are not required // Set @nullFlavor=NI and add "No information" text on required but empty sections