parent
13023e5913
commit
2fc0c88ed8
|
|
@ -5,14 +5,18 @@ from fastapi.security import HTTPBearer
|
|||
# Import the security scheme
|
||||
bearer_scheme = HTTPBearer(scheme_name="Bearer Authentication")
|
||||
|
||||
from .endpoints import clinics, doctors, calender, appointments, patients, admin, auth, s3, users, clinicDoctor
|
||||
from .endpoints import clinics, doctors, calender, appointments, patients, admin, auth, s3, users, clinicDoctor, dashboard
|
||||
|
||||
api_router = APIRouter()
|
||||
# api_router.include_router(twilio.router, prefix="/twilio")
|
||||
api_router.include_router(clinics.router, prefix="/clinics", tags=["clinics"])
|
||||
|
||||
api_router.include_router(doctors.router, prefix="/doctors", tags=["doctors"])
|
||||
|
||||
api_router.include_router(calender.router, prefix="/calender", tags=["calender"])
|
||||
|
||||
api_router.include_router(appointments.router, prefix="/appointments", tags=["appointments"])
|
||||
|
||||
api_router.include_router(patients.router, prefix="/patients", tags=["patients"])
|
||||
|
||||
api_router.include_router(
|
||||
|
|
@ -20,7 +24,14 @@ api_router.include_router(
|
|||
prefix="/admin",
|
||||
dependencies=[Depends(auth_required)],
|
||||
tags=["admin"])
|
||||
|
||||
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
|
||||
api_router.include_router(s3.router, dependencies=[Depends(auth_required)], prefix="/s3", tags=["s3"])
|
||||
|
||||
api_router.include_router(s3.router, dependencies=[Depends(auth_required)],
|
||||
prefix="/s3", tags=["s3"])
|
||||
|
||||
api_router.include_router(users.router, prefix="/users", tags=["users"], dependencies=[Depends(auth_required)])
|
||||
|
||||
api_router.include_router(clinicDoctor.router, prefix="/clinic-doctors", tags=["clinic-doctors"], dependencies=[Depends(auth_required)])
|
||||
|
||||
api_router.include_router(dashboard.router, prefix="/dashboard", tags=["dashboard"], dependencies=[Depends(auth_required)])
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
from asyncio.log import logger
|
||||
from typing import List
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
# database
|
||||
from database import get_db
|
||||
|
||||
# schemas
|
||||
from schemas.ResponseSchemas import Clinic, ClinicWithDoctors
|
||||
from schemas.CreateSchemas import ClinicCreate
|
||||
from schemas.ResponseSchemas import Clinic
|
||||
from schemas.UpdateSchemas import ClinicUpdate
|
||||
from models.Clinics import Clinics
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
from fastapi import APIRouter, Request
|
||||
from services.dashboardService import DashboardService
|
||||
from schemas.ApiResponse import ApiResponse
|
||||
from enums.enums import UserType
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
async def get_clinic_doctor_status_count(req:Request):
|
||||
counts = DashboardService().get_dashboard_counts(isSuperAdmin=req.state.user["userType"] == UserType.SUPER_ADMIN)
|
||||
return ApiResponse(data=counts, message="Counts fetched successfully")
|
||||
|
|
@ -47,3 +47,24 @@ class ClinicDoctorsServices:
|
|||
clinic_doctor = self.db.query(ClinicDoctors).filter(ClinicDoctors.id == clinic_doctor_id).first()
|
||||
self.db.delete(clinic_doctor)
|
||||
self.db.commit()
|
||||
|
||||
def get_doctor_status_count(self):
|
||||
# Use SQLAlchemy's func.count to get the count for each status
|
||||
from sqlalchemy import func
|
||||
from enums.enums import ClinicDoctorStatus
|
||||
|
||||
# Query to count doctors by status
|
||||
status_counts = self.db.query(
|
||||
ClinicDoctors.status,
|
||||
func.count(ClinicDoctors.id).label('count')
|
||||
).group_by(ClinicDoctors.status).all()
|
||||
|
||||
# Initialize result dictionary with all possible statuses set to 0
|
||||
result = {status.value: 0 for status in ClinicDoctorStatus}
|
||||
|
||||
# Update with actual counts from the query
|
||||
for status, count in status_counts:
|
||||
result[status.value] = count
|
||||
|
||||
return result
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ from schemas.UpdateSchemas import ClinicUpdate
|
|||
from schemas.ResponseSchemas import Clinic
|
||||
from typing import List
|
||||
from exceptions import ResourceNotFoundException
|
||||
from enums.enums import ClinicStatus
|
||||
|
||||
class ClinicServices:
|
||||
def __init__(self):
|
||||
|
|
@ -48,5 +49,45 @@ class ClinicServices:
|
|||
if clinic is None:
|
||||
raise ResourceNotFoundException("Clinic not found")
|
||||
|
||||
self.db.delete(clinic)
|
||||
self.db.commit()
|
||||
clinic.soft_delete(self.db)
|
||||
|
||||
def get_clinic_count(self):
|
||||
from sqlalchemy import func
|
||||
|
||||
# Get total count
|
||||
totalClinics = self.db.query(Clinics).count()
|
||||
|
||||
# Get counts for specific statuses in a single query
|
||||
status_counts = self.db.query(
|
||||
Clinics.status,
|
||||
func.count(Clinics.id).label('count')
|
||||
).filter(
|
||||
Clinics.status.in_([
|
||||
ClinicStatus.ACTIVE,
|
||||
ClinicStatus.UNDER_REVIEW,
|
||||
ClinicStatus.REJECTED
|
||||
])
|
||||
).group_by(Clinics.status).all()
|
||||
|
||||
# Initialize counts with 0
|
||||
counts = {
|
||||
"totalClinics": totalClinics,
|
||||
"totalActiveClinics": 0,
|
||||
"totalUnderReviewClinics": 0,
|
||||
"totalRejectedClinics": 0
|
||||
}
|
||||
|
||||
# Map status values to their respective count keys
|
||||
status_to_key = {
|
||||
ClinicStatus.ACTIVE: "totalActiveClinics",
|
||||
ClinicStatus.UNDER_REVIEW: "totalUnderReviewClinics",
|
||||
ClinicStatus.REJECTED: "totalRejectedClinics"
|
||||
}
|
||||
|
||||
# Update counts with actual values from the query
|
||||
for status, count in status_counts:
|
||||
key = status_to_key.get(status)
|
||||
if key:
|
||||
counts[key] = count
|
||||
|
||||
return counts
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
from database import get_db
|
||||
from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||
from services.clinicServices import ClinicServices
|
||||
|
||||
class DashboardService:
|
||||
def __init__(self):
|
||||
self.db = next(get_db())
|
||||
self.clinicDoctorsServices = ClinicDoctorsServices()
|
||||
self.clinicServices = ClinicServices()
|
||||
|
||||
def get_dashboard_counts(self, isSuperAdmin:bool):
|
||||
if isSuperAdmin:
|
||||
clinicCounts = self.clinicServices.get_clinic_count()
|
||||
return clinicCounts
|
||||
else:
|
||||
clinicDoctorsCount = self.clinicDoctorsServices.get_doctor_status_count()
|
||||
return clinicDoctorsCount
|
||||
Loading…
Reference in New Issue