healthdatalayer 1.0.0__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.

Files changed (88) hide show
  1. {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/METADATA +3 -3
  2. healthdatalayer-1.1.0.dist-info/RECORD +93 -0
  3. models/bridge_area_floor_branch/__init__.py +0 -0
  4. models/bridge_area_floor_branch/area.py +8 -0
  5. models/bridge_area_floor_branch/branch.py +16 -0
  6. models/bridge_area_floor_branch/bridge_area_floor_branch.py +27 -0
  7. models/bridge_area_floor_branch/floor.py +8 -0
  8. models/bridge_area_floor_branch/room.py +8 -0
  9. models/bridge_area_floor_branch/system.py +8 -0
  10. models/client/__init__.py +0 -0
  11. models/client/address.py +13 -0
  12. models/client/client.py +25 -0
  13. models/client/client_type.py +9 -0
  14. models/client/education.py +9 -0
  15. models/client/emergency_contact.py +17 -0
  16. models/client/gender.py +9 -0
  17. models/client/marriage_status.py +9 -0
  18. models/client/nationality.py +10 -0
  19. models/client/pathological_history.py +29 -0
  20. models/client/pet.py +16 -0
  21. models/client/profession.py +9 -0
  22. models/client/px.py +28 -0
  23. models/collaborator/__init__.py +0 -0
  24. models/collaborator/collaborator.py +33 -0
  25. models/collaborator/collaborator_speciality.py +8 -0
  26. models/collaborator/collaborator_type.py +9 -0
  27. models/collaborator/speciality.py +23 -0
  28. models/lab/__init__.py +0 -0
  29. models/lab/client_lab.py +13 -0
  30. models/lab/measure_lab.py +11 -0
  31. models/lab/medical_lab.py +17 -0
  32. models/medical_visit/__init__.py +0 -0
  33. models/medical_visit/medical_diagnosis.py +12 -0
  34. models/medical_visit/medical_diagnosis_visit.py +25 -0
  35. models/medical_visit/medical_drug.py +27 -0
  36. models/medical_visit/medical_drug_recipe.py +18 -0
  37. models/medical_visit/medical_recipe_visit.py +28 -0
  38. models/medical_visit/medical_visit.py +51 -0
  39. models/medical_visit/organ_system_review.py +28 -0
  40. models/medical_visit/physical_exam.py +45 -0
  41. models/medical_visit/visit_triage.py +28 -0
  42. models/user/__init__.py +0 -0
  43. models/user/permission.py +27 -0
  44. models/user/permission_user.py +8 -0
  45. models/user/role.py +27 -0
  46. models/user/role_permission.py +8 -0
  47. models/user/role_user.py +8 -0
  48. models/user/user.py +30 -0
  49. repositories/client_repositories/__init__.py +0 -0
  50. repositories/client_repositories/address_repository.py +64 -0
  51. repositories/client_repositories/client_type_repository.py +69 -0
  52. repositories/client_repositories/education_repository.py +70 -0
  53. repositories/client_repositories/gender_repository.py +70 -0
  54. repositories/client_repositories/marriage_status_repository.py +70 -0
  55. repositories/client_repositories/pet_repository.py +126 -0
  56. repositories/client_repositories/profession_repository.py +70 -0
  57. repositories/client_repositories/px_repository.py +210 -0
  58. repositories/collaborator_repositories/__init__.py +0 -0
  59. repositories/collaborator_repositories/collaborator_repository.py +150 -0
  60. repositories/collaborator_repositories/collaborator_type_repository.py +69 -0
  61. repositories/collaborator_repositories/speciality_repository.py +75 -0
  62. repositories/infraestructure_repositories/__init__.py +0 -0
  63. repositories/infraestructure_repositories/area_repository.py +69 -0
  64. repositories/infraestructure_repositories/branch_repository.py +69 -0
  65. repositories/infraestructure_repositories/bridge_repository.py +80 -0
  66. repositories/infraestructure_repositories/floor_repository.py +69 -0
  67. repositories/infraestructure_repositories/room_repository.py +69 -0
  68. repositories/infraestructure_repositories/system_repository.py +69 -0
  69. repositories/lab_repositories/__init__.py +0 -0
  70. repositories/lab_repositories/measure_lab_repository.py +80 -0
  71. repositories/lab_repositories/medical_lab_repository.py +254 -0
  72. repositories/medical_visit_repositories/__init__.py +0 -0
  73. repositories/medical_visit_repositories/medical_diagnosis_repository.py +63 -0
  74. repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +92 -0
  75. repositories/medical_visit_repositories/medical_drug_recipe_repository.py +70 -0
  76. repositories/medical_visit_repositories/medical_drug_repository.py +63 -0
  77. repositories/medical_visit_repositories/medical_recipe_visit_repository.py +93 -0
  78. repositories/medical_visit_repositories/medical_visit_repository.py +110 -0
  79. repositories/medical_visit_repositories/organ_system_review_repository.py +89 -0
  80. repositories/medical_visit_repositories/physical_exam_repository.py +89 -0
  81. repositories/medical_visit_repositories/visit_triage_repository.py +89 -0
  82. repositories/user_repositories/__init__.py +0 -0
  83. repositories/user_repositories/permission_repository.py +238 -0
  84. repositories/user_repositories/role_repository.py +174 -0
  85. repositories/user_repositories/user_repository.py +251 -0
  86. healthdatalayer-1.0.0.dist-info/RECORD +0 -10
  87. {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/WHEEL +0 -0
  88. {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/top_level.txt +0 -0
@@ -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())
@@ -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 Profession
6
+ from config.db import engines, get_session
7
+
8
+ class ProfessionRepository:
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, profession: Profession) -> Profession:
16
+ with get_session(self.tenant) as session:
17
+ session.add(profession)
18
+ session.commit()
19
+ session.refresh(profession)
20
+ return profession
21
+
22
+ def get_by_id_command(self, profession_id: UUID) -> Optional[Profession]:
23
+ with get_session(self.tenant) as session:
24
+ return session.get(Profession, profession_id)
25
+
26
+ def get_by_name_command(self, name: str) -> Optional[Profession]:
27
+ with get_session(self.tenant) as session:
28
+ statement = select(Profession).where(Profession.name == name)
29
+ result = session.exec(statement).first()
30
+ return result
31
+
32
+ def list_all_command(self, active_only: bool = True) -> List[Profession]:
33
+ with get_session(self.tenant) as session:
34
+ statement = select(Profession)
35
+
36
+ if active_only:
37
+ statement = statement.where(Profession.is_active == True)
38
+
39
+ results = session.exec(statement)
40
+ return results.all()
41
+
42
+ def update_command(self, profession_id: UUID, **kwargs) -> Optional[Profession]:
43
+ with get_session(self.tenant) as session:
44
+ db_profession = session.get(Profession, profession_id)
45
+ if not db_profession:
46
+ return None
47
+
48
+ for key, value in kwargs.items():
49
+ if hasattr(db_profession, key):
50
+ setattr(db_profession, key, value)
51
+
52
+ session.add(db_profession)
53
+ session.commit()
54
+ session.refresh(db_profession)
55
+ return db_profession
56
+
57
+ def delete_command(self, profession_id: UUID, soft_delete: bool = True) -> bool:
58
+ with get_session(self.tenant) as session:
59
+ db_profession = session.get(Profession, profession_id)
60
+ if not db_profession:
61
+ return False
62
+
63
+ if soft_delete:
64
+ db_profession.is_active = False
65
+ session.add(db_profession)
66
+ else:
67
+ session.delete(db_profession)
68
+
69
+ session.commit()
70
+ return True
@@ -0,0 +1,210 @@
1
+ from typing import Optional, List
2
+ from uuid import UUID
3
+ from sqlmodel import select
4
+
5
+ from models import Px
6
+ from config.db import engines, get_session
7
+
8
+ class PxRepository:
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, px: Px) -> Px:
15
+ with get_session(self.tenant) as session:
16
+ session.add(px)
17
+ session.commit()
18
+ session.refresh(px)
19
+ return px
20
+
21
+ def get_by_id_command(self, px_id: UUID, load_relations: bool = False) -> Optional[Px]:
22
+ with get_session(self.tenant) as session:
23
+ px = session.get(Px, px_id)
24
+
25
+ if px and load_relations:
26
+ if px.gender_id:
27
+ from models.client.gender import Gender
28
+ gender_obj = session.get(Gender, px.gender_id)
29
+ object.__setattr__(px, 'gender', gender_obj)
30
+
31
+ if px.address_id:
32
+ from models.client.address import Address
33
+ address_obj = session.get(Address, px.address_id)
34
+ object.__setattr__(px, 'address', address_obj)
35
+
36
+ if px.marriage_status_id:
37
+ from models.client.marriage_status import MarriageStatus
38
+ marriage_status_obj = session.get(MarriageStatus, px.marriage_status_id)
39
+ object.__setattr__(px, 'marriage_status', marriage_status_obj)
40
+
41
+ if px.profession_id:
42
+ from models.client.profession import Profession
43
+ profession_obj = session.get(Profession, px.profession_id)
44
+ object.__setattr__(px, 'profession', profession_obj)
45
+
46
+ if px.education_id:
47
+ from models.client.education import Education
48
+ education_obj = session.get(Education, px.education_id)
49
+ object.__setattr__(px, 'education', education_obj)
50
+
51
+ if px.user_id:
52
+ from models.user.user import User
53
+ user_obj = session.get(User, px.user_id)
54
+ object.__setattr__(px, 'user', user_obj)
55
+
56
+ return px
57
+
58
+ def get_by_identification_command(self, identification: str, load_relations: bool = False) -> Optional[Px]:
59
+ with get_session(self.tenant) as session:
60
+ statement = select(Px).where(Px.identification == identification)
61
+ px = session.exec(statement).first()
62
+
63
+ if px and load_relations:
64
+ if px.gender_id:
65
+ from models.client.gender import Gender
66
+ gender_obj = session.get(Gender, px.gender_id)
67
+ object.__setattr__(px, 'gender', gender_obj)
68
+
69
+ if px.address_id:
70
+ from models.client.address import Address
71
+ address_obj = session.get(Address, px.address_id)
72
+ object.__setattr__(px, 'address', address_obj)
73
+
74
+ if px.marriage_status_id:
75
+ from models.client.marriage_status import MarriageStatus
76
+ marriage_status_obj = session.get(MarriageStatus, px.marriage_status_id)
77
+ object.__setattr__(px, 'marriage_status', marriage_status_obj)
78
+
79
+ if px.profession_id:
80
+ from models.client.profession import Profession
81
+ profession_obj = session.get(Profession, px.profession_id)
82
+ object.__setattr__(px, 'profession', profession_obj)
83
+
84
+ if px.education_id:
85
+ from models.client.education import Education
86
+ education_obj = session.get(Education, px.education_id)
87
+ object.__setattr__(px, 'education', education_obj)
88
+
89
+ if px.user_id:
90
+ from models.user.user import User
91
+ user_obj = session.get(User, px.user_id)
92
+ object.__setattr__(px, 'user', user_obj)
93
+
94
+ return px
95
+
96
+ def search_by_name_command(self, name: str, load_relations: bool = False) -> List[Px]:
97
+ with get_session(self.tenant) as session:
98
+ statement = select(Px).where(
99
+ (Px.first_name.ilike(f"%{name}%")) |
100
+ (Px.last_name.ilike(f"%{name}%"))
101
+ )
102
+
103
+ results = session.exec(statement).all()
104
+
105
+ if load_relations:
106
+ for px in results:
107
+ if px.gender_id:
108
+ from models.client.gender import Gender
109
+ gender_obj = session.get(Gender, px.gender_id)
110
+ object.__setattr__(px, 'gender', gender_obj)
111
+
112
+ if px.address_id:
113
+ from models.client.address import Address
114
+ address_obj = session.get(Address, px.address_id)
115
+ object.__setattr__(px, 'address', address_obj)
116
+
117
+ if px.marriage_status_id:
118
+ from models.client.marriage_status import MarriageStatus
119
+ marriage_status_obj = session.get(MarriageStatus, px.marriage_status_id)
120
+ object.__setattr__(px, 'marriage_status', marriage_status_obj)
121
+
122
+ if px.profession_id:
123
+ from models.client.profession import Profession
124
+ profession_obj = session.get(Profession, px.profession_id)
125
+ object.__setattr__(px, 'profession', profession_obj)
126
+
127
+ if px.education_id:
128
+ from models.client.education import Education
129
+ education_obj = session.get(Education, px.education_id)
130
+ object.__setattr__(px, 'education', education_obj)
131
+
132
+ if px.user_id:
133
+ from models.user.user import User
134
+ user_obj = session.get(User, px.user_id)
135
+ object.__setattr__(px, 'user', user_obj)
136
+
137
+ return results
138
+
139
+ def list_all_command(self, active_only: bool = True, load_relations: bool = False) -> List[Px]:
140
+ with get_session(self.tenant) as session:
141
+ statement = select(Px)
142
+
143
+ if active_only:
144
+ statement = statement.where(Px.is_active == True)
145
+
146
+ results = session.exec(statement).all()
147
+
148
+ if load_relations:
149
+ for px in results:
150
+ if px.gender_id:
151
+ from models.client.gender import Gender
152
+ gender_obj = session.get(Gender, px.gender_id)
153
+ object.__setattr__(px, 'gender', gender_obj)
154
+
155
+ if px.address_id:
156
+ from models.client.address import Address
157
+ address_obj = session.get(Address, px.address_id)
158
+ object.__setattr__(px, 'address', address_obj)
159
+
160
+ if px.marriage_status_id:
161
+ from models.client.marriage_status import MarriageStatus
162
+ marriage_status_obj = session.get(MarriageStatus, px.marriage_status_id)
163
+ object.__setattr__(px, 'marriage_status', marriage_status_obj)
164
+
165
+ if px.profession_id:
166
+ from models.client.profession import Profession
167
+ profession_obj = session.get(Profession, px.profession_id)
168
+ object.__setattr__(px, 'profession', profession_obj)
169
+
170
+ if px.education_id:
171
+ from models.client.education import Education
172
+ education_obj = session.get(Education, px.education_id)
173
+ object.__setattr__(px, 'education', education_obj)
174
+
175
+ if px.user_id:
176
+ from models.user.user import User
177
+ user_obj = session.get(User, px.user_id)
178
+ object.__setattr__(px, 'user', user_obj)
179
+
180
+ return results
181
+
182
+ def update_command(self, px: Px) -> Px:
183
+ with get_session(self.tenant) as session:
184
+ db_px = session.merge(px)
185
+ session.commit()
186
+ session.refresh(db_px)
187
+ return db_px
188
+
189
+ def delete_command(self, px_id: UUID, soft_delete: bool = True) -> bool:
190
+ with get_session(self.tenant) as session:
191
+ db_px = session.get(Px, px_id)
192
+ if not db_px:
193
+ return False
194
+
195
+ if soft_delete:
196
+ db_px.is_active = False
197
+ session.add(db_px)
198
+ else:
199
+ session.delete(db_px)
200
+
201
+ session.commit()
202
+ return True
203
+
204
+ def count_command(self, active_only: bool = True) -> int:
205
+ with get_session(self.tenant) as session:
206
+ statement = select(Px)
207
+ if active_only:
208
+ statement = statement.where(Px.is_active == True)
209
+ results = session.exec(statement)
210
+ return len(results.all())
File without changes
@@ -0,0 +1,150 @@
1
+ from typing import Optional, List
2
+ from uuid import UUID
3
+ from sqlmodel import select, or_
4
+ from sqlalchemy.orm import selectinload,joinedload
5
+ from models import Collaborator
6
+ from models import Speciality
7
+ from config.db import engines, get_session
8
+
9
+ class CollaboratorRepository:
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, collaborator: Collaborator) -> Collaborator:
16
+ with get_session(self.tenant) as session:
17
+ session.add(collaborator)
18
+ session.commit()
19
+ session.refresh(collaborator)
20
+ return collaborator
21
+
22
+ def get_by_id_command(self, collaborator_id: UUID, load_relations: bool = False) -> Optional[Collaborator]:
23
+ with get_session(self.tenant) as session:
24
+ if load_relations:
25
+ statement = select(Collaborator).where(Collaborator.collaborator_id == collaborator_id).options(
26
+ selectinload(Collaborator.specialties)
27
+ )
28
+ collaborator = session.exec(statement).first()
29
+ if load_relations:
30
+
31
+ if collaborator.collaborator_type_id:
32
+ from models.collaborator.collaborator_type import CollaboratorType
33
+ collab_type_obj = session.get(CollaboratorType, collaborator.collaborator_type_id)
34
+ object.__setattr__(collaborator,'collaborator_type', collab_type_obj)
35
+
36
+ if collaborator.user_id:
37
+ from models.user.user import User
38
+ user_obj = session.get(User, collaborator.user_id)
39
+ object.__setattr__(collaborator,'user',user_obj)
40
+
41
+ return collaborator
42
+ else:
43
+ return session.get(Collaborator, collaborator_id)
44
+
45
+ def get_by_ruc_name_code_command(self, content: str, active_only: bool = True, load_relations : bool = False)->List[Collaborator]:
46
+ with get_session(self.tenant) as session:
47
+
48
+ query = select(Collaborator).where(
49
+ or_(
50
+ Collaborator.name.ilike(f"%{content}%"),
51
+ Collaborator.ruc.ilike(f"%{content}%"),
52
+ Collaborator.code.ilike(f"%{content}%")
53
+ )
54
+ )
55
+
56
+ if load_relations:
57
+ query = select(Collaborator).options(
58
+ selectinload(Collaborator.collaborator_type),
59
+ joinedload(Collaborator.user),
60
+ selectinload(Collaborator.specialties)
61
+ ).where(
62
+ or_(
63
+ Collaborator.name.ilike(f"%{content}%"),
64
+ Collaborator.ruc.ilike(f"%{content}%"),
65
+ Collaborator.code.ilike(f"%{content}%")
66
+ )
67
+ )
68
+
69
+ if active_only:
70
+ query.where(Collaborator.is_active == True)
71
+
72
+ collaborators = session.exec(query).all()
73
+
74
+ return collaborators
75
+
76
+
77
+ def get_all_command(self, active_only: bool = True,load_related: bool = False) -> List[Collaborator]:
78
+ with get_session(self.tenant) as session:
79
+
80
+
81
+ if load_related:
82
+
83
+ statement = select(Collaborator).options(
84
+ selectinload(Collaborator.specialties)
85
+ )
86
+ if active_only:
87
+ statement = statement.where(Collaborator.is_active == True)
88
+ collaborators = session.exec(statement).all()
89
+
90
+ for collaborator in collaborators:
91
+ if collaborator.collaborator_type_id:
92
+ from models.collaborator.collaborator_type import CollaboratorType
93
+ collab_type_obj = session.get(CollaboratorType, collaborator.collaborator_type_id)
94
+ object.__setattr__(collaborator,'collaborator_type', collab_type_obj)
95
+
96
+ if collaborator.user_id:
97
+ from models.user.user import User
98
+ user_obj = session.get(User, collaborator.user_id)
99
+ object.__setattr__(collaborator,'user',user_obj)
100
+ return collaborators
101
+
102
+ statement = select(Collaborator)
103
+ return session.exec(statement).all()
104
+
105
+ def update_command(self, collaborator: Collaborator) -> Collaborator:
106
+ with get_session(self.tenant) as session:
107
+ existing_collaborator = session.get(Collaborator, collaborator.collaborator_id)
108
+ if not existing_collaborator:
109
+ raise ValueError(f"collaborator with id {collaborator.collaborator_id} does not exist")
110
+
111
+ for key, value in collaborator.dict(exclude_unset=True).items():
112
+ setattr(existing_collaborator, key, value)
113
+
114
+ bd_collaborator = session.merge(existing_collaborator)
115
+ session.commit()
116
+ session.refresh(bd_collaborator)
117
+ return bd_collaborator
118
+
119
+ def delete_command(self, collaborator_id: UUID, soft_delete: bool = False)->None:
120
+ with get_session(self.tenant) as session:
121
+ existing_bridge = session.get(Collaborator, collaborator_id)
122
+ if not existing_bridge:
123
+ raise ValueError(f"Collaborator with id {collaborator_id} does not exist")
124
+
125
+ if soft_delete:
126
+ existing_bridge.is_active = False
127
+ session.add(existing_bridge)
128
+ else:
129
+ session.delete(existing_bridge)
130
+
131
+ session.commit()
132
+
133
+ def assign_speciality_command(self, collaborator_id: UUID, speciality_id: UUID) -> Optional[Collaborator]:
134
+ with get_session(self.tenant) as session:
135
+ collab_statement = select(Collaborator).options(selectinload(Collaborator.specialties)).where(Collaborator.collaborator_id == collaborator_id)
136
+ collab = session.exec(collab_statement).first()
137
+ if not collab:
138
+ return None
139
+
140
+ speciality = session.get(Speciality, speciality_id)
141
+ if not speciality:
142
+ return None
143
+
144
+ if speciality not in collab.specialties:
145
+ collab.specialties.append(speciality)
146
+ session.add(collab)
147
+ session.commit()
148
+ session.refresh(collab)
149
+
150
+ return collab
@@ -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 CollaboratorType
6
+ from config.db import engines, get_session
7
+
8
+ class CollaboratorTypeRepository:
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,collaborator_type : CollaboratorType)-> CollaboratorType:
15
+ with get_session(self.tenant) as session:
16
+ session.add(collaborator_type)
17
+ session.commit()
18
+ session.refresh(collaborator_type)
19
+ return collaborator_type
20
+
21
+ def get_by_id_command(self, collaborator_type_id: UUID) -> Optional[CollaboratorType]:
22
+ with get_session(self.tenant) as session:
23
+ return session.get(CollaboratorType, collaborator_type_id)
24
+
25
+ def get_by_name_command(self, name: str) -> Optional[CollaboratorType]:
26
+ with get_session(self.tenant) as session:
27
+ statement = select(CollaboratorType).where(CollaboratorType.name == name)
28
+ result = session.exec(statement).first()
29
+ return result
30
+
31
+ def list_all_command(self, active_only: bool = True) -> List[CollaboratorType]:
32
+ with get_session(self.tenant) as session:
33
+ statement = select(CollaboratorType)
34
+
35
+ if active_only:
36
+ statement = statement.where(CollaboratorType.is_active == True)
37
+
38
+ results = session.exec(statement)
39
+ return results.all()
40
+
41
+ def update_command(self, collaborator_type_id: UUID, **kwargs) -> Optional[CollaboratorType]:
42
+ with get_session(self.tenant) as session:
43
+ db_collaborator_type = session.get(CollaboratorType, collaborator_type_id)
44
+ if not db_collaborator_type:
45
+ return None
46
+
47
+ for key, value in kwargs.items():
48
+ if hasattr(db_collaborator_type, key):
49
+ setattr(db_collaborator_type, key, value)
50
+
51
+ session.add(db_collaborator_type)
52
+ session.commit()
53
+ session.refresh(db_collaborator_type)
54
+ return db_collaborator_type
55
+
56
+ def delete_command(self, collaborator_type_id: UUID, soft_delete: bool = True) -> bool:
57
+ with get_session(self.tenant) as session:
58
+ db_collaborator_type = session.get(CollaboratorType, collaborator_type_id)
59
+ if not db_collaborator_type:
60
+ return False
61
+
62
+ if soft_delete:
63
+ db_collaborator_type.is_active = False
64
+ session.add(db_collaborator_type)
65
+ else:
66
+ session.delete(db_collaborator_type)
67
+
68
+ session.commit()
69
+ return True