Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix good status code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Feb 15, 2024
1 parent 9f150cd commit f28ef11
Show file tree
Hide file tree
Showing 35 changed files with 186 additions and 177 deletions.
26 changes: 13 additions & 13 deletions src/main/java/org/isf/accounting/rest/BillController.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public BillController(BillBrowserManager billManager, PriceListManager priceList
* @throws OHServiceException
*/
@PostMapping(value = "/bills", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException {
public ResponseEntity<?> newBill(@RequestBody FullBillDTO newBillDto) throws OHServiceException {

if (newBillDto == null) {
throw new OHAPIException(new OHExceptionMessage("Bill is null."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill is null."));
}
LOGGER.info("Create Bill {}", newBillDto);

Expand All @@ -123,13 +123,13 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto)
if (pat != null) {
bill.setBillPatient(pat);
} else {
ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
}

if (plist != null) {
bill.setPriceList(plist);
} else {
ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
}

List<BillItems> billItems = billItemsMapper.map2ModelList(newBillDto.getBillItems());
Expand All @@ -139,9 +139,9 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto)
try {
billManager.newBill(bill, billItems, billPayments);
} catch (OHServiceException e) {
throw new OHAPIException(new OHExceptionMessage("Bill is not created."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not created."));
}
return ResponseEntity.ok().body(newBillDto);
return ResponseEntity.status(HttpStatus.CREATED).body(newBillDto);
}

/**
Expand All @@ -152,15 +152,15 @@ public ResponseEntity<FullBillDTO> newBill(@RequestBody FullBillDTO newBillDto)
* @throws OHServiceException
*/
@PutMapping(value = "/bills/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @RequestBody FullBillDTO odBillDto) throws OHServiceException {
public ResponseEntity<?> updateBill(@PathVariable Integer id, @RequestBody FullBillDTO odBillDto) throws OHServiceException {

LOGGER.info("updated Bill {}", odBillDto);
Bill bill = billMapper.map2Model(odBillDto.getBill());

bill.setId(id);

if (billManager.getBill(id) == null) {
ResponseEntity.badRequest().body(new OHExceptionMessage("Bill to update not found."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Bill to update not found."));
}

Patient pat = patientManager.getPatientById(bill.getBillPatient().getCode());
Expand All @@ -172,13 +172,13 @@ public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @Request
if (pat != null) {
bill.setBillPatient(pat);
} else {
ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Patient not found."));
}

if (plist != null) {
bill.setPriceList(plist);
} else {
ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Price list not found."));
}

List<BillItems> billItems = billItemsMapper.map2ModelList(odBillDto.getBillItems());
Expand All @@ -188,7 +188,7 @@ public ResponseEntity<FullBillDTO> updateBill(@PathVariable Integer id, @Request
try {
billManager.updateBill(bill, billItems, billPayments);
} catch (OHServiceException e) {
throw new OHAPIException(new OHExceptionMessage("Bill is not updated."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("Bill is not updated."));
}
return ResponseEntity.ok().body(odBillDto);
}
Expand Down Expand Up @@ -411,11 +411,11 @@ public ResponseEntity<List<BillItemsDTO>> getDistinctItems() throws OHServiceExc
}

@DeleteMapping(value = "/bills/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Boolean> deleteBill(@PathVariable Integer id) throws OHServiceException {
public ResponseEntity<?> deleteBill(@PathVariable Integer id) throws OHServiceException {
LOGGER.info("Delete bill id: {}", id);
Bill bill = billManager.getBill(id);
if (bill == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("No bill found with the specified id.");
}
try {
billManager.deleteBill(bill);
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/isf/admission/rest/AdmissionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ public AdmissionController(AdmissionBrowserManager admissionManager, PatientBrow
* @throws OHServiceException
*/
@GetMapping(value = "/admissions/patient/{patientCode}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<AdmissionDTO>> getAdmissions(@PathVariable("patientCode") int patientCode) throws OHServiceException {
public ResponseEntity<?> getAdmissions(@PathVariable("patientCode") int patientCode) throws OHServiceException {
LOGGER.info("Get admission by patient id: {}", patientCode);
Patient patient = patientManager.getPatientById(patientCode);
if (patient == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("No patient found with the specified code.");
}
List<Admission> listAdmissions = admissionManager.getAdmissions(patient);
if (listAdmissions == null) {
Expand All @@ -179,12 +179,12 @@ public ResponseEntity<List<AdmissionDTO>> getAdmissions(@PathVariable("patientCo
* @throws OHServiceException
*/
@GetMapping(value = "/admissions/current", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<AdmissionDTO> getCurrentAdmission(@RequestParam("patientCode") int patientCode)
public ResponseEntity<?> getCurrentAdmission(@RequestParam("patientCode") int patientCode)
throws OHServiceException {
LOGGER.info("Get admission by patient code: {}", patientCode);
Patient patient = patientManager.getPatientById(patientCode);
if (patient == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("No patient found with the specified code.");
}
Admission admission = admissionManager.getCurrentAdmission(patient);
if (admission == null) {
Expand Down Expand Up @@ -297,7 +297,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.notFound().build();
return ResponseEntity.badRequest().body("No ward found with the specified code.");
}

return ResponseEntity.ok(admissionManager.getNextYProg(wardCode));
Expand All @@ -315,7 +315,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.notFound().build();
return ResponseEntity.badRequest().body("No ward found with the specified code.");
}

return ResponseEntity.ok(admissionManager.getUsedWardBed(wardCode));
Expand All @@ -329,11 +329,11 @@ public ResponseEntity<?> getUsedWardBed(@RequestParam("wardid") String wardCode)
* @throws OHServiceException
*/
@DeleteMapping(value = "/admissions/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Boolean> deleteAdmissionType(@PathVariable("id") int id) throws OHServiceException {
public ResponseEntity<?> deleteAdmission(@PathVariable("id") int id) throws OHServiceException {
LOGGER.info("setting admission to deleted: {}", id);
Admission admission = admissionManager.getAdmission(id);
if (admission == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("No admission found with the specified id.");
}
admissionManager.setDeleted(id);
return ResponseEntity.ok(true);
Expand All @@ -354,17 +354,17 @@ public ResponseEntity<?> dischargePatient(@RequestParam("patientCode") int patie
Patient patient = patientManager.getPatientById(patientCode);

if (patient == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("No patient found with the specified code.");
}
Admission admission = admissionManager.getCurrentAdmission(patient);

if (admission == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("Patient is not admitted.");
}
Admission adm = admissionMapper.map2Model(currentAdmissionDTO);

if (adm == null || admission.getId() != adm.getId()) {
return ResponseEntity.internalServerError().build();
return ResponseEntity.badRequest().body("Current admission not found.");
}
if (adm.getDiseaseOut1() == null) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("at least one disease must be give."));
Expand Down Expand Up @@ -529,7 +529,7 @@ ResponseEntity<?> newAdmissions(@Valid @RequestBody AdmissionDTO newAdmissionDTO
newAdmission.setId(aId);
}
AdmissionDTO admDTO = admissionMapper.map2DTO(newAdmission);
return ResponseEntity.ok().body(admDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(admDTO);
}

@ExceptionHandler
Expand All @@ -550,7 +550,7 @@ ResponseEntity<?> updateAdmissions(@RequestBody AdmissionDTO updateAdmissionDTO)

Admission old = admissionManager.getAdmission(updateAdmissionDTO.getId());
if (old == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("Admission not found.");
}
Admission updateAdmission = admissionMapper.map2Model(updateAdmissionDTO);

Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/isf/admtype/rest/AdmissionTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -75,10 +76,10 @@ 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("Admission Type is not created."));
if (admtManager.isCodePresent(code)) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("The code of Admission Type is already used."));
}
return ResponseEntity.ok().body(mapper.map2DTO(newAdmissionType));
return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newAdmissionType));
}

/**
Expand All @@ -88,12 +89,12 @@ ResponseEntity<?> newAdmissionType(@RequestBody AdmissionTypeDTO admissionTypeDT
* @throws OHServiceException
*/
@PutMapping(value = "/admissiontypes", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<AdmissionTypeDTO> updateAdmissionTypes(@RequestBody AdmissionTypeDTO admissionTypeDTO)
ResponseEntity<?> updateAdmissionTypes(@RequestBody AdmissionTypeDTO admissionTypeDTO)
throws OHServiceException {
LOGGER.info("Update admissiontypes code: {}", admissionTypeDTO.getCode());
AdmissionType admt = mapper.map2Model(admissionTypeDTO);
if (!admtManager.isCodePresent(admt.getCode())) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body(new OHExceptionMessage("The Admission Type is not found."));
}
AdmissionType updatedAdmissionType = admtManager.updateAdmissionType(admt);
return ResponseEntity.ok(mapper.map2DTO(updatedAdmissionType));
Expand All @@ -110,7 +111,7 @@ public ResponseEntity<List<AdmissionTypeDTO>> getAdmissionTypes() throws OHServi
List<AdmissionType> admissionTypes = admtManager.getAdmissionType();
List<AdmissionTypeDTO> admissionTypeDTOs = mapper.map2DTOList(admissionTypes);
if (admissionTypeDTOs.isEmpty()) {
return ResponseEntity.internalServerError().build();
return ResponseEntity.notFound().build();
} else {
return ResponseEntity.ok(admissionTypeDTOs);
}
Expand All @@ -123,7 +124,7 @@ public ResponseEntity<List<AdmissionTypeDTO>> getAdmissionTypes() throws OHServi
* @throws OHServiceException
*/
@DeleteMapping(value = "/admissiontypes/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Boolean> deleteAdmissionType(@PathVariable("code") String code) throws OHServiceException {
public ResponseEntity<?> deleteAdmissionType(@PathVariable("code") String code) throws OHServiceException {
LOGGER.info("Delete Admission Type code: {}", code);
if (admtManager.isCodePresent(code)) {
List<AdmissionType> admissionTypes = admtManager.getAdmissionType();
Expand All @@ -133,7 +134,7 @@ public ResponseEntity<Boolean> deleteAdmissionType(@PathVariable("code") String
admtManager.deleteAdmissionType(admtFounds.get(0));
}
} else {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("The Admission Type is not found.");
}
return ResponseEntity.ok(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/isf/agetype/rest/AgeTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ResponseEntity<?> updateAgeType(@Valid @RequestBody AgeTypeDTO ageTypeDTO) throw
ageTypeManager.updateAgeType(ageTypes);
return ResponseEntity.ok(ageTypeDTO);
} catch (OHServiceException ex) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("The age type is not updated."));
return ResponseEntity.internalServerError().body(new OHExceptionMessage("The age type is not updated."));
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/isf/disctype/rest/DischargeTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -78,7 +79,7 @@ ResponseEntity<?> newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) t
if (!discTypeManager.isCodePresent(code)) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok().body(mapper.map2DTO(newDischargeType));
return ResponseEntity.status(HttpStatus.CREATED).body(mapper.map2DTO(newDischargeType));
}

/**
Expand All @@ -88,15 +89,15 @@ ResponseEntity<?> newDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) t
* @throws OHServiceException
*/
@PutMapping(value = "/dischargetypes", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<?> updateDischargeTypet(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException {
ResponseEntity<?> updateDischargeType(@RequestBody DischargeTypeDTO dischTypeDTO) throws OHServiceException {
LOGGER.info("Update discharge type with code: {}", dischTypeDTO.getCode());
DischargeType dischType = mapper.map2Model(dischTypeDTO);
if (!discTypeManager.isCodePresent(dischTypeDTO.getCode())) {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body(null);
}
DischargeType updatedDischargeType = discTypeManager.updateDischargeType(dischType);
if (!discTypeManager.isCodePresent(updatedDischargeType.getCode())) {
return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge Type is not updated."));
return ResponseEntity.badRequest().body(new OHExceptionMessage("Discharge Type not found."));
}
return ResponseEntity.ok(mapper.map2DTO(dischType));
}
Expand All @@ -112,7 +113,7 @@ public ResponseEntity<List<DischargeTypeDTO>> getDischargeTypes() throws OHServi
List<DischargeType> dischTypes = discTypeManager.getDischargeType();
List<DischargeTypeDTO> dischTypeDTOs = mapper.map2DTOList(dischTypes);
if (dischTypeDTOs.isEmpty()) {
return ResponseEntity.internalServerError().body(dischTypeDTOs);
return ResponseEntity.notFound().build();
} else {
return ResponseEntity.ok(dischTypeDTOs);
}
Expand All @@ -125,7 +126,7 @@ public ResponseEntity<List<DischargeTypeDTO>> getDischargeTypes() throws OHServi
* @throws OHServiceException
*/
@DeleteMapping(value = "/dischargetypes/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Boolean> deleteDischargeType(@PathVariable("code") String code) throws OHServiceException {
public ResponseEntity<?> deleteDischargeType(@PathVariable("code") String code) throws OHServiceException {
LOGGER.info("Delete discharge type code: {}", code);
if (discTypeManager.isCodePresent(code)) {
List<DischargeType> dischTypes = discTypeManager.getDischargeType();
Expand All @@ -135,7 +136,7 @@ public ResponseEntity<Boolean> deleteDischargeType(@PathVariable("code") String
discTypeManager.deleteDischargeType(dischTypeFounds.get(0));
}
} else {
return ResponseEntity.notFound().build();
return ResponseEntity.badRequest().body("Discharge Type not found.");
}
return ResponseEntity.ok(true);
}
Expand Down
Loading

0 comments on commit f28ef11

Please sign in to comment.