VlerService implements IVlerService { protected List<VLERDoc> retrieveVlerDocuments(VlerQuery query) { long startTime, endTime; startTime = System.currentTimeMillis(); VLERDocQueryResponse vlerDocQueryResponse = vlerDocumentService.retrieveVlerDocumentList(query); if (vlerDocQueryResponse.isError()) { LOG.error("VlerService.retrieveVlerDocument An error occurred::" + vlerDocQueryResponse.getErrorMsg()); throw new VlerServiceException(vlerDocQueryResponse.getErrorMsg()); } List<VLERDoc> vlerMetaDocumentList = vlerDocQueryResponse.getDocumentList(); endTime = System.currentTimeMillis(); LOG.debug("VlerService.getVlerDocuments: fetched VLER document list - count: {}, completed in {} ms", vlerMetaDocumentList != null ? vlerMetaDocumentList.size() : "is null", (endTime-startTime)); if (vlerMetaDocumentList == null) return null; final String KEY_VLER_FUTURE = "future"; final String KEY_VLER_METADATA = "vlerMetadata"; List<Map<String, Object>> vlerMetaFutureMapList = new ArrayList<>(); for(VLERDoc vlerMetaDoc : vlerMetaDocumentList) { Map<String, Object> vlerMetaFutureMap = new HashMap<>(); vlerMetaFutureMap.put(KEY_VLER_METADATA, vlerMetaDoc); VlerQuery vlerDocRetrieveQuery = new VlerQuery(); vlerDocRetrieveQuery.setVlerDoc(vlerMetaDoc); vlerDocRetrieveQuery.setPatientIds(query.getPatientIds()); vlerMetaFutureMap.put(KEY_VLER_FUTURE, vlerDocumentService.retrieveVlerDocument(vlerDocRetrieveQuery)); vlerMetaFutureMapList.add(vlerMetaFutureMap); } List<VLERDoc> vlerDocumentList = new ArrayList<>(); for(Map<String, Object> vlerMap : vlerMetaFutureMapList) { try { Future vlerFuture = (Future) vlerMap.get(KEY_VLER_FUTURE); VLERDocRetrieveResponse vlerDocRetrieveResponse = (VLERDocRetrieveResponse) vlerFuture.get(); vlerDocumentList.add(vlerDocRetrieveResponse.getVlerDoc()); } catch (InterruptedException | ExecutionException e) { VlerDocument vlerMetaDoc = (VlerDocument) vlerMap.get(KEY_VLER_METADATA); LOG.error("An error occurred while retrieving VLER document.", e); LOG.debug("Failed to fetch vler document! Document Id: " + vlerMetaDoc.getDocumentUniqueId() + " Home Community Id: " + vlerMetaDoc.getHomeCommunityId() + " Repository Id: " + vlerMetaDoc.getRepositoryUniqueId()); } } return vlerDocumentList; } @Autowired  VlerService(IRetrieveVlerDocumentService vlerDocumentService); List<VistaDataChunk> fetchVlerData(PatientIds patientIds); static final String DOMAIN_VLER_DOCUMENT; }
@Test public void testRetrieveVlerDocuments() { VlerQuery query = new VlerQuery(); query.setPatientIds(new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .build()); List<VLERDoc> vlerDocuments = vlerService.retrieveVlerDocuments(query); assertNotNull(vlerDocuments); assertThat(vlerDocuments.size(), is(1)); for(VLERDoc doc : vlerDocuments) { assertThat(doc.getMimeType(), is(testC32Document.getMimeType())); assertThat(doc.getCreationTime(), is(testC32Document.getCreationTime())); assertThat(doc.getDocument(), is(testC32Document.getDocument())); assertThat(doc.getDocumentUniqueId(), is(testC32Document.getDocumentUniqueId())); assertThat(doc.getHomeCommunityId(), is(testC32Document.getHomeCommunityId())); assertThat(doc.getName(), is(testC32Document.getName())); assertThat(doc.getRepositoryUniqueId(), is(testC32Document.getRepositoryUniqueId())); assertThat(doc.getSourcePatientId(), is(testC32Document.getSourcePatientId())); for(Author author : doc.getAuthorList()) { assertThat(author.getName(), is(testC32Document.getAuthorList().get(0).getName())); assertThat(author.getInstitution(), is(testC32Document.getAuthorList().get(0).getInstitution())); } } }