TrendController { protected List<Map<String, Object>> createTrendData(List<? extends IPatientObject> items) { List chartData = new ArrayList(); for (IPatientObject item : items) { Map<String, Object> itemData = item.getData(); PointInTime observed = HL7DateTimeFormat.parse((String) itemData.get("observed")); Long jsDate = observed != null ? pitToJsDate(observed) : null; String resultStr = (String) itemData.get("result"); try { Float result = StringUtils.hasText(resultStr) ? Float.valueOf(resultStr) : null; if (jsDate != null && result != null) { LinkedHashMap<String, Object> map = new LinkedHashMap<>(2); map.put("x", jsDate); map.put("y", result); for (String key : Arrays.asList("interpretationCode", "comment", "high", "low", "units")) { String val = (String) itemData.get(key); if (StringUtils.hasText(val)) { map.put(key, val); } } if (itemData.containsKey("interpretationCode")) { String displayInterpretationCode = Result.getDisplayInterpretationCode((String) itemData.get("interpretationCode")); map.put("displayInterpretationCode", displayInterpretationCode); } chartData.add(map); } } catch (NumberFormatException e) { } } return chartData; }  @Autowired void setLinkService(ILinkService linkService); @Autowired void setGenericPatientObjectDao(IGenericPatientObjectDAO genericPatientObjectDao); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=xml") String renderXml(HttpServletRequest request); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=json") ModelAndView renderJson(HttpServletRequest request); @RequestMapping(value = "/vpr/trend/**", method = RequestMethod.GET, params = "format=extjs") @ResponseBody String renderExtJs(@RequestParam("format") String format, HttpServletRequest request); static final String LAB_INDEX; static final String VITAL_INDEX; }
@Test public void testCreateTrendData() throws Exception { List<Result> list = new ArrayList(); Map<String, Object> map = new LinkedHashMap<>(10); map.put("pid", "123"); map.put("facilityName", "SLC-FO HMP DEV"); map.put("high", 100); map.put("low", "Neg."); map.put("observed", "20120529180230.000"); map.put("result", 12.5f); map.put("specimen", "URINE"); map.put("typeName", "URINE GLUCOSE"); map.put("uid", "urn:va:lab:F484:8:CH;6879469.819787;690"); map.put("units", "mg/dL"); map.put("comment", "foo"); Result result = new Result(map); list.add(result); List<Map<String,Object>> trendData = tc.createTrendData(list); assertEquals(1, trendData.size()); DateTime t = new DateTime(2012, 5, 29, 18, 2, 30, 0); Map<String, Object> map1 = new LinkedHashMap<>(2); map1.put("x", t.getMillis()); map1.put("y", 12.5f); map1.put("high", 100); map1.put("low", "Neg."); map1.put("units", "mg/dL"); assertEquals(1, trendData.size()); Map<String,Object> ret = trendData.get(0); assertEquals(t.getMillis(), ret.get("x")); assertEquals(12.5f, ret.get("y")); assertEquals("100", ret.get("high")); assertEquals("Neg.", ret.get("low")); assertEquals("mg/dL", ret.get("units")); assertEquals("foo", ret.get("comment")); }
@Test public void testCreateTrendData_ResultMissing() throws Exception { List list = new ArrayList(); LinkedHashMap<String, Object> map = new LinkedHashMap<>(10); map.put("pid", "123"); map.put("facilityName", "SLC-FO HMP DEV"); map.put("high", 100); map.put("low", "Neg."); map.put("observed", null); map.put("result", "Neg."); map.put("specimen", "URINE"); map.put("typeName", "URINE GLUCOSE"); map.put("uid", "urn:va:lab:F484:8:CH;6879469.819787;690"); map.put("units", "mg/dL"); Result result = new Result(map); list.add(result); List trendData = tc.createTrendData(list); assertEquals(0, trendData.size()); }
@Test public void testCreateTrendData_NoObserved() throws Exception { List list = new ArrayList(); LinkedHashMap<String, Object> map = new LinkedHashMap<>(9); map.put("pid", "123"); map.put("facilityName", "SLC-FO HMP DEV"); map.put("high", 100); map.put("low", "Neg."); map.put("result", "12"); map.put("specimen", "URINE"); map.put("typeName", "URINE GLUCOSE"); map.put("uid", "urn:va:lab:F484:8:CH;6879469.819787;690"); map.put("units", "mg/dL"); Result result = new Result(map); list.add(result); List trendData = tc.createTrendData(list); assertEquals(0, trendData.size()); }
@Test public void testCreateTrendData_ObservedIncomplete() throws Exception { List list = new ArrayList(); LinkedHashMap<String, Object> map = new LinkedHashMap<>(10); map.put("pid", "123"); map.put("facilityName", "SLC-FO HMP DEV"); map.put("observed", 201209); map.put("result", "12"); map.put("high", 100); map.put("low", "Neg."); map.put("specimen", "URINE"); map.put("typeName", "URINE GLUCOSE"); map.put("uid", "urn:va:lab:F484:8:CH;6879469.819787;690"); map.put("units", "mg/dL"); Result result = new Result(map); list.add(result); List trendData = tc.createTrendData(list); assertEquals(0, trendData.size()); }