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

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 (185) hide show
  1. package/README.md +35 -8
  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 +16 -0
  6. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  7. package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
  8. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  9. package/dist/analytics/fieldInteraction.d.ts +18 -0
  10. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  11. package/dist/analytics/fieldInteraction.js +102 -0
  12. package/dist/analytics/fieldInteraction.js.map +1 -0
  13. package/dist/analytics/tracker.d.ts +17 -0
  14. package/dist/analytics/tracker.d.ts.map +1 -0
  15. package/dist/analytics/tracker.js +36 -0
  16. package/dist/analytics/tracker.js.map +1 -0
  17. package/dist/analytics/viewed.d.ts +11 -0
  18. package/dist/analytics/viewed.d.ts.map +1 -0
  19. package/dist/analytics/viewed.js +16 -0
  20. package/dist/analytics/viewed.js.map +1 -0
  21. package/dist/components/PhotonOrder.d.ts.map +1 -1
  22. package/dist/components/PhotonOrder.js +20 -16
  23. package/dist/components/PhotonOrder.js.map +1 -1
  24. package/dist/components/PhotonPatient.d.ts.map +1 -1
  25. package/dist/components/PhotonPatient.js +4 -2
  26. package/dist/components/PhotonPatient.js.map +1 -1
  27. package/dist/components/PhotonPrescription.d.ts +1 -12
  28. package/dist/components/PhotonPrescription.d.ts.map +1 -1
  29. package/dist/components/PhotonPrescription.js +7 -360
  30. package/dist/components/PhotonPrescription.js.map +1 -1
  31. package/dist/components/format.d.ts +2 -2
  32. package/dist/components/format.js +2 -2
  33. package/dist/components/index.d.ts +1 -1
  34. package/dist/components/index.d.ts.map +1 -1
  35. package/dist/components/index.js +1 -1
  36. package/dist/components/index.js.map +1 -1
  37. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  38. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  39. package/dist/components/order/DraftOrderPrompt.js +26 -0
  40. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  41. package/dist/components/patient/Benefits.d.ts.map +1 -1
  42. package/dist/components/patient/Benefits.js +2 -1
  43. package/dist/components/patient/Benefits.js.map +1 -1
  44. package/dist/components/patient/Clinical.d.ts +3 -2
  45. package/dist/components/patient/Clinical.d.ts.map +1 -1
  46. package/dist/components/patient/Clinical.js +21 -20
  47. package/dist/components/patient/Clinical.js.map +1 -1
  48. package/dist/components/patient/IntakeForm.d.ts.map +1 -1
  49. package/dist/components/patient/IntakeForm.js +52 -43
  50. package/dist/components/patient/IntakeForm.js.map +1 -1
  51. package/dist/components/patient/Summary.d.ts +1 -1
  52. package/dist/components/patient/Summary.d.ts.map +1 -1
  53. package/dist/components/patient/Summary.js +13 -3
  54. package/dist/components/patient/Summary.js.map +1 -1
  55. package/dist/components/patient/fields.d.ts +1 -2
  56. package/dist/components/patient/fields.d.ts.map +1 -1
  57. package/dist/components/patient/fields.js +2 -1
  58. package/dist/components/patient/fields.js.map +1 -1
  59. package/dist/components/patient/query.d.ts +14 -0
  60. package/dist/components/patient/query.d.ts.map +1 -1
  61. package/dist/components/patient/query.js +5 -0
  62. package/dist/components/patient/query.js.map +1 -1
  63. package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
  64. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  65. package/dist/components/prescription/PrescriptionCard.js +179 -0
  66. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  67. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  68. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  69. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  70. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  71. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  72. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  73. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  74. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  75. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  76. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  77. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  78. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  79. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  80. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  81. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  82. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  83. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  84. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  85. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  86. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  87. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  88. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  89. package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
  90. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  91. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  92. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  93. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  94. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  95. package/dist/components/schemaErrors.d.ts +12 -0
  96. package/dist/components/schemaErrors.d.ts.map +1 -0
  97. package/dist/components/schemaErrors.js +24 -0
  98. package/dist/components/schemaErrors.js.map +1 -0
  99. package/dist/index.d.ts +2 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +1 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/meta/version.d.ts +5 -0
  104. package/dist/meta/version.d.ts.map +1 -0
  105. package/dist/meta/version.js +5 -0
  106. package/dist/meta/version.js.map +1 -0
  107. package/dist/primitives/PhotonProvider.d.ts +3 -1
  108. package/dist/primitives/PhotonProvider.d.ts.map +1 -1
  109. package/dist/primitives/PhotonProvider.js +23 -11
  110. package/dist/primitives/PhotonProvider.js.map +1 -1
  111. package/dist/primitives/defaults.d.ts.map +1 -1
  112. package/dist/primitives/defaults.js +6 -3
  113. package/dist/primitives/defaults.js.map +1 -1
  114. package/dist/primitives/photonContext.d.ts +3 -0
  115. package/dist/primitives/photonContext.d.ts.map +1 -0
  116. package/dist/primitives/photonContext.js +3 -0
  117. package/dist/primitives/photonContext.js.map +1 -0
  118. package/dist/primitives/types.d.ts +15 -3
  119. package/dist/primitives/types.d.ts.map +1 -1
  120. package/dist/primitives/types.js.map +1 -1
  121. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  122. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  123. package/dist/primitives/useProvidedPhoton.js +8 -0
  124. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  125. package/dist/styles.css +45 -3
  126. package/dist/test-utils/contract.d.ts.map +1 -1
  127. package/dist/test-utils/contract.js +23 -2
  128. package/dist/test-utils/contract.js.map +1 -1
  129. package/package.json +5 -3
  130. package/src/adapters/tailwind.tsx +52 -24
  131. package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
  132. package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
  133. package/src/analytics/fieldInteraction.test.tsx +184 -0
  134. package/src/analytics/fieldInteraction.tsx +148 -0
  135. package/src/analytics/tracker.test.ts +52 -0
  136. package/src/analytics/tracker.ts +42 -0
  137. package/src/analytics/viewed.ts +27 -0
  138. package/src/components/PhotonOrder.test.tsx +256 -0
  139. package/src/components/PhotonOrder.tsx +45 -30
  140. package/src/components/PhotonPatient.tsx +11 -7
  141. package/src/components/PhotonPrescription.test.tsx +116 -0
  142. package/src/components/PhotonPrescription.tsx +10 -570
  143. package/src/components/format.ts +2 -2
  144. package/src/components/index.ts +1 -1
  145. package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
  146. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  147. package/src/components/patient/Benefits.tsx +21 -13
  148. package/src/components/patient/Clinical.tsx +31 -26
  149. package/src/components/patient/IntakeForm.test.tsx +89 -0
  150. package/src/components/patient/IntakeForm.tsx +168 -136
  151. package/src/components/patient/Summary.test.tsx +106 -0
  152. package/src/components/patient/Summary.tsx +54 -34
  153. package/src/components/patient/fields.tsx +52 -38
  154. package/src/components/patient/query.ts +6 -0
  155. package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
  156. package/src/components/prescription/PrescriptionCard.tsx +347 -0
  157. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
  158. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  159. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
  160. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  161. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
  162. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  163. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  164. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  165. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
  166. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  167. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  168. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
  169. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  170. package/src/components/schemaErrors.test.ts +49 -0
  171. package/src/components/schemaErrors.ts +33 -0
  172. package/src/index.ts +2 -0
  173. package/src/meta/version.test.ts +10 -0
  174. package/src/meta/version.ts +4 -0
  175. package/src/primitives/PhotonProvider.tsx +30 -15
  176. package/src/primitives/defaults.tsx +44 -21
  177. package/src/primitives/photonContext.ts +4 -0
  178. package/src/primitives/types.ts +15 -3
  179. package/src/primitives/useProvidedPhoton.ts +21 -0
  180. package/src/styles.css +45 -3
  181. package/src/test-utils/contract.tsx +45 -2
  182. package/dist/components/TreatmentPicker.d.ts +0 -45
  183. package/dist/components/TreatmentPicker.d.ts.map +0 -1
  184. package/dist/components/TreatmentPicker.js.map +0 -1
  185. package/src/components/TreatmentPicker.tsx +0 -350
@@ -10,7 +10,8 @@ import { FEW, searchKeys, SearchResults, useTypeAhead, type SearchHandle } from
10
10
 
11
11
  import { noAutofill, SEX_OPTIONS } from "./fields.tsx";
12
12
  import { focusProps, searchProps } from "../flow.ts";
13
- import { isSearchable, parseQuery, searchBoth } from "./query.ts";
13
+ import { isSearchable, parseQuery, searchBoth, toSearchInput } from "./query.ts";
14
+ import { TrackedField, useFieldInteractions } from "../../analytics/fieldInteraction.tsx";
14
15
 
15
16
  const IDENTITY_KEYS = ["demographic.name.first", "demographic.name.last", "demographic.dateOfBirth", "demographic.sex"];
16
17
 
@@ -30,17 +31,18 @@ export function PatientIntakeForm({
30
31
  const formId = useId();
31
32
  // Starts from what's already been sent — e.g. a host's details the server hasn't matched yet — to edit on.
32
33
  const known = patient.known;
33
- const [first, setFirst] = useState(known.name?.first ?? "");
34
- const [last, setLast] = useState(known.name?.last ?? "");
35
- const [dob, setDob] = useState(known.dateOfBirth ?? "");
36
- const [sex, setSex] = useState<Sex | null>(known.sex ?? null);
37
- const [email, setEmail] = useState(known.email ?? "");
38
- const [phone, setPhone] = useState(known.phone ? formatPhone(known.phone) : "");
39
- const [street1, setStreet1] = useState(known.address?.street1 ?? "");
40
- const [street2, setStreet2] = useState(known.address?.street2 ?? "");
41
- const [city, setCity] = useState(known.address?.city ?? "");
42
- const [state, setState] = useState(known.address?.state ?? "");
43
- const [postalCode, setPostalCode] = useState(known.address?.postalCode ?? "");
34
+ const [first, setFirst] = useState(known.demographic?.name?.first ?? "");
35
+ const [last, setLast] = useState(known.demographic?.name?.last ?? "");
36
+ const [dob, setDob] = useState(known.demographic?.dateOfBirth ?? "");
37
+ const [sex, setSex] = useState<Sex | null>(known.demographic?.sex ?? null);
38
+ const sexPicked = useFieldInteractions("new_patient_form")("sex", { isOptional: false, hasValue: Boolean(sex) });
39
+ const [email, setEmail] = useState(known.contact?.email ?? "");
40
+ const [phone, setPhone] = useState(known.contact?.phone ? formatPhone(known.contact.phone) : "");
41
+ const [street1, setStreet1] = useState(known.contact?.address?.street1 ?? "");
42
+ const [street2, setStreet2] = useState(known.contact?.address?.street2 ?? "");
43
+ const [city, setCity] = useState(known.contact?.address?.city ?? "");
44
+ const [state, setState] = useState(known.contact?.address?.state ?? "");
45
+ const [postalCode, setPostalCode] = useState(known.contact?.address?.postalCode ?? "");
44
46
  /**
45
47
  * Finding someone and adding them are two different jobs, so the card does one at a time. Searching is
46
48
  * one field and never writes (`search` goes without `sex`, which is what network-api needs to create).
@@ -48,7 +50,9 @@ export function PatientIntakeForm({
48
50
  * they typed. Details handed in that the server hasn't matched start there, as they always did.
49
51
  */
50
52
  const [mode, setMode] = useState<"search" | "create">(() =>
51
- known.name?.first || known.name?.last || known.dateOfBirth ? "create" : "search",
53
+ known.demographic?.name?.first || known.demographic?.name?.last || known.demographic?.dateOfBirth
54
+ ? "create"
55
+ : "search",
52
56
  );
53
57
  const [query, setQuery] = useState("");
54
58
  const creating = mode === "create";
@@ -75,14 +79,16 @@ export function PatientIntakeForm({
75
79
  });
76
80
 
77
81
  /** Everything known on the form. Phone / email ride along once they're valid; the browser shows why otherwise. */
78
- const demographic = (overrides: { sex?: Sex | null } = {}) => {
82
+ const form = (overrides: { sex?: Sex | null } = {}) => {
79
83
  const chosenSex = overrides.sex !== undefined ? overrides.sex : sex;
80
84
  const validPhone = new RegExp(`^(?:${PHONE_PATTERN})$`).test(phone.trim());
81
85
  const validEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim());
82
- return {
86
+ const demographic = {
83
87
  name: { first, last },
84
88
  dateOfBirth: dob,
85
89
  ...(chosenSex ? { sex: chosenSex } : {}),
90
+ };
91
+ const contact = {
86
92
  ...(validPhone ? { phone: toE164(phone) } : {}),
87
93
  ...(validEmail ? { email: email.trim() } : {}),
88
94
  ...(addressComplete
@@ -98,6 +104,7 @@ export function PatientIntakeForm({
98
104
  }
99
105
  : {}),
100
106
  };
107
+ return { demographic, contact };
101
108
  };
102
109
  // What the list of matches answers: the form as it was last sent — and whether typing sent it (a search), not
103
110
  // leaving a field.
@@ -112,8 +119,8 @@ export function PatientIntakeForm({
112
119
  * it only lists who it might be). The object adds it to what it sent before; the same query isn't sent twice.
113
120
  */
114
121
  const send = (from: Field, kind: "sync" | "search" = "sync", overrides: { sex?: Sex | null } = {}) => {
115
- const input = { demographic: demographic(overrides) };
116
- sent.current = JSON.stringify(input.demographic);
122
+ const input = form(overrides);
123
+ sent.current = JSON.stringify(input);
117
124
  typedSearch.current = kind === "search";
118
125
  void (kind === "sync" ? patient.sync(input) : patient.search(input)).catch(() => {}); // failures land on the object
119
126
  if (patient.busy) setSentFrom(from);
@@ -131,9 +138,9 @@ export function PatientIntakeForm({
131
138
  setSentFrom("query");
132
139
  void (async () => {
133
140
  try {
134
- await patient.search({ demographic: parsed });
141
+ await patient.search(toSearchInput(parsed));
135
142
  const alsoLast = searchBoth(parsed);
136
- if (alsoLast && patient.snapshot.candidates.length === 0) await patient.search({ demographic: alsoLast });
143
+ if (alsoLast && patient.snapshot.candidates.length === 0) await patient.search(toSearchInput(alsoLast));
137
144
  } catch {
138
145
  // failures land on the object
139
146
  }
@@ -193,7 +200,7 @@ export function PatientIntakeForm({
193
200
  const answered =
194
201
  !typeAhead.waiting() &&
195
202
  !busy &&
196
- (field === "query" ? searched === query.trim() : sent.current === JSON.stringify(demographic()));
203
+ (field === "query" ? searched === query.trim() : sent.current === JSON.stringify(form()));
197
204
  if (searchKeys(e, matches.current, answered)) return;
198
205
  if (e.key === "Tab" && !e.shiftKey && field !== "query") visit(field);
199
206
  };
@@ -208,7 +215,7 @@ export function PatientIntakeForm({
208
215
  const answered =
209
216
  !typeAhead.waiting() &&
210
217
  !busy &&
211
- (mode === "search" ? searched === query.trim() : sent.current === JSON.stringify(demographic()));
218
+ (mode === "search" ? searched === query.trim() : sent.current === JSON.stringify(form()));
212
219
  if (!few || !answered || !typedSearch.current || !field || document.activeElement !== field) return;
213
220
  if (focusedFor.current === matchesFor) return;
214
221
  focusedFor.current = matchesFor;
@@ -305,79 +312,89 @@ export function PatientIntakeForm({
305
312
  <Stack gap="3">
306
313
  {mode === "search" && (
307
314
  <div {...focusProps} {...searchProps}>
308
- <Input
309
- label="Find patient"
310
- placeholder="Name, date of birth, phone or email"
311
- value={query}
312
- onChange={(e) => {
313
- setQuery(e.target.value);
314
- typeAhead.typed("query", e.target.value);
315
- // Too little left to search on: the matches on screen answer a query that isn't there
316
- // any more, so they go, and the card is back where it started — including what it has
317
- // already moved the cursor to, or typing the same name again would land nowhere.
318
- if (typeAhead.tooShort(e.target.value)) {
319
- setSearched(null);
320
- focusedFor.current = null;
321
- }
322
- }}
323
- onBlur={() => {
324
- // Leaving asks now rather than after the pause — a search, never a sync: it can't
325
- // create anyone and it can't change whoever it finds.
326
- typeAhead.cancel();
327
- if (query.trim() !== searched) runSearch();
328
- }}
329
- onKeyDown={(e) => onKeys(e, "query")}
330
- loading={spinning === "query"}
331
- role="combobox"
332
- aria-expanded={searched !== null}
333
- aria-autocomplete="list"
334
- aria-activedescendant={activeId ?? undefined}
335
- autoFocus
336
- {...noAutofill}
337
- />
315
+ <TrackedField formName="find_patient" fieldName="patientSearch" isOptional={false}>
316
+ <Input
317
+ label="Find patient"
318
+ placeholder="Name, date of birth, phone or email"
319
+ value={query}
320
+ onChange={(e) => {
321
+ setQuery(e.target.value);
322
+ typeAhead.typed("query", e.target.value);
323
+ // Too little left to search on: the matches on screen answer a query that isn't there
324
+ // any more, so they go, and the card is back where it started — including what it has
325
+ // already moved the cursor to, or typing the same name again would land nowhere.
326
+ if (typeAhead.tooShort(e.target.value)) {
327
+ setSearched(null);
328
+ focusedFor.current = null;
329
+ }
330
+ }}
331
+ onBlur={() => {
332
+ // Leaving asks now rather than after the pause — a search, never a sync: it can't
333
+ // create anyone and it can't change whoever it finds.
334
+ typeAhead.cancel();
335
+ if (query.trim() !== searched) runSearch();
336
+ }}
337
+ onKeyDown={(e) => onKeys(e, "query")}
338
+ loading={spinning === "query"}
339
+ role="combobox"
340
+ aria-expanded={searched !== null}
341
+ aria-autocomplete="list"
342
+ aria-activedescendant={activeId ?? undefined}
343
+ autoFocus
344
+ {...noAutofill}
345
+ />
346
+ </TrackedField>
338
347
  </div>
339
348
  )}
340
349
  {creating && (
341
350
  <Grid min="200px" gap="3">
342
351
  <div {...focusProps}>
352
+ <TrackedField formName="new_patient_form" fieldName="firstName" isOptional={false}>
353
+ <Input
354
+ {...gap("first")}
355
+ label="First name"
356
+ value={first}
357
+ onChange={type("first", setFirst)}
358
+ onBlur={() => leaveField("first")}
359
+ onKeyDown={(e) => onKeys(e, "first")}
360
+ loading={spinning === "first"}
361
+ autoFocus
362
+ {...noAutofill}
363
+ />
364
+ </TrackedField>
365
+ </div>
366
+ <TrackedField formName="new_patient_form" fieldName="lastName" isOptional={false}>
343
367
  <Input
344
- {...gap("first")}
345
- label="First name"
346
- value={first}
347
- onChange={type("first", setFirst)}
348
- onBlur={() => leaveField("first")}
349
- onKeyDown={(e) => onKeys(e, "first")}
350
- loading={spinning === "first"}
351
- autoFocus
368
+ {...gap("last")}
369
+ label="Last name"
370
+ value={last}
371
+ onChange={type("last", setLast)}
372
+ onBlur={() => leaveField("last")}
373
+ onKeyDown={(e) => onKeys(e, "last")}
374
+ loading={spinning === "last"}
352
375
  {...noAutofill}
353
376
  />
354
- </div>
355
- <Input
356
- {...gap("last")}
357
- label="Last name"
358
- value={last}
359
- onChange={type("last", setLast)}
360
- onBlur={() => leaveField("last")}
361
- onKeyDown={(e) => onKeys(e, "last")}
362
- loading={spinning === "last"}
363
- {...noAutofill}
364
- />
377
+ </TrackedField>
365
378
  {rows >= 2 && (
366
379
  <>
367
- <Input
368
- {...gap("dob")}
369
- label="Date of birth"
370
- type="date"
371
- {...noAutofill}
372
- value={dob}
373
- onChange={type("dob", setDob)}
374
- onBlur={() => leaveField("dob")}
375
- onKeyDown={(e) => onKeys(e, "dob")}
376
- loading={spinning === "dob"}
377
- />
380
+ <TrackedField formName="new_patient_form" fieldName="dateOfBirth" isOptional={false}>
381
+ <Input
382
+ {...gap("dob")}
383
+ label="Date of birth"
384
+ type="date"
385
+ {...noAutofill}
386
+ value={dob}
387
+ onChange={type("dob", setDob)}
388
+ onBlur={() => leaveField("dob")}
389
+ onKeyDown={(e) => onKeys(e, "dob")}
390
+ loading={spinning === "dob"}
391
+ />
392
+ </TrackedField>
378
393
  <div
379
394
  ref={sexField}
395
+ onFocus={sexPicked.onFocus}
380
396
  onBlur={(e) => {
397
+ sexPicked.onBlur(e);
381
398
  if (!e.currentTarget.contains(e.relatedTarget as Node | null)) visit("sex");
382
399
  }}
383
400
  onKeyDown={(e) => onKeys(e, "sex")}
@@ -389,6 +406,7 @@ export function PatientIntakeForm({
389
406
  options={SEX_OPTIONS}
390
407
  value={sex}
391
408
  onChange={(next) => {
409
+ sexPicked.onChange(true);
392
410
  setSex(next);
393
411
  visit("sex");
394
412
  setMissing((m) => m.filter((f) => f !== "sex"));
@@ -397,33 +415,37 @@ export function PatientIntakeForm({
397
415
  </div>
398
416
  {rows >= 3 && (
399
417
  <>
400
- <Input
401
- label="Phone"
402
- helper="The patient is texted their order link here, so a mobile number."
403
- type="tel"
404
- inputMode="tel"
405
- pattern={PHONE_PATTERN}
406
- value={phone}
407
- onChange={type("phone", setPhone)}
408
- onBlur={() => {
409
- setPhone(formatPhone(phone));
410
- leaveField("phone");
411
- }}
412
- onKeyDown={(e) => onKeys(e, "phone")}
413
- loading={spinning === "phone"}
414
- {...noAutofill}
415
- />
416
- <Input
417
- label="Email"
418
- type="email"
419
- inputMode="email"
420
- value={email}
421
- onChange={type("email", setEmail)}
422
- onBlur={() => leaveField("email")}
423
- onKeyDown={(e) => onKeys(e, "email")}
424
- loading={spinning === "email"}
425
- {...noAutofill}
426
- />
418
+ <TrackedField formName="new_patient_form" fieldName="phone" isOptional>
419
+ <Input
420
+ label="Phone"
421
+ helper="The patient is texted their order link here, so a mobile number."
422
+ type="tel"
423
+ inputMode="tel"
424
+ pattern={PHONE_PATTERN}
425
+ value={phone}
426
+ onChange={type("phone", setPhone)}
427
+ onBlur={() => {
428
+ setPhone(formatPhone(phone));
429
+ leaveField("phone");
430
+ }}
431
+ onKeyDown={(e) => onKeys(e, "phone")}
432
+ loading={spinning === "phone"}
433
+ {...noAutofill}
434
+ />
435
+ </TrackedField>
436
+ <TrackedField formName="new_patient_form" fieldName="email" isOptional>
437
+ <Input
438
+ label="Email"
439
+ type="email"
440
+ inputMode="email"
441
+ value={email}
442
+ onChange={type("email", setEmail)}
443
+ onBlur={() => leaveField("email")}
444
+ onKeyDown={(e) => onKeys(e, "email")}
445
+ loading={spinning === "email"}
446
+ {...noAutofill}
447
+ />
448
+ </TrackedField>
427
449
  </>
428
450
  )}
429
451
  </>
@@ -434,7 +456,7 @@ export function PatientIntakeForm({
434
456
  {/* Nothing came back. That the list is empty needs no saying — the prescriber can see it. What
435
457
  they can't see is that matching has no tolerance for a typo, so an empty list is not "they
436
458
  aren't here", and adding someone already on file is how a duplicate is made. This stands in
437
- for a gap: core's docs/api-gaps.md item 3 asks for fuzzy name matching, and when that ships
459
+ for a gap: network-api doesn't match names fuzzily yet, and when it does
438
460
  an empty list means what it looks like and these words should go. */}
439
461
  {mode === "search" && answeredNothing && (
440
462
  <Alert
@@ -482,35 +504,45 @@ export function PatientIntakeForm({
482
504
  <Alert tone="warning" title="Address needed" description={snap.error.message} />
483
505
  )}
484
506
  <Grid min="120px" gap="3">
485
- <Input
486
- label="Street"
487
- value={street1}
488
- onChange={(e) => setStreet1(e.target.value)}
489
- {...noAutofill}
490
- />
491
- <Input
492
- label="Apt / suite"
493
- value={street2}
494
- onChange={(e) => setStreet2(e.target.value)}
495
- {...noAutofill}
496
- />
507
+ <TrackedField formName="new_patient_form" fieldName="address_street1" isOptional={false}>
508
+ <Input
509
+ label="Street"
510
+ value={street1}
511
+ onChange={(e) => setStreet1(e.target.value)}
512
+ {...noAutofill}
513
+ />
514
+ </TrackedField>
515
+ <TrackedField formName="new_patient_form" fieldName="address_street2" isOptional>
516
+ <Input
517
+ label="Apt / suite"
518
+ value={street2}
519
+ onChange={(e) => setStreet2(e.target.value)}
520
+ {...noAutofill}
521
+ />
522
+ </TrackedField>
497
523
  </Grid>
498
524
  <Grid min="120px" gap="3">
499
- <Input label="City" value={city} onChange={(e) => setCity(e.target.value)} {...noAutofill} />
500
- <Input
501
- label="State"
502
- value={state}
503
- onChange={(e) => setState(e.target.value)}
504
- maxLength={2}
505
- {...noAutofill}
506
- />
507
- <Input
508
- label="ZIP"
509
- value={postalCode}
510
- onChange={(e) => setPostalCode(e.target.value)}
511
- inputMode="numeric"
512
- {...noAutofill}
513
- />
525
+ <TrackedField formName="new_patient_form" fieldName="address_city" isOptional={false}>
526
+ <Input label="City" value={city} onChange={(e) => setCity(e.target.value)} {...noAutofill} />
527
+ </TrackedField>
528
+ <TrackedField formName="new_patient_form" fieldName="address_state" isOptional={false}>
529
+ <Input
530
+ label="State"
531
+ value={state}
532
+ onChange={(e) => setState(e.target.value)}
533
+ maxLength={2}
534
+ {...noAutofill}
535
+ />
536
+ </TrackedField>
537
+ <TrackedField formName="new_patient_form" fieldName="address_zip" isOptional={false}>
538
+ <Input
539
+ label="ZIP"
540
+ value={postalCode}
541
+ onChange={(e) => setPostalCode(e.target.value)}
542
+ inputMode="numeric"
543
+ {...noAutofill}
544
+ />
545
+ </TrackedField>
514
546
  </Grid>
515
547
  </Stack>
516
548
  </div>
@@ -0,0 +1,106 @@
1
+ // @vitest-environment jsdom
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import { fakeNetworkApiClient, payload } from "@photonhealth/client/testing";
6
+ import { PhotonPatient } from "../../index.ts";
7
+ import { patient } from "../../../test/cards.fixtures.tsx";
8
+ import {
9
+ edited,
10
+ leaveField,
11
+ meAsPrescriber,
12
+ recordAnalytics,
13
+ type RecordedAnalytics,
14
+ typeInto,
15
+ unmountAndRestoreFetch,
16
+ withAnalytics,
17
+ } from "../../../test/analytics.fixtures.tsx";
18
+
19
+ let analytics: RecordedAnalytics;
20
+ beforeEach(() => {
21
+ analytics = recordAnalytics();
22
+ });
23
+ afterEach(unmountAndRestoreFetch);
24
+
25
+ const editPatient = async () => {
26
+ render(<PhotonPatient patient="pat_1" />, {
27
+ wrapper: withAnalytics(
28
+ fakeNetworkApiClient({
29
+ ...meAsPrescriber,
30
+ GetPatient: () => payload("patient", "PatientPayload", patient),
31
+ UpdatePatient: () => payload("patient", "PatientPayload", patient),
32
+ }).client,
33
+ ),
34
+ });
35
+ await userEvent.click(await screen.findByRole("button", { name: "Edit patient" }));
36
+ };
37
+
38
+ describe("PatientSummary: Field Interaction", () => {
39
+ it("editing a patient: each field visited sends focus, one change and blur as update_patient_form", async () => {
40
+ await editPatient();
41
+ await typeInto("First name", "Zqx");
42
+ await typeInto("Last name", "Zqx");
43
+ await userEvent.click(screen.getByLabelText("Date of birth"));
44
+ fireEvent.change(screen.getByLabelText("Date of birth"), { target: { value: "1991-02-03" } });
45
+ leaveField();
46
+ await userEvent.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "FEMALE");
47
+ leaveField();
48
+ await typeInto("Phone", "5555550100");
49
+ await typeInto("Email", "zqx@example.com");
50
+ await typeInto("Street", "Zqx");
51
+ await typeInto("Apt / suite", "Zqx");
52
+ await typeInto("City", "Zqx");
53
+ await typeInto("State", "{Backspace}Q");
54
+ await typeInto("ZIP", "99999");
55
+ for (const addLabel of ["Add allergy", "Add medication", "Add diagnosis"]) {
56
+ await userEvent.click(screen.getByRole("button", { name: addLabel }));
57
+ await userEvent.keyboard("Zqxentry");
58
+ leaveField();
59
+ }
60
+ await userEvent.click(screen.getByRole("button", { name: "Add insurance" }));
61
+ await userEvent.keyboard("987654");
62
+ await userEvent.tab();
63
+ await userEvent.keyboard("ZQXPCN");
64
+ leaveField();
65
+
66
+ const fields = {
67
+ firstName: false,
68
+ lastName: false,
69
+ dateOfBirth: false,
70
+ sex: false,
71
+ phone: true,
72
+ email: true,
73
+ address_street1: true,
74
+ address_street2: true,
75
+ address_city: true,
76
+ address_state: true,
77
+ address_zip: true,
78
+ allergies: true,
79
+ medications: true,
80
+ diagnoses: true,
81
+ insurance: true,
82
+ };
83
+ await analytics.expectEventLog([
84
+ "Prescribe Workflow Viewed",
85
+ ...edited("firstName"),
86
+ ...edited("lastName"),
87
+ ...edited("dateOfBirth"),
88
+ ...edited("sex"),
89
+ ...edited("phone"),
90
+ ...edited("email"),
91
+ ...edited("address_street1"),
92
+ ...edited("address_street2"),
93
+ ...edited("address_city"),
94
+ ...edited("address_state"),
95
+ ...edited("address_zip"),
96
+ ...edited("allergies"),
97
+ ...edited("medications"),
98
+ ...edited("diagnoses"),
99
+ ...edited("insurance"),
100
+ ]);
101
+ const sent = analytics.fieldInteractions();
102
+ expect(new Set(sent.map((s) => s.formName))).toEqual(new Set(["update_patient_form"]));
103
+ expect(Object.fromEntries(sent.map((s) => [s.fieldName, s.isOptional]))).toEqual(fields);
104
+ for (const body of analytics.bodies()) expect(body).not.toMatch(/Zqx|1991|5555550100|99999|987654|FEMALE/i);
105
+ });
106
+ });