From 8159d34c65a9094e8513bb945aa2f1b728b3c078 Mon Sep 17 00:00:00 2001 From: deepvasoya Date: Thu, 22 May 2025 16:35:08 +0530 Subject: [PATCH] feat: freeze clinic api --- apis/endpoints/admin.py | 5 ++-- schemas/UpdateSchemas.py | 1 + services/authService.py | 3 ++- services/clinicServices.py | 50 ++++++++++++++++++------------------- services/emailService.py | 51 ++++++++++++++++++-------------------- 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/apis/endpoints/admin.py b/apis/endpoints/admin.py index 87419ec..82091da 100644 --- a/apis/endpoints/admin.py +++ b/apis/endpoints/admin.py @@ -14,9 +14,8 @@ router = APIRouter() @router.put("/clinic/status") def update_clinic_status(req:Request, data: ClinicStatusUpdate): - response = ClinicServices().update_clinic_status(req.state.user, data.clinic_id, data.status, data.documentStatus, data.rejection_reason) - return ApiResponse(data=response, message="Clinic status updated successfully") - + ClinicServices().update_clinic_status(req.state.user, data.clinic_id, data.status, data.documentStatus, data.rejection_reason) + return ApiResponse(data="OK", message="Clinic status updated successfully") @router.post("/user") def create_user(req:Request, user_data: CreateSuperAdmin): diff --git a/schemas/UpdateSchemas.py b/schemas/UpdateSchemas.py index 9979269..105620d 100644 --- a/schemas/UpdateSchemas.py +++ b/schemas/UpdateSchemas.py @@ -1,3 +1,4 @@ +from typing import Literal from .BaseSchemas import * from enums.enums import ClinicStatus, Integration diff --git a/services/authService.py b/services/authService.py index 0430d0a..9ebe4ee 100644 --- a/services/authService.py +++ b/services/authService.py @@ -155,6 +155,7 @@ class AuthService: if user["userType"] != UserType.SUPER_ADMIN: raise UnauthorizedException("User is not authorized to perform this action") + # password = "admin@123" password = generate_secure_password() hashed_password = hash_password(password) @@ -185,7 +186,7 @@ class AuthService: LOGIN_URL = self.url # send email to user - self.email_service.send_new_admin_email(data.email, password, LOGIN_URL) + self.email_service.send_new_admin_email(data.username, data.email, password, LOGIN_URL) return diff --git a/services/clinicServices.py b/services/clinicServices.py index 0dd683e..4afa4a5 100644 --- a/services/clinicServices.py +++ b/services/clinicServices.py @@ -7,7 +7,7 @@ from exceptions import ResourceNotFoundException, ValidationException from enums.enums import ClinicStatus, UserType from exceptions.unauthorized_exception import UnauthorizedException from interface.common_response import CommonResponse -from sqlalchemy import or_,func, case +from sqlalchemy import or_,not_ from sqlalchemy import text from services.s3Service import get_file_key, get_signed_url @@ -28,9 +28,9 @@ class ClinicServices: clinics_query = self.db.query(Clinics) if filter_type == "UNREGISTERED": - clinics_query = clinics_query.filter(Clinics.status != ClinicStatus.ACTIVE) + clinics_query = clinics_query.filter(not_(Clinics.status == ClinicStatus.ACTIVE),not_(Clinics.status == ClinicStatus.INACTIVE)) elif filter_type == "REGISTERED": - clinics_query = clinics_query.filter(Clinics.status == ClinicStatus.ACTIVE) + clinics_query = clinics_query.filter(or_(Clinics.status == ClinicStatus.ACTIVE,Clinics.status == ClinicStatus.INACTIVE)) if search: clinics_query = clinics_query.filter( @@ -48,8 +48,8 @@ class ClinicServices: count_query = text(""" SELECT COUNT(*) as total, - COUNT(CASE WHEN status = 'ACTIVE' THEN 1 END) as active, - COUNT(CASE WHEN status = 'REJECTED' OR status = 'UNDER_REVIEW' OR status = 'PAYMENT_DUE' OR status = 'REQUESTED_DOC' THEN 1 END) as rejected + COUNT(CASE WHEN status = 'ACTIVE' OR status = 'INACTIVE' THEN 1 END) as active, + COUNT(CASE WHEN status != 'ACTIVE' AND status != 'INACTIVE' THEN 1 END) as rejected FROM clinics """) @@ -216,40 +216,40 @@ class ClinicServices: if clinic.status == ClinicStatus.ACTIVE: clinic_file_verification = self.db.query(ClinicFileVerifications).filter(ClinicFileVerifications.clinic_id == clinic_id).first() - clinic_file_verification.logo_is_verified = True - clinic_file_verification.abn_doc_is_verified = True - clinic_file_verification.contract_doc_is_verified = True + clinic_file_verification.logo_is_verified = True + clinic_file_verification.abn_doc_is_verified = True + clinic_file_verification.contract_doc_is_verified = True - self.db.add(clinic_file_verification) - self.db.commit() + self.db.add(clinic_file_verification) + self.db.commit() - # send mail to user - self.email_service.send_apporve_clinic_email(clinic.email, clinic.name) + # send mail to user + self.email_service.send_apporve_clinic_email(clinic.email, clinic.name) if clinic.status == ClinicStatus.REJECTED or clinic.status == ClinicStatus.UNDER_REVIEW: clinic_file_verification = self.db.query(ClinicFileVerifications).filter(ClinicFileVerifications.clinic_id == clinic_id).first() - if documentStatus and "LOGO" in documentStatus: - clinic_file_verification.logo_is_verified = documentStatus.get("LOGO") - clinic_file_verification.rejection_reason = rejection_reason + if documentStatus and "LOGO" in documentStatus: + clinic_file_verification.logo_is_verified = documentStatus.get("LOGO") + clinic_file_verification.rejection_reason = rejection_reason - if documentStatus and "ABN" in documentStatus: - clinic_file_verification.abn_doc_is_verified = documentStatus.get("ABN") - clinic_file_verification.rejection_reason = rejection_reason + if documentStatus and "ABN" in documentStatus: + clinic_file_verification.abn_doc_is_verified = documentStatus.get("ABN") + clinic_file_verification.rejection_reason = rejection_reason - if documentStatus and "CONTRACT" in documentStatus: - clinic_file_verification.contract_doc_is_verified = documentStatus.get("CONTRACT") - clinic_file_verification.rejection_reason = rejection_reason + if documentStatus and "CONTRACT" in documentStatus: + clinic_file_verification.contract_doc_is_verified = documentStatus.get("CONTRACT") + clinic_file_verification.rejection_reason = rejection_reason - self.db.add(clinic_file_verification) - self.db.commit() + self.db.add(clinic_file_verification) + self.db.commit() - # send mail to user - self.email_service.send_reject_clinic_email(clinic.email, clinic.name) + # send mail to user + self.email_service.send_reject_clinic_email(clinic.email, clinic.name) # if rejected or under review then email to clinic creator diff --git a/services/emailService.py b/services/emailService.py index 547fd75..8629263 100644 --- a/services/emailService.py +++ b/services/emailService.py @@ -29,9 +29,9 @@ class EmailService:

Thank you for using our service. To complete your authentication, please use the following one-time password (OTP):

OTP: {{otp}}

This OTP is valid for 15 minutes. Do not share this OTP with anyone for security reasons. If you did not request this OTP, please ignore this email.

-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear User, Thank you for using our service. To complete your authentication, please use the following one-time password (OTP): OTP: {{otp}} This OTP is valid for 15 minutes. Do not share this OTP with anyone for security reasons. If you did not request this OTP, please ignore this email. Thank you, Team 24x7 AIHR" + "TextPart": "Dear User, Thank you for using our service. To complete your authentication, please use the following one-time password (OTP): OTP: {{otp}} This OTP is valid for 15 minutes. Do not share this OTP with anyone for security reasons. If you did not request this OTP, please ignore this email. Thank you, Team 24x7 AI Health Receptionist" } new_clinic_template = { @@ -40,9 +40,9 @@ class EmailService: "HtmlPart": """

Dear Admin,

A new clinic has been added to the system.

-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear Admin, A new clinic has been added to the system. Thank you, Team 24x7 AIHR" + "TextPart": "Dear Admin, A new clinic has been added to the system. Thank you, Team 24x7 AI Health Receptionist" } reject_clinic_template = { @@ -51,9 +51,9 @@ class EmailService: "HtmlPart": """

Dear User,

Your clinic {{name}} has been rejected.

-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear User, Your clinic {{name}} has been rejected. Thank you, Team 24x7 AIHR" + "TextPart": "Dear User, Your clinic {{name}} has been rejected. Thank you, Team 24x7 AI Health Receptionist" } apporve_clinic_template = { @@ -62,16 +62,18 @@ class EmailService: "HtmlPart": """

Dear User,

Congratulations! Your clinic {{name}} has been approved.

-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear User, Congratulations! Your clinic {{name}} has been approved. Thank you, Team 24x7 AIHR" + "TextPart": "Dear User, Congratulations! Your clinic {{name}} has been approved. Thank you, Team 24x7 AI Health Receptionist" } new_admin_template = { "TemplateName": "newAdmin", "SubjectPart": "Login Credentials", "HtmlPart": """ -

Dear User,

+

Dear {{username}},

+

You have been granted admin access to manage the 24x7 AI Health Receptionist System Admin Panel.

+

Your login credentials are:

Email: {{email}}

@@ -81,9 +83,9 @@ class EmailService:

Use the following link to login:

Login URL: {{login_url}}


-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear User, Your login credentials are: Email: {{email}} Password: {{password}} Login URL: {{login_url}} Thank you, Team 24x7 AIHR" + "TextPart": "Dear User, Your login credentials are: Email: {{email}} Password: {{password}} Login URL: {{login_url}} Thank you, Team 24x7 AI Health Receptionist System" } reset_password_template = { @@ -94,9 +96,9 @@ class EmailService:

You have requested to reset your password. Please use the following link to reset your password:

Reset Password URL: {{reset_password_url}}


-

Thank you,
Team 24x7 AIHR

+

Thank you,
Team 24x7 AI Health Receptionist

""", - "TextPart": "Dear User, You have requested to reset your password. Please use the following link to reset your password: Reset Password URL: {{reset_password_url}} Thank you, Team 24x7 AIHR" + "TextPart": "Dear User, You have requested to reset your password. Please use the following link to reset your password: Reset Password URL: {{reset_password_url}} Thank you, Team 24x7 AI Health Receptionist" } # self.client.create_template(Template=otp_template) @@ -127,20 +129,15 @@ class EmailService: return except Exception as e: logger.error(f"Error sending email to {to_address}: {str(e)}") - raise + # raise TODO: un-comment when ready def send_otp_email(self, email: str, otp: str) -> None: - try: - """Send OTP email""" - self.send_email( - template_name="sendOTP", - to_address=email, - template_data={"otp": otp, "email": email} - ) - return - except Exception as e: - logger.error(f"Error sending OTP email to {email}: {str(e)}") - raise + self.send_email( + template_name="sendOTP", + to_address=email, + template_data={"otp": otp, "email": email} + ) + return def send_new_clinic_email(self, email: str, clinic_name: str): """Send new clinic email""" @@ -169,12 +166,12 @@ class EmailService: ) return - def send_new_admin_email(self, email: str, password:str, login_url:str): + def send_new_admin_email(self, username: str, email: str, password:str, login_url:str): """Send new admin email""" self.send_email( template_name="newAdmin", to_address=email, - template_data={"email": email, "password": password, "login_url": login_url} + template_data={"username": username, "email": email, "password": password, "login_url": login_url} ) return