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,185 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { getReferenceString } from '@medplum/core';
4
+ import { AppShell, Loading, Logo, NotificationIcon, useMedplum, useMedplumProfile } from '@medplum/react';
5
+ import {
6
+ IconApps,
7
+ IconBook2,
8
+ IconCalendarEvent,
9
+ IconClipboardCheck,
10
+ IconMail,
11
+ IconUserPlus,
12
+ IconUsers,
13
+ } from '@tabler/icons-react';
14
+ import type { JSX } from 'react';
15
+ import { Suspense } from 'react';
16
+ import { Navigate, Route, Routes, useLocation, useSearchParams } from 'react-router';
17
+ import { DoseSpotIcon } from './components/DoseSpotIcon';
18
+ import { TaskDetailsModal } from './components/tasks/TaskDetailsModal';
19
+ import { hasDoseSpotIdentifier } from './components/utils';
20
+ import './index.css';
21
+ import { EncounterChartPage } from './pages/encounter/EncounterChartPage';
22
+ import { EncounterModal } from './pages/encounter/EncounterModal';
23
+ import { DoseSpotFavoritesPage } from './pages/integrations/DoseSpotFavoritesPage';
24
+ import { IntegrationsPage } from './pages/integrations/IntegrationsPage';
25
+ import { MessagesPage } from './pages/messages/MessagesPage';
26
+ import { CommunicationTab } from './pages/patient/CommunicationTab';
27
+ import { DoseSpotTab } from './pages/patient/DoseSpotTab';
28
+ import { EditTab } from './pages/patient/EditTab';
29
+ import { ExportTab } from './pages/patient/ExportTab';
30
+ import { IntakeFormPage } from './pages/patient/IntakeFormPage';
31
+ import { LabsPage } from './pages/patient/LabsPage';
32
+ import { PatientPage } from './pages/patient/PatientPage';
33
+ import { PatientSearchPage } from './pages/patient/PatientSearchPage';
34
+ import { TasksTab } from './pages/patient/TasksTab';
35
+ import { TimelineTab } from './pages/patient/TimelineTab';
36
+ import { ResourceCreatePage } from './pages/resource/ResourceCreatePage';
37
+ import { ResourceDetailPage } from './pages/resource/ResourceDetailPage';
38
+ import { ResourceEditPage } from './pages/resource/ResourceEditPage';
39
+ import { ResourceHistoryPage } from './pages/resource/ResourceHistoryPage';
40
+ import { ResourcePage } from './pages/resource/ResourcePage';
41
+ import { SchedulePage } from './pages/schedule/SchedulePage';
42
+ import { SearchPage } from './pages/SearchPage';
43
+ import { SignInPage } from './pages/SignInPage';
44
+ import { SpacesPage } from './pages/spaces/SpacesPage';
45
+ import { TasksPage } from './pages/tasks/TasksPage';
46
+
47
+ export function App(): JSX.Element | null {
48
+ const medplum = useMedplum();
49
+ const profile = useMedplumProfile();
50
+ const location = useLocation();
51
+ const [searchParams] = useSearchParams();
52
+
53
+ if (medplum.isLoading()) {
54
+ return null;
55
+ }
56
+
57
+ const membership = medplum.getProjectMembership();
58
+ const hasDoseSpot = hasDoseSpotIdentifier(membership);
59
+
60
+ return (
61
+ <AppShell
62
+ logo={<Logo size={24} />}
63
+ pathname={location.pathname}
64
+ searchParams={searchParams}
65
+ menus={
66
+ profile
67
+ ? [
68
+ {
69
+ links: [
70
+ { icon: <IconBook2 />, label: 'Spaces', href: '/Spaces/Communication' },
71
+ {
72
+ icon: <IconUsers />,
73
+ label: 'Patients',
74
+ href: '/Patient?_count=20&_fields=name,email,gender&_sort=-_lastUpdated',
75
+ },
76
+ { icon: <IconCalendarEvent />, label: 'Schedule', href: '/schedule' },
77
+ {
78
+ icon: (
79
+ <NotificationIcon
80
+ resourceType="Communication"
81
+ countCriteria={`recipient=${getReferenceString(profile)}&status:not=completed&_summary=count`}
82
+ subscriptionCriteria={`Communication?recipient=${getReferenceString(profile)}`}
83
+ iconComponent={<IconMail />}
84
+ />
85
+ ),
86
+ label: 'Messages',
87
+ href: `/Communication?status=in-progress`,
88
+ },
89
+ {
90
+ icon: (
91
+ <NotificationIcon
92
+ resourceType="Task"
93
+ countCriteria={`owner=${getReferenceString(profile)}&status=requested,ready,received,accepted,in-progress,draft&_summary=count`}
94
+ subscriptionCriteria={`Task?owner=${getReferenceString(profile)}&status=requested,ready,received,accepted,in-progress,draft`}
95
+ iconComponent={<IconClipboardCheck />}
96
+ />
97
+ ),
98
+ label: 'Tasks',
99
+ href: `/Task?owner=${getReferenceString(profile)}&_sort=-_lastUpdated&status=requested,ready,received,accepted,in-progress,draft`,
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ title: 'Quick Links',
105
+ links: [
106
+ { icon: <IconUserPlus />, label: 'New Patient', href: '/onboarding' },
107
+ { icon: <IconApps />, label: 'Integrations', href: '/integrations' },
108
+ ...(hasDoseSpot
109
+ ? [{ icon: <DoseSpotIcon />, label: 'DoseSpot', href: '/integrations/dosespot' }]
110
+ : []),
111
+ ],
112
+ },
113
+ ]
114
+ : undefined
115
+ }
116
+ resourceTypeSearchDisabled={true}
117
+ >
118
+ <Suspense fallback={<Loading />}>
119
+ <Routes>
120
+ {profile ? (
121
+ <>
122
+ <Route path="/Spaces/Communication" element={<SpacesPage />}>
123
+ <Route index element={<SpacesPage />} />
124
+ <Route path=":topicId" element={<SpacesPage />} />
125
+ </Route>
126
+ <Route
127
+ path="/"
128
+ element={<Navigate to="/Patient?_count=20&_fields=name,email,gender&_sort=-_lastUpdated" replace />}
129
+ />
130
+ <Route path="/Patient/new" element={<ResourceCreatePage />} />
131
+ <Route path="/Patient/:patientId" element={<PatientPage />}>
132
+ <Route path="Encounter/new" element={<EncounterModal />} />
133
+ <Route path="Encounter/:encounterId" element={<EncounterChartPage />}>
134
+ <Route path="Task/:taskId" element={<TaskDetailsModal />} />
135
+ </Route>
136
+ <Route path="edit" element={<EditTab />} />
137
+ <Route path="Communication" element={<CommunicationTab />} />
138
+ <Route path="Communication/:messageId" element={<CommunicationTab />} />
139
+ <Route path="Task" element={<TasksTab />} />
140
+ <Route path="Task/:taskId" element={<TasksTab />} />
141
+ {hasDoseSpot && <Route path="dosespot" element={<DoseSpotTab />} />}
142
+ <Route path="timeline" element={<TimelineTab />} />
143
+ <Route path="export" element={<ExportTab />} />
144
+ <Route path="ServiceRequest" element={<LabsPage />} />
145
+ <Route path="ServiceRequest/:serviceRequestId" element={<LabsPage />} />
146
+ <Route path=":resourceType" element={<PatientSearchPage />} />
147
+ <Route path=":resourceType/new" element={<ResourceCreatePage />} />
148
+ <Route path=":resourceType/:id" element={<ResourcePage />}>
149
+ <Route path="" element={<ResourceDetailPage />} />
150
+ <Route path="edit" element={<ResourceEditPage />} />
151
+ <Route path="history" element={<ResourceHistoryPage />} />
152
+ </Route>
153
+ <Route path="" element={<TimelineTab />} />
154
+ </Route>
155
+ <Route path="/Communication" element={<MessagesPage />}>
156
+ <Route index element={<MessagesPage />} />
157
+ <Route path=":messageId" element={<MessagesPage />} />
158
+ </Route>
159
+ <Route path="Task" element={<TasksPage />} />
160
+ <Route path="Task/:taskId" element={<TasksPage />} />
161
+ <Route path="/onboarding" element={<IntakeFormPage />} />
162
+ <Route path="/schedule" element={<SchedulePage />} />
163
+ <Route path="/signin" element={<SignInPage />} />
164
+ <Route path="/dosespot" element={<DoseSpotTab />} />
165
+ <Route path="/integrations" element={<IntegrationsPage />} />
166
+ <Route path="/:resourceType" element={<SearchPage />} />
167
+ <Route path="/:resourceType/new" element={<ResourceCreatePage />} />
168
+ <Route path="/:resourceType/:id" element={<ResourcePage />}>
169
+ <Route path="" element={<ResourceDetailPage />} />
170
+ <Route path="edit" element={<ResourceEditPage />} />
171
+ <Route path="history" element={<ResourceHistoryPage />} />
172
+ </Route>
173
+ {hasDoseSpot && <Route path="/integrations/dosespot" element={<DoseSpotFavoritesPage />} />}
174
+ </>
175
+ ) : (
176
+ <>
177
+ <Route path="/signin" element={<SignInPage />} />
178
+ <Route path="*" element={<Navigate to="/signin" replace />} />
179
+ </>
180
+ )}
181
+ </Routes>
182
+ </Suspense>
183
+ </AppShell>
184
+ );
185
+ }
@@ -0,0 +1,350 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { MantineProvider } from '@mantine/core';
5
+ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import { MedplumProvider } from '@medplum/react';
8
+ import type { ChargeItem, ChargeItemDefinition, CodeableConcept, Encounter, Patient } from '@medplum/fhirtypes';
9
+ import { MockClient } from '@medplum/mock';
10
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
11
+ import { ChargeItemList } from './ChargeItemList';
12
+ import * as chargeItemsUtils from '../../utils/chargeitems';
13
+
14
+ const mockPatient: Patient = {
15
+ resourceType: 'Patient',
16
+ id: 'patient-123',
17
+ name: [{ given: ['John'], family: 'Doe' }],
18
+ };
19
+
20
+ const mockEncounter: Encounter = {
21
+ resourceType: 'Encounter',
22
+ id: 'encounter-123',
23
+ status: 'in-progress',
24
+ class: {
25
+ system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode',
26
+ code: 'AMB',
27
+ },
28
+ subject: { reference: 'Patient/patient-123' },
29
+ };
30
+
31
+ const mockChargeItem: ChargeItem = {
32
+ resourceType: 'ChargeItem',
33
+ id: 'charge-123',
34
+ status: 'billable',
35
+ subject: { reference: 'Patient/patient-123' },
36
+ code: {
37
+ coding: [
38
+ {
39
+ system: 'http://www.ama-assn.org/go/cpt',
40
+ code: '99213',
41
+ display: 'Office Visit',
42
+ },
43
+ ],
44
+ },
45
+ priceOverride: {
46
+ value: 100,
47
+ currency: 'USD',
48
+ },
49
+ };
50
+
51
+ vi.mock('../../utils/chargeitems', () => ({
52
+ applyChargeItemDefinition: vi.fn(),
53
+ calculateTotalPrice: vi.fn(),
54
+ }));
55
+
56
+ describe('ChargeItemList', () => {
57
+ let medplum: MockClient;
58
+
59
+ beforeEach(() => {
60
+ medplum = new MockClient();
61
+ vi.clearAllMocks();
62
+ vi.spyOn(chargeItemsUtils, 'calculateTotalPrice').mockImplementation((items) => {
63
+ return items.reduce((sum, item) => sum + (item.priceOverride?.value || 0), 0);
64
+ });
65
+ vi.spyOn(chargeItemsUtils, 'applyChargeItemDefinition').mockImplementation(async (_, item) => item);
66
+ });
67
+
68
+ const setup = (props: Partial<Parameters<typeof ChargeItemList>[0]> = {}): ReturnType<typeof render> => {
69
+ return render(
70
+ <MedplumProvider medplum={medplum}>
71
+ <MantineProvider>
72
+ <ChargeItemList
73
+ patient={mockPatient}
74
+ encounter={mockEncounter}
75
+ chargeItems={[]}
76
+ updateChargeItems={vi.fn()}
77
+ {...props}
78
+ />
79
+ </MantineProvider>
80
+ </MedplumProvider>
81
+ );
82
+ };
83
+
84
+ test('renders empty state', () => {
85
+ setup({ chargeItems: [] });
86
+ expect(screen.getByText('No charge items available')).toBeInTheDocument();
87
+ expect(screen.getByText('Add Charge Item')).toBeInTheDocument();
88
+ });
89
+
90
+ test('renders charge items list', () => {
91
+ setup({ chargeItems: [mockChargeItem] });
92
+
93
+ expect(screen.getByText('Charge Items')).toBeInTheDocument();
94
+ expect(screen.getByText('CPT Code')).toBeInTheDocument();
95
+ expect(screen.getByDisplayValue('$100.00')).toBeInTheDocument();
96
+ });
97
+
98
+ test('calculates total price', () => {
99
+ const item2 = { ...mockChargeItem, id: 'charge-456', priceOverride: { value: 50 } };
100
+ setup({ chargeItems: [mockChargeItem, item2] });
101
+
102
+ expect(screen.getByDisplayValue('$150')).toBeInTheDocument();
103
+ });
104
+
105
+ test('deletes charge item', async () => {
106
+ const updateChargeItems = vi.fn();
107
+ const user = userEvent.setup();
108
+
109
+ vi.spyOn(medplum, 'deleteResource').mockResolvedValue({} as any);
110
+
111
+ setup({ chargeItems: [mockChargeItem], updateChargeItems });
112
+
113
+ const buttons = screen.getAllByRole('button', { hidden: true });
114
+ const deleteButton = buttons.find((btn) => btn.getAttribute('aria-haspopup') === 'menu');
115
+
116
+ if (!deleteButton) {
117
+ throw new Error('Delete button not found');
118
+ }
119
+
120
+ await user.click(deleteButton);
121
+
122
+ const deleteMenuItem = await screen.findByText('Delete');
123
+ await user.click(deleteMenuItem);
124
+
125
+ await waitFor(() => {
126
+ expect(medplum.deleteResource).toHaveBeenCalledWith('ChargeItem', 'charge-123');
127
+ expect(updateChargeItems).toHaveBeenCalledWith([]);
128
+ });
129
+ });
130
+
131
+ test('opens add charge item modal', async () => {
132
+ const user = userEvent.setup();
133
+ setup();
134
+
135
+ await user.click(screen.getByText('Add Charge Item'));
136
+
137
+ await waitFor(() => {
138
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
139
+ });
140
+
141
+ expect(screen.getByText('Add Charge Item', { selector: '.mantine-Modal-title' })).toBeInTheDocument();
142
+
143
+ expect(screen.getByText('CPT Code')).toBeInTheDocument();
144
+ expect(screen.getByText('Charge Item Definition')).toBeInTheDocument();
145
+
146
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
147
+ const addButtons = screen.getAllByRole('button', { name: 'Add Charge Item' });
148
+ expect(addButtons.length).toBeGreaterThan(1);
149
+ });
150
+
151
+ test('closes modal on cancel', async () => {
152
+ const user = userEvent.setup();
153
+ setup();
154
+
155
+ await user.click(screen.getByText('Add Charge Item'));
156
+
157
+ await waitFor(() => {
158
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
159
+ });
160
+
161
+ await user.click(screen.getByRole('button', { name: 'Cancel' }));
162
+
163
+ await waitFor(() => {
164
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
165
+ });
166
+ });
167
+
168
+ test('displays total calculated price', () => {
169
+ setup({ chargeItems: [mockChargeItem] });
170
+
171
+ expect(screen.getByText('Total Calculated Price to Bill')).toBeInTheDocument();
172
+ expect(screen.getByDisplayValue('$100')).toBeInTheDocument();
173
+ });
174
+
175
+ test('adds charge item successfully with CPT code and definition', async () => {
176
+ const user = userEvent.setup();
177
+ const updateChargeItems = vi.fn();
178
+ const mockCptCode: CodeableConcept = {
179
+ coding: [
180
+ {
181
+ system: 'http://www.ama-assn.org/go/cpt',
182
+ code: '99214',
183
+ display: 'Office Visit Level 4',
184
+ },
185
+ ],
186
+ };
187
+ const mockDefinition: ChargeItemDefinition & { id: string } = {
188
+ resourceType: 'ChargeItemDefinition',
189
+ id: 'def-123',
190
+ status: 'active',
191
+ url: 'http://example.com/charge-item-def',
192
+ title: 'Test Definition',
193
+ };
194
+ const newChargeItem: ChargeItem & { id: string } = {
195
+ resourceType: 'ChargeItem',
196
+ id: 'charge-new',
197
+ status: 'planned',
198
+ subject: { reference: 'Patient/patient-123' },
199
+ code: mockCptCode,
200
+ };
201
+ const appliedChargeItem: ChargeItem & { id: string } = {
202
+ ...newChargeItem,
203
+ priceOverride: { value: 200, currency: 'USD' },
204
+ };
205
+
206
+ // Mock valueSetExpand for CPT code search
207
+ medplum.valueSetExpand = vi.fn().mockResolvedValue({
208
+ resourceType: 'ValueSet',
209
+ expansion: {
210
+ contains: [
211
+ {
212
+ system: 'http://www.ama-assn.org/go/cpt',
213
+ code: '99214',
214
+ display: 'Office Visit Level 4',
215
+ },
216
+ ],
217
+ },
218
+ });
219
+
220
+ // Mock searchResources for ChargeItemDefinition search
221
+ vi.spyOn(medplum, 'searchResources').mockResolvedValue([mockDefinition] as any);
222
+ vi.spyOn(medplum, 'createResource').mockResolvedValue(newChargeItem);
223
+ vi.spyOn(chargeItemsUtils, 'applyChargeItemDefinition').mockResolvedValue(appliedChargeItem);
224
+
225
+ setup({ updateChargeItems });
226
+
227
+ // Open modal
228
+ await user.click(screen.getByText('Add Charge Item'));
229
+
230
+ await waitFor(() => {
231
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
232
+ });
233
+
234
+ // Find CPT Code input
235
+ const cptInputs = screen.getAllByRole('searchbox');
236
+ const cptInput = cptInputs.find((input) => {
237
+ const label = input.closest('.mantine-InputWrapper-root')?.querySelector('label');
238
+ return label?.textContent?.includes('CPT Code');
239
+ }) as HTMLInputElement;
240
+
241
+ expect(cptInput).toBeDefined();
242
+
243
+ // Type in CPT code input
244
+ await act(async () => {
245
+ await user.type(cptInput, '99214');
246
+ });
247
+
248
+ // Wait for valueSetExpand to be called
249
+ await waitFor(
250
+ () => {
251
+ expect(medplum.valueSetExpand).toHaveBeenCalled();
252
+ },
253
+ { timeout: 3000 }
254
+ );
255
+
256
+ // Select the CPT code option
257
+ await act(async () => {
258
+ fireEvent.keyDown(cptInput, { key: 'ArrowDown', code: 'ArrowDown' });
259
+ fireEvent.keyDown(cptInput, { key: 'Enter', code: 'Enter' });
260
+ });
261
+
262
+ // Wait for CPT code to be selected (check for selected items or code display)
263
+ await waitFor(
264
+ () => {
265
+ // Check if the code appears in selected items or if the input value changed
266
+ const selectedItems = document.querySelector('[data-testid="selected-items"]');
267
+ const hasCode =
268
+ selectedItems?.textContent?.includes('99214') || selectedItems?.textContent?.includes('Office Visit Level 4');
269
+ return hasCode === true;
270
+ },
271
+ { timeout: 3000 }
272
+ );
273
+
274
+ // Find Charge Item Definition input
275
+ const definitionInputs = screen.getAllByRole('searchbox');
276
+ const definitionInput = definitionInputs.find((input) => {
277
+ const placeholder = (input as HTMLInputElement).placeholder;
278
+ return placeholder?.toLowerCase().includes('charge item definition');
279
+ }) as HTMLInputElement;
280
+
281
+ expect(definitionInput).toBeDefined();
282
+
283
+ // Type in definition input
284
+ await act(async () => {
285
+ await user.type(definitionInput, 'Test');
286
+ });
287
+
288
+ // Wait for searchResources to be called
289
+ await waitFor(
290
+ () => {
291
+ expect(medplum.searchResources).toHaveBeenCalledWith(
292
+ 'ChargeItemDefinition',
293
+ expect.any(URLSearchParams),
294
+ expect.any(Object)
295
+ );
296
+ },
297
+ { timeout: 3000 }
298
+ );
299
+
300
+ // Select the definition option
301
+ await act(async () => {
302
+ fireEvent.keyDown(definitionInput, { key: 'ArrowDown', code: 'ArrowDown' });
303
+ fireEvent.keyDown(definitionInput, { key: 'Enter', code: 'Enter' });
304
+ });
305
+
306
+ // Wait for definition to be selected and button to be enabled
307
+ await waitFor(
308
+ () => {
309
+ const addButtons = screen.getAllByRole('button', { name: 'Add Charge Item' });
310
+ const submitButton = addButtons.find((btn) => {
311
+ const htmlBtn = btn as HTMLButtonElement;
312
+ return htmlBtn.type === 'button' && !htmlBtn.disabled;
313
+ });
314
+ return submitButton !== undefined;
315
+ },
316
+ { timeout: 5000 }
317
+ );
318
+
319
+ // Submit the form
320
+ const addButtons = screen.getAllByRole('button', { name: 'Add Charge Item' });
321
+ const submitButton = addButtons.find((btn) => {
322
+ const htmlBtn = btn as HTMLButtonElement;
323
+ return htmlBtn.type === 'button' && !htmlBtn.disabled;
324
+ });
325
+
326
+ expect(submitButton).toBeDefined();
327
+ if (submitButton) {
328
+ await user.click(submitButton);
329
+
330
+ // Verify charge item was created
331
+ await waitFor(() => {
332
+ expect(medplum.createResource).toHaveBeenCalledWith(
333
+ expect.objectContaining({
334
+ resourceType: 'ChargeItem',
335
+ status: 'planned',
336
+ code: mockCptCode,
337
+ definitionCanonical: ['http://example.com/charge-item-def'],
338
+ })
339
+ );
340
+ expect(chargeItemsUtils.applyChargeItemDefinition).toHaveBeenCalled();
341
+ expect(updateChargeItems).toHaveBeenCalledWith([appliedChargeItem]);
342
+ });
343
+
344
+ // Verify modal closed
345
+ await waitFor(() => {
346
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
347
+ });
348
+ }
349
+ });
350
+ });