healthdatalayer 1.0.1__py3-none-any.whl → 1.1.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-1.0.1.dist-info → healthdatalayer-1.1.0.dist-info}/METADATA +2 -2
- healthdatalayer-1.1.0.dist-info/RECORD +93 -0
- models/bridge_area_floor_branch/__init__.py +0 -0
- models/bridge_area_floor_branch/area.py +8 -0
- models/bridge_area_floor_branch/branch.py +16 -0
- models/bridge_area_floor_branch/bridge_area_floor_branch.py +27 -0
- models/bridge_area_floor_branch/floor.py +8 -0
- models/bridge_area_floor_branch/room.py +8 -0
- models/bridge_area_floor_branch/system.py +8 -0
- models/client/__init__.py +0 -0
- models/client/address.py +13 -0
- models/client/client.py +25 -0
- models/client/client_type.py +9 -0
- models/client/education.py +9 -0
- models/client/emergency_contact.py +17 -0
- models/client/gender.py +9 -0
- models/client/marriage_status.py +9 -0
- models/client/nationality.py +10 -0
- models/client/pathological_history.py +29 -0
- models/client/pet.py +16 -0
- models/client/profession.py +9 -0
- models/client/px.py +28 -0
- models/collaborator/__init__.py +0 -0
- models/collaborator/collaborator.py +33 -0
- models/collaborator/collaborator_speciality.py +8 -0
- models/collaborator/collaborator_type.py +9 -0
- models/collaborator/speciality.py +23 -0
- models/lab/__init__.py +0 -0
- models/lab/client_lab.py +13 -0
- models/lab/measure_lab.py +11 -0
- models/lab/medical_lab.py +17 -0
- models/medical_visit/__init__.py +0 -0
- models/medical_visit/medical_diagnosis.py +12 -0
- models/medical_visit/medical_diagnosis_visit.py +25 -0
- models/medical_visit/medical_drug.py +27 -0
- models/medical_visit/medical_drug_recipe.py +18 -0
- models/medical_visit/medical_recipe_visit.py +28 -0
- models/medical_visit/medical_visit.py +51 -0
- models/medical_visit/organ_system_review.py +28 -0
- models/medical_visit/physical_exam.py +45 -0
- models/medical_visit/visit_triage.py +28 -0
- models/user/__init__.py +0 -0
- models/user/permission.py +27 -0
- models/user/permission_user.py +8 -0
- models/user/role.py +27 -0
- models/user/role_permission.py +8 -0
- models/user/role_user.py +8 -0
- models/user/user.py +30 -0
- repositories/client_repositories/__init__.py +0 -0
- repositories/client_repositories/address_repository.py +64 -0
- repositories/client_repositories/client_type_repository.py +69 -0
- repositories/client_repositories/education_repository.py +70 -0
- repositories/client_repositories/gender_repository.py +70 -0
- repositories/client_repositories/marriage_status_repository.py +70 -0
- repositories/client_repositories/pet_repository.py +126 -0
- repositories/client_repositories/profession_repository.py +70 -0
- repositories/client_repositories/px_repository.py +210 -0
- repositories/collaborator_repositories/__init__.py +0 -0
- repositories/collaborator_repositories/collaborator_repository.py +150 -0
- repositories/collaborator_repositories/collaborator_type_repository.py +69 -0
- repositories/collaborator_repositories/speciality_repository.py +75 -0
- repositories/infraestructure_repositories/__init__.py +0 -0
- repositories/infraestructure_repositories/area_repository.py +69 -0
- repositories/infraestructure_repositories/branch_repository.py +69 -0
- repositories/infraestructure_repositories/bridge_repository.py +80 -0
- repositories/infraestructure_repositories/floor_repository.py +69 -0
- repositories/infraestructure_repositories/room_repository.py +69 -0
- repositories/infraestructure_repositories/system_repository.py +69 -0
- repositories/lab_repositories/__init__.py +0 -0
- repositories/lab_repositories/measure_lab_repository.py +80 -0
- repositories/lab_repositories/medical_lab_repository.py +254 -0
- repositories/medical_visit_repositories/__init__.py +0 -0
- repositories/medical_visit_repositories/medical_diagnosis_repository.py +63 -0
- repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +92 -0
- repositories/medical_visit_repositories/medical_drug_recipe_repository.py +70 -0
- repositories/medical_visit_repositories/medical_drug_repository.py +63 -0
- repositories/medical_visit_repositories/medical_recipe_visit_repository.py +93 -0
- repositories/medical_visit_repositories/medical_visit_repository.py +110 -0
- repositories/medical_visit_repositories/organ_system_review_repository.py +89 -0
- repositories/medical_visit_repositories/physical_exam_repository.py +89 -0
- repositories/medical_visit_repositories/visit_triage_repository.py +89 -0
- repositories/user_repositories/__init__.py +0 -0
- repositories/user_repositories/permission_repository.py +238 -0
- repositories/user_repositories/role_repository.py +174 -0
- repositories/user_repositories/user_repository.py +251 -0
- healthdatalayer-1.0.1.dist-info/RECORD +0 -10
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.1.0.dist-info}/WHEEL +0 -0
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import Speciality
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class SpecialityRepository:
|
|
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, speciality : Speciality) -> Speciality:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(speciality)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(speciality)
|
|
19
|
+
return speciality
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, speciality_id: UUID) -> Optional[Speciality]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(Speciality, speciality_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[Speciality]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(Speciality).where(Speciality.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def get_by_subspeciality_command(self, subspeciality: str) -> Optional[List[Speciality]]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(Speciality).where(Speciality.subspeciality == subspeciality)
|
|
34
|
+
result = session.exec(statement).first()
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
def list_all_command(self, active_only: bool = True) -> List[Speciality]:
|
|
38
|
+
with get_session(self.tenant) as session:
|
|
39
|
+
statement = select(Speciality)
|
|
40
|
+
|
|
41
|
+
if active_only:
|
|
42
|
+
statement = statement.where(Speciality.is_active == True)
|
|
43
|
+
|
|
44
|
+
results = session.exec(statement)
|
|
45
|
+
return results.all()
|
|
46
|
+
|
|
47
|
+
def update_command(self, speciality_id: UUID, **kwargs) -> Optional[Speciality]:
|
|
48
|
+
with get_session(self.tenant) as session:
|
|
49
|
+
db_speciality = session.get(Speciality, speciality_id)
|
|
50
|
+
if not db_speciality:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
for key, value in kwargs.items():
|
|
54
|
+
if hasattr(db_speciality, key):
|
|
55
|
+
setattr(db_speciality, key, value)
|
|
56
|
+
|
|
57
|
+
session.add(db_speciality)
|
|
58
|
+
session.commit()
|
|
59
|
+
session.refresh(db_speciality)
|
|
60
|
+
return db_speciality
|
|
61
|
+
|
|
62
|
+
def delete_command(self, speciality_id: UUID, soft_delete: bool = True) -> bool:
|
|
63
|
+
with get_session(self.tenant) as session:
|
|
64
|
+
db_speciality = session.get(Speciality, speciality_id)
|
|
65
|
+
if not db_speciality:
|
|
66
|
+
return False
|
|
67
|
+
|
|
68
|
+
if soft_delete:
|
|
69
|
+
db_speciality.is_active = False
|
|
70
|
+
session.add(db_speciality)
|
|
71
|
+
else:
|
|
72
|
+
session.delete(db_speciality)
|
|
73
|
+
|
|
74
|
+
session.commit()
|
|
75
|
+
return True
|
|
File without changes
|
|
@@ -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 Area
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class AreaRepository:
|
|
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, area: Area) -> Area:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(area)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(area)
|
|
19
|
+
return area
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, area_id: UUID) -> Optional[Area]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(Area, area_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[Area]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(Area).where(Area.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[Area]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(Area)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(Area.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, area_id: UUID, **kwargs) -> Optional[Area]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_area = session.get(Area, area_id)
|
|
44
|
+
if not db_area:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_area, key):
|
|
49
|
+
setattr(db_area, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_area)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_area)
|
|
54
|
+
return db_area
|
|
55
|
+
|
|
56
|
+
def delete_command(self, area_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_area = session.get(Area, area_id)
|
|
59
|
+
if not db_area:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_area.is_active = False
|
|
64
|
+
session.add(db_area)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_area)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
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 Branch
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class BranchRepository:
|
|
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, branch: Branch) -> Branch:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(branch)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(branch)
|
|
19
|
+
return branch
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, branch_id: UUID) -> Optional[Branch]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(Branch, branch_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[Branch]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(Branch).where(Branch.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[Branch]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(Branch)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(Branch.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, branch_id: UUID, **kwargs) -> Optional[Branch]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_branch = session.get(Branch, branch_id)
|
|
44
|
+
if not db_branch:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_branch, key):
|
|
49
|
+
setattr(db_branch, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_branch)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_branch)
|
|
54
|
+
return db_branch
|
|
55
|
+
|
|
56
|
+
def delete_command(self, branch_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_branch = session.get(Branch, branch_id)
|
|
59
|
+
if not db_branch:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_branch.is_active = False
|
|
64
|
+
session.add(db_branch)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_branch)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
return True
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
from sqlalchemy.orm import selectinload,joinedload
|
|
5
|
+
|
|
6
|
+
from models import BridgeAreaFloorBranch
|
|
7
|
+
from models import Branch
|
|
8
|
+
from config.db import engines, get_session
|
|
9
|
+
|
|
10
|
+
class BridgeAreaFloorBranchRepository:
|
|
11
|
+
def __init__(self, tenant: str):
|
|
12
|
+
self.tenant = tenant
|
|
13
|
+
if tenant not in engines:
|
|
14
|
+
raise ValueError(f"Tenant {tenant} is not configured")
|
|
15
|
+
|
|
16
|
+
def create_command(self, bridge: BridgeAreaFloorBranch) -> BridgeAreaFloorBranch:
|
|
17
|
+
with get_session(self.tenant) as session:
|
|
18
|
+
session.add(bridge)
|
|
19
|
+
session.commit()
|
|
20
|
+
session.refresh(bridge)
|
|
21
|
+
return bridge
|
|
22
|
+
|
|
23
|
+
def get_by_id_command(self, bridge_id: UUID, load_related: bool = False) -> Optional[BridgeAreaFloorBranch]:
|
|
24
|
+
with get_session(self.tenant) as session:
|
|
25
|
+
statement = select(BridgeAreaFloorBranch).where(BridgeAreaFloorBranch.bridge_area_floor_branch_id == bridge_id)
|
|
26
|
+
if load_related:
|
|
27
|
+
statement = statement.options(
|
|
28
|
+
selectinload(BridgeAreaFloorBranch.branch).selectinload(Branch.system),
|
|
29
|
+
selectinload(BridgeAreaFloorBranch.area),
|
|
30
|
+
selectinload(BridgeAreaFloorBranch.floor)
|
|
31
|
+
)
|
|
32
|
+
bridge = session.exec(statement).first()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
return bridge
|
|
36
|
+
|
|
37
|
+
def get_all_command(self, active_only: bool = True,load_related: bool = False) -> List[BridgeAreaFloorBranch]:
|
|
38
|
+
with get_session(self.tenant) as session:
|
|
39
|
+
statement = select(BridgeAreaFloorBranch)
|
|
40
|
+
if active_only:
|
|
41
|
+
statement = statement.where(BridgeAreaFloorBranch.is_active == True)
|
|
42
|
+
#results = session.exec(statement).all()
|
|
43
|
+
|
|
44
|
+
if load_related:
|
|
45
|
+
statement = statement.options(
|
|
46
|
+
selectinload(BridgeAreaFloorBranch.branch).selectinload(Branch.system),
|
|
47
|
+
selectinload(BridgeAreaFloorBranch.area),
|
|
48
|
+
selectinload(BridgeAreaFloorBranch.floor)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
results = session.exec(statement).all()
|
|
52
|
+
return results
|
|
53
|
+
|
|
54
|
+
def update_command(self, bridge: BridgeAreaFloorBranch) -> BridgeAreaFloorBranch:
|
|
55
|
+
with get_session(self.tenant) as session:
|
|
56
|
+
existing_bridge = session.get(BridgeAreaFloorBranch, bridge.bridge_area_floor_branch_id)
|
|
57
|
+
if not existing_bridge:
|
|
58
|
+
raise ValueError(f"BridgeAreaFloorBranch with id {bridge.bridge_area_floor_branch_id} does not exist")
|
|
59
|
+
|
|
60
|
+
for key, value in bridge.dict(exclude_unset=True).items():
|
|
61
|
+
setattr(existing_bridge, key, value)
|
|
62
|
+
|
|
63
|
+
bd_bridge = session.merge(existing_bridge)
|
|
64
|
+
session.commit()
|
|
65
|
+
session.refresh(bd_bridge)
|
|
66
|
+
return bd_bridge
|
|
67
|
+
|
|
68
|
+
def delete_command(self, bridge_id: UUID, soft_delete: bool = False) -> None:
|
|
69
|
+
with get_session(self.tenant) as session:
|
|
70
|
+
existing_bridge = session.get(BridgeAreaFloorBranch, bridge_id)
|
|
71
|
+
if not existing_bridge:
|
|
72
|
+
raise ValueError(f"BridgeAreaFloorBranch with id {bridge_id} does not exist")
|
|
73
|
+
|
|
74
|
+
if soft_delete:
|
|
75
|
+
existing_bridge.is_active = False
|
|
76
|
+
session.add(existing_bridge)
|
|
77
|
+
else:
|
|
78
|
+
session.delete(existing_bridge)
|
|
79
|
+
|
|
80
|
+
session.commit()
|
|
@@ -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 Floor
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class FloorRepository:
|
|
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, floor: Floor) -> Floor:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(floor)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(floor)
|
|
19
|
+
return floor
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, floor_id: UUID) -> Optional[Floor]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(Floor, floor_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[Floor]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(Floor).where(Floor.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[Floor]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(Floor)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(Floor.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, floor_id: UUID, **kwargs) -> Optional[Floor]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_floor = session.get(Floor, floor_id)
|
|
44
|
+
if not db_floor:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_floor, key):
|
|
49
|
+
setattr(db_floor, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_floor)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_floor)
|
|
54
|
+
return db_floor
|
|
55
|
+
|
|
56
|
+
def delete_command(self, floor_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_floor = session.get(Floor, floor_id)
|
|
59
|
+
if not db_floor:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_floor.is_active = False
|
|
64
|
+
session.add(db_floor)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_floor)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
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 Room
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class RoomRepository:
|
|
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, room: Room) -> Room:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(room)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(room)
|
|
19
|
+
return room
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, room_id: UUID) -> Optional[Room]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(Room, room_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[Room]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(Room).where(Room.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[Room]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(Room)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(Room.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, room_id: UUID, **kwargs) -> Optional[Room]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_room = session.get(Room, room_id)
|
|
44
|
+
if not db_room:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_room, key):
|
|
49
|
+
setattr(db_room, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_room)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_room)
|
|
54
|
+
return db_room
|
|
55
|
+
|
|
56
|
+
def delete_command(self, room_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_room = session.get(Room, room_id)
|
|
59
|
+
if not db_room:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_room.is_active = False
|
|
64
|
+
session.add(db_room)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_room)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
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 System
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class SystemRepository:
|
|
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, system: System) -> System:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(system)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(system)
|
|
19
|
+
return system
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, system_id: UUID) -> Optional[System]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(System, system_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[System]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(System).where(System.name == name)
|
|
28
|
+
result = session.exec(statement).first()
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
def list_all_command(self, active_only: bool = True) -> List[System]:
|
|
32
|
+
with get_session(self.tenant) as session:
|
|
33
|
+
statement = select(System)
|
|
34
|
+
|
|
35
|
+
if active_only:
|
|
36
|
+
statement = statement.where(System.is_active == True)
|
|
37
|
+
|
|
38
|
+
results = session.exec(statement)
|
|
39
|
+
return results.all()
|
|
40
|
+
|
|
41
|
+
def update_command(self, system_id: UUID, **kwargs) -> Optional[System]:
|
|
42
|
+
with get_session(self.tenant) as session:
|
|
43
|
+
db_system = session.get(System, system_id)
|
|
44
|
+
if not db_system:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for key, value in kwargs.items():
|
|
48
|
+
if hasattr(db_system, key):
|
|
49
|
+
setattr(db_system, key, value)
|
|
50
|
+
|
|
51
|
+
session.add(db_system)
|
|
52
|
+
session.commit()
|
|
53
|
+
session.refresh(db_system)
|
|
54
|
+
return db_system
|
|
55
|
+
|
|
56
|
+
def delete_command(self, system_id: UUID, soft_delete: bool = True) -> bool:
|
|
57
|
+
with get_session(self.tenant) as session:
|
|
58
|
+
db_system = session.get(System, system_id)
|
|
59
|
+
if not db_system:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
if soft_delete:
|
|
63
|
+
db_system.is_active = False
|
|
64
|
+
session.add(db_system)
|
|
65
|
+
else:
|
|
66
|
+
session.delete(db_system)
|
|
67
|
+
|
|
68
|
+
session.commit()
|
|
69
|
+
return True
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import MeasureLab
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MeasureLabRepository:
|
|
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, measure_lab: MeasureLab) -> MeasureLab:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(measure_lab)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(measure_lab)
|
|
19
|
+
return measure_lab
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, measure_lab_id: UUID) -> Optional[MeasureLab]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(MeasureLab, measure_lab_id)
|
|
24
|
+
|
|
25
|
+
def get_by_name_command(self, name: str) -> Optional[MeasureLab]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(MeasureLab).where(MeasureLab.name == name)
|
|
28
|
+
return session.exec(statement).first()
|
|
29
|
+
|
|
30
|
+
def search_by_name_command(self, name: str) -> List[MeasureLab]:
|
|
31
|
+
with get_session(self.tenant) as session:
|
|
32
|
+
statement = select(MeasureLab).where(MeasureLab.name.ilike(f"%{name}%"))
|
|
33
|
+
results = session.exec(statement)
|
|
34
|
+
return results.all()
|
|
35
|
+
|
|
36
|
+
def list_all_command(self, active_only: bool = True) -> List[MeasureLab]:
|
|
37
|
+
with get_session(self.tenant) as session:
|
|
38
|
+
statement = select(MeasureLab)
|
|
39
|
+
|
|
40
|
+
if active_only:
|
|
41
|
+
statement = statement.where(MeasureLab.is_active == True)
|
|
42
|
+
|
|
43
|
+
results = session.exec(statement)
|
|
44
|
+
return results.all()
|
|
45
|
+
|
|
46
|
+
def update_command(self, measure_lab: MeasureLab) -> MeasureLab:
|
|
47
|
+
with get_session(self.tenant) as session:
|
|
48
|
+
db_measure_lab = session.merge(measure_lab)
|
|
49
|
+
session.commit()
|
|
50
|
+
session.refresh(db_measure_lab)
|
|
51
|
+
return db_measure_lab
|
|
52
|
+
|
|
53
|
+
def delete_command(self, measure_lab_id: UUID, soft_delete: bool = True) -> bool:
|
|
54
|
+
with get_session(self.tenant) as session:
|
|
55
|
+
db_measure_lab = session.get(MeasureLab, measure_lab_id)
|
|
56
|
+
if not db_measure_lab:
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
if soft_delete:
|
|
60
|
+
db_measure_lab.is_active = False
|
|
61
|
+
session.add(db_measure_lab)
|
|
62
|
+
else:
|
|
63
|
+
session.delete(db_measure_lab)
|
|
64
|
+
|
|
65
|
+
session.commit()
|
|
66
|
+
return True
|
|
67
|
+
|
|
68
|
+
def count_command(self, active_only: bool = True) -> int:
|
|
69
|
+
with get_session(self.tenant) as session:
|
|
70
|
+
statement = select(MeasureLab)
|
|
71
|
+
if active_only:
|
|
72
|
+
statement = statement.where(MeasureLab.is_active == True)
|
|
73
|
+
results = session.exec(statement)
|
|
74
|
+
return len(results.all())
|
|
75
|
+
|
|
76
|
+
def exists_by_name_command(self, name: str) -> bool:
|
|
77
|
+
with get_session(self.tenant) as session:
|
|
78
|
+
statement = select(MeasureLab).where(MeasureLab.name == name)
|
|
79
|
+
result = session.exec(statement).first()
|
|
80
|
+
return result is not None
|