healthdatalayer 1.0.1__py3-none-any.whl → 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of healthdatalayer might be problematic. Click here for more details.
- healthdatalayer/config/__init__.py +0 -0
- healthdatalayer/models/bridge_area_floor_branch/__init__.py +0 -0
- healthdatalayer/models/bridge_area_floor_branch/area.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/branch.py +16 -0
- healthdatalayer/models/bridge_area_floor_branch/bridge_area_floor_branch.py +27 -0
- healthdatalayer/models/bridge_area_floor_branch/floor.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/room.py +8 -0
- healthdatalayer/models/bridge_area_floor_branch/system.py +8 -0
- healthdatalayer/models/client/__init__.py +0 -0
- healthdatalayer/models/client/address.py +13 -0
- healthdatalayer/models/client/client.py +25 -0
- healthdatalayer/models/client/client_type.py +9 -0
- healthdatalayer/models/client/education.py +9 -0
- healthdatalayer/models/client/emergency_contact.py +17 -0
- healthdatalayer/models/client/gender.py +9 -0
- healthdatalayer/models/client/marriage_status.py +9 -0
- healthdatalayer/models/client/nationality.py +10 -0
- healthdatalayer/models/client/pathological_history.py +29 -0
- healthdatalayer/models/client/pet.py +16 -0
- healthdatalayer/models/client/profession.py +9 -0
- healthdatalayer/models/client/px.py +28 -0
- healthdatalayer/models/collaborator/__init__.py +0 -0
- healthdatalayer/models/collaborator/collaborator.py +33 -0
- healthdatalayer/models/collaborator/collaborator_speciality.py +8 -0
- healthdatalayer/models/collaborator/collaborator_type.py +9 -0
- healthdatalayer/models/collaborator/speciality.py +23 -0
- healthdatalayer/models/lab/__init__.py +0 -0
- healthdatalayer/models/lab/client_lab.py +13 -0
- healthdatalayer/models/lab/measure_lab.py +11 -0
- healthdatalayer/models/lab/medical_lab.py +17 -0
- healthdatalayer/models/medical_visit/__init__.py +0 -0
- healthdatalayer/models/medical_visit/medical_diagnosis.py +12 -0
- healthdatalayer/models/medical_visit/medical_diagnosis_visit.py +25 -0
- healthdatalayer/models/medical_visit/medical_drug.py +27 -0
- healthdatalayer/models/medical_visit/medical_drug_recipe.py +18 -0
- healthdatalayer/models/medical_visit/medical_recipe_visit.py +28 -0
- healthdatalayer/models/medical_visit/medical_visit.py +51 -0
- healthdatalayer/models/medical_visit/organ_system_review.py +28 -0
- healthdatalayer/models/medical_visit/physical_exam.py +45 -0
- healthdatalayer/models/medical_visit/visit_triage.py +28 -0
- healthdatalayer/models/user/__init__.py +0 -0
- healthdatalayer/models/user/permission.py +27 -0
- healthdatalayer/models/user/permission_user.py +8 -0
- healthdatalayer/models/user/role.py +27 -0
- healthdatalayer/models/user/role_permission.py +8 -0
- healthdatalayer/models/user/role_user.py +8 -0
- healthdatalayer/models/user/user.py +30 -0
- healthdatalayer/repositories/client_repositories/__init__.py +0 -0
- healthdatalayer/repositories/client_repositories/address_repository.py +64 -0
- healthdatalayer/repositories/client_repositories/client_type_repository.py +69 -0
- healthdatalayer/repositories/client_repositories/education_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/gender_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/marriage_status_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/pet_repository.py +126 -0
- healthdatalayer/repositories/client_repositories/profession_repository.py +70 -0
- healthdatalayer/repositories/client_repositories/px_repository.py +210 -0
- healthdatalayer/repositories/collaborator_repositories/__init__.py +0 -0
- healthdatalayer/repositories/collaborator_repositories/collaborator_repository.py +150 -0
- healthdatalayer/repositories/collaborator_repositories/collaborator_type_repository.py +69 -0
- healthdatalayer/repositories/collaborator_repositories/speciality_repository.py +75 -0
- healthdatalayer/repositories/infraestructure_repositories/__init__.py +0 -0
- healthdatalayer/repositories/infraestructure_repositories/area_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/branch_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/bridge_repository.py +80 -0
- healthdatalayer/repositories/infraestructure_repositories/floor_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/room_repository.py +69 -0
- healthdatalayer/repositories/infraestructure_repositories/system_repository.py +69 -0
- healthdatalayer/repositories/lab_repositories/__init__.py +0 -0
- healthdatalayer/repositories/lab_repositories/measure_lab_repository.py +80 -0
- healthdatalayer/repositories/lab_repositories/medical_lab_repository.py +254 -0
- healthdatalayer/repositories/medical_visit_repositories/__init__.py +0 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_repository.py +63 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +92 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_recipe_repository.py +70 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_repository.py +63 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_recipe_visit_repository.py +93 -0
- healthdatalayer/repositories/medical_visit_repositories/medical_visit_repository.py +110 -0
- healthdatalayer/repositories/medical_visit_repositories/organ_system_review_repository.py +89 -0
- healthdatalayer/repositories/medical_visit_repositories/physical_exam_repository.py +89 -0
- healthdatalayer/repositories/medical_visit_repositories/visit_triage_repository.py +89 -0
- healthdatalayer/repositories/user_repositories/__init__.py +0 -0
- healthdatalayer/repositories/user_repositories/permission_repository.py +238 -0
- healthdatalayer/repositories/user_repositories/role_repository.py +174 -0
- healthdatalayer/repositories/user_repositories/user_repository.py +251 -0
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.2.0.dist-info}/METADATA +2 -2
- healthdatalayer-1.2.0.dist-info/RECORD +94 -0
- healthdatalayer-1.2.0.dist-info/top_level.txt +1 -0
- healthdatalayer-1.0.1.dist-info/RECORD +0 -10
- healthdatalayer-1.0.1.dist-info/top_level.txt +0 -3
- {config → healthdatalayer}/__init__.py +0 -0
- {config → healthdatalayer/config}/config.py +0 -0
- {config → healthdatalayer/config}/db.py +0 -0
- {config → healthdatalayer/config}/vault.py +0 -0
- {models → healthdatalayer/models}/__init__.py +0 -0
- {repositories → healthdatalayer/repositories}/__init__.py +0 -0
- {healthdatalayer-1.0.1.dist-info → healthdatalayer-1.2.0.dist-info}/WHEEL +0 -0
|
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
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
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 MedicalVisit
|
|
6
|
+
from config.db import engines, get_session
|
|
7
|
+
|
|
8
|
+
class MedicalVisitRepository:
|
|
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_visit: MedicalVisit) -> MedicalVisit:
|
|
15
|
+
with get_session(self.tenant) as session:
|
|
16
|
+
session.add(medical_visit)
|
|
17
|
+
session.commit()
|
|
18
|
+
session.refresh(medical_visit)
|
|
19
|
+
return medical_visit
|
|
20
|
+
|
|
21
|
+
def get_by_id_command(self, medical_visit_id: UUID, load_relations: bool = False) -> Optional[MedicalVisit]:
|
|
22
|
+
with get_session(self.tenant) as session:
|
|
23
|
+
|
|
24
|
+
if load_relations:
|
|
25
|
+
statement = select(MedicalVisit).where(MedicalVisit.medical_visit_id == medical_visit_id).options(
|
|
26
|
+
joinedload(MedicalVisit.client),
|
|
27
|
+
joinedload(MedicalVisit.collaborator),
|
|
28
|
+
joinedload(MedicalVisit.speciality),
|
|
29
|
+
selectinload(MedicalVisit.medical_diagnosis_visits),
|
|
30
|
+
selectinload(MedicalVisit.medical_recipe_visits),
|
|
31
|
+
selectinload(MedicalVisit.organ_system_reviews),
|
|
32
|
+
selectinload(MedicalVisit.physical_exams)
|
|
33
|
+
)
|
|
34
|
+
medical_visit = session.exec(statement).first()
|
|
35
|
+
|
|
36
|
+
return medical_visit
|
|
37
|
+
else:
|
|
38
|
+
return session.get(MedicalVisit, medical_visit_id)
|
|
39
|
+
|
|
40
|
+
def list_all_command(self, active_only: bool = True, load_relations: bool = False)->List[MedicalVisit]:
|
|
41
|
+
with get_session(self.tenant) as session:
|
|
42
|
+
statement = select(MedicalVisit)
|
|
43
|
+
|
|
44
|
+
if load_relations:
|
|
45
|
+
|
|
46
|
+
statement = select(MedicalVisit).options(
|
|
47
|
+
joinedload(MedicalVisit.client),
|
|
48
|
+
joinedload(MedicalVisit.collaborator),
|
|
49
|
+
joinedload(MedicalVisit.speciality),
|
|
50
|
+
selectinload(MedicalVisit.medical_diagnosis_visits),
|
|
51
|
+
selectinload(MedicalVisit.medical_recipe_visits),
|
|
52
|
+
selectinload(MedicalVisit.organ_system_reviews),
|
|
53
|
+
selectinload(MedicalVisit.physical_exams)
|
|
54
|
+
)
|
|
55
|
+
if active_only:
|
|
56
|
+
statement = statement.where(MedicalVisit.is_active == True)
|
|
57
|
+
medical_visits = session.exec(statement).all()
|
|
58
|
+
|
|
59
|
+
return medical_visits
|
|
60
|
+
|
|
61
|
+
statement = select(MedicalVisit)
|
|
62
|
+
return session.exec(statement).all()
|
|
63
|
+
|
|
64
|
+
def get_by_client_id_command(self, client_id: UUID, active_only: bool = True, load_relations: bool = False) -> List[MedicalVisit]:
|
|
65
|
+
with get_session(self.tenant) as session:
|
|
66
|
+
statement = select(MedicalVisit).where(MedicalVisit.client_id == client_id)
|
|
67
|
+
if active_only:
|
|
68
|
+
statement = statement.where(MedicalVisit.is_active == True)
|
|
69
|
+
if load_relations:
|
|
70
|
+
statement = statement.options(
|
|
71
|
+
joinedload(MedicalVisit.client),
|
|
72
|
+
joinedload(MedicalVisit.collaborator),
|
|
73
|
+
joinedload(MedicalVisit.speciality),
|
|
74
|
+
selectinload(MedicalVisit.medical_diagnosis_visits),
|
|
75
|
+
selectinload(MedicalVisit.medical_recipe_visits),
|
|
76
|
+
selectinload(MedicalVisit.organ_system_reviews),
|
|
77
|
+
selectinload(MedicalVisit.physical_exams)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
medical_visits = session.exec(statement).all()
|
|
81
|
+
return medical_visits
|
|
82
|
+
|
|
83
|
+
def update_command(self, medical_visit: MedicalVisit) -> MedicalVisit:
|
|
84
|
+
with get_session(self.tenant) as session:
|
|
85
|
+
existing_medical_visit = session.get(MedicalVisit, medical_visit.medical_visit_id)
|
|
86
|
+
if not existing_medical_visit:
|
|
87
|
+
raise ValueError(f"medical_visit with id {medical_visit.medical_visit_id} does not exist")
|
|
88
|
+
|
|
89
|
+
for key, value in medical_visit.dict(exclude_unset=True).items():
|
|
90
|
+
setattr(existing_medical_visit, key, value)
|
|
91
|
+
|
|
92
|
+
bd_medical_visit = session.merge(existing_medical_visit)
|
|
93
|
+
session.commit()
|
|
94
|
+
session.refresh(bd_medical_visit)
|
|
95
|
+
return bd_medical_visit
|
|
96
|
+
|
|
97
|
+
def delete_command(self, medical_visit_id: UUID, soft_delete: bool = False)->None:
|
|
98
|
+
with get_session(self.tenant) as session:
|
|
99
|
+
existing_bridge = session.get(MedicalVisit, medical_visit_id)
|
|
100
|
+
if not existing_bridge:
|
|
101
|
+
raise ValueError(f"MedicalVisit with id {medical_visit_id} does not exist")
|
|
102
|
+
|
|
103
|
+
if soft_delete:
|
|
104
|
+
existing_bridge.is_active = False
|
|
105
|
+
session.add(existing_bridge)
|
|
106
|
+
else:
|
|
107
|
+
session.delete(existing_bridge)
|
|
108
|
+
|
|
109
|
+
session.commit()
|
|
110
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
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 OrganSystemReview
|
|
6
|
+
from models import MedicalVisit
|
|
7
|
+
from config.db import engines, get_session
|
|
8
|
+
|
|
9
|
+
class OrganSystemReviewRepository:
|
|
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, organ_system_review: OrganSystemReview) -> OrganSystemReview:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(organ_system_review)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(organ_system_review)
|
|
20
|
+
return organ_system_review
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, organ_system_review_id: UUID, load_relations: bool = False) -> Optional[OrganSystemReview]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
|
|
25
|
+
if load_relations:
|
|
26
|
+
statement = select(OrganSystemReview).where(OrganSystemReview.organ_system_review_id == organ_system_review_id).options(
|
|
27
|
+
joinedload(OrganSystemReview.medical_visit)
|
|
28
|
+
)
|
|
29
|
+
organ_system_review = session.exec(statement).first()
|
|
30
|
+
|
|
31
|
+
return organ_system_review
|
|
32
|
+
else:
|
|
33
|
+
return session.get(OrganSystemReview, organ_system_review_id)
|
|
34
|
+
|
|
35
|
+
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) ->Optional[OrganSystemReview]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
|
|
38
|
+
statement = select(OrganSystemReview).where(OrganSystemReview.medical_visit_id == medical_visit_id)
|
|
39
|
+
if load_relations:
|
|
40
|
+
statement = statement.options(
|
|
41
|
+
joinedload(OrganSystemReview.medical_visit)
|
|
42
|
+
)
|
|
43
|
+
organ_system_review = session.exec(statement).first()
|
|
44
|
+
|
|
45
|
+
return organ_system_review
|
|
46
|
+
|
|
47
|
+
def get_all_command(self, active_only: bool = True,load_related: bool = False) -> List[OrganSystemReview]:
|
|
48
|
+
with get_session(self.tenant) as session:
|
|
49
|
+
|
|
50
|
+
statement = select(OrganSystemReview)
|
|
51
|
+
|
|
52
|
+
if load_related:
|
|
53
|
+
statement = select(OrganSystemReview).options(
|
|
54
|
+
selectinload(OrganSystemReview.medical_visit)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if active_only:
|
|
58
|
+
statement = statement.where(OrganSystemReview.is_active == True)
|
|
59
|
+
organ_system_review = session.exec(statement).all()
|
|
60
|
+
|
|
61
|
+
return organ_system_review
|
|
62
|
+
|
|
63
|
+
def update_command(self, organ_system_review: OrganSystemReview) -> OrganSystemReview:
|
|
64
|
+
with get_session(self.tenant) as session:
|
|
65
|
+
existing_organ_system_review = session.get(OrganSystemReview, organ_system_review.organ_system_review_id)
|
|
66
|
+
if not existing_organ_system_review:
|
|
67
|
+
raise ValueError(f"triage with id {organ_system_review.organ_system_review_id} does not exist")
|
|
68
|
+
|
|
69
|
+
for key, value in organ_system_review.dict(exclude_unset=True).items():
|
|
70
|
+
setattr(existing_organ_system_review, key, value)
|
|
71
|
+
|
|
72
|
+
bd_organ_system_review = session.merge(existing_organ_system_review)
|
|
73
|
+
session.commit()
|
|
74
|
+
session.refresh(bd_organ_system_review)
|
|
75
|
+
return bd_organ_system_review
|
|
76
|
+
|
|
77
|
+
def delete_command(self, organ_system_review_id: UUID, soft_delete: bool = False)->None:
|
|
78
|
+
with get_session(self.tenant) as session:
|
|
79
|
+
existing_organ_system_review = session.get(MedicalVisit, organ_system_review_id)
|
|
80
|
+
if not existing_organ_system_review:
|
|
81
|
+
raise ValueError(f"MedicalVisit with id {organ_system_review_id} does not exist")
|
|
82
|
+
|
|
83
|
+
if soft_delete:
|
|
84
|
+
existing_organ_system_review.is_active = False
|
|
85
|
+
session.add(existing_organ_system_review)
|
|
86
|
+
else:
|
|
87
|
+
session.delete(existing_organ_system_review)
|
|
88
|
+
|
|
89
|
+
session.commit()
|
|
@@ -0,0 +1,89 @@
|
|
|
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 PhysicalExam
|
|
6
|
+
from models import MedicalVisit
|
|
7
|
+
from config.db import engines, get_session
|
|
8
|
+
|
|
9
|
+
class PhysicalExamRepository:
|
|
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, physical_exam: PhysicalExam) -> PhysicalExam:
|
|
16
|
+
with get_session(self.tenant) as session:
|
|
17
|
+
session.add(physical_exam)
|
|
18
|
+
session.commit()
|
|
19
|
+
session.refresh(physical_exam)
|
|
20
|
+
return physical_exam
|
|
21
|
+
|
|
22
|
+
def get_by_id_command(self, physical_exam_id: UUID, load_relations: bool = False) -> Optional[PhysicalExam]:
|
|
23
|
+
with get_session(self.tenant) as session:
|
|
24
|
+
|
|
25
|
+
if load_relations:
|
|
26
|
+
statement = select(PhysicalExam).where(PhysicalExam.physical_exam_id == physical_exam_id).options(
|
|
27
|
+
joinedload(PhysicalExam.medical_visit)
|
|
28
|
+
)
|
|
29
|
+
physical_exam = session.exec(statement).first()
|
|
30
|
+
|
|
31
|
+
return physical_exam
|
|
32
|
+
else:
|
|
33
|
+
return session.get(PhysicalExam, physical_exam_id)
|
|
34
|
+
|
|
35
|
+
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) ->Optional[PhysicalExam]:
|
|
36
|
+
with get_session(self.tenant) as session:
|
|
37
|
+
|
|
38
|
+
statement = select(PhysicalExam).where(PhysicalExam.medical_visit_id == medical_visit_id)
|
|
39
|
+
if load_relations:
|
|
40
|
+
statement = statement.options(
|
|
41
|
+
joinedload(PhysicalExam.medical_visit)
|
|
42
|
+
)
|
|
43
|
+
physical_exam = session.exec(statement).first()
|
|
44
|
+
|
|
45
|
+
return physical_exam
|
|
46
|
+
|
|
47
|
+
def get_all_command(self, active_only: bool = True,load_related: bool = False) -> List[PhysicalExam]:
|
|
48
|
+
with get_session(self.tenant) as session:
|
|
49
|
+
|
|
50
|
+
statement = select(PhysicalExam)
|
|
51
|
+
|
|
52
|
+
if load_related:
|
|
53
|
+
statement = select(PhysicalExam).options(
|
|
54
|
+
selectinload(PhysicalExam.medical_visit)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if active_only:
|
|
58
|
+
statement = statement.where(PhysicalExam.is_active == True)
|
|
59
|
+
physical_exam = session.exec(statement).all()
|
|
60
|
+
|
|
61
|
+
return physical_exam
|
|
62
|
+
|
|
63
|
+
def update_command(self, physical_exam: PhysicalExam) -> PhysicalExam:
|
|
64
|
+
with get_session(self.tenant) as session:
|
|
65
|
+
existing_physical_exam = session.get(PhysicalExam, physical_exam.physical_exam_id)
|
|
66
|
+
if not existing_physical_exam:
|
|
67
|
+
raise ValueError(f"triage with id {physical_exam.physical_exam_id} does not exist")
|
|
68
|
+
|
|
69
|
+
for key, value in physical_exam.dict(exclude_unset=True).items():
|
|
70
|
+
setattr(existing_physical_exam, key, value)
|
|
71
|
+
|
|
72
|
+
bd_physical_exam = session.merge(existing_physical_exam)
|
|
73
|
+
session.commit()
|
|
74
|
+
session.refresh(bd_physical_exam)
|
|
75
|
+
return bd_physical_exam
|
|
76
|
+
|
|
77
|
+
def delete_command(self, physical_exam_id: UUID, soft_delete: bool = False)->None:
|
|
78
|
+
with get_session(self.tenant) as session:
|
|
79
|
+
existing_physical_exam = session.get(MedicalVisit, physical_exam_id)
|
|
80
|
+
if not existing_physical_exam:
|
|
81
|
+
raise ValueError(f"MedicalVisit with id {physical_exam_id} does not exist")
|
|
82
|
+
|
|
83
|
+
if soft_delete:
|
|
84
|
+
existing_physical_exam.is_active = False
|
|
85
|
+
session.add(existing_physical_exam)
|
|
86
|
+
else:
|
|
87
|
+
session.delete(existing_physical_exam)
|
|
88
|
+
|
|
89
|
+
session.commit()
|