canvas 0.15.0__py3-none-any.whl → 0.16.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 canvas might be problematic. Click here for more details.

Files changed (46) hide show
  1. {canvas-0.15.0.dist-info → canvas-0.16.0.dist-info}/METADATA +2 -2
  2. {canvas-0.15.0.dist-info → canvas-0.16.0.dist-info}/RECORD +46 -32
  3. canvas_cli/templates/plugins/application/{{ cookiecutter.__project_slug }}/CANVAS_MANIFEST.json +6 -3
  4. canvas_cli/templates/plugins/application/{{ cookiecutter.__project_slug }}/applications/my_application.py +4 -1
  5. canvas_cli/utils/validators/manifest_schema.py +9 -2
  6. canvas_generated/messages/effects_pb2.py +2 -2
  7. canvas_generated/messages/effects_pb2.pyi +14 -0
  8. canvas_generated/messages/events_pb2.py +2 -2
  9. canvas_generated/messages/events_pb2.pyi +40 -0
  10. canvas_sdk/effects/launch_modal.py +14 -3
  11. canvas_sdk/handlers/action_button.py +33 -16
  12. canvas_sdk/templates/__init__.py +3 -0
  13. canvas_sdk/templates/tests/__init__.py +0 -0
  14. canvas_sdk/templates/tests/test_utils.py +43 -0
  15. canvas_sdk/templates/utils.py +44 -0
  16. canvas_sdk/v1/data/__init__.py +23 -1
  17. canvas_sdk/v1/data/allergy_intolerance.py +22 -2
  18. canvas_sdk/v1/data/appointment.py +56 -0
  19. canvas_sdk/v1/data/assessment.py +40 -0
  20. canvas_sdk/v1/data/base.py +35 -22
  21. canvas_sdk/v1/data/billing.py +2 -2
  22. canvas_sdk/v1/data/care_team.py +60 -0
  23. canvas_sdk/v1/data/command.py +1 -1
  24. canvas_sdk/v1/data/common.py +53 -0
  25. canvas_sdk/v1/data/condition.py +19 -3
  26. canvas_sdk/v1/data/coverage.py +294 -0
  27. canvas_sdk/v1/data/detected_issue.py +1 -0
  28. canvas_sdk/v1/data/lab.py +26 -3
  29. canvas_sdk/v1/data/medication.py +13 -3
  30. canvas_sdk/v1/data/note.py +5 -1
  31. canvas_sdk/v1/data/observation.py +15 -3
  32. canvas_sdk/v1/data/patient.py +140 -1
  33. canvas_sdk/v1/data/protocol_override.py +18 -2
  34. canvas_sdk/v1/data/questionnaire.py +15 -2
  35. canvas_sdk/value_set/hcc2018.py +55369 -0
  36. plugin_runner/sandbox.py +28 -0
  37. plugin_runner/tests/fixtures/plugins/test_render_template/CANVAS_MANIFEST.json +47 -0
  38. plugin_runner/tests/fixtures/plugins/test_render_template/README.md +11 -0
  39. plugin_runner/tests/fixtures/plugins/test_render_template/protocols/__init__.py +0 -0
  40. plugin_runner/tests/fixtures/plugins/test_render_template/protocols/my_protocol.py +43 -0
  41. plugin_runner/tests/fixtures/plugins/test_render_template/templates/template.html +10 -0
  42. plugin_runner/tests/test_plugin_runner.py +0 -46
  43. plugin_runner/tests/test_sandbox.py +21 -1
  44. settings.py +10 -0
  45. {canvas-0.15.0.dist-info → canvas-0.16.0.dist-info}/WHEEL +0 -0
  46. {canvas-0.15.0.dist-info → canvas-0.16.0.dist-info}/entry_points.txt +0 -0
@@ -1,7 +1,15 @@
1
+ from typing import cast
2
+
1
3
  from django.db import models
2
4
  from django.db.models import TextChoices
3
5
 
4
- from canvas_sdk.v1.data.base import ValueSetLookupQuerySet
6
+ from canvas_sdk.v1.data.base import (
7
+ BaseModelManager,
8
+ BaseQuerySet,
9
+ CommittableQuerySetMixin,
10
+ ForPatientQuerySetMixin,
11
+ ValueSetLookupQuerySetMixin,
12
+ )
5
13
 
6
14
 
7
15
  class ClinicalStatus(TextChoices):
@@ -14,12 +22,20 @@ class ClinicalStatus(TextChoices):
14
22
  INVESTIGATIVE = "investigative", "investigative"
15
23
 
16
24
 
17
- class ConditionQuerySet(ValueSetLookupQuerySet):
25
+ class ConditionQuerySet(
26
+ BaseQuerySet,
27
+ ValueSetLookupQuerySetMixin,
28
+ CommittableQuerySetMixin,
29
+ ForPatientQuerySetMixin,
30
+ ):
18
31
  """ConditionQuerySet."""
19
32
 
20
33
  pass
21
34
 
22
35
 
36
+ ConditionManager = BaseModelManager.from_queryset(ConditionQuerySet)
37
+
38
+
23
39
  class Condition(models.Model):
24
40
  """Condition."""
25
41
 
@@ -27,7 +43,7 @@ class Condition(models.Model):
27
43
  managed = False
28
44
  db_table = "canvas_sdk_data_api_condition_001"
29
45
 
30
- objects = ConditionQuerySet.as_manager()
46
+ objects = cast(ConditionQuerySet, ConditionManager())
31
47
 
32
48
  id = models.UUIDField()
33
49
  dbid = models.BigIntegerField(primary_key=True)
@@ -0,0 +1,294 @@
1
+ from django.contrib.postgres.fields import ArrayField
2
+ from django.db import models
3
+
4
+ from canvas_sdk.v1.data.common import (
5
+ AddressState,
6
+ AddressType,
7
+ AddressUse,
8
+ ContactPointState,
9
+ ContactPointSystem,
10
+ ContactPointUse,
11
+ )
12
+
13
+
14
+ class CoverageStack(models.TextChoices):
15
+ """CoverageStack."""
16
+
17
+ IN_USE = "IN_USE", "In use"
18
+ OTHER = "OTHER", "Other"
19
+ REMOVED = "REMOVED", "Removed"
20
+
21
+
22
+ class CoverageState(models.TextChoices):
23
+ """CoverageState."""
24
+
25
+ ACTIVE = "active", "Active"
26
+ DELETED = "deleted", "Deleted"
27
+
28
+
29
+ class CoverageType(models.TextChoices):
30
+ """CoverageType."""
31
+
32
+ COMMERCIAL = "commercial", "Commercial"
33
+ WORKERS_COMP = "workerscomp", "Workers Comp"
34
+ BCBS = "bcbs", "Blue Cross Blue Shield"
35
+ TRICARE = "champus", "Tricare/Champus"
36
+ MEDICAID = "medicaid", "Medicaid"
37
+ MEDICARE = "medicare", "Medicare"
38
+ OTHER = "other", "Other"
39
+ TPA = "tpa", "Third Party Administrator"
40
+ MVA = "motorvehicle", "Motor Vehicle"
41
+ LIEN = "lien", "Attorney/Lien"
42
+ PIP = "pip", "Personal Injury"
43
+
44
+
45
+ class CoverageRelationshipCode(models.TextChoices):
46
+ """CoverageRelationshipCode."""
47
+
48
+ SELF = "18", "Self"
49
+ SPOUSE = "01" "Spouse"
50
+ CHILD_INSURED_HAS_FINANCIAL_RESP = "19", "Natural Child, insured has financial responsibility"
51
+ CHILD_HAS_FINANCIAL_RESP = "43", "Natural Child, insured does not have financial responsibility"
52
+ STEP_CHILD = "17", "Step Child"
53
+ FOSTER_CHILD = "10", "Foster Child"
54
+ WARD_OF_COURT = "15", "Ward of the Court"
55
+ EMPLOYEE = "20", "Employee"
56
+ UNKNOWN = "21", "Unknown"
57
+ HANDICAPPED_DEPENDENT = "22", "Handicapped Dependent"
58
+ ORGAN_DONOR = "39", "Organ donor"
59
+ CADAVER_DONOR = "40", "Cadaver donor"
60
+ GRANDCHILD = "05", "Grandchild"
61
+ NIECE_NEPHEW = "07", "Niece/Nephew"
62
+ INJURED_PLAINTIFF = "41", "Injured Plaintiff"
63
+ SPONSORED_DEPENDENT = "23", "Sponsored Dependent"
64
+ MINOR_DEP_OF_MINOR_DEP = "24", "Minor Dependent of a Minor Dependent"
65
+ MOTHER = "32", "Mother"
66
+ FATHER = "33", "Father"
67
+ GRANDPARENT = "04", "Grandparent"
68
+ LIFE_PARTNER = "53", "Life Partner"
69
+ SIGNIFICANT_OTHER = "29", "Significant Other"
70
+ OTHER = "G8", "Other"
71
+
72
+
73
+ class TransactorCoverageType(models.TextChoices):
74
+ """TransactorCoverageType."""
75
+
76
+ ANNU = "ANNU", "annuity policy"
77
+ AUTOPOL = "AUTOPOL", "automobile"
78
+ CHAR = "CHAR", "charity program"
79
+ COL = "COL", "collision coverage policy"
80
+ CRIME = "CRIME", "crime victim program"
81
+ DENTAL = "DENTAL", "dental care policy"
82
+ DENTPRG = "DENTPRG", "dental program"
83
+ DIS = "DIS", "disability insurance policy"
84
+ DISEASE = "DISEASE", "disease specific policy"
85
+ DRUGPOL = "DRUGPOL", "drug policy"
86
+ EAP = "EAP", "employee assistance program"
87
+ EWB = "EWB", "employee welfare benefit plan policy"
88
+ ENDRENAL = "ENDRENAL", "end renal program"
89
+ EHCPOL = "EHCPOL", "extended healthcare"
90
+ FLEXP = "FLEXP", "flexible benefit plan policy"
91
+ GOVEMP = "GOVEMP", "government employee health program"
92
+ HIP = "HIP", "health insurance plan policy"
93
+ HMO = "HMO", "health maintenance organization policy"
94
+ HSAPOL = "HSAPOL", "health spending account"
95
+ HIRISK = "HIRISK", "high risk pool program"
96
+ HIVAIDS = "HIVAIDS", "HIV-AIDS program"
97
+ IND = "IND", "indigenous peoples health program"
98
+ LIFE = "LIFE", "life insurance policy"
99
+ LTC = "LTC", "long term care policy"
100
+ MCPOL = "MCPOL", "managed care policy"
101
+ MANDPOL = "MANDPOL", "mandatory health program"
102
+ MENTPOL = "MENTPOL", "mental health policy"
103
+ MENTPRG = "MENTPRG", "mental health program"
104
+ MILITARY = "MILITARY", "military health program"
105
+ PAY = "pay", "Pay"
106
+ POS = "POS", "point of service policy"
107
+ PPO = "PPO", "preferred provider organization policy"
108
+ PNC = "PNC", "property and casualty insurance policy"
109
+ DISEASEPRG = "DISEASEPRG", "public health program"
110
+ PUBLICPOL = "PUBLICPOL", "public healthcare"
111
+ REI = "REI", "reinsurance policy"
112
+ RETIRE = "RETIRE", "retiree health program"
113
+ SAFNET = "SAFNET", "safety net clinic program"
114
+ SOCIAL = "SOCIAL", "social service program"
115
+ SUBSIDIZ = "SUBSIDIZ", "subsidized health program"
116
+ SUBSIDMC = "SUBSIDMC", "subsidized managed care program"
117
+ SUBSUPP = "SUBSUPP", "subsidized supplemental health program"
118
+ SUBPOL = "SUBPOL", "substance use policy"
119
+ SUBPRG = "SUBPRG", "substance use program"
120
+ SURPL = "SURPL", "surplus line insurance policy"
121
+ TLIFE = "TLIFE", "term life insurance policy"
122
+ UMBRL = "UMBRL", "umbrella liability insurance policy"
123
+ UNINSMOT = "UNINSMOT", "uninsured motorist policy"
124
+ ULIFE = "ULIFE", "universal life insurance policy"
125
+ VET = "VET", "veteran health program"
126
+ VISPOL = "VISPOL", "vision care policy"
127
+ CANPRG = "CANPRG", "women's cancer detection program"
128
+ WCBPOL = "WCBPOL", "worker's compensation"
129
+
130
+
131
+ class TransactorType(models.TextChoices):
132
+ """TransactorType."""
133
+
134
+ COMMERCIAL = "commercial", "Commercial"
135
+ WORKERS_COMP = "workerscomp", "Workers Comp"
136
+ TRICARE = "champus", "Tricare/Champus"
137
+ MEDICAID = "medicaid", "Medicaid"
138
+ MEDICARE = "medicare", "Medicare"
139
+ MEDICARE_ADVANTAGE = "medicare_advantage", "Medicare Advantage"
140
+ CHIP = "CHIP", "CHIP"
141
+ AUTO = "automobile", "Automobile"
142
+ EMPLOYER = "employer", "Employer"
143
+ DIRECT_CARE = "direct_care", "Direct Care"
144
+ BCBS = "bcbs", "Blue Cross Blue Shield"
145
+
146
+
147
+ class Coverage(models.Model):
148
+ """Coverage."""
149
+
150
+ class Meta:
151
+ managed = False
152
+ db_table = "canvas_sdk_data_api_coverage_001"
153
+
154
+ id = models.UUIDField()
155
+ dbid = models.BigIntegerField(primary_key=True)
156
+ created = models.DateTimeField()
157
+ modified = models.DateTimeField()
158
+ patient = models.ForeignKey(
159
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="coverages", null=True
160
+ )
161
+ guarantor = models.ForeignKey(
162
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="dependent_coverages", null=True
163
+ )
164
+ subscriber = models.ForeignKey(
165
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="subscribed_coverages", null=True
166
+ )
167
+ patient_relationship_to_subscriber = models.CharField(choices=CoverageRelationshipCode.choices)
168
+ issuer = models.ForeignKey(
169
+ "v1.Transactor", on_delete=models.DO_NOTHING, related_name="coverages", null=True
170
+ )
171
+ id_number = models.CharField()
172
+ plan = models.CharField()
173
+ sub_plan = models.CharField()
174
+ group = models.CharField()
175
+ sub_group = models.CharField()
176
+ employer = models.CharField()
177
+ coverage_start_date = models.DateField()
178
+ coverage_end_date = models.DateField()
179
+ coverage_rank = models.IntegerField()
180
+ state = models.CharField(choices=CoverageState.choices)
181
+ plan_type = models.CharField(choices=CoverageType.choices)
182
+ coverage_type = models.CharField(choices=TransactorCoverageType.choices)
183
+ issuer_address = models.ForeignKey(
184
+ "v1.TransactorAddress",
185
+ on_delete=models.DO_NOTHING,
186
+ related_name="coverages",
187
+ null=True,
188
+ )
189
+ issuer_phone = models.ForeignKey(
190
+ "v1.TransactorPhone", on_delete=models.DO_NOTHING, related_name="coverages", null=True
191
+ )
192
+ comments = models.TextField()
193
+ stack = models.CharField(choices=CoverageStack.choices)
194
+
195
+ def __str__(self) -> str:
196
+ return f"id={self.id}"
197
+
198
+
199
+ class Transactor(models.Model):
200
+ """Transactor."""
201
+
202
+ class Meta:
203
+ managed = False
204
+ db_table = "canvas_sdk_data_quality_and_revenue_transactor_001"
205
+
206
+ dbid = models.BigIntegerField(primary_key=True)
207
+ payer_id = models.CharField()
208
+ name = models.CharField()
209
+ type = models.CharField()
210
+ transactor_type = models.CharField(choices=TransactorType.choices)
211
+ clearinghouse_payer = models.BooleanField()
212
+ institutional = models.BooleanField(null=True)
213
+ institutional_enrollment_req = models.BooleanField(null=True)
214
+ professional = models.BooleanField(null=True)
215
+ professional_enrollment_req = models.BooleanField(null=True)
216
+ era = models.BooleanField(null=True)
217
+ era_enrollment_req = models.BooleanField(null=True)
218
+ eligibility = models.BooleanField(null=True)
219
+ eligibility_enrollment_req = models.BooleanField(null=True)
220
+ workers_comp = models.BooleanField(null=True)
221
+ secondary_support = models.BooleanField(null=True)
222
+ claim_fee = models.BooleanField(null=True)
223
+ remit_fee = models.BooleanField(null=True)
224
+ state = models.CharField()
225
+ description = models.CharField()
226
+ active = models.BooleanField()
227
+ use_provider_for_eligibility = models.BooleanField()
228
+
229
+ use_for_submission = models.ForeignKey(
230
+ "v1.Transactor",
231
+ on_delete=models.DO_NOTHING,
232
+ null=True,
233
+ related_name="used_for_submission_by",
234
+ )
235
+
236
+ coverage_types = ArrayField(models.CharField(choices=TransactorCoverageType.choices))
237
+
238
+
239
+ class TransactorAddress(models.Model):
240
+ """TransactorAddress."""
241
+
242
+ class Meta:
243
+ managed = False
244
+ db_table = "canvas_sdk_data_quality_and_revenue_transactoraddress_001"
245
+
246
+ id = models.UUIDField()
247
+ dbid = models.BigIntegerField(primary_key=True)
248
+ created = models.DateTimeField()
249
+ modified = models.DateTimeField()
250
+ line1 = models.CharField()
251
+ line2 = models.CharField()
252
+ city = models.CharField()
253
+ district = models.CharField()
254
+ state_code = models.CharField()
255
+ postal_code = models.CharField()
256
+ use = models.CharField(choices=AddressUse.choices)
257
+ type = models.CharField(choices=AddressType.choices)
258
+ longitude = models.FloatField(null=True, default=None, blank=True)
259
+ latitude = models.FloatField(null=True, default=None, blank=True)
260
+ start = models.DateField(null=True, blank=True)
261
+ end = models.DateField(null=True, blank=True)
262
+ country = models.CharField(max_length=255)
263
+ state = models.CharField(choices=AddressState.choices)
264
+ transactor = models.ForeignKey(
265
+ "v1.Transactor", on_delete=models.DO_NOTHING, related_name="addresses", null=True
266
+ )
267
+
268
+ def __str__(self) -> str:
269
+ return f"id={self.id}"
270
+
271
+
272
+ class TransactorPhone(models.Model):
273
+ """TransactorPhone."""
274
+
275
+ class Meta:
276
+ managed = False
277
+ db_table = "canvas_sdk_data_quality_and_revenue_transactorphone_001"
278
+
279
+ id = models.UUIDField()
280
+ dbid = models.BigIntegerField(primary_key=True)
281
+ created = models.DateTimeField()
282
+ modified = models.DateTimeField()
283
+ system = models.CharField(choices=ContactPointSystem.choices)
284
+ value = models.CharField()
285
+ use = models.CharField(choices=ContactPointUse.choices)
286
+ use_notes = models.CharField()
287
+ rank = models.IntegerField()
288
+ state = models.CharField(choices=ContactPointState.choices)
289
+ transactor = models.ForeignKey(
290
+ "v1.Transactor", on_delete=models.DO_NOTHING, related_name="phones", null=True
291
+ )
292
+
293
+ def __str__(self) -> str:
294
+ return f"id={self.id}"
@@ -36,6 +36,7 @@ class DetectedIssueEvidence(models.Model):
36
36
  managed = False
37
37
  db_table = "canvas_sdk_data_api_detectedissueevidence_001"
38
38
 
39
+ id = models.UUIDField()
39
40
  dbid = models.BigIntegerField(primary_key=True)
40
41
  system = models.CharField()
41
42
  version = models.CharField()
canvas_sdk/v1/data/lab.py CHANGED
@@ -1,12 +1,26 @@
1
+ from typing import cast
2
+
1
3
  from django.db import models
2
4
 
3
5
  from canvas_sdk.v1.data.base import (
4
- CommittableModelManager,
6
+ BaseModelManager,
7
+ BaseQuerySet,
8
+ CommittableQuerySetMixin,
9
+ ForPatientQuerySetMixin,
5
10
  TimeframeLookupQuerySetMixin,
6
11
  ValueSetLookupQuerySet,
7
12
  )
8
13
 
9
14
 
15
+ class LabReportQuerySet(BaseQuerySet, CommittableQuerySetMixin, ForPatientQuerySetMixin):
16
+ """A queryset for lab reports."""
17
+
18
+ pass
19
+
20
+
21
+ LabReportManager = BaseModelManager.from_queryset(LabReportQuerySet)
22
+
23
+
10
24
  class TransmissionType(models.TextChoices):
11
25
  """Choices for transmission types."""
12
26
 
@@ -22,7 +36,7 @@ class LabReport(models.Model):
22
36
  managed = False
23
37
  db_table = "canvas_sdk_data_api_labreport_001"
24
38
 
25
- objects = CommittableModelManager()
39
+ objects = cast(LabReportQuerySet, LabReportManager())
26
40
 
27
41
  id = models.UUIDField()
28
42
  dbid = models.BigIntegerField(primary_key=True)
@@ -52,6 +66,15 @@ class LabReport(models.Model):
52
66
  deleted = models.BooleanField()
53
67
 
54
68
 
69
+ class LabReviewQuerySet(BaseQuerySet, CommittableQuerySetMixin, ForPatientQuerySetMixin):
70
+ """A queryset for lab reviews."""
71
+
72
+ pass
73
+
74
+
75
+ LabReviewManager = BaseModelManager.from_queryset(LabReviewQuerySet)
76
+
77
+
55
78
  class LabReview(models.Model):
56
79
  """A class representing a lab review."""
57
80
 
@@ -59,7 +82,7 @@ class LabReview(models.Model):
59
82
  managed = False
60
83
  db_table = "canvas_sdk_data_api_labreview_001"
61
84
 
62
- objects = CommittableModelManager()
85
+ objects = cast(LabReviewQuerySet, LabReviewManager())
63
86
 
64
87
  id = models.UUIDField()
65
88
  dbid = models.BigIntegerField(primary_key=True)
@@ -1,7 +1,14 @@
1
+ from typing import cast
2
+
1
3
  from django.db import models
2
4
  from django.db.models import TextChoices
3
5
 
4
- from canvas_sdk.v1.data.base import CommittableModelManager, ValueSetLookupQuerySet
6
+ from canvas_sdk.v1.data.base import (
7
+ BaseModelManager,
8
+ CommittableQuerySetMixin,
9
+ ForPatientQuerySetMixin,
10
+ ValueSetLookupQuerySet,
11
+ )
5
12
 
6
13
 
7
14
  class Status(TextChoices):
@@ -11,12 +18,15 @@ class Status(TextChoices):
11
18
  INACTIVE = "inactive", "inactive"
12
19
 
13
20
 
14
- class MedicationQuerySet(ValueSetLookupQuerySet):
21
+ class MedicationQuerySet(ValueSetLookupQuerySet, CommittableQuerySetMixin, ForPatientQuerySetMixin):
15
22
  """MedicationQuerySet."""
16
23
 
17
24
  pass
18
25
 
19
26
 
27
+ MedicationManager = BaseModelManager.from_queryset(MedicationQuerySet)
28
+
29
+
20
30
  class Medication(models.Model):
21
31
  """Medication."""
22
32
 
@@ -24,7 +34,7 @@ class Medication(models.Model):
24
34
  managed = False
25
35
  db_table = "canvas_sdk_data_api_medication_001"
26
36
 
27
- objects = CommittableModelManager.from_queryset(MedicationQuerySet)()
37
+ objects = cast(MedicationQuerySet, MedicationManager())
28
38
 
29
39
  id = models.UUIDField()
30
40
  dbid = models.BigIntegerField(primary_key=True)
@@ -120,6 +120,8 @@ class NoteType(models.Model):
120
120
  deprecated_at = models.DateTimeField()
121
121
  is_patient_required = models.BooleanField()
122
122
  allow_custom_title = models.BooleanField()
123
+ is_scheduleable_via_patient_portal = models.BooleanField()
124
+ online_duration = models.IntegerField()
123
125
 
124
126
 
125
127
  class Note(models.Model):
@@ -133,7 +135,9 @@ class Note(models.Model):
133
135
  dbid = models.BigIntegerField(db_column="dbid", primary_key=True)
134
136
  created = models.DateTimeField()
135
137
  modified = models.DateTimeField()
136
- patient = models.ForeignKey("v1.Patient", on_delete=models.DO_NOTHING, null=True)
138
+ patient = models.ForeignKey(
139
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="notes", null=True
140
+ )
137
141
  provider = models.ForeignKey(
138
142
  "v1.Staff", on_delete=models.DO_NOTHING, related_name="notes", null=True
139
143
  )
@@ -1,14 +1,26 @@
1
+ from typing import cast
2
+
1
3
  from django.db import models
2
4
 
3
- from canvas_sdk.v1.data.base import CommittableModelManager, ValueSetLookupQuerySet
5
+ from canvas_sdk.v1.data.base import (
6
+ BaseModelManager,
7
+ CommittableQuerySetMixin,
8
+ ForPatientQuerySetMixin,
9
+ ValueSetLookupQuerySet,
10
+ )
4
11
 
5
12
 
6
- class ObservationQuerySet(ValueSetLookupQuerySet):
13
+ class ObservationQuerySet(
14
+ ValueSetLookupQuerySet, CommittableQuerySetMixin, ForPatientQuerySetMixin
15
+ ):
7
16
  """ObservationQuerySet."""
8
17
 
9
18
  pass
10
19
 
11
20
 
21
+ ObservationManager = BaseModelManager.from_queryset(ObservationQuerySet)
22
+
23
+
12
24
  class Observation(models.Model):
13
25
  """Observation."""
14
26
 
@@ -16,7 +28,7 @@ class Observation(models.Model):
16
28
  managed = False
17
29
  db_table = "canvas_sdk_data_api_observation_001"
18
30
 
19
- objects = CommittableModelManager.from_queryset(ObservationQuerySet)()
31
+ objects = cast(ObservationQuerySet, ObservationManager())
20
32
 
21
33
  id = models.UUIDField()
22
34
  dbid = models.BigIntegerField(primary_key=True)
@@ -1,10 +1,22 @@
1
- from typing import Self
1
+ from typing import TYPE_CHECKING, Any, Self
2
2
 
3
3
  import arrow
4
4
  from django.contrib.postgres.fields import ArrayField
5
5
  from django.db import models
6
6
  from django.db.models import TextChoices
7
7
 
8
+ from canvas_sdk.v1.data.common import (
9
+ AddressState,
10
+ AddressType,
11
+ AddressUse,
12
+ ContactPointState,
13
+ ContactPointSystem,
14
+ ContactPointUse,
15
+ )
16
+
17
+ if TYPE_CHECKING:
18
+ from django_stubs_ext.db.models.manager import RelatedManager
19
+
8
20
 
9
21
  class SexAtBirth(TextChoices):
10
22
  """SexAtBirth."""
@@ -16,6 +28,16 @@ class SexAtBirth(TextChoices):
16
28
  BLANK = "", ""
17
29
 
18
30
 
31
+ class PatientSettingConstants:
32
+ """PatientSettingConstants."""
33
+
34
+ LAB = "lab"
35
+ PHARMACY = "pharmacy"
36
+ IMAGING_CENTER = "imagingCenter"
37
+ CONTACT_METHOD = "contactMethod"
38
+ PREFERRED_SCHEDULING_TIMEZONE = "preferredSchedulingTimezone"
39
+
40
+
19
41
  class Patient(models.Model):
20
42
  """A class representing a patient."""
21
43
 
@@ -59,6 +81,8 @@ class Patient(models.Model):
59
81
  default_location_id = models.BigIntegerField()
60
82
  default_provider_id = models.BigIntegerField()
61
83
 
84
+ settings: "RelatedManager[PatientSetting]"
85
+
62
86
  @classmethod
63
87
  def find(cls, id: str) -> Self:
64
88
  """Find a patient by id."""
@@ -83,3 +107,118 @@ class Patient(models.Model):
83
107
  next_year = birth_date.shift(years=age + 1)
84
108
  age += (time.date() - current_year.date()) / (next_year.date() - current_year.date())
85
109
  return age
110
+
111
+ def get_setting(self, name: str) -> Any:
112
+ """Returns a patient setting value by name."""
113
+ try:
114
+ return self.settings.get(name=name).value
115
+ except PatientSetting.DoesNotExist:
116
+ return None
117
+
118
+ @property
119
+ def preferred_pharmacy(self) -> dict[str, str] | None:
120
+ """Returns the patient's preferred pharmacy."""
121
+ pharmacy_setting = self.get_setting(PatientSettingConstants.PHARMACY) or {}
122
+ if isinstance(pharmacy_setting, list):
123
+ for pharmacy in pharmacy_setting:
124
+ if pharmacy.get("default", False):
125
+ return pharmacy
126
+ return None
127
+ return pharmacy_setting
128
+
129
+
130
+ class PatientContactPoint(models.Model):
131
+ """A class representing a patient contact point."""
132
+
133
+ class Meta:
134
+ managed = False
135
+ db_table = "canvas_sdk_data_api_patientcontactpoint_001"
136
+
137
+ id = models.UUIDField()
138
+ dbid = models.BigIntegerField(primary_key=True)
139
+ system = models.CharField(choices=ContactPointSystem.choices)
140
+ value = models.CharField()
141
+ use = models.CharField(choices=ContactPointUse.choices)
142
+ use_notes = models.CharField()
143
+ rank = models.IntegerField()
144
+ state = models.CharField(choices=ContactPointState.choices)
145
+ patient = models.ForeignKey(
146
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="telecom", null=True
147
+ )
148
+ has_consent = models.BooleanField()
149
+ last_verified = models.DateTimeField
150
+ verification_token = models.CharField()
151
+ opted_out = models.BooleanField()
152
+
153
+
154
+ class PatientAddress(models.Model):
155
+ """A class representing a patient address."""
156
+
157
+ class Meta:
158
+ managed = False
159
+ db_table = "canvas_sdk_data_api_patientaddress_001"
160
+
161
+ id = models.UUIDField()
162
+ dbid = models.BigIntegerField(primary_key=True)
163
+ line1 = models.CharField()
164
+ line2 = models.CharField()
165
+ city = models.CharField()
166
+ district = models.CharField()
167
+ state_code = models.CharField()
168
+ postal_code = models.CharField()
169
+ use = models.CharField(choices=AddressUse.choices)
170
+ type = models.CharField(choices=AddressType.choices)
171
+ longitude = models.FloatField()
172
+ latitude = models.FloatField()
173
+ start = models.DateField()
174
+ end = models.DateField()
175
+ country = models.CharField()
176
+ state = models.CharField(choices=AddressState.choices)
177
+ patient = models.ForeignKey(
178
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="addresses", null=True
179
+ )
180
+
181
+ def __str__(self) -> str:
182
+ return f"id={self.id}"
183
+
184
+
185
+ class PatientExternalIdentifier(models.Model):
186
+ """A class representing a patient external identifier."""
187
+
188
+ class Meta:
189
+ managed = False
190
+ db_table = "canvas_sdk_data_api_patientexternalidentifier_001"
191
+
192
+ id = models.UUIDField()
193
+ dbid = models.BigIntegerField(primary_key=True)
194
+ created = models.DateTimeField()
195
+ modified = models.DateTimeField()
196
+ patient = models.ForeignKey(
197
+ "v1.Patient", related_name="external_identifiers", on_delete=models.DO_NOTHING, null=True
198
+ )
199
+ use = models.CharField()
200
+ identifier_type = models.CharField()
201
+ system = models.CharField()
202
+ value = models.CharField()
203
+ issued_date = models.DateField()
204
+ expiration_date = models.DateField()
205
+
206
+ def __str__(self) -> str:
207
+ return f"id={self.id}"
208
+
209
+
210
+ class PatientSetting(models.Model):
211
+ """PatientSetting."""
212
+
213
+ class Meta:
214
+ managed = False
215
+ db_table = "canvas_sdk_data_api_patientsetting_001"
216
+
217
+ dbid = models.BigIntegerField(primary_key=True)
218
+ created = models.DateTimeField()
219
+ modified = models.DateTimeField()
220
+ patient = models.ForeignKey(
221
+ "v1.Patient", on_delete=models.DO_NOTHING, related_name="settings", null=True
222
+ )
223
+ name = models.CharField()
224
+ value = models.JSONField()