from database import get_db from services.clinicDoctorsServices import ClinicDoctorsServices from services.clinicServices import ClinicServices from schemas.BaseSchemas import SignupPricingMasterBase from schemas.ResponseSchemas import SignupPricingMasterResponse from models.SignupPricingMaster import SignupPricingMaster from exceptions import UnauthorizedException from enums.enums import UserType from exceptions import ResourceNotFoundException class DashboardService: def __init__(self): self.db = next(get_db()) self.clinicDoctorsServices = ClinicDoctorsServices() self.clinicServices = ClinicServices() async def get_dashboard_counts(self, isSuperAdmin: bool): if isSuperAdmin: clinicCounts = await self.clinicServices.get_clinic_count() return clinicCounts else: clinicDoctorsCount = await self.clinicDoctorsServices.get_doctor_status_count() return clinicDoctorsCount async def update_signup_pricing_master( self, user, pricing_data: SignupPricingMasterBase ): if user["userType"] != UserType.SUPER_ADMIN: raise UnauthorizedException( "You are not authorized to update signup pricing master" ) existing_pricing = self.db.query(SignupPricingMaster).first() if existing_pricing is None: # Create new record new_pricing = SignupPricingMaster( **pricing_data.model_dump() ) self.db.add(new_pricing) self.db.commit() self.db.refresh(new_pricing) response = SignupPricingMasterResponse( **new_pricing.__dict__.copy() ) return response else: # Update existing record with values from the request existing_pricing.setup_fees = pricing_data.setup_fees existing_pricing.subscription_fees = pricing_data.subscription_fees existing_pricing.per_call_charges = pricing_data.per_call_charges self.db.commit() self.db.refresh(existing_pricing) response = SignupPricingMasterResponse( **existing_pricing.__dict__.copy() ) return response async def get_signup_pricing_master(self): signup_pricing_master = self.db.query(SignupPricingMaster).first() if signup_pricing_master is None: raise ResourceNotFoundException("Signup pricing master not found") response = SignupPricingMasterResponse( **signup_pricing_master.__dict__.copy() ) return response