-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
87 lines (60 loc) · 1.64 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
from pydantic import BaseModel, validator, Field
from typing import List, Optional
from enum import Enum
class BaseStaff(BaseModel):
username: str
password: str
class Staff(BaseStaff):
hospital_id: str
is_admin: bool
access: List[str]
class Token(BaseModel):
sub: str # user_id or staff_id
aud: str # issued to whom (hospital or user)
expire: int
class StaffToken(Token):
hospital_id: Optional[str]
is_admin: bool = False
access: List[str]
class SexEnum(str, Enum):
Male = "M"
Female = "F"
class BaseDoctor(BaseModel):
registration_no: str
name: str
sex: SexEnum
speciality: List[str]
@validator("registration_no")
def check_reg_no(cls, registration_no: str):
if len(registration_no) <= 30:
return registration_no
raise ValueError("Value too large")
class Doctor(BaseDoctor):
doctor_id: str = Field()
hospital_id: str
class AddDoctor(BaseDoctor):
...
class Address(BaseModel):
state: str
district: str
city: str
landmark: str
pin_code: int
@validator("pin_code")
def validate_pin_code(cls, pin_code: str):
if 999999 >= pin_code > 99999:
return pin_code
raise ValueError("Invalid Pin Code")
class BaseHospital(BaseModel):
name: str
registration_no: str
location: Address
@validator("registration_no")
def check_reg_no(cls, registration_no: str):
if len(registration_no) <= 30:
return registration_no
raise ValueError("Value too large")
class Hospital(BaseHospital):
hospital_id: str
class AddHospital(BaseHospital):
...