DocumentCleanupForNoEntryAndNoSection extends
		AbstractPostRedactionLevelRedactionHandler { @Override public void execute(Document xmlDocument, XacmlResult xacmlResult, FactModel factModel, Document factModelDocument, RuleExecutionContainer ruleExecutionContainer, List<Node> listOfNodes, Set<String> redactSectionCodesAndGeneratedEntryIds) throws XPathExpressionException { cleanUpSectionComponentsWithNoEntries(xmlDocument); addEmptySectionComponentIfNoneExists(xmlDocument); } DocumentCleanupForNoEntryAndNoSection(DocumentAccessor documentAccessor); @Override void execute(Document xmlDocument, XacmlResult xacmlResult,
			FactModel factModel, Document factModelDocument,
			RuleExecutionContainer ruleExecutionContainer,
			List<Node> listOfNodes,
			Set<String> redactSectionCodesAndGeneratedEntryIds); static final String URN_HL7_V3; static final String TAG_COMPONENT; static final String TAG_SECTION; static final String XPATH_NO_COMPONENT_IN_STRUCTURED_BODY; static final String XPATH_SECTION_COMPONENT_WITH_NO_ENTRY; }
@Test public void testExecute_CleanUpSectionComponentsWithNoEntries() throws IOException, SimpleMarshallerException, XPathExpressionException { String c32FileName = "MIE_SampleC32-sectionWithNoEntries.xml"; String factmodelXml = fileReader.readFile(TEST_PATH + FACTMODEL_PATH + c32FileName); String c32 = embeddedClinicalDocumentExtractor.extractClinicalDocumentFromFactModel(factmodelXml); String ruleExecutionContainerXml = fileReader.readFile(TEST_PATH + RULEEXECUTIONCONTAINER_PATH + c32FileName); RuleExecutionContainer ruleExecutionContainer = marshaller.unmarshalFromXml(RuleExecutionContainer.class, ruleExecutionContainerXml); Document c32Document = documentXmlConverter.loadDocument(c32); Document factModelDocument = documentXmlConverter.loadDocument(factmodelXml); FactModel factModel = marshaller.unmarshalFromXml(FactModel.class, factmodelXml); List<Node> listOfNodes = new LinkedList<Node>(); Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); sut.execute(c32Document, factModel.getXacmlResult(), factModel, factModelDocument, ruleExecutionContainer, listOfNodes, redactSectionCodesAndGeneratedEntryIds); assertEquals(1, documentAccessor.getNodeList(c32Document, " assertEquals(0, documentAccessor.getNodeList(c32Document, " assertEquals(1, documentAccessor.getNodeList(c32Document, " }
@Test public void testExecute_CleanUpSectionComponentsWithNoEntries_EmptySectionComponentsNull() throws IOException, SimpleMarshallerException, XPathExpressionException { DocumentAccessor documentAccessorMock = mock(DocumentAccessor.class); sut = new DocumentCleanupForNoEntryAndNoSection(documentAccessorMock); String c32FileName = "MIE_SampleC32-sectionWithNoEntries.xml"; String factmodelXml = fileReader.readFile(TEST_PATH + FACTMODEL_PATH + c32FileName); String c32 = embeddedClinicalDocumentExtractor.extractClinicalDocumentFromFactModel(factmodelXml); String ruleExecutionContainerXml = fileReader.readFile(TEST_PATH + RULEEXECUTIONCONTAINER_PATH + c32FileName); RuleExecutionContainer ruleExecutionContainer = marshaller.unmarshalFromXml(RuleExecutionContainer.class, ruleExecutionContainerXml); Document c32Document = documentXmlConverter.loadDocument(c32); Document factModelDocument = documentXmlConverter.loadDocument(factmodelXml); FactModel factModel = marshaller.unmarshalFromXml(FactModel.class, factmodelXml); List<Node> listOfNodes = new LinkedList<Node>(); Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); when(documentAccessorMock.getNodeList(eq(c32Document), anyString())).thenReturn(null); sut.execute(c32Document, factModel.getXacmlResult(), factModel, factModelDocument, ruleExecutionContainer, listOfNodes, redactSectionCodesAndGeneratedEntryIds); assertEquals(2, documentAccessor.getNodeList(c32Document, " assertEquals(1, documentAccessor.getNodeList(c32Document, " assertEquals(1, documentAccessor.getNodeList(c32Document, " }
@Test public void testExecute_CleanUpSectionComponentsWithNoEntries_EmptySectionComponents_ParentNull() throws IOException, SimpleMarshallerException, XPathExpressionException { Logger loggerMock = mock(Logger.class); DocumentAccessor documentAccessorMock = mock(DocumentAccessor.class); sut = new DocumentCleanupForNoEntryAndNoSection(documentAccessorMock); ReflectionTestUtils.setField(sut, "logger", loggerMock); String c32FileName = "MIE_SampleC32-sectionWithNoEntries.xml"; String factmodelXml = fileReader.readFile(TEST_PATH + FACTMODEL_PATH + c32FileName); String c32 = embeddedClinicalDocumentExtractor.extractClinicalDocumentFromFactModel(factmodelXml); String ruleExecutionContainerXml = fileReader.readFile(TEST_PATH + RULEEXECUTIONCONTAINER_PATH + c32FileName); RuleExecutionContainer ruleExecutionContainer = marshaller.unmarshalFromXml(RuleExecutionContainer.class, ruleExecutionContainerXml); Document c32Document = documentXmlConverter.loadDocument(c32); Document factModelDocument = documentXmlConverter.loadDocument(factmodelXml); FactModel factModel = marshaller.unmarshalFromXml(FactModel.class, factmodelXml); List<Node> listOfNodes = new LinkedList<Node>(); Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); NodeList nodeListMock = mock(NodeList.class); when(nodeListMock.getLength()).thenReturn(1); Node nodeMock = mock(Node.class); when(nodeListMock.item(0)).thenReturn(nodeMock); when(nodeMock.getParentNode()).thenReturn(null); when(documentAccessorMock.getNodeList(eq(c32Document), anyString())).thenReturn(nodeListMock); sut.execute(c32Document, factModel.getXacmlResult(), factModel, factModelDocument, ruleExecutionContainer, listOfNodes, redactSectionCodesAndGeneratedEntryIds); assertEquals(2, documentAccessor.getNodeList(c32Document, " assertEquals(1, documentAccessor.getNodeList(c32Document, " assertEquals(1, documentAccessor.getNodeList(c32Document, " verify(loggerMock, times(1)).warn(anyString(), any(Throwable.class)); }
@Test public void testExecute_AddEmptySectionComponentIfNoneExists() throws IOException, SimpleMarshallerException, XPathExpressionException { String c32FileName = "MIE_SampleC32-sectionWithNoEntriesAndNoOtherSections.xml"; String factmodelXml = fileReader.readFile(TEST_PATH + FACTMODEL_PATH + c32FileName); String c32 = embeddedClinicalDocumentExtractor.extractClinicalDocumentFromFactModel(factmodelXml); String ruleExecutionContainerXml = fileReader.readFile(TEST_PATH + RULEEXECUTIONCONTAINER_PATH + c32FileName); RuleExecutionContainer ruleExecutionContainer = marshaller.unmarshalFromXml(RuleExecutionContainer.class, ruleExecutionContainerXml); Document c32Document = documentXmlConverter.loadDocument(c32); Document factModelDocument = documentXmlConverter.loadDocument(factmodelXml); FactModel factModel = marshaller.unmarshalFromXml(FactModel.class, factmodelXml); List<Node> listOfNodes = new LinkedList<Node>(); Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); sut.execute(c32Document, factModel.getXacmlResult(), factModel, factModelDocument, ruleExecutionContainer, listOfNodes, redactSectionCodesAndGeneratedEntryIds); assertEquals(1, documentAccessor.getNodeList(c32Document, " assertEquals(0, documentAccessor.getNodeList(c32Document, " assertEquals(0, documentAccessor.getNodeList(c32Document, " assertEquals(0, documentAccessor.getNodeList(c32Document, " }