Changeset 6c00695 for backend/src
- Timestamp:
- 05/29/26 20:18:54 (4 months ago)
- Branches:
- master
- Children:
- b63d7b5
- Parents:
- f18b11b
- Location:
- backend/src/main/java/medora
- Files:
-
- 2 edited
-
controller/LabController.java (modified) (2 diffs)
-
service/LabService.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
backend/src/main/java/medora/controller/LabController.java
rf18b11b r6c00695 92 92 93 93 @GetMapping 94 public ResponseEntity<?> getAllLabTests() { 95 try { 94 public ResponseEntity<?> getAllLabTests(HttpServletRequest httpRequest) { 95 try { 96 String role = securityUtil.getRoleFromRequest(httpRequest); 97 if (role == null) { 98 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 99 .body(Map.of("error", "Unauthorized")); 100 } 101 102 // BILLING_ADMIN cannot access lab tests 103 if (role.equals("BILLING_ADMIN")) { 104 return ResponseEntity.status(HttpStatus.FORBIDDEN) 105 .body(Map.of("error", "You do not have permission to access lab tests")); 106 } 107 96 108 logger.info("Fetching all lab tests"); 97 109 List<LabTests> tests = labService.getAllLabTests(); … … 307 319 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) 308 320 .body(Map.of("error", "Failed to fetch pending lab tests: " + e.getMessage())); 321 } 322 } 323 324 @GetMapping("/results") 325 public ResponseEntity<?> getAllSubmittedLabResults(HttpServletRequest httpRequest) { 326 try { 327 String role = securityUtil.getRoleFromRequest(httpRequest); 328 if (role == null) { 329 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 330 .body(Map.of("error", "Unauthorized")); 331 } 332 333 if (!role.equals("LAB_TECHNICIAN")) { 334 return ResponseEntity.status(HttpStatus.FORBIDDEN) 335 .body(Map.of("error", "Only lab technicians can view submitted results")); 336 } 337 338 logger.info("Fetching all submitted lab results"); 339 List<MedicalRecordLabResults> results = labService.getAllSubmittedLabResults(); 340 List<Map<String, Object>> dtos = results.stream() 341 .map(recordResult -> { 342 LabResults labResult = recordResult.getLabResult(); 343 MedicalRecord medicalRecord = recordResult.getMedicalRecord(); 344 String patientName = "N/A"; 345 if (medicalRecord != null && medicalRecord.getPatient() != null) { 346 Patient patient = medicalRecord.getPatient(); 347 patientName = patient.getFirstName() + " " + patient.getLastName(); 348 } 349 Map<String, Object> resultMap = new java.util.HashMap<>(); 350 resultMap.put("resultId", labResult.getResultId()); 351 resultMap.put("testId", labResult.getLabTest().getTestId()); 352 resultMap.put("testName", labResult.getLabTest().getTestName()); 353 resultMap.put("patientName", patientName); 354 resultMap.put("doctorName", ""); 355 resultMap.put("testDate", labResult.getResultDate()); 356 resultMap.put("resultDate", labResult.getResultDate()); 357 resultMap.put("createdDate", labResult.getResultDate()); 358 resultMap.put("results", labResult.getResults()); 359 resultMap.put("description", labResult.getLabTest().getDescription() != null ? labResult.getLabTest().getDescription() : ""); 360 return resultMap; 361 }) 362 .collect(Collectors.toList()); 363 return ResponseEntity.ok(dtos); 364 } catch (RuntimeException e) { 365 logger.error("Error fetching submitted lab results: {}", e.getMessage()); 366 return ResponseEntity.badRequest() 367 .body(Map.of("error", e.getMessage())); 368 } catch (Exception e) { 369 logger.error("Unexpected error fetching submitted lab results: {}", e.getMessage()); 370 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) 371 .body(Map.of("error", "Failed to fetch submitted lab results: " + e.getMessage())); 309 372 } 310 373 } -
backend/src/main/java/medora/service/LabService.java
rf18b11b r6c00695 13 13 14 14 /** 15 * 15 * LabService handles lab test and lab result operations. 16 16 * UC013 – Record Lab Test Request 17 17 * UC014 – Store Lab Results … … 53 53 } 54 54 55 55 // ================= LAB TEST ================= 56 56 57 57 @Transactional … … 107 107 } 108 108 109 // UC013109 // ================= LAB TEST REQUESTS (UC013) ================= 110 110 111 111 @Transactional … … 172 172 } 173 173 174 // UC014, UC015174 // ================= LAB RESULTS (UC014, UC015) ================= 175 175 176 176 @Transactional … … 245 245 .toList(); 246 246 } 247 248 @Transactional(readOnly = true) 249 public List<MedicalRecordLabResults> getAllSubmittedLabResults() { 250 logger.info("Fetching all submitted lab results"); 251 return medicalRecordLabResultRepository.findAll(); 252 } 247 253 }
Note:
See TracChangeset
for help on using the changeset viewer.
