healthdatalayer 1.0.1__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of healthdatalayer might be problematic. Click here for more details.
- healthdatalayer/config/__init__.py +0 -0
- healthdatalayer/models/bridge_area_floor_branch/__init__.py +0 -0
- healthdatalayer/models/bridge_area_floor_branch/area.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/branch.py +16 -0
- healthdatalayer/models/bridge_area_floor_branch/bridge_area_floor_branch.py +27 -0
- healthdatalayer/models/bridge_area_floor_branch/floor.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/room.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/system.py +8 -0
- healthdatalayer/models/client/__init__.py +0 -0
- healthdatalayer/models/client/address.py +13 -0
- healthdatalayer/models/client/client.py +25 -0
- healthdatalayer/models/client/client_type.py +9 -0
- healthdatalayer/models/client/education.py +9 -0
- healthdatalayer/models/client/emergency_contact.py +17 -0
- healthdatalayer/models/client/gender.py +9 -0
- healthdatalayer/models/client/marriage_status.py +9 -0
- healthdatalayer/models/client/nationality.py +10 -0
- healthdatalayer/models/client/pathological_history.py +29 -0
- healthdatalayer/models/client/pet.py +16 -0
- healthdatalayer/models/client/profession.py +9 -0
- healthdatalayer/models/client/px.py +28 -0
- healthdatalayer/models/collaborator/__init__.py +0 -0
- healthdatalayer/models/collaborator/collaborator.py +33 -0
- healthdatalayer/models/collaborator/collaborator_speciality.py +8 -0
- healthdatalayer/models/collaborator/collaborator_type.py +9 -0
- healthdatalayer/models/collaborator/speciality.py +23 -0
- healthdatalayer/models/lab/__init__.py +0 -0
- healthdatalayer/models/lab/client_lab.py +13 -0
- healthdatalayer/models/lab/measure_lab.py +11 -0
- healthdatalayer/models/lab/medical_lab.py +17 -0
- healthdatalayer/models/medical_visit/__init__.py +0 -0
- healthdatalayer/models/medical_visit/medical_diagnosis.py +12 -0
- healthdatalayer/models/medical_visit/medical_diagnosis_visit.py +25 -0
- healthdatalayer/models/medical_visit/medical_drug.py +27 -0
- healthdatalayer/models/medical_visit/medical_drug_recipe.py +18 -0
- healthdatalayer/models/medical_visit/medical_recipe_visit.py +28 -0
- healthdatalayer/models/medical_visit/medical_visit.py +51 -0
- healthdatalayer/models/medical_visit/organ_system_review.py +28 -0
- healthdatalayer/models/medical_visit/physical_exam.py +45 -0
- healthdatalayer/models/medical_visit/visit_triage.py +28 -0
- healthdatalayer/models/user/__init__.py +0 -0
- healthdatalayer/models/user/permission.py +27 -0
- healthdatalayer/models/user/permission_user.py +8 -0
- healthdatalayer/models/user/role.py +27 -0
- healthdatalayer/models/user/role_permission.py +8 -0
- healthdatalayer/models/user/role_user.py +8 -0
- healthdatalayer/models/user/user.py +30 -0
- healthdatalayer/repositories/client_repositories/__init__.py +0 -0
- healthdatalayer/repositories/client_repositories/address_repository.py +64 -0
- healthdatalayer/repositories/client_repositories/client_type_repository.py +69 -0
- healthdatalayer/repositories/client_repositories/education_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/gender_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/marriage_status_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/pet_repository.py +126 -0
- healthdatalayer/repositories/client_repositories/profession_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/px_repository.py +210 -0
- healthdatalayer/repositories/collaborator_repositories/__init__.py +0 -0
- healthdatalayer/repositories/collaborator_repositories/collaborator_repository.py +150 -0
- healthdatalayer/repositories/collaborator_repositories/collaborator_type_repository.py +69 -0
- healthdatalayer/repositories/collaborator_repositories/speciality_repository.py +75 -0
- healthdatalayer/repositories/infraestructure_repositories/__init__.py +0 -0
- healthdatalayer/repositories/infraestructure_repositories/area_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/branch_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/bridge_repository.py +80 -0
- healthdatalayer/repositories/infraestructure_repositories/floor_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/room_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/system_repository.py +69 -0
- healthdatalayer/repositories/lab_repositories/__init__.py +0 -0
- healthdatalayer/repositories/lab_repositories/measure_lab_repository.py +80 -0
- healthdatalayer/repositories/lab_repositories/medical_lab_repository.py +254 -0
- healthdatalayer/repositories/medical_visit_repositories/__init__.py +0 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_repository.py +63 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +92 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_recipe_repository.py +70 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_repository.py +63 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_recipe_visit_repository.py +93 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_visit_repository.py +110 -0
- healthdatalayer/repositories/medical_visit_repositories/organ_system_review_repository.py +89 -0
- healthdatalayer/repositories/medical_visit_repositories/physical_exam_repository.py +89 -0
- healthdatalayer/repositories/medical_visit_repositories/visit_triage_repository.py +89 -0
- healthdatalayer/repositories/user_repositories/__init__.py +0 -0
- healthdatalayer/repositories/user_repositories/permission_repository.py +238 -0
- healthdatalayer/repositories/user_repositories/role_repository.py +174 -0
- healthdatalayer/repositories/user_repositories/user_repository.py +251 -0
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.2.0.dist-info}/METADATA +2 -2
- healthdatalayer-1.2.0.dist-info/RECORD +94 -0
- healthdatalayer-1.2.0.dist-info/top_level.txt +1 -0
- healthdatalayer-1.0.1.dist-info/RECORD +0 -10
- healthdatalayer-1.0.1.dist-info/top_level.txt +0 -3
- {config → healthdatalayer}/__init__.py +0 -0
- {config → healthdatalayer/config}/config.py +0 -0
- {config → healthdatalayer/config}/db.py +0 -0
- {config → healthdatalayer/config}/vault.py +0 -0
- {models → healthdatalayer/models}/__init__.py +0 -0
- {repositories → healthdatalayer/repositories}/__init__.py +0 -0
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.2.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from typing import Optional,TYPE_CHECKING
|
|
3
|
+
from sqlmodel import SQLModel, Field, Relationship
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from models import MedicalVisit
|
|
7
|
+
|
|
8
|
+
class PhysicalExam(SQLModel, table=True):
|
|
9
|
+
__tablename__ = "physical_exam"
|
|
10
|
+
|
|
11
|
+
physical_exam_id:uuid.UUID=Field(default_factory=uuid.uuid4,primary_key=True)
|
|
12
|
+
|
|
13
|
+
medical_visit_id: Optional[uuid.UUID] = Field(default=None, foreign_key="medical_visit.medical_visit_id")
|
|
14
|
+
medical_visit: Optional["MedicalVisit"] = Relationship(back_populates="physical_exams")
|
|
15
|
+
|
|
16
|
+
comments: Optional[str] = Field(default=None)
|
|
17
|
+
|
|
18
|
+
r1: Optional[bool] = Field(default=None)
|
|
19
|
+
r2: Optional[bool] = Field(default=None)
|
|
20
|
+
r3: Optional[bool] = Field(default=None)
|
|
21
|
+
r4: Optional[bool] = Field(default=None)
|
|
22
|
+
r5: Optional[bool] = Field(default=None)
|
|
23
|
+
r6: Optional[bool] = Field(default=None)
|
|
24
|
+
r7: Optional[bool] = Field(default=None)
|
|
25
|
+
r8: Optional[bool] = Field(default=None)
|
|
26
|
+
r9: Optional[bool] = Field(default=None)
|
|
27
|
+
r10: Optional[bool] = Field(default=None)
|
|
28
|
+
r11: Optional[bool] = Field(default=None)
|
|
29
|
+
r12: Optional[bool] = Field(default=None)
|
|
30
|
+
r13: Optional[bool] = Field(default=None)
|
|
31
|
+
r14: Optional[bool] = Field(default=None)
|
|
32
|
+
r15: Optional[bool] = Field(default=None)
|
|
33
|
+
|
|
34
|
+
s1: Optional[bool] = Field(default=None)
|
|
35
|
+
s2: Optional[bool] = Field(default=None)
|
|
36
|
+
s3: Optional[bool] = Field(default=None)
|
|
37
|
+
s4: Optional[bool] = Field(default=None)
|
|
38
|
+
s5: Optional[bool] = Field(default=None)
|
|
39
|
+
s6: Optional[bool] = Field(default=None)
|
|
40
|
+
s7: Optional[bool] = Field(default=None)
|
|
41
|
+
s8: Optional[bool] = Field(default=None)
|
|
42
|
+
s9: Optional[bool] = Field(default=None)
|
|
43
|
+
s10: Optional[bool] = Field(default=None)
|
|
44
|
+
|
|
45
|
+
is_active: bool = Field(default=True)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from typing import Optional,TYPE_CHECKING
|
|
3
|
+
from sqlmodel import SQLModel, Field, Relationship
|
|
4
|
+
from decimal import Decimal
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from models.medical_visit.medical_visit import MedicalVisit
|
|
8
|
+
|
|
9
|
+
class VisitTriage(SQLModel, table=True):
|
|
10
|
+
__tablename__ = "visit_triage"
|
|
11
|
+
|
|
12
|
+
visit_triage_id:uuid.UUID=Field(default_factory=uuid.uuid4,primary_key=True)
|
|
13
|
+
|
|
14
|
+
weight:Optional[Decimal]=Field(default=None)
|
|
15
|
+
height:Optional[Decimal]=Field(default=None)
|
|
16
|
+
heart_rate:Optional[int]=Field(default=None)
|
|
17
|
+
blood_pressure:Optional[str]=Field(default=None)
|
|
18
|
+
temperature:Optional[Decimal]=Field(default=None)
|
|
19
|
+
|
|
20
|
+
imc:Optional[Decimal]=Field(default=None)
|
|
21
|
+
abdominal_perimeter:Optional[Decimal]=Field(default=None)
|
|
22
|
+
capillary_hemoglobin:Optional[Decimal]=Field(default=None)
|
|
23
|
+
pulse_oximetry:Optional[Decimal]=Field(default=None)
|
|
24
|
+
|
|
25
|
+
medical_visit_id:Optional[uuid.UUID]=Field(default=None,foreign_key="medical_visit.medical_visit_id")
|
|
26
|
+
medical_visit: Optional["MedicalVisit"] = Relationship()
|
|
27
|
+
|
|
28
|
+
is_active: bool = Field(default=True)
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel, Field, Relationship
|
|
3
|
+
from typing import List, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from models.user.role_permission import RolePermission
|
|
6
|
+
from models.user.permission_user import PermissionUser
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from models.user.user import User
|
|
10
|
+
from models.user.role import Role
|
|
11
|
+
|
|
12
|
+
class Permission(SQLModel, table=True):
|
|
13
|
+
__tablename__ = "permission"
|
|
14
|
+
|
|
15
|
+
permission_id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
|
16
|
+
name: str
|
|
17
|
+
is_active: bool
|
|
18
|
+
|
|
19
|
+
roles: List["Role"] = Relationship(
|
|
20
|
+
back_populates="permissions",
|
|
21
|
+
link_model=RolePermission
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
users: List["User"] = Relationship(
|
|
25
|
+
back_populates="permissions",
|
|
26
|
+
link_model=PermissionUser
|
|
27
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel,Field
|
|
3
|
+
|
|
4
|
+
class PermissionUser(SQLModel,table=True):
|
|
5
|
+
__tablename__ = "permission_user"
|
|
6
|
+
|
|
7
|
+
permission_id: uuid.UUID = Field(foreign_key="permission.permission_id", primary_key=True)
|
|
8
|
+
user_id: uuid.UUID = Field(foreign_key="user.user_id", primary_key=True)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel, Field, Relationship
|
|
3
|
+
from typing import List, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from models.user.role_user import RoleUser
|
|
6
|
+
from models.user.role_permission import RolePermission
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from models.user.user import User
|
|
10
|
+
from models.user.permission import Permission
|
|
11
|
+
|
|
12
|
+
class Role(SQLModel, table=True):
|
|
13
|
+
__tablename__ = "role"
|
|
14
|
+
|
|
15
|
+
role_id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
|
16
|
+
name: str
|
|
17
|
+
is_active: bool
|
|
18
|
+
|
|
19
|
+
users: List["User"] = Relationship(
|
|
20
|
+
back_populates="roles",
|
|
21
|
+
link_model=RoleUser
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
permissions: List["Permission"] = Relationship(
|
|
25
|
+
back_populates="roles",
|
|
26
|
+
link_model=RolePermission
|
|
27
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel,Field
|
|
3
|
+
|
|
4
|
+
class RolePermission(SQLModel,table=True):
|
|
5
|
+
__tablename__ = "role_permission"
|
|
6
|
+
|
|
7
|
+
role_id: uuid.UUID = Field(foreign_key="role.role_id", primary_key=True)
|
|
8
|
+
permission_id: uuid.UUID = Field(foreign_key="permission.permission_id", primary_key=True)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel,Field
|
|
3
|
+
|
|
4
|
+
class RoleUser(SQLModel,table=True):
|
|
5
|
+
__tablename__ = "role_user"
|
|
6
|
+
|
|
7
|
+
role_id: uuid.UUID = Field(foreign_key="role.role_id", primary_key=True)
|
|
8
|
+
user_id: uuid.UUID = Field(foreign_key="user.user_id", primary_key=True)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel,Field, Relationship
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Optional, List, TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
from models.user.role_user import RoleUser
|
|
7
|
+
from models.user.permission_user import PermissionUser
|
|
8
|
+
|
|
9
|
+
from models.user.role import Role
|
|
10
|
+
from models.user.permission import Permission
|
|
11
|
+
|
|
12
|
+
class User(SQLModel,table=True):
|
|
13
|
+
__tablename__ = "user"
|
|
14
|
+
|
|
15
|
+
user_id:uuid.UUID=Field(default_factory=uuid.uuid4,primary_key=True)
|
|
16
|
+
username: str = Field(index=True, nullable=False, unique=True)
|
|
17
|
+
password: str = Field(nullable=False)
|
|
18
|
+
last_access: Optional[datetime] = Field(default=None)
|
|
19
|
+
email: Optional[str] = None
|
|
20
|
+
is_active: bool
|
|
21
|
+
|
|
22
|
+
roles: List["Role"] = Relationship(
|
|
23
|
+
back_populates="users",
|
|
24
|
+
link_model=RoleUser
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
permissions: List["Permission"] = Relationship(
|
|
28
|
+
back_populates="users",
|
|
29
|
+
link_model=PermissionUser
|
|
30
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import Address
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class AddressRepository:
|
|
9
|
+
|
|
10
|
+
def __init__(self, tenant: str):
|
|
11
|
+
self.tenant = tenant
|
|
12
|
+
if tenant not in engines:
|
|
13
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
14
|
+
|
|
15
|
+
def create_command(self, address: Address) -> Address:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(address)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(address)
|
|
20
|
+
return address
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, address_id: UUID) -> Optional[Address]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
return session.get(Address, address_id)
|
|
25
|
+
|
|
26
|
+
def list_all_command(self, active_only: bool = True) -> List[Address]:
|
|
27
|
+
with get_session(self.tenant) as session:
|
|
28
|
+
statement = select(Address)
|
|
29
|
+
|
|
30
|
+
if active_only:
|
|
31
|
+
statement = statement.where(Address.is_active == True)
|
|
32
|
+
|
|
33
|
+
results = session.exec(statement)
|
|
34
|
+
return results.all()
|
|
35
|
+
|
|
36
|
+
def update_command(self, address_id: UUID, **kwargs) -> Optional[Address]:
|
|
37
|
+
with get_session(self.tenant) as session:
|
|
38
|
+
db_address = session.get(Address, address_id)
|
|
39
|
+
if not db_address:
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
for key, value in kwargs.items():
|
|
43
|
+
if hasattr(db_address, key):
|
|
44
|
+
setattr(db_address, key, value)
|
|
45
|
+
|
|
46
|
+
session.add(db_address)
|
|
47
|
+
session.commit()
|
|
48
|
+
session.refresh(db_address)
|
|
49
|
+
return db_address
|
|
50
|
+
|
|
51
|
+
def delete_command(self, address_id: UUID, soft_delete: bool = True) -> bool:
|
|
52
|
+
with get_session(self.tenant) as session:
|
|
53
|
+
db_address = session.get(Address, address_id)
|
|
54
|
+
if not db_address:
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
if soft_delete:
|
|
58
|
+
db_address.is_active = False
|
|
59
|
+
session.add(db_address)
|
|
60
|
+
else:
|
|
61
|
+
session.delete(db_address)
|
|
62
|
+
|
|
63
|
+
session.commit()
|
|
64
|
+
return True
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import ClientType
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class ClientTypeRepository:
|
|
9
|
+
def __init__(self, tenant: str):
|
|
10
|
+
self.tenant = tenant
|
|
11
|
+
if tenant not in engines:
|
|
12
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
13
|
+
|
|
14
|
+
def create_command(self, client_type: ClientType) -> ClientType:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(client_type)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(client_type)
|
|
19
|
+
return client_type
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, client_type_id: UUID) -> Optional[ClientType]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(ClientType, client_type_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[ClientType]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(ClientType).where(ClientType.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[ClientType]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(ClientType)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(ClientType.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, client_type_id: UUID, **kwargs) -> Optional[ClientType]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_client_type = session.get(ClientType, client_type_id)
|
|
44
|
+
if not db_client_type:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_client_type, key):
|
|
49
|
+
setattr(db_client_type, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_client_type)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_client_type)
|
|
54
|
+
return db_client_type
|
|
55
|
+
|
|
56
|
+
def delete_command(self, client_type_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_client_type = session.get(ClientType, client_type_id)
|
|
59
|
+
if not db_client_type:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_client_type.is_active = False
|
|
64
|
+
session.add(db_client_type)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_client_type)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
return True
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import Education
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class EducationRepository:
|
|
9
|
+
|
|
10
|
+
def __init__(self, tenant: str):
|
|
11
|
+
self.tenant = tenant
|
|
12
|
+
if tenant not in engines:
|
|
13
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
14
|
+
|
|
15
|
+
def create_command(self, education: Education) -> Education:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(education)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(education)
|
|
20
|
+
return education
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, education_id: UUID) -> Optional[Education]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
return session.get(Education, education_id)
|
|
25
|
+
|
|
26
|
+
def get_by_name_command(self, name: str) -> Optional[Education]:
|
|
27
|
+
with get_session(self.tenant) as session:
|
|
28
|
+
statement = select(Education).where(Education.name == name)
|
|
29
|
+
result = session.exec(statement).first()
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def list_all_command(self, active_only: bool = True) -> List[Education]:
|
|
33
|
+
with get_session(self.tenant) as session:
|
|
34
|
+
statement = select(Education)
|
|
35
|
+
|
|
36
|
+
if active_only:
|
|
37
|
+
statement = statement.where(Education.is_active == True)
|
|
38
|
+
|
|
39
|
+
results = session.exec(statement)
|
|
40
|
+
return results.all()
|
|
41
|
+
|
|
42
|
+
def update_command(self, education_id: UUID, **kwargs) -> Optional[Education]:
|
|
43
|
+
with get_session(self.tenant) as session:
|
|
44
|
+
db_education = session.get(Education, education_id)
|
|
45
|
+
if not db_education:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
for key, value in kwargs.items():
|
|
49
|
+
if hasattr(db_education, key):
|
|
50
|
+
setattr(db_education, key, value)
|
|
51
|
+
|
|
52
|
+
session.add(db_education)
|
|
53
|
+
session.commit()
|
|
54
|
+
session.refresh(db_education)
|
|
55
|
+
return db_education
|
|
56
|
+
|
|
57
|
+
def delete_command(self, education_id: UUID, soft_delete: bool = True) -> bool:
|
|
58
|
+
with get_session(self.tenant) as session:
|
|
59
|
+
db_education = session.get(Education, education_id)
|
|
60
|
+
if not db_education:
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
if soft_delete:
|
|
64
|
+
db_education.is_active = False
|
|
65
|
+
session.add(db_education)
|
|
66
|
+
else:
|
|
67
|
+
session.delete(db_education)
|
|
68
|
+
|
|
69
|
+
session.commit()
|
|
70
|
+
return True
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import Gender
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class GenderRepository:
|
|
9
|
+
|
|
10
|
+
def __init__(self, tenant: str):
|
|
11
|
+
self.tenant = tenant
|
|
12
|
+
if tenant not in engines:
|
|
13
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
14
|
+
|
|
15
|
+
def create_command(self, gender: Gender) -> Gender:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(gender)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(gender)
|
|
20
|
+
return gender
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, gender_id: UUID) -> Optional[Gender]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
return session.get(Gender, gender_id)
|
|
25
|
+
|
|
26
|
+
def get_by_name_command(self, name: str) -> Optional[Gender]:
|
|
27
|
+
with get_session(self.tenant) as session:
|
|
28
|
+
statement = select(Gender).where(Gender.name == name)
|
|
29
|
+
result = session.exec(statement).first()
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def list_all_command(self, active_only: bool = True) -> List[Gender]:
|
|
33
|
+
with get_session(self.tenant) as session:
|
|
34
|
+
statement = select(Gender)
|
|
35
|
+
|
|
36
|
+
if active_only:
|
|
37
|
+
statement = statement.where(Gender.is_active == True)
|
|
38
|
+
|
|
39
|
+
results = session.exec(statement)
|
|
40
|
+
return results.all()
|
|
41
|
+
|
|
42
|
+
def update_command(self, gender_id: UUID, **kwargs) -> Optional[Gender]:
|
|
43
|
+
with get_session(self.tenant) as session:
|
|
44
|
+
db_gender = session.get(Gender, gender_id)
|
|
45
|
+
if not db_gender:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
for key, value in kwargs.items():
|
|
49
|
+
if hasattr(db_gender, key):
|
|
50
|
+
setattr(db_gender, key, value)
|
|
51
|
+
|
|
52
|
+
session.add(db_gender)
|
|
53
|
+
session.commit()
|
|
54
|
+
session.refresh(db_gender)
|
|
55
|
+
return db_gender
|
|
56
|
+
|
|
57
|
+
def delete_command(self, gender_id: UUID, soft_delete: bool = True) -> bool:
|
|
58
|
+
with get_session(self.tenant) as session:
|
|
59
|
+
db_gender = session.get(Gender, gender_id)
|
|
60
|
+
if not db_gender:
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
if soft_delete:
|
|
64
|
+
db_gender.is_active = False
|
|
65
|
+
session.add(db_gender)
|
|
66
|
+
else:
|
|
67
|
+
session.delete(db_gender)
|
|
68
|
+
|
|
69
|
+
session.commit()
|
|
70
|
+
return True
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import MarriageStatus
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MarriageStatusRepository:
|
|
9
|
+
|
|
10
|
+
def __init__(self, tenant: str):
|
|
11
|
+
self.tenant = tenant
|
|
12
|
+
if tenant not in engines:
|
|
13
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
14
|
+
|
|
15
|
+
def create_command(self, marriage_status: MarriageStatus) -> MarriageStatus:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(marriage_status)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(marriage_status)
|
|
20
|
+
return marriage_status
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, marriage_status_id: UUID) -> Optional[MarriageStatus]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
return session.get(MarriageStatus, marriage_status_id)
|
|
25
|
+
|
|
26
|
+
def get_by_name_command(self, name: str) -> Optional[MarriageStatus]:
|
|
27
|
+
with get_session(self.tenant) as session:
|
|
28
|
+
statement = select(MarriageStatus).where(MarriageStatus.name == name)
|
|
29
|
+
result = session.exec(statement).first()
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def list_all_command(self, active_only: bool = True) -> List[MarriageStatus]:
|
|
33
|
+
with get_session(self.tenant) as session:
|
|
34
|
+
statement = select(MarriageStatus)
|
|
35
|
+
|
|
36
|
+
if active_only:
|
|
37
|
+
statement = statement.where(MarriageStatus.is_active == True)
|
|
38
|
+
|
|
39
|
+
results = session.exec(statement)
|
|
40
|
+
return results.all()
|
|
41
|
+
|
|
42
|
+
def update_command(self, marriage_status_id: UUID, **kwargs) -> Optional[MarriageStatus]:
|
|
43
|
+
with get_session(self.tenant) as session:
|
|
44
|
+
db_marriage_status = session.get(MarriageStatus, marriage_status_id)
|
|
45
|
+
if not db_marriage_status:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
for key, value in kwargs.items():
|
|
49
|
+
if hasattr(db_marriage_status, key):
|
|
50
|
+
setattr(db_marriage_status, key, value)
|
|
51
|
+
|
|
52
|
+
session.add(db_marriage_status)
|
|
53
|
+
session.commit()
|
|
54
|
+
session.refresh(db_marriage_status)
|
|
55
|
+
return db_marriage_status
|
|
56
|
+
|
|
57
|
+
def delete_command(self, marriage_status_id: UUID, soft_delete: bool = True) -> bool:
|
|
58
|
+
with get_session(self.tenant) as session:
|
|
59
|
+
db_marriage_status = session.get(MarriageStatus, marriage_status_id)
|
|
60
|
+
if not db_marriage_status:
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
if soft_delete:
|
|
64
|
+
db_marriage_status.is_active = False
|
|
65
|
+
session.add(db_marriage_status)
|
|
66
|
+
else:
|
|
67
|
+
session.delete(db_marriage_status)
|
|
68
|
+
|
|
69
|
+
session.commit()
|
|
70
|
+
return True
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
from sqlalchemy.orm import selectinload
|
|
5
|
+
|
|
6
|
+
from models import Pet
|
|
7
|
+
from config.db import engines, get_session
|
|
8
|
+
|
|
9
|
+
class PetRepository:
|
|
10
|
+
def __init__(self, tenant: str):
|
|
11
|
+
self.tenant = tenant
|
|
12
|
+
if tenant not in engines:
|
|
13
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
14
|
+
|
|
15
|
+
def create_command(self, pet: Pet) -> Pet:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(pet)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(pet)
|
|
20
|
+
return pet
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, pet_id: UUID, load_relations: bool = False) -> Optional[Pet]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
if load_relations:
|
|
25
|
+
statement = (
|
|
26
|
+
select(Pet)
|
|
27
|
+
.where(Pet.client_id == pet_id)
|
|
28
|
+
.options(
|
|
29
|
+
selectinload(Pet.gender),
|
|
30
|
+
selectinload(Pet.address),
|
|
31
|
+
selectinload(Pet.marriage_status),
|
|
32
|
+
selectinload(Pet.profession),
|
|
33
|
+
selectinload(Pet.education),
|
|
34
|
+
selectinload(Pet.user),
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
result = session.exec(statement).first()
|
|
38
|
+
return result
|
|
39
|
+
else:
|
|
40
|
+
return session.get(Pet, pet_id)
|
|
41
|
+
|
|
42
|
+
def get_by_identification_command(self, identification: str, load_relations: bool = False) -> Optional[Pet]:
|
|
43
|
+
with get_session(self.tenant) as session:
|
|
44
|
+
statement = select(Pet).where(Pet.identification == identification)
|
|
45
|
+
|
|
46
|
+
if load_relations:
|
|
47
|
+
statement = statement.options(
|
|
48
|
+
selectinload(Pet.gender),
|
|
49
|
+
selectinload(Pet.address),
|
|
50
|
+
selectinload(Pet.marriage_status),
|
|
51
|
+
selectinload(Pet.profession),
|
|
52
|
+
selectinload(Pet.education),
|
|
53
|
+
selectinload(Pet.user),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
result = session.exec(statement).first()
|
|
57
|
+
return result
|
|
58
|
+
|
|
59
|
+
def search_by_name_command(self, name: str, load_relations: bool = False) -> List[Pet]:
|
|
60
|
+
with get_session(self.tenant) as session:
|
|
61
|
+
statement = select(Pet).where(
|
|
62
|
+
(Pet.first_name.ilike(f"%{name}%")) |
|
|
63
|
+
(Pet.last_name.ilike(f"%{name}%"))
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if load_relations:
|
|
67
|
+
statement = statement.options(
|
|
68
|
+
selectinload(Pet.gender),
|
|
69
|
+
selectinload(Pet.address),
|
|
70
|
+
selectinload(Pet.marriage_status),
|
|
71
|
+
selectinload(Pet.profession),
|
|
72
|
+
selectinload(Pet.education),
|
|
73
|
+
selectinload(Pet.user),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
results = session.exec(statement)
|
|
77
|
+
return results.all()
|
|
78
|
+
|
|
79
|
+
def list_all_command(self, active_only: bool = True, load_relations: bool = False) -> List[Pet]:
|
|
80
|
+
with get_session(self.tenant) as session:
|
|
81
|
+
statement = select(Pet)
|
|
82
|
+
|
|
83
|
+
if active_only:
|
|
84
|
+
statement = statement.where(Pet.is_active == True)
|
|
85
|
+
|
|
86
|
+
if load_relations:
|
|
87
|
+
statement = statement.options(
|
|
88
|
+
selectinload(Pet.gender),
|
|
89
|
+
selectinload(Pet.address),
|
|
90
|
+
selectinload(Pet.marriage_status),
|
|
91
|
+
selectinload(Pet.profession),
|
|
92
|
+
selectinload(Pet.education),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
results = session.exec(statement)
|
|
96
|
+
return results.all()
|
|
97
|
+
|
|
98
|
+
def update_command(self, pet: Pet) -> Pet:
|
|
99
|
+
with get_session(self.tenant) as session:
|
|
100
|
+
db_pet = session.merge(pet)
|
|
101
|
+
session.commit()
|
|
102
|
+
session.refresh(db_pet)
|
|
103
|
+
return db_pet
|
|
104
|
+
|
|
105
|
+
def delete_command(self, pet_id: UUID, soft_delete: bool = True) -> bool:
|
|
106
|
+
with get_session(self.tenant) as session:
|
|
107
|
+
db_pet = session.get(Pet, pet_id)
|
|
108
|
+
if not db_pet:
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
if soft_delete:
|
|
112
|
+
db_pet.is_active = False
|
|
113
|
+
session.add(db_pet)
|
|
114
|
+
else:
|
|
115
|
+
session.delete(db_pet)
|
|
116
|
+
|
|
117
|
+
session.commit()
|
|
118
|
+
return True
|
|
119
|
+
|
|
120
|
+
def count_command(self, active_only: bool = True) -> int:
|
|
121
|
+
with get_session(self.tenant) as session:
|
|
122
|
+
statement = select(Pet)
|
|
123
|
+
if active_only:
|
|
124
|
+
statement = statement.where(Pet.is_active == True)
|
|
125
|
+
results = session.exec(statement)
|
|
126
|
+
return len(results.all())
|