feat: call transcripts api
fix: other small fixes
This commit is contained in:
@@ -262,7 +262,7 @@ class AuthService:
|
||||
self.db.add(reset_password)
|
||||
self.db.commit()
|
||||
|
||||
reset_password_url = f"{self.url}/auth/reset-password?token={reset_password_token}"
|
||||
reset_password_url = f"{self.url}auth/reset-password?token={reset_password_token}"
|
||||
|
||||
self.email_service.send_reset_password_email(email, reset_password_url)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import datetime
|
||||
from typing import Optional
|
||||
from fastapi import BackgroundTasks
|
||||
from sqlalchemy.orm import Session
|
||||
import tempfile
|
||||
@@ -6,7 +8,7 @@ import time
|
||||
from fastapi.responses import FileResponse
|
||||
import os
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
from sqlalchemy import desc
|
||||
from schemas.ResponseSchemas import CallTranscriptsResponse
|
||||
from database import get_db
|
||||
from models.CallTranscripts import CallTranscripts
|
||||
@@ -15,23 +17,44 @@ from services.s3Service import get_signed_url
|
||||
from interface.common_response import CommonResponse
|
||||
from loguru import logger
|
||||
|
||||
from schemas.CreateSchemas import CallTranscriptsCreate
|
||||
|
||||
from exceptions.db_exceptions import DBExceptionHandler
|
||||
|
||||
class CallTranscriptServices:
|
||||
def __init__(self):
|
||||
self.db:Session = next(get_db())
|
||||
self.logger = logger
|
||||
|
||||
async def get_call_transcripts(self, limit:int, offset:int):
|
||||
|
||||
async def create_call_transcript(self, data:CallTranscriptsCreate):
|
||||
try:
|
||||
call_transcripts = self.db.query(CallTranscripts).limit(limit).offset(offset).all()
|
||||
call_transcript = CallTranscripts(**data.model_dump())
|
||||
self.db.add(call_transcript)
|
||||
self.db.commit()
|
||||
return
|
||||
except Exception as e:
|
||||
DBExceptionHandler.handle_exception(e, context="creating call transcript")
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
async def get_call_transcripts(self, limit:int, offset:int, search: str = "", orderBy: str = "call_received_time", order: str = "ASC", startDate: Optional[datetime.datetime] = None, endDate: Optional[datetime.datetime] = None):
|
||||
try:
|
||||
query = self.db.query(CallTranscripts).order_by(desc(getattr(CallTranscripts, orderBy)) if order == "DESC" else getattr(CallTranscripts, orderBy))
|
||||
|
||||
if search:
|
||||
query = query.filter(CallTranscripts.patient_number.contains(search))
|
||||
|
||||
if startDate and endDate:
|
||||
query = query.filter(CallTranscripts.call_received_time.between(startDate, endDate))
|
||||
|
||||
call_transcripts = query.limit(limit).offset(offset).all()
|
||||
|
||||
total = self.db.query(CallTranscripts).count()
|
||||
|
||||
response = [CallTranscriptsResponse(**call_transcript.__dict__.copy()) for call_transcript in call_transcripts]
|
||||
|
||||
for call_transcript in response:
|
||||
call_transcript.transcript_key_id = get_signed_url(call_transcript.transcript_key_id)
|
||||
call_transcript.transcript_key_id = await get_signed_url(call_transcript.transcript_key_id)
|
||||
|
||||
return_response = CommonResponse(data=response, total=total)
|
||||
|
||||
@@ -41,7 +64,7 @@ class CallTranscriptServices:
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
def download_call_transcript(self, key_id: str):
|
||||
async def download_call_transcript(self, key_id: str):
|
||||
try:
|
||||
call_transcript = self.db.query(CallTranscripts).filter(CallTranscripts.transcript_key_id == key_id).first()
|
||||
|
||||
@@ -115,7 +138,7 @@ class CallTranscriptServices:
|
||||
download_info = []
|
||||
for key in keys:
|
||||
# Generate signed URL for each key
|
||||
url = get_signed_url(key)
|
||||
url = await get_signed_url(key)
|
||||
|
||||
# Determine filename (using key's basename or a formatted name)
|
||||
filename = os.path.basename(key)
|
||||
@@ -148,14 +171,14 @@ class CallTranscriptServices:
|
||||
zip_file.write(file_path, arcname=arcname)
|
||||
|
||||
# Add cleanup task to run after response is sent
|
||||
background_tasks.add_task(self.cleanup_temp_files, temp_dir, zip_path)
|
||||
# background_tasks.add_task(self.cleanup_temp_files, temp_dir, zip_path)
|
||||
|
||||
# Return the zip file as a response
|
||||
return FileResponse(
|
||||
path=zip_path,
|
||||
media_type="application/zip",
|
||||
filename="call_transcripts.zip",
|
||||
background=background_tasks
|
||||
# background=background_tasks
|
||||
)
|
||||
except Exception as e:
|
||||
DBExceptionHandler.handle_exception(e, context="bulk downloading call transcripts")
|
||||
|
||||
@@ -14,10 +14,16 @@ class MasterAppointmentServices:
|
||||
self.logger = logger
|
||||
|
||||
|
||||
async def get_master_appointment_types(self):
|
||||
async def get_master_appointment_types(self, limit: int, offset: int, search: str):
|
||||
try:
|
||||
appointment_types = self.db.query(MasterAppointmentTypes).all()
|
||||
total= self.db.query(MasterAppointmentTypes).count()
|
||||
query = self.db.query(MasterAppointmentTypes)
|
||||
total= query.count()
|
||||
|
||||
if search:
|
||||
query = query.filter(MasterAppointmentTypes.type.contains(search))
|
||||
total = query.count()
|
||||
|
||||
appointment_types = query.limit(limit).offset(offset).all()
|
||||
response = CommonResponse(data=[MasterAppointmentTypeResponse(**appointment_type.__dict__.copy()) for appointment_type in appointment_types], total=total)
|
||||
return response
|
||||
except Exception as e:
|
||||
|
||||
@@ -110,8 +110,9 @@ async def get_signed_url(key: str) -> str:
|
||||
Params={
|
||||
'Bucket': s3_service.bucket_name,
|
||||
'Key': key,
|
||||
'ResponseContentDisposition': 'attachment'
|
||||
},
|
||||
ExpiresIn=3600 # 1 hour
|
||||
ExpiresIn=3600, # 1 hour
|
||||
)
|
||||
return url
|
||||
except ClientError as e:
|
||||
|
||||
Reference in New Issue
Block a user