@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,164 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { BenefitsInputForm } from "./BenefitsInputForm.tsx";
5
+
6
+ type Props = Parameters<typeof BenefitsInputForm>[0];
7
+
8
+ const plan = { id: "ben_1", bin: "610014", pcn: "PCN1", groupId: "GRP1", memberId: "M123" };
9
+
10
+ const renderForm = (overrides: Partial<Props> = {}) => {
11
+ const props: Props = {
12
+ benefits: null,
13
+ saving: false,
14
+ onAdd: vi.fn(),
15
+ onRemove: vi.fn(),
16
+ onNone: vi.fn(),
17
+ ...overrides,
18
+ };
19
+ const user = userEvent.setup();
20
+ render(<BenefitsInputForm {...props} />);
21
+ return { user, props };
22
+ };
23
+
24
+ const button = (name: string) => screen.queryByRole("button", { name });
25
+ const field = (label: string) => screen.getByLabelText(label);
26
+
27
+ describe("BenefitsInputForm", () => {
28
+ describe("insurance on file", () => {
29
+ // Pins today's behavior
30
+ // Question: what do we think about this display?
31
+ it('plan with every field: shows a chip "BIN <bin> · PCN <pcn> · Group <group> · Member <member id>"', () => {
32
+ renderForm({ benefits: [plan] });
33
+ expect(screen.getByText("BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")).toBeInTheDocument();
34
+ });
35
+
36
+ it("plan without a PCN or group: leaves them out of the chip", () => {
37
+ renderForm({ benefits: [{ ...plan, pcn: null, groupId: null }] });
38
+ expect(screen.getByText("BIN 610014 · Member M123")).toBeInTheDocument();
39
+ });
40
+
41
+ it("several plans: shows a chip for each plan", () => {
42
+ renderForm({ benefits: [plan, { ...plan, id: "ben_2", bin: "004336", memberId: "M456" }] });
43
+ expect(screen.getByText("BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")).toBeInTheDocument();
44
+ expect(screen.getByText("BIN 004336 · PCN PCN1 · Group GRP1 · Member M456")).toBeInTheDocument();
45
+ });
46
+
47
+ it("clicking a plan's remove button: calls onRemove with that plan", async () => {
48
+ const { user, props } = renderForm({ benefits: [plan] });
49
+ await user.click(button("Remove BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")!);
50
+ expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(plan);
51
+ });
52
+ });
53
+
54
+ describe("none", () => {
55
+ it('insurance not recorded: shows "Not recorded" and the "Mark no insurance" button', () => {
56
+ renderForm({ benefits: null });
57
+ expect(screen.getByText("Not recorded")).toBeInTheDocument();
58
+ expect(button("Mark no insurance")).toHaveTextContent("Mark none");
59
+ });
60
+
61
+ it('clicking "Mark no insurance": calls onNone', async () => {
62
+ const { user, props } = renderForm({ benefits: null });
63
+ await user.click(button("Mark no insurance")!);
64
+ expect(props.onNone).toHaveBeenCalledOnce();
65
+ });
66
+
67
+ it('no insurance recorded: shows "No insurance" instead of "Not recorded" and the none button', () => {
68
+ renderForm({ benefits: [] });
69
+ expect(screen.getByText("No insurance")).toBeInTheDocument();
70
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
71
+ expect(button("Mark no insurance")).not.toBeInTheDocument();
72
+ });
73
+
74
+ it('plans on file: shows no "Not recorded" and no none button', () => {
75
+ renderForm({ benefits: [plan] });
76
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
77
+ expect(button("Mark no insurance")).not.toBeInTheDocument();
78
+ });
79
+ });
80
+
81
+ describe("adding a plan", () => {
82
+ it('clicking "Add insurance": opens the form with the cursor in BIN, in place of the add button', async () => {
83
+ const { user } = renderForm();
84
+ await user.click(button("Add insurance")!);
85
+ expect(field("BIN")).toHaveFocus();
86
+ expect(button("Add insurance")).not.toBeInTheDocument();
87
+ });
88
+
89
+ it('form open: hides "Not recorded" and the none button', async () => {
90
+ const { user } = renderForm();
91
+ await user.click(button("Add insurance")!);
92
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
93
+ expect(button("Mark no insurance")).not.toBeInTheDocument();
94
+ });
95
+
96
+ it('BIN or member ID empty, or only spaces: "Save insurance" is disabled', async () => {
97
+ const { user } = renderForm();
98
+ await user.click(button("Add insurance")!);
99
+ expect(button("Save insurance")).toBeDisabled();
100
+ await user.type(field("BIN"), "610014");
101
+ expect(button("Save insurance")).toBeDisabled();
102
+ await user.type(field("Member ID"), " ");
103
+ expect(button("Save insurance")).toBeDisabled();
104
+ });
105
+
106
+ it('BIN and member ID filled in, then "Save insurance": calls onAdd with them trimmed, without PCN or group', async () => {
107
+ const { user, props } = renderForm();
108
+ await user.click(button("Add insurance")!);
109
+ await user.type(field("BIN"), " 610014 ");
110
+ await user.type(field("Member ID"), " M123 ");
111
+ await user.click(button("Save insurance")!);
112
+ expect(props.onAdd).toHaveBeenCalledExactlyOnceWith({
113
+ bin: "610014",
114
+ memberId: "M123",
115
+ pcn: undefined,
116
+ groupId: undefined,
117
+ });
118
+ });
119
+
120
+ it("every field filled in: calls onAdd with the PCN and group too", async () => {
121
+ const { user, props } = renderForm();
122
+ await user.click(button("Add insurance")!);
123
+ await user.type(field("BIN"), "610014");
124
+ await user.type(field("PCN"), "PCN1");
125
+ await user.type(field("Group"), "GRP1");
126
+ await user.type(field("Member ID"), "M123");
127
+ await user.click(button("Save insurance")!);
128
+ expect(props.onAdd).toHaveBeenCalledExactlyOnceWith({
129
+ bin: "610014",
130
+ memberId: "M123",
131
+ pcn: "PCN1",
132
+ groupId: "GRP1",
133
+ });
134
+ });
135
+
136
+ it("Enter in any field, with BIN and member ID filled in: calls onAdd", async () => {
137
+ const { user, props } = renderForm();
138
+ await user.click(button("Add insurance")!);
139
+ await user.type(field("BIN"), "610014");
140
+ await user.type(field("Member ID"), "M123");
141
+ await user.type(field("PCN"), "{Enter}");
142
+ expect(props.onAdd).toHaveBeenCalledOnce();
143
+ });
144
+
145
+ it("Enter with member ID empty: doesn't call onAdd, and the form stays open", async () => {
146
+ const { user, props } = renderForm();
147
+ await user.click(button("Add insurance")!);
148
+ await user.type(field("BIN"), "610014{Enter}");
149
+ expect(props.onAdd).not.toHaveBeenCalled();
150
+ expect(field("BIN")).toHaveValue("610014");
151
+ });
152
+
153
+ it("Cancel: closes the form without calling onAdd, and the form renders with fields cleared the next time it is opened", async () => {
154
+ const { user, props } = renderForm();
155
+ await user.click(button("Add insurance")!);
156
+ await user.type(field("BIN"), "610014");
157
+ await user.click(button("Cancel")!);
158
+ expect(props.onAdd).not.toHaveBeenCalled();
159
+ expect(screen.queryByLabelText("BIN")).not.toBeInTheDocument();
160
+ await user.click(button("Add insurance")!);
161
+ expect(field("BIN")).toHaveValue("");
162
+ });
163
+ });
164
+ });
@@ -1,12 +1,13 @@
1
1
  /** The patient's insurance on file. */
2
2
  import { useState } from "react";
3
- import { useComponents } from "../../primitives/index.ts";
4
- import { noAutofill } from "./fields.tsx";
3
+ import { useComponents } from "../../../primitives/index.ts";
4
+ import { noAutofill } from "../fields.tsx";
5
+ import { TrackedField } from "../../../analytics/fieldInteraction.tsx";
5
6
 
6
7
  export type BenefitInput = { id?: string; bin?: string; pcn?: string; groupId?: string; memberId?: string };
7
8
 
8
9
  /** Insurance on file: chips, "Add insurance" (BIN + member id required, PCN / group optional), "No insurance". */
9
- export function BenefitsSection({
10
+ export function BenefitsInputForm({
10
11
  benefits,
11
12
  saving,
12
13
  onAdd,
@@ -96,19 +97,26 @@ export function BenefitsSection({
96
97
  }}
97
98
  >
98
99
  <Stack gap="2">
99
- <Grid min="72px" gap="2">
100
- <Input
101
- label="BIN"
102
- value={bin}
103
- onChange={(e) => setBin(e.target.value)}
104
- inputMode="numeric"
105
- autoFocus
106
- {...noAutofill}
107
- />
108
- <Input label="PCN" value={pcn} onChange={(e) => setPcn(e.target.value)} {...noAutofill} />
109
- <Input label="Group" value={groupId} onChange={(e) => setGroupId(e.target.value)} {...noAutofill} />
110
- <Input label="Member ID" value={memberId} onChange={(e) => setMemberId(e.target.value)} {...noAutofill} />
111
- </Grid>
100
+ <TrackedField formName="update_patient_form" fieldName="insurance" isOptional>
101
+ <Grid min="72px" gap="2">
102
+ <Input
103
+ label="BIN"
104
+ value={bin}
105
+ onChange={(e) => setBin(e.target.value)}
106
+ inputMode="numeric"
107
+ autoFocus
108
+ {...noAutofill}
109
+ />
110
+ <Input label="PCN" value={pcn} onChange={(e) => setPcn(e.target.value)} {...noAutofill} />
111
+ <Input label="Group" value={groupId} onChange={(e) => setGroupId(e.target.value)} {...noAutofill} />
112
+ <Input
113
+ label="Member ID"
114
+ value={memberId}
115
+ onChange={(e) => setMemberId(e.target.value)}
116
+ {...noAutofill}
117
+ />
118
+ </Grid>
119
+ </TrackedField>
112
120
  <Row justify="end" gap="2">
113
121
  <Button variant="ghost" onClick={reset}>
114
122
  Cancel
@@ -0,0 +1,247 @@
1
+ import { render, screen, waitFor } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import type { Change, ChangeOption } from "@photonhealth/client";
5
+ import { ClinicalInputForm } from "./ClinicalInputForm.tsx";
6
+
7
+ type Allergy = { id: string; name: string };
8
+ type Props = Parameters<typeof ClinicalInputForm<Allergy>>[0];
9
+
10
+ const penicillin = { id: "alg_1", name: "Penicillin" };
11
+
12
+ const option = (displayName: string): ChangeOption =>
13
+ ({ displayName, reason: null, path: "clinical.allergies.add.0.id", value: displayName, id: null }) as ChangeOption;
14
+
15
+ /** A server change about the allergies list. */
16
+ const allergyChange = (overrides: Partial<Change>): Change => ({
17
+ key: "clinical.allergies.add.0",
18
+ label: "Allergy",
19
+ status: "AMBIGUOUS",
20
+ severity: "BLOCKING",
21
+ reason: null,
22
+ category: null,
23
+ operation: "ADDED",
24
+ options: [],
25
+ after: null,
26
+ inputText: null,
27
+ resolvedId: null,
28
+ ...overrides,
29
+ });
30
+
31
+ /**
32
+ * The allergies list, as PatientSummary renders it. Like the card, `onAdd` and `onChoose` start a save right
33
+ * away (`saving: true`). `update` re-renders with new props, the way the card does once the server answers.
34
+ */
35
+ const renderForm = (overrides: Partial<Props> = {}) => {
36
+ let props: Props = {
37
+ label: "Allergies",
38
+ fieldName: "allergies",
39
+ items: [],
40
+ tone: "warning",
41
+ addLabel: "Add allergy",
42
+ noneLabel: "No known allergies",
43
+ noneAction: "Mark NKDA",
44
+ confirmedNone: false,
45
+ unknownLabel: "Unknown allergy",
46
+ saving: false,
47
+ onAdd: vi.fn(() => update({ saving: true })),
48
+ onRemove: vi.fn(),
49
+ onNone: vi.fn(),
50
+ choices: [],
51
+ problems: [],
52
+ onChoose: vi.fn(() => update({ saving: true })),
53
+ ...overrides,
54
+ };
55
+ const user = userEvent.setup();
56
+ const { rerender } = render(<ClinicalInputForm {...props} />);
57
+ const update = (next: Partial<Props>) => {
58
+ props = { ...props, ...next };
59
+ rerender(<ClinicalInputForm {...props} />);
60
+ };
61
+ return { user, props, update };
62
+ };
63
+
64
+ const addField = () => screen.queryByRole("textbox", { name: "Add allergy" });
65
+ const addButton = () => screen.queryByRole("button", { name: "Add allergy" });
66
+
67
+ describe("ClinicalInputForm", () => {
68
+ describe("entries on file", () => {
69
+ it("entries on file: shows a chip for each entry", () => {
70
+ renderForm({ items: [penicillin, { id: "alg_2", name: "Latex" }] });
71
+ expect(screen.getByText("Penicillin")).toBeInTheDocument();
72
+ expect(screen.getByText("Latex")).toBeInTheDocument();
73
+ });
74
+
75
+ it("entry without a name: shows the unknown label on its chip", () => {
76
+ renderForm({ items: [{ id: "alg_1", name: "" }] });
77
+ expect(screen.getByText("Unknown allergy")).toBeInTheDocument();
78
+ });
79
+
80
+ it("clicking an entry's remove button: calls onRemove with that entry", async () => {
81
+ const { user, props } = renderForm({ items: [penicillin] });
82
+ await user.click(screen.getByRole("button", { name: "Remove Penicillin" }));
83
+ expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(penicillin);
84
+ });
85
+ });
86
+
87
+ // User should explicitly confirm none vs. our system inferring lack of info as none
88
+ describe("none", () => {
89
+ it('nothing on file and none not recorded: shows "Not recorded" and the none button', () => {
90
+ renderForm();
91
+ expect(screen.getByText("Not recorded")).toBeInTheDocument();
92
+ expect(screen.getByRole("button", { name: "Mark NKDA" })).toBeInTheDocument();
93
+ });
94
+
95
+ it("clicking the none button: calls onNone", async () => {
96
+ const { user, props } = renderForm();
97
+ await user.click(screen.getByRole("button", { name: "Mark NKDA" }));
98
+ expect(props.onNone).toHaveBeenCalledOnce();
99
+ });
100
+
101
+ it('none confirmed: shows noneLabel instead of "Not recorded" and the none button', () => {
102
+ renderForm({ confirmedNone: true });
103
+ expect(screen.getByText("No known allergies")).toBeInTheDocument();
104
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
105
+ expect(screen.queryByRole("button", { name: "Mark NKDA" })).not.toBeInTheDocument();
106
+ });
107
+
108
+ // Pins today's behavior
109
+ // Question: I agree with this behavior, but is this even possible in the API?
110
+ it("none confirmed, but an entry on file: shows the entry, not the none label", () => {
111
+ renderForm({ confirmedNone: true, items: [penicillin] });
112
+ expect(screen.getByText("Penicillin")).toBeInTheDocument();
113
+ expect(screen.queryByText("No known allergies")).not.toBeInTheDocument();
114
+ });
115
+
116
+ it(`entries on file: doesn't show "Not recorded" or none button`, () => {
117
+ renderForm({ items: [penicillin] });
118
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
119
+ expect(screen.queryByRole("button", { name: "Mark NKDA" })).not.toBeInTheDocument();
120
+ });
121
+
122
+ it('none button named "Mark none": names the list in its accessible name', () => {
123
+ renderForm({ label: "Medications", noneLabel: "No active meds", noneAction: "Mark none" });
124
+ expect(screen.getByRole("button", { name: "Mark no medications" })).toHaveTextContent("Mark none");
125
+ });
126
+ });
127
+
128
+ describe("adding an entry", () => {
129
+ it("clicking the add button: opens the add field with the cursor in it, in place of the add button", async () => {
130
+ const { user } = renderForm();
131
+ await user.click(addButton()!);
132
+ expect(addField()).toHaveFocus();
133
+ expect(addButton()).not.toBeInTheDocument();
134
+ });
135
+
136
+ it('add field open: hides "Not recorded" and the none button', async () => {
137
+ const { user } = renderForm();
138
+ await user.click(addButton()!);
139
+ expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
140
+ expect(screen.queryByRole("button", { name: "Mark NKDA" })).not.toBeInTheDocument();
141
+ });
142
+
143
+ it("text typed with spaces around it, then Enter: calls onAdd with the text trimmed", async () => {
144
+ const { user, props } = renderForm();
145
+ await user.click(addButton()!);
146
+ await user.keyboard(" Penicillin {Enter}");
147
+ expect(props.onAdd).toHaveBeenCalledExactlyOnceWith("Penicillin");
148
+ });
149
+
150
+ it("text typed, then leaving the field: calls onAdd with the text", async () => {
151
+ const { user, props } = renderForm();
152
+ await user.click(addButton()!);
153
+ await user.keyboard("Penicillin");
154
+ await user.tab();
155
+ expect(props.onAdd).toHaveBeenCalledExactlyOnceWith("Penicillin");
156
+ });
157
+
158
+ // Pins today's behavior
159
+ // TODO: Rename similar props to onTryAdd or smth similar, name doesn't
160
+ // reflect that onAdd may return candidates instead of adding
161
+ it("3 or more characters typed, then a pause: calls onAdd without Enter", async () => {
162
+ const { user, props } = renderForm();
163
+ await user.click(addButton()!);
164
+ await user.keyboard("Pen");
165
+ await waitFor(() => expect(props.onAdd).toHaveBeenCalledExactlyOnceWith("Pen"));
166
+ });
167
+
168
+ it("fewer than 3 characters typed, then a pause: doesn't call onAdd", async () => {
169
+ const { user, props } = renderForm();
170
+ await user.click(addButton()!);
171
+ await user.keyboard("Pe");
172
+ await new Promise((done) => setTimeout(done, 500));
173
+ expect(props.onAdd).not.toHaveBeenCalled();
174
+ });
175
+
176
+ it("text added after a pause, then Enter with the same text: doesn't call onAdd again", async () => {
177
+ const { user, props } = renderForm();
178
+ await user.click(addButton()!);
179
+ await user.keyboard("Penicillin");
180
+ await waitFor(() => expect(props.onAdd).toHaveBeenCalledOnce());
181
+ await user.keyboard("{Enter}");
182
+ expect(props.onAdd).toHaveBeenCalledOnce();
183
+ });
184
+
185
+ it("Enter in the empty add field: closes the field without calling onAdd", async () => {
186
+ const { user, props } = renderForm();
187
+ await user.click(addButton()!);
188
+ await user.keyboard("{Enter}");
189
+ expect(addField()).not.toBeInTheDocument();
190
+ expect(props.onAdd).not.toHaveBeenCalled();
191
+ });
192
+
193
+ // Pins today's behavior
194
+ // TODO: Form stronger opinion around keyboard interactions
195
+ it("Escape: closes the add field without calling onAdd", async () => {
196
+ const { user, props } = renderForm();
197
+ await user.click(addButton()!);
198
+ await user.keyboard("Pe{Escape}");
199
+ expect(addField()).not.toBeInTheDocument();
200
+ expect(props.onAdd).not.toHaveBeenCalled();
201
+ });
202
+
203
+ it("entry sent, and the server adds it to the list: closes the add field", async () => {
204
+ const { user, update } = renderForm();
205
+ await user.click(addButton()!);
206
+ await user.keyboard("Penicillin{Enter}");
207
+ update({ saving: false, items: [penicillin] });
208
+ expect(addField()).not.toBeInTheDocument();
209
+ expect(screen.getByText("Penicillin")).toBeInTheDocument();
210
+ });
211
+ });
212
+
213
+ describe("server choices and problems", () => {
214
+ it("entry sent, and the server offers choices: keeps the add field open and shows the choices under it", async () => {
215
+ const { user, update } = renderForm();
216
+ await user.click(addButton()!);
217
+ await user.keyboard("Penicillin{Enter}");
218
+ update({
219
+ saving: false,
220
+ choices: [allergyChange({ options: [option("Penicillin G"), option("Penicillin V")] })],
221
+ });
222
+ expect(addField()).toBeInTheDocument();
223
+ expect(screen.getByText("Penicillin G")).toBeInTheDocument();
224
+ expect(screen.getByText("Penicillin V")).toBeInTheDocument();
225
+ });
226
+
227
+ it("clicking a choice: calls onChoose with that option", async () => {
228
+ const { user, props } = renderForm({
229
+ choices: [allergyChange({ options: [option("Penicillin G"), option("Penicillin V")] })],
230
+ });
231
+ await user.click(screen.getByText("Penicillin V"));
232
+ expect(props.onChoose).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ displayName: "Penicillin V" }));
233
+ });
234
+
235
+ it("entry sent, and the server rejects it: keeps the add field open with the text, and shows the server's reason", async () => {
236
+ const { user, update } = renderForm();
237
+ await user.click(addButton()!);
238
+ await user.keyboard("Zqx{Enter}");
239
+ update({
240
+ saving: false,
241
+ problems: [allergyChange({ status: "REJECTED", reason: 'Nothing matches "Zqx"' })],
242
+ });
243
+ expect(addField()).toHaveValue("Zqx");
244
+ expect(screen.getByText(/Nothing matches "Zqx"/)).toBeInTheDocument();
245
+ });
246
+ });
247
+ });
@@ -1,11 +1,12 @@
1
1
  /** The patient's clinical lists — allergies, medications, diagnoses — and which server changes belong to them. */
2
2
  import { type ChangeOption, type ClassifiedChanges } from "@photonhealth/client";
3
3
  import { useRef, useState } from "react";
4
- import { useComponents } from "../../primitives/index.ts";
5
- import { useHeldActivity } from "../activity.ts";
6
- import { ChangeList } from "../ChangeList.tsx";
7
- import { afterPress, searchKeys, useTypeAhead, type SearchHandle } from "../search.tsx";
8
- import { noAutofill } from "./fields.tsx";
4
+ import { useComponents } from "../../../primitives/index.ts";
5
+ import { useHeldActivity } from "../../activity.ts";
6
+ import { ChangeList } from "../../ChangeList.tsx";
7
+ import { afterPress, searchKeys, useTypeAhead, type SearchHandle } from "../../search.tsx";
8
+ import { noAutofill } from "../fields.tsx";
9
+ import { TrackedField } from "../../../analytics/fieldInteraction.tsx";
9
10
 
10
11
  /** Which clinical list a server change belongs to (keys look like "clinical.allergies.add.0" / "allergies.0"). */
11
12
  const CLINICAL_SECTIONS = ["allergies", "medications", "diagnoses"] as const;
@@ -19,21 +20,24 @@ export const withoutInline = (changes: ClassifiedChanges): ClassifiedChanges =>
19
20
  blocking: changes.blocking.filter((c) => !sectionOf(c.key)),
20
21
  });
21
22
 
23
+ export type DiagnosisInput = { icd10Code: string } | { name: string };
24
+
22
25
  /** An ICD-10 code ("J02.0") goes as a code; anything else as free text for the server to resolve. */
23
- export const diagnosisRef = (text: string) =>
26
+ export const diagnosisRef = (text: string): DiagnosisInput =>
24
27
  /^[A-TV-Z]\d{2}(\.[0-9A-Z]{1,4})?$/i.test(text) ? { icd10Code: text.toUpperCase() } : { name: text };
25
28
 
26
29
  /**
27
30
  * A clinical list (allergies, medications, diagnoses): chips for what's on file, plus "Add …" and "No …"
28
- * (records none — `confirmedNone` is the record's `[]`; network-api can't read it back yet, docs/api-gaps.md).
31
+ * (records none — `confirmedNone` is the record's `[]`; network-api can't read it back yet).
29
32
  *
30
33
  * "Add …" is a search field (search.tsx) — type-ahead, its spinner, its results (the server's choices, e.g.
31
34
  * which penicillin) and keys. Each search is an add, by design: what's typed, once it matches one entry, is that
32
35
  * entry — added then, as is a single row or the one match the server is sure of (core takes it). The field closes as soon as an entry lands, or once what's committed (Enter,
33
36
  * leaving it, a choice) is answered. Escape closes it.
34
37
  */
35
- export function ClinicalList<T extends { id: string; name: string }>({
38
+ export function ClinicalInputForm<T extends { id: string; name: string }>({
36
39
  label,
40
+ fieldName,
37
41
  items,
38
42
  tone,
39
43
  addLabel,
@@ -41,7 +45,6 @@ export function ClinicalList<T extends { id: string; name: string }>({
41
45
  noneAction,
42
46
  confirmedNone,
43
47
  unknownLabel,
44
- pickedNames,
45
48
  saving,
46
49
  onAdd,
47
50
  onRemove,
@@ -51,23 +54,23 @@ export function ClinicalList<T extends { id: string; name: string }>({
51
54
  onChoose,
52
55
  }: {
53
56
  label: string;
57
+ fieldName: "allergies" | "medications" | "diagnoses";
54
58
  items: T[];
55
59
  tone: "warning" | "neutral";
56
60
  addLabel: string;
57
- /** Offer "none" (e.g. No known allergies). Omit for lists where "none" isn't worth recording. */
58
- noneLabel?: string;
61
+ /** Shown once "none" is recorded (e.g. No known allergies). */
62
+ noneLabel: string;
59
63
  /** The button that records "none" (e.g. "Mark NKDA") — an action, so it can't be read as a status. */
60
- noneAction?: string;
64
+ noneAction: string;
61
65
  /** "None" was recorded this session. */
62
- confirmedNone?: boolean;
63
- /** Shown when the server returns no real name (today allergies come back with name = id). */
66
+ confirmedNone: boolean;
67
+ /** Shown for an entry the server returns without a name. */
64
68
  unknownLabel: string;
65
- /** Names the prescriber picked this session, by id — shown when the server returns only the id. */
66
- pickedNames: Readonly<Record<string, string>>;
67
69
  saving: boolean;
68
70
  onAdd: (name: string) => void;
69
71
  onRemove: (item: T) => void;
70
- onNone?: () => void;
72
+ /** Records "none" for this list. */
73
+ onNone: () => void;
71
74
  /** The server's choices for what was just entered (e.g. which penicillin) — shown right under the field. */
72
75
  choices: ClassifiedChanges["needsChoice"];
73
76
  /** What the server rejected for this list (e.g. a name nothing matches) — shown in the same place. */
@@ -102,7 +105,7 @@ export function ClinicalList<T extends { id: string; name: string }>({
102
105
  const spinning = useHeldActivity(adding && before !== null && saving ? "add" : null) === "add";
103
106
  const results = useRef<SearchHandle | null>(null);
104
107
  const field = useRef<HTMLDivElement>(null);
105
- const none = Boolean(confirmedNone) && items.length === 0;
108
+ const none = confirmedNone && items.length === 0;
106
109
 
107
110
  /** Add what's typed — unless it was just sent. */
108
111
  const send = (name: string) => {
@@ -142,25 +145,25 @@ export function ClinicalList<T extends { id: string; name: string }>({
142
145
  <Button variant="ghost" aria-label={addLabel} title={addLabel} onClick={() => setAdding(true)} icon="add" />
143
146
  )}
144
147
  {items.map((item) => {
145
- const name = item.name && item.name !== item.id ? item.name : (pickedNames[item.id] ?? unknownLabel);
148
+ const name = item.name || unknownLabel;
146
149
  return (
147
150
  <Badge key={item.id} tone={tone} onRemove={() => onRemove(item)} removeLabel={`Remove ${name}`}>
148
151
  {name}
149
152
  </Badge>
150
153
  );
151
154
  })}
152
- {none && noneLabel && <Badge tone="success">{noneLabel}</Badge>}
153
- {/* network-api can't tell "never asked" from "none" (docs/api-gaps.md): say which we know. */}
154
- {noneLabel && !none && items.length === 0 && !adding && <Text tone="tertiary">Not recorded</Text>}
155
+ {none && <Badge tone="success">{noneLabel}</Badge>}
156
+ {/* network-api can't tell "never asked" from "none": say which we know. */}
157
+ {!none && items.length === 0 && !adding && <Text tone="tertiary">Not recorded</Text>}
155
158
  </Row>
156
- {noneLabel && onNone && !adding && items.length === 0 && !none && (
159
+ {!adding && items.length === 0 && !none && (
157
160
  <Button
158
161
  variant="ghost"
159
162
  onClick={onNone} // never disabled by another save: calls are queued
160
163
  // "Mark none" on several lists: each named for its own.
161
164
  aria-label={noneAction === "Mark none" ? `Mark no ${label.toLowerCase()}` : undefined}
162
165
  >
163
- {noneAction ?? noneLabel}
166
+ {noneAction}
164
167
  </Button>
165
168
  )}
166
169
  </Row>
@@ -168,30 +171,32 @@ export function ClinicalList<T extends { id: string; name: string }>({
168
171
  <div ref={field}>
169
172
  <Stack gap="2">
170
173
  {adding && (
171
- <Input
172
- label={addLabel}
173
- value={value}
174
- autoFocus
175
- loading={spinning}
176
- {...noAutofill}
177
- onChange={(e) => {
178
- setValue(e.target.value);
179
- typeAhead.typed("add", e.target.value);
180
- }}
181
- onBlur={(e) => {
182
- // Into its results isn't leaving; anywhere else sends what's typed (or closes an empty field).
183
- if (field.current?.contains(e.relatedTarget) || results.current?.pointing?.()) return;
184
- afterPress(add); // e.g. pressing "Mark none" below: it mustn't move before the click lands
185
- }}
186
- onKeyDown={(e) => {
187
- if (searchKeys(e, results.current, value.trim() === sent && !saving)) return;
188
- if (e.key === "Enter") {
189
- e.preventDefault();
190
- add();
191
- }
192
- if (e.key === "Escape") close();
193
- }}
194
- />
174
+ <TrackedField formName="update_patient_form" fieldName={fieldName} isOptional>
175
+ <Input
176
+ label={addLabel}
177
+ value={value}
178
+ autoFocus
179
+ loading={spinning}
180
+ {...noAutofill}
181
+ onChange={(e) => {
182
+ setValue(e.target.value);
183
+ typeAhead.typed("add", e.target.value);
184
+ }}
185
+ onBlur={(e) => {
186
+ // Into its results isn't leaving; anywhere else sends what's typed (or closes an empty field).
187
+ if (field.current?.contains(e.relatedTarget) || results.current?.pointing?.()) return;
188
+ afterPress(add); // e.g. pressing "Mark none" below: it mustn't move before the click lands
189
+ }}
190
+ onKeyDown={(e) => {
191
+ if (searchKeys(e, results.current, value.trim() === sent && !saving)) return;
192
+ if (e.key === "Enter") {
193
+ e.preventDefault();
194
+ add();
195
+ }
196
+ if (e.key === "Escape") close();
197
+ }}
198
+ />
199
+ </TrackedField>
195
200
  )}
196
201
  {(choices.length > 0 || problems.length > 0) && (
197
202
  <ChangeList