AdapterComponentDocRepositoryHelper { long queryRepositoryByPatientId(String sPatId, String sDocId, String sClassCode, String sStatus, DocumentService docService) { long nhincDocRepositoryDocId = 0; DocumentQueryParams params = new DocumentQueryParams(); params.setPatientId(sPatId); List<String> lClassCodeList = new ArrayList<>(); lClassCodeList.add(sClassCode); params.setClassCodes(lClassCodeList); List<String> lStatus = new ArrayList<>(); lStatus.add(sStatus); params.setStatuses(lStatus); List<DocumentMetadata> documents = docService.documentQuery(params); if (NullChecker.isNotNullish(documents)) { LOG.debug("queryRepositoryByPatientId {} documents for patient: {}", documents.size(), sPatId); for (DocumentMetadata doc : documents) { LOG.debug("queryRepositoryByPatientId - sDocId: {}", sDocId); if (sDocId.equals(doc.getDocumentUniqueId())) { nhincDocRepositoryDocId = doc.getDocumentid(); break; } } } return nhincDocRepositoryDocId; }    }
@Test public void testQueryRepositoryByPatientId() { AdapterComponentDocRepositoryHelper docRepoHelper = new AdapterComponentDocRepositoryHelper(); final String SPATID = "sPatId"; final String SDOCID = "Doc ID 1"; final String SCLASSCODE = "sClassCode"; final String ESTATUS = "sStatus"; final String DOC_UNIQUE_ID = "Doc ID 1"; final long DOC_ID = 12345; DocumentService docService = mock(DocumentService.class); List<DocumentMetadata> documents = new ArrayList<>(); DocumentMetadata doc = mock(DocumentMetadata.class); documents.add(doc); when(docService.documentQuery(any(DocumentQueryParams.class))).thenReturn(documents); when(doc.getDocumentUniqueId()).thenReturn(DOC_UNIQUE_ID); when(doc.getDocumentid()).thenReturn(DOC_ID); long result = docRepoHelper.queryRepositoryByPatientId(SPATID, SDOCID, SCLASSCODE, ESTATUS, docService); assertEquals(result, DOC_ID); }