healthdatalayer 1.6.6__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.
- healthdatalayer/__init__.py +0 -0
- healthdatalayer/config/__init__.py +0 -0
- healthdatalayer/config/config.py +24 -0
- healthdatalayer/config/db.py +12 -0
- healthdatalayer/config/vault.py +20 -0
- healthdatalayer/dtos/__init__.py +2 -0
- healthdatalayer/dtos/collaborator/__init__.py +0 -0
- healthdatalayer/dtos/collaborator/schedule_collaborator.py +13 -0
- healthdatalayer/dtos/medical_visit/__init__.py +0 -0
- healthdatalayer/dtos/medical_visit/medical_certificate.py +62 -0
- healthdatalayer/models/__init__.py +75 -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/city.py +11 -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 +35 -0
- healthdatalayer/models/client/state.py +9 -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 +19 -0
- healthdatalayer/models/medical_visit/medical_recipe_visit.py +28 -0
- healthdatalayer/models/medical_visit/medical_visit.py +53 -0
- healthdatalayer/models/medical_visit/organ_system_review.py +28 -0
- healthdatalayer/models/medical_visit/physical_exam.py +45 -0
- healthdatalayer/models/medical_visit/status_visit_enum.py +8 -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/__init__.py +40 -0
- healthdatalayer/repositories/client_repositories/__init__.py +0 -0
- healthdatalayer/repositories/client_repositories/address_repository.py +94 -0
- healthdatalayer/repositories/client_repositories/client_type_repository.py +69 -0
- healthdatalayer/repositories/client_repositories/education_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/emergency_contact_repository.py +78 -0
- healthdatalayer/repositories/client_repositories/gender_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/marriage_status_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/nationality_repository.py +69 -0
- healthdatalayer/repositories/client_repositories/pathological_history_repository.py +73 -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 +239 -0
- healthdatalayer/repositories/collaborator_repositories/__init__.py +0 -0
- healthdatalayer/repositories/collaborator_repositories/collaborator_repository.py +197 -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 +82 -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 +98 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +109 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_recipe_repository.py +71 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_repository.py +78 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_recipe_visit_repository.py +93 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_visit_repository.py +509 -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 +95 -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.6.6.dist-info/METADATA +30 -0
- healthdatalayer-1.6.6.dist-info/RECORD +105 -0
- healthdatalayer-1.6.6.dist-info/WHEEL +5 -0
- healthdatalayer-1.6.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select
|
|
4
|
+
|
|
5
|
+
from healthdatalayer.models import MedicalLab
|
|
6
|
+
from healthdatalayer.models import Px
|
|
7
|
+
from healthdatalayer.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 healthdatalayer.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 healthdatalayer.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 healthdatalayer.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 healthdatalayer.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 healthdatalayer.models import MeasureLab
|
|
78
|
+
from healthdatalayer.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 healthdatalayer.models import MeasureLab
|
|
109
|
+
from healthdatalayer.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 healthdatalayer.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 healthdatalayer.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 healthdatalayer.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 healthdatalayer.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,98 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select, or_
|
|
4
|
+
|
|
5
|
+
from healthdatalayer.models import MedicalDiagnosis
|
|
6
|
+
from healthdatalayer.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 get_by_name_command(self, name:str, active_only: bool = True) -> Optional[MedicalDiagnosis]:
|
|
26
|
+
with get_session(self.tenant) as session:
|
|
27
|
+
statement = select(MedicalDiagnosis).where(MedicalDiagnosis.name == name)
|
|
28
|
+
|
|
29
|
+
if active_only:
|
|
30
|
+
statement = statement.where(MedicalDiagnosis.is_active == True)
|
|
31
|
+
|
|
32
|
+
medical_diagnosis = session.exec(statement).first()
|
|
33
|
+
return medical_diagnosis
|
|
34
|
+
|
|
35
|
+
def get_by_name_code_ilike_command(self, name:str, active_only: bool = True) -> List[MedicalDiagnosis]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
statement = select(MedicalDiagnosis).where(
|
|
38
|
+
or_(
|
|
39
|
+
MedicalDiagnosis.name.ilike(f"%{name}%"),
|
|
40
|
+
MedicalDiagnosis.cie_10_code.ilike(f"%{name}%")
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if active_only:
|
|
45
|
+
statement = statement.where(MedicalDiagnosis.is_active == True)
|
|
46
|
+
|
|
47
|
+
medical_diagnosis = session.exec(statement).all()
|
|
48
|
+
return medical_diagnosis
|
|
49
|
+
|
|
50
|
+
def get_by_code_command(self, code:str, active_only: bool = True) -> Optional[MedicalDiagnosis]:
|
|
51
|
+
with get_session(self.tenant) as session:
|
|
52
|
+
statement = select(MedicalDiagnosis).where(MedicalDiagnosis.cie_10_code == code)
|
|
53
|
+
|
|
54
|
+
if active_only:
|
|
55
|
+
statement = statement.where(MedicalDiagnosis.is_active == True)
|
|
56
|
+
|
|
57
|
+
medical_diagnosis = session.exec(statement).first()
|
|
58
|
+
return medical_diagnosis
|
|
59
|
+
|
|
60
|
+
def list_all_command(self, active_only: bool = True) -> List[MedicalDiagnosis]:
|
|
61
|
+
with get_session(self.tenant) as session:
|
|
62
|
+
statement = select(MedicalDiagnosis)
|
|
63
|
+
|
|
64
|
+
if active_only:
|
|
65
|
+
statement = statement.where(MedicalDiagnosis.is_active == True)
|
|
66
|
+
|
|
67
|
+
results = session.exec(statement)
|
|
68
|
+
return results.all()
|
|
69
|
+
|
|
70
|
+
def update_command(self, medical_diagnosis_id: UUID, **kwargs) -> Optional[MedicalDiagnosis]:
|
|
71
|
+
with get_session(self.tenant) as session:
|
|
72
|
+
db_medical_diagnosis = session.get(MedicalDiagnosis, medical_diagnosis_id)
|
|
73
|
+
if not db_medical_diagnosis:
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
for key, value in kwargs.items():
|
|
77
|
+
if hasattr(db_medical_diagnosis, key):
|
|
78
|
+
setattr(db_medical_diagnosis, key, value)
|
|
79
|
+
|
|
80
|
+
session.add(db_medical_diagnosis)
|
|
81
|
+
session.commit()
|
|
82
|
+
session.refresh(db_medical_diagnosis)
|
|
83
|
+
return db_medical_diagnosis
|
|
84
|
+
|
|
85
|
+
def delete_command(self, medical_diagnosis_id: UUID, soft_delete: bool = True) -> bool:
|
|
86
|
+
with get_session(self.tenant) as session:
|
|
87
|
+
db_medical_diagnosis = session.get(MedicalDiagnosis, medical_diagnosis_id)
|
|
88
|
+
if not db_medical_diagnosis:
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
if soft_delete:
|
|
92
|
+
db_medical_diagnosis.is_active = False
|
|
93
|
+
session.add(db_medical_diagnosis)
|
|
94
|
+
else:
|
|
95
|
+
session.delete(db_medical_diagnosis)
|
|
96
|
+
|
|
97
|
+
session.commit()
|
|
98
|
+
return True
|
|
@@ -0,0 +1,109 @@
|
|
|
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 healthdatalayer.models import MedicalDiagnosisVisit
|
|
6
|
+
from healthdatalayer.models import MedicalVisit
|
|
7
|
+
from healthdatalayer.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) ->List[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_visits = session.exec(statement).all()
|
|
46
|
+
|
|
47
|
+
return medical_diagnosis_visits
|
|
48
|
+
|
|
49
|
+
def get_by_medicalvisitid_and_diagnosisid_command(self, medical_visit_id: UUID, medical_diagnosis_id: UUID, load_relations: bool = False) ->Optional[MedicalDiagnosisVisit]:
|
|
50
|
+
with get_session(self.tenant) as session:
|
|
51
|
+
|
|
52
|
+
statement = select(MedicalDiagnosisVisit).where(
|
|
53
|
+
MedicalDiagnosisVisit.medical_visit_id == medical_visit_id,
|
|
54
|
+
MedicalDiagnosisVisit.medical_diagnosis_id == medical_diagnosis_id
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if load_relations:
|
|
58
|
+
statement = statement.options(
|
|
59
|
+
joinedload(MedicalDiagnosisVisit.medical_visit),
|
|
60
|
+
joinedload(MedicalDiagnosisVisit.medical_diagnosis)
|
|
61
|
+
)
|
|
62
|
+
medical_diagnosis_visit = session.exec(statement).first()
|
|
63
|
+
|
|
64
|
+
return medical_diagnosis_visit
|
|
65
|
+
|
|
66
|
+
def list_all_command(self, active_only: bool = True,load_related: bool = False) -> List[MedicalDiagnosisVisit]:
|
|
67
|
+
with get_session(self.tenant) as session:
|
|
68
|
+
|
|
69
|
+
statement = select(MedicalDiagnosisVisit)
|
|
70
|
+
|
|
71
|
+
if load_related:
|
|
72
|
+
statement = select(MedicalDiagnosisVisit).options(
|
|
73
|
+
selectinload(MedicalDiagnosisVisit.medical_visit),
|
|
74
|
+
joinedload(MedicalDiagnosisVisit.medical_diagnosis)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if active_only:
|
|
78
|
+
statement = statement.where(MedicalDiagnosisVisit.is_active == True)
|
|
79
|
+
medical_diagnosis_visit = session.exec(statement).all()
|
|
80
|
+
|
|
81
|
+
return medical_diagnosis_visit
|
|
82
|
+
|
|
83
|
+
def update_command(self, medical_diagnosis_visit: MedicalDiagnosisVisit) -> MedicalDiagnosisVisit:
|
|
84
|
+
with get_session(self.tenant) as session:
|
|
85
|
+
existing_medical_diagnosis_visit = session.get(MedicalDiagnosisVisit, medical_diagnosis_visit.medical_diagnosis_visit_id)
|
|
86
|
+
if not existing_medical_diagnosis_visit:
|
|
87
|
+
raise ValueError(f"MedicalDiagnosisVisit with id {medical_diagnosis_visit.medical_diagnosis_visit_id} does not exist")
|
|
88
|
+
|
|
89
|
+
for key, value in medical_diagnosis_visit.dict(exclude_unset=True).items():
|
|
90
|
+
setattr(existing_medical_diagnosis_visit, key, value)
|
|
91
|
+
|
|
92
|
+
bd_medical_diagnosis_visit = session.merge(existing_medical_diagnosis_visit)
|
|
93
|
+
session.commit()
|
|
94
|
+
session.refresh(bd_medical_diagnosis_visit)
|
|
95
|
+
return bd_medical_diagnosis_visit
|
|
96
|
+
|
|
97
|
+
def delete_command(self, medical_diagnosis_visit_id: UUID, soft_delete: bool = False)->None:
|
|
98
|
+
with get_session(self.tenant) as session:
|
|
99
|
+
existing_medical_diagnosis_visit = session.get(MedicalDiagnosisVisit, medical_diagnosis_visit_id)
|
|
100
|
+
if not existing_medical_diagnosis_visit:
|
|
101
|
+
raise ValueError(f"MedicalDiagnosisVisit with id {medical_diagnosis_visit_id} does not exist")
|
|
102
|
+
|
|
103
|
+
if soft_delete:
|
|
104
|
+
existing_medical_diagnosis_visit.is_active = False
|
|
105
|
+
session.add(existing_medical_diagnosis_visit)
|
|
106
|
+
else:
|
|
107
|
+
session.delete(existing_medical_diagnosis_visit)
|
|
108
|
+
|
|
109
|
+
session.commit()
|
|
@@ -0,0 +1,71 @@
|
|
|
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 healthdatalayer.models import MedicalDrugRecipe
|
|
6
|
+
from healthdatalayer.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
|
+
statement = select(MedicalDrugRecipe).where(MedicalDrugRecipe.medical_drug_recipe_id == medical_drug_recipe_id)
|
|
23
|
+
return session.exec(statement).first()
|
|
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
|
+
statement = select(MedicalDrugRecipe).where(MedicalDrugRecipe.medical_drug_recipe_id == medical_drug_recipe_id)
|
|
60
|
+
db_medical_drug_recipe = session.exec(statement).first()
|
|
61
|
+
if not db_medical_drug_recipe:
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
if soft_delete:
|
|
65
|
+
db_medical_drug_recipe.is_active = False
|
|
66
|
+
session.add(db_medical_drug_recipe)
|
|
67
|
+
else:
|
|
68
|
+
session.delete(db_medical_drug_recipe)
|
|
69
|
+
|
|
70
|
+
session.commit()
|
|
71
|
+
return True
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sqlmodel import select,or_
|
|
4
|
+
|
|
5
|
+
from healthdatalayer.models import MedicalDrug
|
|
6
|
+
from healthdatalayer.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
|
|
64
|
+
|
|
65
|
+
def get_by_name_code_ilike_command(self, name:str, active_only: bool = True) -> List[MedicalDrug]:
|
|
66
|
+
with get_session(self.tenant) as session:
|
|
67
|
+
statement = select(MedicalDrug).where(
|
|
68
|
+
or_(
|
|
69
|
+
MedicalDrug.drug_name.ilike(f"%{name}%"),
|
|
70
|
+
MedicalDrug.drug_code.ilike(f"%{name}%")
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if active_only:
|
|
75
|
+
statement = statement.where(MedicalDrug.is_active == True)
|
|
76
|
+
|
|
77
|
+
medical_diagnosis = session.exec(statement).all()
|
|
78
|
+
return medical_diagnosis
|