canvas 0.32.0__py3-none-any.whl → 0.33.1__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 (257) hide show
  1. {canvas-0.32.0.dist-info → canvas-0.33.1.dist-info}/METADATA +2 -1
  2. canvas-0.33.1.dist-info/RECORD +272 -0
  3. canvas_generated/messages/effects_pb2.py +2 -2
  4. canvas_generated/messages/effects_pb2.pyi +4 -0
  5. canvas_sdk/__init__.py +3 -0
  6. canvas_sdk/commands/__init__.py +1 -1
  7. canvas_sdk/commands/base.py +3 -0
  8. canvas_sdk/commands/commands/__init__.py +1 -0
  9. canvas_sdk/commands/commands/adjust_prescription.py +3 -0
  10. canvas_sdk/commands/commands/allergy.py +7 -0
  11. canvas_sdk/commands/commands/assess.py +2 -0
  12. canvas_sdk/commands/commands/close_goal.py +3 -0
  13. canvas_sdk/commands/commands/diagnose.py +3 -0
  14. canvas_sdk/commands/commands/exam.py +3 -0
  15. canvas_sdk/commands/commands/family_history.py +3 -0
  16. canvas_sdk/commands/commands/follow_up.py +3 -0
  17. canvas_sdk/commands/commands/goal.py +3 -0
  18. canvas_sdk/commands/commands/history_present_illness.py +3 -0
  19. canvas_sdk/commands/commands/imaging_order.py +3 -0
  20. canvas_sdk/commands/commands/instruct.py +3 -0
  21. canvas_sdk/commands/commands/lab_order.py +3 -0
  22. canvas_sdk/commands/commands/medical_history.py +3 -0
  23. canvas_sdk/commands/commands/medication_statement.py +2 -0
  24. canvas_sdk/commands/commands/past_surgical_history.py +3 -0
  25. canvas_sdk/commands/commands/perform.py +3 -0
  26. canvas_sdk/commands/commands/plan.py +3 -0
  27. canvas_sdk/commands/commands/prescribe.py +8 -0
  28. canvas_sdk/commands/commands/questionnaire/__init__.py +3 -13
  29. canvas_sdk/commands/commands/questionnaire/question.py +10 -0
  30. canvas_sdk/commands/commands/reason_for_visit.py +3 -0
  31. canvas_sdk/commands/commands/refer.py +3 -0
  32. canvas_sdk/commands/commands/refill.py +3 -0
  33. canvas_sdk/commands/commands/remove_allergy.py +3 -0
  34. canvas_sdk/commands/commands/resolve_condition.py +3 -0
  35. canvas_sdk/commands/commands/review_of_systems.py +3 -0
  36. canvas_sdk/commands/commands/stop_medication.py +3 -0
  37. canvas_sdk/commands/commands/structured_assessment.py +3 -0
  38. canvas_sdk/commands/commands/task.py +7 -0
  39. canvas_sdk/commands/commands/update_diagnosis.py +3 -0
  40. canvas_sdk/commands/commands/update_goal.py +3 -0
  41. canvas_sdk/commands/commands/vitals.py +3 -0
  42. canvas_sdk/commands/constants.py +8 -0
  43. canvas_sdk/effects/__init__.py +1 -1
  44. canvas_sdk/effects/banner_alert/__init__.py +1 -1
  45. canvas_sdk/effects/banner_alert/add_banner_alert.py +3 -0
  46. canvas_sdk/effects/banner_alert/remove_banner_alert.py +3 -0
  47. canvas_sdk/effects/base.py +7 -0
  48. canvas_sdk/effects/billing_line_item/__init__.py +5 -1
  49. canvas_sdk/effects/billing_line_item/add_billing_line_item.py +3 -0
  50. canvas_sdk/effects/billing_line_item/remove_billing_line_item.py +3 -0
  51. canvas_sdk/effects/billing_line_item/update_billing_line_item.py +3 -0
  52. canvas_sdk/effects/launch_modal.py +3 -0
  53. canvas_sdk/effects/patient_chart_summary_configuration.py +3 -0
  54. canvas_sdk/effects/patient_portal/__init__.py +1 -0
  55. canvas_sdk/effects/patient_portal/application_configuration.py +3 -0
  56. canvas_sdk/effects/patient_portal/form_result.py +3 -0
  57. canvas_sdk/effects/patient_portal_menu_configuration.py +3 -0
  58. canvas_sdk/effects/patient_profile_configuration.py +6 -1
  59. canvas_sdk/effects/protocol_card/__init__.py +1 -1
  60. canvas_sdk/effects/protocol_card/protocol_card.py +6 -0
  61. canvas_sdk/effects/questionnaire_result.py +3 -0
  62. canvas_sdk/effects/send_invite.py +46 -0
  63. canvas_sdk/effects/show_button.py +3 -0
  64. canvas_sdk/effects/simple_api.py +9 -0
  65. canvas_sdk/effects/surescripts/__init__.py +2 -2
  66. canvas_sdk/effects/surescripts/surescripts_messages.py +7 -0
  67. canvas_sdk/effects/task/__init__.py +6 -1
  68. canvas_sdk/effects/task/task.py +8 -0
  69. canvas_sdk/effects/update_user.py +81 -0
  70. canvas_sdk/effects/widgets/__init__.py +1 -1
  71. canvas_sdk/effects/widgets/portal_widget.py +3 -0
  72. canvas_sdk/events/__init__.py +6 -1
  73. canvas_sdk/events/base.py +3 -0
  74. canvas_sdk/handlers/__init__.py +1 -1
  75. canvas_sdk/handlers/action_button.py +6 -0
  76. canvas_sdk/handlers/application.py +3 -0
  77. canvas_sdk/handlers/base.py +3 -0
  78. canvas_sdk/handlers/cron_task.py +3 -0
  79. canvas_sdk/handlers/simple_api/__init__.py +3 -2
  80. canvas_sdk/handlers/simple_api/api.py +26 -1
  81. canvas_sdk/handlers/simple_api/exceptions.py +10 -0
  82. canvas_sdk/handlers/simple_api/security.py +21 -5
  83. canvas_sdk/handlers/simple_api/tools.py +9 -0
  84. canvas_sdk/protocols/__init__.py +1 -1
  85. canvas_sdk/protocols/base.py +3 -0
  86. canvas_sdk/protocols/clinical_quality_measure.py +6 -1
  87. canvas_sdk/protocols/timeframe.py +3 -0
  88. canvas_sdk/questionnaires/__init__.py +1 -1
  89. canvas_sdk/questionnaires/utils.py +7 -0
  90. canvas_sdk/templates/__init__.py +1 -1
  91. canvas_sdk/templates/utils.py +3 -0
  92. canvas_sdk/utils/__init__.py +1 -1
  93. canvas_sdk/utils/http.py +69 -35
  94. canvas_sdk/utils/plugins.py +4 -0
  95. canvas_sdk/utils/stats.py +11 -0
  96. canvas_sdk/v1/__init__.py +1 -0
  97. canvas_sdk/v1/apps.py +3 -0
  98. canvas_sdk/v1/data/__init__.py +2 -2
  99. canvas_sdk/v1/data/allergy_intolerance.py +3 -0
  100. canvas_sdk/v1/data/appointment.py +7 -0
  101. canvas_sdk/v1/data/assessment.py +3 -0
  102. canvas_sdk/v1/data/banner_alert.py +3 -0
  103. canvas_sdk/v1/data/base.py +3 -0
  104. canvas_sdk/v1/data/billing.py +7 -0
  105. canvas_sdk/v1/data/care_team.py +7 -0
  106. canvas_sdk/v1/data/command.py +3 -0
  107. canvas_sdk/v1/data/common.py +18 -0
  108. canvas_sdk/v1/data/condition.py +7 -0
  109. canvas_sdk/v1/data/coverage.py +14 -0
  110. canvas_sdk/v1/data/detected_issue.py +3 -0
  111. canvas_sdk/v1/data/device.py +3 -0
  112. canvas_sdk/v1/data/imaging.py +7 -0
  113. canvas_sdk/v1/data/lab.py +16 -0
  114. canvas_sdk/v1/data/medication.py +3 -0
  115. canvas_sdk/v1/data/note.py +9 -0
  116. canvas_sdk/v1/data/observation.py +9 -0
  117. canvas_sdk/v1/data/organization.py +3 -0
  118. canvas_sdk/v1/data/patient.py +20 -3
  119. canvas_sdk/v1/data/practicelocation.py +7 -0
  120. canvas_sdk/v1/data/protocol_override.py +7 -0
  121. canvas_sdk/v1/data/questionnaire.py +16 -3
  122. canvas_sdk/v1/data/reason_for_visit.py +3 -0
  123. canvas_sdk/v1/data/staff.py +3 -0
  124. canvas_sdk/v1/data/task.py +12 -0
  125. canvas_sdk/v1/data/team.py +8 -1
  126. canvas_sdk/v1/data/user.py +5 -1
  127. canvas_sdk/v1/models.py +2 -0
  128. canvas_sdk/value_set/__init__.py +1 -0
  129. canvas_sdk/value_set/_utilities.py +16 -0
  130. canvas_sdk/value_set/custom.py +4 -0
  131. canvas_sdk/value_set/hcc2018.py +3 -0
  132. canvas_sdk/value_set/v2022/__init__.py +1 -0
  133. canvas_sdk/value_set/v2022/adverse_event.py +3 -0
  134. canvas_sdk/value_set/v2022/allergy.py +5 -0
  135. canvas_sdk/value_set/v2022/assessment.py +5 -0
  136. canvas_sdk/value_set/v2022/communication.py +5 -0
  137. canvas_sdk/value_set/v2022/condition.py +5 -0
  138. canvas_sdk/value_set/v2022/device.py +5 -0
  139. canvas_sdk/value_set/v2022/diagnostic_study.py +5 -0
  140. canvas_sdk/value_set/v2022/encounter.py +5 -0
  141. canvas_sdk/value_set/v2022/immunization.py +5 -0
  142. canvas_sdk/value_set/v2022/individual_characteristic.py +5 -0
  143. canvas_sdk/value_set/v2022/intervention.py +5 -0
  144. canvas_sdk/value_set/v2022/laboratory_test.py +5 -0
  145. canvas_sdk/value_set/v2022/medication.py +5 -0
  146. canvas_sdk/value_set/v2022/physical_exam.py +5 -0
  147. canvas_sdk/value_set/v2022/procedure.py +5 -0
  148. canvas_sdk/value_set/v2022/symptom.py +3 -0
  149. canvas_sdk/value_set/value_set.py +9 -0
  150. canvas_sdk/views/__init__.py +1 -0
  151. logger/__init__.py +2 -0
  152. logger/logger.py +3 -0
  153. plugin_runner/aws_headers.py +1 -1
  154. plugin_runner/load_all_plugins.py +202 -0
  155. plugin_runner/plugin_runner.py +26 -24
  156. plugin_runner/sandbox.py +497 -115
  157. protobufs/canvas_generated/messages/effects.proto +3 -0
  158. settings.py +5 -2
  159. canvas-0.32.0.dist-info/RECORD +0 -364
  160. canvas_cli/apps/auth/tests.py +0 -155
  161. canvas_cli/apps/plugin/tests.py +0 -85
  162. canvas_cli/conftest.py +0 -28
  163. canvas_cli/tests.py +0 -217
  164. canvas_cli/utils/context/tests.py +0 -131
  165. canvas_cli/utils/print/tests.py +0 -69
  166. canvas_cli/utils/urls/tests.py +0 -12
  167. canvas_cli/utils/validators/tests.py +0 -37
  168. canvas_sdk/commands/tests/protocol/__init__.py +0 -0
  169. canvas_sdk/commands/tests/protocol/tests.py +0 -83
  170. canvas_sdk/commands/tests/schema/__init__.py +0 -0
  171. canvas_sdk/commands/tests/schema/tests.py +0 -108
  172. canvas_sdk/commands/tests/test_base_command.py +0 -81
  173. canvas_sdk/commands/tests/test_utils.py +0 -375
  174. canvas_sdk/commands/tests/unit/__init__.py +0 -0
  175. canvas_sdk/commands/tests/unit/tests.py +0 -278
  176. canvas_sdk/effects/banner_alert/tests.py +0 -288
  177. canvas_sdk/effects/protocol_card/tests.py +0 -191
  178. canvas_sdk/questionnaires/tests/__init__.py +0 -0
  179. canvas_sdk/questionnaires/tests/test_utils.py +0 -74
  180. canvas_sdk/templates/tests/__init__.py +0 -0
  181. canvas_sdk/templates/tests/test_utils.py +0 -43
  182. canvas_sdk/tests/__init__.py +0 -0
  183. canvas_sdk/tests/handlers/__init__.py +0 -0
  184. canvas_sdk/tests/handlers/test_simple_api.py +0 -1167
  185. canvas_sdk/utils/tests.py +0 -72
  186. canvas_sdk/value_set/tests/test_value_sets.py +0 -72
  187. plugin_runner/tests/__init__.py +0 -0
  188. plugin_runner/tests/fixtures/plugins/example_plugin/CANVAS_MANIFEST.json +0 -29
  189. plugin_runner/tests/fixtures/plugins/example_plugin/README.md +0 -12
  190. plugin_runner/tests/fixtures/plugins/example_plugin/__init__.py +0 -0
  191. plugin_runner/tests/fixtures/plugins/example_plugin/protocols/__init__.py +0 -0
  192. plugin_runner/tests/fixtures/plugins/example_plugin/protocols/my_protocol.py +0 -18
  193. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/CANVAS_MANIFEST.json +0 -38
  194. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/README.md +0 -11
  195. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/protocols/__init__.py +0 -0
  196. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/protocols/my_protocol.py +0 -33
  197. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/templates/__init__.py +0 -3
  198. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/templates/base.py +0 -6
  199. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/utils/__init__.py +0 -5
  200. plugin_runner/tests/fixtures/plugins/test_implicit_imports_plugin/utils/base.py +0 -4
  201. plugin_runner/tests/fixtures/plugins/test_load_questionnaire/CANVAS_MANIFEST.json +0 -52
  202. plugin_runner/tests/fixtures/plugins/test_load_questionnaire/README.md +0 -11
  203. plugin_runner/tests/fixtures/plugins/test_load_questionnaire/protocols/__init__.py +0 -0
  204. plugin_runner/tests/fixtures/plugins/test_load_questionnaire/protocols/my_protocol.py +0 -39
  205. plugin_runner/tests/fixtures/plugins/test_load_questionnaire/questionnaires/example_questionnaire.yml +0 -61
  206. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/CANVAS_MANIFEST.json +0 -29
  207. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/README.md +0 -12
  208. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/other_module/__init__.py +0 -0
  209. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/other_module/base.py +0 -10
  210. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/protocols/__init__.py +0 -0
  211. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_plugin/protocols/my_protocol.py +0 -18
  212. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/CANVAS_MANIFEST.json +0 -29
  213. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/README.md +0 -12
  214. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/other_module/__init__.py +0 -0
  215. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/other_module/base.py +0 -10
  216. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/protocols/__init__.py +0 -0
  217. plugin_runner/tests/fixtures/plugins/test_module_forbidden_imports_runtime_plugin/protocols/my_protocol.py +0 -18
  218. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/CANVAS_MANIFEST.json +0 -29
  219. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/README.md +0 -12
  220. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/other_module/__init__.py +0 -0
  221. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/other_module/base.py +0 -3
  222. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/protocols/__init__.py +0 -0
  223. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v1/protocols/my_protocol.py +0 -18
  224. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/CANVAS_MANIFEST.json +0 -29
  225. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/README.md +0 -12
  226. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/other_module/__init__.py +0 -0
  227. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/other_module/base.py +0 -6
  228. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/protocols/__init__.py +0 -0
  229. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v2/protocols/my_protocol.py +0 -18
  230. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/CANVAS_MANIFEST.json +0 -29
  231. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/README.md +0 -12
  232. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/other_module/__init__.py +0 -0
  233. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/other_module/base.py +0 -8
  234. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/protocols/__init__.py +0 -0
  235. plugin_runner/tests/fixtures/plugins/test_module_imports_outside_plugin_v3/protocols/my_protocol.py +0 -18
  236. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/CANVAS_MANIFEST.json +0 -29
  237. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/README.md +0 -12
  238. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/other_module/__init__.py +0 -0
  239. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/other_module/base.py +0 -3
  240. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/protocols/__init__.py +0 -0
  241. plugin_runner/tests/fixtures/plugins/test_module_imports_plugin/protocols/my_protocol.py +0 -18
  242. plugin_runner/tests/fixtures/plugins/test_render_template/CANVAS_MANIFEST.json +0 -47
  243. plugin_runner/tests/fixtures/plugins/test_render_template/README.md +0 -11
  244. plugin_runner/tests/fixtures/plugins/test_render_template/protocols/__init__.py +0 -0
  245. plugin_runner/tests/fixtures/plugins/test_render_template/protocols/my_protocol.py +0 -43
  246. plugin_runner/tests/fixtures/plugins/test_render_template/templates/template.html +0 -10
  247. plugin_runner/tests/fixtures/plugins/test_simple_api/CANVAS_MANIFEST.json +0 -47
  248. plugin_runner/tests/fixtures/plugins/test_simple_api/README.md +0 -11
  249. plugin_runner/tests/fixtures/plugins/test_simple_api/__init__.py +0 -0
  250. plugin_runner/tests/fixtures/plugins/test_simple_api/protocols/__init__.py +0 -0
  251. plugin_runner/tests/fixtures/plugins/test_simple_api/protocols/my_protocol.py +0 -43
  252. plugin_runner/tests/test_application.py +0 -65
  253. plugin_runner/tests/test_plugin_installer.py +0 -127
  254. plugin_runner/tests/test_plugin_runner.py +0 -388
  255. plugin_runner/tests/test_sandbox.py +0 -137
  256. {canvas-0.32.0.dist-info → canvas-0.33.1.dist-info}/WHEEL +0 -0
  257. {canvas-0.32.0.dist-info → canvas-0.33.1.dist-info}/entry_points.txt +0 -0
@@ -1,191 +0,0 @@
1
- from typing import Any
2
-
3
- import pytest
4
- from pydantic import ValidationError
5
-
6
- from canvas_sdk.commands import (
7
- AssessCommand,
8
- DiagnoseCommand,
9
- GoalCommand,
10
- HistoryOfPresentIllnessCommand,
11
- MedicationStatementCommand,
12
- PlanCommand,
13
- PrescribeCommand,
14
- QuestionnaireCommand,
15
- ReasonForVisitCommand,
16
- StopMedicationCommand,
17
- UpdateGoalCommand,
18
- )
19
- from canvas_sdk.commands.base import _BaseCommand
20
- from canvas_sdk.effects.protocol_card import ProtocolCard, Recommendation
21
-
22
-
23
- def test_apply_method_succeeds_with_patient_id_and_key() -> None:
24
- """Test that the apply method succeeds with all required fields."""
25
- p = ProtocolCard(patient_id="uuid", key="something-unique")
26
- applied = p.apply()
27
- assert (
28
- applied.payload
29
- == '{"patient": "uuid", "patient_filter": null, "key": "something-unique", "data": {"title": "", "narrative": "", "recommendations": [], "status": "due", "feedback_enabled": false, "due_in": -1}}'
30
- )
31
-
32
-
33
- def test_apply_method_raises_error_without_patient_id_and_key() -> None:
34
- """Test that the apply method raises an error when missing required fields."""
35
- p = ProtocolCard()
36
-
37
- with pytest.raises(ValidationError) as e:
38
- p.apply()
39
- err_msg = repr(e.value)
40
-
41
- assert "2 validation errors for ProtocolCard" in err_msg
42
- assert (
43
- "Field 'patient_id' or 'patient_filter' is required to apply a ProtocolCard [type=missing, input_value=None, input_type=NoneType]"
44
- in err_msg
45
- )
46
- assert (
47
- "Field 'key' is required to apply a ProtocolCard [type=missing, input_value=None, input_type=NoneType]"
48
- in err_msg
49
- )
50
-
51
-
52
- @pytest.mark.parametrize(
53
- "init_params,rec1_params,rec2_params",
54
- [
55
- (
56
- {
57
- "key": "link_rec",
58
- "patient_id": "patientuuid",
59
- "title": "This is a test!",
60
- "narrative": "we should only expect a link and a button",
61
- },
62
- {
63
- "title": "this is a link",
64
- "button": "click this",
65
- "href": "https://canvasmedical.com/",
66
- },
67
- {"title": "second link", "button": "don't click this", "href": "https://google.com/"},
68
- ),
69
- (
70
- {
71
- "key": "command_rec",
72
- "patient_id": "patientuuid",
73
- "title": "This is a test for command recommendations!",
74
- "narrative": "we should only expect buttons to insert commands",
75
- },
76
- {
77
- "title": "this is a command",
78
- "button": "click this",
79
- "command": "updategoal",
80
- "context": {"progress": "none"},
81
- },
82
- {
83
- "title": "another command",
84
- "button": "hypertension",
85
- "command": "diagnose",
86
- "context": {"background": "stuff"},
87
- },
88
- ),
89
- (
90
- {
91
- "patient_id": "patientuuid",
92
- "key": "command_rec_with_coding_filter",
93
- "title": "This is a test for command recommendations with coding filters!",
94
- "narrative": "we should only expect buttons to insert commands",
95
- },
96
- {
97
- "title": "hypertension",
98
- "button": "diagnose",
99
- "command": "diagnose",
100
- "context": {"background": "hey", "icd10_code": "I10"},
101
- },
102
- {
103
- "title": "fake medication",
104
- "button": "prescribe",
105
- "command": "prescribe",
106
- "context": {"sig": "1pobid"},
107
- },
108
- ),
109
- ],
110
- )
111
- def test_add_recommendations(
112
- init_params: dict[Any, Any], rec1_params: dict[Any, Any], rec2_params: dict[Any, Any]
113
- ) -> None:
114
- """Test that the add_recommendation method adds recommendations to the ProtocolCard."""
115
- p = ProtocolCard(**init_params)
116
- p.add_recommendation(**rec1_params)
117
- p.recommendations.append(Recommendation(**rec2_params))
118
- assert p.values == {
119
- "title": init_params["title"],
120
- "narrative": init_params["narrative"],
121
- "recommendations": [
122
- {
123
- "title": rec1_params.get("title"),
124
- "button": rec1_params.get("button"),
125
- "href": rec1_params.get("href"),
126
- "command": {"type": rec1_params["command"]} if "command" in rec1_params else {},
127
- "context": rec1_params.get("context", {}),
128
- "key": 0,
129
- },
130
- {
131
- "title": rec2_params.get("title"),
132
- "button": rec2_params.get("button"),
133
- "href": rec2_params.get("href"),
134
- "command": {"type": rec2_params["command"]} if "command" in rec2_params else {},
135
- "context": rec2_params.get("context", {}),
136
- "key": 1,
137
- },
138
- ],
139
- "status": "due",
140
- "due_in": -1,
141
- "feedback_enabled": False,
142
- }
143
-
144
-
145
- @pytest.mark.parametrize(
146
- "Command,init_params",
147
- [
148
- (AssessCommand, {}),
149
- (DiagnoseCommand, {"icd10_code": "I10"}),
150
- (GoalCommand, {}),
151
- (HistoryOfPresentIllnessCommand, {}),
152
- (MedicationStatementCommand, {"fdb_code": "fakeroo"}),
153
- (PlanCommand, {}),
154
- (PrescribeCommand, {"fdb_code": "fake"}),
155
- (QuestionnaireCommand, {}),
156
- (ReasonForVisitCommand, {}),
157
- (StopMedicationCommand, {}),
158
- (UpdateGoalCommand, {}),
159
- ],
160
- )
161
- def test_add_recommendations_from_commands(
162
- Command: type[_BaseCommand], init_params: dict[str, str]
163
- ) -> None:
164
- """Test that the add_recommendation method adds recommendations from commands to the ProtocolCard."""
165
- cmd = Command(**init_params)
166
- p = ProtocolCard(patient_id="uuid", key="commands")
167
- p.recommendations.append(cmd.recommend())
168
- p.recommendations.append(cmd.recommend(title="hello", button="click"))
169
- p.add_recommendation(
170
- title="yeehaw", button="click here", command=cmd.Meta.key.lower(), context=init_params
171
- )
172
-
173
- rec1, rec2, rec3 = p.values["recommendations"]
174
- assert rec1["title"] == ""
175
- assert rec1["button"] == cmd.constantized_key().lower().replace("_", " ")
176
- assert rec1["href"] is None
177
- assert rec1["context"] == cmd.values
178
- assert rec1["command"]["type"] == cmd.Meta.key.lower()
179
-
180
- assert rec2["title"] == "hello"
181
- assert rec2["button"] == "click"
182
- assert rec2["href"] is None
183
- assert rec2["context"] == cmd.values
184
- assert rec2["command"]["type"] == cmd.Meta.key.lower()
185
-
186
- assert rec3["title"] == "yeehaw"
187
- assert rec3["button"] == "click here"
188
- assert rec3["href"] is None
189
- assert rec3["command"]["type"] == cmd.Meta.key.lower()
190
- for k, v in init_params.items():
191
- assert rec3["context"][k] == v
File without changes
@@ -1,74 +0,0 @@
1
- import json
2
- from pathlib import Path
3
-
4
- import pytest
5
- import yaml
6
-
7
- from canvas_sdk.effects import Effect
8
- from canvas_sdk.events import Event, EventRequest, EventType
9
- from canvas_sdk.questionnaires import questionnaire_from_yaml
10
- from plugin_runner.plugin_runner import LOADED_PLUGINS
11
- from settings import PLUGIN_DIRECTORY
12
-
13
-
14
- @pytest.mark.parametrize("install_test_plugin", ["test_load_questionnaire"], indirect=True)
15
- def test_from_yaml_valid_questionnaire(install_test_plugin: Path, load_test_plugins: None) -> None:
16
- """Test that the from_yaml function loads a valid questionnaire."""
17
- plugin = LOADED_PLUGINS[
18
- "test_load_questionnaire:test_load_questionnaire.protocols.my_protocol:ValidQuestionnaire"
19
- ]
20
- result: list[Effect] = plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
21
-
22
- assert (
23
- yaml.load(
24
- (
25
- Path(PLUGIN_DIRECTORY)
26
- / "test_load_questionnaire/questionnaires/example_questionnaire.yml"
27
- )
28
- .resolve()
29
- .read_text(),
30
- Loader=yaml.SafeLoader,
31
- ).items()
32
- <= json.loads(result[0].payload).items()
33
- )
34
-
35
-
36
- @pytest.mark.parametrize("install_test_plugin", ["test_load_questionnaire"], indirect=True)
37
- def test_from_yaml_invalid_questionnaire(
38
- install_test_plugin: Path, load_test_plugins: None
39
- ) -> None:
40
- """Test that the from_yaml function raises an error for invalid questionnaires."""
41
- plugin = LOADED_PLUGINS[
42
- "test_load_questionnaire:test_load_questionnaire.protocols.my_protocol:InvalidQuestionnaire"
43
- ]
44
- with pytest.raises(FileNotFoundError):
45
- plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
46
-
47
-
48
- @pytest.mark.parametrize("install_test_plugin", ["test_load_questionnaire"], indirect=True)
49
- def test_from_yaml_forbidden_questionnaire(
50
- install_test_plugin: Path, load_test_plugins: None
51
- ) -> None:
52
- """Test that the from_yaml function raises an error for a questionnaire outside plugin package."""
53
- plugin = LOADED_PLUGINS[
54
- "test_load_questionnaire:test_load_questionnaire.protocols.my_protocol:ForbiddenQuestionnaire"
55
- ]
56
- with pytest.raises(PermissionError):
57
- plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
58
-
59
-
60
- def test_from_yaml_non_plugin_caller() -> None:
61
- """Test that the from_yaml function returns None when called outside a plugin."""
62
- assert questionnaire_from_yaml("questionnaires/example_questionnaire.yml") is None
63
-
64
-
65
- @pytest.mark.parametrize("install_test_plugin", ["test_load_questionnaire"], indirect=True)
66
- def test_from_yaml_sets_default_values(install_test_plugin: Path) -> None:
67
- """Test that the from_yaml function sets default values for properties."""
68
- globals()["__is_plugin__"] = True
69
- globals()["__name__"] = "test_load_questionnaire"
70
-
71
- definition = questionnaire_from_yaml("questionnaires/example_questionnaire.yml")
72
-
73
- assert definition is not None
74
- assert definition["display_results_in_social_history_section"] is False
File without changes
@@ -1,43 +0,0 @@
1
- from pathlib import Path
2
-
3
- import pytest
4
-
5
- from canvas_sdk.effects import Effect
6
- from canvas_sdk.events import Event, EventRequest, EventType
7
- from plugin_runner.plugin_runner import LOADED_PLUGINS
8
-
9
-
10
- @pytest.mark.parametrize("install_test_plugin", ["test_render_template"], indirect=True)
11
- def test_render_to_string_valid_template(
12
- install_test_plugin: Path, load_test_plugins: None
13
- ) -> None:
14
- """Test that the render_to_string function loads and renders a valid template."""
15
- plugin = LOADED_PLUGINS[
16
- "test_render_template:test_render_template.protocols.my_protocol:ValidTemplate"
17
- ]
18
- result: list[Effect] = plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
19
- assert "html" in result[0].payload
20
-
21
-
22
- @pytest.mark.parametrize("install_test_plugin", ["test_render_template"], indirect=True)
23
- def test_render_to_string_invalid_template(
24
- install_test_plugin: Path, load_test_plugins: None
25
- ) -> None:
26
- """Test that the render_to_string function raises an error for invalid templates."""
27
- plugin = LOADED_PLUGINS[
28
- "test_render_template:test_render_template.protocols.my_protocol:InvalidTemplate"
29
- ]
30
- with pytest.raises(FileNotFoundError):
31
- plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
32
-
33
-
34
- @pytest.mark.parametrize("install_test_plugin", ["test_render_template"], indirect=True)
35
- def test_render_to_string_forbidden_template(
36
- install_test_plugin: Path, load_test_plugins: None
37
- ) -> None:
38
- """Test that the render_to_string function raises an error for a template outside plugin package."""
39
- plugin = LOADED_PLUGINS[
40
- "test_render_template:test_render_template.protocols.my_protocol:ForbiddenTemplate"
41
- ]
42
- with pytest.raises(PermissionError):
43
- plugin["class"](Event(EventRequest(type=EventType.UNKNOWN))).compute()
File without changes
File without changes