@photonhealth/react 2.0.0-rc.1 → 2.0.0-rc.3

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 (272) hide show
  1. package/README.md +52 -9
  2. package/dist/adapters/tailwind.d.ts.map +1 -1
  3. package/dist/adapters/tailwind.js +7 -4
  4. package/dist/adapters/tailwind.js.map +1 -1
  5. package/dist/analytics/PhotonAnalyticsProvider.d.ts +19 -0
  6. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  7. package/dist/analytics/PhotonAnalyticsProvider.js +76 -0
  8. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  9. package/dist/analytics/cardLifecycle.d.ts +10 -0
  10. package/dist/analytics/cardLifecycle.d.ts.map +1 -0
  11. package/dist/analytics/cardLifecycle.js +43 -0
  12. package/dist/analytics/cardLifecycle.js.map +1 -0
  13. package/dist/analytics/fieldInteraction.d.ts +18 -0
  14. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  15. package/dist/analytics/fieldInteraction.js +102 -0
  16. package/dist/analytics/fieldInteraction.js.map +1 -0
  17. package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
  18. package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
  19. package/dist/analytics/lifecycleOutcomes.js +16 -0
  20. package/dist/analytics/lifecycleOutcomes.js.map +1 -0
  21. package/dist/analytics/tracker.d.ts +19 -0
  22. package/dist/analytics/tracker.d.ts.map +1 -0
  23. package/dist/analytics/tracker.js +41 -0
  24. package/dist/analytics/tracker.js.map +1 -0
  25. package/dist/analytics/viewed.d.ts +11 -0
  26. package/dist/analytics/viewed.d.ts.map +1 -0
  27. package/dist/analytics/viewed.js +16 -0
  28. package/dist/analytics/viewed.js.map +1 -0
  29. package/dist/components/PhotonOrder.d.ts +18 -18
  30. package/dist/components/PhotonOrder.d.ts.map +1 -1
  31. package/dist/components/PhotonOrder.js +34 -19
  32. package/dist/components/PhotonOrder.js.map +1 -1
  33. package/dist/components/PhotonPatient.d.ts +7 -35
  34. package/dist/components/PhotonPatient.d.ts.map +1 -1
  35. package/dist/components/PhotonPatient.js +6 -78
  36. package/dist/components/PhotonPatient.js.map +1 -1
  37. package/dist/components/PhotonPrescription.d.ts +15 -26
  38. package/dist/components/PhotonPrescription.d.ts.map +1 -1
  39. package/dist/components/PhotonPrescription.js +6 -360
  40. package/dist/components/PhotonPrescription.js.map +1 -1
  41. package/dist/components/format.d.ts +2 -2
  42. package/dist/components/format.js +2 -2
  43. package/dist/components/index.d.ts +1 -1
  44. package/dist/components/index.d.ts.map +1 -1
  45. package/dist/components/index.js +1 -1
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/open.d.ts +11 -13
  48. package/dist/components/open.d.ts.map +1 -1
  49. package/dist/components/open.js +7 -2
  50. package/dist/components/open.js.map +1 -1
  51. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  52. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  53. package/dist/components/order/DraftOrderPrompt.js +26 -0
  54. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  55. package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
  56. package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
  57. package/dist/components/patient/PatientCard/PatientCard.js +101 -0
  58. package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
  59. package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
  60. package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
  61. package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
  62. package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
  63. package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
  64. package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
  65. package/dist/components/patient/PatientIntakeForm.js +114 -0
  66. package/dist/components/patient/PatientIntakeForm.js.map +1 -0
  67. package/dist/components/patient/PatientSearch.d.ts +12 -0
  68. package/dist/components/patient/PatientSearch.d.ts.map +1 -0
  69. package/dist/components/patient/PatientSearch.js +148 -0
  70. package/dist/components/patient/PatientSearch.js.map +1 -0
  71. package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
  72. package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
  73. package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +6 -5
  74. package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
  75. package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +15 -16
  76. package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
  77. package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +29 -28
  78. package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
  79. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
  80. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
  81. package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
  82. package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
  83. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
  84. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
  85. package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
  86. package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
  87. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
  88. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
  89. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
  90. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
  91. package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
  92. package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
  93. package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
  94. package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
  95. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
  96. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
  97. package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
  98. package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
  99. package/dist/components/patient/fields.d.ts +7 -26
  100. package/dist/components/patient/fields.d.ts.map +1 -1
  101. package/dist/components/patient/fields.js +11 -52
  102. package/dist/components/patient/fields.js.map +1 -1
  103. package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
  104. package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
  105. package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -10
  106. package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
  107. package/dist/components/prescription/PrescriptionCard.d.ts +51 -0
  108. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  109. package/dist/components/prescription/PrescriptionCard.js +186 -0
  110. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  111. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  112. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  113. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  114. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  115. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  116. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  117. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  118. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  119. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  120. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  121. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  122. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  123. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  124. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  125. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  126. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  127. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  128. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  129. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  130. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  131. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  132. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  133. package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
  134. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  135. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  136. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  137. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  138. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  139. package/dist/components/schemaErrors.d.ts +13 -0
  140. package/dist/components/schemaErrors.d.ts.map +1 -0
  141. package/dist/components/schemaErrors.js +25 -0
  142. package/dist/components/schemaErrors.js.map +1 -0
  143. package/dist/components/search.d.ts +1 -1
  144. package/dist/components/search.js +1 -1
  145. package/dist/index.d.ts +2 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +1 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/meta/version.d.ts +5 -0
  150. package/dist/meta/version.d.ts.map +1 -0
  151. package/dist/meta/version.js +5 -0
  152. package/dist/meta/version.js.map +1 -0
  153. package/dist/primitives/PhotonProvider.d.ts +3 -1
  154. package/dist/primitives/PhotonProvider.d.ts.map +1 -1
  155. package/dist/primitives/PhotonProvider.js +23 -11
  156. package/dist/primitives/PhotonProvider.js.map +1 -1
  157. package/dist/primitives/defaults.d.ts.map +1 -1
  158. package/dist/primitives/defaults.js +6 -3
  159. package/dist/primitives/defaults.js.map +1 -1
  160. package/dist/primitives/photonContext.d.ts +3 -0
  161. package/dist/primitives/photonContext.d.ts.map +1 -0
  162. package/dist/primitives/photonContext.js +3 -0
  163. package/dist/primitives/photonContext.js.map +1 -0
  164. package/dist/primitives/types.d.ts +15 -3
  165. package/dist/primitives/types.d.ts.map +1 -1
  166. package/dist/primitives/types.js.map +1 -1
  167. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  168. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  169. package/dist/primitives/useProvidedPhoton.js +8 -0
  170. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  171. package/dist/styles.css +45 -3
  172. package/dist/test-utils/contract.d.ts.map +1 -1
  173. package/dist/test-utils/contract.js +23 -2
  174. package/dist/test-utils/contract.js.map +1 -1
  175. package/package.json +8 -3
  176. package/src/adapters/tailwind.tsx +52 -24
  177. package/src/analytics/PhotonAnalyticsProvider.test.tsx +190 -0
  178. package/src/analytics/PhotonAnalyticsProvider.tsx +151 -0
  179. package/src/analytics/cardLifecycle.test.tsx +272 -0
  180. package/src/analytics/cardLifecycle.ts +44 -0
  181. package/src/analytics/fieldInteraction.test.tsx +186 -0
  182. package/src/analytics/fieldInteraction.tsx +148 -0
  183. package/src/analytics/lifecycleOutcomes.test.ts +78 -0
  184. package/src/analytics/lifecycleOutcomes.ts +29 -0
  185. package/src/analytics/tracker.test.ts +52 -0
  186. package/src/analytics/tracker.ts +49 -0
  187. package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
  188. package/src/analytics/viewed.ts +27 -0
  189. package/src/components/PhotonOrder.test.tsx +394 -0
  190. package/src/components/PhotonOrder.tsx +79 -53
  191. package/src/components/PhotonPatient.tsx +15 -166
  192. package/src/components/PhotonPrescription.test.tsx +120 -0
  193. package/src/components/PhotonPrescription.tsx +23 -583
  194. package/src/components/ScreeningAlerts.test.tsx +81 -0
  195. package/src/components/format.ts +2 -2
  196. package/src/components/index.ts +1 -1
  197. package/src/components/open.ts +13 -16
  198. package/src/components/order/DraftOrderPrompt.test.tsx +77 -0
  199. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  200. package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
  201. package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
  202. package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
  203. package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
  204. package/src/components/patient/PatientIntakeForm.tsx +222 -0
  205. package/src/components/patient/PatientSearch.test.tsx +204 -0
  206. package/src/components/patient/PatientSearch.tsx +221 -0
  207. package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
  208. package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +24 -16
  209. package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
  210. package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +53 -48
  211. package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
  212. package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
  213. package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
  214. package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
  215. package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
  216. package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
  217. package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
  218. package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
  219. package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
  220. package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
  221. package/src/components/patient/fields.tsx +12 -124
  222. package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
  223. package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -15
  224. package/src/components/prescription/PrescriptionCard.test.tsx +247 -0
  225. package/src/components/prescription/PrescriptionCard.tsx +361 -0
  226. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +82 -0
  227. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  228. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +206 -0
  229. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  230. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +453 -0
  231. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  232. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  233. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  234. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +72 -0
  235. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  236. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  237. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +695 -0
  238. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  239. package/src/components/schemaErrors.test.ts +49 -0
  240. package/src/components/schemaErrors.ts +34 -0
  241. package/src/components/search.tsx +1 -1
  242. package/src/index.ts +2 -0
  243. package/src/meta/version.test.ts +11 -0
  244. package/src/meta/version.ts +4 -0
  245. package/src/primitives/PhotonProvider.tsx +30 -15
  246. package/src/primitives/defaults.tsx +44 -21
  247. package/src/primitives/photonContext.ts +4 -0
  248. package/src/primitives/types.ts +15 -3
  249. package/src/primitives/useProvidedPhoton.ts +21 -0
  250. package/src/styles.css +45 -3
  251. package/src/test-utils/contract.tsx +45 -2
  252. package/dist/components/TreatmentPicker.d.ts +0 -45
  253. package/dist/components/TreatmentPicker.d.ts.map +0 -1
  254. package/dist/components/TreatmentPicker.js.map +0 -1
  255. package/dist/components/patient/Benefits.d.ts.map +0 -1
  256. package/dist/components/patient/Benefits.js.map +0 -1
  257. package/dist/components/patient/Clinical.d.ts.map +0 -1
  258. package/dist/components/patient/Clinical.js.map +0 -1
  259. package/dist/components/patient/IntakeForm.d.ts +0 -10
  260. package/dist/components/patient/IntakeForm.d.ts.map +0 -1
  261. package/dist/components/patient/IntakeForm.js +0 -324
  262. package/dist/components/patient/IntakeForm.js.map +0 -1
  263. package/dist/components/patient/Summary.d.ts +0 -48
  264. package/dist/components/patient/Summary.d.ts.map +0 -1
  265. package/dist/components/patient/Summary.js +0 -80
  266. package/dist/components/patient/Summary.js.map +0 -1
  267. package/dist/components/patient/query.d.ts +0 -23
  268. package/dist/components/patient/query.d.ts.map +0 -1
  269. package/dist/components/patient/query.js.map +0 -1
  270. package/src/components/TreatmentPicker.tsx +0 -350
  271. package/src/components/patient/IntakeForm.tsx +0 -532
  272. package/src/components/patient/Summary.tsx +0 -310
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useComponents } from "../../primitives/index.js";
4
+ import { treatmentHeading } from "../display.js";
5
+ import { cardProps, focusProps } from "../flow.js";
6
+ import { ReadOnlyRx, StatusBadge } from "../prescription/PrescriptionCard.js";
7
+ /**
8
+ * A patient's draft order, found when they're chosen: its prescriptions, each on its own card as the order's lines
9
+ * are, then the question — continue it, or start a new order. Nothing changes until one is picked. Renders cards
10
+ * only, for PhotonOrder's flow.
11
+ */
12
+ export function DraftOrderPrompt({ draft, onContinue, onStartNew }) {
13
+ const { Button, Card, CardBody, CardFooter, CardHeader, Row, Stack, Text } = useComponents();
14
+ // Which choice is in flight: that button spins, and neither can be pressed again until it settles.
15
+ const [choosing, setChoosing] = useState(null);
16
+ const choose = (which, act) => {
17
+ setChoosing(which);
18
+ // A failure lands on the order (snapshot.error), where the card shows it.
19
+ void new Promise((resolve) => resolve(act())).catch(() => { }).finally(() => setChoosing(null));
20
+ };
21
+ return (_jsxs(_Fragment, { children: [draft.prescriptions.map((rx) => {
22
+ const heading = treatmentHeading(rx.treatment.name, rx.treatment);
23
+ return (_jsx("div", { ...cardProps, children: _jsxs(Card, { divided: true, label: heading.title, children: [_jsx(CardHeader, { title: heading.title, description: heading.detail }), _jsx(CardBody, { children: _jsx(ReadOnlyRx, { rx: rx, status: _jsx(StatusBadge, { rx: rx }) }) })] }) }, rx.id));
24
+ }), _jsx("div", { ...cardProps, children: _jsx(Card, { children: _jsx(CardFooter, { start: _jsxs(Stack, { gap: "3", children: [_jsx(Text, { children: "Would you like to continue this order?" }), _jsxs(Row, { gap: "2", children: [_jsx("span", { ...focusProps, children: _jsx(Button, { loading: choosing === "continue", disabled: choosing !== null, onClick: () => choose("continue", onContinue), children: "Continue" }) }), _jsx(Button, { variant: "secondary", loading: choosing === "new", disabled: choosing !== null, onClick: () => choose("new", onStartNew), children: "Start a new order" })] })] }) }) }) })] }));
25
+ }
26
+ //# sourceMappingURL=DraftOrderPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DraftOrderPrompt.js","sourceRoot":"","sources":["../../../src/components/order/DraftOrderPrompt.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnD,O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AE,GAAI,GAAI,GAC9C,IACN,IANC,EAAE,CAAC,EAAE,CAOT,CACP,CAAC;YACJ,CAAC,CAAC,EACF,iBAAS,SAAS,YAChB,KAAC,IAAI,cAGH,KAAC,UAAU,IACT,KAAK,EACH,MAAC,KAAK,IAAC,GAAG,EAAC,GAAG,aACZ,KAAC,IAAI,yDAA8C,EACnD,MAAC,GAAG,IAAC,GAAG,EAAC,GAAG,aACV,kBAAU,UAAU,YAClB,KAAC,MAAM,IACL,OAAO,EAAE,QAAQ,KAAK,UAAU,EAChC,QAAQ,EAAE,QAAQ,KAAK,IAAI,EAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,yBAGtC,GACJ,EACP,KAAC,MAAM,IACL,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,QAAQ,KAAK,KAAK,EAC3B,QAAQ,EAAE,QAAQ,KAAK,IAAI,EAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,kCAGjC,IACL,IACA,GAEV,GACG,GACH,IACL,CACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type NotFound } from "../../open.ts";
2
+ import type { PhotonPatientProps } from "../../PhotonPatient.tsx";
3
+ /** What PatientCard renders, in the order its body checks for each. */
4
+ export declare enum PatientCardState {
5
+ /** The patient couldn't be opened for a reason other than not found: an error alert. */
6
+ FAILED_TO_OPEN = "failedToOpen",
7
+ /** No live patient yet, or no snapshot of it: the "Loading…" card. */
8
+ LOADING = "loading",
9
+ /** The patient has a record: PatientSummary. */
10
+ SUMMARY = "summary",
11
+ /** The patient has no record yet: PatientSearch, to match any existing records. */
12
+ SEARCH = "search",
13
+ /** The patient has no record yet, and user is adding the patient to Photon: PatientIntakeForm. */
14
+ INTAKE_FORM = "intakeForm"
15
+ }
16
+ /**
17
+ * PhotonPatient, and what only PhotonOrder gives it: read-only and no "Change patient" (a sent order), no "Change
18
+ * patient" (an order handed off to it), and the server's request for a way to reach the patient (its reason),
19
+ * which opens the contact fields. Internal: the package index exports only PhotonPatient.
20
+ */
21
+ export declare function PatientCard({ patient: patientProp, onPatient, readOnly, hideChangePatient, addressRequest, notFound: notFoundInOrder, }: PhotonPatientProps & {
22
+ /** Nothing to edit, and no "Change patient" (a sent order's patient). */
23
+ readOnly?: boolean;
24
+ /** No "Change patient", but still editable (an order handed off to PhotonOrder). */
25
+ hideChangePatient?: boolean;
26
+ addressRequest?: string | null;
27
+ /** The patient it was given by id isn't there (PhotonOrder's): said in the form, with the matches. */
28
+ notFound?: NotFound | null;
29
+ }): import("react").JSX.Element;
30
+ //# sourceMappingURL=PatientCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatientCard.d.ts","sourceRoot":"","sources":["../../../../src/components/patient/PatientCard/PatientCard.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAiBlE,uEAAuE;AACvE,oBAAY,gBAAgB;IAC1B,wFAAwF;IACxF,cAAc,iBAAiB;IAC/B,sEAAsE;IACtE,OAAO,YAAY;IACnB,gDAAgD;IAChD,OAAO,YAAY;IACnB,mFAAmF;IACnF,MAAM,WAAW;IACjB,kGAAkG;IAClG,WAAW,eAAe;CAC3B;AA8BD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAC1B,OAAO,EAAE,WAAW,EACpB,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,QAAQ,EAAE,eAAe,GAC1B,EAAE,kBAAkB,GAAG;IACtB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oFAAoF;IACpF,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,sGAAsG;IACtG,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B,+BA4FA"}
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useComponents } from "../../../primitives/index.js";
3
+ import { classify } from "@photonhealth/client";
4
+ import { useLive, useOnChange } from "../../../hooks/index.js";
5
+ import { useState } from "react";
6
+ import { openFailed } from "../../open.js";
7
+ import { PatientIntakeForm } from "../PatientIntakeForm.js";
8
+ import { PatientSearch } from "../PatientSearch.js";
9
+ import { PatientSummary } from "../PatientSummary/PatientSummary.js";
10
+ import { usePatientToShow } from "./usePatientToShow.js";
11
+ import { useSavePatientAndSendEvent } from "../../../analytics/cardLifecycle.js";
12
+ /** A stable key per live object: a different patient object gets a fresh form. */
13
+ const objectKeys = new WeakMap();
14
+ let nextKey = 0;
15
+ const keyOf = (obj) => {
16
+ if (!objectKeys.has(obj))
17
+ objectKeys.set(obj, ++nextKey);
18
+ return objectKeys.get(obj);
19
+ };
20
+ /** What PatientCard renders, in the order its body checks for each. */
21
+ export var PatientCardState;
22
+ (function (PatientCardState) {
23
+ /** The patient couldn't be opened for a reason other than not found: an error alert. */
24
+ PatientCardState["FAILED_TO_OPEN"] = "failedToOpen";
25
+ /** No live patient yet, or no snapshot of it: the "Loading…" card. */
26
+ PatientCardState["LOADING"] = "loading";
27
+ /** The patient has a record: PatientSummary. */
28
+ PatientCardState["SUMMARY"] = "summary";
29
+ /** The patient has no record yet: PatientSearch, to match any existing records. */
30
+ PatientCardState["SEARCH"] = "search";
31
+ /** The patient has no record yet, and user is adding the patient to Photon: PatientIntakeForm. */
32
+ PatientCardState["INTAKE_FORM"] = "intakeForm";
33
+ })(PatientCardState || (PatientCardState = {}));
34
+ /** Which state PatientCard is in, from what usePatientToShow and useLive give it. */
35
+ const getPatientCardState = ({ failedToOpen, patient, snap, adding, }) => {
36
+ if (failedToOpen)
37
+ return PatientCardState.FAILED_TO_OPEN;
38
+ if (!patient || !snap)
39
+ return PatientCardState.LOADING;
40
+ if (snap.state)
41
+ return PatientCardState.SUMMARY;
42
+ return adding ? PatientCardState.INTAKE_FORM : PatientCardState.SEARCH;
43
+ };
44
+ /**
45
+ * Whether a patient without a record starts on PatientIntakeForm rather than PatientSearch: when it already has
46
+ * a name or date of birth (e.g. a host's details the server hasn't matched), there's nothing left to search for.
47
+ */
48
+ const startsAdding = (patient) => {
49
+ const demographic = patient.known.demographic;
50
+ return Boolean(demographic?.name?.first || demographic?.name?.last || demographic?.dateOfBirth);
51
+ };
52
+ /**
53
+ * PhotonPatient, and what only PhotonOrder gives it: read-only and no "Change patient" (a sent order), no "Change
54
+ * patient" (an order handed off to it), and the server's request for a way to reach the patient (its reason),
55
+ * which opens the contact fields. Internal: the package index exports only PhotonPatient.
56
+ */
57
+ export function PatientCard({ patient: patientProp, onPatient, readOnly, hideChangePatient, addressRequest, notFound: notFoundInOrder, }) {
58
+ const { Alert, Card, CardHeader } = useComponents();
59
+ const { patient, notFound, failedToOpen, startOver } = usePatientToShow(patientProp, { readOnly });
60
+ const snap = useLive(patient);
61
+ useOnChange(patient, (p) => p.state, onPatient);
62
+ const savePatientAndSendEvent = useSavePatientAndSendEvent();
63
+ // Finding someone and adding them are two different jobs, so the card does one at a time. Decided once per patient
64
+ // object: "Add new patient" switches to adding, with what was typed; a different patient object starts over.
65
+ const [intake, setIntake] = useState(null);
66
+ const intakeForPatient = intake?.patient === patient ? intake : null;
67
+ if (patient && !intakeForPatient)
68
+ setIntake({ patient, adding: startsAdding(patient), query: null });
69
+ const adding = intakeForPatient?.adding ?? (patient ? startsAdding(patient) : false);
70
+ const state = getPatientCardState({ failedToOpen, patient, snap, adding });
71
+ if (state === PatientCardState.FAILED_TO_OPEN)
72
+ return _jsx(Alert, { tone: "critical", title: openFailed("patient", failedToOpen), description: failedToOpen.message });
73
+ if (state === PatientCardState.LOADING) {
74
+ return (_jsx(Card, { divided: true, children: _jsx(CardHeader, { title: "Patient", description: "Loading\u2026" }) }));
75
+ }
76
+ // Past LOADING, getPatientCardState guarantees both are set.
77
+ const livePatient = patient;
78
+ const snapshot = snap;
79
+ const changes = classify(snapshot.changes);
80
+ const update = (input) => void savePatientAndSendEvent(livePatient, () => livePatient.update(input)).catch(() => { }); // failures land on the object
81
+ const patchClinical = (clinical) => update({ clinical });
82
+ const choose = (option) => void savePatientAndSendEvent(livePatient, () => livePatient.choose(option)).catch(() => { });
83
+ if (state === PatientCardState.SUMMARY) {
84
+ const record = snapshot.state;
85
+ return (_jsx(PatientSummary, { patient: record, saving: snapshot.status === "saving", changes: changes, error: snapshot.error, onChoose: choose, onAddAllergy: (name) => patchClinical({ allergies: { add: [{ name }] } }), onConfirmNone: (list) => patchClinical({ [list]: { none: true } }), onRemoveAllergy: (a) => patchClinical({ allergies: { remove: [{ id: a.id }] } }), onRemoveMedication: (m) => patchClinical({ medications: { remove: [{ id: m.id, status: m.status }] } }), onAddDiagnosis: (diagnosis) => patchClinical({ diagnoses: { add: [diagnosis] } }), onRemoveDiagnosis: (d) => patchClinical({ diagnoses: { remove: [{ id: d.id }] } }), onAddBenefit: (b) => update({ benefits: { add: [b] } }), onRemoveBenefit: (b) => update({ benefits: { remove: [{ id: b.id }] } }), onConfirmNoBenefits: () => update({ benefits: { none: true } }), onAddMedication: (name) => patchClinical({ medications: { add: [{ name, status: "ACTIVE" }] } }), onSaveDetails: (input) => savePatientAndSendEvent(livePatient, () => livePatient.update(input)).then(() => true, () => false), addressRequest: readOnly ? null : (addressRequest ?? null), readOnly: readOnly, onChangePatient: readOnly || hideChangePatient
86
+ ? undefined
87
+ : () => {
88
+ onPatient?.(null); // given a patient, the host decides what's next
89
+ startOver();
90
+ } }, record.id));
91
+ }
92
+ // SEARCH or INTAKE_FORM. An id that was not found: said with the search, or on the form, for someone else.
93
+ const notFoundError = notFoundInOrder ?? notFound;
94
+ const notice = notFoundError && { title: openFailed("patient", notFoundError), description: notFoundError.message };
95
+ // A different patient object (e.g. after "Change patient") starts a fresh search or form.
96
+ if (state === PatientCardState.SEARCH) {
97
+ return (_jsx(PatientSearch, { patient: livePatient, notice: notice, onAddNew: (query) => setIntake({ patient: livePatient, adding: true, query }) }, keyOf(livePatient)));
98
+ }
99
+ return (_jsx(PatientIntakeForm, { patient: livePatient, query: intakeForPatient?.query, notice: notice }, keyOf(livePatient)));
100
+ }
101
+ //# sourceMappingURL=PatientCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatientCard.js","sourceRoot":"","sources":["../../../../src/components/patient/PatientCard/PatientCard.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAsD,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,UAAU,EAAiB,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAsC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAIjF,kFAAkF;AAClF,MAAM,UAAU,GAAG,IAAI,OAAO,EAAkB,CAAC;AACjD,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,UAAU,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;AAC9B,CAAC,CAAC;AAEF,uEAAuE;AACvE,MAAM,CAAN,IAAY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AIvB,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,iBAAiB,IAA0B,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,IAAxF,KAAK,CAAC,WAAW,CAAC,CAA0E,CACrH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Patient } from "@photonhealth/client";
2
+ import { NotFound } from "../../open.ts";
3
+ import type { PhotonPatientProps } from "../../PhotonPatient.tsx";
4
+ /**
5
+ * Which live Patient a patient card shows, from its `patient` prop:
6
+ * - the host's live `Patient`, if it passed one;
7
+ * - otherwise a blank patient the card made to find or add someone, if it has one for this prop — made when the
8
+ * prop has nothing to open, when its id isn't found, or on "Change patient" (`startOver`);
9
+ * - otherwise the one opened from the prop's id or fields (`null` while it opens).
10
+ *
11
+ * A blank patient belongs to the prop value it was made for, so when the host passes something else the card
12
+ * shows that instead, and passing nothing again gives a fresh blank patient.
13
+ */
14
+ export declare function usePatientToShow(patientProp: PhotonPatientProps["patient"], { readOnly }?: {
15
+ readOnly?: boolean | undefined;
16
+ }): {
17
+ patient: Patient | null;
18
+ notFound: NotFound | null;
19
+ failedToOpen: Error | null;
20
+ startOver: () => void;
21
+ };
22
+ //# sourceMappingURL=usePatientToShow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePatientToShow.d.ts","sourceRoot":"","sources":["../../../../src/components/patient/PatientCard/usePatientToShow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAyC,MAAM,sBAAsB,CAAC;AAGtF,OAAO,EAAE,QAAQ,EAAqB,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAKlE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,CAAC,SAAS,CAAC,EAAE,EAAE,QAAgB,EAAE;;CAAK;;;;;EAwBrG"}
@@ -0,0 +1,40 @@
1
+ import { Patient } from "@photonhealth/client";
2
+ import { useState } from "react";
3
+ import { usePhoton } from "../../../primitives/index.js";
4
+ import { NotFound, toOpen, useOpened } from "../../open.js";
5
+ // At module level, not inline: useOpened re-runs its server call when this function changes.
6
+ const patientOf = (result) => result.patient;
7
+ /**
8
+ * Which live Patient a patient card shows, from its `patient` prop:
9
+ * - the host's live `Patient`, if it passed one;
10
+ * - otherwise a blank patient the card made to find or add someone, if it has one for this prop — made when the
11
+ * prop has nothing to open, when its id isn't found, or on "Change patient" (`startOver`);
12
+ * - otherwise the one opened from the prop's id or fields (`null` while it opens).
13
+ *
14
+ * A blank patient belongs to the prop value it was made for, so when the host passes something else the card
15
+ * shows that instead, and passing nothing again gives a fresh blank patient.
16
+ */
17
+ export function usePatientToShow(patientProp, { readOnly = false } = {}) {
18
+ const ph = usePhoton();
19
+ const hostPatient = patientProp instanceof Patient ? patientProp : null;
20
+ const patientToOpen = toOpen(patientProp, Boolean(hostPatient));
21
+ // Hooks run on every render, before any return (React's rule). With a host patient there's nothing to open.
22
+ const { opened: openedPatient, error: openError } = useOpened(ph.patient, patientToOpen, patientOf, "patient");
23
+ const [blank, setBlank] = useState(null);
24
+ // The host's live Patient: shown as is. "Change patient" is the host's to handle (the card calls onPatient(null)).
25
+ if (hostPatient)
26
+ return { patient: hostPatient, notFound: null, failedToOpen: null, startOver: () => { } };
27
+ const propKey = JSON.stringify(patientToOpen);
28
+ const startOver = () => setBlank({ forProp: propKey, patient: ph.patient() });
29
+ const blankPatient = blank?.forProp === propKey ? blank.patient : null;
30
+ // An id the server doesn't have: the card asks for someone to find or add instead, saying why. A read-only card
31
+ // can't add anyone, so it shows the error instead.
32
+ const notFound = openError instanceof NotFound && !readOnly ? openError : null;
33
+ // Any other failure to open: the card shows it.
34
+ const failedToOpen = openError && !notFound ? openError : null;
35
+ // Nothing to open, or not found: a blank patient to find or add someone.
36
+ if (!blankPatient && (!patientToOpen || notFound))
37
+ startOver();
38
+ return { patient: blankPatient ?? openedPatient, notFound, failedToOpen, startOver };
39
+ }
40
+ //# sourceMappingURL=usePatientToShow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePatientToShow.js","sourceRoot":"","sources":["../../../../src/components/patient/PatientCard/usePatientToShow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAyC,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG5D,6FAA6F;AAC7F,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;AAE5D;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAA0C,EAAE,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,EAAE;IACpG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IACvB,MAAM,WAAW,GAAG,WAAW,YAAY,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;IACxE,MAAM,aAAa,GAAG,MAAM,CAAe,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC9E,4GAA4G;IAC5G,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAC/G,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA+C,IAAI,CAAC,CAAC;IAEvF,mHAAmH;IACnH,IAAI,WAAW;QAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAE1G,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC9E,MAAM,YAAY,GAAG,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,gHAAgH;IAChH,mDAAmD;IACnD,MAAM,QAAQ,GAAG,SAAS,YAAY,QAAQ,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/E,gDAAgD;IAChD,MAAM,YAAY,GAAG,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAE/D,yEAAyE;IACzE,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,aAAa,IAAI,QAAQ,CAAC;QAAE,SAAS,EAAE,CAAC;IAE/D,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;AACvF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type Patient } from "@photonhealth/client";
2
+ export declare function PatientIntakeForm({ patient, query, notice, }: {
3
+ patient: Patient;
4
+ /**
5
+ * What was typed in PatientSearch before "Add new patient": split into the fields, so nothing is retyped and the
6
+ * prescriber can see, and correct, how it was read. Without one, the fields start from what the patient already
7
+ * has (e.g. a host's details the server hasn't matched yet).
8
+ */
9
+ query?: string | null;
10
+ /** Why someone else is being added (e.g. the patient given by id isn't there). */
11
+ notice?: {
12
+ title: string;
13
+ description: string;
14
+ } | null;
15
+ }): import("react").JSX.Element;
16
+ //# sourceMappingURL=PatientIntakeForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatientIntakeForm.d.ts","sourceRoot":"","sources":["../../../src/components/patient/PatientIntakeForm.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,OAAO,EAAY,MAAM,sBAAsB,CAAC;AAcxE,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,KAAK,EACL,MAAM,GACP,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,kFAAkF;IAClF,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACxD,+BA+LA"}
@@ -0,0 +1,114 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** PhotonPatient before a record, adding them: the fields network-api needs, and what the server says about them. */
3
+ import { useComponents } from "../../primitives/index.js";
4
+ import { classify } from "@photonhealth/client";
5
+ import { useLive } from "../../hooks/index.js";
6
+ import { useEffect, useId, useRef, useState } from "react";
7
+ import { ChangeList } from "../ChangeList.js";
8
+ import { formatPhone, PHONE_PATTERN, toE164 } from "../format.js";
9
+ import { IDENTITY_KEYS, noAutofill, SEX_OPTIONS } from "./fields.js";
10
+ import { focusProps } from "../flow.js";
11
+ import { parsePatientSearchQuery } from "./parsePatientSearchQuery.js";
12
+ import { TrackedField, useFieldInteractions } from "../../analytics/fieldInteraction.js";
13
+ import { useSavePatientAndSendEvent } from "../../analytics/cardLifecycle.js";
14
+ export function PatientIntakeForm({ patient, query, notice, }) {
15
+ const { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Grid, Input, Select, Spinner, Stack } = useComponents();
16
+ const snap = useLive(patient);
17
+ const formId = useId();
18
+ const savePatientAndSendEvent = useSavePatientAndSendEvent();
19
+ const known = patient.known;
20
+ const typed = query != null ? parsePatientSearchQuery(query) : null;
21
+ const [first, setFirst] = useState((typed ? typed.name?.first : known.demographic?.name?.first) ?? "");
22
+ const [last, setLast] = useState((typed ? typed.name?.last : known.demographic?.name?.last) ?? "");
23
+ const [dob, setDob] = useState((typed ? typed.dateOfBirth : known.demographic?.dateOfBirth) ?? "");
24
+ const [sex, setSex] = useState(known.demographic?.sex ?? null);
25
+ const sexPicked = useFieldInteractions("new_patient_form")("sex", { isOptional: false, hasValue: Boolean(sex) });
26
+ const [email, setEmail] = useState(typed?.email ?? known.contact?.email ?? "");
27
+ const knownPhone = typed?.phone ?? known.contact?.phone;
28
+ const [phone, setPhone] = useState(knownPhone ? formatPhone(knownPhone) : "");
29
+ /** Which of the four network-api needs were empty when Save was last pressed. */
30
+ const [missing, setMissing] = useState([]);
31
+ /** What a required field says while Save is waiting on it. The server names all four at once; we don't. */
32
+ const gap = (field) => missing.includes(field) ? { invalid: true, errorMessage: "Needed to add a patient" } : {};
33
+ const busy = snap.status === "loading" || snap.status === "saving";
34
+ // What the server still needs to add the patient (name, DOB, sex) is what this form asks for next — not an
35
+ // error. Once the prescriber has filled all four, anything it still rejects about them is shown.
36
+ const identityFilled = Boolean(first.trim() && last.trim() && dob && sex);
37
+ const changes = classify({
38
+ ...snap.changes,
39
+ unapplied: snap.changes.unapplied.filter((c) => identityFilled || !IDENTITY_KEYS.includes(c.key)),
40
+ });
41
+ /** Everything known on the form. Phone / email ride along once they're valid; the browser shows why otherwise. */
42
+ const form = () => {
43
+ const validPhone = new RegExp(`^(?:${PHONE_PATTERN})$`).test(phone.trim());
44
+ const validEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim());
45
+ const demographic = {
46
+ name: { first, last },
47
+ dateOfBirth: dob,
48
+ ...(sex ? { sex } : {}),
49
+ };
50
+ const contact = {
51
+ ...(validPhone ? { phone: toE164(phone) } : {}),
52
+ ...(validEmail ? { email: email.trim() } : {}),
53
+ };
54
+ return { demographic, contact };
55
+ };
56
+ /** Send everything known: the server may find or add the patient. The object adds it to what it sent before. */
57
+ const send = () => void savePatientAndSendEvent(patient, () => patient.sync(form())).catch(() => { }); // failures land on the object
58
+ /** A field changed: keep it. Answering what Save asked for puts it right at once. */
59
+ const type = (field, set) => (e) => {
60
+ set(e.target.value);
61
+ if (field && e.target.value.trim())
62
+ setMissing((m) => m.filter((f) => f !== field));
63
+ };
64
+ const submit = (e) => {
65
+ e.preventDefault();
66
+ save();
67
+ };
68
+ /**
69
+ * Add them. network-api creates a patient only with a first name, a last name, a date of birth and a sex
70
+ * (`Sex` has UNKNOWN, so there is always an answer), and the schema says nothing about which of them a
71
+ * payload is short of — so the form checks before it sends, rather than Save failing with a rejection
72
+ * naming every field at once.
73
+ *
74
+ * The server still decides what this means: it may find the patient instead of adding them, or come back
75
+ * with people it might be. Only this press asks it.
76
+ */
77
+ const REQUIRED = [
78
+ ["first", Boolean(first.trim())],
79
+ ["last", Boolean(last.trim())],
80
+ ["dob", Boolean(dob)],
81
+ ["sex", Boolean(sex)],
82
+ ];
83
+ const save = () => {
84
+ const empty = REQUIRED.filter(([, filled]) => !filled).map(([field]) => field);
85
+ setMissing(empty);
86
+ if (empty.length)
87
+ return; // the fields say which; the cursor goes to the first of them (below)
88
+ send();
89
+ };
90
+ // Sex is the one thing a search never fills in, and the one network-api needs to create, so that's where focus
91
+ // goes: the form is filled in and the deliberate act is choosing it.
92
+ const sexField = useRef(null);
93
+ const fields = useRef(null);
94
+ // Save pressed with gaps: the cursor goes to the first field it is waiting on, so answering starts there.
95
+ useEffect(() => {
96
+ if (!missing.length)
97
+ return;
98
+ fields.current?.querySelector('[aria-invalid="true"], [data-invalid]')?.focus();
99
+ }, [missing]);
100
+ // Once the form is up, the cursor goes to Sex (the Select is a building block, so by where it lands).
101
+ const landed = useRef(false);
102
+ useEffect(() => {
103
+ if (landed.current || !sexField.current)
104
+ return;
105
+ landed.current = true;
106
+ sexField.current.querySelector("input, select, button")?.focus();
107
+ }, []);
108
+ return (_jsxs(Card, { divided: true, children: [_jsx(CardHeader, { title: "Patient" }), _jsx(CardBody, { children: _jsx("form", { ...noAutofill, ref: fields, id: formId, onSubmit: submit, children: _jsxs(Stack, { gap: "3", children: [_jsxs(Grid, { min: "200px", gap: "3", children: [_jsx("div", { ...focusProps, children: _jsx(TrackedField, { formName: "new_patient_form", fieldName: "firstName", isOptional: false, children: _jsx(Input, { ...gap("first"), label: "First name", value: first, onChange: type("first", setFirst), autoFocus: true, ...noAutofill }) }) }), _jsx(TrackedField, { formName: "new_patient_form", fieldName: "lastName", isOptional: false, children: _jsx(Input, { ...gap("last"), label: "Last name", value: last, onChange: type("last", setLast), ...noAutofill }) }), _jsx(TrackedField, { formName: "new_patient_form", fieldName: "dateOfBirth", isOptional: false, children: _jsx(Input, { ...gap("dob"), label: "Date of birth", type: "date", ...noAutofill, value: dob, onChange: type("dob", setDob) }) }), _jsx("div", { ref: sexField, onFocus: sexPicked.onFocus, onBlur: sexPicked.onBlur, children: _jsx(Select, { ...gap("sex"), label: "Sex", placeholder: "Select\u2026", options: SEX_OPTIONS, value: sex, onChange: (next) => {
109
+ sexPicked.onChange(true);
110
+ setSex(next);
111
+ setMissing((m) => m.filter((f) => f !== "sex"));
112
+ } }) }), _jsx(TrackedField, { formName: "new_patient_form", fieldName: "phone", isOptional: true, children: _jsx(Input, { label: "Phone", helper: "The patient is texted their order link here, so a mobile number.", type: "tel", inputMode: "tel", pattern: PHONE_PATTERN, value: phone, onChange: type(null, setPhone), onBlur: () => setPhone(formatPhone(phone)), ...noAutofill }) }), _jsx(TrackedField, { formName: "new_patient_form", fieldName: "email", isOptional: true, children: _jsx(Input, { label: "Email", type: "email", inputMode: "email", value: email, onChange: type(null, setEmail), ...noAutofill }) })] }), notice && _jsx(Alert, { tone: "critical", title: notice.title, description: notice.description }), _jsx(ChangeList, { changes: changes }), snap.error && _jsx(Badge, { tone: "critical", children: snap.error.message })] }) }) }), _jsx(CardFooter, { start: busy ? _jsx(Spinner, { label: "Adding\u2026" }) : undefined, children: _jsx(Button, { type: "submit", form: formId, loading: busy, children: "Save patient" }) })] }));
113
+ }
114
+ //# sourceMappingURL=PatientIntakeForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatientIntakeForm.js","sourceRoot":"","sources":["../../../src/components/patient/PatientIntakeForm.tsx"],"names":[],"mappings":";AAAA,qHAAqH;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAA0B,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAoB,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAc,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qCAAsC,CAAC;AAC1F,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAI9E,MAAM,UAAU,iBAAiB,CAAC,EAChC,OAAO,EACP,KAAK,EACL,MAAM,GAWP;IACC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GACzG,aAAa,EAAE,CAAC;IAClB,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;IACvB,M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C,KAAK,IACJ,KAAK,EAAC,OAAO,EACb,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,OAAO,EACjB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,KAC1B,UAAU,GACd,GACW,IACV,EAGN,MAAM,IAAI,KAAC,KAAK,IAAC,IAAI,EAAC,UAAU,EAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,GAAI,EAC1F,KAAC,UAAU,IAAC,OAAO,EAAE,OAAO,GAAI,EAC/B,IAAI,CAAC,KAAK,IAAI,KAAC,KAAK,IAAC,IAAI,EAAC,UAAU,YAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAS,IAC5D,GACH,GACE,EAGX,KAAC,UAAU,IAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAC,OAAO,IAAC,KAAK,EAAC,cAAS,GAAG,CAAC,CAAC,CAAC,SAAS,YAC/D,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,6BAExC,GACE,IACR,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type Patient } from "@photonhealth/client";
2
+ export declare function PatientSearch({ patient, notice, onAddNew, }: {
3
+ patient: Patient;
4
+ /** Why someone else is being found (e.g. the patient given by id isn't there): shown with the matches. */
5
+ notice?: {
6
+ title: string;
7
+ description: string;
8
+ } | null;
9
+ /** "Add new patient": none of these. Gets what was typed, to fill PatientIntakeForm from. */
10
+ onAddNew: (query: string) => void;
11
+ }): import("react").JSX.Element;
12
+ //# sourceMappingURL=PatientSearch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatientSearch.d.ts","sourceRoot":"","sources":["../../../src/components/patient/PatientSearch.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AA6B9D,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,MAAM,EACN,QAAQ,GACT,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,0GAA0G;IAC1G,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACvD,6FAA6F;IAC7F,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,+BAmLA"}
@@ -0,0 +1,148 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** PhotonPatient before a record, finding them: one field that searches as it's typed in, and who they might be. */
3
+ import { useComponents } from "../../primitives/index.js";
4
+ import { classify } from "@photonhealth/client";
5
+ import { useLatestCallback, useLive } from "../../hooks/index.js";
6
+ import { useEffect, useRef, useState } from "react";
7
+ import { useHeldActivity } from "../activity.js";
8
+ import { ChangeList } from "../ChangeList.js";
9
+ import { formatDate } from "../format.js";
10
+ import { FEW, searchKeys, SearchResults, useTypeAhead } from "../search.js";
11
+ import { focusProps, searchProps } from "../flow.js";
12
+ import { IDENTITY_KEYS, noAutofill } from "./fields.js";
13
+ import { parsePatientSearchQuery } from "./parsePatientSearchQuery.js";
14
+ import { TrackedField } from "../../analytics/fieldInteraction.js";
15
+ /** query as patient input */
16
+ const toSearchInput = ({ phone, email, ...demographic }) => ({
17
+ demographic,
18
+ contact: { ...(phone ? { phone } : {}), ...(email ? { email } : {}) },
19
+ });
20
+ /** Whether a query says anything the server can match on. */
21
+ const isSearchable = (q) => Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
22
+ /**
23
+ * One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
24
+ * as a last name — "Lovelace" is as likely as "Ada".
25
+ */
26
+ const searchBoth = (q) => q.name?.first && !q.name.last && !q.dateOfBirth && !q.phone && !q.email ? { name: { last: q.name.first } } : null;
27
+ export function PatientSearch({ patient, notice, onAddNew, }) {
28
+ const { Alert, Badge, Card, CardBody, CardHeader, Input, Stack } = useComponents();
29
+ const snap = useLive(patient);
30
+ const [query, setQuery] = useState("");
31
+ /** What the matches below answer — the query as it was typed when the search went out. */
32
+ const [searched, setSearched] = useState(null);
33
+ /** The row the keys are on, by DOM id: the field says so with `aria-activedescendant`. */
34
+ const [activeId, setActiveId] = useState(null);
35
+ const busy = snap.status === "loading" || snap.status === "saving";
36
+ const candidates = snap.candidates;
37
+ // What the server says. While searching, nothing about the patient's name, date of birth or sex is missing yet:
38
+ // the search only lists who it might be.
39
+ const changes = classify({
40
+ ...snap.changes,
41
+ unapplied: snap.changes.unapplied.filter((c) => !IDENTITY_KEYS.includes(c.key)),
42
+ });
43
+ // The field shows a spinner while its search is out (held briefly, so it doesn't flicker).
44
+ const [searching, setSearching] = useState(false);
45
+ if (searching && !busy)
46
+ setSearching(false); // answered
47
+ const spinning = useHeldActivity(searching ? "query" : null) === "query";
48
+ /**
49
+ * The search, answered. Only ever `search`: it can't create, and it can't change whoever it finds. One word
50
+ * could be either name, so if it draws a blank as a first name it's asked again as a last name — "Lovelace"
51
+ * is as likely to be typed as "Ada".
52
+ */
53
+ const runSearch = useLatestCallback(() => {
54
+ const text = query.trim();
55
+ const parsed = parsePatientSearchQuery(text);
56
+ if (!isSearchable(parsed))
57
+ return;
58
+ setSearching(true);
59
+ void (async () => {
60
+ try {
61
+ await patient.search(toSearchInput(parsed));
62
+ const alsoLast = searchBoth(parsed);
63
+ if (alsoLast && patient.snapshot.candidates.length === 0)
64
+ await patient.search(toSearchInput(alsoLast));
65
+ }
66
+ catch {
67
+ // failures land on the object
68
+ }
69
+ setSearched(text);
70
+ })();
71
+ });
72
+ // Two characters: network-api matches "a first/last name prefix of 2+ characters" (`AmbiguousPatientMatch`),
73
+ // and short surnames are real — Ng, Wu, Li. Not one: that would match thousands, and the server returns at
74
+ // most twenty candidates, so it would hand back an arbitrary slice — a list without your patient in it reads
75
+ // as "not here", which is how a duplicate gets made.
76
+ const typeAhead = useTypeAhead(() => runSearch(), { minChars: 2 });
77
+ // A few matches listed: they're the next thing to look at.
78
+ const few = candidates.length > 0 && candidates.length < FEW;
79
+ const answered = () => !typeAhead.waiting() && !busy && searched === query.trim();
80
+ /** The search is answered, and nobody came back. Not the same as nobody being there. */
81
+ const answeredNothing = searched !== null && searched === query.trim() && candidates.length === 0 && !busy && !typeAhead.waiting();
82
+ const matches = useRef(null);
83
+ // The search field: Esc in the matches goes back to it.
84
+ const field = useRef(null);
85
+ // The field is a search field over the matches (searchKeys): ↑ ↓ move a highlight, Return takes it. Return
86
+ // with nothing to take searches now, rather than after the pause.
87
+ const onKeyDown = (e) => {
88
+ if (searchKeys(e, matches.current, answered()))
89
+ return;
90
+ if (e.key !== "Enter")
91
+ return;
92
+ e.preventDefault();
93
+ typeAhead.cancel();
94
+ runSearch();
95
+ };
96
+ // A few matches for what's being typed, and the prescriber is still in the field: focus goes to the first,
97
+ // ready to pick — typing carries on in the field (search.tsx). Once per answer.
98
+ const matchesFor = candidates.map((c) => c.id).join();
99
+ const focusedFor = useRef(null);
100
+ const focusFew = useLatestCallback(() => {
101
+ if (!few || !answered() || !field.current || document.activeElement !== field.current)
102
+ return;
103
+ if (focusedFor.current === matchesFor)
104
+ return;
105
+ focusedFor.current = matchesFor;
106
+ matches.current?.focus(true);
107
+ });
108
+ // Also on `searched`: the matches can land before the card has noted which query they answer, and until
109
+ // it has, they aren't an answer to move to.
110
+ useEffect(() => focusFew(), [matchesFor, busy, searched, focusFew]);
111
+ return (_jsxs(Card, { divided: true, children: [_jsx(CardHeader, { title: "Patient" }), _jsx(CardBody, { children: _jsxs(Stack, { gap: "3", children: [_jsx("div", { ...focusProps, ...searchProps, onFocus: (e) => {
112
+ if (e.target instanceof HTMLInputElement)
113
+ field.current = e.target;
114
+ }, children: _jsx(TrackedField, { formName: "find_patient", fieldName: "patientSearch", isOptional: false, children: _jsx(Input, { label: "Find patient", placeholder: "Name, date of birth, phone or email", value: query, onChange: (e) => {
115
+ setQuery(e.target.value);
116
+ typeAhead.typed("query", e.target.value);
117
+ // Too little left to search on: the matches on screen answer a query that isn't there any more,
118
+ // so they go, and the card is back where it started — including what it has already moved the
119
+ // cursor to, or typing the same name again would land nowhere.
120
+ if (typeAhead.tooShort(e.target.value)) {
121
+ setSearched(null);
122
+ focusedFor.current = null;
123
+ }
124
+ }, onBlur: () => {
125
+ // Leaving asks now rather than after the pause — a search, never a sync: it can't create anyone
126
+ // and it can't change whoever it finds.
127
+ typeAhead.cancel();
128
+ if (query.trim() !== searched)
129
+ runSearch();
130
+ }, onKeyDown: onKeyDown, loading: spinning, role: "combobox", "aria-expanded": searched !== null, "aria-autocomplete": "list", "aria-activedescendant": activeId ?? undefined, autoFocus: true, ...noAutofill }) }) }), answeredNothing && (_jsx(Alert, { title: "Spelling has to be exact.", description: "Try another spelling, fewer letters, or a date of birth." })), searched !== null && (_jsx(SearchResults, { label: candidates.length > 0 ? "Matching patients" : "No matching patients", results: candidates.map((m) => ({
131
+ key: m.id,
132
+ label: [m.firstName, m.lastName].filter(Boolean).join(" "),
133
+ meta: m.dateOfBirth ? formatDate(m.dateOfBirth) : undefined,
134
+ })), onPick: (id) => void patient.pick(id).catch(() => { }), busy: busy, handleRef: matches, onBack: () => field.current?.focus(),
135
+ // The cursor stays in the field: ↑ ↓ move a highlight, Return takes it, and a letter or a Backspace
136
+ // always lands in the field — the prescriber can narrow or start over mid-list.
137
+ inField: true, onActive: setActiveId,
138
+ // The last row: ↓ past the final match lands on it, and Return takes it.
139
+ action: {
140
+ label: "Add new patient",
141
+ icon: "add",
142
+ onChoose: () => {
143
+ typeAhead.cancel();
144
+ onAddNew(query);
145
+ },
146
+ } })), notice && _jsx(Alert, { tone: "critical", title: notice.title, description: notice.description }), _jsx(ChangeList, { changes: changes }), snap.error && _jsx(Badge, { tone: "critical", children: snap.error.message })] }) })] }));
147
+ }
148
+ //# sourceMappingURL=PatientSearch.js.map
@@ -0,0 +1 @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