TorbatYar/backend/services/healthcare/app/repositories/profiles.py
Mortezakoohjani 625275e55b feat(healthcare): add backend service and finalize frontend build
Add the Healthcare platform backend (phases 13.0–13.7) with Alembic migration revision fix, production deploy script, validation reports, shared UI exports, and loyalty list page client directives so Next.js build succeeds.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 11:38:31 +03:30

54 lines
1.8 KiB
Python

"""Doctor and Patient repositories."""
from __future__ import annotations
from uuid import UUID
from sqlalchemy import select
from app.models.profiles import Doctor, Patient
from app.repositories.base import TenantBaseRepository
class DoctorRepository(TenantBaseRepository[Doctor]):
model = Doctor
async def get_by_code(self, tenant_id: UUID, code: str) -> Doctor | None:
stmt = select(self.model).where(
self.model.tenant_id == tenant_id,
self.model.code == code,
self.model.is_deleted.is_(False),
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_by_user_id(self, tenant_id: UUID, user_id: str) -> Doctor | None:
stmt = select(self.model).where(
self.model.tenant_id == tenant_id,
self.model.user_id == user_id,
self.model.is_deleted.is_(False),
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
class PatientRepository(TenantBaseRepository[Patient]):
model = Patient
async def get_by_code(self, tenant_id: UUID, code: str) -> Patient | None:
stmt = select(self.model).where(
self.model.tenant_id == tenant_id,
self.model.code == code,
self.model.is_deleted.is_(False),
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_by_user_id(self, tenant_id: UUID, user_id: str) -> Patient | None:
stmt = select(self.model).where(
self.model.tenant_id == tenant_id,
self.model.user_id == user_id,
self.model.is_deleted.is_(False),
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()