1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- """Module schemas/subjects verifies table data type"""
- from datetime import date
- from datetime import datetime
- from typing import List, Literal
- from typing import Optional
- from typing import Union
- from pydantic import BaseModel
- from pydantic import Field
- from pydantic import validator
- from schemas.trains import ShowTrain
- from settings.config import settings
- language = settings.config["lang"]
- message_dict = settings.get_message()
- message = message_dict[language]
- def get_timestamp() -> datetime:
- return datetime.strptime(datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
- "%Y-%m-%d %H:%M:%S")
- class SubjectBase(BaseModel):
- """Subject Base Pydantic Model"""
- name: str
- id_card: Union[str, None]
- gender: Literal["男", "女"]
- birthday: date
- rehabilitation_parts: list
- remarks: str = ""
- @validator("birthday")
- def validate_birthday_date(cls, value):
- value = datetime.strptime(str(value), "%Y-%m-%d")
- if value > datetime.now() or value < datetime.strptime(
- "1880-01-01", "%Y-%m-%d"):
- raise ValueError(message["form_error_gender"])
- return value
- @validator("rehabilitation_parts")
- def validate_rehabilitation_parts_date(cls, value):
- if len(value) == 0 or len(value) > 4:
- raise ValueError(message["rehab_parts_length"])
- for part in value:
- if part not in ["左手", "右手", "左腿", "右腿"]:
- raise ValueError(message["rehab_parts_value_error"])
- return value
- class SubjectUpdate(SubjectBase):
- pass
- class SubjectCreate(SubjectBase):
- create_time: Optional[datetime] = Field(default_factory=get_timestamp)
- class ShowSubject(BaseModel):
- """展示患者信息"""
- id: str
- name: str
- id_card: str
- age: int
- gender: str
- rehabilitation_parts: str
- create_time: datetime
- class Config():
- orm_mode = True
- class ShowSubjectDetails(ShowSubject):
- """展示患者详情"""
- trains: List[ShowTrain]
- class TodayStats(BaseModel):
- today_num_format: str
- class SubjectIds(BaseModel):
- ids: List[str] = Field(...)
|