-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
101 lines (76 loc) · 2.29 KB
/
models.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
from pydantic import BaseModel, validator, Field, EmailStr
from typing import List, Optional
from enum import Enum
from datetime import date
class Token(BaseModel):
sub: str # ayur_id or staff_id
aud: str # issued to whom (hospital or user)
expire: int
class UserToken(Token):
phone_number: Optional[str]
class User(BaseModel):
...
class SexEnum(str, Enum):
Male = "M"
Female = "F"
class Config:
use_enum_values = True
class BloodGroupEnum(str, Enum):
A1 = 'A+'
A2 = 'A-'
B1 = 'B+'
B2 = 'B-'
O1 = 'O+'
O2 = 'O-'
AB1 = 'AB+'
AB2 = 'AB-'
class Config:
use_enum_values = True
class BaseDetails(BaseModel):
email_id: EmailStr
class BasicDetails(BaseDetails):
name: str
sex: SexEnum
weight: int
height: int
emergency_contact_number: List[str]
allergies: List[str]
major_problems: List[str]
dob: date
birth_mark: str
blood_group: BloodGroupEnum
class UserDetails(BasicDetails):
phone_number: str
ayur_id: str
photo: str
@validator("phone_number")
def validate_phone_number(cls, phone_number):
try:
if phone_number[:3] !="+91" or len(phone_number[3:]):
int(phone_number)
return phone_number
raise ValueError("Invalid Phone Number")
except ValueError:
raise ValueError("Invalid phone number")
class UpdateDetails(BaseModel):
email_id: str | None
phone_number: str | None
weight: int | None # weight in kg
height: int | None # height in cm
emergency_contact_number: List[str] | None
allergies: List[str] | None
@validator("phone_number")
def validate_phone_number(cls, phone_number):
try:
if phone_number[:3] != "+91" or len(phone_number[3:]):
int(phone_number)
return phone_number
raise ValueError("Invalid Phone Number")
except ValueError:
raise ValueError("Invalid phone number")
if __name__ == "__main__":
t ='{"email_id": "cosmicoppai@protonmail.com","phone_number": "+918007611826","weight": 69,"height": 180,"emergency_contact_number": ["+918828087038"],"allergies": ["love"]}'
data = json.loads(t)
print(data)
print(UpdateDetails(**data))