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,65 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { CPT, getReferenceString } from '@medplum/core';
4
+ import type { MedplumClient } from '@medplum/core';
5
+ import type { ChargeItem, Claim, ClaimItem, Coverage, Encounter, Reference } from '@medplum/fhirtypes';
6
+ import { calculateTotalPrice } from './chargeitems';
7
+ import { createSelfPayCoverage } from './coverage';
8
+
9
+ export async function createClaimFromEncounter(
10
+ medplum: MedplumClient,
11
+ patientId: string,
12
+ encounterId: string,
13
+ practitionerId: string,
14
+ chargeItems: ChargeItem[]
15
+ ): Promise<Claim | undefined> {
16
+ const coverageResults = await medplum.searchResources('Coverage', `patient=Patient/${patientId}&status=active`);
17
+ let coverage: Coverage = coverageResults[0];
18
+ if (!coverage) {
19
+ coverage = await createSelfPayCoverage(medplum, patientId);
20
+ }
21
+
22
+ const claim: Claim = {
23
+ resourceType: 'Claim',
24
+ status: 'draft',
25
+ type: { coding: [{ code: 'professional' }] },
26
+ use: 'claim',
27
+ created: new Date().toISOString(),
28
+ patient: { reference: `Patient/${patientId}` },
29
+ provider: { reference: `Practitioner/${practitionerId}`, type: 'Practitioner' },
30
+ priority: { coding: [{ code: 'normal' }] },
31
+ insurance: [
32
+ {
33
+ sequence: 1,
34
+ focal: true,
35
+ coverage: { reference: getReferenceString(coverage) },
36
+ },
37
+ ],
38
+ item: getCptChargeItems(chargeItems, { reference: `Encounter/${encounterId}` }),
39
+ total: { value: calculateTotalPrice(chargeItems) },
40
+ };
41
+ return medplum.createResource(claim);
42
+ }
43
+
44
+ export function getCptChargeItems(chargeItems: ChargeItem[], encounter: Reference<Encounter>): ClaimItem[] {
45
+ const cptChargeItems = chargeItems.filter((item) => item.code?.coding?.some((coding) => coding.system === CPT));
46
+ return cptChargeItems.map((chargeItem: ChargeItem, index: number) => {
47
+ const modifiers = chargeItem.extension
48
+ ?.filter((ext) => ext.url === 'http://hl7.org/fhir/StructureDefinition/chargeitem-modifier')
49
+ .map((ext) => {
50
+ return ext.valueCodeableConcept;
51
+ })
52
+ .filter((modifier) => modifier !== undefined);
53
+
54
+ return {
55
+ sequence: index + 1,
56
+ encounter: [encounter],
57
+ productOrService: {
58
+ coding: chargeItem.code.coding?.filter((coding) => coding.system === CPT),
59
+ text: chargeItem.code.text,
60
+ },
61
+ net: chargeItem.priceOverride,
62
+ ...(modifiers && modifiers.length > 0 ? { modifier: modifiers } : {}),
63
+ };
64
+ });
65
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { parseSearchRequest } from '@medplum/core';
5
+ import type { SearchRequest } from '@medplum/core';
6
+
7
+ export interface NormalizeCommunicationSearchOptions {
8
+ search?: string;
9
+ defaultSort?: string;
10
+ defaultStatus?: string;
11
+ defaultCount?: string;
12
+ defaultTotal?: string;
13
+ }
14
+
15
+ export interface NormalizeCommunicationSearchResult {
16
+ normalizedSearch: string;
17
+ parsedSearch: SearchRequest;
18
+ }
19
+
20
+ export function normalizeCommunicationSearch({
21
+ search = '',
22
+ defaultSort = '-_lastUpdated',
23
+ defaultStatus = 'in-progress',
24
+ defaultCount = '20',
25
+ defaultTotal = 'accurate',
26
+ }: NormalizeCommunicationSearchOptions): NormalizeCommunicationSearchResult {
27
+ const params = new URLSearchParams(search || `_sort=${defaultSort}`);
28
+ const entries = Array.from(params.entries());
29
+
30
+ const addIfMissing = (key: string, value: string | undefined): void => {
31
+ if (value && !params.has(key)) {
32
+ entries.push([key, value]);
33
+ }
34
+ };
35
+
36
+ addIfMissing('_sort', defaultSort);
37
+ addIfMissing('status', defaultStatus);
38
+ addIfMissing('_count', defaultCount);
39
+ addIfMissing('_total', defaultTotal);
40
+
41
+ const normalizedSearch = new URLSearchParams(entries).toString();
42
+
43
+ return {
44
+ normalizedSearch,
45
+ parsedSearch: parseSearchRequest(`Communication?${normalizedSearch}`),
46
+ };
47
+ }
@@ -0,0 +1,48 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { Coverage } from '@medplum/fhirtypes';
4
+ import { MockClient } from '@medplum/mock';
5
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
6
+ import { createSelfPayCoverage } from './coverage';
7
+
8
+ describe('createSelfPayCoverage', () => {
9
+ let medplum: MockClient;
10
+
11
+ beforeEach(() => {
12
+ medplum = new MockClient();
13
+ });
14
+
15
+ test('creates a self-pay coverage for patient', async () => {
16
+ const createdCoverage: Coverage = {
17
+ resourceType: 'Coverage',
18
+ id: 'coverage-123',
19
+ status: 'active',
20
+ beneficiary: { reference: 'Patient/patient-123' },
21
+ payor: [{ reference: 'Patient/patient-123' }],
22
+ type: {
23
+ coding: [{ code: 'SELFPAY', display: 'Self Pay' }],
24
+ },
25
+ period: {
26
+ start: new Date().toISOString(),
27
+ },
28
+ };
29
+ const createSpy = vi.spyOn(medplum, 'createResource').mockResolvedValue(createdCoverage as any);
30
+
31
+ const result = await createSelfPayCoverage(medplum as any, 'patient-123');
32
+
33
+ expect(createSpy).toHaveBeenCalledWith(
34
+ expect.objectContaining({
35
+ subscriber: { reference: 'Patient/patient-123' },
36
+ beneficiary: { reference: 'Patient/patient-123' },
37
+ payor: [{ reference: 'Patient/patient-123' }],
38
+ type: expect.objectContaining({
39
+ coding: [expect.objectContaining({ code: 'SELFPAY', display: 'Self Pay' })],
40
+ }),
41
+ period: expect.objectContaining({
42
+ start: expect.any(String),
43
+ }),
44
+ })
45
+ );
46
+ expect(result).toBe(createdCoverage);
47
+ });
48
+ });
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { MedplumClient } from '@medplum/core';
4
+ import type { Coverage } from '@medplum/fhirtypes';
5
+
6
+ /**
7
+ * Creates a self-pay coverage for a patient
8
+ * @param medplum - Medplum client instance
9
+ * @param patientId - ID of the patient
10
+ * @returns Promise with the created Coverage resource
11
+ */
12
+ export async function createSelfPayCoverage(medplum: MedplumClient, patientId: string): Promise<Coverage> {
13
+ return medplum.createResource({
14
+ resourceType: 'Coverage',
15
+ status: 'active',
16
+ type: {
17
+ coding: [
18
+ {
19
+ system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode',
20
+ code: 'SELFPAY',
21
+ display: 'Self Pay',
22
+ },
23
+ ],
24
+ text: 'Self Pay',
25
+ },
26
+ subscriber: { reference: `Patient/${patientId}` },
27
+ beneficiary: { reference: `Patient/${patientId}` },
28
+ payor: [{ reference: `Patient/${patientId}` }],
29
+ period: {
30
+ start: new Date().toISOString(),
31
+ },
32
+ });
33
+ }
@@ -0,0 +1,102 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { DocumentReference, ServiceRequest } from '@medplum/fhirtypes';
4
+ import { MockClient } from '@medplum/mock';
5
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
6
+ import { fetchLabOrderRequisitionDocuments, getHealthGorillaRequisitionId } from './documentReference';
7
+
8
+ describe('documentReference utils', () => {
9
+ let medplum: MockClient;
10
+
11
+ beforeEach(() => {
12
+ medplum = new MockClient();
13
+ });
14
+
15
+ describe('getHealthGorillaRequisitionId', () => {
16
+ test('returns id from requisition', () => {
17
+ const request: ServiceRequest = {
18
+ resourceType: 'ServiceRequest',
19
+ requisition: {
20
+ system: 'https://www.healthgorilla.com',
21
+ value: 'req-1',
22
+ },
23
+ status: 'active',
24
+ intent: 'order',
25
+ subject: { reference: 'Patient/patient-1' },
26
+ };
27
+
28
+ expect(getHealthGorillaRequisitionId(request)).toBe('req-1');
29
+ });
30
+
31
+ test('returns id from identifier array', () => {
32
+ const request: ServiceRequest = {
33
+ resourceType: 'ServiceRequest',
34
+ identifier: [
35
+ { system: 'https://www.healthgorilla.com', value: 'req-2' },
36
+ { system: 'http://example.com', value: 'other' },
37
+ ],
38
+ status: 'active',
39
+ intent: 'order',
40
+ subject: { reference: 'Patient/patient-1' },
41
+ };
42
+
43
+ expect(getHealthGorillaRequisitionId(request)).toBe('req-2');
44
+ });
45
+
46
+ test('returns undefined when not present', () => {
47
+ const request: ServiceRequest = {
48
+ resourceType: 'ServiceRequest',
49
+ status: 'active',
50
+ intent: 'order',
51
+ subject: { reference: 'Patient/patient-1' },
52
+ };
53
+ expect(getHealthGorillaRequisitionId(request)).toBeUndefined();
54
+ });
55
+ });
56
+
57
+ describe('fetchLabOrderRequisitionDocuments', () => {
58
+ test('returns empty array when requisition id missing', async () => {
59
+ const request: ServiceRequest = {
60
+ resourceType: 'ServiceRequest',
61
+ status: 'active',
62
+ intent: 'order',
63
+ subject: { reference: 'Patient/patient-1' },
64
+ };
65
+ const searchSpy = vi.spyOn(medplum, 'searchResources');
66
+
67
+ const result = await fetchLabOrderRequisitionDocuments(medplum as any, request);
68
+
69
+ expect(result).toEqual([]);
70
+ expect(searchSpy).not.toHaveBeenCalled();
71
+ });
72
+
73
+ test('fetches requisition documents', async () => {
74
+ const request: ServiceRequest = {
75
+ resourceType: 'ServiceRequest',
76
+ requisition: { system: 'https://www.healthgorilla.com', value: 'req-42' },
77
+ status: 'active',
78
+ intent: 'order',
79
+ subject: { reference: 'Patient/patient-1' },
80
+ };
81
+ const documents: DocumentReference[] = [
82
+ { resourceType: 'DocumentReference', id: 'doc-1', status: 'current', content: [] },
83
+ ];
84
+ const searchSpy = vi.spyOn(medplum, 'searchResources').mockResolvedValue(documents as any);
85
+
86
+ const result = await fetchLabOrderRequisitionDocuments(medplum as any, request);
87
+
88
+ expect(searchSpy).toHaveBeenCalledWith(
89
+ 'DocumentReference',
90
+ expect.objectContaining({
91
+ toString: expect.any(Function),
92
+ }),
93
+ { cache: 'no-cache' }
94
+ );
95
+ const searchParams = (searchSpy.mock.calls[0][1] as URLSearchParams).toString();
96
+ expect(searchParams).toContain('category=LabOrderRequisition');
97
+ expect(searchParams).toContain('identifier=https%3A%2F%2Fwww.healthgorilla.com%7Creq-42');
98
+ expect(searchParams).toContain('_sort=-_lastUpdated');
99
+ expect(result).toEqual(documents);
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,55 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import type { DocumentReference, ServiceRequest } from '@medplum/fhirtypes';
4
+ import type { MedplumClient } from '@medplum/core';
5
+
6
+ const HEALTH_GORILLA_REQUEST_SYSTEM = 'https://www.healthgorilla.com';
7
+
8
+ /**
9
+ * Fetches DocumentReference resources with LabOrderRequisition category that match a ServiceRequest's Health Gorilla Requisition ID
10
+ * @param medplum - The Medplum client
11
+ * @param serviceRequest - The ServiceRequest to fetch the DocumentReference for
12
+ * @returns The DocumentReference resources
13
+ */
14
+ export async function fetchLabOrderRequisitionDocuments(
15
+ medplum: MedplumClient,
16
+ serviceRequest: ServiceRequest
17
+ ): Promise<DocumentReference[]> {
18
+ const healthGorillaRequisitionId = getHealthGorillaRequisitionId(serviceRequest);
19
+
20
+ if (!healthGorillaRequisitionId) {
21
+ return [];
22
+ }
23
+
24
+ const searchParams = new URLSearchParams({
25
+ category: 'LabOrderRequisition',
26
+ identifier: `${HEALTH_GORILLA_REQUEST_SYSTEM}|${healthGorillaRequisitionId}`,
27
+ _sort: '-_lastUpdated',
28
+ });
29
+
30
+ const results = await medplum.searchResources('DocumentReference', searchParams, { cache: 'no-cache' });
31
+ return results;
32
+ }
33
+
34
+ /**
35
+ * Extracts the Health Gorilla Requisition ID from a ServiceRequest
36
+ * Looks for the requisition identifier with system "https://www.healthgorilla.com"
37
+ * @param serviceRequest - The ServiceRequest to extract the Health Gorilla Requisition ID from
38
+ * @returns The Health Gorilla Requisition ID
39
+ */
40
+ export function getHealthGorillaRequisitionId(serviceRequest: ServiceRequest): string | undefined {
41
+ // Check if ServiceRequest has a requisition identifier
42
+ if (serviceRequest.requisition?.system === HEALTH_GORILLA_REQUEST_SYSTEM) {
43
+ return serviceRequest.requisition.value;
44
+ }
45
+
46
+ // Also check the identifier array for Health Gorilla identifiers
47
+ if (serviceRequest.identifier) {
48
+ const healthGorillaIdentifier = serviceRequest.identifier.find((id) => id.system === HEALTH_GORILLA_REQUEST_SYSTEM);
49
+ if (healthGorillaIdentifier?.value) {
50
+ return healthGorillaIdentifier.value;
51
+ }
52
+ }
53
+
54
+ return undefined;
55
+ }
@@ -0,0 +1,169 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { HTTP_HL7_ORG } from '@medplum/core';
4
+ import type { Coding, Encounter, Patient, PlanDefinition, Practitioner, Appointment, Task } from '@medplum/fhirtypes';
5
+ import { MockClient } from '@medplum/mock';
6
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
7
+ import { createEncounter, updateEncounterStatus } from './encounter';
8
+
9
+ describe('encounter utils', () => {
10
+ let medplum: MockClient;
11
+ let practitioner: Practitioner;
12
+ let patient: Patient;
13
+ let classification: Coding;
14
+
15
+ beforeEach(() => {
16
+ medplum = new MockClient();
17
+ practitioner = {
18
+ resourceType: 'Practitioner',
19
+ id: 'prac-1',
20
+ name: [{ given: ['Demo'], family: 'Doctor' }],
21
+ };
22
+ patient = { resourceType: 'Patient', id: 'patient-1', name: [{ given: ['Pat'], family: 'Smith' }] };
23
+ classification = { system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode', code: 'AMB' };
24
+ vi.spyOn(medplum, 'getProfile').mockReturnValue(practitioner);
25
+ });
26
+
27
+ describe('createEncounter', () => {
28
+ test('creates encounter and related resources', async () => {
29
+ // Capture createResource calls and respond with deterministic IDs
30
+ const createResourceSpy = vi.spyOn(medplum, 'createResource').mockImplementation(async (resource: any) => {
31
+ if (resource.resourceType === 'Appointment') {
32
+ return { ...resource, id: 'appt-1' };
33
+ }
34
+ if (resource.resourceType === 'Encounter') {
35
+ return { ...resource, id: 'enc-1' };
36
+ }
37
+ if (resource.resourceType === 'ChargeItem') {
38
+ return { ...resource, id: `charge-${Math.random()}` };
39
+ }
40
+ return { ...resource };
41
+ });
42
+ const postSpy = vi.spyOn(medplum, 'post').mockResolvedValue({});
43
+ const searchSpy = vi.spyOn(medplum, 'search').mockResolvedValue({
44
+ entry: [
45
+ {
46
+ resource: {
47
+ resourceType: 'Task',
48
+ focus: { reference: 'ServiceRequest/sr-1' },
49
+ } as Task,
50
+ },
51
+ ],
52
+ } as any);
53
+ vi.spyOn(medplum, 'searchResources').mockResolvedValue([] as any);
54
+ const readReferenceSpy = vi.spyOn(medplum, 'readReference').mockResolvedValue({
55
+ resourceType: 'ServiceRequest',
56
+ id: 'sr-1',
57
+ encounter: { reference: 'Encounter/enc-1' },
58
+ code: { coding: [{ system: 'http://www.ama-assn.org/go/cpt', code: '1234' }] },
59
+ occurrenceDateTime: '2020-01-01T12:00:00Z',
60
+ extension: [
61
+ {
62
+ url: 'http://medplum.com/fhir/StructureDefinition/applicable-charge-definition',
63
+ valueCanonical: 'ChargeItemDefinition/1',
64
+ },
65
+ ],
66
+ } as any);
67
+
68
+ const planDefinition: PlanDefinition = {
69
+ resourceType: 'PlanDefinition',
70
+ id: 'plan-1',
71
+ extension: [
72
+ {
73
+ url: `${HTTP_HL7_ORG}/fhir/uv/order-catalog/StructureDefinition/ServiceBillingCode`,
74
+ valueCodeableConcept: {
75
+ coding: [{ system: 'http://www.ama-assn.org/go/cpt', code: '99202', display: 'Office visit' }],
76
+ },
77
+ },
78
+ {
79
+ url: 'http://medplum.com/fhir/StructureDefinition/applicable-charge-definition',
80
+ valueCanonical: 'ChargeItemDefinition/plan',
81
+ },
82
+ ],
83
+ status: 'active',
84
+ };
85
+
86
+ const encounter = await createEncounter(
87
+ medplum as any,
88
+ new Date('2020-01-01T10:00:00Z'),
89
+ new Date('2020-01-01T10:30:00Z'),
90
+ classification,
91
+ patient,
92
+ planDefinition
93
+ );
94
+
95
+ expect(encounter.status).toBe('planned');
96
+ expect(encounter.id).toBe('enc-1');
97
+ expect(createResourceSpy).toHaveBeenCalledWith(expect.objectContaining({ resourceType: 'Appointment' }));
98
+ expect(postSpy).toHaveBeenCalled();
99
+ expect(searchSpy).toHaveBeenCalledWith('Task', expect.objectContaining({ encounter: 'Encounter/enc-1' }));
100
+ expect(readReferenceSpy).toHaveBeenCalledWith({ reference: 'ServiceRequest/sr-1' });
101
+ // Ensure a ChargeItem was attempted from service request
102
+ expect(
103
+ createResourceSpy.mock.calls.some(([resource]) => resource.resourceType === 'ChargeItem' && resource.code)
104
+ ).toBe(true);
105
+ });
106
+ });
107
+
108
+ describe('updateEncounterStatus', () => {
109
+ test('updates encounter period and appointment status', async () => {
110
+ const encounter: Encounter = {
111
+ resourceType: 'Encounter',
112
+ id: 'enc-1',
113
+ status: 'planned',
114
+ class: classification,
115
+ };
116
+ const appointment: Appointment = {
117
+ resourceType: 'Appointment',
118
+ id: 'appt-1',
119
+ status: 'booked',
120
+ participant: [
121
+ {
122
+ actor: { reference: 'Practitioner/prac-1' },
123
+ status: 'accepted',
124
+ },
125
+ ],
126
+ };
127
+ const updateSpy = vi.spyOn(medplum, 'updateResource').mockImplementation(async (resource) => resource as any);
128
+
129
+ const updatedEncounter = await updateEncounterStatus(medplum as any, encounter, appointment, 'in-progress');
130
+
131
+ expect(updateSpy).toHaveBeenCalledWith(
132
+ expect.objectContaining({ resourceType: 'Appointment', status: 'checked-in' })
133
+ );
134
+ expect(updateSpy).toHaveBeenCalledWith(
135
+ expect.objectContaining({ resourceType: 'Encounter', status: 'in-progress' })
136
+ );
137
+ expect(updatedEncounter.period?.start).toBeDefined();
138
+
139
+ // Move to finished state
140
+ await updateEncounterStatus(medplum as any, updatedEncounter, appointment, 'finished');
141
+ expect(updateSpy).toHaveBeenCalledWith(expect.objectContaining({ status: 'fulfilled' }));
142
+ });
143
+
144
+ test('updates appointment status for cancellation', async () => {
145
+ const encounter: Encounter = {
146
+ resourceType: 'Encounter',
147
+ id: 'enc-2',
148
+ status: 'in-progress',
149
+ class: classification,
150
+ };
151
+ const appointment: Appointment = {
152
+ resourceType: 'Appointment',
153
+ id: 'appt-2',
154
+ status: 'booked',
155
+ participant: [
156
+ {
157
+ actor: { reference: 'Practitioner/prac-1' },
158
+ status: 'accepted',
159
+ },
160
+ ],
161
+ };
162
+ const updateSpy = vi.spyOn(medplum, 'updateResource').mockImplementation(async (resource) => resource as any);
163
+
164
+ await updateEncounterStatus(medplum as any, encounter, appointment, 'cancelled');
165
+
166
+ expect(updateSpy).toHaveBeenCalledWith(expect.objectContaining({ status: 'cancelled' }));
167
+ });
168
+ });
169
+ });