JMeadowsConsultNoteService implements IJMeadowsConsultNoteService { @Override public List<VistaDataChunk> fetchDodConsults(JMeadowsQuery oQuery, PatientIds oPatientIds) throws JMeadowsException_Exception { LOG.debug("JMeadowsClinicalNoteService.fetchDodNotes - Entering method..."); validateParams(oQuery, oPatientIds, USER, PATIENT); List<VistaDataChunk> oaDocumentChunk = new ArrayList<>(); List<Consult> oConsults = jMeadowsClient.getPatientConsultRequests(oQuery); if (LOG.isDebugEnabled() && oConsults != null) { LOG.debug("JMeadowsConsultNoteService.fetchDodConsults: " + ((oConsults == null) ? "NO" : "" + oConsults.size()) + " results retrieved from JMeadows."); } if ((oConsults != null) && (oConsults.size() > 0)) { oConsults = (List<Consult>) filterOnSourceProtocol(oConsults, SOURCE_PROTOCOL_DODADAPTER); int iNumNotes = calculateNumConsults(oConsults); Map<Document, Future<Document>> queuedDodDocumentServiceRequestMap = new LinkedHashMap<>(); List<Document> oaVprDocuments = new ArrayList<>(); for (Consult oConsult : oConsults) { LOG.debug("JMeadowsConsultNoteService.fetchDodConsults: Found DoD consult note - Transforming it..."); Document oVprDocument = transformConsult(oConsult, "DOD", oPatientIds.getEdipi()); if (oVprDocument != null) { if (dodDocServiceEnabled && StringUtils.isNotBlank(oConsult.getComplexDataUrl())) { Future<Document> documentFuture = queueRTFDocumentServiceRequest(oConsult.getComplexDataUrl(), oPatientIds, getEventId(oVprDocument.getUid()), oVprDocument); queuedDodDocumentServiceRequestMap.put(oVprDocument, documentFuture); } else { if (StringUtils.isNotBlank(oConsult.getComplexDataUrl())) { oVprDocument.setData("dodComplexNoteUri", "Complex note unavailable: DoD Document Service is disabled."); } oaVprDocuments.add(oVprDocument); } } } for (Map.Entry<Document, Future<Document>> entry : queuedDodDocumentServiceRequestMap.entrySet()) try { LOG.debug("Processing DoD RTF for document with UID: " + entry.getKey().getUid()); Future<Document> future = entry.getValue(); Document oVprDocument = future.get(); oaVprDocuments.add(oVprDocument); } catch (Exception e) { oaVprDocuments.add(entry.getKey()); LOG.error("An error occurred while processing DoD RTF note. The note text and attached note will be excluded from result.::" + e.getMessage(), e); } int iCurNoteIdx = 1; for (Document oVprDocument : oaVprDocuments) { LOG.debug("JMeadowsProgressNoteService.fetchDodConsults: Found DoD consult note - Processing it... idx: " + iCurNoteIdx); VistaDataChunk oNoteChunk = transformDocumentChunk(oVprDocument, oPatientIds, iNumNotes, iCurNoteIdx); if (oNoteChunk != null) { oaDocumentChunk.add(oNoteChunk); iCurNoteIdx++; } } } return oaDocumentChunk; } @Autowired  JMeadowsConsultNoteService(JMeadowsConfiguration jMeadowsConfiguration); @Autowired void setDodDocumentService(IDodDocumentService dodDocumentService); void setJMeadowsClient(JMeadowsData jMeadowsClient); @Override List<VistaDataChunk> fetchDodConsults(JMeadowsQuery oQuery, PatientIds oPatientIds); static final String DOMAIN_DOCUMENT; }
@Test public void testFetchDodConsults() { try { when(this.mockJMeadowsClient.getPatientConsultRequests(any(JMeadowsQuery.class))).thenReturn(createTestData()); JMeadowsQuery query = new JMeadowsQueryBuilder() .user(user) .patient(patient) .build(); PatientIds patientIds = new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .edipi(edipi) .build(); List<VistaDataChunk> vistaDataChunkList = jMeadowsConsultNoteService.fetchDodConsults(query, patientIds); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(2)); List<Consult> testDataList = createTestData(); for (int i = 0; i < vistaDataChunkList.size(); i++) { VistaDataChunk vistaDataChunk = vistaDataChunkList.get(i); assertThat(JMeadowsNoteService.DOMAIN_DOCUMENT, is(vistaDataChunk.getDomain())); assertThat(2, is(vistaDataChunk.getItemCount())); assertThat(i + 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("DOD;" + edipi, is(vistaDataChunk.getPatientId())); assertThat("vrpcb: assertThat(VistaDataChunk.NEW_OR_UPDATE, is(vistaDataChunk.getType())); Map<String, Object> jsonMap = vistaDataChunk.getJsonMap(); Consult testConsult = testDataList.get(i); assertThat("DOD", is(jsonMap.get("facilityCode"))); assertThat("DOD", is(jsonMap.get("facilityName"))); if (testConsult.getCdrEventId() == null) { MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); messageDigest.update(testConsult.getReport().getBytes("UTF-8")); byte[] bHash = messageDigest.digest(); BigInteger bigInteger = new BigInteger(1, bHash); String sHash = bigInteger.toString(16); String eventId = String.format("%s_%s", sHash, formatCalendar(testConsult.getRequestDate().toGregorianCalendar())); assertThat("urn:va:document:DOD:" + edipi + ":" + eventId, is(jsonMap.get("uid"))); } else { assertThat("urn:va:document:DOD:" + edipi + ":" + testConsult.getCdrEventId(), is(jsonMap.get("uid"))); } assertThat(testConsult.getService(), is(jsonMap.get("localTitle"))); assertThat(testConsult.getProcedureConsult(), is(jsonMap.get("documentTypeName"))); assertThat(formatCalendar(testConsult.getRequestDate().toGregorianCalendar()), is(jsonMap.get("referenceDateTime"))); List<Map<String, Object>> documentTextList = (List<Map<String, Object>>) jsonMap.get("text"); Map<String, Object> docTextJsonMap = documentTextList.get(0); if (StringUtils.isNotBlank(testConsult.getComplexDataUrl())) { assertNotNull(docTextJsonMap.get("content")); assertThat(formatCalendar(testConsult.getRequestDate().toGregorianCalendar()), is(docTextJsonMap.get("dateTime"))); assertNotNull(jsonMap.get("dodComplexNoteUri")); } else { assertThat(testConsult.getReport(), is(docTextJsonMap.get("content"))); assertThat(formatCalendar(testConsult.getRequestDate().toGregorianCalendar()), is(docTextJsonMap.get("dateTime"))); } List<Map<String, Object>> codes = (List<Map<String, Object>>) jsonMap.get("codes"); assertThat(JLVTerminologySystem.LOINC.getUrn(), is(codes.get(0).get("system"))); } } catch (Exception e) { fail(e.getMessage()); } }
@Test public void testNullAndEmptyVitalList() { try { when(this.mockJMeadowsClient.getPatientProgressNotes(any(JMeadowsQuery.class))).thenReturn(null); JMeadowsQuery query = new JMeadowsQueryBuilder() .user(user) .patient(patient) .build(); PatientIds patientIds = new PatientIds.Builder() .pid(pid) .icn(icn) .uid(uid) .edipi(edipi) .build(); List<VistaDataChunk> vistaDataChunkList = jMeadowsConsultNoteService.fetchDodConsults(query, patientIds); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); when(this.mockJMeadowsClient.getPatientVitals(any(JMeadowsQuery.class))).thenReturn(new ArrayList<Vitals>()); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); } catch (JMeadowsException_Exception e) { fail(e.getMessage()); } }