medical card create base
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
"""add medical card unique constaint
|
||||||
|
|
||||||
|
Revision ID: 9bac2789f1a8
|
||||||
|
Revises: 7f86841687c3
|
||||||
|
Create Date: 2023-07-22 02:00:26.177149
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '9bac2789f1a8'
|
||||||
|
down_revision = '7f86841687c3'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_unique_constraint('person_id', 'medical_cards', ['person_id'])
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint('person_id', 'medical_cards', type_='unique')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -6,7 +6,8 @@ import sqlalchemy as sa
|
|||||||
from sqlalchemy.dialects.postgresql import UUID, ARRAY, JSONB
|
from sqlalchemy.dialects.postgresql import UUID, ARRAY, JSONB
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import relationship, DeclarativeBase
|
from sqlalchemy.orm import relationship, DeclarativeBase
|
||||||
from sqlalchemy.sql.schema import ForeignKey
|
from sqlalchemy.sql.schema import ForeignKey, UniqueConstraint
|
||||||
|
|
||||||
|
|
||||||
class Base(DeclarativeBase):
|
class Base(DeclarativeBase):
|
||||||
pass
|
pass
|
||||||
@@ -26,12 +27,14 @@ class MedicalCard(BaseModel):
|
|||||||
health_maps = relationship('HealthMap', back_populates='medical_card')
|
health_maps = relationship('HealthMap', back_populates='medical_card')
|
||||||
confidant_persons = sa.Column(ARRAY(UUID(as_uuid=True)))
|
confidant_persons = sa.Column(ARRAY(UUID(as_uuid=True)))
|
||||||
person_id = sa.Column(UUID(as_uuid=True), nullable=False)
|
person_id = sa.Column(UUID(as_uuid=True), nullable=False)
|
||||||
|
|
||||||
|
__table_args__ = (UniqueConstraint("person_id", name="person_id"),)
|
||||||
|
|
||||||
|
|
||||||
class Checkup(BaseModel):
|
class Checkup(BaseModel):
|
||||||
__tablename__ = 'checkups'
|
__tablename__ = 'checkups'
|
||||||
|
|
||||||
medical_card_id = sa.Column(UUID(as_uuid=True), sa.ForeignKey("medical_cards.id"), nullable=False)
|
medical_card_id = sa.Column(UUID(as_uuid=True), ForeignKey("medical_cards.id"), nullable=False)
|
||||||
medical_card = relationship('MedicalCard', back_populates='checkups')
|
medical_card = relationship('MedicalCard', back_populates='checkups')
|
||||||
medic_id = sa.Column(UUID(as_uuid=True))
|
medic_id = sa.Column(UUID(as_uuid=True))
|
||||||
claims = sa.Column(ARRAY(sa.String)) # жалобы
|
claims = sa.Column(ARRAY(sa.String)) # жалобы
|
||||||
@@ -49,5 +52,5 @@ class HealthMap(BaseModel):
|
|||||||
|
|
||||||
comment = sa.Column(sa.Text)
|
comment = sa.Column(sa.Text)
|
||||||
attachments = sa.Column(ARRAY(sa.String))
|
attachments = sa.Column(ARRAY(sa.String))
|
||||||
medical_card_id = sa.Column(UUID(as_uuid=True), sa.ForeignKey("medical_cards.id"), nullable=False)
|
medical_card_id = sa.Column(UUID(as_uuid=True), ForeignKey("medical_cards.id"), nullable=False)
|
||||||
medical_card = relationship('MedicalCard', back_populates='health_maps')
|
medical_card = relationship('MedicalCard', back_populates='health_maps')
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from pydantic.types import UUID4
|
||||||
|
|
||||||
class MedicalCard(BaseModel):
|
class MedicalCard(BaseModel):
|
||||||
number: str
|
number: str
|
||||||
person_id: str
|
person_id: UUID4
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|
||||||
class MedicalCardCreate(BaseModel):
|
class MedicalCardCreate(BaseModel):
|
||||||
person_id: str
|
number: str
|
||||||
|
person_id: UUID4
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ from fastapi.routing import APIRouter
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from medical_info.db import models
|
from medical_info.db import models
|
||||||
from medical_info.db.schemas import MedicalCard
|
from medical_info.db.schemas import MedicalCard, MedicalCardCreate
|
||||||
from medical_info.services import MedicalCardService, get_medical_cards_service
|
from medical_info.services import MedicalCardService, get_medical_cards_service
|
||||||
|
|
||||||
router = APIRouter(prefix='/medical_cards')
|
router = APIRouter(prefix='/medical_cards')
|
||||||
@@ -14,3 +14,8 @@ def list_medical_cards(
|
|||||||
) -> List[models.MedicalCard]:
|
) -> List[models.MedicalCard]:
|
||||||
return medical_cards_service.list()
|
return medical_cards_service.list()
|
||||||
|
|
||||||
|
@router.post('/', status_code=201, response_model=MedicalCard)
|
||||||
|
async def create_medical_card(
|
||||||
|
medical_card: MedicalCardCreate, medical_cards_service: MedicalCardService = Depends(get_medical_cards_service)
|
||||||
|
) -> models.MedicalCard:
|
||||||
|
return medical_cards_service.create(medical_card)
|
||||||
Reference in New Issue
Block a user