diff --git a/src/main/java/org/isf/accounting/rest/BillController.java b/src/main/java/org/isf/accounting/rest/BillController.java index c63bf4957..0170a662c 100644 --- a/src/main/java/org/isf/accounting/rest/BillController.java +++ b/src/main/java/org/isf/accounting/rest/BillController.java @@ -39,7 +39,6 @@ import org.isf.patient.model.Patient; import org.isf.priceslist.manager.PriceListManager; import org.isf.priceslist.model.PriceList; -import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.slf4j.Logger; @@ -49,6 +48,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -108,7 +108,7 @@ public BillController(BillBrowserManager billManager, PriceListManager priceList public ResponseEntity newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException { if (newBillDto == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill is null.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Bill is null.")); } LOGGER.info("Create Bill {}", newBillDto); @@ -123,13 +123,13 @@ public ResponseEntity newBill(@RequestBody FullBillDTO newBillDto) throws OHS if (pat != null) { bill.setBillPatient(pat); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } if (plist != null) { bill.setPriceList(plist); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Price list not found.")); } List billItems = billItemsMapper.map2ModelList(newBillDto.getBillItems()); @@ -160,7 +160,7 @@ public ResponseEntity updateBill(@PathVariable Integer id, @RequestBody FullB bill.setId(id); if (billManager.getBill(id) == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill to update not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Bill to update not found.")); } Patient pat = patientManager.getPatientById(bill.getBillPatient().getCode()); @@ -172,13 +172,13 @@ public ResponseEntity updateBill(@PathVariable Integer id, @RequestBody FullB if (pat != null) { bill.setBillPatient(pat); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } if (plist != null) { bill.setPriceList(plist); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Price list not found.")); } List billItems = billItemsMapper.map2ModelList(odBillDto.getBillItems()); @@ -415,12 +415,12 @@ public ResponseEntity deleteBill(@PathVariable Integer id) throws OHServiceEx LOGGER.info("Delete bill id: {}", id); Bill bill = billManager.getBill(id); if (bill == null) { - return ResponseEntity.badRequest().body("No bill found with the specified id."); + return ResponseEntity.notFound().build(); } try { billManager.deleteBill(bill); } catch (OHServiceException e) { - throw new OHAPIException(new OHExceptionMessage("Bill is not deleted.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not deleted.")); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/admission/rest/AdmissionController.java b/src/main/java/org/isf/admission/rest/AdmissionController.java index 6e0ab9624..66bf42dce 100644 --- a/src/main/java/org/isf/admission/rest/AdmissionController.java +++ b/src/main/java/org/isf/admission/rest/AdmissionController.java @@ -62,6 +62,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; @@ -152,7 +153,7 @@ public ResponseEntity getAdmissions(@PathVariable("patientCode") int patientC LOGGER.info("Get admission by patient id: {}", patientCode); Patient patient = patientManager.getPatientById(patientCode); if (patient == null) { - return ResponseEntity.badRequest().body("No patient found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No patient found with the specified code."); } List listAdmissions = admissionManager.getAdmissions(patient); if (listAdmissions == null) { @@ -184,7 +185,7 @@ public ResponseEntity getCurrentAdmission(@RequestParam("patientCode") int pa LOGGER.info("Get admission by patient code: {}", patientCode); Patient patient = patientManager.getPatientById(patientCode); if (patient == null) { - return ResponseEntity.badRequest().body("No patient found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No patient found with the specified code."); } Admission admission = admissionManager.getCurrentAdmission(patient); if (admission == null) { @@ -297,7 +298,7 @@ public ResponseEntity getNextYProg(@RequestParam("wardcode") String wardCode) LOGGER.info("get the next prog in the year for ward code: {}", wardCode); if (wardCode.trim().isEmpty() || !wardManager.isCodePresent(wardCode)) { - return ResponseEntity.badRequest().body("Ward not found for code:" + wardCode); + return ((BodyBuilder) ResponseEntity.notFound()).body("Ward not found for code:" + wardCode); } return ResponseEntity.ok(admissionManager.getNextYProg(wardCode)); @@ -315,7 +316,7 @@ public ResponseEntity getUsedWardBed(@RequestParam("wardid") String wardCode) LOGGER.info("Counts the number of used bed for ward code: {}", wardCode); if (wardCode.trim().isEmpty() || !wardManager.isCodePresent(wardCode)) { - return ResponseEntity.badRequest().body("Ward not found for code:" + wardCode); + return ((BodyBuilder) ResponseEntity.notFound()).body("Ward not found for code:" + wardCode); } return ResponseEntity.ok(admissionManager.getUsedWardBed(wardCode)); @@ -333,7 +334,7 @@ public ResponseEntity deleteAdmission(@PathVariable("id") int id) throws OHSe LOGGER.info("setting admission to deleted: {}", id); Admission admission = admissionManager.getAdmission(id); if (admission == null) { - return ResponseEntity.badRequest().body("No admission found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No admission found with the specified id."); } admissionManager.setDeleted(id); return ResponseEntity.ok(true); @@ -354,29 +355,29 @@ public ResponseEntity dischargePatient(@RequestParam("patientCode") int patie Patient patient = patientManager.getPatientById(patientCode); if (patient == null) { - return ResponseEntity.badRequest().body("No patient found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No patient found with the specified code."); } Admission admission = admissionManager.getCurrentAdmission(patient); if (admission == null) { - return ResponseEntity.badRequest().body("Patient is not admitted."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Patient is not admitted."); } Admission adm = admissionMapper.map2Model(currentAdmissionDTO); if (adm == null || admission.getId() != adm.getId()) { - return ResponseEntity.badRequest().body("Current admission not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Current admission not found."); } if (adm.getDiseaseOut1() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("at least one disease must be give.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("at least one disease must be give.")); } if (adm.getDisDate() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("the exit date must be filled in.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("the exit date must be filled in.")); } if (adm.getDisDate().isBefore(adm.getAdmDate())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("the exit date must be after the entry date.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("the exit date must be after the entry date.")); } if (adm.getDisType() == null || !dischargeTypeManager.isCodePresent(adm.getDisType().getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("the type of output is mandatory or does not exist.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("the type of output is mandatory or does not exist.")); } adm.setAdmitted(0); Admission admissionUpdated = admissionManager.updateAdmission(adm); @@ -401,11 +402,11 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO List wards = wardManager.getWards().stream() .filter(w -> w.getCode().equals(newAdmissionDTO.getWard().getCode())).collect(Collectors.toList()); if (wards.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Ward not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Ward not found.")); } newAdmission.setWard(wards.get(0)); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Ward field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Ward field is required.")); } if (newAdmissionDTO.getAdmType() != null && newAdmissionDTO.getAdmType().getCode() != null @@ -414,21 +415,21 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(admt -> admt.getCode().equals(newAdmissionDTO.getAdmType().getCode())) .collect(Collectors.toList()); if (types.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Admission type not found.")); } newAdmission.setAdmType(types.get(0)); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission type field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Admission type field is required.")); } if (newAdmissionDTO.getPatient() != null && newAdmissionDTO.getPatient().getCode() != null) { Patient patient = patientManager.getPatientById(newAdmissionDTO.getPatient().getCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } newAdmission.setPatient(patient); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Patient field is required.")); } List diseases = diseaseManager.getDiseaseAll(); @@ -437,7 +438,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseIn().getCode())) .collect(Collectors.toList()); if (dIns.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease in not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease in not found.")); } newAdmission.setDiseaseIn(dIns.get(0)); } @@ -447,7 +448,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut1().getCode())) .collect(Collectors.toList()); if (dOut1.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 1 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 1 not found.")); } newAdmission.setDiseaseOut1(dOut1.get(0)); } @@ -457,7 +458,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut2().getCode())) .collect(Collectors.toList()); if (dOut2.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 2 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 2 not found.")); } newAdmission.setDiseaseOut2(dOut2.get(0)); } @@ -467,7 +468,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(d -> d.getCode().equals(newAdmissionDTO.getDiseaseOut3().getCode())) .collect(Collectors.toList()); if (dOut3.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 3 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 3 not found.")); } newAdmission.setDiseaseOut3(dOut3.get(0)); } @@ -479,7 +480,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(dtp -> dtp.getCode().equals(newAdmissionDTO.getDisType().getCode())) .collect(Collectors.toList()); if (disTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Discharge type not found.")); } newAdmission.setDisType(disTypesF.get(0)); } @@ -491,7 +492,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(pregtt -> pregtt.getCode().equals(newAdmissionDTO.getPregTreatmentType().getCode())) .collect(Collectors.toList()); if (pregTTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Pregnant treatment type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Pregnant treatment type not found.")); } newAdmission.setPregTreatmentType(pregTTypesF.get(0)); } @@ -503,7 +504,7 @@ ResponseEntity newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO .filter(dlvrType -> dlvrType.getCode().equals(newAdmissionDTO.getDeliveryType().getCode())) .collect(Collectors.toList()); if (dlvrTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Delivery type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Delivery type not found.")); } newAdmission.setDeliveryType(dlvrTypesF.get(0)); } @@ -550,7 +551,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) Admission old = admissionManager.getAdmission(updateAdmissionDTO.getId()); if (old == null) { - return ResponseEntity.badRequest().body("Admission not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Admission not found."); } Admission updateAdmission = admissionMapper.map2Model(updateAdmissionDTO); @@ -559,11 +560,11 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) List wards = wardManager.getWards().stream() .filter(w -> w.getCode().equals(updateAdmissionDTO.getWard().getCode())).collect(Collectors.toList()); if (wards.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Ward not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Ward not found.")); } updateAdmission.setWard(wards.get(0)); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Ward field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Ward field is required.")); } if (updateAdmissionDTO.getAdmType() != null && updateAdmissionDTO.getAdmType().getCode() != null @@ -572,21 +573,21 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(admt -> admt.getCode().equals(updateAdmissionDTO.getAdmType().getCode())) .collect(Collectors.toList()); if (types.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Admission type not found.")); } updateAdmission.setAdmType(types.get(0)); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission type field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Admission type field is required.")); } if (updateAdmissionDTO.getPatient() != null && updateAdmissionDTO.getPatient().getCode() != null) { Patient patient = patientManager.getPatientById(updateAdmissionDTO.getPatient().getCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } updateAdmission.setPatient(patient); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient field is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Patient field is required.")); } List diseases = diseaseManager.getDiseaseAll(); if (updateAdmissionDTO.getDiseaseIn() != null && updateAdmissionDTO.getDiseaseIn().getCode() != null) { @@ -594,7 +595,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(d -> d.getCode().equals(updateAdmissionDTO.getDiseaseIn().getCode())) .collect(Collectors.toList()); if (dIns.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease in not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease in not found.")); } updateAdmission.setDiseaseIn(dIns.get(0)); } @@ -604,7 +605,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(d -> d.getCode().equals(updateAdmissionDTO.getDiseaseOut1().getCode())) .collect(Collectors.toList()); if (dOut1s.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 1 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 1 not found.")); } updateAdmission.setDiseaseOut1(dOut1s.get(0)); } @@ -614,7 +615,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(d -> d.getCode().equals(updateAdmissionDTO.getDiseaseOut2().getCode())) .collect(Collectors.toList()); if (dOut2s.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 2 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 2 not found.")); } updateAdmission.setDiseaseOut2(dOut2s.get(0)); } @@ -624,7 +625,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(d -> d.getCode().equals(updateAdmissionDTO.getDiseaseOut3().getCode())) .collect(Collectors.toList()); if (dOut3s.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease out 3 not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease out 3 not found.")); } updateAdmission.setDiseaseOut3(dOut3s.get(0)); } @@ -636,7 +637,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(dtp -> dtp.getCode().equals(updateAdmissionDTO.getDisType().getCode())) .collect(Collectors.toList()); if (disTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Discharge type not found.")); } updateAdmission.setDisType(disTypesF.get(0)); } @@ -648,7 +649,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(pregtt -> pregtt.getCode().equals(updateAdmissionDTO.getPregTreatmentType().getCode())) .collect(Collectors.toList()); if (pregTTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Pregnant treatment type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Pregnant treatment type not found.")); } updateAdmission.setPregTreatmentType(pregTTypesF.get(0)); } @@ -660,7 +661,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) .filter(dlvrType -> dlvrType.getCode().equals(updateAdmissionDTO.getDeliveryType().getCode())) .collect(Collectors.toList()); if (dlvrTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Delivery type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Delivery type not found.")); } updateAdmission.setDeliveryType(dlvrTypesF.get(0)); } @@ -672,7 +673,7 @@ ResponseEntity updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO) dlvrrestType -> dlvrrestType.getCode().equals(updateAdmissionDTO.getDeliveryResult().getCode())) .collect(Collectors.toList()); if (dlvrrestTypesF.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Delivery result type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Delivery result type not found.")); } updateAdmission.setDeliveryResult(dlvrrestTypesF.get(0)); } diff --git a/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java b/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java index 9f78c50c1..d74895434 100644 --- a/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java +++ b/src/main/java/org/isf/admtype/rest/AdmissionTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -76,8 +77,8 @@ ResponseEntity newAdmissionType(@RequestBody AdmissionTypeDTO admissionTypeDT String code = admissionTypeDTO.getCode(); LOGGER.info("Create Admission Type {}", code); AdmissionType newAdmissionType = admtManager.newAdmissionType(mapper.map2Model(admissionTypeDTO)); - if (admtManager.isCodePresent(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The code of Admission Type is already used.")); + if (!admtManager.isCodePresent(code)) { + return ResponseEntity.internalServerError().body(new OHExceptionMessage("The code of Admission Type is already used.")); } return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newAdmissionType)); } @@ -94,7 +95,7 @@ ResponseEntity updateAdmissionTypes(@RequestBody AdmissionTypeDTO admissionTy LOGGER.info("Update admissiontypes code: {}", admissionTypeDTO.getCode()); AdmissionType admt = mapper.map2Model(admissionTypeDTO); if (!admtManager.isCodePresent(admt.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Admission Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Admission Type not found.")); } AdmissionType updatedAdmissionType = admtManager.updateAdmissionType(admt); return ResponseEntity.ok(mapper.map2DTO(updatedAdmissionType)); @@ -134,7 +135,7 @@ public ResponseEntity deleteAdmissionType(@PathVariable("code") String code) admtManager.deleteAdmissionType(admtFounds.get(0)); } } else { - return ResponseEntity.badRequest().body("Admission Type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Admission Type not found."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/agetype/rest/AgeTypeController.java b/src/main/java/org/isf/agetype/rest/AgeTypeController.java index d66fe2eaa..a323794ab 100644 --- a/src/main/java/org/isf/agetype/rest/AgeTypeController.java +++ b/src/main/java/org/isf/agetype/rest/AgeTypeController.java @@ -32,7 +32,6 @@ import org.isf.agetype.manager.AgeTypeBrowserManager; import org.isf.agetype.mapper.AgeTypeMapper; import org.isf.agetype.model.AgeType; -import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.slf4j.Logger; @@ -40,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; @@ -95,7 +95,7 @@ public ResponseEntity> getAllAgeTypes() throws OHServiceExcepti @PutMapping(value = "/agetypes", produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity updateAgeType(@Valid @RequestBody AgeTypeDTO ageTypeDTO) throws OHServiceException { if (ageTypeDTO.getCode() == null || ageTypeDTO.getCode().trim().isEmpty()) { - throw new OHAPIException(new OHExceptionMessage("The age type is not valid.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The age type is not valid.")); } LOGGER.info("Update age type"); AgeType ageType = mapper.map2Model(ageTypeDTO); diff --git a/src/main/java/org/isf/disctype/rest/DischargeTypeController.java b/src/main/java/org/isf/disctype/rest/DischargeTypeController.java index 64f642a20..11759e2b4 100644 --- a/src/main/java/org/isf/disctype/rest/DischargeTypeController.java +++ b/src/main/java/org/isf/disctype/rest/DischargeTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -77,7 +78,7 @@ ResponseEntity newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) t LOGGER.info("Create discharge type {}", code); DischargeType newDischargeType = discTypeManager.newDischargeType(mapper.map2Model(dischTypeDTO)); if (!discTypeManager.isCodePresent(code)) { - return ResponseEntity.notFound().build(); + return ResponseEntity.internalServerError().body("Discharge Type is not created."); } return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newDischargeType)); } @@ -93,11 +94,11 @@ ResponseEntity updateDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO LOGGER.info("Update discharge type with code: {}", dischTypeDTO.getCode()); DischargeType dischType = mapper.map2Model(dischTypeDTO); if (!discTypeManager.isCodePresent(dischTypeDTO.getCode())) { - return ResponseEntity.badRequest().body(null); + return ((BodyBuilder) ResponseEntity.notFound()).body("Discharge Type not found."); } DischargeType updatedDischargeType = discTypeManager.updateDischargeType(dischType); if (!discTypeManager.isCodePresent(updatedDischargeType.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge Type is not updated.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Discharge Type is not updated.")); } return ResponseEntity.ok(mapper.map2DTO(dischType)); } @@ -136,7 +137,7 @@ public ResponseEntity deleteDischargeType(@PathVariable("code") String code) discTypeManager.deleteDischargeType(dischTypeFounds.get(0)); } } else { - return ResponseEntity.badRequest().body("Discharge Type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Discharge Type not found."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/disease/rest/DiseaseController.java b/src/main/java/org/isf/disease/rest/DiseaseController.java index 445c70c49..467b834ca 100644 --- a/src/main/java/org/isf/disease/rest/DiseaseController.java +++ b/src/main/java/org/isf/disease/rest/DiseaseController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -244,10 +245,10 @@ public ResponseEntity getDiseaseByCode(@PathVariable("code") String public ResponseEntity newDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) throws OHServiceException { Disease disease = mapper.map2Model(diseaseDTO); if (diseaseManager.isCodePresent(disease.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Duplicated disease code.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Duplicated disease code.")); } if (diseaseManager.descriptionControl(disease.getDescription(), disease.getType().getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Duplicated disease description for the same disease type.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Duplicated disease description for the same disease type.")); } try { diseaseManager.newDisease(disease); @@ -267,7 +268,7 @@ public ResponseEntity newDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) t public ResponseEntity updateDisease(@Valid @RequestBody DiseaseDTO diseaseDTO) throws OHServiceException { Disease disease = mapper.map2Model(diseaseDTO); if (!diseaseManager.isCodePresent(disease.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease not found.")); } disease.setLock(diseaseDTO.getLock()); try { @@ -299,7 +300,7 @@ public ResponseEntity deleteDisease(@PathVariable("code") String code) throws result.put("deleted", isDeleted); return ResponseEntity.ok(result); } else { - return ResponseEntity.badRequest().body("No disease found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No disease found with the specified code."); } } diff --git a/src/main/java/org/isf/distype/rest/DiseaseTypeController.java b/src/main/java/org/isf/distype/rest/DiseaseTypeController.java index 24d70bddf..b9fd81352 100644 --- a/src/main/java/org/isf/distype/rest/DiseaseTypeController.java +++ b/src/main/java/org/isf/distype/rest/DiseaseTypeController.java @@ -38,6 +38,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -91,7 +92,7 @@ public ResponseEntity> getAllDiseaseTypes() throws OHServic public ResponseEntity newDiseaseType(@Valid @RequestBody DiseaseTypeDTO diseaseTypeDTO) throws OHServiceException { DiseaseType diseaseType = mapper.map2Model(diseaseTypeDTO); if (diseaseTypeManager.isCodePresent(diseaseType.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Specified Disease Type code is already used.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Specified Disease Type code is already used.")); } try { diseaseTypeManager.newDiseaseType(diseaseType); @@ -111,7 +112,7 @@ public ResponseEntity newDiseaseType(@Valid @RequestBody DiseaseTypeDTO disea public ResponseEntity updateDiseaseType(@Valid @RequestBody DiseaseTypeDTO diseaseTypeDTO) throws OHServiceException { DiseaseType diseaseType = mapper.map2Model(diseaseTypeDTO); if (!diseaseTypeManager.isCodePresent(diseaseType.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Disease Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Disease Type not found.")); } try { diseaseTypeManager.updateDiseaseType(diseaseType); @@ -143,7 +144,7 @@ public ResponseEntity deleteDiseaseType(@PathVariable String code) throws OHS return ResponseEntity.internalServerError().body(new OHExceptionMessage("Disease Type not deleted.")); } } else { - return ResponseEntity.badRequest().body("No Disease Type found with the given code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Disease Type found with the given code."); } } diff --git a/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java b/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java index 6e87f6de7..db932fffc 100644 --- a/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java +++ b/src/main/java/org/isf/dlvrrestype/rest/DeliveryResultTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -101,7 +102,7 @@ ResponseEntity updateDeliveryResultTypes(@RequestBody DeliveryResultTypeDTO d LOGGER.info("Update Delivery Result Type code: {}", dlvrrestTypeDTO.getCode()); DeliveryResultType dlvrrestType = mapper.map2Model(dlvrrestTypeDTO); if (!dlvrrestManager.isCodePresent(dlvrrestType.getCode())) { - return ResponseEntity.badRequest().body("Delivery Result Type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Delivery Result Type not found."); } try { dlvrrestManager.updateDeliveryResultType(dlvrrestType); @@ -150,7 +151,7 @@ public ResponseEntity deleteDeliveryResultType(@PathVariable("code") String c } } } else { - return ResponseEntity.badRequest().body("No delivery result type found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No delivery result type found with the specified code."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java b/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java index fa66dace3..824d6ed1d 100644 --- a/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java +++ b/src/main/java/org/isf/dlvrtype/rest/DeliveryTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -99,7 +100,7 @@ ResponseEntity updateDeliveryTypes(@RequestBody DeliveryTypeDTO dlvrTypeDTO) LOGGER.info("Update Delivery Type code: {}", dlvrTypeDTO.getCode()); DeliveryType dlvrType = deliveryTypeMapper.map2Model(dlvrTypeDTO); if (!dlvrtypeManager.isCodePresent(dlvrType.getCode())) { - return ResponseEntity.badRequest().body("Delivery Type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Delivery Type not found."); } try { dlvrtypeManager.updateDeliveryType(dlvrType); @@ -143,7 +144,7 @@ public ResponseEntity deleteDeliveryType(@PathVariable("code") String code) t dlvrtypeManager.deleteDeliveryType(dlvrTypeFounds.get(0)); } } else { - return ResponseEntity.badRequest().body("No Delivery Type found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Delivery Type found with the specified code."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/exam/rest/ExamController.java b/src/main/java/org/isf/exam/rest/ExamController.java index 63512d143..a0cc9b0b4 100644 --- a/src/main/java/org/isf/exam/rest/ExamController.java +++ b/src/main/java/org/isf/exam/rest/ExamController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -71,7 +72,7 @@ public ResponseEntity newExam(@RequestBody ExamDTO newExam) throws OHServiceE ExamType examType = examTypeBrowserManager.getExamType().stream().filter(et -> newExam.getExamtype().getCode().equals(et.getCode())).findFirst().orElse(null); if (examType == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam type not found.")); } Exam exam = examMapper.map2Model(newExam); @@ -88,15 +89,15 @@ public ResponseEntity newExam(@RequestBody ExamDTO newExam) throws OHServiceE public ResponseEntity updateExams(@PathVariable String code, @RequestBody ExamDTO updateExam) throws OHServiceException { if (!updateExam.getCode().equals(code)) { - return ResponseEntity.badRequest().body("The specified code is different with the Exam code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("The specified code is different with the Exam code."); } if (examManager.getExams().stream().noneMatch(e -> e.getCode().equals(code))) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } ExamType examType = examTypeBrowserManager.getExamType().stream().filter(et -> updateExam.getExamtype().getCode().equals(et.getCode())).findFirst().orElse(null); if (examType == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam type not found.")); } Exam exam = examMapper.map2Model(updateExam); @@ -137,7 +138,7 @@ public ResponseEntity> getExams() throws OHServiceException { public ResponseEntity deleteExam(@PathVariable String code) throws OHServiceException { Optional exam = examManager.getExams().stream().filter(e -> e.getCode().equals(code)).findFirst(); if (!exam.isPresent()) { - return ResponseEntity.badRequest().body("No Exam found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Exam found with the specified code."); } try { examManager.deleteExam(exam.get()); diff --git a/src/main/java/org/isf/exam/rest/ExamRowController.java b/src/main/java/org/isf/exam/rest/ExamRowController.java index c4a6c29ab..b04066766 100644 --- a/src/main/java/org/isf/exam/rest/ExamRowController.java +++ b/src/main/java/org/isf/exam/rest/ExamRowController.java @@ -29,20 +29,19 @@ import org.isf.exa.model.ExamRow; import org.isf.exam.dto.ExamRowDTO; import org.isf.exam.mapper.ExamRowMapper; -import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -73,7 +72,7 @@ public ResponseEntity newExamRow(@RequestBody ExamRowDTO examRowDTO) throws O Exam exam = examManager.getExams().stream().filter(e -> examRowDTO.getExam().getCode().equals(e.getCode())).findFirst().orElse(null); if (exam == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } ExamRow examRow = examRowMapper.map2Model(examRowDTO); @@ -123,7 +122,7 @@ public ResponseEntity> getExamRowsByCodeAndDescription(@Request public ResponseEntity deleteExam(@PathVariable Integer code) throws OHServiceException { List examRows = examRowBrowsingManager.getExamRow(code); if (examRows == null || examRows.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("No ExamRows found with the specified code.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("No ExamRows found with the specified code.")); } if (examRows.size() > 1) { return ResponseEntity.internalServerError().body(new OHExceptionMessage("Found multiple ExamRows.")); diff --git a/src/main/java/org/isf/examination/rest/ExaminationController.java b/src/main/java/org/isf/examination/rest/ExaminationController.java index d9fdf9619..94ec2bc32 100644 --- a/src/main/java/org/isf/examination/rest/ExaminationController.java +++ b/src/main/java/org/isf/examination/rest/ExaminationController.java @@ -44,6 +44,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -98,15 +99,15 @@ public ResponseEntity newPatientExamination(@RequestBody PatientExaminationDT @ResponseStatus(HttpStatus.OK) public ResponseEntity updateExamination(@PathVariable Integer id, @RequestBody PatientExaminationDTO dto) throws OHServiceException { if (dto.getPex_ID() != id) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient examination id mismatch.")); + return ((BodyBuilder) ResponseEntity.internalServerError()).body(new OHExceptionMessage("Patient examination id mismatch.")); } if (examinationBrowserManager.getByID(id) == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient examination not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient examination not found.")); } Patient patient = patientBrowserManager.getPatientById(dto.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient does not exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient does not exist.")); } validateExamination(dto); PatientExamination patientExamination = patientExaminationMapper.map2Model(dto); @@ -122,7 +123,7 @@ public ResponseEntity getDefaultPatientExamination(@RequestParam Integer patI Patient patient = patientBrowserManager.getPatientById(patId); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient does not exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient does not exist.")); } PatientExamination patientExamination = examinationBrowserManager.getDefaultPatientExamination(patient); PatientExaminationDTO patientExaminationDTO = patientExaminationMapper.map2DTO(patientExamination); @@ -210,69 +211,69 @@ public void validateExamination(PatientExaminationDTO newPatientExamination) thr Integer pex_height = newPatientExamination.getPex_height(); Double pex_weight = newPatientExamination.getPex_weight(); if (pex_height == null || pex_weight == null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("The height and weight are compulsory")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("The height and weight are compulsory")); } if (pex_height < ExaminationParameters.HEIGHT_MIN || pex_height > ExaminationParameters.HEIGHT_MAX) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "The height should be between " + ExaminationParameters.HEIGHT_MIN + " and " + ExaminationParameters.HEIGHT_MAX)); } if (pex_weight < ExaminationParameters.WEIGHT_MIN || pex_weight > ExaminationParameters.WEIGHT_MAX) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "The weight should be between" + ExaminationParameters.WEIGHT_MIN + " and " + ExaminationParameters.WEIGHT_MAX)); } Integer pex_ap_min = newPatientExamination.getPex_ap_min(); Integer pex_ap_max = newPatientExamination.getPex_ap_max(); if (pex_ap_min == null && pex_ap_max != null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("Malformed minimum/maximum blood pressure: minimum missing")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("Malformed minimum/maximum blood pressure: minimum missing")); } if (pex_ap_min != null && pex_ap_max == null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("Malformed minimum/maximum blood pressure: maximum missing")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("Malformed minimum/maximum blood pressure: maximum missing")); } if (pex_ap_min != null && pex_ap_max != null && pex_ap_min > pex_ap_max) { - ResponseEntity.badRequest().body(new OHExceptionMessage("The minimum blood pressure must be lower than the maximum blood pressure")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("The minimum blood pressure must be lower than the maximum blood pressure")); } Integer pex_hr = newPatientExamination.getPex_hr(); if (pex_hr != null && (pex_hr < ExaminationParameters.HR_MIN || pex_hr > ExaminationParameters.HR_MAX)) { - ResponseEntity.badRequest().body( + ResponseEntity.internalServerError().body( new OHExceptionMessage("Heart rate should be between " + ExaminationParameters.HR_MIN + " and " + ExaminationParameters.HR_MAX)); } Double pex_temp = newPatientExamination.getPex_temp(); if (pex_temp != null && (pex_temp < ExaminationParameters.TEMP_MIN || pex_temp > ExaminationParameters.TEMP_MAX)) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "The temperature should be between " + ExaminationParameters.TEMP_MIN + " and " + ExaminationParameters.TEMP_MAX)); } Double pex_sat = newPatientExamination.getPex_sat(); if (pex_sat != null && (pex_sat < ExaminationParameters.SAT_MIN || pex_sat > ExaminationParameters.SAT_MAX)) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "The saturation should be between " + ExaminationParameters.SAT_MIN + " and " + ExaminationParameters.SAT_MAX)); } Integer pex_hgt = newPatientExamination.getPex_hgt(); if (pex_hgt != null && (pex_hgt < ExaminationParameters.HGT_MIN || pex_hgt > ExaminationParameters.HGT_MAX)) { - ResponseEntity.badRequest().body( + ResponseEntity.internalServerError().body( new OHExceptionMessage("HGT should be between " + ExaminationParameters.HGT_MIN + " and " + ExaminationParameters.HGT_MAX)); } Integer pex_rr = newPatientExamination.getPex_rr(); if (pex_rr != null && (pex_rr < ExaminationParameters.RR_MIN || pex_rr > ExaminationParameters.RR_MAX)) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "Respiratory rate should be between " + ExaminationParameters.RR_MIN + " and " + ExaminationParameters.RR_MAX)); } Integer pex_diuresis = newPatientExamination.getPex_diuresis(); if (pex_diuresis != null && (pex_diuresis < ExaminationParameters.DIURESIS_MIN || pex_diuresis > ExaminationParameters.DIURESIS_MAX)) { - ResponseEntity.badRequest().body(new OHExceptionMessage( + ResponseEntity.internalServerError().body(new OHExceptionMessage( "Diuresis should be between " + ExaminationParameters.DIURESIS_MIN + " and " + ExaminationParameters.DIURESIS_MAX)); } Diurese pex_diuresis_desc = newPatientExamination.getPex_diuresis_desc(); if (pex_diuresis_desc != null && Diurese.valueOf(pex_diuresis_desc.toString()) == null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("Diuresis description is not found")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("Diuresis description is not found")); } Bowel pex_bowel_desc = newPatientExamination.getPex_bowel_desc(); if (pex_bowel_desc != null && Bowel.valueOf(pex_bowel_desc.toString()) == null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("Bowel description is not found")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("Bowel description is not found")); } Ausculation pex_auscultation = newPatientExamination.getPex_auscultation(); if (pex_auscultation != null && Ausculation.valueOf(pex_auscultation.toString()) == null) { - ResponseEntity.badRequest().body(new OHExceptionMessage("Auscultation is not found")); + ResponseEntity.internalServerError().body(new OHExceptionMessage("Auscultation is not found")); } } } diff --git a/src/main/java/org/isf/exatype/rest/ExamTypeController.java b/src/main/java/org/isf/exatype/rest/ExamTypeController.java index 7dde3ab27..d0aa9d704 100644 --- a/src/main/java/org/isf/exatype/rest/ExamTypeController.java +++ b/src/main/java/org/isf/exatype/rest/ExamTypeController.java @@ -28,7 +28,6 @@ import org.isf.exatype.manager.ExamTypeBrowserManager; import org.isf.exatype.mapper.ExamTypeMapper; import org.isf.exatype.model.ExamType; -import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.slf4j.Logger; @@ -37,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -78,10 +78,10 @@ public ResponseEntity newExamType(@RequestBody ExamTypeDTO newExamT public ResponseEntity updateExamType(@PathVariable String code, @RequestBody ExamTypeDTO updateExamType) throws OHServiceException { if (!updateExamType.getCode().equals(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam Type code mismatch.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Exam Type code mismatch.")); } if (!examTypeBrowserManager.isCodePresent(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam Type not found.")); } ExamType examType = examTypeMapper.map2Model(updateExamType); @@ -105,7 +105,7 @@ public ResponseEntity deleteExamType(@PathVariable String code) throws OHServ LOGGER.info("Delete Exam Type code: {}", code); Optional examType = examTypeBrowserManager.getExamType().stream().filter(e -> e.getCode().equals(code)).findFirst(); if (examType.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam Type not found.")); } examTypeBrowserManager.deleteExamType(examType.get()); if (examTypeBrowserManager.isCodePresent(code)) { diff --git a/src/main/java/org/isf/hospital/rest/HospitalController.java b/src/main/java/org/isf/hospital/rest/HospitalController.java index a52cf8471..8d07950a2 100644 --- a/src/main/java/org/isf/hospital/rest/HospitalController.java +++ b/src/main/java/org/isf/hospital/rest/HospitalController.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; @@ -59,10 +60,10 @@ public HospitalController(HospitalBrowsingManager hospitalBrowsingManager, Hospi public ResponseEntity updateHospital(@PathVariable String code, @RequestBody HospitalDTO hospitalDTO) throws OHServiceException { if (!hospitalDTO.getCode().equals(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Hospital code mismatch.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Hospital code mismatch.")); } if (hospitalBrowsingManager.getHospital().getCode() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Hospital not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Hospital not found.")); } Hospital hospital = hospitalMapper.map2Model(hospitalDTO); diff --git a/src/main/java/org/isf/lab/rest/LaboratoryController.java b/src/main/java/org/isf/lab/rest/LaboratoryController.java index 2bb2e8ad2..248869533 100644 --- a/src/main/java/org/isf/lab/rest/LaboratoryController.java +++ b/src/main/java/org/isf/lab/rest/LaboratoryController.java @@ -52,6 +52,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -123,13 +124,13 @@ public ResponseEntity newLaboratory(@RequestBody LabWithRowsDTO labWithRowsDT Patient patient = patientBrowserManager.getPatientById(laboratoryDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) .findFirst().orElse(null); if (exam == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } Laboratory labToInsert = laboratoryMapper.map2Model(laboratoryDTO); @@ -163,13 +164,13 @@ public ResponseEntity newExamRequest(@RequestBody LaboratoryDTO laboratoryDTO Patient patient = patientBrowserManager.getPatientById(laboratoryDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) .findFirst().orElse(null); if (exam == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } Laboratory labToInsert = laboratoryMapper.map2Model(laboratoryDTO); @@ -216,13 +217,13 @@ public ResponseEntity newLaboratory2(@RequestBody List labsWi LaboratoryDTO laboratoryDTO = labWithRowsDTO.getLaboratoryDTO(); Patient patient = patientBrowserManager.getPatientById(laboratoryDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Exam exam = examManager.getExams().stream() .filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())).findFirst().orElse(null); if (exam == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } Laboratory labToInsert = laboratoryMapper.map2Model(laboratoryDTO); @@ -267,26 +268,26 @@ public ResponseEntity updateLaboratory(@PathVariable Integer code, List labRow = labWithRowsDTO.getLaboratoryRowList(); if (!code.equals(laboratoryDTO.getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Laboratory code mismatch.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Laboratory code mismatch.")); } Optional labo = laboratoryManager.getLaboratory(code); if (!labo.isPresent()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Laboratory not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Laboratory not found.")); } Laboratory lab = labo.get(); if (lab.getStatus().equalsIgnoreCase(DELETED) || lab.getStatus().equalsIgnoreCase(INVALID)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("This exam can not be update because its status is " + lab.getStatus())); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("This exam can not be update because its status is " + lab.getStatus())); } Patient patient = patientBrowserManager.getPatientById(laboratoryDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) .findFirst().orElse(null); if (exam == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Exam not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Exam not found.")); } Laboratory labToInsert = laboratoryMapper.map2Model(laboratoryDTO); @@ -334,7 +335,7 @@ public ResponseEntity updateExamRequest(@PathVariable Integer code, @RequestP } return ResponseEntity.ok(true); } else { - return ResponseEntity.badRequest().body(new OHExceptionMessage("This status doesn't exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("This status doesn't exist.")); } } @@ -356,7 +357,7 @@ public ResponseEntity deleteExam(@PathVariable Integer code) throws OHService return ResponseEntity.internalServerError().body(new OHExceptionMessage("This exam can not be deleted because its status is " + labToDelete.getStatus())); } } else { - return ResponseEntity.badRequest().body("No Exam found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Exam found with the specified code."); } try { laboratoryManager.updateExamRequest(code, DELETED); @@ -427,7 +428,7 @@ public ResponseEntity getLaboratory(@PathVariable Integer patId) throws OHSer LOGGER.info("Get LabWithRows for patient Id: {}", patId); Patient patient = patientBrowserManager.getPatientById(patId); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } List labList = laboratoryManager.getLaboratory(patient).stream() @@ -477,7 +478,7 @@ public ResponseEntity getLaboratoryExamRequest(@PathVariable Integer patId) LOGGER.info("Get Exam requested by patient Id: {}", patId); Patient patient = patientBrowserManager.getPatientById(patId); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } List labList = laboratoryManager.getLaboratory(patient).stream() @@ -726,7 +727,7 @@ public ResponseEntity deleteExamRequest(@PathVariable Integer code) throws OH return ResponseEntity.internalServerError().body(new OHExceptionMessage("This exam can not be deleted because its status is " + lab.getStatus())); } } else { - return ResponseEntity.badRequest().body("No Exam found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Exam found with the specified code."); } try { laboratoryManager.updateExamRequest(code, INVALID); diff --git a/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java b/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java index 9a43c4e88..859935203 100644 --- a/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java +++ b/src/main/java/org/isf/malnutrition/rest/MalnutritionController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -151,7 +152,7 @@ public ResponseEntity deleteMalnutrition(@RequestParam int code) throws OHSer .collect(Collectors.toList()); } if (matchedMalnutritions.isEmpty()) { - return ResponseEntity.badRequest().body("No Malnutrition found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Malnutrition found with the specified code."); } try { manager.deleteMalnutrition(matchedMalnutritions.get(0)); diff --git a/src/main/java/org/isf/medical/rest/MedicalController.java b/src/main/java/org/isf/medical/rest/MedicalController.java index a94430b97..0f3bb6a3d 100644 --- a/src/main/java/org/isf/medical/rest/MedicalController.java +++ b/src/main/java/org/isf/medical/rest/MedicalController.java @@ -30,7 +30,6 @@ import org.isf.medical.mapper.MedicalMapper; import org.isf.medicals.manager.MedicalBrowsingManager; import org.isf.medicals.model.Medical; -import org.isf.shared.exceptions.OHAPIException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; import org.slf4j.Logger; @@ -39,6 +38,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -207,7 +207,7 @@ public ResponseEntity updateMedical( public ResponseEntity deleteMedical(@PathVariable Integer code) throws OHServiceException { Medical medical = medicalManager.getMedical(code); if (medical == null) { - return ResponseEntity.badRequest().body("No Medical found with the specified code"); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Medical found with the specified code"); } try { medicalManager.deleteMedical(medical); diff --git a/src/main/java/org/isf/medicalstockward/rest/MedicalStockWardController.java b/src/main/java/org/isf/medicalstockward/rest/MedicalStockWardController.java index 8572f0ed5..76bd9ada7 100644 --- a/src/main/java/org/isf/medicalstockward/rest/MedicalStockWardController.java +++ b/src/main/java/org/isf/medicalstockward/rest/MedicalStockWardController.java @@ -47,6 +47,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -113,11 +114,11 @@ public ResponseEntity getCurrentQuantityInWard( @RequestParam("med_id") int medicalId) throws OHServiceException { Medical medical = medicalManager.getMedical(medicalId); if (medical == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The medical not found with the specified code")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The medical not found with the specified code")); } List wards = wardManager.getWards().stream().filter(w -> w.getCode().equals(wardId)).collect(Collectors.toList()); if (wards == null || wards.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The ward not found with the specified code")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The ward not found with the specified code")); } return ResponseEntity.ok(movWardBrowserManager.getCurrentQuantityInWard(wards.get(0), medical)); } diff --git a/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java b/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java index b40cb36e1..784c464a9 100644 --- a/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java +++ b/src/main/java/org/isf/medstockmovtype/rest/MedStockMovementTypeController.java @@ -38,6 +38,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -123,7 +124,7 @@ public ResponseEntity updateMedicalDsrStockMovementType(@RequestBody @Valid M throws OHServiceException { MovementType medicalDsrStockMovementType = mapper.map2Model(medicalDsrStockMovementTypeDTO); if (!manager.isCodePresent(medicalDsrStockMovementType.getCode())) { - return ResponseEntity.badRequest().body("Movement type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Movement type not found."); } try { MovementType isUpdatedMovementType = manager.updateMedicalDsrStockMovementType(medicalDsrStockMovementType); @@ -157,7 +158,7 @@ public ResponseEntity deleteMedicalDsrStockMovementType(@PathVariable("code") .filter(item -> item.getCode().equals(code)) .collect(Collectors.toList()); if (matchedMvmntTypes.isEmpty()) { - return ResponseEntity.badRequest().body("No Movement type found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Movement type found with the specified code."); } try { manager.deleteMedicalDsrStockMovementType(matchedMvmntTypes.get(0)); diff --git a/src/main/java/org/isf/medtype/rest/MedicalTypeController.java b/src/main/java/org/isf/medtype/rest/MedicalTypeController.java index 83d1997e0..449c7ca4f 100644 --- a/src/main/java/org/isf/medtype/rest/MedicalTypeController.java +++ b/src/main/java/org/isf/medtype/rest/MedicalTypeController.java @@ -38,6 +38,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -106,7 +107,7 @@ public ResponseEntity createMedicalType(@RequestBody @Valid MedicalTypeDTO me public ResponseEntity updateMedicalType(@RequestBody @Valid MedicalTypeDTO medicalTypeDTO) throws OHServiceException { MedicalType medicalType = medicalTypeMapper.map2Model(medicalTypeDTO); if (!medicalTypeBrowserManager.isCodePresent(medicalType.getCode())) { - return ResponseEntity.badRequest().body("Medical type not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Medical type not found."); } MedicalType isUpdatedMedicalType = medicalTypeBrowserManager.updateMedicalType(medicalType); if (isUpdatedMedicalType == null) { @@ -146,7 +147,7 @@ public ResponseEntity deleteMedicalType(@PathVariable("code") String code) th } return ResponseEntity.ok(true); } else { - return ResponseEntity.badRequest().body("No Medical type found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No Medical type found with the specified code."); } } } diff --git a/src/main/java/org/isf/menu/rest/UserController.java b/src/main/java/org/isf/menu/rest/UserController.java index 28a610fab..168581f9a 100644 --- a/src/main/java/org/isf/menu/rest/UserController.java +++ b/src/main/java/org/isf/menu/rest/UserController.java @@ -52,6 +52,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -169,7 +170,7 @@ public ResponseEntity updateUser( return ResponseEntity.internalServerError().body(new OHExceptionMessage("Not allowed.")); } if (userManager.getUserByName(requestUserName) == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The specified user does not exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The specified user does not exist.")); } User user = userMapper.map2Model(userDTO); boolean isUpdated; @@ -194,7 +195,7 @@ public ResponseEntity updateUser( public ResponseEntity deleteUser(@PathVariable String username) throws OHServiceException { User foundUser = userManager.getUserByName(username); if (foundUser == null) { - return ResponseEntity.badRequest().body("No user found with the specified username."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No user found with the specified username."); } try { userManager.deleteUser(foundUser); @@ -263,7 +264,7 @@ public ResponseEntity newUserGroup(@Valid @RequestBody UserGroupDTO aGroup) t public ResponseEntity updateUserGroup(@Valid @RequestBody UserGroupDTO aGroup) throws OHServiceException { UserGroup group = userGroupMapper.map2Model(aGroup); if (userManager.getUserGroup().stream().noneMatch(g -> g.getCode().equals(group.getCode()))) { - return ResponseEntity.badRequest().body("User group not found"); + return ((BodyBuilder) ResponseEntity.notFound()).body("User group not found"); } boolean isUpdated = userManager.updateUserGroup(group); if (isUpdated) { @@ -276,7 +277,7 @@ public ResponseEntity updateUserGroup(@Valid @RequestBody UserGroupDTO aGroup private UserGroup loadUserGroup(String code) throws OHServiceException { List group = userManager.getUserGroup().stream().filter(g -> g.getCode().equals(code)).collect(Collectors.toList()); if (group.isEmpty()) { - throw new OHAPIException(new OHExceptionMessage("User group not found.")); + ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("User group not found.")); } return group.get(0); } @@ -376,13 +377,13 @@ public ResponseEntity newUserSettings(@Valid @RequestBody UserSettingDTO user final String ADMIN = "admin"; if (!requestUserName.equals(currentUser) && !currentUser.equals(ADMIN)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Not allowed.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Not allowed.")); } if (userSettingManager.getUserSettingByUserNameConfigName(requestUserName, userSettingDTO.getConfigName()) != null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("A setting with that name already exists.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("A setting with that name already exists.")); } if (userManager.getUserByName(requestUserName) == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The specified user does not exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The specified user does not exist.")); } userSettingDTO.setId(0); UserSetting userSetting = userSettingMapper.map2Model(userSettingDTO); @@ -417,14 +418,14 @@ public ResponseEntity updateUserSettings(@PathVariable(name = "id") int id, @ UserSetting updated; if (userSetting.isEmpty()) { LOGGER.info("No user settings with id {}.", id); - return ResponseEntity.badRequest().body(new OHExceptionMessage("UserSetting doesn't exists.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("UserSetting doesn't exists.")); } if (!userSetting.get().getUser().equals(requestUserName) && !currentUser.equals(ADMIN)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Not allowed.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Not allowed.")); } if (userSetting.get().getUser().equals(currentUser) || currentUser.equals(ADMIN)) { if (userManager.getUserByName(requestUserName) == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("The specified user does not exist.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("The specified user does not exist.")); } UserSetting uSetting = userSettingMapper.map2Model(userSettingDTO); updated = userSettingManager.updateUserSetting(uSetting); @@ -495,7 +496,7 @@ public ResponseEntity deleteUserSetting(@PathVariable(name = "id") int id) th String currentUser = SecurityContextHolder.getContext().getAuthentication().getName(); if (userSetting.isEmpty()) { LOGGER.info("No user settings with id {}.", id); - return ResponseEntity.badRequest().body("No user setting found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No user setting found with the specified id."); } if (userSetting.get().getUser().equals(currentUser) || currentUser.equals(ADMIN)) { try { diff --git a/src/main/java/org/isf/opd/rest/OpdController.java b/src/main/java/org/isf/opd/rest/OpdController.java index f9f539933..c924e1925 100644 --- a/src/main/java/org/isf/opd/rest/OpdController.java +++ b/src/main/java/org/isf/opd/rest/OpdController.java @@ -52,6 +52,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -119,10 +120,10 @@ ResponseEntity newOpd(@RequestBody OpdDTO opdDTO) throws OHServiceException { LOGGER.info("store Out patient {}", code); Patient patient = patientManager.getPatientById(opdDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } if (" ".equals(opdDTO.getNote())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Note field mandatory.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Note field mandatory.")); } Opd opdToInsert = mapper.map2Model(opdDTO); opdToInsert.setPatient(patient); @@ -146,10 +147,10 @@ ResponseEntity newOpdWithOperationRow(@RequestBody OpdWithOperationRowDTO opd OpdWithOperationRowDTO opdWithOperatioRow = new OpdWithOperationRowDTO(); Patient patient = patientManager.getPatientById(opdWithOperationRowDTO.getOpdDTO().getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } if (" ".equals(opdWithOperationRowDTO.getOpdDTO().getNote())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Note field mandatory.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Note field mandatory.")); } Opd opdToInsert = mapper.map2Model(opdWithOperationRowDTO.getOpdDTO()); opdToInsert.setPatient(patient); @@ -182,16 +183,16 @@ ResponseEntity updateOpd(@PathVariable("code") int code, @RequestBody OpdDTO throws OHServiceException { LOGGER.info("Update opds code: {}", opdDTO.getCode()); if (opdManager.getOpdById(code).isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Opd not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Opd not found.")); } if (opdDTO.getCode() != 0 && opdDTO.getCode() != code) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Opd not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Opd not found.")); } Patient patient = patientManager.getPatientById(opdDTO.getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Opd opdToUpdate = mapper.map2Model(opdDTO); @@ -216,16 +217,16 @@ ResponseEntity updateOpdWithOperationRow(@PathVariable("code") int code, @Req LOGGER.info("Update opds code: {}", code); OpdWithOperationRowDTO opdWithOperatioRow = new OpdWithOperationRowDTO(); if (opdManager.getOpdById(code).isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Opd not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Opd not found.")); } if (opdWithOperationRowDTO.getOpdDTO().getCode() != 0 && opdWithOperationRowDTO.getOpdDTO().getCode() != code) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Opd not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Opd not found.")); } Patient patient = patientManager.getPatientById(opdWithOperationRowDTO.getOpdDTO().getPatientCode()); if (patient == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Opd opdToUpdate = mapper.map2Model(opdWithOperationRowDTO.getOpdDTO()); diff --git a/src/main/java/org/isf/operation/rest/OperationController.java b/src/main/java/org/isf/operation/rest/OperationController.java index d74bd8711..0ffe4b832 100644 --- a/src/main/java/org/isf/operation/rest/OperationController.java +++ b/src/main/java/org/isf/operation/rest/OperationController.java @@ -47,6 +47,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -103,7 +104,7 @@ ResponseEntity newOperation(@RequestBody OperationDTO operationDTO) throws OH String code = operationDTO.getCode(); LOGGER.info("Create operation {}.", code); if (operationManager.descriptionControl(operationDTO.getDescription(), operationDTO.getType().getCode())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Another operation already created with provided description and types.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Another operation already created with provided description and types.")); } Operation isCreatedOperation = operationManager.newOperation(mapper.map2Model(operationDTO)); if (isCreatedOperation == null) { @@ -124,7 +125,7 @@ ResponseEntity updateOperation(@PathVariable String code, @RequestBody Operat LOGGER.info("Update operations code: {}.", operationDTO.getCode()); Operation operation = mapper.map2Model(operationDTO); if (!operationManager.isCodePresent(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Operation not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Operation not found.")); } operation.setLock(operationDTO.getLock()); Operation isUpdatedOperation = operationManager.updateOperation(operation); @@ -196,7 +197,7 @@ public ResponseEntity deleteOperation(@PathVariable("code") String code) thro Operation operation = operationManager.getOperationByCode(code); if (operation == null) { - return ResponseEntity.badRequest().body("No operation found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No operation found with the specified code."); } try { operationManager.deleteOperation(operation); @@ -217,7 +218,7 @@ ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRowDTO) int code = operationRowDTO.getAdmission().getId(); LOGGER.info("Create operation: {}.", code); if (operationRowDTO.getAdmission() == null && operationRowDTO.getOpd() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("At least one field between admission and Opd is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("At least one field between admission and Opd is required.")); } OperationRow opRow = opRowMapper.map2Model(operationRowDTO); @@ -246,14 +247,14 @@ ResponseEntity newOperationRow(@RequestBody OperationRowDTO operationRowDTO) ResponseEntity updateOperationRow(@RequestBody OperationRowDTO operationRowDTO) throws OHServiceException { LOGGER.info("Update operations row code: {}.", operationRowDTO.getId()); if (operationRowDTO.getAdmission() == null && operationRowDTO.getOpd() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("At least one field between admission and Opd is required.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("At least one field between admission and Opd is required.")); } OperationRow opRow = opRowMapper.map2Model(operationRowDTO); List opRowFounds = operationRowManager.getOperationRowByAdmission(opRow.getAdmission()).stream().filter(op -> op.getId() == opRow.getId()) .collect(Collectors.toList()); if (opRowFounds.isEmpty()) { - return ResponseEntity.badRequest().body("Operation row not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Operation row not found."); } OperationRow updateOpeRow = operationRowManager.updateOperationRow(opRow); if (updateOpeRow == null) { diff --git a/src/main/java/org/isf/opetype/rest/OperationTypeController.java b/src/main/java/org/isf/opetype/rest/OperationTypeController.java index f5a2fb792..c71748a8e 100644 --- a/src/main/java/org/isf/opetype/rest/OperationTypeController.java +++ b/src/main/java/org/isf/opetype/rest/OperationTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -96,7 +97,7 @@ ResponseEntity updateOperationTypes(@PathVariable String code, @RequestBody O LOGGER.info("Update operationtypes code: {}", operationTypeDTO.getCode()); OperationType opeType = mapper.map2Model(operationTypeDTO); if (!opeTypeManager.isCodePresent(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Operation Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Operation Type not found.")); } OperationType updatedOperationType; try { @@ -146,7 +147,7 @@ public ResponseEntity deleteOperationType(@PathVariable("code") String code) } } } else { - return ResponseEntity.badRequest().body("No operation type found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No operation type found with the specified code."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/patconsensus/rest/PatientConsensusController.java b/src/main/java/org/isf/patconsensus/rest/PatientConsensusController.java index 771b25555..8f4a63f14 100644 --- a/src/main/java/org/isf/patconsensus/rest/PatientConsensusController.java +++ b/src/main/java/org/isf/patconsensus/rest/PatientConsensusController.java @@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; @@ -72,11 +73,11 @@ ResponseEntity updatePatientConsensus(@PathVariable Integer patientId, @Reque throws OHServiceException { LOGGER.info("Update patient consensus by id: {}", patientId); if (!patientId.equals(patientConsensus.getPatientId())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient code mismatch.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient code mismatch.")); } Optional patConsensusOpt = this.manager.getPatientConsensusByUserId(patientId); if (patConsensusOpt.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("PatientConsensus not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("PatientConsensus not found.")); } PatientConsensus updatedPatienConsensusModel = mapper.map2Model(patientConsensus); updatedPatienConsensusModel.setId(patConsensusOpt.get().getId()); diff --git a/src/main/java/org/isf/patient/rest/PatientController.java b/src/main/java/org/isf/patient/rest/PatientController.java index b7b42b69a..422fa8793 100644 --- a/src/main/java/org/isf/patient/rest/PatientController.java +++ b/src/main/java/org/isf/patient/rest/PatientController.java @@ -36,7 +36,6 @@ import org.isf.patient.manager.PatientBrowserManager; import org.isf.patient.mapper.PatientMapper; import org.isf.patient.model.Patient; -import org.isf.shared.exceptions.OHAPIException; import org.isf.shared.pagination.Page; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; @@ -47,6 +46,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -105,7 +105,7 @@ ResponseEntity newPatient(@RequestBody PatientDTO newPatient) throws OHServic // TODO: remove this line when UI will be ready to collect the patient consensus newPatient.setConsensusFlag(true); if (newPatient.getBlobPhoto() != null && newPatient.getBlobPhoto().length == 0) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Malformed picture.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Malformed picture.")); } Patient patientModel = patientMapper.map2Model(newPatient); Patient patient = patientManager.savePatient(patientModel); @@ -120,15 +120,15 @@ ResponseEntity newPatient(@RequestBody PatientDTO newPatient) throws OHServic ResponseEntity updatePatient(@PathVariable int code, @RequestBody PatientDTO updatePatient) throws OHServiceException { LOGGER.info("Update patient code: '{}'.", code); if (!updatePatient.getCode().equals(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient code mismatch.")); + return ResponseEntity.internalServerError().body(new OHExceptionMessage("Patient code mismatch.")); } Patient patientRead = patientManager.getPatientById(code); if (patientRead == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } Optional patientConsensus = patientConsensusManager.getPatientConsensusByUserId(patientRead.getCode()); if (patientConsensus.isEmpty()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("PatientConsensus not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("PatientConsensus not found.")); } if (updatePatient.getBlobPhoto() != null && updatePatient.getBlobPhoto().length == 0) { return ResponseEntity.badRequest().body(new OHExceptionMessage("Malformed picture.")); @@ -242,7 +242,7 @@ public ResponseEntity deletePatient(@PathVariable int code) throws OHServiceE Patient patient = patientManager.getPatientById(code); if (patient == null) { - return ResponseEntity.badRequest().body("No patient found with the specified code"); + return ((BodyBuilder) ResponseEntity.notFound()).body("Patient not found"); } try { patientManager.deletePatient(patient); @@ -258,7 +258,7 @@ public ResponseEntity mergePatients(@RequestParam int mergedcode, @RequestPar Patient mergedPatient = patientManager.getPatientById(mergedcode); Patient patient2 = patientManager.getPatientById(code2); if (mergedPatient == null || patient2 == null) { - return ResponseEntity.badRequest().body("Patient not found"); + return ((BodyBuilder) ResponseEntity.notFound()).body("Patient not found"); } try { patientManager.mergePatient(mergedPatient, patient2); diff --git a/src/main/java/org/isf/permissions/rest/PermissionController.java b/src/main/java/org/isf/permissions/rest/PermissionController.java index d7424c97e..06eb17471 100644 --- a/src/main/java/org/isf/permissions/rest/PermissionController.java +++ b/src/main/java/org/isf/permissions/rest/PermissionController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -133,7 +134,7 @@ public ResponseEntity updatePermission(@PathVariable int id, @RequestBody Per permissionDTO.setId(id); if (!permissionManager.exists(permissionDTO.getId())) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Permission not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Permission not found.")); } Permission model = permissionMapper.map2Model(permissionDTO); diff --git a/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java b/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java index 377c7c6ac..865b47395 100644 --- a/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java +++ b/src/main/java/org/isf/pregtreattype/rest/PregnantTreatmentTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -94,7 +95,7 @@ ResponseEntity updatePregnantTreatmentTypes(@PathVariable String code, @Reque LOGGER.info("Update PregnantTreatmentType code: {}", pregnantTreatmentTypeDTO.getCode()); PregnantTreatmentType pregTreatType = mapper.map2Model(pregnantTreatmentTypeDTO); if (!pregTreatTypeManager.isCodePresent(code)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Pregnant Treatment Type not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Pregnant Treatment Type not found.")); } PregnantTreatmentType isUpdatedPregnantTreatmentType = pregTreatTypeManager.updatePregnantTreatmentType(pregTreatType); if (isUpdatedPregnantTreatmentType == null) { @@ -142,7 +143,7 @@ public ResponseEntity deletePregnantTreatmentType(@PathVariable("code") Strin } } } else { - return ResponseEntity.badRequest().body("No pregnanc treatment found with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No pregnanc treatment found with the specified code."); } return ResponseEntity.ok(true); } diff --git a/src/main/java/org/isf/priceslist/rest/PriceListController.java b/src/main/java/org/isf/priceslist/rest/PriceListController.java index a198a2141..d9e51377d 100644 --- a/src/main/java/org/isf/priceslist/rest/PriceListController.java +++ b/src/main/java/org/isf/priceslist/rest/PriceListController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -154,7 +155,7 @@ public ResponseEntity deletePriceList(@PathVariable int id) throws OHServiceE List priceLists = priceListManager.getLists(); List priceListFounds = priceLists.stream().filter(pl -> pl.getId() == id).collect(Collectors.toList()); if (priceListFounds.isEmpty()) { - return ResponseEntity.badRequest().body("No price list found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No price list found with the specified id."); } try { priceListManager.deleteList(priceListFounds.get(0)); @@ -175,7 +176,7 @@ public ResponseEntity copyList(@PathVariable Long id) throws OHServiceExcepti List priceLists = priceListManager.getLists(); List priceListFounds = priceLists.stream().filter(pl -> pl.getId() == id).collect(Collectors.toList()); if (priceListFounds.isEmpty()) { - return ResponseEntity.badRequest().body("No price list found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No price list found with the specified id."); } try { priceListManager.copyList(priceListFounds.get(0)); @@ -196,7 +197,7 @@ public ResponseEntity copyByFactorAndStep(@PathVariable Long id, @RequestPara List priceLists = priceListManager.getLists(); List priceListFounds = priceLists.stream().filter(pl -> pl.getId() == id).collect(Collectors.toList()); if (priceListFounds.isEmpty()) { - return ResponseEntity.badRequest().body("No price list found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No price list found with the specified id."); } try { priceListManager.copyList(priceListFounds.get(0), factor, step); diff --git a/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java b/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java index 1b17a6881..2a78a246e 100644 --- a/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java +++ b/src/main/java/org/isf/pricesothers/rest/PricesOthersController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -97,7 +98,7 @@ ResponseEntity updatePricesOthers(@PathVariable Integer id, @RequestBody Pric List pricesOthersFounds = pricesOthersManager.getOthers().stream().filter(po -> po.getId() == pricesOthersDTO.getId()) .collect(Collectors.toList()); if (pricesOthersFounds.isEmpty()) { - return ResponseEntity.badRequest().body("Price others not found."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Price others not found."); } PricesOthers isUpdatedPricesOthers; try { @@ -137,7 +138,7 @@ public ResponseEntity deletePricesOthers(@PathVariable int id) throws OHServi List pricesOthers = pricesOthersManager.getOthers(); List pricesOthersFounds = pricesOthers.stream().filter(po -> po.getId() == id).collect(Collectors.toList()); if (pricesOthersFounds.isEmpty()) { - return ResponseEntity.badRequest().body("No price others found with the specified id."); + return ((BodyBuilder) ResponseEntity.notFound()).body("No price others found with the specified id."); } try { pricesOthersManager.deleteOther(pricesOthersFounds.get(0)); diff --git a/src/main/java/org/isf/sms/rest/SmsController.java b/src/main/java/org/isf/sms/rest/SmsController.java index 011fd4445..086781163 100644 --- a/src/main/java/org/isf/sms/rest/SmsController.java +++ b/src/main/java/org/isf/sms/rest/SmsController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -110,7 +111,7 @@ public ResponseEntity saveSms( public ResponseEntity deleteSms(@RequestBody @Valid List smsDTOList) throws OHServiceException { List smsList = smsMapper.map2ModelList(smsDTOList); if (smsList.stream().anyMatch(sms -> sms.getSmsId() <= 0)) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Some Sms are not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Some Sms are not found.")); } smsManager.delete(smsList); return ResponseEntity.ok(true); diff --git a/src/main/java/org/isf/stats/rest/ReportsController.java b/src/main/java/org/isf/stats/rest/ReportsController.java index 3a32f0d8b..33444cb96 100644 --- a/src/main/java/org/isf/stats/rest/ReportsController.java +++ b/src/main/java/org/isf/stats/rest/ReportsController.java @@ -39,6 +39,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -68,10 +69,10 @@ private ResponseEntity getReport(JasperReportResultDto resultDto, HttpServlet try { resource = new UrlResource(report.toUri()); if (!resource.exists()) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("File not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("File not found.")); } } catch (MalformedURLException e) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("File not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("File not found.")); } String contentType; diff --git a/src/main/java/org/isf/therapy/rest/TherapyController.java b/src/main/java/org/isf/therapy/rest/TherapyController.java index eb40c417b..82cd08194 100644 --- a/src/main/java/org/isf/therapy/rest/TherapyController.java +++ b/src/main/java/org/isf/therapy/rest/TherapyController.java @@ -44,6 +44,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -83,7 +84,7 @@ public class TherapyController { @PostMapping(value = "/therapies", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity newTherapy(@RequestBody TherapyRowDTO thRowDTO) throws OHServiceException { if (thRowDTO.getPatID() == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Patient not found.")); } TherapyRow thRow = therapyRowMapper.map2Model(thRowDTO); thRow = manager.newTherapy(thRow); diff --git a/src/main/java/org/isf/vaccine/rest/VaccineController.java b/src/main/java/org/isf/vaccine/rest/VaccineController.java index 59616959b..3741ad5ff 100644 --- a/src/main/java/org/isf/vaccine/rest/VaccineController.java +++ b/src/main/java/org/isf/vaccine/rest/VaccineController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -161,7 +162,7 @@ public ResponseEntity deleteVaccine(@PathVariable("code") String code) throws } return ResponseEntity.ok(true); } - return ResponseEntity.badRequest().body("Vaccine not fount with the specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Vaccine not fount with the specified code."); } /** diff --git a/src/main/java/org/isf/vactype/rest/VaccineTypeController.java b/src/main/java/org/isf/vactype/rest/VaccineTypeController.java index 1a46dbe16..2bb62cadd 100644 --- a/src/main/java/org/isf/vactype/rest/VaccineTypeController.java +++ b/src/main/java/org/isf/vactype/rest/VaccineTypeController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -144,7 +145,7 @@ public ResponseEntity deleteVaccineType(@PathVariable String code) throws OHS } return ResponseEntity.ok(true); } - return ResponseEntity.badRequest().body("Vaccine type not found with th specified code."); + return ((BodyBuilder) ResponseEntity.notFound()).body("Vaccine type not found with th specified code."); } /** diff --git a/src/main/java/org/isf/visits/rest/VisitsController.java b/src/main/java/org/isf/visits/rest/VisitsController.java index 961ddb8a9..52f2f20f3 100644 --- a/src/main/java/org/isf/visits/rest/VisitsController.java +++ b/src/main/java/org/isf/visits/rest/VisitsController.java @@ -36,6 +36,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -150,7 +151,7 @@ public ResponseEntity updateVisit(@PathVariable("visitID") int visitID, @Requ LOGGER.info("Create Visits"); Visit visit = visitManager.findVisit(visitID); if (visit == null) { - return ResponseEntity.badRequest().body(new OHExceptionMessage("Visit not found.")); + return ((BodyBuilder) ResponseEntity.notFound()).body(new OHExceptionMessage("Visit not found.")); } if (visit.getVisitID() != updateVisit.getVisitID()) { diff --git a/src/test/java/org/isf/accounting/rest/BillControllerTest.java b/src/test/java/org/isf/accounting/rest/BillControllerTest.java index 86605cb3f..596f6d881 100644 --- a/src/test/java/org/isf/accounting/rest/BillControllerTest.java +++ b/src/test/java/org/isf/accounting/rest/BillControllerTest.java @@ -1,6 +1,6 @@ /* * Open Hospital (www.open-hospital.org) - * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) * * Open Hospital is a free and open source software for healthcare data management. * @@ -191,7 +191,7 @@ public void when_post_bills_is_call_with_empty_body_then_BadRequest_HttpMessageN } @Test - public void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception { + public void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_Not_Found() throws Exception { String request = "/bills"; FullBillDTO newFullBillDTO = FullBillDTOHelper.setup(patientMapper, billItemsMapper, billPaymentsMapper); Integer id = 0; @@ -211,7 +211,7 @@ public void when_post_patients_PatientBrowserManager_getPatient_returns_null_the ) .andDo(log()) .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) //TODO Create OHCreateAPIException + .andExpect(status().isNotFound()) //TODO Create OHCreateAPIException .andExpect(content().string(containsString("Patient not found."))) .andReturn(); @@ -223,7 +223,7 @@ public void when_post_patients_PatientBrowserManager_getPatient_returns_null_the } @Test - public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception { + public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_Not_Found() throws Exception { Integer id = 123; String request = "/bills/{id}"; @@ -244,7 +244,7 @@ public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OH ) .andDo(log()) .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) //TODO Create OHCreateAPIException + .andExpect(status().isNotFound()) //TODO Create OHCreateAPIException .andExpect(content().string(containsString("Patient not found."))) .andReturn(); @@ -303,7 +303,7 @@ public void when_put_bills_PatientBrowserManager_getPatient_returns_null_then_OK .content(FullBillDTOHelper.asJsonString(newFullBillDTO)) ) .andDo(log()) - .andExpect(status().isCreated()) + .andExpect(status().isOk()) .andExpect(content().string(containsString(FullBillDTOHelper.asJsonString(newFullBillDTO)))) .andReturn(); } @@ -343,7 +343,7 @@ public void when_get_items_with_existent_id_then_getItems_is_empty_and_isNoConte .contentType(MediaType.APPLICATION_JSON) ) .andDo(log()) - .andExpect(status().isNoContent()); + .andExpect(status().isNotFound()); } @Test diff --git a/src/test/java/org/isf/patient/rest/PatientControllerTest.java b/src/test/java/org/isf/patient/rest/PatientControllerTest.java index 59ea83a06..7739d73f6 100644 --- a/src/test/java/org/isf/patient/rest/PatientControllerTest.java +++ b/src/test/java/org/isf/patient/rest/PatientControllerTest.java @@ -1,6 +1,6 @@ /* * Open Hospital (www.open-hospital.org) - * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) * * Open Hospital is a free and open source software for healthcare data management. * @@ -178,7 +178,7 @@ public void when_post_patients_is_call_with_empty_body_then_BadRequest_HttpMessa * @throws Exception */ @Test - public void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_BadRequest() throws Exception { + public void when_post_patients_PatientBrowserManager_getPatient_returns_null_then_OHAPIException_InternalServerError() throws Exception { String request = "/patients"; PatientDTO newPatientDTO = PatientHelper.setup(patientMapper); @@ -190,8 +190,8 @@ public void when_post_patients_PatientBrowserManager_getPatient_returns_null_the .contentType(MediaType.APPLICATION_JSON) .content(PatientHelper.asJsonString(newPatientDTO))) .andDo(log()) - .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) // TODO Create OHCreateAPIException + .andExpect(status().is5xxServerError()) + .andExpect(status().isInternalServerError()) // TODO Create OHCreateAPIException .andExpect(content().string(containsString("Patient not created."))) .andReturn(); @@ -265,7 +265,7 @@ public void when_post_patients_and_both_calls_to_PatientBrowserManager_success_t * @throws Exception */ @Test - public void when_put_update_patient_with_valid_body_and_existent_code_then_BadRequest() throws Exception { + public void when_put_update_patient_with_valid_body_and_existent_code_then_InternalServerError() throws Exception { String request = "/patients/{code}"; Integer code = 12345; @@ -293,8 +293,8 @@ public void when_put_update_patient_with_valid_body_and_existent_code_then_BadRe .content(PatientHelper.asJsonString(newPatientDTO))) .andDo(log()) .andDo(print()) - .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) + .andExpect(status().is5xxServerError()) + .andExpect(status().isInternalServerError()) .andExpect(content().string(containsString("Patient not updated."))); } @@ -331,7 +331,7 @@ public void when_put_update_patient_with_invalid_body_and_existent_code_then_Htt * @throws Exception */ @Test - public void when_put_update_patient_with_valid_body_and_unexistent_code_then_OHAPIException_BadRequest() throws Exception { + public void when_put_update_patient_with_valid_body_and_unexistent_code_then_OHAPIException_Not_Found() throws Exception { String request = "/patients/{code}"; Integer code = 123; @@ -345,7 +345,7 @@ public void when_put_update_patient_with_valid_body_and_unexistent_code_then_OHA .content(PatientHelper.asJsonString(newPatientDTO))) .andDo(log()) .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) // TODO Create OHUpdateAPIException + .andExpect(status().isNotFound()) // TODO Create OHUpdateAPIException .andExpect(content().string(containsString("Patient not found."))).andReturn(); // TODO Create OHUpdateAPIException @@ -456,7 +456,7 @@ public void when_get_patients_with_existent_code_and_admitted_then_response_Pati * @throws Exception */ @Test - public void when_get_patients_search_without_name_and_unexistent_code_then_response_null_and_NO_Content() throws Exception { + public void when_get_patients_search_without_name_and_unexistent_code_then_response_null_and_NOT_Fount() throws Exception { Integer code = 1000; String request = "/patients/search"; @@ -468,7 +468,7 @@ public void when_get_patients_search_without_name_and_unexistent_code_then_respo .param("code", code.toString()) .contentType(MediaType.APPLICATION_JSON)) .andDo(log()) - .andExpect(status().isNoContent()); + .andExpect(status().isNotFound()); } /** @@ -478,7 +478,7 @@ public void when_get_patients_search_without_name_and_unexistent_code_then_respo * @throws Exception */ @Test - public void when_get_patients_search_without_name_and_without_code_then_response_null_and_NO_Content() throws Exception { + public void when_get_patients_search_without_name_and_without_code_then_response_null_and_NOT_Found() throws Exception { String request = "/patients/search"; this.mockMvc @@ -486,7 +486,7 @@ public void when_get_patients_search_without_name_and_without_code_then_response get(request) .contentType(MediaType.APPLICATION_JSON)) .andDo(log()) - .andExpect(status().isNoContent()); + .andExpect(status().isNotFound()); } /** @@ -496,7 +496,7 @@ public void when_get_patients_search_without_name_and_without_code_then_response * @throws Exception */ @Test - public void when_get_patients_search_with_unexistent_name_and_without_code_then_response_null_and_NO_Content() throws Exception { + public void when_get_patients_search_with_unexistent_name_and_without_code_then_response_null_and_NOT_Found() throws Exception { String name = null; String request = "/patients/search"; @@ -508,7 +508,7 @@ public void when_get_patients_search_with_unexistent_name_and_without_code_then_ .param("name", name) .contentType(MediaType.APPLICATION_JSON)) .andDo(log()) - .andExpect(status().isNoContent()); + .andExpect(status().isNotFound()); } /** @@ -560,7 +560,7 @@ public void when_delete_patients_with_unexistent_code_then_response_Not_Found() * @throws Exception */ @Test - public void when_delete_patients_with_existent_code_but_fail_deletion_then_OHAPIException_BadRequest() throws Exception { + public void when_delete_patients_with_existent_code_but_fail_deletion_then_OHAPIException_InternalServerError() throws Exception { Integer code = 123; String request = "/patients/{code}"; Patient patient = PatientHelper.setup(); @@ -575,8 +575,8 @@ public void when_delete_patients_with_existent_code_but_fail_deletion_then_OHAPI delete(request, code) .contentType(MediaType.APPLICATION_JSON)) .andDo(log()) - .andExpect(status().is4xxClientError()) - .andExpect(status().isBadRequest()) // TODO Create OHDeleteAPIException + .andExpect(status().is5xxServerError()) + .andExpect(status().isInternalServerError()) // TODO Create OHDeleteAPIException .andExpect(content().string(containsString("Patient not deleted."))) .andReturn();