diff --git a/src/main/java/org/isf/examination/manager/ExaminationBrowserManager.java b/src/main/java/org/isf/examination/manager/ExaminationBrowserManager.java index 870db85cc..1d167c62a 100644 --- a/src/main/java/org/isf/examination/manager/ExaminationBrowserManager.java +++ b/src/main/java/org/isf/examination/manager/ExaminationBrowserManager.java @@ -107,7 +107,7 @@ private String formatLastNote(PatientExamination lastPatientExamination) { } private void buildAuscultationHashMap() { - auscultationHashMap = new LinkedHashMap<>(); + auscultationHashMap = new LinkedHashMap<>(6); auscultationHashMap.put("normal", MessageBundle.getMessage("angal.examination.auscultation.normal.txt")); auscultationHashMap.put("wheezes", MessageBundle.getMessage("angal.examination.auscultation.wheezes.txt")); auscultationHashMap.put("rhonchi", MessageBundle.getMessage("angal.examination.auscultation.rhonchi.txt")); @@ -148,9 +148,9 @@ public String getAuscultationKey(String description) { * @param patex - the PatientExamination to save * @throws OHServiceException */ - public void saveOrUpdate(PatientExamination patex) throws OHServiceException { + public PatientExamination saveOrUpdate(PatientExamination patex) throws OHServiceException { validateExamination(patex); - ioOperations.saveOrUpdate(patex); + return ioOperations.saveOrUpdate(patex); } public PatientExamination getByID(int id) throws OHServiceException { @@ -159,14 +159,13 @@ public PatientExamination getByID(int id) throws OHServiceException { public PatientExamination getLastByPatID(int patID) throws OHServiceException { List patExamination = getByPatID(patID); - return !patExamination.isEmpty() ? patExamination.get(0) : null; } public List getLastNByPatID(int patID, int number) throws OHServiceException { return ioOperations.getLastNByPatID(patID, number); } - + public PagedResponse getLastNByPatIDPageable(int patID, int number) throws OHServiceException { return ioOperations.getLastNByPatIDPageable(patID, number); } @@ -193,20 +192,20 @@ public String getBMIdescription(double bmi) { if (bmi >= 18.5 && bmi < 24.5) { return MessageBundle.getMessage("angal.examination.bmi.normalweight.txt"); } - if (bmi >= 24.5 && bmi < 30) { + if (bmi >= 24.5 && bmi < 30.0) { return MessageBundle.getMessage("angal.examination.bmi.overweight.txt"); } - if (bmi >= 30 && bmi < 35) { + if (bmi >= 30.0 && bmi < 35.0) { return MessageBundle.getMessage("angal.examination.bmi.obesityclassilight.txt"); } - if (bmi >= 35 && bmi < 40) { + if (bmi >= 35.0 && bmi < 40.0) { return MessageBundle.getMessage("angal.examination.bmi.obesityclassiimedium.txt"); } return MessageBundle.getMessage("angal.examination.bmi.obesityclassiiisevere.txt"); } private void buildDiuresisDescriptionHashMap() { - diuresisDescriptionHashMap = new HashMap<>(); + diuresisDescriptionHashMap = new HashMap<>(8); diuresisDescriptionHashMap.put("physiological", MessageBundle.getMessage("angal.examination.diuresis.physiological.txt")); diuresisDescriptionHashMap.put("oliguria", MessageBundle.getMessage("angal.examination.diuresis.oliguria.txt")); diuresisDescriptionHashMap.put("anuria", MessageBundle.getMessage("angal.examination.diuresis.anuria.txt")); @@ -218,7 +217,7 @@ private void buildDiuresisDescriptionHashMap() { } private void buildBowelDescriptionHashMap() { - bowelDescriptionHashMap = new HashMap<>(); + bowelDescriptionHashMap = new HashMap<>(4); bowelDescriptionHashMap.put("regular", MessageBundle.getMessage("angal.examination.bowel.regular.txt")); bowelDescriptionHashMap.put("irregular", MessageBundle.getMessage("angal.examination.bowel.irregular.txt")); bowelDescriptionHashMap.put("constipation", MessageBundle.getMessage("angal.examination.bowel.constipation.txt")); diff --git a/src/main/java/org/isf/examination/service/ExaminationOperations.java b/src/main/java/org/isf/examination/service/ExaminationOperations.java index bf1d33542..570400d6b 100644 --- a/src/main/java/org/isf/examination/service/ExaminationOperations.java +++ b/src/main/java/org/isf/examination/service/ExaminationOperations.java @@ -50,7 +50,7 @@ public ExaminationOperations() { } /** - * Get from last PatientExamination (only height, weight & note) + * Get from last PatientExamination */ public PatientExamination getFromLastPatientExamination(PatientExamination lastPatientExamination) { return new PatientExamination(TimeTools.getNow(), @@ -77,8 +77,8 @@ public PatientExamination getFromLastPatientExamination(PatientExamination lastP * - the PatientExamination to save * @throws OHServiceException */ - public void saveOrUpdate(PatientExamination patex) throws OHServiceException { - repository.save(patex); + public PatientExamination saveOrUpdate(PatientExamination patex) throws OHServiceException { + return repository.save(patex); } public PatientExamination getByID(int id) throws OHServiceException { diff --git a/src/main/java/org/isf/hospital/manager/HospitalBrowsingManager.java b/src/main/java/org/isf/hospital/manager/HospitalBrowsingManager.java index 8613b6595..ff70a9408 100644 --- a/src/main/java/org/isf/hospital/manager/HospitalBrowsingManager.java +++ b/src/main/java/org/isf/hospital/manager/HospitalBrowsingManager.java @@ -40,9 +40,9 @@ public class HospitalBrowsingManager { private HospitalIoOperations ioOperations; /** - * Reads from database hospital information + * Reads from the database the {@link Hospital} information. * - * @return {@link Hospital} object + * @return the {@link Hospital} object * @throws OHServiceException */ public Hospital getHospital() throws OHServiceException { @@ -50,9 +50,9 @@ public Hospital getHospital() throws OHServiceException { } /** - * Reads from database currency cod + * Reads from the database the currency code. * - * @return currency cod + * @return the currency code * @throws OHServiceException */ public String getHospitalCurrencyCod() throws OHServiceException { @@ -60,9 +60,9 @@ public String getHospitalCurrencyCod() throws OHServiceException { } /** - * Updates hospital information + * Updates the {@link Hospital} information. * - * @return true if the hospital information has been updated, false otherwise + * @return return the updated {@link Hospital} object. * @throws OHServiceException */ public Hospital updateHospital(Hospital hospital) throws OHServiceException { diff --git a/src/main/java/org/isf/hospital/service/HospitalIoOperations.java b/src/main/java/org/isf/hospital/service/HospitalIoOperations.java index a3f286760..9970f0aaa 100644 --- a/src/main/java/org/isf/hospital/service/HospitalIoOperations.java +++ b/src/main/java/org/isf/hospital/service/HospitalIoOperations.java @@ -46,9 +46,9 @@ public class HospitalIoOperations { private HospitalIoOperationRepository repository; /** - * Reads from database hospital information + * Reads from database {@link Hospital} information. * - * @return {@link Hospital} object + * @return the {@link Hospital} object. * @throws OHServiceException */ public Hospital getHospital() throws OHServiceException { @@ -57,8 +57,8 @@ public Hospital getHospital() throws OHServiceException { } /** - * Reads from database currency cod - * @return currency cod + * Reads from the database the currency code. + * @return the currency code * @throws OHServiceException */ public String getHospitalCurrencyCod() throws OHServiceException { @@ -67,9 +67,9 @@ public String getHospitalCurrencyCod() throws OHServiceException { } /** - * Updates hospital information + * Updates the {@link Hospital} information. * - * @return true if the hospital information has been updated, false otherwise + * @return the updated {@link Hospital} object. * @throws OHServiceException */ public Hospital updateHospital(Hospital hospital) throws OHServiceException { @@ -80,7 +80,7 @@ public Hospital updateHospital(Hospital hospital) throws OHServiceException { * Sanitize the given {@link String} value. * This method is maintained only for backward compatibility. * @param value the value to sanitize. - * @return the sanitized value or null if the passed value is null. + * @return the sanitized value or {@code null} if the passed value is {@code null}. */ protected String sanitize(String value) { if (value == null) { diff --git a/src/test/java/org/isf/hospital/test/Tests.java b/src/test/java/org/isf/hospital/test/Tests.java index 1e2fced95..9179f460d 100644 --- a/src/test/java/org/isf/hospital/test/Tests.java +++ b/src/test/java/org/isf/hospital/test/Tests.java @@ -72,7 +72,8 @@ public void testHospitalSets() throws Exception { @Test public void testIoGetHospital() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); Hospital getHospital = hospitalIoOperation.getHospital(); assertThat(getHospital).isEqualTo(foundHospital); } @@ -80,22 +81,24 @@ public void testIoGetHospital() throws Exception { @Test public void testIoUpdateHospital() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); foundHospital.setDescription("Update"); - Hospital updateHospital = hospitalIoOperation.updateHospital(foundHospital); - assertThat(updateHospital.getDescription()).isEqualTo("Update"); + Hospital updatedHospital = hospitalIoOperation.updateHospital(foundHospital); + assertThat(updatedHospital.getDescription()).isEqualTo("Update"); } @Test public void testIoGetHospitalCurrencyCod() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); String cod = hospitalIoOperation.getHospitalCurrencyCod(); assertThat(foundHospital.getCurrencyCod()).isEqualTo(cod); foundHospital.setCurrencyCod(null); - Hospital updateHospital = hospitalIoOperation.updateHospital(foundHospital); - assertThat(updateHospital.getCurrencyCod()).isNull(); + Hospital updatedHospital = hospitalIoOperation.updateHospital(foundHospital); + assertThat(updatedHospital.getCurrencyCod()).isNull(); } @Test @@ -110,7 +113,8 @@ public void testIoHospitalSanitize() throws Exception { @Test public void testMgrGetHospital() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); Hospital getHospital = hospitalBrowsingManager.getHospital(); assertThat(getHospital).isEqualTo(foundHospital); } @@ -118,16 +122,18 @@ public void testMgrGetHospital() throws Exception { @Test public void testMgrUpdateHospital() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); foundHospital.setDescription("Update"); - Hospital updateHospital = hospitalBrowsingManager.updateHospital(foundHospital); - assertThat(updateHospital.getDescription()).isEqualTo("Update"); + Hospital updatedHospital = hospitalBrowsingManager.updateHospital(foundHospital); + assertThat(updatedHospital.getDescription()).isEqualTo("Update"); } @Test public void testMgrGetHospitalCurrencyCod() throws Exception { String code = setupTestHospital(false); - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); String cod = hospitalBrowsingManager.getHospitalCurrencyCod(); assertThat(foundHospital.getCurrencyCod()).isEqualTo(cod); @@ -139,7 +145,8 @@ public void testMgrGetHospitalCurrencyCod() throws Exception { @Test public void testHospitalGetterSetter() throws Exception { String code = setupTestHospital(false); - Hospital hospital = hospitalIoOperationRepository.findById(code).get(); + Hospital hospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(hospital).isNotNull(); hospital.getLock(); hospital.setLock(-1); @@ -149,7 +156,8 @@ public void testHospitalGetterSetter() throws Exception { @Test public void testHospitalHashToString() throws Exception { String code = setupTestHospital(false); - Hospital hospital = hospitalIoOperationRepository.findById(code).get(); + Hospital hospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(hospital).isNotNull(); assertThat(hospital.hashCode()).isPositive(); @@ -163,7 +171,8 @@ private String setupTestHospital(boolean usingSet) throws OHException { } private void checkHospitalIntoDb(String code) throws OHException { - Hospital foundHospital = hospitalIoOperationRepository.findById(code).get(); + Hospital foundHospital = hospitalIoOperationRepository.findById(code).orElse(null); + assertThat(foundHospital).isNotNull(); testHospital.check(foundHospital); } } \ No newline at end of file