vintasend 0.4.0 → 0.4.7

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.
Files changed (284) hide show
  1. package/README.md +5 -0
  2. package/dist/examples/vintasend-medplum-example/.env.example +11 -0
  3. package/dist/examples/vintasend-medplum-example/IMPLEMENTATION_PLAN_FILE_ATTACHMENTS.md +597 -0
  4. package/dist/examples/vintasend-medplum-example/README.md +190 -0
  5. package/dist/examples/vintasend-medplum-example/TUTORIAL_EMAIL_NOTIFICATIONS.md +2596 -0
  6. package/dist/examples/vintasend-medplum-example/bots/handlers/send-pending-notifications-bot.ts +39 -0
  7. package/dist/examples/vintasend-medplum-example/bots/handlers/send-task-assignment-email.ts +41 -0
  8. package/dist/examples/vintasend-medplum-example/bots/handlers/task-due-soon-notification-bot.ts +86 -0
  9. package/dist/examples/vintasend-medplum-example/bots/index.ts +53 -0
  10. package/dist/examples/vintasend-medplum-example/bots/services/emails/schedule-task-due-soon-email.ts +84 -0
  11. package/dist/examples/vintasend-medplum-example/bots/services/emails/send-task-assignment-email.test.ts +388 -0
  12. package/dist/examples/vintasend-medplum-example/bots/services/emails/send-task-assignment-email.ts +113 -0
  13. package/dist/examples/vintasend-medplum-example/bots/shared/task-due-soon-helpers.ts +115 -0
  14. package/dist/examples/vintasend-medplum-example/bots/task-assignment-bot.ts +41 -0
  15. package/dist/examples/vintasend-medplum-example/compiled-notification-templates.json +6 -0
  16. package/dist/examples/vintasend-medplum-example/esbuild-script.mjs +71 -0
  17. package/dist/examples/vintasend-medplum-example/index.html +14 -0
  18. package/dist/examples/vintasend-medplum-example/lib/constants.ts +32 -0
  19. package/dist/examples/vintasend-medplum-example/lib/extensions.ts +1 -0
  20. package/dist/examples/vintasend-medplum-example/lib/file-upload.test.ts +389 -0
  21. package/dist/examples/vintasend-medplum-example/lib/file-upload.ts +222 -0
  22. package/dist/examples/vintasend-medplum-example/lib/medplum-singleton.ts +18 -0
  23. package/dist/examples/vintasend-medplum-example/lib/notification-service.test.ts +293 -0
  24. package/dist/examples/vintasend-medplum-example/lib/notification-service.ts +284 -0
  25. package/dist/examples/vintasend-medplum-example/lib/patients.ts +20 -0
  26. package/dist/examples/vintasend-medplum-example/notification-templates/emails/task-assignment/body.html.pug +37 -0
  27. package/dist/examples/vintasend-medplum-example/notification-templates/emails/task-assignment/subject.txt.pug +4 -0
  28. package/dist/examples/vintasend-medplum-example/notification-templates/emails/task-due-soon/body.html.pug +34 -0
  29. package/dist/examples/vintasend-medplum-example/notification-templates/emails/task-due-soon/subject.txt.pug +4 -0
  30. package/dist/examples/vintasend-medplum-example/package.json +75 -0
  31. package/dist/examples/vintasend-medplum-example/plugins/gql-plugin.mjs +31 -0
  32. package/dist/examples/vintasend-medplum-example/postcss.config.mjs +21 -0
  33. package/dist/examples/vintasend-medplum-example/public/favicon.ico +0 -0
  34. package/dist/examples/vintasend-medplum-example/public/img/integrations/acuity.png +0 -0
  35. package/dist/examples/vintasend-medplum-example/public/img/integrations/auth0.png +0 -0
  36. package/dist/examples/vintasend-medplum-example/public/img/integrations/azure.png +0 -0
  37. package/dist/examples/vintasend-medplum-example/public/img/integrations/calcom.png +0 -0
  38. package/dist/examples/vintasend-medplum-example/public/img/integrations/candid.png +0 -0
  39. package/dist/examples/vintasend-medplum-example/public/img/integrations/claude.png +0 -0
  40. package/dist/examples/vintasend-medplum-example/public/img/integrations/datadog.png +0 -0
  41. package/dist/examples/vintasend-medplum-example/public/img/integrations/deepseek.png +0 -0
  42. package/dist/examples/vintasend-medplum-example/public/img/integrations/entra.png +0 -0
  43. package/dist/examples/vintasend-medplum-example/public/img/integrations/epic.png +0 -0
  44. package/dist/examples/vintasend-medplum-example/public/img/integrations/google.png +0 -0
  45. package/dist/examples/vintasend-medplum-example/public/img/integrations/healthgorilla.png +0 -0
  46. package/dist/examples/vintasend-medplum-example/public/img/integrations/healthie.png +0 -0
  47. package/dist/examples/vintasend-medplum-example/public/img/integrations/labcorp.png +0 -0
  48. package/dist/examples/vintasend-medplum-example/public/img/integrations/okta.png +0 -0
  49. package/dist/examples/vintasend-medplum-example/public/img/integrations/openai.png +0 -0
  50. package/dist/examples/vintasend-medplum-example/public/img/integrations/particle.png +0 -0
  51. package/dist/examples/vintasend-medplum-example/public/img/integrations/quest.png +0 -0
  52. package/dist/examples/vintasend-medplum-example/public/img/integrations/recaptcha.png +0 -0
  53. package/dist/examples/vintasend-medplum-example/public/img/integrations/snowflake.png +0 -0
  54. package/dist/examples/vintasend-medplum-example/public/img/integrations/stedi.png +0 -0
  55. package/dist/examples/vintasend-medplum-example/public/img/integrations/stripe.png +0 -0
  56. package/dist/examples/vintasend-medplum-example/public/img/integrations/sumo.png +0 -0
  57. package/dist/examples/vintasend-medplum-example/scripts/README.md +162 -0
  58. package/dist/examples/vintasend-medplum-example/scripts/client.ts +18 -0
  59. package/dist/examples/vintasend-medplum-example/scripts/deploy-bots.ts +171 -0
  60. package/dist/examples/vintasend-medplum-example/src/App.tsx +185 -0
  61. package/dist/examples/vintasend-medplum-example/src/components/ChargeItem/ChargeItemList.test.tsx +350 -0
  62. package/dist/examples/vintasend-medplum-example/src/components/ChargeItem/ChargeItemList.tsx +241 -0
  63. package/dist/examples/vintasend-medplum-example/src/components/ChargeItem/ChargeItemPanel.test.tsx +616 -0
  64. package/dist/examples/vintasend-medplum-example/src/components/ChargeItem/ChargeItemPanel.tsx +138 -0
  65. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionItem.test.tsx +92 -0
  66. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionItem.tsx +47 -0
  67. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionList.test.tsx +464 -0
  68. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionList.tsx +186 -0
  69. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionModal.test.tsx +80 -0
  70. package/dist/examples/vintasend-medplum-example/src/components/Conditions/ConditionModal.tsx +82 -0
  71. package/dist/examples/vintasend-medplum-example/src/components/DoseSpotIcon.test.tsx +100 -0
  72. package/dist/examples/vintasend-medplum-example/src/components/DoseSpotIcon.tsx +20 -0
  73. package/dist/examples/vintasend-medplum-example/src/components/IntegrationCard.module.css +3 -0
  74. package/dist/examples/vintasend-medplum-example/src/components/IntegrationCard.tsx +62 -0
  75. package/dist/examples/vintasend-medplum-example/src/components/MessageWithLinks.tsx +47 -0
  76. package/dist/examples/vintasend-medplum-example/src/components/PerformingLabInput.test.tsx +299 -0
  77. package/dist/examples/vintasend-medplum-example/src/components/PerformingLabInput.tsx +52 -0
  78. package/dist/examples/vintasend-medplum-example/src/components/ResourceFormWithRequiredProfile.tsx +82 -0
  79. package/dist/examples/vintasend-medplum-example/src/components/encounter/BillingTab.test.tsx +1016 -0
  80. package/dist/examples/vintasend-medplum-example/src/components/encounter/BillingTab.tsx +298 -0
  81. package/dist/examples/vintasend-medplum-example/src/components/encounter/EncounterChart.test.tsx +732 -0
  82. package/dist/examples/vintasend-medplum-example/src/components/encounter/EncounterChart.tsx +282 -0
  83. package/dist/examples/vintasend-medplum-example/src/components/encounter/EncounterHeader.test.tsx +268 -0
  84. package/dist/examples/vintasend-medplum-example/src/components/encounter/EncounterHeader.tsx +224 -0
  85. package/dist/examples/vintasend-medplum-example/src/components/encounter/SignAddendum.test.tsx +255 -0
  86. package/dist/examples/vintasend-medplum-example/src/components/encounter/SignAddendum.tsx +212 -0
  87. package/dist/examples/vintasend-medplum-example/src/components/encounter/SignLockDialog.test.tsx +120 -0
  88. package/dist/examples/vintasend-medplum-example/src/components/encounter/SignLockDialog.tsx +57 -0
  89. package/dist/examples/vintasend-medplum-example/src/components/encounter/VisitDetailsPanel.test.tsx +224 -0
  90. package/dist/examples/vintasend-medplum-example/src/components/encounter/VisitDetailsPanel.tsx +100 -0
  91. package/dist/examples/vintasend-medplum-example/src/components/labs/CoverageInput.test.tsx +431 -0
  92. package/dist/examples/vintasend-medplum-example/src/components/labs/CoverageInput.tsx +130 -0
  93. package/dist/examples/vintasend-medplum-example/src/components/labs/LabListItem.module.css +31 -0
  94. package/dist/examples/vintasend-medplum-example/src/components/labs/LabListItem.test.tsx +234 -0
  95. package/dist/examples/vintasend-medplum-example/src/components/labs/LabListItem.tsx +143 -0
  96. package/dist/examples/vintasend-medplum-example/src/components/labs/LabOrderDetails.module.css +11 -0
  97. package/dist/examples/vintasend-medplum-example/src/components/labs/LabOrderDetails.test.tsx +875 -0
  98. package/dist/examples/vintasend-medplum-example/src/components/labs/LabOrderDetails.tsx +943 -0
  99. package/dist/examples/vintasend-medplum-example/src/components/labs/LabResultDetails.test.tsx +413 -0
  100. package/dist/examples/vintasend-medplum-example/src/components/labs/LabResultDetails.tsx +203 -0
  101. package/dist/examples/vintasend-medplum-example/src/components/labs/LabSelectEmpty.tsx +22 -0
  102. package/dist/examples/vintasend-medplum-example/src/components/labs/README.md +104 -0
  103. package/dist/examples/vintasend-medplum-example/src/components/labs/TestMetadataCardInput.test.tsx +318 -0
  104. package/dist/examples/vintasend-medplum-example/src/components/labs/TestMetadataCardInput.tsx +87 -0
  105. package/dist/examples/vintasend-medplum-example/src/components/messages/ChatList.test.tsx +126 -0
  106. package/dist/examples/vintasend-medplum-example/src/components/messages/ChatList.tsx +38 -0
  107. package/dist/examples/vintasend-medplum-example/src/components/messages/ChatListItem.module.css +23 -0
  108. package/dist/examples/vintasend-medplum-example/src/components/messages/ChatListItem.test.tsx +167 -0
  109. package/dist/examples/vintasend-medplum-example/src/components/messages/ChatListItem.tsx +53 -0
  110. package/dist/examples/vintasend-medplum-example/src/components/messages/NewTopicDialog.test.tsx +94 -0
  111. package/dist/examples/vintasend-medplum-example/src/components/messages/NewTopicDialog.tsx +165 -0
  112. package/dist/examples/vintasend-medplum-example/src/components/messages/ParticipantFilter.module.css +8 -0
  113. package/dist/examples/vintasend-medplum-example/src/components/messages/ParticipantFilter.test.tsx +523 -0
  114. package/dist/examples/vintasend-medplum-example/src/components/messages/ParticipantFilter.tsx +230 -0
  115. package/dist/examples/vintasend-medplum-example/src/components/messages/ThreadInbox.module.css +23 -0
  116. package/dist/examples/vintasend-medplum-example/src/components/messages/ThreadInbox.test.tsx +567 -0
  117. package/dist/examples/vintasend-medplum-example/src/components/messages/ThreadInbox.tsx +358 -0
  118. package/dist/examples/vintasend-medplum-example/src/components/plandefinition/AddPlanDefinition.module.css +40 -0
  119. package/dist/examples/vintasend-medplum-example/src/components/plandefinition/AddPlanDefinition.tsx +257 -0
  120. package/dist/examples/vintasend-medplum-example/src/components/schedule/CreateVisit.module.css +7 -0
  121. package/dist/examples/vintasend-medplum-example/src/components/schedule/CreateVisit.test.tsx +279 -0
  122. package/dist/examples/vintasend-medplum-example/src/components/schedule/CreateVisit.tsx +156 -0
  123. package/dist/examples/vintasend-medplum-example/src/components/spaces/HistoryList.module.css +45 -0
  124. package/dist/examples/vintasend-medplum-example/src/components/spaces/HistoryList.test.tsx +90 -0
  125. package/dist/examples/vintasend-medplum-example/src/components/spaces/HistoryList.tsx +84 -0
  126. package/dist/examples/vintasend-medplum-example/src/components/spaces/ResourceBox.module.css +26 -0
  127. package/dist/examples/vintasend-medplum-example/src/components/spaces/ResourceBox.tsx +90 -0
  128. package/dist/examples/vintasend-medplum-example/src/components/spaces/ResourcePanel.test.tsx +305 -0
  129. package/dist/examples/vintasend-medplum-example/src/components/spaces/ResourcePanel.tsx +46 -0
  130. package/dist/examples/vintasend-medplum-example/src/components/spaces/SpacesInbox.module.css +262 -0
  131. package/dist/examples/vintasend-medplum-example/src/components/spaces/SpacesInbox.test.tsx +622 -0
  132. package/dist/examples/vintasend-medplum-example/src/components/spaces/SpacesInbox.tsx +286 -0
  133. package/dist/examples/vintasend-medplum-example/src/components/tasks/NewTaskModal.tsx +275 -0
  134. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskAttachmentList.tsx +132 -0
  135. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskBoard.module.css +45 -0
  136. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskBoard.test.tsx +749 -0
  137. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskBoard.tsx +416 -0
  138. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskDetailPanel.test.tsx +278 -0
  139. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskDetailPanel.tsx +133 -0
  140. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskDetailsModal.module.css +16 -0
  141. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskDetailsModal.test.tsx +255 -0
  142. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskDetailsModal.tsx +203 -0
  143. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskFileUpload.tsx +129 -0
  144. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskFilterMenu.test.tsx +156 -0
  145. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskFilterMenu.tsx +142 -0
  146. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskFilterMenu.utils.ts +28 -0
  147. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskInputNote.test.tsx +134 -0
  148. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskInputNote.tsx +250 -0
  149. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskListItem.module.css +23 -0
  150. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskListItem.test.tsx +149 -0
  151. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskListItem.tsx +53 -0
  152. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskNoteItem.test.tsx +68 -0
  153. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskNoteItem.tsx +46 -0
  154. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskProperties.test.tsx +555 -0
  155. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskProperties.tsx +170 -0
  156. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskSelectEmpty.test.tsx +32 -0
  157. package/dist/examples/vintasend-medplum-example/src/components/tasks/TaskSelectEmpty.tsx +34 -0
  158. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/SimpleTask.test.tsx +47 -0
  159. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/SimpleTask.tsx +29 -0
  160. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskPanel.test.tsx +285 -0
  161. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskPanel.tsx +129 -0
  162. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskQuestionnaireForm.test.tsx +455 -0
  163. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskQuestionnaireForm.tsx +167 -0
  164. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskServiceRequest.test.tsx +435 -0
  165. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskServiceRequest.tsx +116 -0
  166. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskStatusPanel.module.css +38 -0
  167. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskStatusPanel.test.tsx +200 -0
  168. package/dist/examples/vintasend-medplum-example/src/components/tasks/encounter/TaskStatusPanel.tsx +84 -0
  169. package/dist/examples/vintasend-medplum-example/src/components/utils.test.ts +176 -0
  170. package/dist/examples/vintasend-medplum-example/src/components/utils.ts +17 -0
  171. package/dist/examples/vintasend-medplum-example/src/config/constants.ts +3 -0
  172. package/dist/examples/vintasend-medplum-example/src/hooks/useDebouncedUpdateResource.test.tsx +166 -0
  173. package/dist/examples/vintasend-medplum-example/src/hooks/useDebouncedUpdateResource.ts +28 -0
  174. package/dist/examples/vintasend-medplum-example/src/hooks/useEncounter.test.tsx +94 -0
  175. package/dist/examples/vintasend-medplum-example/src/hooks/useEncounter.ts +11 -0
  176. package/dist/examples/vintasend-medplum-example/src/hooks/useEncounterChart.test.tsx +477 -0
  177. package/dist/examples/vintasend-medplum-example/src/hooks/useEncounterChart.ts +191 -0
  178. package/dist/examples/vintasend-medplum-example/src/hooks/usePatient.test.tsx +100 -0
  179. package/dist/examples/vintasend-medplum-example/src/hooks/usePatient.ts +18 -0
  180. package/dist/examples/vintasend-medplum-example/src/hooks/useThreadInbox.test.tsx +379 -0
  181. package/dist/examples/vintasend-medplum-example/src/hooks/useThreadInbox.ts +194 -0
  182. package/dist/examples/vintasend-medplum-example/src/index.css +8 -0
  183. package/dist/examples/vintasend-medplum-example/src/main.tsx +57 -0
  184. package/dist/examples/vintasend-medplum-example/src/pages/SearchPage.module.css +6 -0
  185. package/dist/examples/vintasend-medplum-example/src/pages/SearchPage.test.tsx +295 -0
  186. package/dist/examples/vintasend-medplum-example/src/pages/SearchPage.tsx +124 -0
  187. package/dist/examples/vintasend-medplum-example/src/pages/SignInPage.test.tsx +77 -0
  188. package/dist/examples/vintasend-medplum-example/src/pages/SignInPage.tsx +22 -0
  189. package/dist/examples/vintasend-medplum-example/src/pages/encounter/EncounterChartPage.test.tsx +87 -0
  190. package/dist/examples/vintasend-medplum-example/src/pages/encounter/EncounterChartPage.tsx +27 -0
  191. package/dist/examples/vintasend-medplum-example/src/pages/encounter/EncounterModal.module.css +16 -0
  192. package/dist/examples/vintasend-medplum-example/src/pages/encounter/EncounterModal.test.tsx +287 -0
  193. package/dist/examples/vintasend-medplum-example/src/pages/encounter/EncounterModal.tsx +151 -0
  194. package/dist/examples/vintasend-medplum-example/src/pages/integrations/DoseSpotFavoritesPage.test.tsx +519 -0
  195. package/dist/examples/vintasend-medplum-example/src/pages/integrations/DoseSpotFavoritesPage.tsx +179 -0
  196. package/dist/examples/vintasend-medplum-example/src/pages/integrations/FavoriteMedicationsTable.tsx +76 -0
  197. package/dist/examples/vintasend-medplum-example/src/pages/integrations/IntegrationsPage.test.tsx +234 -0
  198. package/dist/examples/vintasend-medplum-example/src/pages/integrations/IntegrationsPage.tsx +222 -0
  199. package/dist/examples/vintasend-medplum-example/src/pages/labs/OrderLabsPage.test.tsx +356 -0
  200. package/dist/examples/vintasend-medplum-example/src/pages/labs/OrderLabsPage.tsx +275 -0
  201. package/dist/examples/vintasend-medplum-example/src/pages/messages/MessagesPage.module.css +8 -0
  202. package/dist/examples/vintasend-medplum-example/src/pages/messages/MessagesPage.test.tsx +103 -0
  203. package/dist/examples/vintasend-medplum-example/src/pages/messages/MessagesPage.tsx +78 -0
  204. package/dist/examples/vintasend-medplum-example/src/pages/patient/CommunicationTab.test.tsx +84 -0
  205. package/dist/examples/vintasend-medplum-example/src/pages/patient/CommunicationTab.tsx +82 -0
  206. package/dist/examples/vintasend-medplum-example/src/pages/patient/DoseSpotAdvancedOptions.test.tsx +364 -0
  207. package/dist/examples/vintasend-medplum-example/src/pages/patient/DoseSpotAdvancedOptions.tsx +149 -0
  208. package/dist/examples/vintasend-medplum-example/src/pages/patient/DoseSpotTab.test.tsx +159 -0
  209. package/dist/examples/vintasend-medplum-example/src/pages/patient/DoseSpotTab.tsx +37 -0
  210. package/dist/examples/vintasend-medplum-example/src/pages/patient/EditTab.test.tsx +140 -0
  211. package/dist/examples/vintasend-medplum-example/src/pages/patient/EditTab.tsx +72 -0
  212. package/dist/examples/vintasend-medplum-example/src/pages/patient/ExportTab.test.tsx +57 -0
  213. package/dist/examples/vintasend-medplum-example/src/pages/patient/ExportTab.tsx +14 -0
  214. package/dist/examples/vintasend-medplum-example/src/pages/patient/IntakeFormPage.test.tsx +241 -0
  215. package/dist/examples/vintasend-medplum-example/src/pages/patient/IntakeFormPage.tsx +710 -0
  216. package/dist/examples/vintasend-medplum-example/src/pages/patient/LabsPage.module.css +37 -0
  217. package/dist/examples/vintasend-medplum-example/src/pages/patient/LabsPage.test.tsx +428 -0
  218. package/dist/examples/vintasend-medplum-example/src/pages/patient/LabsPage.tsx +334 -0
  219. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientPage.module.css +24 -0
  220. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientPage.test.tsx +154 -0
  221. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientPage.tsx +115 -0
  222. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientPage.utils.test.ts +223 -0
  223. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientPage.utils.ts +89 -0
  224. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientSearchPage.test.tsx +147 -0
  225. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientSearchPage.tsx +79 -0
  226. package/dist/examples/vintasend-medplum-example/src/pages/patient/PatientTabsNavigation.tsx +35 -0
  227. package/dist/examples/vintasend-medplum-example/src/pages/patient/TasksTab.test.tsx +185 -0
  228. package/dist/examples/vintasend-medplum-example/src/pages/patient/TasksTab.tsx +115 -0
  229. package/dist/examples/vintasend-medplum-example/src/pages/patient/TimelineTab.tsx +14 -0
  230. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceCreatePage.test.tsx +170 -0
  231. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceCreatePage.tsx +117 -0
  232. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceDetailPage.tsx +28 -0
  233. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceEditPage.test.tsx +131 -0
  234. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceEditPage.tsx +65 -0
  235. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceHistoryPage.test.tsx +108 -0
  236. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourceHistoryPage.tsx +16 -0
  237. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourcePage.module.css +7 -0
  238. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourcePage.test.tsx +37 -0
  239. package/dist/examples/vintasend-medplum-example/src/pages/resource/ResourcePage.tsx +44 -0
  240. package/dist/examples/vintasend-medplum-example/src/pages/resource/useResourceType.ts +44 -0
  241. package/dist/examples/vintasend-medplum-example/src/pages/resource/utils.ts +9 -0
  242. package/dist/examples/vintasend-medplum-example/src/pages/schedule/SchedulePage.test.tsx +302 -0
  243. package/dist/examples/vintasend-medplum-example/src/pages/schedule/SchedulePage.tsx +416 -0
  244. package/dist/examples/vintasend-medplum-example/src/pages/spaces/ChatInput.tsx +91 -0
  245. package/dist/examples/vintasend-medplum-example/src/pages/spaces/SpacesPage.module.css +6 -0
  246. package/dist/examples/vintasend-medplum-example/src/pages/spaces/SpacesPage.test.tsx +102 -0
  247. package/dist/examples/vintasend-medplum-example/src/pages/spaces/SpacesPage.tsx +44 -0
  248. package/dist/examples/vintasend-medplum-example/src/pages/tasks/TasksPage.module.css +7 -0
  249. package/dist/examples/vintasend-medplum-example/src/pages/tasks/TasksPage.test.tsx +133 -0
  250. package/dist/examples/vintasend-medplum-example/src/pages/tasks/TasksPage.tsx +91 -0
  251. package/dist/examples/vintasend-medplum-example/src/test-utils/render.tsx +20 -0
  252. package/dist/examples/vintasend-medplum-example/src/test.setup.ts +49 -0
  253. package/dist/examples/vintasend-medplum-example/src/types/encounter.ts +8 -0
  254. package/dist/examples/vintasend-medplum-example/src/types/spaces.ts +10 -0
  255. package/dist/examples/vintasend-medplum-example/src/utils/chargeitems.test.ts +141 -0
  256. package/dist/examples/vintasend-medplum-example/src/utils/chargeitems.ts +59 -0
  257. package/dist/examples/vintasend-medplum-example/src/utils/claims.test.ts +153 -0
  258. package/dist/examples/vintasend-medplum-example/src/utils/claims.ts +65 -0
  259. package/dist/examples/vintasend-medplum-example/src/utils/communication-search.ts +47 -0
  260. package/dist/examples/vintasend-medplum-example/src/utils/coverage.test.ts +48 -0
  261. package/dist/examples/vintasend-medplum-example/src/utils/coverage.ts +33 -0
  262. package/dist/examples/vintasend-medplum-example/src/utils/documentReference.test.ts +102 -0
  263. package/dist/examples/vintasend-medplum-example/src/utils/documentReference.ts +55 -0
  264. package/dist/examples/vintasend-medplum-example/src/utils/encounter.test.ts +169 -0
  265. package/dist/examples/vintasend-medplum-example/src/utils/encounter.ts +261 -0
  266. package/dist/examples/vintasend-medplum-example/src/utils/intake-form.test.ts +154 -0
  267. package/dist/examples/vintasend-medplum-example/src/utils/intake-form.ts +272 -0
  268. package/dist/examples/vintasend-medplum-example/src/utils/intake-utils.test.ts +1137 -0
  269. package/dist/examples/vintasend-medplum-example/src/utils/intake-utils.ts +827 -0
  270. package/dist/examples/vintasend-medplum-example/src/utils/notifications.test.ts +27 -0
  271. package/dist/examples/vintasend-medplum-example/src/utils/notifications.ts +15 -0
  272. package/dist/examples/vintasend-medplum-example/src/utils/spaceMessaging.ts +249 -0
  273. package/dist/examples/vintasend-medplum-example/src/utils/spacePersistence.test.ts +450 -0
  274. package/dist/examples/vintasend-medplum-example/src/utils/spacePersistence.ts +147 -0
  275. package/dist/examples/vintasend-medplum-example/src/utils/task-search.ts +63 -0
  276. package/dist/examples/vintasend-medplum-example/src/vite-env.d.ts +3 -0
  277. package/dist/examples/vintasend-medplum-example/tsconfig.bots.json +4 -0
  278. package/dist/examples/vintasend-medplum-example/tsconfig.json +19 -0
  279. package/dist/examples/vintasend-medplum-example/vercel.json +3 -0
  280. package/dist/examples/vintasend-medplum-example/vite.config.ts +44 -0
  281. package/dist/services/notification-backends/base-notification-backend.d.ts +5 -0
  282. package/dist/services/notification-service.js +11 -1
  283. package/dist/services/notification-template-renderers/base-email-template-renderer.d.ts +5 -0
  284. package/package.json +1 -1
@@ -0,0 +1,100 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { renderHook, waitFor } from '@testing-library/react';
4
+ import { MedplumProvider } from '@medplum/react';
5
+ import type { JSX } from 'react';
6
+ import type { Patient } from '@medplum/fhirtypes';
7
+ import { MockClient } from '@medplum/mock';
8
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
9
+ import { usePatient } from './usePatient';
10
+
11
+ vi.mock('react-router', async () => {
12
+ const actual = await vi.importActual('react-router');
13
+ return {
14
+ ...actual,
15
+ useParams: vi.fn(),
16
+ };
17
+ });
18
+
19
+ import { useParams } from 'react-router';
20
+
21
+ describe('usePatient', () => {
22
+ let medplum: MockClient;
23
+
24
+ beforeEach(async () => {
25
+ medplum = new MockClient();
26
+ vi.clearAllMocks();
27
+ vi.mocked(useParams).mockReturnValue({});
28
+ });
29
+
30
+ const wrapper = ({ children }: { children: React.ReactNode }): JSX.Element => (
31
+ <MedplumProvider medplum={medplum}>{children}</MedplumProvider>
32
+ );
33
+
34
+ test('returns undefined when patient ID is not found in params', () => {
35
+ vi.mocked(useParams).mockReturnValue({});
36
+
37
+ expect(() => {
38
+ renderHook(() => usePatient(), { wrapper });
39
+ }).toThrow('Patient ID not found');
40
+ });
41
+
42
+ test('returns undefined when patient ID is missing but ignoreMissingPatientId is true', () => {
43
+ vi.mocked(useParams).mockReturnValue({});
44
+
45
+ const { result } = renderHook(() => usePatient({ ignoreMissingPatientId: true }), { wrapper });
46
+
47
+ expect(result.current).toBeUndefined();
48
+ });
49
+
50
+ test('loads patient resource by ID from URL params', async () => {
51
+ const mockPatient: Patient = {
52
+ resourceType: 'Patient',
53
+ id: 'patient-123',
54
+ name: [{ given: ['John'], family: 'Doe' }],
55
+ };
56
+
57
+ await medplum.createResource(mockPatient);
58
+ vi.mocked(useParams).mockReturnValue({ patientId: 'patient-123' });
59
+
60
+ const { result } = renderHook(() => usePatient(), { wrapper });
61
+
62
+ await waitFor(() => {
63
+ expect(result.current).toBeDefined();
64
+ expect(result.current?.id).toBe('patient-123');
65
+ expect(result.current?.name?.[0]?.given?.[0]).toBe('John');
66
+ expect(result.current?.name?.[0]?.family).toBe('Doe');
67
+ });
68
+ });
69
+
70
+ test('calls setOutcome callback when patient is not found', async () => {
71
+ const setOutcome = vi.fn();
72
+ vi.mocked(useParams).mockReturnValue({ patientId: 'patient-nonexistent' });
73
+
74
+ const { result } = renderHook(() => usePatient({ setOutcome }), { wrapper });
75
+
76
+ await waitFor(() => {
77
+ expect(setOutcome).toHaveBeenCalled();
78
+ });
79
+
80
+ expect(result.current).toBeUndefined();
81
+ });
82
+
83
+ test('handles patient reference correctly', async () => {
84
+ const mockPatient: Patient = {
85
+ resourceType: 'Patient',
86
+ id: 'patient-456',
87
+ name: [{ given: ['Jane'], family: 'Smith' }],
88
+ };
89
+
90
+ await medplum.createResource(mockPatient);
91
+ vi.mocked(useParams).mockReturnValue({ patientId: 'patient-456' });
92
+
93
+ const { result } = renderHook(() => usePatient(), { wrapper });
94
+
95
+ await waitFor(() => {
96
+ expect(result.current?.id).toBe('patient-456');
97
+ expect(result.current?.name?.[0]?.given?.[0]).toBe('Jane');
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,18 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { OperationOutcome, Patient } from '@medplum/fhirtypes';
4
+ import { useResource } from '@medplum/react';
5
+ import { useParams } from 'react-router';
6
+
7
+ type Options = {
8
+ ignoreMissingPatientId?: boolean;
9
+ setOutcome?: (outcome: OperationOutcome) => void;
10
+ };
11
+
12
+ export function usePatient(options?: Options): Patient | undefined {
13
+ const { patientId } = useParams();
14
+ if (!patientId && !options?.ignoreMissingPatientId) {
15
+ throw new Error('Patient ID not found');
16
+ }
17
+ return useResource<Patient>({ reference: `Patient/${patientId}` }, options?.setOutcome);
18
+ }
@@ -0,0 +1,379 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { renderHook, waitFor, act } from '@testing-library/react';
4
+ import { MedplumProvider } from '@medplum/react';
5
+ import type { JSX } from 'react';
6
+ import type { Communication } from '@medplum/fhirtypes';
7
+ import { MockClient } from '@medplum/mock';
8
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
9
+ import { useThreadInbox } from './useThreadInbox';
10
+ import type { WithId } from '@medplum/core';
11
+
12
+ const mockCommunication1: Communication = {
13
+ resourceType: 'Communication',
14
+ id: 'comm-1',
15
+ status: 'completed',
16
+ sent: '2024-01-01T10:00:00Z',
17
+ payload: [{ contentString: 'First message' }],
18
+ };
19
+
20
+ const mockCommunication2: Communication = {
21
+ resourceType: 'Communication',
22
+ id: 'comm-2',
23
+ status: 'completed',
24
+ sent: '2024-01-01T11:00:00Z',
25
+ payload: [{ contentString: 'Second message' }],
26
+ partOf: [{ reference: 'Communication/comm-1' }],
27
+ };
28
+
29
+ describe('useThreadInbox', () => {
30
+ let medplum: MockClient;
31
+
32
+ beforeEach(async () => {
33
+ medplum = new MockClient();
34
+ vi.clearAllMocks();
35
+ });
36
+
37
+ const wrapper = ({ children }: { children: React.ReactNode }): JSX.Element => (
38
+ <MedplumProvider medplum={medplum}>{children}</MedplumProvider>
39
+ );
40
+
41
+ test('returns initial loading state', () => {
42
+ const { result } = renderHook(() => useThreadInbox({ query: '', threadId: undefined }), { wrapper });
43
+
44
+ expect(result.current.loading).toBe(true);
45
+ expect(result.current.threadMessages).toEqual([]);
46
+ expect(result.current.selectedThread).toBeUndefined();
47
+ expect(result.current.error).toBeNull();
48
+ expect(result.current.total).toBeUndefined();
49
+ });
50
+
51
+ test('fetches thread messages and returns only one message per topic', async () => {
52
+ const mockCommunication4: Communication = {
53
+ resourceType: 'Communication',
54
+ id: 'comm-4',
55
+ status: 'completed',
56
+ sent: '2024-01-01T13:00:00Z',
57
+ payload: [{ contentString: 'Fourth message' }],
58
+ partOf: [{ reference: 'Communication/comm-1' }],
59
+ };
60
+
61
+ vi.spyOn(medplum, 'search').mockResolvedValue({
62
+ resourceType: 'Bundle',
63
+ type: 'searchset',
64
+ total: 1,
65
+ entry: [{ resource: mockCommunication1 as WithId<Communication> }],
66
+ });
67
+
68
+ const graphqlSpy = vi.spyOn(medplum, 'graphql').mockResolvedValue({
69
+ data: {
70
+ thread_comm1: [mockCommunication4],
71
+ },
72
+ } as any);
73
+
74
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: undefined }), {
75
+ wrapper,
76
+ });
77
+
78
+ await waitFor(() => {
79
+ expect(result.current.loading).toBe(false);
80
+ });
81
+
82
+ expect(graphqlSpy).toHaveBeenCalled();
83
+
84
+ await waitFor(() => {
85
+ expect(result.current.threadMessages).toHaveLength(1);
86
+ expect(result.current.threadMessages[0][0].id).toBe('comm-1');
87
+ expect(result.current.threadMessages[0][1]?.id).toBe('comm-4');
88
+ });
89
+ });
90
+
91
+ test('skips topics without messages', async () => {
92
+ const parentWithoutMessages: Communication = {
93
+ resourceType: 'Communication',
94
+ id: 'comm-no-replies',
95
+ status: 'completed',
96
+ sent: '2024-01-01T10:00:00Z',
97
+ payload: [{ contentString: 'Parent with no replies' }],
98
+ };
99
+
100
+ const parentWithMessages: Communication = {
101
+ resourceType: 'Communication',
102
+ id: 'comm-with-replies',
103
+ status: 'completed',
104
+ sent: '2024-01-01T11:00:00Z',
105
+ payload: [{ contentString: 'Parent with replies' }],
106
+ };
107
+
108
+ const replyMessage: Communication = {
109
+ resourceType: 'Communication',
110
+ id: 'comm-reply',
111
+ status: 'completed',
112
+ sent: '2024-01-01T12:00:00Z',
113
+ payload: [{ contentString: 'Reply message' }],
114
+ partOf: [{ reference: 'Communication/comm-with-replies' }],
115
+ };
116
+
117
+ vi.spyOn(medplum, 'search').mockResolvedValue({
118
+ resourceType: 'Bundle',
119
+ type: 'searchset',
120
+ total: 2,
121
+ entry: [
122
+ { resource: parentWithoutMessages as WithId<Communication> },
123
+ { resource: parentWithMessages as WithId<Communication> },
124
+ ],
125
+ });
126
+
127
+ vi.spyOn(medplum, 'graphql').mockResolvedValue({
128
+ data: {
129
+ thread_commnoreplies: [],
130
+ thread_commwithreplies: [replyMessage],
131
+ },
132
+ } as any);
133
+
134
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: undefined }), {
135
+ wrapper,
136
+ });
137
+
138
+ await waitFor(() => {
139
+ expect(result.current.loading).toBe(false);
140
+ });
141
+
142
+ await waitFor(() => {
143
+ expect(result.current.threadMessages).toHaveLength(1);
144
+ expect(result.current.threadMessages[0][0].id).toBe('comm-with-replies');
145
+ expect(result.current.threadMessages[0][1]?.id).toBe('comm-reply');
146
+ expect(result.current.threadMessages.find((t) => t[0].id === 'comm-no-replies')).toBeUndefined();
147
+ });
148
+ });
149
+
150
+ test('selects thread by threadId', async () => {
151
+ await medplum.createResource(mockCommunication1);
152
+ await medplum.createResource(mockCommunication2);
153
+
154
+ vi.spyOn(medplum, 'graphql').mockResolvedValue({
155
+ data: {
156
+ thread_comm1: [mockCommunication2],
157
+ },
158
+ } as any);
159
+
160
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: 'comm-1' }), {
161
+ wrapper,
162
+ });
163
+
164
+ await waitFor(() => {
165
+ expect(result.current.loading).toBe(false);
166
+ });
167
+
168
+ await waitFor(() => {
169
+ expect(result.current.selectedThread?.id).toBe('comm-1');
170
+ });
171
+ });
172
+
173
+ test('reads thread from API when threadId not found in messages', async () => {
174
+ // Don't create the resource, so it won't be found in search
175
+ // This simulates a thread that exists but isn't in the current search results
176
+
177
+ const readSpy = vi.spyOn(medplum, 'readResource').mockResolvedValue(mockCommunication1 as WithId<Communication>);
178
+
179
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: 'comm-1' }), {
180
+ wrapper,
181
+ });
182
+
183
+ await waitFor(() => {
184
+ expect(result.current.loading).toBe(false);
185
+ });
186
+
187
+ await waitFor(() => {
188
+ expect(readSpy).toHaveBeenCalledWith('Communication', 'comm-1');
189
+ expect(result.current.selectedThread?.id).toBe('comm-1');
190
+ });
191
+ });
192
+
193
+ test('reads parent thread when reading child communication with partOf field', async () => {
194
+ const parentCommunication: Communication = {
195
+ resourceType: 'Communication',
196
+ id: 'comm-0',
197
+ status: 'completed',
198
+ sent: '2024-01-01T09:00:00Z',
199
+ payload: [{ contentString: 'Parent message' }],
200
+ };
201
+
202
+ const communicationWithPartOf: Communication = {
203
+ ...mockCommunication1,
204
+ partOf: [{ reference: 'Communication/comm-0' }],
205
+ };
206
+
207
+ vi.spyOn(medplum, 'readResource').mockResolvedValue(communicationWithPartOf as WithId<Communication>);
208
+
209
+ const readReferenceSpy = vi.spyOn(medplum, 'readReference').mockResolvedValue(parentCommunication as any);
210
+
211
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: 'comm-1' }), {
212
+ wrapper,
213
+ });
214
+
215
+ await waitFor(() => {
216
+ expect(result.current.loading).toBe(false);
217
+ });
218
+
219
+ await waitFor(() => {
220
+ expect(readReferenceSpy).toHaveBeenCalledWith({ reference: 'Communication/comm-0' });
221
+ expect(result.current.selectedThread?.id).toBe('comm-0');
222
+ });
223
+ });
224
+
225
+ test('handles thread status update', async () => {
226
+ vi.spyOn(medplum, 'search').mockResolvedValue({
227
+ resourceType: 'Bundle',
228
+ type: 'searchset',
229
+ total: 1,
230
+ entry: [{ resource: mockCommunication1 as WithId<Communication> }],
231
+ });
232
+
233
+ vi.spyOn(medplum, 'graphql').mockResolvedValue({
234
+ data: {
235
+ thread_comm1: [mockCommunication2],
236
+ },
237
+ } as any);
238
+
239
+ const updatedCommunication: Communication = {
240
+ ...mockCommunication1,
241
+ status: 'in-progress',
242
+ };
243
+
244
+ const updateSpy = vi
245
+ .spyOn(medplum, 'updateResource')
246
+ .mockResolvedValue(updatedCommunication as WithId<Communication>);
247
+
248
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: 'comm-1' }), {
249
+ wrapper,
250
+ });
251
+
252
+ await waitFor(() => {
253
+ expect(result.current.selectedThread?.id).toBe('comm-1');
254
+ });
255
+
256
+ await act(async () => result.current.handleThreadStatusChange('in-progress'));
257
+
258
+ await waitFor(() => {
259
+ expect(updateSpy).toHaveBeenCalled();
260
+ expect(result.current.selectedThread?.status).toBe('in-progress');
261
+ expect(result.current.threadMessages[0][0].status).toBe('in-progress');
262
+ });
263
+ });
264
+
265
+ test('does not update status when no thread is selected', async () => {
266
+ const updateSpy = vi.spyOn(medplum, 'updateResource');
267
+
268
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: undefined }), {
269
+ wrapper,
270
+ });
271
+
272
+ await waitFor(() => {
273
+ expect(result.current.loading).toBe(false);
274
+ });
275
+
276
+ await result.current.handleThreadStatusChange('in-progress');
277
+
278
+ expect(updateSpy).not.toHaveBeenCalled();
279
+ });
280
+
281
+ test('handles update errors gracefully', async () => {
282
+ await medplum.createResource(mockCommunication1);
283
+ await medplum.createResource(mockCommunication2);
284
+
285
+ vi.spyOn(medplum, 'graphql').mockResolvedValue({
286
+ data: {
287
+ thread_comm1: [mockCommunication2],
288
+ },
289
+ } as any);
290
+
291
+ const error = new Error('Update failed');
292
+ vi.spyOn(medplum, 'updateResource').mockRejectedValue(error);
293
+
294
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: 'comm-1' }), {
295
+ wrapper,
296
+ });
297
+
298
+ await waitFor(() => {
299
+ expect(result.current.selectedThread?.id).toBe('comm-1');
300
+ });
301
+
302
+ await act(async () => result.current.handleThreadStatusChange('in-progress'));
303
+
304
+ await waitFor(() => {
305
+ expect(result.current.error).toBe(error);
306
+ });
307
+ });
308
+
309
+ test('adds new thread message', async () => {
310
+ const newMessage: Communication = {
311
+ resourceType: 'Communication',
312
+ id: 'comm-new',
313
+ status: 'completed',
314
+ sent: '2024-01-01T13:00:00Z',
315
+ payload: [{ contentString: 'New message' }],
316
+ };
317
+
318
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: undefined }), {
319
+ wrapper,
320
+ });
321
+
322
+ await waitFor(() => {
323
+ expect(result.current.loading).toBe(false);
324
+ });
325
+
326
+ await act(async () => {
327
+ result.current.addThreadMessage(newMessage);
328
+ });
329
+
330
+ await waitFor(() => {
331
+ expect(result.current.threadMessages).toHaveLength(1);
332
+ expect(result.current.threadMessages[0][0].id).toBe('comm-new');
333
+ expect(result.current.threadMessages[0][1]).toBeUndefined();
334
+ });
335
+ });
336
+
337
+ test('handles search errors gracefully', async () => {
338
+ const error = new Error('Search failed');
339
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
340
+ vi.spyOn(medplum, 'search').mockRejectedValue(error);
341
+
342
+ const { result } = renderHook(() => useThreadInbox({ query: 'status=completed', threadId: undefined }), {
343
+ wrapper,
344
+ });
345
+
346
+ await waitFor(() => {
347
+ expect(result.current.loading).toBe(false);
348
+ expect(result.current.error).toBe(error);
349
+ });
350
+
351
+ consoleErrorSpy.mockRestore();
352
+ });
353
+
354
+ test('clears selected thread when threadId becomes undefined', async () => {
355
+ await medplum.createResource(mockCommunication1);
356
+ await medplum.createResource(mockCommunication2);
357
+
358
+ vi.spyOn(medplum, 'graphql').mockResolvedValue({
359
+ data: {
360
+ thread_comm1: [mockCommunication2],
361
+ },
362
+ } as any);
363
+
364
+ const { result, rerender } = renderHook(({ threadId }) => useThreadInbox({ query: 'status=completed', threadId }), {
365
+ wrapper,
366
+ initialProps: { threadId: 'comm-1' as string | undefined },
367
+ });
368
+
369
+ await waitFor(() => {
370
+ expect(result.current.selectedThread?.id).toBe('comm-1');
371
+ });
372
+
373
+ rerender({ threadId: undefined });
374
+
375
+ await waitFor(() => {
376
+ expect(result.current.selectedThread).toBeUndefined();
377
+ });
378
+ });
379
+ });
@@ -0,0 +1,194 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { useState, useEffect, useCallback } from 'react';
4
+ import type { Communication } from '@medplum/fhirtypes';
5
+ import { useMedplum } from '@medplum/react';
6
+ import { getReferenceString } from '@medplum/core';
7
+
8
+ export interface UseThreadInboxOptions {
9
+ query: string;
10
+ threadId: string | undefined;
11
+ }
12
+
13
+ export interface UseThreadInboxReturn {
14
+ loading: boolean;
15
+ error: Error | null;
16
+ // Tuple: [Parent Thread, Last Message in Thread (optional)]
17
+ threadMessages: [Communication, Communication | undefined][];
18
+ selectedThread: Communication | undefined;
19
+ total: number | undefined;
20
+ addThreadMessage: (message: Communication) => void;
21
+ handleThreadStatusChange: (newStatus: Communication['status']) => Promise<void>;
22
+ refreshThreadMessages: () => Promise<void>;
23
+ }
24
+
25
+ /*
26
+ useThreadInbox is a hook that fetches all communications and returns the thread messages and selected thread.
27
+ All comunications returned do not have a partOf field.
28
+ It also provides a function to update the status of the selected thread.
29
+
30
+ @param query - The query to fetch all communications.
31
+ @param threadId - The id of the thread to select.
32
+ @returns The thread messages and selected thread.
33
+ @returns A function to update the status of the selected thread.
34
+ */
35
+ export function useThreadInbox({ query, threadId }: UseThreadInboxOptions): UseThreadInboxReturn {
36
+ const medplum = useMedplum();
37
+ const [loading, setLoading] = useState(true);
38
+ const [threadMessages, setThreadMessages] = useState<[Communication, Communication | undefined][]>([]);
39
+ const [selectedThread, setSelectedThread] = useState<Communication | undefined>(undefined);
40
+ const [error, setError] = useState<Error | null>(null);
41
+ const [total, setTotal] = useState<number | undefined>(undefined);
42
+
43
+ const fetchAllCommunications = useCallback(async (): Promise<void> => {
44
+ const searchParams = new URLSearchParams(query);
45
+ searchParams.append('identifier:not', 'ai-message-topic');
46
+ searchParams.append('part-of:missing', 'true');
47
+ searchParams.append('_has:Communication:part-of:_id:not', 'null');
48
+
49
+ const bundle = await medplum.search('Communication', searchParams.toString(), { cache: 'no-cache' });
50
+ const parents =
51
+ bundle.entry
52
+ ?.map((entry) => entry.resource as Communication)
53
+ .filter((r): r is Communication => r !== undefined) || [];
54
+
55
+ if (bundle.total !== undefined) {
56
+ setTotal(bundle.total);
57
+ }
58
+
59
+ if (parents.length === 0) {
60
+ setThreadMessages([]);
61
+ return;
62
+ }
63
+
64
+ const queryParts = parents.map((parent) => {
65
+ const safeId = parent.id?.replace(/-/g, '') || '';
66
+ const alias = `thread_${safeId}`;
67
+ const ref = getReferenceString(parent);
68
+
69
+ return `
70
+ ${alias}: CommunicationList(
71
+ part_of: "${ref}"
72
+ _sort: "-sent"
73
+ _count: 1
74
+ ) {
75
+ id
76
+ meta {
77
+ lastUpdated
78
+ }
79
+ partOf {
80
+ reference
81
+ }
82
+ sender {
83
+ display
84
+ reference
85
+ }
86
+ payload {
87
+ contentString
88
+ }
89
+ sent
90
+ status
91
+ }
92
+ `;
93
+ });
94
+
95
+ const fullQuery = `
96
+ query {
97
+ ${queryParts.join('\n')}
98
+ }
99
+ `;
100
+
101
+ const response = await medplum.graphql(fullQuery);
102
+
103
+ const threadsWithReplies = parents
104
+ .map((parent) => {
105
+ const safeId = parent.id?.replace(/-/g, '') || '';
106
+ const alias = `thread_${safeId}`;
107
+ const childList = response.data[alias] as Communication[] | undefined;
108
+ const lastMessage = childList && childList.length > 0 ? childList[0] : undefined;
109
+ return [parent, lastMessage];
110
+ })
111
+ .filter((thread): thread is [Communication, Communication] => thread[1] !== undefined);
112
+
113
+ setThreadMessages(threadsWithReplies);
114
+ }, [medplum, query]);
115
+
116
+ useEffect(() => {
117
+ setLoading(true);
118
+ fetchAllCommunications()
119
+ .catch((err: Error) => {
120
+ setError(err);
121
+ })
122
+ .finally(() => {
123
+ setLoading(false);
124
+ });
125
+ }, [fetchAllCommunications]);
126
+
127
+ useEffect(() => {
128
+ const fetchThread = async (): Promise<void> => {
129
+ if (threadId) {
130
+ const thread = threadMessages.find((t) => t[0].id === threadId);
131
+ if (thread) {
132
+ setSelectedThread(thread[0]);
133
+ } else {
134
+ try {
135
+ const communication: Communication = await medplum.readResource('Communication', threadId);
136
+
137
+ if (communication.partOf === undefined) {
138
+ setSelectedThread(communication);
139
+ } else {
140
+ const parentRef = communication.partOf[0].reference;
141
+ if (parentRef) {
142
+ const parent = await medplum.readReference({ reference: parentRef } as any);
143
+ setSelectedThread(parent as Communication);
144
+ }
145
+ }
146
+ } catch (err) {
147
+ setError(err as Error);
148
+ }
149
+ }
150
+ } else {
151
+ setSelectedThread(undefined);
152
+ }
153
+ };
154
+
155
+ fetchThread().catch((err) => {
156
+ setError(err as Error);
157
+ });
158
+ }, [threadId, threadMessages, medplum]);
159
+
160
+ const handleThreadStatusChange = async (newStatus: Communication['status']): Promise<void> => {
161
+ if (!selectedThread) {
162
+ return;
163
+ }
164
+ try {
165
+ const updatedThread = await medplum.updateResource({
166
+ ...selectedThread,
167
+ status: newStatus,
168
+ });
169
+
170
+ setSelectedThread(updatedThread);
171
+ setThreadMessages((prev) =>
172
+ prev.map(([parent, lastMsg]) => (parent.id === updatedThread.id ? [updatedThread, lastMsg] : [parent, lastMsg]))
173
+ );
174
+ } catch (err) {
175
+ setError(err as Error);
176
+ }
177
+ };
178
+
179
+ const addThreadMessage = async (message: Communication): Promise<void> => {
180
+ await fetchAllCommunications();
181
+ setThreadMessages((prev) => [[message, undefined], ...prev]);
182
+ };
183
+
184
+ return {
185
+ loading,
186
+ error,
187
+ threadMessages,
188
+ selectedThread,
189
+ total,
190
+ addThreadMessage,
191
+ handleThreadStatusChange,
192
+ refreshThreadMessages: fetchAllCommunications,
193
+ };
194
+ }
@@ -0,0 +1,8 @@
1
+ .rbc-calendar {
2
+ font-family:
3
+ -apple-system, 'system-ui', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
4
+ }
5
+
6
+ .rbc-btn-group button {
7
+ font-size: 14px;
8
+ }