Changeset ed083e6


Ignore:
Timestamp:
05/24/26 11:34:17 (4 months ago)
Author:
MBK <marija.karapandzova@…>
Branches:
master
Children:
cb0881d
Parents:
ccb5a6b
Message:

Assign role permissions for billing admins and add migrations for logging

Location:
backend/src/main
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • backend/src/main/java/medora/controller/AppointmentController.java

    rccb5a6b red083e6  
    119119            }
    120120
    121             // Patients cannot view all appointments
    122             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")) {
    123123                return ResponseEntity.status(HttpStatus.FORBIDDEN)
    124                         .body(Map.of("error", "Patients cannot view all appointments"));
     124                        .body(Map.of("error", "You do not have permission to view appointments"));
    125125            }
    126126
     
    137137                appointments = appointmentService.getAppointmentsForDoctor(doctorIdFromToken);
    138138            } else {
    139                 // ADMIN and other roles can view all appointments
     139                // ADMIN can view all appointments
    140140                logger.info("Fetching all appointments");
    141141                appointments = appointmentService.getAllAppointments();
  • backend/src/main/java/medora/controller/PatientController.java

    rccb5a6b red083e6  
    8484
    8585    @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
    88100            logger.info("Fetching patient with ID: {}", patientId);
    89101            return patientService.getPatientById(patientId)
     
    102114
    103115    @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
    106130            logger.info("Fetching patient with EMBG: {}", embg);
    107131            return patientService.getPatientByEmbg(embg)
     
    120144
    121145    @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
    124160            logger.info("Fetching patient with email: {}", emailAddress);
    125161            return patientService.getPatientByEmail(emailAddress)
     
    138174
    139175    @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
    142190            logger.info("Fetching all patients");
    143191            List<Patient> patients = patientService.getAllPatients();
  • backend/src/main/java/medora/models/domain/User.java

    rccb5a6b red083e6  
    3434    private Boolean isActive = true;
    3535
    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)
    3838    @JoinColumn(name = "patient_id")
    3939    private Patient patient;
    4040
    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)
    4343    @JoinColumn(name = "doctor_id")
    4444    private Doctors doctor;
  • backend/src/main/java/medora/repository/BillingRepository.java

    rccb5a6b red083e6  
    5555    BigDecimal calculateTotalCostForMedicalRecord(@Param("recordId") Long recordId);
    5656
    57     // Helper: Get billing records by payment status
     57   //Get billing records by payment status
    5858    @Query("""
    5959        SELECT b FROM Billing b
     
    6363    List<Billing> findByPaymentStatus(@Param("status") String status);
    6464
    65     // Helper: Get unpaid bills for a patient
     65    // Get unpaid bills for a patient
    6666    @Query("""
    6767        SELECT b FROM Billing b
     
    7272    List<Billing> findUnpaidBillsForPatient(@Param("patientId") Long patientId);
    7373
    74     // Helper: Get all bills for a patient sorted by date
     74    //Get all bills for a patient sorted by date
    7575    @Query("""
    7676        SELECT b FROM Billing b
  • backend/src/main/java/medora/service/AuthService.java

    rccb5a6b red083e6  
    5454        }
    5555
    56         // Generate JWT token with patientId for patients
    5756        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);
    5959
    60         // Return response
    6160        Map<String, Object> response = new HashMap<>();
    6261        response.put("token", token);
    6362        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);
    6565        response.put("username", user.getUsername());
    6666        response.put("role", user.getRole());
  • backend/src/main/java/medora/service/BillingService.java

    rccb5a6b red083e6  
    429429        BillingDetailDTO detail = new BillingDetailDTO();
    430430        detail.setBillId(billing.getBillId());
     431        detail.setPatientId(billing.getMedicalRecord().getPatient().getPatientId());
    431432        detail.setPatientName(billing.getMedicalRecord().getPatient().getFirstName() + " " +
    432433                billing.getMedicalRecord().getPatient().getLastName());
Note: See TracChangeset for help on using the changeset viewer.