Changeset ccb5a6b for backend/src/main


Ignore:
Timestamp:
05/23/26 20:35:57 (4 months ago)
Author:
MBK <marija.karapandzova@…>
Branches:
master
Children:
ed083e6
Parents:
946877f
Message:

Assign role permissions for lab technitians

Location:
backend/src/main/java/medora
Files:
5 edited

Legend:

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

    r946877f rccb5a6b  
    278278    }
    279279
     280    @GetMapping("/requests/pending")
     281    public ResponseEntity<?> getPendingLabTests(HttpServletRequest httpRequest) {
     282        try {
     283            String role = securityUtil.getRoleFromRequest(httpRequest);
     284            if (role == null) {
     285                return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
     286                        .body(Map.of("error", "Unauthorized"));
     287            }
     288
     289
     290            if (!role.equals("LAB_TECHNICIAN")) {
     291                return ResponseEntity.status(HttpStatus.FORBIDDEN)
     292                        .body(Map.of("error", "Only lab technicians can view pending tests"));
     293            }
     294
     295            logger.info("Fetching pending lab tests");
     296            List<PerformedLabTests> pendingTests = labService.getPendingLabTests();
     297            List<LabTestRequestDTO> dtos = pendingTests.stream()
     298                    .map(this::convertPerformedTestToDTO)
     299                    .collect(Collectors.toList());
     300            return ResponseEntity.ok(dtos);
     301        } catch (RuntimeException e) {
     302            logger.error("Error fetching pending lab tests: {}", e.getMessage());
     303            return ResponseEntity.badRequest()
     304                    .body(Map.of("error", e.getMessage()));
     305        } catch (Exception e) {
     306            logger.error("Unexpected error fetching pending lab tests: {}", e.getMessage());
     307            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
     308                    .body(Map.of("error", "Failed to fetch pending lab tests: " + e.getMessage()));
     309        }
     310    }
     311
    280312    private LabTestDTO convertToDTO(LabTests labTest) {
    281313        return new LabTestDTO(
     
    295327                performedTest.getDoctor().getDoctorId(),
    296328                performedTest.getDoctor().getFirstName() + " " + performedTest.getDoctor().getLastName(),
     329                performedTest.getCreatedAt() != null ? performedTest.getCreatedAt().toLocalDate() : performedTest.getTestDate(),
    297330                performedTest.getTestDate(),
    298331                performedTest.getNotes()
  • backend/src/main/java/medora/dto/LabTestRequestDTO.java

    r946877f rccb5a6b  
    55import lombok.NoArgsConstructor;
    66import lombok.Setter;
    7 
    87import java.time.LocalDate;
    98
     
    2019    private String doctorName;
    2120    private LocalDate requestDate;
     21    private LocalDate testDate;
    2222    private String notes;
    2323}
  • backend/src/main/java/medora/models/domain/PerformedLabTests.java

    r946877f rccb5a6b  
    66
    77import java.time.LocalDate;
     8import java.time.LocalDateTime;
    89
    910@Getter
     
    3839    private LocalDate testDate;
    3940
     41    @Column(name = "created_at")
     42    private LocalDateTime createdAt;
     43
    4044    private String notes;
    4145
     
    4448
    4549    public PerformedLabTests(Long performedTestId,
    46                             LabTests labTest,
    47                             Patient patient,
    48                             Doctors doctor,
    49                             LabTechnician technician,
    50                             LocalDate testDate,
    51                             String notes) {
     50                             LabTests labTest,
     51                             Patient patient,
     52                             Doctors doctor,
     53                             LabTechnician technician,
     54                             LocalDate testDate,
     55                             String notes) {
    5256        this.performedTestId = performedTestId;
    5357        this.labTest = labTest;
  • backend/src/main/java/medora/repository/PerformedLabTestRepository.java

    r946877f rccb5a6b  
    2222    """)
    2323    List<PerformedLabTests> findByPatientAndDate(@Param("patientId") Long patientId, @Param("testDate") java.time.LocalDate testDate);
     24
    2425}
  • backend/src/main/java/medora/service/LabService.java

    r946877f rccb5a6b  
    1313
    1414/**
    15  * LabService handles lab test and lab result operations.
     15 *
    1616 * UC013 – Record Lab Test Request
    1717 * UC014 – Store Lab Results
     
    5353    }
    5454
    55     // ================= LAB TEST =================
     55
    5656
    5757    @Transactional
     
    107107    }
    108108
    109     // ================= LAB TEST REQUESTS (UC013) =================
     109    // UC013
    110110
    111111    @Transactional
     
    172172    }
    173173
    174     // ================= LAB RESULTS (UC014, UC015) =================
     174    //UC014, UC015
    175175
    176176    @Transactional
     
    220220        return medicalRecordLabResultRepository.findByMedicalRecordRecordId(medicalRecordId);
    221221    }
     222
     223    @Transactional(readOnly = true)
     224    public List<PerformedLabTests> getPendingLabTests() {
     225        // Get all performed tests and filter to only those without results
     226        List<PerformedLabTests> allTests = performedLabTestRepository.findAll();
     227
     228        return allTests.stream()
     229                .filter(test -> {
     230                    // Get the patient's medical record
     231                    Optional<MedicalRecord> recordOpt = medicalRecordRepository.findByPatientPatientId(test.getPatient().getPatientId());
     232                    if (recordOpt.isEmpty()) {
     233                        return true; // No medical record, so no results possible
     234                    }
     235
     236                    MedicalRecord record = recordOpt.get();
     237                    // Check if this test has results in this medical record
     238                    List<MedicalRecordLabResults> results = medicalRecordLabResultRepository
     239                            .findByMedicalRecordRecordId(record.getRecordId());
     240
     241                    // Filter to only results for this specific test
     242                    return results.stream()
     243                            .noneMatch(r -> r.getLabResult().getLabTest().getTestId().equals(test.getLabTest().getTestId()));
     244                })
     245                .toList();
     246    }
    222247}
Note: See TracChangeset for help on using the changeset viewer.