@Test public void testSearchDiagnosisByDescriptionWithOrdinaryValue() { String searchTerm = "infekt"; int greaterThanZero = Integer.MAX_VALUE - 1; DiagnosResponse result = service.searchDiagnosisByDescription(searchTerm, ICD_10, greaterThanZero); assertThat(result, Matchers.<DiagnosResponse>allOf( is(notNullValue()), is(either( allOf( hasProperty("resultat", equalTo(DiagnosResponseType.OK)), hasProperty("diagnoser", hasSize(greaterThan(0))))) .or(hasProperty("resultat", equalTo(DiagnosResponseType.NOT_FOUND)))))); assertEquals("Null should return invalid", DiagnosResponseType.INVALID_SEARCH_STRING, service.searchDiagnosisByDescription(null, ICD_10, 5).getResultat()); assertEquals("Empty should return invalid", DiagnosResponseType.INVALID_SEARCH_STRING, service.searchDiagnosisByDescription("", ICD_10, 5).getResultat()); assertEquals("Spaces should return invalid", DiagnosResponseType.INVALID_SEARCH_STRING, service.searchDiagnosisByDescription(" ", ICD_10, 5).getResultat()); }
@Override public DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults) { Assert.isTrue(nbrOfResults + 1 > 1, "nbrOfResults must be larger that 0"); if (Strings.nullToEmpty(searchString).trim().isEmpty()) { return DiagnosResponse.invalidSearchString(); } Diagnoskodverk codeSystem = getDiagnoskodverk(codeSystemStr); List<Diagnos> matches; if (codeSystem == null) { LOG.warn("Code system is null"); return DiagnosResponse.invalidCodesystem(); } switch (codeSystem) { case ICD_10_SE: matches = icd10seDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.ICD_10_SE); break; case KSH_97_P: matches = ksh97pDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.KSH_97_P); break; default: LOG.warn("Unknown code system '{}'", codeSystem); return DiagnosResponse.invalidCodesystem(); } if (matches.isEmpty()) { return DiagnosResponse.notFound(); } if (matches.size() <= nbrOfResults) { return DiagnosResponse.ok(matches, false); } LOG.debug("Returning {} diagnosises out of a match of {}", nbrOfResults, matches.size()); return DiagnosResponse.ok(matches.subList(0, nbrOfResults), true); }
DiagnosServiceImpl implements DiagnosService { @Override public DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults) { Assert.isTrue(nbrOfResults + 1 > 1, "nbrOfResults must be larger that 0"); if (Strings.nullToEmpty(searchString).trim().isEmpty()) { return DiagnosResponse.invalidSearchString(); } Diagnoskodverk codeSystem = getDiagnoskodverk(codeSystemStr); List<Diagnos> matches; if (codeSystem == null) { LOG.warn("Code system is null"); return DiagnosResponse.invalidCodesystem(); } switch (codeSystem) { case ICD_10_SE: matches = icd10seDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.ICD_10_SE); break; case KSH_97_P: matches = ksh97pDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.KSH_97_P); break; default: LOG.warn("Unknown code system '{}'", codeSystem); return DiagnosResponse.invalidCodesystem(); } if (matches.isEmpty()) { return DiagnosResponse.notFound(); } if (matches.size() <= nbrOfResults) { return DiagnosResponse.ok(matches, false); } LOG.debug("Returning {} diagnosises out of a match of {}", nbrOfResults, matches.size()); return DiagnosResponse.ok(matches.subList(0, nbrOfResults), true); } }
DiagnosServiceImpl implements DiagnosService { @Override public DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults) { Assert.isTrue(nbrOfResults + 1 > 1, "nbrOfResults must be larger that 0"); if (Strings.nullToEmpty(searchString).trim().isEmpty()) { return DiagnosResponse.invalidSearchString(); } Diagnoskodverk codeSystem = getDiagnoskodverk(codeSystemStr); List<Diagnos> matches; if (codeSystem == null) { LOG.warn("Code system is null"); return DiagnosResponse.invalidCodesystem(); } switch (codeSystem) { case ICD_10_SE: matches = icd10seDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.ICD_10_SE); break; case KSH_97_P: matches = ksh97pDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.KSH_97_P); break; default: LOG.warn("Unknown code system '{}'", codeSystem); return DiagnosResponse.invalidCodesystem(); } if (matches.isEmpty()) { return DiagnosResponse.notFound(); } if (matches.size() <= nbrOfResults) { return DiagnosResponse.ok(matches, false); } LOG.debug("Returning {} diagnosises out of a match of {}", nbrOfResults, matches.size()); return DiagnosResponse.ok(matches.subList(0, nbrOfResults), true); }  }
DiagnosServiceImpl implements DiagnosService { @Override public DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults) { Assert.isTrue(nbrOfResults + 1 > 1, "nbrOfResults must be larger that 0"); if (Strings.nullToEmpty(searchString).trim().isEmpty()) { return DiagnosResponse.invalidSearchString(); } Diagnoskodverk codeSystem = getDiagnoskodverk(codeSystemStr); List<Diagnos> matches; if (codeSystem == null) { LOG.warn("Code system is null"); return DiagnosResponse.invalidCodesystem(); } switch (codeSystem) { case ICD_10_SE: matches = icd10seDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.ICD_10_SE); break; case KSH_97_P: matches = ksh97pDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.KSH_97_P); break; default: LOG.warn("Unknown code system '{}'", codeSystem); return DiagnosResponse.invalidCodesystem(); } if (matches.isEmpty()) { return DiagnosResponse.notFound(); } if (matches.size() <= nbrOfResults) { return DiagnosResponse.ok(matches, false); } LOG.debug("Returning {} diagnosises out of a match of {}", nbrOfResults, matches.size()); return DiagnosResponse.ok(matches.subList(0, nbrOfResults), true); }  @PostConstruct void initDiagnosRepository(); @Override DiagnosResponse getDiagnosisByCode(String code, String codeSystemStr); @Override DiagnosResponse getDiagnosisByCode(String code, Diagnoskodverk codeSystem); @Override DiagnosResponse searchDiagnosisByCode(String codeFragment, String codeSystemStr, int nbrOfResults); @Override DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults); @Override boolean validateDiagnosisCode(String diagnosisCode, String codeSystemStr); }
DiagnosServiceImpl implements DiagnosService { @Override public DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults) { Assert.isTrue(nbrOfResults + 1 > 1, "nbrOfResults must be larger that 0"); if (Strings.nullToEmpty(searchString).trim().isEmpty()) { return DiagnosResponse.invalidSearchString(); } Diagnoskodverk codeSystem = getDiagnoskodverk(codeSystemStr); List<Diagnos> matches; if (codeSystem == null) { LOG.warn("Code system is null"); return DiagnosResponse.invalidCodesystem(); } switch (codeSystem) { case ICD_10_SE: matches = icd10seDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.ICD_10_SE); break; case KSH_97_P: matches = ksh97pDiagnosRepo.searchDiagnosisByDescription(searchString.trim(), nbrOfResults + 1); matches = filterResultList(matches, Diagnoskodverk.KSH_97_P); break; default: LOG.warn("Unknown code system '{}'", codeSystem); return DiagnosResponse.invalidCodesystem(); } if (matches.isEmpty()) { return DiagnosResponse.notFound(); } if (matches.size() <= nbrOfResults) { return DiagnosResponse.ok(matches, false); } LOG.debug("Returning {} diagnosises out of a match of {}", nbrOfResults, matches.size()); return DiagnosResponse.ok(matches.subList(0, nbrOfResults), true); }  @PostConstruct void initDiagnosRepository(); @Override DiagnosResponse getDiagnosisByCode(String code, String codeSystemStr); @Override DiagnosResponse getDiagnosisByCode(String code, Diagnoskodverk codeSystem); @Override DiagnosResponse searchDiagnosisByCode(String codeFragment, String codeSystemStr, int nbrOfResults); @Override DiagnosResponse searchDiagnosisByDescription(String searchString, String codeSystemStr, int nbrOfResults); @Override boolean validateDiagnosisCode(String diagnosisCode, String codeSystemStr);  }