Skip to content

Implement appointment booking features and validation services#20

Merged
RedAvocado22 merged 10 commits into
mainfrom
feature/appointment
Mar 27, 2026
Merged

Implement appointment booking features and validation services#20
RedAvocado22 merged 10 commits into
mainfrom
feature/appointment

Conversation

@RedAvocado22

Copy link
Copy Markdown
Owner

No description provided.

- Add DoctorScheduleDetailResponse record with schedule fields and static from() factory
- Add findByDoctor_IdAndDateAndStartTimeAndEndTime query to DoctorScheduleRepository
- Add DoctorScheduleQueryService exposing findDoctorSchedule() and getReferenceById()
  for cross-domain access without direct repository coupling
- Add Appointment entity extending BaseEntity with LAZY associations to
  PatientInfo, Account (doctor), and DoctorSchedule
- Add AppointmentRepository with queries for patient, doctor, status filters
  and countAppointmentByDoctorSchedule_Id for Redis slot cold-start sync
…onse

- BookAppointmentRequest: doctorId, date, startTime, endTime, reason, patientId
  with @NotNull/@notblank Jakarta annotations; patientId nullable to support
  PATIENT role flow where it is resolved from JWT in service validate()
- BookAppointmentResponse: record with static from(Appointment, BookAppointmentRequest)
  factory — takes startTime/endTime from request to avoid triggering lazy proxy load
  on DoctorSchedule
- Replace non-atomic get/setIfAbsent/increment chain with a single Lua script
  executed atomically — eliminates race condition window between Redis calls
- Cold-start: if key missing, initialize from DB count then increment;
  skip DB query on hot path when key already exists
- Over-limit: decrement and return 0 inside the script atomically
- Extract script and RedisScript as static final constants to avoid
  re-allocation on every request
…validation

- validate(): checks date not in past, start time not in past for today,
  start time before end time; RECEPTIONIST must provide patientId,
  PATIENT resolves patientId from JWT via PatientQueryService.getPatientIdByAccountId()
- doProcess(): verifies schedule isAvailable before slot booking, delegates
  slot counter to AppointmentSlotService, saves Appointment with PENDING status
- PatientQueryService: add getPatientIdByAccountId(UUID accountId) using
  findByAccount_Id repository query to resolve PatientInfo UUID from Account UUID
- AppointmentController mapped to /appointments
- POST / guarded by @PreAuthorize hasAnyRole(PATIENT, RECEPTIONIST)
- Accepts @Valid @RequestBody BookAppointmentRequest, returns 201 Created
- Query account by username before calling Keycloak; throw BusinessException
  with generic message if not found to avoid username enumeration
- Throw BusinessException with clear message if account isActive is false,
  before attempting Keycloak authentication
- JwtContextExtractor: add private constructor to prevent instantiation
  of utility class with only static methods
- GetMedicalRecordDetailService: fix grammar in access denied message
- EmployeeQueryService: remove trailing blank line
@RedAvocado22 RedAvocado22 merged commit 1f7f1f0 into main Mar 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant