-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_model.py
More file actions
52 lines (44 loc) · 1.55 KB
/
Copy pathbase_model.py
File metadata and controls
52 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from datetime import date
from uuid import UUID
from pydantic import computed_field
from sqlalchemy import ARRAY, String
from sqlmodel import Field, SQLModel
class AddressBase(SQLModel):
"""Base model for an address."""
id: UUID | None = None
patient_id: UUID | None = None
address_type: str | None = None
address_line: str | None = None
street: str | None = None
city: str | None = None
state: str | None = None
zip_code: str | None = None
country: str | None = None
class PatientBase(SQLModel):
"""Base model for a patient."""
id: UUID | None = None
patient_id: str | None = None
first_name: str | None = None
last_name: str | None = None
date_of_birth: date | None = None
gender: str | None = None
blood_type: str | None = None
height: str | None = None
weight: str | None = None
primary_address_id: UUID | None = None
primary_physician: str | None = None
insurance_provider: str | None = None
insurance_number: str | None = None
phone: str | None = None
email: str | None = None
conditions: list[str] = Field(sa_type=ARRAY(String), default_factory=list)
allergies: list[str] = Field(sa_type=ARRAY(String), default_factory=list)
@computed_field
def age(self) -> int | None:
"""Calculate age based on date of birth."""
if not self.date_of_birth:
return None
today = date.today()
born = self.date_of_birth
age = today.year - born.year - ((today.month, today.day) < (born.month, born.day))
return age