felicity-lims/felicity/apps/patient/repository.py

66 lines
1.7 KiB
Python
Raw Normal View History

2024-07-21 15:06:51 +08:00
import sqlalchemy as sa
2024-07-22 16:20:56 +08:00
2024-07-21 21:44:22 +08:00
from felicity.apps.patient.entities import (
2024-07-21 15:06:51 +08:00
Patient,
Identification,
PatientIdentification,
)
2024-07-22 16:20:56 +08:00
from felicity.database.paging import PageCursor
2024-07-24 04:30:01 +08:00
from felicity.apps.abstract.repository import BaseRepository
2024-07-21 15:06:51 +08:00
2024-07-22 16:20:56 +08:00
class PatientRepository(BaseRepository[Patient]):
2024-07-21 15:06:51 +08:00
def __init__(self) -> None:
2024-07-22 16:20:56 +08:00
super().__init__(Patient)
2024-07-21 15:06:51 +08:00
async def paginate_with_cursors(
self,
page_size: int | None = None,
after_cursor: str | None = None,
before_cursor: str | None = None,
text: str | None = None,
sort_by: list[str] | None = None,
**kwargs,
) -> PageCursor:
filters = {}
_or_ = dict()
if text:
arg_list = [
"first_name__ilike",
"last_name__ilike",
"middle_name__ilike",
"client_patient_id__ilike",
"patient_id__ilike",
"client___name__ilike",
"patient_id__ilike",
"email__ilike",
"phone_mobile__ilike",
"phone_home__ilike",
]
for _arg in arg_list:
_or_[_arg] = f"%{text}%"
filters = {sa.or_: _or_}
2024-07-22 16:20:56 +08:00
return await super().paginate_with_cursors(
2024-07-21 15:06:51 +08:00
page_size, after_cursor, before_cursor, filters, sort_by
)
class IdentificationRepository(
2024-07-22 16:20:56 +08:00
BaseRepository[Identification]
2024-07-21 15:06:51 +08:00
):
def __init__(self) -> None:
self.model = Identification
super().__init__()
class PatientIdentificationRepository(
2024-07-22 16:20:56 +08:00
BaseRepository[PatientIdentification]
2024-07-21 15:06:51 +08:00
):
def __init__(self) -> None:
self.model = PatientIdentification
super().__init__()