@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.
- package/README.md +35 -8
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -4
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +20 -16
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +4 -2
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +1 -12
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +7 -360
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/format.d.ts +2 -2
- package/dist/components/format.js +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -1
- package/dist/components/patient/Benefits.js +2 -1
- package/dist/components/patient/Benefits.js.map +1 -1
- package/dist/components/patient/Clinical.d.ts +3 -2
- package/dist/components/patient/Clinical.d.ts.map +1 -1
- package/dist/components/patient/Clinical.js +21 -20
- package/dist/components/patient/Clinical.js.map +1 -1
- package/dist/components/patient/IntakeForm.d.ts.map +1 -1
- package/dist/components/patient/IntakeForm.js +52 -43
- package/dist/components/patient/IntakeForm.js.map +1 -1
- package/dist/components/patient/Summary.d.ts +1 -1
- package/dist/components/patient/Summary.d.ts.map +1 -1
- package/dist/components/patient/Summary.js +13 -3
- package/dist/components/patient/Summary.js.map +1 -1
- package/dist/components/patient/fields.d.ts +1 -2
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +2 -1
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/query.d.ts +14 -0
- package/dist/components/patient/query.d.ts.map +1 -1
- package/dist/components/patient/query.js +5 -0
- package/dist/components/patient/query.js.map +1 -1
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +3 -1
- package/dist/primitives/PhotonProvider.d.ts.map +1 -1
- package/dist/primitives/PhotonProvider.js +23 -11
- package/dist/primitives/PhotonProvider.js.map +1 -1
- package/dist/primitives/defaults.d.ts.map +1 -1
- package/dist/primitives/defaults.js +6 -3
- package/dist/primitives/defaults.js.map +1 -1
- package/dist/primitives/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.js.map +1 -0
- package/dist/primitives/types.d.ts +15 -3
- package/dist/primitives/types.d.ts.map +1 -1
- package/dist/primitives/types.js.map +1 -1
- package/dist/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +45 -3
- package/dist/test-utils/contract.d.ts.map +1 -1
- package/dist/test-utils/contract.js +23 -2
- package/dist/test-utils/contract.js.map +1 -1
- package/package.json +5 -3
- package/src/adapters/tailwind.tsx +52 -24
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +45 -30
- package/src/components/PhotonPatient.tsx +11 -7
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +10 -570
- package/src/components/format.ts +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +21 -13
- package/src/components/patient/Clinical.tsx +31 -26
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +168 -136
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +54 -34
- package/src/components/patient/fields.tsx +52 -38
- package/src/components/patient/query.ts +6 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -0
- package/src/index.ts +2 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +30 -15
- package/src/primitives/defaults.tsx +44 -21
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/types.ts +15 -3
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +45 -3
- package/src/test-utils/contract.tsx +45 -2
- package/dist/components/TreatmentPicker.d.ts +0 -45
- package/dist/components/TreatmentPicker.d.ts.map +0 -1
- package/dist/components/TreatmentPicker.js.map +0 -1
- 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
|
|
38
|
-
const [
|
|
39
|
-
const [
|
|
40
|
-
const [
|
|
41
|
-
const [
|
|
42
|
-
const [
|
|
43
|
-
const [
|
|
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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
116
|
-
sent.current = JSON.stringify(input
|
|
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(
|
|
141
|
+
await patient.search(toSearchInput(parsed));
|
|
135
142
|
const alsoLast = searchBoth(parsed);
|
|
136
|
-
if (alsoLast && patient.snapshot.candidates.length === 0) await patient.search(
|
|
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(
|
|
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(
|
|
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
|
-
<
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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("
|
|
345
|
-
label="
|
|
346
|
-
value={
|
|
347
|
-
onChange={type("
|
|
348
|
-
onBlur={() => leaveField("
|
|
349
|
-
onKeyDown={(e) => onKeys(e, "
|
|
350
|
-
loading={spinning === "
|
|
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
|
-
</
|
|
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
|
-
<
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
<
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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:
|
|
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
|
-
<
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
-
<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
+
});
|