Changeset ed083e6
- Timestamp:
- 05/24/26 11:34:17 (4 months ago)
- Branches:
- master
- Children:
- cb0881d
- Parents:
- ccb5a6b
- Location:
- backend/src/main
- Files:
-
- 3 added
- 6 edited
-
java/medora/controller/AppointmentController.java (modified) (2 diffs)
-
java/medora/controller/PatientController.java (modified) (4 diffs)
-
java/medora/models/domain/User.java (modified) (1 diff)
-
java/medora/repository/BillingRepository.java (modified) (3 diffs)
-
java/medora/service/AuthService.java (modified) (1 diff)
-
java/medora/service/BillingService.java (modified) (1 diff)
-
resources/db.migration/V3__Insert_Doctor_Users.sql (added)
-
resources/db.migration/V4__Insert_Lab_Technician_Users.sql (added)
-
resources/db.migration/V5__Insert_Billing_Admin_Users.sql (added)
Legend:
- Unmodified
- Added
- Removed
-
backend/src/main/java/medora/controller/AppointmentController.java
rccb5a6b red083e6 119 119 } 120 120 121 // Patients cannot view all appointments122 if (role.equals("PATIENT") ) {121 // Patients, BILLING_ADMIN, and LAB_TECHNICIAN cannot view all appointments 122 if (role.equals("PATIENT") || role.equals("BILLING_ADMIN") || role.equals("LAB_TECHNICIAN")) { 123 123 return ResponseEntity.status(HttpStatus.FORBIDDEN) 124 .body(Map.of("error", " Patients cannot view allappointments"));124 .body(Map.of("error", "You do not have permission to view appointments")); 125 125 } 126 126 … … 137 137 appointments = appointmentService.getAppointmentsForDoctor(doctorIdFromToken); 138 138 } else { 139 // ADMIN and other rolescan view all appointments139 // ADMIN can view all appointments 140 140 logger.info("Fetching all appointments"); 141 141 appointments = appointmentService.getAllAppointments(); -
backend/src/main/java/medora/controller/PatientController.java
rccb5a6b red083e6 84 84 85 85 @GetMapping("/{patientId}") 86 public ResponseEntity<?> getPatientById(@PathVariable Long patientId) { 87 try { 86 public ResponseEntity<?> getPatientById(@PathVariable Long patientId, HttpServletRequest httpRequest) { 87 try { 88 String role = securityUtil.getRoleFromRequest(httpRequest); 89 if (role == null) { 90 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 91 .body(Map.of("error", "Unauthorized")); 92 } 93 94 // BILLING_ADMIN and LAB_TECHNICIAN cannot view patients 95 if (role.equals("BILLING_ADMIN") || role.equals("LAB_TECHNICIAN")) { 96 return ResponseEntity.status(HttpStatus.FORBIDDEN) 97 .body(Map.of("error", "You do not have permission to view patients")); 98 } 99 88 100 logger.info("Fetching patient with ID: {}", patientId); 89 101 return patientService.getPatientById(patientId) … … 102 114 103 115 @GetMapping("/embg/{embg}") 104 public ResponseEntity<?> getPatientByEmbg(@PathVariable String embg) { 105 try { 116 public ResponseEntity<?> getPatientByEmbg(@PathVariable String embg, HttpServletRequest httpRequest) { 117 try { 118 String role = securityUtil.getRoleFromRequest(httpRequest); 119 if (role == null) { 120 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 121 .body(Map.of("error", "Unauthorized")); 122 } 123 124 // BILLING_ADMIN and LAB_TECHNICIAN cannot view patients 125 if (role.equals("BILLING_ADMIN") || role.equals("LAB_TECHNICIAN")) { 126 return ResponseEntity.status(HttpStatus.FORBIDDEN) 127 .body(Map.of("error", "You do not have permission to view patients")); 128 } 129 106 130 logger.info("Fetching patient with EMBG: {}", embg); 107 131 return patientService.getPatientByEmbg(embg) … … 120 144 121 145 @GetMapping("/email/{emailAddress}") 122 public ResponseEntity<?> getPatientByEmail(@PathVariable String emailAddress) { 123 try { 146 public ResponseEntity<?> getPatientByEmail(@PathVariable String emailAddress, HttpServletRequest httpRequest) { 147 try { 148 String role = securityUtil.getRoleFromRequest(httpRequest); 149 if (role == null) { 150 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 151 .body(Map.of("error", "Unauthorized")); 152 } 153 154 // BILLING_ADMIN and LAB_TECHNICIAN cannot view patients 155 if (role.equals("BILLING_ADMIN") || role.equals("LAB_TECHNICIAN")) { 156 return ResponseEntity.status(HttpStatus.FORBIDDEN) 157 .body(Map.of("error", "You do not have permission to view patients")); 158 } 159 124 160 logger.info("Fetching patient with email: {}", emailAddress); 125 161 return patientService.getPatientByEmail(emailAddress) … … 138 174 139 175 @GetMapping 140 public ResponseEntity<?> getAllPatients() { 141 try { 176 public ResponseEntity<?> getAllPatients(HttpServletRequest httpRequest) { 177 try { 178 String role = securityUtil.getRoleFromRequest(httpRequest); 179 if (role == null) { 180 return ResponseEntity.status(HttpStatus.UNAUTHORIZED) 181 .body(Map.of("error", "Unauthorized")); 182 } 183 184 // BILLING_ADMIN and LAB_TECHNICIAN cannot view patients 185 if (role.equals("BILLING_ADMIN") || role.equals("LAB_TECHNICIAN")) { 186 return ResponseEntity.status(HttpStatus.FORBIDDEN) 187 .body(Map.of("error", "You do not have permission to view patients")); 188 } 189 142 190 logger.info("Fetching all patients"); 143 191 List<Patient> patients = patientService.getAllPatients(); -
backend/src/main/java/medora/models/domain/User.java
rccb5a6b red083e6 34 34 private Boolean isActive = true; 35 35 36 // Foreign key to patient (only for PATIENT role)37 @OneToOne(fetch = FetchType.LAZY)36 // Foreign key to patient for PATIENT role 37 @OneToOne(fetch = jakarta.persistence.FetchType.LAZY) 38 38 @JoinColumn(name = "patient_id") 39 39 private Patient patient; 40 40 41 // Foreign key to doctor (only for DOCTOR role)42 @OneToOne(fetch = FetchType.LAZY)41 // Foreign key to doctor for DOCTOR role 42 @OneToOne(fetch = jakarta.persistence.FetchType.LAZY) 43 43 @JoinColumn(name = "doctor_id") 44 44 private Doctors doctor; -
backend/src/main/java/medora/repository/BillingRepository.java
rccb5a6b red083e6 55 55 BigDecimal calculateTotalCostForMedicalRecord(@Param("recordId") Long recordId); 56 56 57 // Helper:Get billing records by payment status57 //Get billing records by payment status 58 58 @Query(""" 59 59 SELECT b FROM Billing b … … 63 63 List<Billing> findByPaymentStatus(@Param("status") String status); 64 64 65 // Helper:Get unpaid bills for a patient65 // Get unpaid bills for a patient 66 66 @Query(""" 67 67 SELECT b FROM Billing b … … 72 72 List<Billing> findUnpaidBillsForPatient(@Param("patientId") Long patientId); 73 73 74 // Helper:Get all bills for a patient sorted by date74 //Get all bills for a patient sorted by date 75 75 @Query(""" 76 76 SELECT b FROM Billing b -
backend/src/main/java/medora/service/AuthService.java
rccb5a6b red083e6 54 54 } 55 55 56 // Generate JWT token with patientId for patients57 56 Long patientId = user.getPatient() != null ? user.getPatient().getPatientId() : null; 58 String token = jwtUtil.generateToken(user.getUsername(), user.getRole(), user.getUserId(), patientId); 57 Long doctorId = user.getDoctor() != null ? user.getDoctor().getDoctorId() : null; 58 String token = jwtUtil.generateTokenWithDoctorId(user.getUsername(), user.getRole(), user.getUserId(), patientId, doctorId); 59 59 60 // Return response61 60 Map<String, Object> response = new HashMap<>(); 62 61 response.put("token", token); 63 62 response.put("userId", user.getUserId()); 64 response.put("patientId", user.getPatient() != null ? user.getPatient().getPatientId() : null); 63 response.put("patientId", patientId); 64 response.put("doctorId", doctorId); 65 65 response.put("username", user.getUsername()); 66 66 response.put("role", user.getRole()); -
backend/src/main/java/medora/service/BillingService.java
rccb5a6b red083e6 429 429 BillingDetailDTO detail = new BillingDetailDTO(); 430 430 detail.setBillId(billing.getBillId()); 431 detail.setPatientId(billing.getMedicalRecord().getPatient().getPatientId()); 431 432 detail.setPatientName(billing.getMedicalRecord().getPatient().getFirstName() + " " + 432 433 billing.getMedicalRecord().getPatient().getLastName());
Note:
See TracChangeset
for help on using the changeset viewer.
