VlerService implements IVlerService { public List<VistaDataChunk> fetchVlerData(PatientIds patientIds) { LOG.debug("VlerService.fetchVlerData - Entering method..."); if (patientIds == null || StringUtils.isBlank(patientIds.getIcn())) throw new IllegalArgumentException("Missing patient icn"); List<VistaDataChunk> vlerDocChunks = new ArrayList<>(); VlerQuery query = new VlerQuery(); query.setPatientIds(patientIds); List<VLERDoc> vlerDocuments = retrieveVlerDocuments(query); LOG.debug("VlerService.fetchVlerData: " + ((vlerDocuments == null) ? "NO" : "" + vlerDocuments.size()) + " results retrieved from JMeadows."); if ((vlerDocuments != null) && (vlerDocuments.size() > 0)) { int curVlerDocIdx = 1; for (VLERDoc vlerDocument : vlerDocuments) { LOG.debug("VlerService.fetchVlerData: Found VLER Document - Processing it... idx: " + curVlerDocIdx); VistaDataChunk vlerDocChunk = transformVlerDocChunk(vlerDocument, query.getPatientIds(), vlerDocuments.size(), curVlerDocIdx); if (vlerDocChunk != null) { vlerDocChunks.add(vlerDocChunk); curVlerDocIdx++; } } } return vlerDocChunks; } @Autowired  VlerService(IRetrieveVlerDocumentService vlerDocumentService); List<VistaDataChunk> fetchVlerData(PatientIds patientIds); static final String DOMAIN_VLER_DOCUMENT; }
@Test public void testFetchC32Data() { PatientIds patientIds = new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .build(); List<VistaDataChunk> vistaDataChunkList = vlerService.fetchVlerData(patientIds); assertThat(vistaDataChunkList.size(), is(1)); VistaDataChunk vistaDataChunk = vistaDataChunkList.get(0); assertThat(VlerService.DOMAIN_VLER_DOCUMENT, is(vistaDataChunk.getDomain())); assertThat(1, is(vistaDataChunk.getItemCount())); assertThat(1, is(vistaDataChunk.getItemIndex())); assertThat(vistaId, is(vistaDataChunk.getParams().get("vistaId"))); assertThat(dfn, is(vistaDataChunk.getParams().get("patientDfn"))); assertThat(vistaId, is(vistaDataChunk.getSystemId())); assertThat(dfn, is(vistaDataChunk.getLocalPatientId())); assertThat(icn, is(vistaDataChunk.getPatientIcn())); assertThat(pid, is(vistaDataChunk.getPatientId())); assertThat("vrpcb: assertThat(VistaDataChunk.NEW_OR_UPDATE, is(vistaDataChunk.getType())); Map<String,Object> jsonMap = vistaDataChunk.getJsonMap(); assertThat("C32 Document", is(jsonMap.get("kind"))); assertThat("urn:va:vlerdocument:VLER:"+icn+":"+testC32Document.getDocumentUniqueId(), is(jsonMap.get("uid"))); assertThat(testC32Document.getName(), is(jsonMap.get("name"))); assertThat(testDocDateTime, is(jsonMap.get("creationTime"))); assertThat("Continuity of Care Document", is(jsonMap.get("summary"))); assertThat(testC32Document.getDocumentUniqueId(), is(jsonMap.get("documentUniqueId"))); assertThat(testC32Document.getHomeCommunityId(), is(jsonMap.get("homeCommunityId"))); assertThat(testC32Document.getMimeType(), is(jsonMap.get("mimeType"))); assertThat(testC32Document.getRepositoryUniqueId(), is(jsonMap.get("repositoryUniqueId"))); assertThat(testC32Document.getSourcePatientId(), is(jsonMap.get("sourcePatientId"))); List sectionList = (List) jsonMap.get("sections"); assertThat(sectionList.size(), is(12)); testC32SectionList(sectionList); }
@Test public void testFetchCCDAData() { when(mockDocRetrieveResponse.getVlerDoc()).thenReturn(testCCDADocument); PatientIds patientIds = new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .build(); List<VistaDataChunk> vistaDataChunkList = vlerService.fetchVlerData(patientIds); assertThat(vistaDataChunkList.size(), is(1)); VistaDataChunk vistaDataChunk = vistaDataChunkList.get(0); assertThat(VlerService.DOMAIN_VLER_DOCUMENT, is(vistaDataChunk.getDomain())); assertThat(1, is(vistaDataChunk.getItemCount())); assertThat(1, is(vistaDataChunk.getItemIndex())); assertThat(vistaId, is(vistaDataChunk.getParams().get("vistaId"))); assertThat(dfn, is(vistaDataChunk.getParams().get("patientDfn"))); assertThat(vistaId, is(vistaDataChunk.getSystemId())); assertThat(dfn, is(vistaDataChunk.getLocalPatientId())); assertThat(icn, is(vistaDataChunk.getPatientIcn())); assertThat(pid, is(vistaDataChunk.getPatientId())); assertThat("vrpcb: assertThat(VistaDataChunk.NEW_OR_UPDATE, is(vistaDataChunk.getType())); Map<String,Object> jsonMap = vistaDataChunk.getJsonMap(); assertThat("C32 Document", is(jsonMap.get("kind"))); assertThat("urn:va:vlerdocument:VLER:"+icn+":"+testCCDADocument.getDocumentUniqueId(), is(jsonMap.get("uid"))); assertThat(testCCDADocument.getName(), is(jsonMap.get("name"))); assertThat(testDocDateTime, is(jsonMap.get("creationTime"))); assertThat("Continuity of Care Document", is(jsonMap.get("summary"))); assertThat(testCCDADocument.getDocumentUniqueId(), is(jsonMap.get("documentUniqueId"))); assertThat(testCCDADocument.getHomeCommunityId(), is(jsonMap.get("homeCommunityId"))); assertThat(testCCDADocument.getMimeType(), is(jsonMap.get("mimeType"))); assertThat(testCCDADocument.getRepositoryUniqueId(), is(jsonMap.get("repositoryUniqueId"))); assertThat(testCCDADocument.getSourcePatientId(), is(jsonMap.get("sourcePatientId"))); List sectionList = (List) jsonMap.get("sections"); assertThat(sectionList.size(), is(13)); testCCDASectionList(sectionList); }
@Test public void testNullAndEmptyVlerDocumentList() { when(mockDocQueryResponse.getDocumentList()).thenReturn(null); PatientIds patientIds = new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .build(); List<VistaDataChunk> vistaDataChunkList = vlerService.fetchVlerData(patientIds); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); when(mockDocQueryResponse.getDocumentList()).thenReturn(new ArrayList<VLERDoc>()); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); }