--
This commit is contained in:
+34
-3
@@ -7,7 +7,7 @@ from app.auth.dependencies import client_ip, get_current_user, require_role
|
||||
from app.common.enums import Role
|
||||
from app.database.session import get_db
|
||||
from app.doctors.models import Doctor
|
||||
from app.doctors.schemas import AssignToMR, DoctorCreate, DoctorRead, DoctorUpdate
|
||||
from app.doctors.schemas import AssignToMR, DoctorCreate, DoctorRead, DoctorUpdate, RejectMaster
|
||||
from app.doctors.service import DoctorService
|
||||
from app.users.models import User
|
||||
|
||||
@@ -26,10 +26,10 @@ async def list_doctors(
|
||||
async def create_doctor(
|
||||
payload: DoctorCreate,
|
||||
request: Request,
|
||||
current_user: User = Depends(require_role(Role.ADMIN)),
|
||||
current_user: User = Depends(require_role(Role.ADMIN, Role.MR)),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Doctor:
|
||||
"""Only an Administrator can create a doctor (MR, AM and GM cannot)."""
|
||||
"""An Administrator, or an MR within their own headquarters (AM and GM cannot)."""
|
||||
return await DoctorService(db).create(payload, current_user, client_ip(request))
|
||||
|
||||
|
||||
@@ -62,3 +62,34 @@ async def assign_doctor(
|
||||
"mr_user_id": assignment.mr_user_id,
|
||||
"effective_from": assignment.effective_from,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/requests", response_model=list[DoctorRead])
|
||||
async def list_doctor_requests(
|
||||
current_user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)
|
||||
) -> list[Doctor]:
|
||||
"""Doctors an MR added that wait for the Area Manager: an MR sees their own (with any
|
||||
rejected and why), an Area Manager what waits for them, the administrator and GM all."""
|
||||
return await DoctorService(db).requests_for(current_user)
|
||||
|
||||
|
||||
@router.post("/{doctor_id}/approve", response_model=DoctorRead)
|
||||
async def approve_doctor(
|
||||
doctor_id: uuid.UUID,
|
||||
request: Request,
|
||||
current_user: User = Depends(require_role(Role.AM, Role.ADMIN)),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Doctor:
|
||||
"""The Area Manager of its headquarters adds it to the list, assigned to the MR who asked."""
|
||||
return await DoctorService(db).review(doctor_id, True, None, current_user, client_ip(request))
|
||||
|
||||
|
||||
@router.post("/{doctor_id}/reject", response_model=DoctorRead)
|
||||
async def reject_doctor(
|
||||
doctor_id: uuid.UUID,
|
||||
payload: RejectMaster,
|
||||
request: Request,
|
||||
current_user: User = Depends(require_role(Role.AM, Role.ADMIN)),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Doctor:
|
||||
return await DoctorService(db).review(doctor_id, False, payload.reason, current_user, client_ip(request))
|
||||
|
||||
Reference in New Issue
Block a user