сделал репозитории для видов приемов и добавил в таблицу приемов поле с датой приема
This commit is contained in:
parent
56fc3d0de2
commit
ca9b519490
21
api/app/application/appointment_types_repository.py
Normal file
21
api/app/application/appointment_types_repository.py
Normal file
@ -0,0 +1,21 @@
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.models import AppointmentType
|
||||
|
||||
|
||||
class AppointmentTypesRepository:
|
||||
def __init__(self, db: AsyncSession):
|
||||
self.db = db
|
||||
|
||||
async def get_all(self) -> Sequence[AppointmentType]:
|
||||
stmt = select(AppointmentType)
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def get_by_id(self, appointment_type_id: int) -> Optional[AppointmentType]:
|
||||
stmt = select(AppointmentType).filter(AppointmentType.id == appointment_type_id)
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().first()
|
||||
30
api/app/application/appointments_repository.py
Normal file
30
api/app/application/appointments_repository.py
Normal file
@ -0,0 +1,30 @@
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from sqlalchemy import select, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from app.domain.models import Appointment
|
||||
|
||||
|
||||
class AppointmentsRepository:
|
||||
def __init__(self, db: AsyncSession):
|
||||
self.db = db
|
||||
|
||||
async def get_all(self) -> Sequence[Appointment]:
|
||||
stmt = (
|
||||
select(Appointment)
|
||||
.options(joinedload(Appointment.type))
|
||||
.options(joinedload(Appointment.patient))
|
||||
.order_by(desc(Appointment.))
|
||||
)
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def get_by_doctor_id(self, doctor_id: int):
|
||||
stmt = (
|
||||
select(Appointment)
|
||||
.options(joinedload(Appointment.type))
|
||||
.options(joinedload(Appointment.patient))
|
||||
.filter()
|
||||
)
|
||||
@ -0,0 +1,30 @@
|
||||
"""добавил таблице с приемами колонку с датой приема
|
||||
|
||||
Revision ID: b189446b0f74
|
||||
Revises: 429c0003ac73
|
||||
Create Date: 2025-03-11 14:32:31.061063
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'b189446b0f74'
|
||||
down_revision: Union[str, None] = '429c0003ac73'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('appointments', sa.Column('date', sa.Date(), server_default=sa.text('now()'), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('appointments', 'date')
|
||||
# ### end Alembic commands ###
|
||||
@ -1,5 +1,6 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.domain.models.base import BaseModel
|
||||
|
||||
@ -9,6 +10,7 @@ class Appointment(BaseModel):
|
||||
|
||||
results = Column(String)
|
||||
days_until_the_next_appointment = Column(Integer)
|
||||
date = Column(Date, nullable=False, server_default=func.now())
|
||||
|
||||
patient_id = Column(Integer, ForeignKey('patients.id'), nullable=False)
|
||||
doctor_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user