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,464 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { MantineProvider } from '@mantine/core';
4
+ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
6
+ import { MedplumProvider } from '@medplum/react';
7
+ // HTTP_HL7_ORG constant
8
+ const HTTP_HL7_ORG = 'http://hl7.org';
9
+ import type { Condition, Encounter, Patient } from '@medplum/fhirtypes';
10
+ import { MockClient } from '@medplum/mock';
11
+ import { describe, expect, test, beforeEach, vi } from 'vitest';
12
+ import { ConditionList } from './ConditionList';
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
+ diagnosis: [
30
+ {
31
+ condition: { reference: 'Condition/condition-123' },
32
+ rank: 1,
33
+ },
34
+ ],
35
+ };
36
+
37
+ const mockCondition: Condition = {
38
+ resourceType: 'Condition',
39
+ id: 'condition-123',
40
+ subject: { reference: 'Patient/patient-123' },
41
+ code: {
42
+ coding: [
43
+ {
44
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
45
+ code: 'J20.9',
46
+ display: 'Acute bronchitis',
47
+ },
48
+ ],
49
+ },
50
+ clinicalStatus: {
51
+ coding: [
52
+ {
53
+ system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
54
+ code: 'active',
55
+ },
56
+ ],
57
+ },
58
+ };
59
+
60
+ describe('ConditionList', () => {
61
+ let medplum: MockClient;
62
+
63
+ beforeEach(() => {
64
+ medplum = new MockClient();
65
+ vi.clearAllMocks();
66
+ });
67
+
68
+ const setup = (props: Partial<Parameters<typeof ConditionList>[0]> = {}): ReturnType<typeof render> => {
69
+ return render(
70
+ <MedplumProvider medplum={medplum}>
71
+ <MantineProvider>
72
+ <ConditionList
73
+ patient={mockPatient}
74
+ encounter={mockEncounter}
75
+ conditions={[]}
76
+ setConditions={vi.fn()}
77
+ onDiagnosisChange={vi.fn()}
78
+ {...props}
79
+ />
80
+ </MantineProvider>
81
+ </MedplumProvider>
82
+ );
83
+ };
84
+
85
+ test('renders diagnosis section', () => {
86
+ setup();
87
+ expect(screen.getByText('Diagnosis')).toBeInTheDocument();
88
+ expect(screen.getByRole('button', { name: 'Add Diagnosis' })).toBeInTheDocument();
89
+ });
90
+
91
+ test('renders condition list', () => {
92
+ setup({ conditions: [mockCondition] });
93
+ expect(screen.getByText('Acute bronchitis')).toBeInTheDocument();
94
+ });
95
+
96
+ test('renders multiple conditions with ranks', () => {
97
+ const condition2: Condition = {
98
+ ...mockCondition,
99
+ id: 'condition-456',
100
+ code: {
101
+ coding: [
102
+ {
103
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
104
+ code: 'I10',
105
+ display: 'Essential hypertension',
106
+ },
107
+ ],
108
+ },
109
+ };
110
+
111
+ setup({ conditions: [mockCondition, condition2] });
112
+
113
+ expect(screen.getByText('Acute bronchitis')).toBeInTheDocument();
114
+ expect(screen.getByText('Essential hypertension')).toBeInTheDocument();
115
+ });
116
+
117
+ test('opens add diagnosis modal', async () => {
118
+ const user = userEvent.setup();
119
+ setup();
120
+
121
+ await user.click(screen.getByRole('button', { name: 'Add Diagnosis' }));
122
+
123
+ await waitFor(() => {
124
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
125
+ expect(screen.getByText('Add Diagnosis', { selector: '.mantine-Modal-title' })).toBeInTheDocument();
126
+ });
127
+ });
128
+
129
+ test('displays modal form fields', async () => {
130
+ const user = userEvent.setup();
131
+ setup();
132
+
133
+ await user.click(screen.getByRole('button', { name: 'Add Diagnosis' }));
134
+
135
+ await waitFor(() => {
136
+ expect(screen.getByText('ICD-10 Code')).toBeInTheDocument();
137
+ expect(screen.getByText('Status')).toBeInTheDocument();
138
+ expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
139
+ });
140
+ });
141
+
142
+ test('removes condition', async () => {
143
+ const setConditions = vi.fn();
144
+ const onDiagnosisChange = vi.fn();
145
+ const user = userEvent.setup();
146
+
147
+ vi.spyOn(medplum, 'deleteResource').mockResolvedValue({} as any);
148
+
149
+ setup({
150
+ conditions: [mockCondition],
151
+ setConditions,
152
+ onDiagnosisChange,
153
+ });
154
+
155
+ const removeButtons = screen.getAllByRole('button', { hidden: true });
156
+ const removeButton = removeButtons.find((btn) => btn.querySelector('svg'));
157
+
158
+ if (!removeButton) {
159
+ throw new Error('Remove button not found');
160
+ }
161
+
162
+ await user.click(removeButton);
163
+
164
+ await waitFor(() => {
165
+ expect(medplum.deleteResource).toHaveBeenCalledWith('Condition', 'condition-123');
166
+ expect(setConditions).toHaveBeenCalledWith([]);
167
+ expect(onDiagnosisChange).toHaveBeenCalled();
168
+ });
169
+ });
170
+
171
+ test('displays rank selects for multiple conditions', () => {
172
+ const condition2: Condition = {
173
+ ...mockCondition,
174
+ id: 'condition-456',
175
+ code: {
176
+ coding: [
177
+ {
178
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
179
+ code: 'I10',
180
+ display: 'Essential hypertension',
181
+ },
182
+ ],
183
+ },
184
+ };
185
+
186
+ setup({
187
+ conditions: [mockCondition, condition2],
188
+ });
189
+
190
+ const selects = screen.getAllByRole('textbox');
191
+ expect(selects).toHaveLength(2);
192
+ expect(selects[0]).toHaveValue('1');
193
+ expect(selects[1]).toHaveValue('2');
194
+ });
195
+
196
+ test('fetches conditions on mount', async () => {
197
+ vi.spyOn(medplum, 'readReference').mockResolvedValue(mockCondition as any);
198
+
199
+ const setConditions = vi.fn();
200
+
201
+ setup({
202
+ encounter: mockEncounter,
203
+ setConditions,
204
+ });
205
+
206
+ await waitFor(() => {
207
+ expect(medplum.readReference).toHaveBeenCalledWith({ reference: 'Condition/condition-123' });
208
+ });
209
+ });
210
+
211
+ test('creates a new condition with cholera ICD-10 code and active status', async () => {
212
+ const user = userEvent.setup();
213
+ const setConditions = vi.fn();
214
+ const onDiagnosisChange = vi.fn();
215
+
216
+ const newCondition: Condition & { id: string } = {
217
+ resourceType: 'Condition',
218
+ id: 'condition-new',
219
+ subject: { reference: 'Patient/patient-123' },
220
+ encounter: { reference: 'Encounter/encounter-123' },
221
+ code: {
222
+ coding: [
223
+ {
224
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
225
+ code: 'A00.9',
226
+ display: 'Cholera, unspecified',
227
+ },
228
+ ],
229
+ },
230
+ clinicalStatus: {
231
+ coding: [
232
+ {
233
+ system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
234
+ code: 'active',
235
+ display: 'Active',
236
+ },
237
+ ],
238
+ },
239
+ };
240
+
241
+ // Mock valueSetExpand for ICD-10 codes (cholera)
242
+ medplum.valueSetExpand = vi
243
+ .fn()
244
+ .mockImplementation(async (params: { url: string; filter?: string; count?: number }) => {
245
+ if (params.url === 'http://hl7.org/fhir/sid/icd-10-cm/vs') {
246
+ const choleraCodes = [
247
+ {
248
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
249
+ code: 'A00.0',
250
+ display: 'Cholera due to Vibrio cholerae 01, biovar cholerae',
251
+ },
252
+ {
253
+ system: 'http://hl7.org/fhir/sid/icd-10-cm',
254
+ code: 'A00.9',
255
+ display: 'Cholera, unspecified',
256
+ },
257
+ ];
258
+ const filtered = params.filter
259
+ ? choleraCodes.filter(
260
+ (c) =>
261
+ c.code.toLowerCase().includes(params.filter?.toLowerCase() ?? '') ||
262
+ c.display.toLowerCase().includes(params.filter?.toLowerCase() ?? '')
263
+ )
264
+ : choleraCodes;
265
+ const paginated = params.count ? filtered.slice(0, params.count) : filtered;
266
+ return {
267
+ resourceType: 'ValueSet',
268
+ expansion: {
269
+ total: filtered.length,
270
+ timestamp: new Date().toISOString(),
271
+ contains: paginated,
272
+ },
273
+ };
274
+ }
275
+ if (params.url === HTTP_HL7_ORG + '/fhir/ValueSet/condition-clinical') {
276
+ const statuses = [
277
+ {
278
+ system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
279
+ code: 'active',
280
+ display: 'Active',
281
+ },
282
+ {
283
+ system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
284
+ code: 'inactive',
285
+ display: 'Inactive',
286
+ },
287
+ {
288
+ system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
289
+ code: 'resolved',
290
+ display: 'Resolved',
291
+ },
292
+ ];
293
+ const filtered = params.filter
294
+ ? statuses.filter(
295
+ (s) =>
296
+ s.code.toLowerCase().includes(params.filter?.toLowerCase() ?? '') ||
297
+ s.display.toLowerCase().includes(params.filter?.toLowerCase() ?? '')
298
+ )
299
+ : statuses;
300
+ const paginated = params.count ? filtered.slice(0, params.count) : filtered;
301
+ return {
302
+ resourceType: 'ValueSet',
303
+ expansion: {
304
+ total: filtered.length,
305
+ timestamp: new Date().toISOString(),
306
+ contains: paginated,
307
+ },
308
+ };
309
+ }
310
+ return { resourceType: 'ValueSet', expansion: { contains: [] } };
311
+ });
312
+
313
+ vi.spyOn(medplum, 'createResource').mockResolvedValue(newCondition);
314
+
315
+ setup({
316
+ setConditions,
317
+ onDiagnosisChange,
318
+ });
319
+
320
+ // Open modal
321
+ await user.click(screen.getByRole('button', { name: 'Add Diagnosis' }));
322
+
323
+ await waitFor(() => {
324
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
325
+ });
326
+
327
+ // Wait for form fields to be ready
328
+ await waitFor(() => {
329
+ expect(screen.getByText('ICD-10 Code')).toBeInTheDocument();
330
+ expect(screen.getByText('Status')).toBeInTheDocument();
331
+ });
332
+
333
+ // Find ICD-10 code input by label
334
+ await waitFor(() => {
335
+ const inputs = screen.getAllByRole('searchbox');
336
+ expect(inputs.length).toBeGreaterThan(0);
337
+ });
338
+
339
+ const icd10Inputs = screen.getAllByRole('searchbox');
340
+ let icd10Input = icd10Inputs.find((input) => {
341
+ const label = input.closest('.mantine-InputWrapper-root')?.querySelector('label');
342
+ return label?.textContent?.includes('ICD-10 Code');
343
+ });
344
+
345
+ // Fallback to first input if label search doesn't work
346
+ if (!icd10Input && icd10Inputs.length > 0) {
347
+ icd10Input = icd10Inputs[0];
348
+ }
349
+
350
+ expect(icd10Input).toBeDefined();
351
+
352
+ if (icd10Input) {
353
+ // Type "cholera" to search
354
+ await user.type(icd10Input, 'cholera');
355
+
356
+ // Wait for valueSetExpand to be called with cholera filter
357
+ await waitFor(
358
+ () => {
359
+ const calls = vi.mocked(medplum.valueSetExpand).mock.calls;
360
+ const choleraCall = calls.find(
361
+ (call) =>
362
+ call[0]?.url === 'http://hl7.org/fhir/sid/icd-10-cm/vs' &&
363
+ call[0]?.filter?.toLowerCase().includes('cholera')
364
+ );
365
+ expect(choleraCall).toBeDefined();
366
+ },
367
+ { timeout: 10000 }
368
+ );
369
+
370
+ // Select cholera option using keyboard navigation (select second option A00.9)
371
+ await act(async () => {
372
+ fireEvent.keyDown(icd10Input, { key: 'ArrowDown', code: 'ArrowDown' });
373
+ await new Promise<void>((resolve) => {
374
+ setTimeout(() => {
375
+ resolve();
376
+ }, 100);
377
+ });
378
+ fireEvent.keyDown(icd10Input, { key: 'ArrowDown', code: 'ArrowDown' });
379
+ await new Promise<void>((resolve) => {
380
+ setTimeout(() => {
381
+ resolve();
382
+ }, 100);
383
+ });
384
+ fireEvent.keyDown(icd10Input, { key: 'Enter', code: 'Enter' });
385
+ });
386
+ }
387
+
388
+ // Find Status input
389
+ await waitFor(() => {
390
+ const inputs = screen.getAllByRole('searchbox');
391
+ expect(inputs.length).toBeGreaterThan(1);
392
+ });
393
+
394
+ const statusInputs = screen.getAllByRole('searchbox');
395
+ let statusInput = statusInputs.find((input) => {
396
+ const label = input.closest('.mantine-InputWrapper-root')?.querySelector('label');
397
+ return label?.textContent?.includes('Status');
398
+ });
399
+
400
+ // Fallback to second input if label search doesn't work
401
+ if (!statusInput && statusInputs.length > 1) {
402
+ statusInput = statusInputs[1];
403
+ }
404
+
405
+ expect(statusInput).toBeDefined();
406
+
407
+ if (statusInput) {
408
+ // Type "active" to search
409
+ await user.type(statusInput, 'active');
410
+
411
+ // Wait for valueSetExpand to be called with condition-clinical
412
+ await waitFor(
413
+ () => {
414
+ const calls = vi.mocked(medplum.valueSetExpand).mock.calls;
415
+ const clinicalStatusCall = calls.find(
416
+ (call) => call[0]?.url === HTTP_HL7_ORG + '/fhir/ValueSet/condition-clinical'
417
+ );
418
+ expect(clinicalStatusCall).toBeDefined();
419
+ },
420
+ { timeout: 10000 }
421
+ );
422
+
423
+ // Select active status using keyboard navigation
424
+ await act(async () => {
425
+ fireEvent.keyDown(statusInput, { key: 'ArrowDown', code: 'ArrowDown' });
426
+ await act(async () => {
427
+ await new Promise<void>((resolve) => {
428
+ setTimeout(() => {
429
+ resolve();
430
+ }, 100);
431
+ });
432
+ });
433
+ fireEvent.keyDown(statusInput, { key: 'Enter', code: 'Enter' });
434
+ });
435
+ }
436
+
437
+ // Submit form
438
+ const saveButton = screen.getByRole('button', { name: 'Save' });
439
+ await user.click(saveButton);
440
+
441
+ // Wait for createResource to be called
442
+ await waitFor(
443
+ () => {
444
+ expect(medplum.createResource).toHaveBeenCalled();
445
+ },
446
+ { timeout: 10000 }
447
+ );
448
+
449
+ // Verify the condition was created with correct values
450
+ const createCall = vi.mocked(medplum.createResource).mock.calls[0][0] as Condition;
451
+ expect(createCall.code?.coding?.[0]?.code).toBe('A00.9');
452
+ expect(createCall.code?.coding?.[0]?.display).toBe('Cholera, unspecified');
453
+ expect(createCall.clinicalStatus?.coding?.[0]?.code).toBe('active');
454
+
455
+ // Verify setConditions and onDiagnosisChange were called
456
+ await waitFor(
457
+ () => {
458
+ expect(setConditions).toHaveBeenCalled();
459
+ expect(onDiagnosisChange).toHaveBeenCalled();
460
+ },
461
+ { timeout: 10000 }
462
+ );
463
+ }, 15000);
464
+ });
@@ -0,0 +1,186 @@
1
+ // SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Button, Flex, Modal, Card, Stack, Text } from '@mantine/core';
4
+ import type { Condition, Encounter, EncounterDiagnosis, Patient } from '@medplum/fhirtypes';
5
+ import { useEffect, useState } from 'react';
6
+ import type { JSX } from 'react';
7
+ import ConditionItem from './ConditionItem';
8
+ import ConditionModal from './ConditionModal';
9
+ import { useMedplum } from '@medplum/react';
10
+ import { getReferenceString } from '@medplum/core';
11
+ import { showErrorNotification } from '../../utils/notifications';
12
+
13
+ interface ConditionListProps {
14
+ patient: Patient;
15
+ encounter: Encounter;
16
+ conditions: Condition[] | undefined;
17
+ setConditions: (conditions: Condition[]) => void;
18
+ onDiagnosisChange: (diagnosis: EncounterDiagnosis[]) => void;
19
+ }
20
+
21
+ export const ConditionList = (props: ConditionListProps): JSX.Element => {
22
+ const { patient, encounter, conditions, setConditions, onDiagnosisChange } = props;
23
+ const medplum = useMedplum();
24
+ const [opened, setOpened] = useState(false);
25
+
26
+ useEffect(() => {
27
+ const fetchConditions = async (): Promise<void> => {
28
+ if (!encounter) {
29
+ return;
30
+ }
31
+
32
+ const diagnosisReferences = encounter.diagnosis?.map((d) => d.condition?.reference).filter(Boolean) || [];
33
+ const conditionsResult = await Promise.all(
34
+ diagnosisReferences.map((ref) => medplum.readReference({ reference: ref }))
35
+ );
36
+
37
+ if (conditionsResult.length > 0 && encounter?.diagnosis) {
38
+ const diagnosisMap = new Map<string, number>();
39
+
40
+ const diagnosisReferences = encounter.diagnosis?.map((d) => d.condition?.reference) || [];
41
+ const conditionsInDiagnosis = conditionsResult.filter((condition) =>
42
+ diagnosisReferences.includes(getReferenceString(condition))
43
+ );
44
+
45
+ encounter.diagnosis.forEach((diagnosis, index) => {
46
+ if (diagnosis.condition?.reference) {
47
+ diagnosisMap.set(diagnosis.condition.reference, diagnosis.rank || index);
48
+ }
49
+ });
50
+
51
+ conditionsInDiagnosis.sort((a, b) => {
52
+ const aRef = getReferenceString(a);
53
+ const bRef = getReferenceString(b);
54
+
55
+ if (diagnosisMap.has(aRef) && diagnosisMap.has(bRef)) {
56
+ const aValue = diagnosisMap.get(aRef) ?? 0;
57
+ const bValue = diagnosisMap.get(bRef) ?? 0;
58
+ return aValue - bValue;
59
+ }
60
+
61
+ if (diagnosisMap.has(aRef)) {
62
+ return -1;
63
+ }
64
+
65
+ if (diagnosisMap.has(bRef)) {
66
+ return 1;
67
+ }
68
+
69
+ return 0;
70
+ });
71
+
72
+ setConditions(conditionsInDiagnosis as Condition[]);
73
+ }
74
+ };
75
+
76
+ fetchConditions().catch((err) => showErrorNotification(err));
77
+ }, [encounter, medplum, setConditions]);
78
+
79
+ /*
80
+ * Re-orders the conditions in the conditions array and updates the encounter diagnosis.
81
+ */
82
+ const handleUpdateDiagnosis = async (condition: Condition, value: string): Promise<void> => {
83
+ if (!conditions || conditions.length === 0 || !encounter) {
84
+ return;
85
+ }
86
+
87
+ const newRank = Number(value);
88
+ const maxAllowedRank = conditions.length;
89
+ const validRank = Math.max(1, Math.min(newRank, maxAllowedRank));
90
+
91
+ const updatedConditions = [...conditions];
92
+ const conditionIndex = updatedConditions.findIndex((c) => getReferenceString(c) === getReferenceString(condition));
93
+
94
+ if (conditionIndex === -1) {
95
+ return;
96
+ }
97
+
98
+ const conditionToMove = updatedConditions.splice(conditionIndex, 1)[0];
99
+ updatedConditions.splice(validRank - 1, 0, conditionToMove);
100
+ setConditions(updatedConditions);
101
+ onDiagnosisChange(
102
+ updatedConditions.map((c, index) => ({
103
+ condition: { reference: `Condition/${c.id}` },
104
+ rank: index + 1,
105
+ }))
106
+ );
107
+ };
108
+
109
+ const handleRemoveDiagnosis = async (condition: Condition): Promise<void> => {
110
+ if (!conditions) {
111
+ return;
112
+ }
113
+
114
+ try {
115
+ await medplum.deleteResource('Condition', condition.id as string);
116
+ setConditions(conditions?.filter((c) => c.id !== condition.id));
117
+ const updatedDiagnosis = encounter.diagnosis?.filter(
118
+ (d) => d.condition?.reference !== getReferenceString(condition)
119
+ );
120
+ const reindexedDiagnosis = updatedDiagnosis?.map((d, index) => ({
121
+ ...d,
122
+ rank: index + 1,
123
+ }));
124
+
125
+ setConditions(conditions?.filter((c) => c.id !== condition.id) || []);
126
+ onDiagnosisChange(reindexedDiagnosis || []);
127
+ } catch (err) {
128
+ showErrorNotification(err);
129
+ }
130
+ };
131
+
132
+ const handleConditionSubmit = async (condition: Condition): Promise<void> => {
133
+ try {
134
+ const newCondition = await medplum.createResource(condition);
135
+ if (encounter) {
136
+ const updatedDiagnosis = [
137
+ ...(encounter.diagnosis || []),
138
+ {
139
+ condition: { reference: `Condition/${newCondition.id}` },
140
+ rank: encounter.diagnosis?.length ? encounter.diagnosis.length + 1 : 1,
141
+ },
142
+ ];
143
+ setConditions([...(conditions || []), newCondition]);
144
+ onDiagnosisChange(updatedDiagnosis);
145
+ }
146
+ } catch (err) {
147
+ showErrorNotification(err);
148
+ } finally {
149
+ setOpened(false);
150
+ }
151
+ };
152
+
153
+ return (
154
+ <>
155
+ <Stack gap={0}>
156
+ <Text fw={600} size="lg" mb="md">
157
+ Diagnosis
158
+ </Text>
159
+
160
+ <Card withBorder shadow="sm">
161
+ <Stack gap="md">
162
+ {conditions &&
163
+ conditions.length > 0 &&
164
+ conditions.map((condition, idx) => (
165
+ <ConditionItem
166
+ key={condition.id ?? idx}
167
+ condition={condition}
168
+ rank={idx + 1}
169
+ total={conditions.length}
170
+ onChange={handleUpdateDiagnosis}
171
+ onRemove={handleRemoveDiagnosis}
172
+ />
173
+ ))}
174
+
175
+ <Flex>
176
+ <Button onClick={() => setOpened(true)}>Add Diagnosis</Button>
177
+ </Flex>
178
+ </Stack>
179
+ </Card>
180
+ </Stack>
181
+ <Modal opened={opened} onClose={() => setOpened(false)} title={'Add Diagnosis'}>
182
+ <ConditionModal patient={patient} encounter={encounter} onSubmit={handleConditionSubmit} />
183
+ </Modal>
184
+ </>
185
+ );
186
+ };