RetrieveDocumentSetResponseFilter { @Loggable public RetrieveDocumentSetResponse filterByPatientAndAuthor( RetrieveDocumentSetResponse response, String patientId, String authorNPI) throws XdsbRepositoryAdapterException { LinkedList<DocumentResponse> removeList = new LinkedList<DocumentResponse>(); for (DocumentResponse docResponse : response.getDocumentResponse()) { try { String docString = new String(docResponse.getDocument()); String xPathExpr = " String attributeName = "extension"; String xPathExpr2 = " String attributeName2 = "extension"; String docPatientId = getAttributeValue(docString, xPathExpr, attributeName); String docAuthorNPI = getAttributeValue(docString, xPathExpr2, attributeName2); if (!patientId.equals(docPatientId) || !authorNPI.equals(docAuthorNPI)) { removeList.add(docResponse); } } catch (NoDocumentFoundException ndf) { logger.error(ndf.getMessage() + patientId); response = xdsbErrorFactory.noClinicalDocumentFound(patientId, authorNPI); } catch (DocumentXmlConverterException | XPathExpressionException e) { logger.error(e.getMessage()); throw new XdsbRepositoryAdapterException(e); } } if (removeList.size() > 0) { response.getDocumentResponse().removeAll(removeList); response = xdsbErrorFactory .setRetrieveDocumentSetResponseRegistryErrorListFilteredByPatientAndAuthor( response, removeList.size(), patientId, authorNPI); } return response; } RetrieveDocumentSetResponseFilter(DocumentXmlConverter converter,
			DocumentAccessor documentAccessor, XdsbErrorFactory xdsbErrorFactory); @Loggable RetrieveDocumentSetResponse filterByPatientAndAuthor(
			RetrieveDocumentSetResponse response, String patientId,
			String authorNPI);  }
@Test(expected = XdsbRepositoryAdapterException.class) public void testFilterByPatientAndAuthor() throws XdsbRepositoryAdapterException, DocumentAccessorException { RetrieveDocumentSetResponse response = mock(RetrieveDocumentSetResponse.class); String patientId = "1"; String authorNPI = "2"; DocumentResponse docResponse1 = mock(DocumentResponse.class); DocumentResponse docResponse2 = mock(DocumentResponse.class); Node nodeMock = mock(Node.class); Document documentMock = mock(Document.class); byte[] document1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<xsl:stylesheet xmlns:xsl=\"http: .getBytes(); byte[] document2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<xsl:stylesheet xmlns:xsl=\"http: .getBytes(); when(docResponse1.getDocument()).thenReturn(document1); when(docResponse2.getDocument()).thenReturn(document2); when(converter.loadDocument(new String(document1))).thenThrow( DocumentXmlConverterException.class); doReturn(nodeMock).when(documentAccessor).getNode(eq(documentMock), anyString(), any(String[].class)); LinkedList<DocumentResponse> docList = new LinkedList<DocumentResponse>(); docList.add(docResponse1); docList.add(docResponse2); when(response.getDocumentResponse()).thenReturn(docList); retrieveDocumentSetResponseFilter.filterByPatientAndAuthor(response, patientId, authorNPI); }
@Test public void testFilterByPatientAndAuthor2() throws XdsbRepositoryAdapterException { RetrieveDocumentSetResponse response = mock(RetrieveDocumentSetResponse.class); String patientId = "1"; String authorNPI = "2"; LinkedList<DocumentResponse> docList = new LinkedList<DocumentResponse>(); when(response.getDocumentResponse()).thenReturn(docList); retrieveDocumentSetResponseFilter.filterByPatientAndAuthor(response, patientId, authorNPI); }