JMeadowsLabService implements IJMeadowsLabService { protected Map<String, String> parseReferenceRange(String referenceRange) { Matcher matcher = this.referenceRangePattern.matcher(referenceRange); Map<String, String> refRangeMap = new HashMap<>(); try { if(matcher.find() && matcher.groupCount() == 2) { String low = matcher.group(1); String high = matcher.group(2); if (StringUtils.hasText(low)) { if (low.contains(".")) low = new Double(low).toString(); else low = new Integer(low).toString(); } if (StringUtils.hasText(high)) { if (high.contains(".")) high = new Double(high).toString(); else high = new Integer(high).toString(); } if (StringUtils.hasText(low) && StringUtils.hasText(high)) { refRangeMap.put("low", low); refRangeMap.put("high", high); } } } catch (IllegalStateException | IndexOutOfBoundsException | NumberFormatException e){ LOG.warn("An error occurred while parsing lab reference range.", e); } return refRangeMap; } @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 testParseReferenceRange() { Map<String, String> refRangeMap = jMeadowsLabService.parseReferenceRange(".2-1.3"); assertThat(refRangeMap.get("low"), is("0.2")); assertThat(refRangeMap.get("high"), is("1.3")); refRangeMap = jMeadowsLabService.parseReferenceRange("6.3-8.2"); assertThat(refRangeMap.get("low"), is("6.3")); assertThat(refRangeMap.get("high"), is("8.2")); refRangeMap = jMeadowsLabService.parseReferenceRange("6.3-.22"); assertThat(refRangeMap.get("low"), is("6.3")); assertThat(refRangeMap.get("high"), is("0.22")); refRangeMap = jMeadowsLabService.parseReferenceRange(".35-4.94"); assertThat(refRangeMap.get("low"), is("0.35")); assertThat(refRangeMap.get("high"), is("4.94")); refRangeMap = jMeadowsLabService.parseReferenceRange("0.0-2.5"); assertThat(refRangeMap.get("low"), is("0.0")); assertThat(refRangeMap.get("high"), is("2.5")); refRangeMap = jMeadowsLabService.parseReferenceRange("0-400"); assertThat(refRangeMap.get("low"), is("0")); assertThat(refRangeMap.get("high"), is("400")); refRangeMap = jMeadowsLabService.parseReferenceRange("(25-28.5)"); assertThat(refRangeMap.get("low"), is("25")); assertThat(refRangeMap.get("high"), is("28.5")); refRangeMap = jMeadowsLabService.parseReferenceRange("0-40.5"); assertThat(refRangeMap.get("low"), is("0")); assertThat(refRangeMap.get("high"), is("40.5")); refRangeMap = jMeadowsLabService.parseReferenceRange("2.5-10)"); assertThat(refRangeMap.get("low"), is("2.5")); assertThat(refRangeMap.get("high"), is("10")); refRangeMap = jMeadowsLabService.parseReferenceRange("(5 - 200)"); assertThat(refRangeMap.get("low"), is("5")); assertThat(refRangeMap.get("high"), is("200")); refRangeMap = jMeadowsLabService.parseReferenceRange("(5.2 - 21.7)"); assertThat(refRangeMap.get("low"), is("5.2")); assertThat(refRangeMap.get("high"), is("21.7")); refRangeMap = jMeadowsLabService.parseReferenceRange("(.23 - .5)"); assertThat(refRangeMap.get("low"), is("0.23")); assertThat(refRangeMap.get("high"), is("0.5")); refRangeMap = jMeadowsLabService.parseReferenceRange("2.5-somestringvalue"); assertTrue(refRangeMap.isEmpty()); refRangeMap = jMeadowsLabService.parseReferenceRange("somestringvalue-22.5"); assertTrue(refRangeMap.isEmpty()); refRangeMap = jMeadowsLabService.parseReferenceRange("(string - otherstring)"); assertTrue(refRangeMap.isEmpty()); refRangeMap = jMeadowsLabService.parseReferenceRange("NEGATIVE"); assertTrue(refRangeMap.isEmpty()); refRangeMap = jMeadowsLabService.parseReferenceRange("null"); assertTrue(refRangeMap.isEmpty()); }