From ac3e7b2465c3ceb124c3210fcce31cf0e18833cb Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Thu, 21 Dec 2023 15:06:14 +0100 Subject: [PATCH] Workaround to fix validation error waiting for OH2-182 (#417) --- .../isf/lab/rest/LaboratoryController.java | 111 ++++++++++-------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/isf/lab/rest/LaboratoryController.java b/src/main/java/org/isf/lab/rest/LaboratoryController.java index 9b14c68b4..5f7486c47 100644 --- a/src/main/java/org/isf/lab/rest/LaboratoryController.java +++ b/src/main/java/org/isf/lab/rest/LaboratoryController.java @@ -72,18 +72,18 @@ public class LaboratoryController { private static final Logger LOGGER = LoggerFactory.getLogger(LaboratoryController.class); - + // TODO: to centralize protected static final String DEFAULT_PAGE_SIZE = "80"; - + private static final String DRAFT = LaboratoryStatus.draft.toString(); - + private static final String OPEN = LaboratoryStatus.open.toString(); private static final String DELETED = LaboratoryStatus.deleted.toString(); - + private static final String INVALID = LaboratoryStatus.invalid.toString(); - + private static final String DONE = LaboratoryStatus.done.toString(); @Autowired @@ -105,8 +105,8 @@ public class LaboratoryController { private LaboratoryForPrintMapper laboratoryForPrintMapper; public LaboratoryController(LabManager laboratoryManager, PatientBrowserManager patientBrowserManager, - ExamBrowsingManager examManager, LaboratoryMapper laboratoryMapper, LaboratoryRowMapper laboratoryRowMapper, - LaboratoryForPrintMapper laboratoryForPrintMapper) { + ExamBrowsingManager examManager, LaboratoryMapper laboratoryMapper, LaboratoryRowMapper laboratoryRowMapper, + LaboratoryForPrintMapper laboratoryForPrintMapper) { this.laboratoryManager = laboratoryManager; this.patientBrowserManager = patientBrowserManager; this.examManager = examManager; @@ -134,7 +134,7 @@ public ResponseEntity newLaboratory(@RequestBody LabWithRowsDTO labWith } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) - .findFirst().orElse(null); + .findFirst().orElse(null); if (exam == null) { throw new OHAPIException(new OHExceptionMessage("Exam not found.")); } @@ -155,7 +155,7 @@ public ResponseEntity newLaboratory(@RequestBody LabWithRowsDTO labWith } return ResponseEntity.status(HttpStatus.CREATED).body(true); } - + /** * Create a new {@link LaboratoryDTO}. * @@ -174,7 +174,7 @@ public ResponseEntity newExamRequest(@RequestBody LaboratoryDTO laborat } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) - .findFirst().orElse(null); + .findFirst().orElse(null); if (exam == null) { throw new OHAPIException(new OHExceptionMessage("Exam not found.")); } @@ -187,7 +187,7 @@ public ResponseEntity newExamRequest(@RequestBody LaboratoryDTO laborat labToInsert.setResult(""); labToInsert.setInOutPatient(laboratoryDTO.getInOutPatient().toString()); List labList = laboratoryManager.getLaboratory(patient).stream() - .filter(e -> e.getStatus().equals(DRAFT)).collect(Collectors.toList()); + .filter(e -> e.getStatus().equals(DRAFT)).collect(Collectors.toList()); if (!(labList == null || labList.isEmpty())) { for (Laboratory lab : labList) { @@ -214,7 +214,7 @@ public ResponseEntity newExamRequest(@RequestBody LaboratoryDTO laborat */ @PostMapping(value = "/laboratories/insertList", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity newLaboratory2(@RequestBody List labsWithRows) - throws OHServiceException { + throws OHServiceException { LOGGER.info("store List of Exam with result"); List labsToInsert = new ArrayList<>(); List> labsRowsToInsert = new ArrayList<>(); @@ -227,7 +227,7 @@ public ResponseEntity newLaboratory2(@RequestBody List } Exam exam = examManager.getExams().stream() - .filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())).findFirst().orElse(null); + .filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())).findFirst().orElse(null); if (exam == null) { throw new OHAPIException(new OHExceptionMessage("Exam not found.")); } @@ -242,7 +242,7 @@ public ResponseEntity newLaboratory2(@RequestBody List List labRowToInsert = new ArrayList<>(); for (String rowDescription : labWithRowsDTO.getLaboratoryRowList()) { labRowToInsert - .add(laboratoryRowMapper.map2Model(new LaboratoryRowDTO(rowDescription, laboratoryDTO))); + .add(laboratoryRowMapper.map2Model(new LaboratoryRowDTO(rowDescription, laboratoryDTO))); } if (!labRowToInsert.isEmpty()) { labsRowsToInsert.add(labRowToInsert); @@ -257,7 +257,7 @@ public ResponseEntity newLaboratory2(@RequestBody List } return ResponseEntity.status(HttpStatus.CREATED).body(true); } - + /** * Updates the specified {@link LaboratoryRowDTO} object. * @@ -268,7 +268,7 @@ public ResponseEntity newLaboratory2(@RequestBody List */ @PutMapping(value = "/laboratories/{code}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity updateLaboratory(@PathVariable Integer code, - @RequestBody LabWithRowsDTO labWithRowsDTO) throws OHServiceException { + @RequestBody LabWithRowsDTO labWithRowsDTO) throws OHServiceException { LOGGER.info("Update labWithRows code: {}", code); LaboratoryDTO laboratoryDTO = labWithRowsDTO.getLaboratoryDTO(); List labRow = labWithRowsDTO.getLaboratoryRowList(); @@ -291,7 +291,7 @@ public ResponseEntity updateLaboratory(@PathVariable Integer code, } Exam exam = examManager.getExams().stream().filter(e -> e.getCode().equals(laboratoryDTO.getExam().getCode())) - .findFirst().orElse(null); + .findFirst().orElse(null); if (exam == null) { throw new OHAPIException(new OHExceptionMessage("Exam not found.")); } @@ -307,10 +307,18 @@ public ResponseEntity updateLaboratory(@PathVariable Integer code, if (!laboratoryDTO.getResult().isEmpty()) { labToInsert.setStatus(DONE); } - laboratoryManager.updateLaboratory(labToInsert, labRows); + try { + laboratoryManager.updateLaboratory(labToInsert, labRows); + } catch (OHServiceException e) { + // TODO: workaround waiting OH2-182 + if (e.getMessages().get(0).getMessage().equals("angal.labnew.someexamswithoutresultpleasecheck.msg")) { + throw new OHAPIException(new OHExceptionMessage("errors.lab.someexamswithoutresultpleasecheck")); + } + throw new OHAPIException(e.getMessages().get(0)); + } return ResponseEntity.ok(true); } - + /** * Updates the specified {@link LaboratoryDTO} object. * @@ -322,7 +330,7 @@ public ResponseEntity updateLaboratory(@PathVariable Integer code, */ @PutMapping(value = "/laboratories/examRequest/{code}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity updateExamRequest(@PathVariable Integer code, @RequestParam String status) - throws OHServiceException { + throws OHServiceException { LOGGER.info("Update exam request code: {}", code); LaboratoryStatus stat = LaboratoryStatus.valueOf(status); if (stat != null) { @@ -335,9 +343,9 @@ public ResponseEntity updateExamRequest(@PathVariable Integer code, @Re } else { throw new OHAPIException(new OHExceptionMessage("This status doesn't exist.")); } - + } - + /** * Set an {@link LaboratoryDTO} record to be deleted. * @@ -375,7 +383,8 @@ public ResponseEntity deleteExam(@PathVariable Integer code) throws OHS * @throws OHServiceException */ @GetMapping(value = "/laboratories", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getLaboratory(@RequestParam boolean oneWeek, @RequestParam int page, @RequestParam int size) throws OHServiceException { + public ResponseEntity> getLaboratory(@RequestParam boolean oneWeek, @RequestParam int page, @RequestParam int size) + throws OHServiceException { LOGGER.info("Get all LabWithRows"); PagedResponse labListPageable = laboratoryManager.getLaboratoryPageable(oneWeek, page, size); if (labListPageable == null || labListPageable.getData().isEmpty()) { @@ -412,7 +421,7 @@ public ResponseEntity> getLaboratory(@RequestParam boolean labWithRowsDtoPageable.setData(labWithRowsDto); return ResponseEntity.ok(labWithRowsDtoPageable); } - + /** * Get all {@link LaboratoryRowDTO}s for the specified id. * @@ -429,7 +438,7 @@ public ResponseEntity> getLaboratory(@PathVariable Integer } List labList = laboratoryManager.getLaboratory(patient).stream() - .filter(e -> !e.getStatus().equalsIgnoreCase(DRAFT) && !e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); + .filter(e -> !e.getStatus().equalsIgnoreCase(DRAFT) && !e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); if (labList == null || labList.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } @@ -460,7 +469,7 @@ public ResponseEntity> getLaboratory(@PathVariable Integer return labDTO; }).collect(Collectors.toList())); } - + /** * Get all {@link LaboratoryDTO}s for the specified id. * @@ -471,7 +480,7 @@ public ResponseEntity> getLaboratory(@PathVariable Integer */ @GetMapping(value = "/laboratories/examRequest/patient/{patId}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getLaboratoryExamRequest(@PathVariable Integer patId) - throws OHServiceException { + throws OHServiceException { LOGGER.info("Get Exam requested by patient Id: {}", patId); Patient patient = patientBrowserManager.getPatientById(patId); if (patient == null) { @@ -479,7 +488,7 @@ public ResponseEntity> getLaboratoryExamRequest(@PathVariabl } List labList = laboratoryManager.getLaboratory(patient).stream() - .filter(e -> e.getStatus().equalsIgnoreCase(DRAFT) || e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); + .filter(e -> e.getStatus().equalsIgnoreCase(DRAFT) || e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); if (labList == null || labList.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } @@ -492,7 +501,7 @@ public ResponseEntity> getLaboratoryExamRequest(@PathVariabl return laboratoryDTO; }).collect(Collectors.toList())); } - + /** * Get all {@link LaboratoryDTO}s. * @@ -504,7 +513,7 @@ public ResponseEntity> getLaboratoryExamRequest(@PathVariabl public ResponseEntity> getLaboratoryExamRequest() throws OHServiceException { LOGGER.info("Get all Exam Requested"); List labList = laboratoryManager.getLaboratory().stream() - .filter(e -> e.getStatus().equalsIgnoreCase(DRAFT) || e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); + .filter(e -> e.getStatus().equalsIgnoreCase(DRAFT) || e.getStatus().equalsIgnoreCase(OPEN)).collect(Collectors.toList()); if (labList == null || labList.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } @@ -517,7 +526,7 @@ public ResponseEntity> getLaboratoryExamRequest() throws OHS return laboratoryDTO; }).collect(Collectors.toList())); } - + /** * Get all {@link String}s. * @@ -545,17 +554,17 @@ public ResponseEntity> getMaterials() throws OHServiceException { * @return the {@link List} of found {@link LabWithRowsDTO} or NO_CONTENT otherwise. * @throws OHServiceException */ - + @GetMapping(value = "/laboratories/exams", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getLaboratoryForPrint( - @RequestParam(required = false, defaultValue = "") String examName, - @RequestParam(value = "dateFrom") String dateFrom, @RequestParam(value = "dateTo") String dateTo, - @RequestParam(value = "patientCode", required = false, defaultValue = "0") int patientCode, - @RequestParam(value = "status", required = false, defaultValue = "") String status, - @RequestParam(value = "page", required = false, defaultValue = "0") int page, - @RequestParam(value = "size", required = false, defaultValue = DEFAULT_PAGE_SIZE) int size, - @RequestParam(value = "paged", required = false, defaultValue = "false") boolean paged) - throws OHServiceException { + @RequestParam(required = false, defaultValue = "") String examName, + @RequestParam(value = "dateFrom") String dateFrom, @RequestParam(value = "dateTo") String dateTo, + @RequestParam(value = "patientCode", required = false, defaultValue = "0") int patientCode, + @RequestParam(value = "status", required = false, defaultValue = "") String status, + @RequestParam(value = "page", required = false, defaultValue = "0") int page, + @RequestParam(value = "size", required = false, defaultValue = DEFAULT_PAGE_SIZE) int size, + @RequestParam(value = "paged", required = false, defaultValue = "false") boolean paged) + throws OHServiceException { LOGGER.info("Get labWithRow within specified date"); LOGGER.debug("examName: {}", examName); LOGGER.debug("dateFrom: {}", dateFrom); @@ -570,12 +579,12 @@ public ResponseEntity> getLaboratoryForPrint( LocalDateTime dateT = LocalDateTime.parse(dateTo, formatter); LocalDateTime dateF = LocalDateTime.parse(dateFrom, formatter); Page result = new Page<>(); - + if (patientCode != 0) { patient = patientBrowserManager.getPatientById(patientCode); if (patient == null || laboratoryManager.getLaboratory(patient) == null) { throw new OHAPIException(new OHExceptionMessage("Patient not found."), - HttpStatus.INTERNAL_SERVER_ERROR); + HttpStatus.INTERNAL_SERVER_ERROR); } } PagedResponse laboratoryPageable; @@ -583,16 +592,16 @@ public ResponseEntity> getLaboratoryForPrint( if (paged) { if (!status.isEmpty()) { if (!examName.isEmpty()) { - Exam exam = examManager.getExams(examName).get(0); + Exam exam = examManager.getExams(examName).get(0); laboratoryPageable = laboratoryManager.getLaboratoryPageable(exam, dateF, dateT, patient, page, size); } else { laboratoryPageable = laboratoryManager.getLaboratoryPageable(null, dateF, dateT, patient, page, size); } labList = laboratoryPageable.getData() - .stream().filter(lab -> lab.getStatus().equalsIgnoreCase(status)).collect(Collectors.toList()); + .stream().filter(lab -> lab.getStatus().equalsIgnoreCase(status)).collect(Collectors.toList()); } else { if (!examName.isEmpty()) { - Exam exam = examManager.getExams(examName).get(0); + Exam exam = examManager.getExams(examName).get(0); laboratoryPageable = laboratoryManager.getLaboratoryPageable(exam, dateF, dateT, patient, page, size); } else { laboratoryPageable = laboratoryManager.getLaboratoryPageable(null, dateF, dateT, patient, page, size); @@ -600,18 +609,18 @@ public ResponseEntity> getLaboratoryForPrint( labList = laboratoryPageable.getData(); } result.setPageInfo(laboratoryMapper.setParameterPageInfo(laboratoryPageable.getPageInfo())); - + } else { if (!status.isEmpty()) { labList = laboratoryManager.getLaboratory(examName, dateF, dateT, patient) - .stream().filter(lab -> lab.getStatus().equalsIgnoreCase(status)).collect(Collectors.toList()); - + .stream().filter(lab -> lab.getStatus().equalsIgnoreCase(status)).collect(Collectors.toList()); + } else { labList = laboratoryManager.getLaboratory(examName, dateF, dateT, patient); } } - + if (labList == null || labList.isEmpty()) { return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null); } else { @@ -645,7 +654,7 @@ public ResponseEntity> getLaboratoryForPrint( } } - /** + /** * Get all the {@link LaboratoryDTO}s for the specified id. * * @param code @@ -706,7 +715,7 @@ public ResponseEntity getExamWithRowsById(@PathVariable Integer lab.setLaboratoryRowList(labDescription); return ResponseEntity.ok(lab); } - + /** * Set an {@link Laboratory} record to be deleted. *