|
1 | 1 | package com.smartclinic.app.services; |
2 | 2 |
|
| 3 | +import com.smartclinic.app.models.Doctor; |
| 4 | +import com.smartclinic.app.repository.DoctorRepository; |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; |
3 | 6 | import org.springframework.stereotype.Service; |
4 | | -import com.smartclinic.app.models.Doctor; // Giả sử đã tạo |
| 7 | + |
| 8 | +import java.time.LocalDate; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Optional; |
5 | 11 |
|
6 | 12 | @Service |
7 | 13 | public class DoctorService { |
8 | 14 |
|
9 | | - // Cần thêm logic nghiệp vụ, ví dụ: |
10 | | - public Doctor getDoctorById(Long id) { |
| 15 | + private final DoctorRepository doctorRepository; |
| 16 | + // Có thể cần thêm AppointmentRepository để kiểm tra lịch trống |
| 17 | + // private final AppointmentRepository appointmentRepository; |
| 18 | + |
| 19 | + @Autowired |
| 20 | + public DoctorService(DoctorRepository doctorRepository) { |
| 21 | + this.doctorRepository = doctorRepository; |
| 22 | + // this.appointmentRepository = appointmentRepository; |
| 23 | + } |
| 24 | + |
| 25 | + // YÊU CẦU 1: Phương thức getDoctorById hoàn chỉnh |
| 26 | + public Optional<Doctor> getDoctorById(Long id) { |
11 | 27 | // Logic truy vấn Doctor từ Repository |
12 | | - return null; |
| 28 | + return doctorRepository.findById(id); |
13 | 29 | } |
14 | 30 |
|
15 | | - public void updateDoctorProfile(Doctor doctor) { |
16 | | - // Logic cập nhật thông tin Doctor |
| 31 | + // YÊU CẦU 2: Phương thức xác thực đăng nhập |
| 32 | + /** |
| 33 | + * Xác thực thông tin đăng nhập của bác sĩ. |
| 34 | + * @param email Email của bác sĩ. |
| 35 | + * @param password Mật khẩu thô (cần mã hóa trong thực tế). |
| 36 | + * @return Optional<Doctor> nếu xác thực thành công. |
| 37 | + */ |
| 38 | + public Optional<Doctor> checkLoginCredentials(String email, String password) { |
| 39 | + // Trong thực tế, sẽ cần sử dụng PasswordEncoder để so sánh mật khẩu. |
| 40 | + // Đây là logic đơn giản hóa cho bài tập: |
| 41 | + return doctorRepository.findByEmail(email) |
| 42 | + .filter(doctor -> doctor.getPassword().equals(password)); |
| 43 | + } |
| 44 | + |
| 45 | + // YÊU CẦU 3: Phương thức truy xuất lịch làm việc |
| 46 | + /** |
| 47 | + * Truy xuất thời gian rảnh (available time slots) của bác sĩ trong ngày. |
| 48 | + * @param doctorId ID của bác sĩ. |
| 49 | + * @param date Ngày cần kiểm tra lịch. |
| 50 | + * @return Danh sách các khung giờ còn trống. |
| 51 | + */ |
| 52 | + public List<String> getAvailability(Long doctorId, LocalDate date) { |
| 53 | + // Logic nghiệp vụ phức tạp sẽ được đặt ở đây: |
| 54 | + // 1. Lấy tất cả cuộc hẹn đã lên lịch của bác sĩ trong ngày (dùng AppointmentRepository). |
| 55 | + // 2. So sánh với khung giờ làm việc cố định của bác sĩ. |
| 56 | + // 3. Trả về các khung giờ trống (Available Slots). |
| 57 | + |
| 58 | + // Trả về dữ liệu giả (mock data) để thể hiện chức năng: |
| 59 | + return List.of("09:00", "11:00", "14:30", "16:00"); |
17 | 60 | } |
18 | 61 | } |
0 commit comments