healthdatalayer 1.4.3__py3-none-any.whl → 1.7.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/dtos/__init__.py +3 -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/dtos/medical_visit/recipe_dto.py +16 -0
- healthdatalayer/models/__init__.py +3 -0
- healthdatalayer/models/client/city.py +11 -0
- healthdatalayer/models/client/px.py +10 -3
- healthdatalayer/models/client/state.py +9 -0
- healthdatalayer/models/medical_visit/medical_drug.py +2 -6
- healthdatalayer/models/medical_visit/medical_drug_recipe.py +10 -3
- healthdatalayer/models/medical_visit/medical_recipe_visit.py +3 -3
- healthdatalayer/models/medical_visit/medical_visit.py +5 -3
- healthdatalayer/models/medical_visit/status_visit_enum.py +8 -0
- healthdatalayer/repositories/client_repositories/address_repository.py +32 -2
- healthdatalayer/repositories/client_repositories/px_repository.py +48 -1
- healthdatalayer/repositories/collaborator_repositories/collaborator_repository.py +49 -2
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_repository.py +36 -1
- healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py +20 -3
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_recipe_repository.py +4 -3
- healthdatalayer/repositories/medical_visit_repositories/medical_drug_repository.py +17 -2
- healthdatalayer/repositories/medical_visit_repositories/medical_recipe_visit_repository.py +58 -6
- healthdatalayer/repositories/medical_visit_repositories/medical_visit_repository.py +403 -4
- healthdatalayer/repositories/medical_visit_repositories/organ_system_review_repository.py +1 -1
- healthdatalayer/repositories/medical_visit_repositories/physical_exam_repository.py +1 -1
- healthdatalayer/repositories/medical_visit_repositories/visit_triage_repository.py +8 -2
- {healthdatalayer-1.4.3.dist-info → healthdatalayer-1.7.0.dist-info}/METADATA +1 -1
- {healthdatalayer-1.4.3.dist-info → healthdatalayer-1.7.0.dist-info}/RECORD +31 -22
- {healthdatalayer-1.4.3.dist-info → healthdatalayer-1.7.0.dist-info}/WHEEL +0 -0
- {healthdatalayer-1.4.3.dist-info → healthdatalayer-1.7.0.dist-info}/top_level.txt +0 -0
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import List
|
|
3
|
+
from datetime import time
|
|
4
|
+
|
|
5
|
+
class ScheduleCollaboratorDTO(BaseModel):
|
|
6
|
+
|
|
7
|
+
available_schedules: List[time] = Field(default_factory=list)
|
|
8
|
+
busy_schedules: List[time] = Field(default_factory=list)
|
|
9
|
+
|
|
10
|
+
class Config:
|
|
11
|
+
json_encoders = {
|
|
12
|
+
time: lambda v: v.strftime('%H:%M')
|
|
13
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
from datetime import date, datetime, time
|
|
4
|
+
|
|
5
|
+
class MedicalCertificateDTO(BaseModel):
|
|
6
|
+
sys: Optional[str] = None
|
|
7
|
+
stablishment: Optional[str] = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
medical_record_number: Optional[str] = None
|
|
11
|
+
number_his: Optional[str] = None
|
|
12
|
+
last_name: Optional[str] = None
|
|
13
|
+
first_name: Optional[str] = None
|
|
14
|
+
sex: Optional[str] = None
|
|
15
|
+
age: Optional[int] = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
service: Optional[str] = None
|
|
19
|
+
speciality: Optional[str] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
year_visit: Optional[int] = None
|
|
23
|
+
month_visit: Optional[int] = None
|
|
24
|
+
day_visit: Optional[int] = None
|
|
25
|
+
hour_start: Optional[time] = None
|
|
26
|
+
hour_end: Optional[time] = None
|
|
27
|
+
visit_date_spanish: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
rest: Optional[bool] = None
|
|
31
|
+
rest_hours: Optional[float] = None
|
|
32
|
+
rest_date_start: Optional[datetime] = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
year_rest_start: Optional[int] = None
|
|
36
|
+
month_rest_start: Optional[int] = None
|
|
37
|
+
day_rest_start: Optional[int] = None
|
|
38
|
+
rest_date_start_spanish: Optional[str] = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
rest_date_end: Optional[datetime] = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
year_rest_end: Optional[int] = None
|
|
45
|
+
month_rest_end: Optional[int] = None
|
|
46
|
+
day_rest_end: Optional[int] = None
|
|
47
|
+
rest_date_end_spanish: Optional[str] = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
doctor_name: Optional[str] = None
|
|
51
|
+
doctor_ruc: Optional[str] = None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class DiagnosisDTO(BaseModel):
|
|
55
|
+
name_diagnosis: str
|
|
56
|
+
cie_10_code: Optional[str] = None
|
|
57
|
+
|
|
58
|
+
class MedicalDiagnosesDTO(BaseModel):
|
|
59
|
+
diagnoses: List[DiagnosisDTO]
|
|
60
|
+
|
|
61
|
+
class Config:
|
|
62
|
+
from_attributes = True
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
from datetime import date, datetime, time
|
|
4
|
+
|
|
5
|
+
class HeaderRecipe(BaseModel):
|
|
6
|
+
visit_date : Optional[datetime] = None
|
|
7
|
+
name_doctor : Optional[str] = None
|
|
8
|
+
ruc : Optional[str] = None
|
|
9
|
+
code : Optional[str] = None
|
|
10
|
+
first_name_px : Optional[str] = None
|
|
11
|
+
last_name_px : Optional[str] = None
|
|
12
|
+
|
|
13
|
+
class RecipeMedicalDrugData(BaseModel):
|
|
14
|
+
drug_name : Optional[str] = None
|
|
15
|
+
comment: Optional[str] = None
|
|
16
|
+
quantity :Optional[int] = None
|
|
@@ -24,6 +24,8 @@ from .client.pathological_history import PathologicalHistory
|
|
|
24
24
|
from .client.pet import Pet
|
|
25
25
|
from .client.profession import Profession
|
|
26
26
|
from .client.px import Px
|
|
27
|
+
from .client.state import State
|
|
28
|
+
from .client.city import City
|
|
27
29
|
|
|
28
30
|
from .collaborator.collaborator_speciality import CollaboratorSpeciality
|
|
29
31
|
from .collaborator.collaborator import Collaborator
|
|
@@ -44,6 +46,7 @@ from .medical_visit.organ_system_review import OrganSystemReview
|
|
|
44
46
|
from .medical_visit.physical_exam import PhysicalExam
|
|
45
47
|
from .medical_visit.visit_triage import VisitTriage
|
|
46
48
|
from .medical_visit.medical_visit import MedicalVisit
|
|
49
|
+
from .medical_visit.status_visit_enum import StatusVisitEnum
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from sqlmodel import SQLModel,Field
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
class City(SQLModel,table=True):
|
|
6
|
+
__tablename__ = "city"
|
|
7
|
+
|
|
8
|
+
city_id:uuid.UUID=Field(default_factory=uuid.uuid4,primary_key=True)
|
|
9
|
+
name:str
|
|
10
|
+
state_id: Optional[uuid.UUID] = Field(default=None, foreign_key="state.state_id")
|
|
11
|
+
is_active: bool = Field(default=True)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional, TYPE_CHECKING
|
|
1
|
+
from typing import Optional, TYPE_CHECKING, List
|
|
2
2
|
from sqlmodel import Field, Relationship
|
|
3
3
|
import uuid
|
|
4
4
|
|
|
@@ -7,6 +7,7 @@ from healthdatalayer.models import Client
|
|
|
7
7
|
|
|
8
8
|
if TYPE_CHECKING:
|
|
9
9
|
from healthdatalayer.models import ClientLab
|
|
10
|
+
from healthdatalayer.models import PathologicalHistory
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class Px(Client, table=True):
|
|
@@ -15,14 +16,20 @@ class Px(Client, table=True):
|
|
|
15
16
|
last_name: str
|
|
16
17
|
phone: Optional[str] = None
|
|
17
18
|
email: Optional[str] = None
|
|
18
|
-
|
|
19
|
+
medical_record_number: Optional[str] = None
|
|
19
20
|
marriage_status_id: Optional[uuid.UUID] = Field(default=None, foreign_key="marriage_status.marriage_status_id")
|
|
20
21
|
profession_id: Optional[uuid.UUID] = Field(default=None, foreign_key="profession.profession_id")
|
|
21
22
|
education_id: Optional[uuid.UUID] = Field(default=None, foreign_key="education.education_id")
|
|
22
23
|
user_id: Optional[uuid.UUID] = Field(default=None, foreign_key="user.user_id")
|
|
24
|
+
nationality_id: Optional[uuid.UUID] = Field(default=None, foreign_key="nationality.nationality_id")
|
|
25
|
+
pathological_histories: List["PathologicalHistory"] = Relationship(
|
|
26
|
+
back_populates="client",
|
|
27
|
+
sa_relationship_kwargs={"lazy": "selectin"}
|
|
28
|
+
)
|
|
23
29
|
|
|
24
30
|
Px.marriage_status = Relationship()
|
|
25
31
|
Px.profession = Relationship()
|
|
26
32
|
Px.education = Relationship()
|
|
27
33
|
Px.user = Relationship()
|
|
28
|
-
Px.
|
|
34
|
+
Px.nationality = Relationship()
|
|
35
|
+
Px.medical_labs = Relationship(back_populates="pxs", link_model="ClientLab")
|
|
@@ -5,8 +5,7 @@ from sqlmodel import SQLModel, Field, Relationship
|
|
|
5
5
|
|
|
6
6
|
from healthdatalayer.models.medical_visit.medical_drug_recipe import MedicalDrugRecipe
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
from healthdatalayer.models.medical_visit.medical_recipe_visit import MedicalRecipeVisit
|
|
8
|
+
|
|
10
9
|
|
|
11
10
|
class MedicalDrug(SQLModel, table=True):
|
|
12
11
|
__tablename__ = "medical_drug"
|
|
@@ -21,7 +20,4 @@ class MedicalDrug(SQLModel, table=True):
|
|
|
21
20
|
|
|
22
21
|
is_active: bool = Field(default=True)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
back_populates="medical_drugs",
|
|
26
|
-
link_model=MedicalDrugRecipe
|
|
27
|
-
)
|
|
23
|
+
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import uuid
|
|
2
2
|
from datetime import datetime
|
|
3
|
-
from typing import Optional
|
|
4
|
-
from sqlmodel import SQLModel, Field
|
|
3
|
+
from typing import Optional, TYPE_CHECKING
|
|
4
|
+
from sqlmodel import SQLModel, Field, Relationship
|
|
5
|
+
|
|
6
|
+
#from healthdatalayer.models import MedicalDrug
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from healthdatalayer.models import MedicalRecipeVisit,MedicalDrug
|
|
5
9
|
|
|
6
10
|
class MedicalDrugRecipe(SQLModel, table=True):
|
|
7
11
|
__tablename__ = "medical_drug_recipe"
|
|
@@ -9,10 +13,13 @@ class MedicalDrugRecipe(SQLModel, table=True):
|
|
|
9
13
|
medical_drug_recipe_id:uuid.UUID=Field(default_factory=uuid.uuid4,primary_key=True)
|
|
10
14
|
|
|
11
15
|
medical_drug_id: uuid.UUID = Field(foreign_key="medical_drug.medical_drug_id", primary_key=True)
|
|
16
|
+
medical_drug: Optional["MedicalDrug"] = Relationship()
|
|
12
17
|
medical_recipe_visit_id: uuid.UUID = Field(foreign_key="medical_recipe_visit.medical_recipe_visit_id", primary_key=True)
|
|
18
|
+
medical_recipe_visit: Optional["MedicalRecipeVisit"] = Relationship()
|
|
13
19
|
|
|
14
20
|
quantity:int
|
|
15
21
|
suplied:bool
|
|
22
|
+
comment:Optional[str] = Field(default=None)
|
|
16
23
|
suplied_date: Optional[datetime] = Field(default=None)
|
|
17
|
-
|
|
24
|
+
|
|
18
25
|
is_active: bool = Field(default=True)
|
|
@@ -22,7 +22,7 @@ class MedicalRecipeVisit(SQLModel, table=True):
|
|
|
22
22
|
|
|
23
23
|
is_active: bool = Field(default=True)
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
back_populates="
|
|
27
|
-
|
|
25
|
+
medical_drug_recipes: List["MedicalDrugRecipe"] = Relationship(
|
|
26
|
+
back_populates="medical_recipe_visit",
|
|
27
|
+
sa_relationship_kwargs={"lazy": "selectin"}
|
|
28
28
|
)
|
|
@@ -2,9 +2,10 @@ import uuid
|
|
|
2
2
|
from datetime import datetime
|
|
3
3
|
from typing import Optional, List, TYPE_CHECKING
|
|
4
4
|
from sqlmodel import SQLModel, Field, Relationship
|
|
5
|
+
from sqlalchemy import Column, Enum as SqlEnum
|
|
5
6
|
|
|
6
7
|
from healthdatalayer.models import Collaborator
|
|
7
|
-
|
|
8
|
+
from healthdatalayer.models.medical_visit.status_visit_enum import StatusVisitEnum
|
|
8
9
|
from healthdatalayer.models import Speciality
|
|
9
10
|
from healthdatalayer.models import BridgeAreaFloorBranch
|
|
10
11
|
if TYPE_CHECKING:
|
|
@@ -28,16 +29,17 @@ class MedicalVisit(SQLModel, table=True):
|
|
|
28
29
|
speciality_id:Optional[uuid.UUID]=Field(default=None,foreign_key="speciality.speciality_id")
|
|
29
30
|
speciality: Optional[Speciality] = Relationship()
|
|
30
31
|
|
|
31
|
-
status_visit:
|
|
32
|
+
status_visit: StatusVisitEnum = Field(sa_column=Column(SqlEnum(StatusVisitEnum, native_enum=False), nullable=False))
|
|
32
33
|
|
|
33
34
|
next_followup_visit_id:Optional[uuid.UUID]=Field(default=None,foreign_key="medical_visit.medical_visit_id")
|
|
34
35
|
|
|
35
|
-
overall_diagnosis:str
|
|
36
|
+
overall_diagnosis:Optional[str]=Field(default=None)
|
|
36
37
|
|
|
37
38
|
bridge_area_floor_branch_id:Optional[uuid.UUID]=Field(default=None,foreign_key="bridge_area_floor_branch.bridge_area_floor_branch_id")
|
|
38
39
|
bridge_area_floor_branch: Optional[BridgeAreaFloorBranch] = Relationship()
|
|
39
40
|
|
|
40
41
|
reason_visit:Optional[str]=Field(default=None)
|
|
42
|
+
current_illness: Optional[str]=Field(default=None)
|
|
41
43
|
rest: Optional[bool] = Field(default=None)
|
|
42
44
|
rest_hours: Optional[int] = Field(default=None)
|
|
43
45
|
rest_date_start: Optional[datetime] = Field(default=None)
|
|
@@ -2,7 +2,7 @@ from typing import Optional, List
|
|
|
2
2
|
from uuid import UUID
|
|
3
3
|
from sqlmodel import select
|
|
4
4
|
|
|
5
|
-
from healthdatalayer.models import Address
|
|
5
|
+
from healthdatalayer.models import Address, City, State
|
|
6
6
|
from healthdatalayer.config.db import engines, get_session
|
|
7
7
|
|
|
8
8
|
class AddressRepository:
|
|
@@ -61,4 +61,34 @@ class AddressRepository:
|
|
|
61
61
|
session.delete(db_address)
|
|
62
62
|
|
|
63
63
|
session.commit()
|
|
64
|
-
return True
|
|
64
|
+
return True
|
|
65
|
+
|
|
66
|
+
def list_all_state_command(self, active_only: bool = True) -> List[Address]:
|
|
67
|
+
with get_session(self.tenant) as session:
|
|
68
|
+
statement = select(State)
|
|
69
|
+
|
|
70
|
+
if active_only:
|
|
71
|
+
statement = statement.where(State.is_active == True)
|
|
72
|
+
|
|
73
|
+
results = session.exec(statement)
|
|
74
|
+
return results.all()
|
|
75
|
+
|
|
76
|
+
def list_all_city_command(self, active_only: bool = True) -> List[Address]:
|
|
77
|
+
with get_session(self.tenant) as session:
|
|
78
|
+
statement = select(City)
|
|
79
|
+
|
|
80
|
+
if active_only:
|
|
81
|
+
statement = statement.where(City.is_active == True)
|
|
82
|
+
|
|
83
|
+
results = session.exec(statement)
|
|
84
|
+
return results.all()
|
|
85
|
+
|
|
86
|
+
def list_city_by_state_id_command(self,state_id: UUID, active_only: bool = True) -> List[Address]:
|
|
87
|
+
with get_session(self.tenant) as session:
|
|
88
|
+
statement = select(City).where(City.state_id == state_id)
|
|
89
|
+
|
|
90
|
+
if active_only:
|
|
91
|
+
statement = statement.where(State.is_active == True)
|
|
92
|
+
|
|
93
|
+
results = session.exec(statement)
|
|
94
|
+
return results.all()
|
|
@@ -52,6 +52,17 @@ class PxRepository:
|
|
|
52
52
|
from healthdatalayer.models.user.user import User
|
|
53
53
|
user_obj = session.get(User, px.user_id)
|
|
54
54
|
object.__setattr__(px, 'user', user_obj)
|
|
55
|
+
|
|
56
|
+
if px.nationality_id:
|
|
57
|
+
from healthdatalayer.models.client.nationality import Nationality
|
|
58
|
+
user_obj = session.get(Nationality, px.nationality_id)
|
|
59
|
+
object.__setattr__(px, 'nationality', user_obj)
|
|
60
|
+
|
|
61
|
+
from healthdatalayer.models.client.pathological_history import PathologicalHistory
|
|
62
|
+
statement = select(PathologicalHistory).where(PathologicalHistory.client_id == px_id)
|
|
63
|
+
pathological_his = session.exec(statement).all()
|
|
64
|
+
if pathological_his:
|
|
65
|
+
object.__setattr__(px, 'pathological_histories',pathological_his)
|
|
55
66
|
|
|
56
67
|
return px
|
|
57
68
|
|
|
@@ -90,6 +101,19 @@ class PxRepository:
|
|
|
90
101
|
from healthdatalayer.models.user.user import User
|
|
91
102
|
user_obj = session.get(User, px.user_id)
|
|
92
103
|
object.__setattr__(px, 'user', user_obj)
|
|
104
|
+
|
|
105
|
+
if px.nationality_id:
|
|
106
|
+
from healthdatalayer.models.client.nationality import Nationality
|
|
107
|
+
user_obj = session.get(Nationality, px.nationality_id)
|
|
108
|
+
object.__setattr__(px, 'nationality', user_obj)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
from healthdatalayer.models.client.pathological_history import PathologicalHistory
|
|
112
|
+
statement = select(PathologicalHistory).where(PathologicalHistory.client_id == px.client_id)
|
|
113
|
+
pathological_his = session.exec(statement).all()
|
|
114
|
+
if pathological_his:
|
|
115
|
+
object.__setattr__(px, 'pathological_histories',pathological_his)
|
|
116
|
+
|
|
93
117
|
|
|
94
118
|
return px
|
|
95
119
|
|
|
@@ -134,7 +158,18 @@ class PxRepository:
|
|
|
134
158
|
from healthdatalayer.models.user.user import User
|
|
135
159
|
user_obj = session.get(User, px.user_id)
|
|
136
160
|
object.__setattr__(px, 'user', user_obj)
|
|
137
|
-
|
|
161
|
+
if px.nationality_id:
|
|
162
|
+
from healthdatalayer.models.client.nationality import Nationality
|
|
163
|
+
user_obj = session.get(Nationality, px.nationality_id)
|
|
164
|
+
object.__setattr__(px, 'nationality', user_obj)
|
|
165
|
+
|
|
166
|
+
from healthdatalayer.models.client.pathological_history import PathologicalHistory
|
|
167
|
+
statement = select(PathologicalHistory).where(PathologicalHistory.client_id == px.client_id)
|
|
168
|
+
pathological_his = session.exec(statement).all()
|
|
169
|
+
if pathological_his:
|
|
170
|
+
object.__setattr__(px, 'pathological_histories',pathological_his)
|
|
171
|
+
|
|
172
|
+
|
|
138
173
|
return results
|
|
139
174
|
|
|
140
175
|
def list_all_command(self, active_only: bool = True, load_relations: bool = False) -> List[Px]:
|
|
@@ -177,6 +212,18 @@ class PxRepository:
|
|
|
177
212
|
from healthdatalayer.models.user.user import User
|
|
178
213
|
user_obj = session.get(User, px.user_id)
|
|
179
214
|
object.__setattr__(px, 'user', user_obj)
|
|
215
|
+
|
|
216
|
+
if px.nationality_id:
|
|
217
|
+
from healthdatalayer.models.client.nationality import Nationality
|
|
218
|
+
user_obj = session.get(Nationality, px.nationality_id)
|
|
219
|
+
object.__setattr__(px, 'nationality', user_obj)
|
|
220
|
+
|
|
221
|
+
from healthdatalayer.models.client.pathological_history import PathologicalHistory
|
|
222
|
+
statement = select(PathologicalHistory).where(PathologicalHistory.client_id == px.client_id)
|
|
223
|
+
pathological_his = session.exec(statement).all()
|
|
224
|
+
if pathological_his:
|
|
225
|
+
object.__setattr__(px, 'pathological_histories',pathological_his)
|
|
226
|
+
|
|
180
227
|
|
|
181
228
|
return results
|
|
182
229
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
from datetime import date
|
|
1
2
|
from typing import Optional, List
|
|
2
3
|
from uuid import UUID
|
|
3
|
-
from sqlmodel import select, or_, join
|
|
4
|
+
from sqlmodel import select, or_, join, text
|
|
4
5
|
from sqlalchemy.orm import selectinload,joinedload
|
|
5
6
|
from healthdatalayer.models import Collaborator
|
|
6
7
|
from healthdatalayer.models import Speciality, CollaboratorSpeciality
|
|
8
|
+
from healthdatalayer.dtos import ScheduleCollaboratorDTO
|
|
7
9
|
from healthdatalayer.config.db import engines, get_session
|
|
8
10
|
|
|
9
11
|
class CollaboratorRepository:
|
|
@@ -147,4 +149,49 @@ class CollaboratorRepository:
|
|
|
147
149
|
session.commit()
|
|
148
150
|
session.refresh(collab)
|
|
149
151
|
|
|
150
|
-
return collab
|
|
152
|
+
return collab
|
|
153
|
+
|
|
154
|
+
def get_availability_schedules_command(self, visit_date: date, collaborator_id: str) -> ScheduleCollaboratorDTO:
|
|
155
|
+
|
|
156
|
+
with get_session(self.tenant) as session:
|
|
157
|
+
|
|
158
|
+
query = text("""
|
|
159
|
+
WITH horarios_generados AS (
|
|
160
|
+
SELECT horario::TIME as hora
|
|
161
|
+
FROM generate_series(
|
|
162
|
+
CAST(:fecha AS DATE)+ TIME '08:00:00',
|
|
163
|
+
CAST(:fecha AS DATE) + TIME '17:00:00',
|
|
164
|
+
INTERVAL '30 minutes'
|
|
165
|
+
) AS horario
|
|
166
|
+
),
|
|
167
|
+
horarios_ocupados AS (
|
|
168
|
+
SELECT t.visit_date::TIME as hora
|
|
169
|
+
FROM medical_visit t
|
|
170
|
+
WHERE t.visit_date::DATE = :fecha
|
|
171
|
+
AND t.collaborator_id = :colab_id
|
|
172
|
+
AND t.status_visit in ('AGENDADO','REAGENDADO')
|
|
173
|
+
)
|
|
174
|
+
SELECT
|
|
175
|
+
hg.hora,
|
|
176
|
+
CASE WHEN ho.hora IS NOT NULL THEN true ELSE false END as ocupado
|
|
177
|
+
FROM horarios_generados hg
|
|
178
|
+
LEFT JOIN horarios_ocupados ho ON hg.hora = ho.hora
|
|
179
|
+
ORDER BY hg.hora
|
|
180
|
+
""")
|
|
181
|
+
|
|
182
|
+
result = session.exec(query, params={"fecha": visit_date, "colab_id": collaborator_id})
|
|
183
|
+
|
|
184
|
+
availables = []
|
|
185
|
+
busy = []
|
|
186
|
+
|
|
187
|
+
for row in result.fetchall():
|
|
188
|
+
hour, is_busy = row[0], row[1]
|
|
189
|
+
if is_busy:
|
|
190
|
+
busy.append(hour)
|
|
191
|
+
else:
|
|
192
|
+
availables.append(hour)
|
|
193
|
+
|
|
194
|
+
return ScheduleCollaboratorDTO(
|
|
195
|
+
available_schedules=availables,
|
|
196
|
+
busy_schedules=busy
|
|
197
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import Optional, List
|
|
2
2
|
from uuid import UUID
|
|
3
|
-
from sqlmodel import select
|
|
3
|
+
from sqlmodel import select, or_
|
|
4
4
|
|
|
5
5
|
from healthdatalayer.models import MedicalDiagnosis
|
|
6
6
|
from healthdatalayer.config.db import engines, get_session
|
|
@@ -21,6 +21,41 @@ class MedicalDiagnosisRepository:
|
|
|
21
21
|
def get_by_id_command(self, medical_diagnosis_id: UUID) -> Optional[MedicalDiagnosis]:
|
|
22
22
|
with get_session(self.tenant) as session:
|
|
23
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
|
|
24
59
|
|
|
25
60
|
def list_all_command(self, active_only: bool = True) -> List[MedicalDiagnosis]:
|
|
26
61
|
with get_session(self.tenant) as session:
|
healthdatalayer/repositories/medical_visit_repositories/medical_diagnosis_visit_repository.py
CHANGED
|
@@ -33,10 +33,27 @@ class MedicalDiagnosisVisitRepository:
|
|
|
33
33
|
else:
|
|
34
34
|
return session.get(MedicalDiagnosisVisit, medical_diagnosis_visit_id)
|
|
35
35
|
|
|
36
|
-
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) ->
|
|
36
|
+
def get_by_medical_visit_id_command(self, medical_visit_id: UUID, load_relations: bool = False) ->List[MedicalDiagnosisVisit]:
|
|
37
37
|
with get_session(self.tenant) as session:
|
|
38
38
|
|
|
39
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
|
+
|
|
40
57
|
if load_relations:
|
|
41
58
|
statement = statement.options(
|
|
42
59
|
joinedload(MedicalDiagnosisVisit.medical_visit),
|
|
@@ -46,7 +63,7 @@ class MedicalDiagnosisVisitRepository:
|
|
|
46
63
|
|
|
47
64
|
return medical_diagnosis_visit
|
|
48
65
|
|
|
49
|
-
def
|
|
66
|
+
def list_all_command(self, active_only: bool = True,load_related: bool = False) -> List[MedicalDiagnosisVisit]:
|
|
50
67
|
with get_session(self.tenant) as session:
|
|
51
68
|
|
|
52
69
|
statement = select(MedicalDiagnosisVisit)
|
|
@@ -79,7 +96,7 @@ class MedicalDiagnosisVisitRepository:
|
|
|
79
96
|
|
|
80
97
|
def delete_command(self, medical_diagnosis_visit_id: UUID, soft_delete: bool = False)->None:
|
|
81
98
|
with get_session(self.tenant) as session:
|
|
82
|
-
existing_medical_diagnosis_visit = session.get(
|
|
99
|
+
existing_medical_diagnosis_visit = session.get(MedicalDiagnosisVisit, medical_diagnosis_visit_id)
|
|
83
100
|
if not existing_medical_diagnosis_visit:
|
|
84
101
|
raise ValueError(f"MedicalDiagnosisVisit with id {medical_diagnosis_visit_id} does not exist")
|
|
85
102
|
|
|
@@ -19,8 +19,8 @@ class MedicalDrugRecipeRepository:
|
|
|
19
19
|
|
|
20
20
|
def get_by_id_command(self, medical_drug_recipe_id: UUID) -> Optional[MedicalDrugRecipe]:
|
|
21
21
|
with get_session(self.tenant) as session:
|
|
22
|
-
|
|
23
|
-
return session.
|
|
22
|
+
statement = select(MedicalDrugRecipe).where(MedicalDrugRecipe.medical_drug_recipe_id == medical_drug_recipe_id)
|
|
23
|
+
return session.exec(statement).first()
|
|
24
24
|
|
|
25
25
|
def list_all_command(self, active_only: bool = True)->List[MedicalDrugRecipe]:
|
|
26
26
|
with get_session(self.tenant) as session:
|
|
@@ -56,7 +56,8 @@ class MedicalDrugRecipeRepository:
|
|
|
56
56
|
|
|
57
57
|
def delete_command(self, medical_drug_recipe_id: UUID, soft_delete: bool = True) -> bool:
|
|
58
58
|
with get_session(self.tenant) as session:
|
|
59
|
-
|
|
59
|
+
statement = select(MedicalDrugRecipe).where(MedicalDrugRecipe.medical_drug_recipe_id == medical_drug_recipe_id)
|
|
60
|
+
db_medical_drug_recipe = session.exec(statement).first()
|
|
60
61
|
if not db_medical_drug_recipe:
|
|
61
62
|
return False
|
|
62
63
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import Optional, List
|
|
2
2
|
from uuid import UUID
|
|
3
|
-
from sqlmodel import select
|
|
3
|
+
from sqlmodel import select,or_
|
|
4
4
|
|
|
5
5
|
from healthdatalayer.models import MedicalDrug
|
|
6
6
|
from healthdatalayer.config.db import engines, get_session
|
|
@@ -60,4 +60,19 @@ class MedicalDrugRepository:
|
|
|
60
60
|
session.delete(db_medical_drug)
|
|
61
61
|
|
|
62
62
|
session.commit()
|
|
63
|
-
return True
|
|
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
|