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.
- {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/METADATA +3 -3
- 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.0.dist-info/RECORD +0 -10
- {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/WHEEL +0 -0
- {healthdatalayer-1.0.0.dist-info → healthdatalayer-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import MedicalLab
|
|
6
|
+
from models import Px
|
|
7
|
+
from config.db import engines, get_session
|
|
8
|
+
|
|
9
|
+
class MedicalLabRepository:
|
|
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, medical_lab: MedicalLab) -> MedicalLab:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(medical_lab)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(medical_lab)
|
|
20
|
+
return medical_lab
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, medical_lab_id: UUID, load_relations: bool = False) -> Optional[MedicalLab]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
medical_lab = session.get(MedicalLab, medical_lab_id)
|
|
25
|
+
|
|
26
|
+
if medical_lab and load_relations:
|
|
27
|
+
if medical_lab.measure_lab_id:
|
|
28
|
+
from models import MeasureLab
|
|
29
|
+
measure_lab_obj = session.get(MeasureLab, medical_lab.measure_lab_id)
|
|
30
|
+
object.__setattr__(medical_lab, 'measure_lab', measure_lab_obj)
|
|
31
|
+
|
|
32
|
+
from models.lab.client_lab import ClientLab
|
|
33
|
+
statement = select(ClientLab).where(ClientLab.medical_lab_id == medical_lab_id)
|
|
34
|
+
client_labs = session.exec(statement).all()
|
|
35
|
+
|
|
36
|
+
pxs_list = []
|
|
37
|
+
for cl in client_labs:
|
|
38
|
+
px = session.get(Px, cl.client_id)
|
|
39
|
+
if px:
|
|
40
|
+
pxs_list.append(px)
|
|
41
|
+
|
|
42
|
+
object.__setattr__(medical_lab, 'pxs', pxs_list)
|
|
43
|
+
|
|
44
|
+
return medical_lab
|
|
45
|
+
|
|
46
|
+
def get_by_parameter_command(self, parameter: str, load_relations: bool = False) -> Optional[MedicalLab]:
|
|
47
|
+
with get_session(self.tenant) as session:
|
|
48
|
+
statement = select(MedicalLab).where(MedicalLab.parameter == parameter)
|
|
49
|
+
medical_lab = session.exec(statement).first()
|
|
50
|
+
|
|
51
|
+
if medical_lab and load_relations:
|
|
52
|
+
if medical_lab.measure_lab_id:
|
|
53
|
+
from models import MeasureLab
|
|
54
|
+
measure_lab_obj = session.get(MeasureLab, medical_lab.measure_lab_id)
|
|
55
|
+
object.__setattr__(medical_lab, 'measure_lab', measure_lab_obj)
|
|
56
|
+
|
|
57
|
+
from models.lab.client_lab import ClientLab
|
|
58
|
+
statement_cl = select(ClientLab).where(ClientLab.medical_lab_id == medical_lab.medical_lab_id)
|
|
59
|
+
client_labs = session.exec(statement_cl).all()
|
|
60
|
+
|
|
61
|
+
pxs_list = []
|
|
62
|
+
for cl in client_labs:
|
|
63
|
+
px = session.get(Px, cl.client_id)
|
|
64
|
+
if px:
|
|
65
|
+
pxs_list.append(px)
|
|
66
|
+
|
|
67
|
+
object.__setattr__(medical_lab, 'pxs', pxs_list)
|
|
68
|
+
|
|
69
|
+
return medical_lab
|
|
70
|
+
|
|
71
|
+
def search_by_parameter_command(self, parameter: str, load_relations: bool = False) -> List[MedicalLab]:
|
|
72
|
+
with get_session(self.tenant) as session:
|
|
73
|
+
statement = select(MedicalLab).where(MedicalLab.parameter.ilike(f"%{parameter}%"))
|
|
74
|
+
results = session.exec(statement).all()
|
|
75
|
+
|
|
76
|
+
if load_relations:
|
|
77
|
+
from models import MeasureLab
|
|
78
|
+
from models.lab.client_lab import ClientLab
|
|
79
|
+
|
|
80
|
+
for medical_lab in results:
|
|
81
|
+
if medical_lab.measure_lab_id:
|
|
82
|
+
measure_lab_obj = session.get(MeasureLab, medical_lab.measure_lab_id)
|
|
83
|
+
object.__setattr__(medical_lab, 'measure_lab', measure_lab_obj)
|
|
84
|
+
|
|
85
|
+
statement_cl = select(ClientLab).where(ClientLab.medical_lab_id == medical_lab.medical_lab_id)
|
|
86
|
+
client_labs = session.exec(statement_cl).all()
|
|
87
|
+
|
|
88
|
+
pxs_list = []
|
|
89
|
+
for cl in client_labs:
|
|
90
|
+
px = session.get(Px, cl.client_id)
|
|
91
|
+
if px:
|
|
92
|
+
pxs_list.append(px)
|
|
93
|
+
|
|
94
|
+
object.__setattr__(medical_lab, 'pxs', pxs_list)
|
|
95
|
+
|
|
96
|
+
return results
|
|
97
|
+
|
|
98
|
+
def list_all_command(self, active_only: bool = True, load_relations: bool = False) -> List[MedicalLab]:
|
|
99
|
+
with get_session(self.tenant) as session:
|
|
100
|
+
statement = select(MedicalLab)
|
|
101
|
+
|
|
102
|
+
if active_only:
|
|
103
|
+
statement = statement.where(MedicalLab.is_active == True)
|
|
104
|
+
|
|
105
|
+
results = session.exec(statement).all()
|
|
106
|
+
|
|
107
|
+
if load_relations:
|
|
108
|
+
from models import MeasureLab
|
|
109
|
+
from models.lab.client_lab import ClientLab
|
|
110
|
+
|
|
111
|
+
for medical_lab in results:
|
|
112
|
+
if medical_lab.measure_lab_id:
|
|
113
|
+
measure_lab_obj = session.get(MeasureLab, medical_lab.measure_lab_id)
|
|
114
|
+
object.__setattr__(medical_lab, 'measure_lab', measure_lab_obj)
|
|
115
|
+
|
|
116
|
+
statement_cl = select(ClientLab).where(ClientLab.medical_lab_id == medical_lab.medical_lab_id)
|
|
117
|
+
client_labs = session.exec(statement_cl).all()
|
|
118
|
+
|
|
119
|
+
pxs_list = []
|
|
120
|
+
for cl in client_labs:
|
|
121
|
+
px = session.get(Px, cl.client_id)
|
|
122
|
+
if px:
|
|
123
|
+
pxs_list.append(px)
|
|
124
|
+
|
|
125
|
+
object.__setattr__(medical_lab, 'pxs', pxs_list)
|
|
126
|
+
|
|
127
|
+
return results
|
|
128
|
+
|
|
129
|
+
def list_by_measure_lab_command(self, measure_lab_id: UUID, active_only: bool = True) -> List[MedicalLab]:
|
|
130
|
+
with get_session(self.tenant) as session:
|
|
131
|
+
statement = select(MedicalLab).where(MedicalLab.measure_lab_id == measure_lab_id)
|
|
132
|
+
|
|
133
|
+
if active_only:
|
|
134
|
+
statement = statement.where(MedicalLab.is_active == True)
|
|
135
|
+
|
|
136
|
+
results = session.exec(statement)
|
|
137
|
+
return results.all()
|
|
138
|
+
|
|
139
|
+
def update_command(self, medical_lab: MedicalLab) -> MedicalLab:
|
|
140
|
+
with get_session(self.tenant) as session:
|
|
141
|
+
db_medical_lab = session.merge(medical_lab)
|
|
142
|
+
session.commit()
|
|
143
|
+
session.refresh(db_medical_lab)
|
|
144
|
+
return db_medical_lab
|
|
145
|
+
|
|
146
|
+
def delete_command(self, medical_lab_id: UUID, soft_delete: bool = True) -> bool:
|
|
147
|
+
with get_session(self.tenant) as session:
|
|
148
|
+
db_medical_lab = session.get(MedicalLab, medical_lab_id)
|
|
149
|
+
if not db_medical_lab:
|
|
150
|
+
return False
|
|
151
|
+
|
|
152
|
+
if soft_delete:
|
|
153
|
+
db_medical_lab.is_active = False
|
|
154
|
+
session.add(db_medical_lab)
|
|
155
|
+
else:
|
|
156
|
+
session.delete(db_medical_lab)
|
|
157
|
+
|
|
158
|
+
session.commit()
|
|
159
|
+
return True
|
|
160
|
+
|
|
161
|
+
def count_command(self, active_only: bool = True) -> int:
|
|
162
|
+
with get_session(self.tenant) as session:
|
|
163
|
+
statement = select(MedicalLab)
|
|
164
|
+
if active_only:
|
|
165
|
+
statement = statement.where(MedicalLab.is_active == True)
|
|
166
|
+
results = session.exec(statement)
|
|
167
|
+
return len(results.all())
|
|
168
|
+
|
|
169
|
+
def exists_by_parameter_command(self, parameter: str) -> bool:
|
|
170
|
+
with get_session(self.tenant) as session:
|
|
171
|
+
statement = select(MedicalLab).where(MedicalLab.parameter == parameter)
|
|
172
|
+
result = session.exec(statement).first()
|
|
173
|
+
return result is not None
|
|
174
|
+
|
|
175
|
+
def get_medical_lab_patients_command(self, medical_lab_id: UUID) -> List[Px]:
|
|
176
|
+
"""Get all patients associated with a medical lab"""
|
|
177
|
+
with get_session(self.tenant) as session:
|
|
178
|
+
from models.lab.client_lab import ClientLab
|
|
179
|
+
|
|
180
|
+
statement = select(ClientLab).where(ClientLab.medical_lab_id == medical_lab_id)
|
|
181
|
+
client_labs = session.exec(statement).all()
|
|
182
|
+
|
|
183
|
+
pxs_list = []
|
|
184
|
+
for cl in client_labs:
|
|
185
|
+
px = session.get(Px, cl.client_id)
|
|
186
|
+
if px:
|
|
187
|
+
pxs_list.append(px)
|
|
188
|
+
|
|
189
|
+
return pxs_list
|
|
190
|
+
|
|
191
|
+
def assign_patient_command(self, medical_lab_id: UUID, px_id: UUID) -> Optional[MedicalLab]:
|
|
192
|
+
"""Assign a patient to a medical lab"""
|
|
193
|
+
with get_session(self.tenant) as session:
|
|
194
|
+
from models.lab.client_lab import ClientLab
|
|
195
|
+
|
|
196
|
+
medical_lab = session.get(MedicalLab, medical_lab_id)
|
|
197
|
+
if not medical_lab:
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
px = session.get(Px, px_id)
|
|
201
|
+
if not px:
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
existing = session.exec(
|
|
205
|
+
select(ClientLab).where(
|
|
206
|
+
ClientLab.medical_lab_id == medical_lab_id,
|
|
207
|
+
ClientLab.client_id == px_id
|
|
208
|
+
)
|
|
209
|
+
).first()
|
|
210
|
+
|
|
211
|
+
if not existing:
|
|
212
|
+
client_lab = ClientLab(medical_lab_id=medical_lab_id, client_id=px_id)
|
|
213
|
+
session.add(client_lab)
|
|
214
|
+
session.commit()
|
|
215
|
+
|
|
216
|
+
session.refresh(medical_lab)
|
|
217
|
+
return medical_lab
|
|
218
|
+
|
|
219
|
+
def remove_patient_command(self, medical_lab_id: UUID, px_id: UUID) -> Optional[MedicalLab]:
|
|
220
|
+
"""Remove a patient from a medical lab"""
|
|
221
|
+
with get_session(self.tenant) as session:
|
|
222
|
+
from models.lab.client_lab import ClientLab
|
|
223
|
+
|
|
224
|
+
medical_lab = session.get(MedicalLab, medical_lab_id)
|
|
225
|
+
if not medical_lab:
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
client_lab = session.exec(
|
|
229
|
+
select(ClientLab).where(
|
|
230
|
+
ClientLab.medical_lab_id == medical_lab_id,
|
|
231
|
+
ClientLab.client_id == px_id
|
|
232
|
+
)
|
|
233
|
+
).first()
|
|
234
|
+
|
|
235
|
+
if client_lab:
|
|
236
|
+
session.delete(client_lab)
|
|
237
|
+
session.commit()
|
|
238
|
+
|
|
239
|
+
session.refresh(medical_lab)
|
|
240
|
+
return medical_lab
|
|
241
|
+
|
|
242
|
+
def is_patient_assigned_command(self, medical_lab_id: UUID, px_id: UUID) -> bool:
|
|
243
|
+
"""Check if a patient is assigned to a medical lab"""
|
|
244
|
+
with get_session(self.tenant) as session:
|
|
245
|
+
from models.lab.client_lab import ClientLab
|
|
246
|
+
|
|
247
|
+
result = session.exec(
|
|
248
|
+
select(ClientLab).where(
|
|
249
|
+
ClientLab.medical_lab_id == medical_lab_id,
|
|
250
|
+
ClientLab.client_id == px_id
|
|
251
|
+
)
|
|
252
|
+
).first()
|
|
253
|
+
|
|
254
|
+
return result is not None
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import MedicalDiagnosis
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MedicalDiagnosisRepository:
|
|
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, medical_diagnosis: MedicalDiagnosis) -> MedicalDiagnosis:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(medical_diagnosis)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(medical_diagnosis)
|
|
19
|
+
return medical_diagnosis
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, medical_diagnosis_id: UUID) -> Optional[MedicalDiagnosis]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(MedicalDiagnosis, medical_diagnosis_id)
|
|
24
|
+
|
|
25
|
+
def list_all_command(self, active_only: bool = True) -> List[MedicalDiagnosis]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(MedicalDiagnosis)
|
|
28
|
+
|
|
29
|
+
if active_only:
|
|
30
|
+
statement = statement.where(MedicalDiagnosis.is_active == True)
|
|
31
|
+
|
|
32
|
+
results = session.exec(statement)
|
|
33
|
+
return results.all()
|
|
34
|
+
|
|
35
|
+
def update_command(self, medical_diagnosis_id: UUID, **kwargs) -> Optional[MedicalDiagnosis]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
db_medical_diagnosis = session.get(MedicalDiagnosis, medical_diagnosis_id)
|
|
38
|
+
if not db_medical_diagnosis:
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
for key, value in kwargs.items():
|
|
42
|
+
if hasattr(db_medical_diagnosis, key):
|
|
43
|
+
setattr(db_medical_diagnosis, key, value)
|
|
44
|
+
|
|
45
|
+
session.add(db_medical_diagnosis)
|
|
46
|
+
session.commit()
|
|
47
|
+
session.refresh(db_medical_diagnosis)
|
|
48
|
+
return db_medical_diagnosis
|
|
49
|
+
|
|
50
|
+
def delete_command(self, medical_diagnosis_id: UUID, soft_delete: bool = True) -> bool:
|
|
51
|
+
with get_session(self.tenant) as session:
|
|
52
|
+
db_medical_diagnosis = session.get(MedicalDiagnosis, medical_diagnosis_id)
|
|
53
|
+
if not db_medical_diagnosis:
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
if soft_delete:
|
|
57
|
+
db_medical_diagnosis.is_active = False
|
|
58
|
+
session.add(db_medical_diagnosis)
|
|
59
|
+
else:
|
|
60
|
+
session.delete(db_medical_diagnosis)
|
|
61
|
+
|
|
62
|
+
session.commit()
|
|
63
|
+
return True
|
|
@@ -0,0 +1,92 @@
|
|
|
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 MedicalDiagnosisVisit
|
|
6
|
+
from models import MedicalVisit
|
|
7
|
+
from config.db import engines, get_session
|
|
8
|
+
|
|
9
|
+
class MedicalDiagnosisVisitRepository:
|
|
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, medical_diagnosis_visit: MedicalDiagnosisVisit) -> MedicalDiagnosisVisit:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(medical_diagnosis_visit)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(medical_diagnosis_visit)
|
|
20
|
+
return medical_diagnosis_visit
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, medical_diagnosis_visit_id: UUID, load_relations: bool = False) -> Optional[MedicalDiagnosisVisit]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
|
|
25
|
+
if load_relations:
|
|
26
|
+
statement = select(MedicalDiagnosisVisit).where(MedicalDiagnosisVisit.medical_diagnosis_visit_id == medical_diagnosis_visit_id).options(
|
|
27
|
+
joinedload(MedicalDiagnosisVisit.medical_visit),
|
|
28
|
+
joinedload(MedicalDiagnosisVisit.medical_diagnosis)
|
|
29
|
+
)
|
|
30
|
+
medical_diagnosis_visit = session.exec(statement).first()
|
|
31
|
+
|
|
32
|
+
return medical_diagnosis_visit
|
|
33
|
+
else:
|
|
34
|
+
return session.get(MedicalDiagnosisVisit, medical_diagnosis_visit_id)
|
|
35
|
+
|
|
36
|
+
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) ->Optional[MedicalDiagnosisVisit]:
|
|
37
|
+
with get_session(self.tenant) as session:
|
|
38
|
+
|
|
39
|
+
statement = select(MedicalDiagnosisVisit).where(MedicalDiagnosisVisit.medical_visit_id == medical_visit_id)
|
|
40
|
+
if load_relations:
|
|
41
|
+
statement = statement.options(
|
|
42
|
+
joinedload(MedicalDiagnosisVisit.medical_visit),
|
|
43
|
+
joinedload(MedicalDiagnosisVisit.medical_diagnosis)
|
|
44
|
+
)
|
|
45
|
+
medical_diagnosis_visit = session.exec(statement).first()
|
|
46
|
+
|
|
47
|
+
return medical_diagnosis_visit
|
|
48
|
+
|
|
49
|
+
def get_all_command(self, active_only: bool = True,load_related: bool = False) -> List[MedicalDiagnosisVisit]:
|
|
50
|
+
with get_session(self.tenant) as session:
|
|
51
|
+
|
|
52
|
+
statement = select(MedicalDiagnosisVisit)
|
|
53
|
+
|
|
54
|
+
if load_related:
|
|
55
|
+
statement = select(MedicalDiagnosisVisit).options(
|
|
56
|
+
selectinload(MedicalDiagnosisVisit.medical_visit),
|
|
57
|
+
joinedload(MedicalDiagnosisVisit.medical_diagnosis)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
if active_only:
|
|
61
|
+
statement = statement.where(MedicalDiagnosisVisit.is_active == True)
|
|
62
|
+
medical_diagnosis_visit = session.exec(statement).all()
|
|
63
|
+
|
|
64
|
+
return medical_diagnosis_visit
|
|
65
|
+
|
|
66
|
+
def update_command(self, medical_diagnosis_visit: MedicalDiagnosisVisit) -> MedicalDiagnosisVisit:
|
|
67
|
+
with get_session(self.tenant) as session:
|
|
68
|
+
existing_medical_diagnosis_visit = session.get(MedicalDiagnosisVisit, medical_diagnosis_visit.medical_diagnosis_visit_id)
|
|
69
|
+
if not existing_medical_diagnosis_visit:
|
|
70
|
+
raise ValueError(f"MedicalDiagnosisVisit with id {medical_diagnosis_visit.medical_diagnosis_visit_id} does not exist")
|
|
71
|
+
|
|
72
|
+
for key, value in medical_diagnosis_visit.dict(exclude_unset=True).items():
|
|
73
|
+
setattr(existing_medical_diagnosis_visit, key, value)
|
|
74
|
+
|
|
75
|
+
bd_medical_diagnosis_visit = session.merge(existing_medical_diagnosis_visit)
|
|
76
|
+
session.commit()
|
|
77
|
+
session.refresh(bd_medical_diagnosis_visit)
|
|
78
|
+
return bd_medical_diagnosis_visit
|
|
79
|
+
|
|
80
|
+
def delete_command(self, medical_diagnosis_visit_id: UUID, soft_delete: bool = False)->None:
|
|
81
|
+
with get_session(self.tenant) as session:
|
|
82
|
+
existing_medical_diagnosis_visit = session.get(MedicalVisit, medical_diagnosis_visit_id)
|
|
83
|
+
if not existing_medical_diagnosis_visit:
|
|
84
|
+
raise ValueError(f"MedicalDiagnosisVisit with id {medical_diagnosis_visit_id} does not exist")
|
|
85
|
+
|
|
86
|
+
if soft_delete:
|
|
87
|
+
existing_medical_diagnosis_visit.is_active = False
|
|
88
|
+
session.add(existing_medical_diagnosis_visit)
|
|
89
|
+
else:
|
|
90
|
+
session.delete(existing_medical_diagnosis_visit)
|
|
91
|
+
|
|
92
|
+
session.commit()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
from sqlalchemy.orm import selectinload,joinedload
|
|
5
|
+
from models import MedicalDrugRecipe
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MedicalDrugRecipeRepository:
|
|
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
|
+
def create_command(self, medical_drug_recipe: MedicalDrugRecipe) -> MedicalDrugRecipe:
|
|
14
|
+
with get_session(self.tenant) as session:
|
|
15
|
+
session.add(medical_drug_recipe)
|
|
16
|
+
session.commit()
|
|
17
|
+
session.refresh(medical_drug_recipe)
|
|
18
|
+
return medical_drug_recipe
|
|
19
|
+
|
|
20
|
+
def get_by_id_command(self, medical_drug_recipe_id: UUID) -> Optional[MedicalDrugRecipe]:
|
|
21
|
+
with get_session(self.tenant) as session:
|
|
22
|
+
|
|
23
|
+
return session.get(MedicalDrugRecipe, medical_drug_recipe_id)
|
|
24
|
+
|
|
25
|
+
def list_all_command(self, active_only: bool = True)->List[MedicalDrugRecipe]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
|
|
28
|
+
statement = select(MedicalDrugRecipe)
|
|
29
|
+
if active_only:
|
|
30
|
+
statement = statement.where(MedicalDrugRecipe.is_active == True)
|
|
31
|
+
|
|
32
|
+
return session.exec(statement).all()
|
|
33
|
+
|
|
34
|
+
def get_by_medical_recipe_visit_id_command(self, medical_recipe_visit_id: UUID,active_only: bool = True)-> List[MedicalDrugRecipe]:
|
|
35
|
+
with get_session(self.tenant) as session:
|
|
36
|
+
statement = select(MedicalDrugRecipe).where(MedicalDrugRecipe.medical_recipe_visit_id == medical_recipe_visit_id)
|
|
37
|
+
if active_only:
|
|
38
|
+
statement = statement.where(MedicalDrugRecipe.is_active == True)
|
|
39
|
+
|
|
40
|
+
return session.exec(statement).all()
|
|
41
|
+
|
|
42
|
+
def update_command(self, medical_drug_recipe_id: UUID, **kwargs) -> Optional[MedicalDrugRecipe]:
|
|
43
|
+
with get_session(self.tenant) as session:
|
|
44
|
+
db_medical_drug_recipe = session.get(MedicalDrugRecipe, medical_drug_recipe_id)
|
|
45
|
+
if not db_medical_drug_recipe:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
for key, value in kwargs.items():
|
|
49
|
+
if hasattr(db_medical_drug_recipe, key):
|
|
50
|
+
setattr(db_medical_drug_recipe, key, value)
|
|
51
|
+
|
|
52
|
+
session.add(db_medical_drug_recipe)
|
|
53
|
+
session.commit()
|
|
54
|
+
session.refresh(db_medical_drug_recipe)
|
|
55
|
+
return db_medical_drug_recipe
|
|
56
|
+
|
|
57
|
+
def delete_command(self, medical_drug_recipe_id: UUID, soft_delete: bool = True) -> bool:
|
|
58
|
+
with get_session(self.tenant) as session:
|
|
59
|
+
db_medical_drug_recipe = session.get(MedicalDrugRecipe, medical_drug_recipe_id)
|
|
60
|
+
if not db_medical_drug_recipe:
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
if soft_delete:
|
|
64
|
+
db_medical_drug_recipe.is_active = False
|
|
65
|
+
session.add(db_medical_drug_recipe)
|
|
66
|
+
else:
|
|
67
|
+
session.delete(db_medical_drug_recipe)
|
|
68
|
+
|
|
69
|
+
session.commit()
|
|
70
|
+
return True
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from models import MedicalDrug
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MedicalDrugRepository:
|
|
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, medical_drug: MedicalDrug) -> MedicalDrug:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(medical_drug)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(medical_drug)
|
|
19
|
+
return medical_drug
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, medical_drug_id: UUID) -> Optional[MedicalDrug]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
return session.get(MedicalDrug, medical_drug_id)
|
|
24
|
+
|
|
25
|
+
def list_all_command(self, active_only: bool = True) -> List[MedicalDrug]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(MedicalDrug)
|
|
28
|
+
|
|
29
|
+
if active_only:
|
|
30
|
+
statement = statement.where(MedicalDrug.is_active == True)
|
|
31
|
+
|
|
32
|
+
results = session.exec(statement)
|
|
33
|
+
return results.all()
|
|
34
|
+
|
|
35
|
+
def update_command(self, medical_drug_id: UUID, **kwargs) -> Optional[MedicalDrug]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
db_medical_drug = session.get(MedicalDrug, medical_drug_id)
|
|
38
|
+
if not db_medical_drug:
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
for key, value in kwargs.items():
|
|
42
|
+
if hasattr(db_medical_drug, key):
|
|
43
|
+
setattr(db_medical_drug, key, value)
|
|
44
|
+
|
|
45
|
+
session.add(db_medical_drug)
|
|
46
|
+
session.commit()
|
|
47
|
+
session.refresh(db_medical_drug)
|
|
48
|
+
return db_medical_drug
|
|
49
|
+
|
|
50
|
+
def delete_command(self, medical_drug_id: UUID, soft_delete: bool = True) -> bool:
|
|
51
|
+
with get_session(self.tenant) as session:
|
|
52
|
+
db_medical_drug = session.get(MedicalDrug, medical_drug_id)
|
|
53
|
+
if not db_medical_drug:
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
if soft_delete:
|
|
57
|
+
db_medical_drug.is_active = False
|
|
58
|
+
session.add(db_medical_drug)
|
|
59
|
+
else:
|
|
60
|
+
session.delete(db_medical_drug)
|
|
61
|
+
|
|
62
|
+
session.commit()
|
|
63
|
+
return True
|
|
@@ -0,0 +1,93 @@
|
|
|
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 MedicalRecipeVisit
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MedicalRecipeVisitRepository:
|
|
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, medical_recipe_visit: MedicalRecipeVisit) -> MedicalRecipeVisit:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(medical_recipe_visit)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(medical_recipe_visit)
|
|
19
|
+
return medical_recipe_visit
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, medical_recipe_visit_id: UUID, load_relations: bool = False) -> Optional[MedicalRecipeVisit]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
|
|
24
|
+
if load_relations:
|
|
25
|
+
statement = select(MedicalRecipeVisit).where(MedicalRecipeVisit.medical_recipe_visit_id == medical_recipe_visit_id).options(
|
|
26
|
+
joinedload(MedicalRecipeVisit.medical_visit),
|
|
27
|
+
joinedload(MedicalRecipeVisit.medical_drugs)
|
|
28
|
+
)
|
|
29
|
+
medical_recipe_visit = session.exec(statement).first()
|
|
30
|
+
|
|
31
|
+
return medical_recipe_visit
|
|
32
|
+
else:
|
|
33
|
+
return session.get(MedicalRecipeVisit, medical_recipe_visit_id)
|
|
34
|
+
|
|
35
|
+
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) -> Optional[MedicalRecipeVisit]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
statement = select(MedicalRecipeVisit).where(MedicalRecipeVisit.medical_visit_id == medical_visit_id)
|
|
38
|
+
if load_relations:
|
|
39
|
+
statement = statement.options(
|
|
40
|
+
selectinload(MedicalRecipeVisit.medical_visit),
|
|
41
|
+
selectinload(MedicalRecipeVisit.medical_drugs)
|
|
42
|
+
)
|
|
43
|
+
medical_recipe_visit = session.exec(statement).first()
|
|
44
|
+
|
|
45
|
+
return medical_recipe_visit
|
|
46
|
+
|
|
47
|
+
def list_all_command(self, active_only: bool = True, load_relations: bool = False)->List[MedicalRecipeVisit]:
|
|
48
|
+
with get_session(self.tenant) as session:
|
|
49
|
+
statement = select(MedicalRecipeVisit)
|
|
50
|
+
|
|
51
|
+
if load_relations:
|
|
52
|
+
|
|
53
|
+
statement = select(MedicalRecipeVisit).options(
|
|
54
|
+
selectinload(MedicalRecipeVisit.medical_visit),
|
|
55
|
+
selectinload(MedicalRecipeVisit.medical_drugs)
|
|
56
|
+
)
|
|
57
|
+
if active_only:
|
|
58
|
+
statement = statement.where(MedicalRecipeVisit.is_active == True)
|
|
59
|
+
medical_recipe_visit = session.exec(statement).all()
|
|
60
|
+
|
|
61
|
+
return medical_recipe_visit
|
|
62
|
+
|
|
63
|
+
statement = select(MedicalRecipeVisit)
|
|
64
|
+
return session.exec(statement).all()
|
|
65
|
+
|
|
66
|
+
def update_command(self, medical_recipe_visit: MedicalRecipeVisit) -> MedicalRecipeVisit:
|
|
67
|
+
with get_session(self.tenant) as session:
|
|
68
|
+
existing_medical_recipe_visit = session.get(MedicalRecipeVisit, medical_recipe_visit.medical_recipe_visit_id)
|
|
69
|
+
if not existing_medical_recipe_visit:
|
|
70
|
+
raise ValueError(f"medical_recipe_visit with id {medical_recipe_visit.medical_recipe_visit_id} does not exist")
|
|
71
|
+
|
|
72
|
+
for key, value in medical_recipe_visit.dict(exclude_unset=True).items():
|
|
73
|
+
setattr(existing_medical_recipe_visit, key, value)
|
|
74
|
+
|
|
75
|
+
bd_medical_recipe_visit = session.merge(existing_medical_recipe_visit)
|
|
76
|
+
session.commit()
|
|
77
|
+
session.refresh(bd_medical_recipe_visit)
|
|
78
|
+
return bd_medical_recipe_visit
|
|
79
|
+
|
|
80
|
+
def delete_command(self, medical_recipe_visit_id: UUID, soft_delete: bool = False)->None:
|
|
81
|
+
with get_session(self.tenant) as session:
|
|
82
|
+
existing_medical_recipe_visit = session.get(MedicalRecipeVisit, medical_recipe_visit_id)
|
|
83
|
+
if not existing_medical_recipe_visit:
|
|
84
|
+
raise ValueError(f"MedicalRecipeVisit with id {medical_recipe_visit_id} does not exist")
|
|
85
|
+
|
|
86
|
+
if soft_delete:
|
|
87
|
+
existing_medical_recipe_visit.is_active = False
|
|
88
|
+
session.add(existing_medical_recipe_visit)
|
|
89
|
+
else:
|
|
90
|
+
session.delete(existing_medical_recipe_visit)
|
|
91
|
+
|
|
92
|
+
session.commit()
|
|
93
|
+
|