-
Notifications
You must be signed in to change notification settings - Fork 3
/
patient.py
87 lines (75 loc) · 2.4 KB
/
patient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import annotations
from welkin.models.assessment import AssessmentRecord, AssessmentRecords
from welkin.models.base import Collection, Resource
from welkin.models.care_plan import CarePlan
from welkin.models.cdt import CDT, CDTs
from welkin.models.chat import Chat, Chats, SearchChats
from welkin.models.document import (
DocumentSummaries,
DocumentSummary,
DocumentSummaryFile,
)
from welkin.models.email import Email, Emails
from welkin.models.encounter import Encounter, Encounters
from welkin.models.program import PatientProgram, PatientPrograms
from welkin.models.sms import SMS, SMSes
from welkin.pagination import PageableIterator
class Patient(Resource):
subresources = (
AssessmentRecord,
AssessmentRecords,
CarePlan,
CDT,
CDTs,
Chat,
Chats,
DocumentSummaries,
DocumentSummary,
DocumentSummaryFile,
Email,
Emails,
Encounter,
Encounters,
PatientProgram,
PatientPrograms,
SearchChats,
SMS,
SMSes,
)
def create(self):
return super().post(f"{self._client.instance}/patients")
def get(self, expand: bool | None = None):
_id = None
if hasattr(self, "id"):
_type = None
_id = self.id
elif hasattr(self, "externalId"):
_type = "EID"
_id = self.externalId
elif hasattr(self, "externalGuid"):
_type = "EGUID"
_id = self.externalGuid
elif hasattr(self, "mrn"):
_type = "MRN"
_id = self.mrn
return super().get(
f"{self._client.instance}/patients/{_id}",
params={
"type": _type,
expand: expand,
},
)
def update(self, **kwargs):
return super().patch(f"{self._client.instance}/patients/{self.id}", kwargs)
def delete(self):
return super().delete(f"{self._client.instance}/patients/{self.id}")
def __str__(self):
return f"{self.firstName} {self.lastName}"
class Patients(Collection):
resource = Patient
iterator = PageableIterator
def get(self, filter: dict | None = None, *args, **kwargs): # noqa: A002
# TODO: Add sort and query arguments.
return super().post(
f"{self._client.instance}/by-filter/patients", *args, json=filter, **kwargs
)