JMeadowsLabService implements IJMeadowsLabService { public List<VistaDataChunk> fetchDodPatientLabs(JMeadowsQuery query, PatientIds patientIds) throws JMeadowsException_Exception { LOG.debug("JMeadowsLabService.fetchDodPatientLabs - Entering method..."); List<VistaDataChunk> oaLabChunk = new ArrayList<VistaDataChunk>(); List<LabResult> oaLabResults = jMeadowsClient.getPatientLabResults(query); LOG.debug("JMeadowsLabService.fetchDodPatientLabs: " + ((oaLabResults == null)? "NO" : ""+oaLabResults.size()) + " Labs retrieved from JMeadows."); if ((oaLabResults != null) && (oaLabResults.size() > 0)) { oaLabResults = (List<LabResult>) filterOnSourceProtocol(oaLabResults, SOURCE_PROTOCOL_DODADAPTER); int iNumLabs = calculateNumLabs(oaLabResults); int iCurLabIdx = 1; for(LabResult oLab : oaLabResults) { LOG.debug("JMeadowsLabService.fetchDodPatientLabs: Found DoD LabResult - Processing it... idx: " + iCurLabIdx); VistaDataChunk[] oLabChunk = transformLabChunk(oLab, patientIds, iNumLabs, iCurLabIdx); if (oLabChunk != null) { oaLabChunk.add(oLabChunk[0]); String accession = oLab.getAccession(); if (accession != null && !accession.toUpperCase().contains("^CH")) { oaLabChunk.add(oLabChunk[1]); } iCurLabIdx++; } } } return oaLabChunk; } @Autowired  JMeadowsLabService(JMeadowsConfiguration jMeadowsConfiguration); void setJMeadowsClient(JMeadowsData jMeadowsClient); List<VistaDataChunk> fetchDodPatientLabs(JMeadowsQuery query, PatientIds patientIds); static final String DOMAIN_LAB; static final String DOMAIN_DOCUMENT; }
@Test public void testFetchPatientLabs() { try { when(this.mockJMeadowsClient.getPatientLabResults(any(JMeadowsQuery.class))).thenReturn(createTestLabData()); 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 = jMeadowsLabService.fetchDodPatientLabs(query, patientIds); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(6)); List<LabResult> testDataList = createTestLabData(); if (testDataList.size() > 0) { VistaDataChunk vistaDataChunk = vistaDataChunkList.get(0); assertThat(JMeadowsLabService.DOMAIN_LAB, is(vistaDataChunk.getDomain())); assertThat(4, 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("DOD;" + edipi, is(vistaDataChunk.getPatientId())); assertThat("vrpcb: assertThat(VistaDataChunk.NEW_OR_UPDATE, is(vistaDataChunk.getType())); Map<String,Object> jsonMap = vistaDataChunk.getJsonMap(); LabResult testLab = testDataList.get(0); assertThat("DOD", is(jsonMap.get("facilityCode"))); assertThat(testLab.getFacilityName(), is(jsonMap.get("facilityName"))); assertThat(testLab.getTestName(), is(jsonMap.get("displayName"))); assertThat(testLab.getSpecimen(), is(jsonMap.get("specimen"))); assertThat(testLab.getOrderId(), is(jsonMap.get("orderId"))); assertThat(testLab.getResult(), is(jsonMap.get("result"))); String labOrderDate = (String) jsonMap.get("observed"); String escapedAccession = testLab.getAccession().replaceAll("[\\s, ^, :]", "-"); if (testLab.getAccession().contains("CH")) { assertThat("urn:va:lab-category:CH", is(jsonMap.get("categoryCode"))); Double low = Double.parseDouble((String) jsonMap.get("low")); assertThat(low, notNullValue()); Double high = Double.parseDouble((String) jsonMap.get("high")); assertThat(high, notNullValue()); assertThat(testLab.getUnits(), is(jsonMap.get("units"))); assertThat("Laboratory", is(jsonMap.get("kind"))); assertThat(testLab.getTestName(), is(jsonMap.get("typeName"))); String abnormalFlag = (String) jsonMap.get("interpretationCode"); assertNotNull(abnormalFlag); assertTrue(abnormalFlag.equals("urn:hl7:observation-interpretation:H") || abnormalFlag.equals("urn:hl7:observation-interpretation:L") || abnormalFlag.equals("urn:hl7:observation-interpretation:HH") || abnormalFlag.equals("urn:hl7:observation-interpretation:LL")); String abnormalFlagName = (String) jsonMap.get("interpretationName"); assertNotNull(abnormalFlagName); assertTrue(abnormalFlagName.equals("High") || abnormalFlagName.equals("Low") || abnormalFlagName.equals("High alert") || abnormalFlagName.equals("Low alert")); String testUid = String.format("urn:va:lab:DOD:%s:%s_%s_%s", edipi, labOrderDate, escapedAccession, testLab.getCodes().get(0).getCode()); assertThat(testUid, is(jsonMap.get("uid"))); } else if (testLab.getAccession().contains("AP")) { assertThat("urn:va:lab-category:AP", is(jsonMap.get("categoryCode"))); assertThat("Pathology", is(jsonMap.get("kind"))); assertThat(null, is(jsonMap.get("typeName"))); String testUid = String.format("urn:va:lab:DOD:%s:%s_%s", edipi, labOrderDate, escapedAccession); assertThat(testUid, is(jsonMap.get("uid"))); } else if (testLab.getAccession().contains("MI")) { assertThat("urn:va:lab-category:MI", is(jsonMap.get("categoryCode"))); assertThat("Microbiology", is(jsonMap.get("kind"))); assertThat(null, is(jsonMap.get("typeName"))); String testUid = String.format("urn:va:lab:DOD:%s:%s_%s", edipi, labOrderDate, escapedAccession); assertThat(testUid, is(jsonMap.get("uid"))); } assertThat(testLab.getComment(), is(jsonMap.get("comment"))); } } catch (JMeadowsException_Exception e) { fail(e.getMessage()); } }
@Test public void testNullAndEmptyLabList() { try { when(this.mockJMeadowsClient.getPatientLabResults(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 = jMeadowsLabService.fetchDodPatientLabs(query, patientIds); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); when(this.mockJMeadowsClient.getPatientLabResults(any(JMeadowsQuery.class))).thenReturn(new ArrayList<LabResult>()); assertNotNull(vistaDataChunkList); assertThat(vistaDataChunkList.size(), is(0)); } catch (JMeadowsException_Exception e) { fail(e.getMessage()); } }