@photonhealth/react 2.0.0-rc.2 → 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.
- package/README.md +17 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +5 -2
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.js +34 -15
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -1
- package/dist/analytics/cardLifecycle.d.ts +10 -0
- package/dist/analytics/cardLifecycle.d.ts.map +1 -0
- package/dist/analytics/cardLifecycle.js +43 -0
- package/dist/analytics/cardLifecycle.js.map +1 -0
- package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
- package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
- package/dist/analytics/lifecycleOutcomes.js +16 -0
- package/dist/analytics/lifecycleOutcomes.js.map +1 -0
- package/dist/analytics/tracker.d.ts +5 -3
- package/dist/analytics/tracker.d.ts.map +1 -1
- package/dist/analytics/tracker.js +10 -5
- package/dist/analytics/tracker.js.map +1 -1
- package/dist/components/PhotonOrder.d.ts +18 -18
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +17 -6
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts +7 -35
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +3 -77
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +14 -14
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +0 -1
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/open.d.ts +11 -13
- package/dist/components/open.d.ts.map +1 -1
- package/dist/components/open.js +7 -2
- package/dist/components/open.js.map +1 -1
- package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
- package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/PatientCard.js +101 -0
- package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
- package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
- package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
- package/dist/components/patient/PatientIntakeForm.js +114 -0
- package/dist/components/patient/PatientIntakeForm.js.map +1 -0
- package/dist/components/patient/PatientSearch.d.ts +12 -0
- package/dist/components/patient/PatientSearch.d.ts.map +1 -0
- package/dist/components/patient/PatientSearch.js +148 -0
- package/dist/components/patient/PatientSearch.js.map +1 -0
- package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
- package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +5 -5
- package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
- package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +13 -15
- package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +11 -11
- package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
- package/dist/components/patient/fields.d.ts +7 -25
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +11 -53
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
- package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
- package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -15
- package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +14 -8
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -1
- package/dist/components/prescription/PrescriptionCard.js +10 -3
- package/dist/components/prescription/PrescriptionCard.js.map +1 -1
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +6 -6
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -1
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +6 -6
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -1
- package/dist/components/schemaErrors.d.ts +3 -2
- package/dist/components/schemaErrors.d.ts.map +1 -1
- package/dist/components/schemaErrors.js +2 -1
- package/dist/components/schemaErrors.js.map +1 -1
- package/dist/components/search.d.ts +1 -1
- package/dist/components/search.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/meta/version.js +1 -1
- package/package.json +5 -2
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +0 -1
- package/src/analytics/PhotonAnalyticsProvider.tsx +75 -20
- package/src/analytics/cardLifecycle.test.tsx +272 -0
- package/src/analytics/cardLifecycle.ts +44 -0
- package/src/analytics/fieldInteraction.test.tsx +11 -9
- package/src/analytics/lifecycleOutcomes.test.ts +78 -0
- package/src/analytics/lifecycleOutcomes.ts +29 -0
- package/src/analytics/tracker.test.ts +1 -1
- package/src/analytics/tracker.ts +13 -6
- package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
- package/src/components/PhotonOrder.test.tsx +146 -8
- package/src/components/PhotonOrder.tsx +37 -26
- package/src/components/PhotonPatient.tsx +8 -163
- package/src/components/PhotonPrescription.test.tsx +22 -18
- package/src/components/PhotonPrescription.tsx +14 -14
- package/src/components/ScreeningAlerts.test.tsx +81 -0
- package/src/components/open.ts +13 -16
- package/src/components/order/DraftOrderPrompt.test.tsx +3 -6
- package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
- package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
- package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
- package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
- package/src/components/patient/PatientIntakeForm.tsx +222 -0
- package/src/components/patient/PatientSearch.test.tsx +204 -0
- package/src/components/patient/PatientSearch.tsx +221 -0
- package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
- package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +4 -4
- package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
- package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +23 -23
- package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
- package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
- package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
- package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
- package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
- package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
- package/src/components/patient/fields.tsx +12 -138
- package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
- package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -21
- package/src/components/prescription/PrescriptionCard.test.tsx +174 -12
- package/src/components/prescription/PrescriptionCard.tsx +28 -14
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +2 -5
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +3 -6
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +34 -37
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +14 -14
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +2 -5
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +3 -7
- package/src/components/schemaErrors.ts +3 -2
- package/src/components/search.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/meta/version.test.ts +1 -0
- package/src/meta/version.ts +1 -1
- package/dist/components/patient/Benefits.d.ts.map +0 -1
- package/dist/components/patient/Benefits.js.map +0 -1
- package/dist/components/patient/Clinical.d.ts.map +0 -1
- package/dist/components/patient/Clinical.js.map +0 -1
- package/dist/components/patient/IntakeForm.d.ts +0 -10
- package/dist/components/patient/IntakeForm.d.ts.map +0 -1
- package/dist/components/patient/IntakeForm.js +0 -333
- package/dist/components/patient/IntakeForm.js.map +0 -1
- package/dist/components/patient/Summary.d.ts +0 -48
- package/dist/components/patient/Summary.d.ts.map +0 -1
- package/dist/components/patient/Summary.js +0 -90
- package/dist/components/patient/Summary.js.map +0 -1
- package/dist/components/patient/query.d.ts +0 -37
- package/dist/components/patient/query.d.ts.map +0 -1
- package/dist/components/patient/query.js.map +0 -1
- package/src/components/patient/IntakeForm.test.tsx +0 -89
- package/src/components/patient/IntakeForm.tsx +0 -564
- package/src/components/patient/Summary.test.tsx +0 -106
- package/src/components/patient/Summary.tsx +0 -330
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it, vi, type Mock } from "vitest";
|
|
4
|
+
import type { PatientRecord } from "@photonhealth/client";
|
|
5
|
+
import { PatientDetailsForm, type PatientDetailsInput } from "./PatientDetailsForm.tsx";
|
|
6
|
+
import { patientRecord as record } from "../../../../test/patientRecord.fixtures.ts";
|
|
7
|
+
|
|
8
|
+
type Contact = NonNullable<PatientRecord["contact"]>;
|
|
9
|
+
|
|
10
|
+
/** Ada Lovelace, born 1990-01-01, female, with the contact details a test passes. */
|
|
11
|
+
const ada = (contact: Partial<Contact> | null = null): PatientRecord => ({
|
|
12
|
+
...record({ demographic: { dateOfBirth: "1990-01-01", sex: "FEMALE" } }),
|
|
13
|
+
contact: contact && { phone: null, email: null, address: null, ...contact },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const address = { street1: "1 Main St", street2: null, city: "Boston", state: "MA", postalCode: "02101" };
|
|
17
|
+
|
|
18
|
+
const renderForm = ({
|
|
19
|
+
patient = ada(),
|
|
20
|
+
addressRequest = null,
|
|
21
|
+
}: { patient?: PatientRecord; addressRequest?: string | null } = {}) => {
|
|
22
|
+
const onSave = vi.fn();
|
|
23
|
+
const user = userEvent.setup();
|
|
24
|
+
render(<PatientDetailsForm patient={patient} addressRequest={addressRequest} onSave={onSave} />);
|
|
25
|
+
return { user, onSave };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const field = (label: string) => screen.getByLabelText(label);
|
|
29
|
+
|
|
30
|
+
/** Replace a field's text, then move the cursor out of it. */
|
|
31
|
+
const retype = async (user: ReturnType<typeof userEvent.setup>, label: string, text: string) => {
|
|
32
|
+
await user.clear(field(label));
|
|
33
|
+
if (text) await user.type(field(label), text);
|
|
34
|
+
await user.tab();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** What the one call to onSave sent. */
|
|
38
|
+
const sent = (onSave: Mock) => {
|
|
39
|
+
expect(onSave).toHaveBeenCalledOnce();
|
|
40
|
+
return onSave.mock.calls[0]![0] as PatientDetailsInput;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const clickSave = (user: ReturnType<typeof userEvent.setup>) =>
|
|
44
|
+
user.click(screen.getByRole("button", { name: "Save" }));
|
|
45
|
+
|
|
46
|
+
describe("PatientDetailsForm", () => {
|
|
47
|
+
describe("initial values", () => {
|
|
48
|
+
it("saved patient: fills in every field from the record, with the phone number formatted", () => {
|
|
49
|
+
renderForm({ patient: ada({ phone: "+14155550172", email: "ada@example.com", address }) });
|
|
50
|
+
expect(field("First name")).toHaveValue("Ada");
|
|
51
|
+
expect(field("Last name")).toHaveValue("Lovelace");
|
|
52
|
+
expect(field("Date of birth")).toHaveValue("1990-01-01");
|
|
53
|
+
expect(screen.getByRole("combobox", { name: "Sex" })).toHaveValue("FEMALE");
|
|
54
|
+
expect(field("Phone")).toHaveValue("+1 (415) 555-0172");
|
|
55
|
+
expect(field("Email")).toHaveValue("ada@example.com");
|
|
56
|
+
expect(field("Street")).toHaveValue("1 Main St");
|
|
57
|
+
expect(field("Apt / suite")).toHaveValue("");
|
|
58
|
+
expect(field("City")).toHaveValue("Boston");
|
|
59
|
+
expect(field("State")).toHaveValue("MA");
|
|
60
|
+
expect(field("ZIP")).toHaveValue("02101");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("no demographic or contact details: every field starts empty", () => {
|
|
64
|
+
renderForm({ patient: record({ demographic: null }) });
|
|
65
|
+
for (const label of ["First name", "Last name", "Date of birth", "Phone", "Email", "Street", "City", "ZIP"]) {
|
|
66
|
+
expect(field(label)).toHaveValue("");
|
|
67
|
+
}
|
|
68
|
+
expect(screen.getByRole("combobox", { name: "Sex" })).toHaveValue("");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("phone", () => {
|
|
73
|
+
it("phone typed, then leaving the field: formats the phone number", async () => {
|
|
74
|
+
const { user } = renderForm();
|
|
75
|
+
await retype(user, "Phone", "415-555-0172");
|
|
76
|
+
expect(field("Phone")).toHaveValue("+1 (415) 555-0172");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Pins today's behavior
|
|
81
|
+
// Question: The form checks a field once the prescriber has left it (react-hook-form's "onTouched"
|
|
82
|
+
// mode), then again on every keystroke. This was an arbitrary choice - open to only showing validation
|
|
83
|
+
// errors on Save instead.
|
|
84
|
+
describe("errors while typing", () => {
|
|
85
|
+
it("phone typed: no error until leaving the field, then the error updates on every keystroke", async () => {
|
|
86
|
+
const { user } = renderForm();
|
|
87
|
+
await user.type(field("Phone"), "415");
|
|
88
|
+
expect(field("Phone")).not.toHaveAccessibleDescription("Enter a valid phone number");
|
|
89
|
+
|
|
90
|
+
await user.tab();
|
|
91
|
+
expect(field("Phone")).toHaveAccessibleDescription("Enter a valid phone number");
|
|
92
|
+
|
|
93
|
+
await user.type(field("Phone"), "5550172");
|
|
94
|
+
expect(field("Phone")).not.toHaveAccessibleDescription("Enter a valid phone number");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// How Save connects the form to PatientDetailsSchema and changesToSave
|
|
99
|
+
describe("Save", () => {
|
|
100
|
+
it("nothing changed, clicking Save: calls onSave once with every field filled in, changed or not", async () => {
|
|
101
|
+
const { user, onSave } = renderForm({ patient: ada({ phone: "+14155550172" }) });
|
|
102
|
+
await clickSave(user);
|
|
103
|
+
expect(onSave).toHaveBeenCalledExactlyOnceWith({
|
|
104
|
+
demographic: { name: { first: "Ada", last: "Lovelace" }, dateOfBirth: "1990-01-01", sex: "FEMALE" },
|
|
105
|
+
contact: { phone: "+14155550172", email: "" },
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("every field changed, clicking Save: sends every field as PatientDetailsSchema parses it", async () => {
|
|
110
|
+
const { user, onSave } = renderForm();
|
|
111
|
+
await retype(user, "First name", "Augusta");
|
|
112
|
+
await retype(user, "Last name", "Byron");
|
|
113
|
+
await retype(user, "Date of birth", "1991-02-03");
|
|
114
|
+
await user.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "MALE");
|
|
115
|
+
await retype(user, "Phone", "415-555-0172");
|
|
116
|
+
await retype(user, "Email", "ada@example.com");
|
|
117
|
+
await retype(user, "Street", " 1 Main St ");
|
|
118
|
+
await retype(user, "Apt / suite", "Apt 2");
|
|
119
|
+
await retype(user, "City", "Boston");
|
|
120
|
+
await retype(user, "State", "ma");
|
|
121
|
+
await retype(user, "ZIP", "02101");
|
|
122
|
+
await clickSave(user);
|
|
123
|
+
expect(onSave).toHaveBeenCalledExactlyOnceWith({
|
|
124
|
+
demographic: { name: { first: "Augusta", last: "Byron" }, dateOfBirth: "1991-02-03", sex: "MALE" },
|
|
125
|
+
contact: {
|
|
126
|
+
phone: "+14155550172",
|
|
127
|
+
email: "ada@example.com",
|
|
128
|
+
address: {
|
|
129
|
+
street1: "1 Main St",
|
|
130
|
+
street2: "Apt 2",
|
|
131
|
+
city: "Boston",
|
|
132
|
+
state: "MA",
|
|
133
|
+
postalCode: "02101",
|
|
134
|
+
country: "US",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("phone on file cleared, clicking Save: sends an empty phone to clear it in network-api", async () => {
|
|
141
|
+
const { user, onSave } = renderForm({ patient: ada({ phone: "+14155550172" }) });
|
|
142
|
+
await retype(user, "Phone", "");
|
|
143
|
+
await clickSave(user);
|
|
144
|
+
expect(sent(onSave)).toMatchObject({ contact: { phone: "" } });
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("email on file cleared, clicking Save: sends an empty email to clear it in network-api", async () => {
|
|
148
|
+
const { user, onSave } = renderForm({ patient: ada({ email: "ada@example.com" }) });
|
|
149
|
+
await retype(user, "Email", "");
|
|
150
|
+
await clickSave(user);
|
|
151
|
+
expect(sent(onSave)).toMatchObject({ contact: { email: "" } });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Documents that clearing a required field and clicking Save runs PatientDetailsSchema,
|
|
155
|
+
// shows its "Required" error on that field, and stops Save from sending anything.
|
|
156
|
+
it('last name cleared, clicking Save: shows "Required" on the last name, and onSave is not called', async () => {
|
|
157
|
+
const { user, onSave } = renderForm();
|
|
158
|
+
await user.clear(field("Last name"));
|
|
159
|
+
await clickSave(user);
|
|
160
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
161
|
+
expect(field("Last name")).toHaveAccessibleDescription("Required");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Documents that filling out a single address field causes
|
|
165
|
+
// other address fields to become required
|
|
166
|
+
it('only street filled in, clicking Save: shows "Required" on the untouched city, state and ZIP fields', async () => {
|
|
167
|
+
const { user, onSave } = renderForm();
|
|
168
|
+
await user.type(field("Street"), "1 Main St");
|
|
169
|
+
await clickSave(user);
|
|
170
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
171
|
+
for (const label of ["City", "State", "ZIP"]) expect(field(label)).toHaveAccessibleDescription("Required");
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Pins today's behavior
|
|
176
|
+
// Sending an order the server refuses until the patient can be reached (a missing phone, email or address)
|
|
177
|
+
// expands PatientSummary and shows this warning above the contact fields. PhotonOrder passes the request down
|
|
178
|
+
// as `addressRequest`.
|
|
179
|
+
// TODO(TECH-1491): find a better place for this error than the patient's details form.
|
|
180
|
+
describe("contact request", () => {
|
|
181
|
+
it('order send refused until the patient can be reached, phone on file: shows "Address needed to send"', () => {
|
|
182
|
+
renderForm({ patient: ada({ phone: "+14155550172" }), addressRequest: "patient pat_1 has no address" });
|
|
183
|
+
expect(screen.getByText("Address needed to send")).toBeInTheDocument();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('order send refused until the patient can be reached, no phone on file: shows "Phone needed to send"', () => {
|
|
187
|
+
renderForm({ addressRequest: "patient pat_1 has no address" });
|
|
188
|
+
expect(screen.getByText("Phone needed to send")).toBeInTheDocument();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("order send refused until the patient can be reached: doesn't show the server's message, which can name internal ids", () => {
|
|
192
|
+
renderForm({ addressRequest: "patient pat_1 has no address" });
|
|
193
|
+
expect(screen.queryByText(/pat_1/)).not.toBeInTheDocument();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("no contact request: shows no message", () => {
|
|
197
|
+
renderForm();
|
|
198
|
+
expect(screen.queryByText(/needed to send/)).not.toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
2
|
+
import { type PatientInput, type PatientRecord } from "@photonhealth/client";
|
|
3
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
|
+
import { Controller, useForm, type Resolver } from "react-hook-form";
|
|
5
|
+
import { formatPhone } from "../../format.ts";
|
|
6
|
+
import { noAutofill, SEX_OPTIONS } from "../fields.tsx";
|
|
7
|
+
import { TrackedField, useFieldInteractions } from "../../../analytics/fieldInteraction.tsx";
|
|
8
|
+
import { PatientDetailsSchema, type PatientDetails, type PatientDetailsFormValues } from "./PatientDetailsSchema.ts";
|
|
9
|
+
|
|
10
|
+
/** The part of an UpdatePatient that PatientDetailsForm sends. */
|
|
11
|
+
export type PatientDetailsInput = Pick<PatientInput, "demographic" | "contact">;
|
|
12
|
+
|
|
13
|
+
export function PatientDetailsForm({
|
|
14
|
+
patient,
|
|
15
|
+
addressRequest,
|
|
16
|
+
onSave,
|
|
17
|
+
}: {
|
|
18
|
+
patient: PatientRecord;
|
|
19
|
+
addressRequest: string | null;
|
|
20
|
+
/** Called by Save once every field is valid, with every field to send. */
|
|
21
|
+
onSave: (input: PatientDetailsInput) => void | Promise<void>;
|
|
22
|
+
}) {
|
|
23
|
+
const { Alert, Button, Grid, Input, Row, Select, Stack } = useComponents();
|
|
24
|
+
const phone = patient.contact?.phone ?? null;
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
control,
|
|
28
|
+
handleSubmit,
|
|
29
|
+
formState: { isSubmitting },
|
|
30
|
+
} = useForm<PatientDetailsFormValues, unknown, PatientDetails>({
|
|
31
|
+
resolver: zodResolver(PatientDetailsSchema) as unknown as Resolver<
|
|
32
|
+
PatientDetailsFormValues,
|
|
33
|
+
unknown,
|
|
34
|
+
PatientDetails
|
|
35
|
+
>,
|
|
36
|
+
defaultValues: formValuesFrom(patient),
|
|
37
|
+
mode: "onTouched",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const fieldInteraction = useFieldInteractions("update_patient_form");
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<Grid min="200px" gap="3">
|
|
45
|
+
<TrackedField formName="update_patient_form" fieldName="firstName" isOptional={false}>
|
|
46
|
+
<Controller
|
|
47
|
+
control={control}
|
|
48
|
+
name="firstName"
|
|
49
|
+
render={({ field, fieldState }) => (
|
|
50
|
+
<Input
|
|
51
|
+
label="First name"
|
|
52
|
+
name={field.name}
|
|
53
|
+
value={field.value}
|
|
54
|
+
onChange={field.onChange}
|
|
55
|
+
onBlur={field.onBlur}
|
|
56
|
+
invalid={fieldState.invalid}
|
|
57
|
+
errorMessage={fieldState.error?.message}
|
|
58
|
+
{...noAutofill}
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
</TrackedField>
|
|
63
|
+
<TrackedField formName="update_patient_form" fieldName="lastName" isOptional={false}>
|
|
64
|
+
<Controller
|
|
65
|
+
control={control}
|
|
66
|
+
name="lastName"
|
|
67
|
+
render={({ field, fieldState }) => (
|
|
68
|
+
<Input
|
|
69
|
+
label="Last name"
|
|
70
|
+
name={field.name}
|
|
71
|
+
value={field.value}
|
|
72
|
+
onChange={field.onChange}
|
|
73
|
+
onBlur={field.onBlur}
|
|
74
|
+
invalid={fieldState.invalid}
|
|
75
|
+
errorMessage={fieldState.error?.message}
|
|
76
|
+
{...noAutofill}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
</TrackedField>
|
|
81
|
+
<TrackedField formName="update_patient_form" fieldName="dateOfBirth" isOptional={false}>
|
|
82
|
+
<Controller
|
|
83
|
+
control={control}
|
|
84
|
+
name="dateOfBirth"
|
|
85
|
+
render={({ field, fieldState }) => (
|
|
86
|
+
<Input
|
|
87
|
+
label="Date of birth"
|
|
88
|
+
type="date"
|
|
89
|
+
{...noAutofill}
|
|
90
|
+
name={field.name}
|
|
91
|
+
value={field.value}
|
|
92
|
+
onChange={field.onChange}
|
|
93
|
+
onBlur={field.onBlur}
|
|
94
|
+
invalid={fieldState.invalid}
|
|
95
|
+
errorMessage={fieldState.error?.message}
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
98
|
+
/>
|
|
99
|
+
</TrackedField>
|
|
100
|
+
<Controller
|
|
101
|
+
control={control}
|
|
102
|
+
name="sex"
|
|
103
|
+
render={({ field, fieldState }) => {
|
|
104
|
+
const sexInteractions = fieldInteraction("sex", { isOptional: false, hasValue: Boolean(field.value) });
|
|
105
|
+
return (
|
|
106
|
+
<div style={{ display: "contents" }} onFocus={sexInteractions.onFocus} onBlur={sexInteractions.onBlur}>
|
|
107
|
+
<Select
|
|
108
|
+
label="Sex"
|
|
109
|
+
placeholder="Select…"
|
|
110
|
+
options={SEX_OPTIONS}
|
|
111
|
+
value={field.value}
|
|
112
|
+
onChange={(sex) => {
|
|
113
|
+
sexInteractions.onChange(true);
|
|
114
|
+
field.onChange(sex);
|
|
115
|
+
}}
|
|
116
|
+
invalid={fieldState.invalid}
|
|
117
|
+
errorMessage={fieldState.error?.message}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
</Grid>
|
|
124
|
+
<Stack gap="2">
|
|
125
|
+
{/* The server's message can name internal ids ("patient pat_… has no address"); the title says it. A send
|
|
126
|
+
needs a phone; an address only when the server still asks with a phone on file. */}
|
|
127
|
+
{addressRequest && <Alert tone="warning" title={phone ? "Address needed to send" : "Phone needed to send"} />}
|
|
128
|
+
<Grid min="120px" gap="3">
|
|
129
|
+
<TrackedField formName="update_patient_form" fieldName="phone" isOptional>
|
|
130
|
+
<Controller
|
|
131
|
+
control={control}
|
|
132
|
+
name="phone"
|
|
133
|
+
render={({ field, fieldState }) => (
|
|
134
|
+
<Input
|
|
135
|
+
label="Phone"
|
|
136
|
+
type="tel"
|
|
137
|
+
inputMode="tel"
|
|
138
|
+
name={field.name}
|
|
139
|
+
value={field.value}
|
|
140
|
+
onChange={field.onChange}
|
|
141
|
+
// Leaving the field shows the number formatted, e.g. "+1 (415) 555-0172".
|
|
142
|
+
onBlur={() => {
|
|
143
|
+
field.onChange(formatPhone(field.value));
|
|
144
|
+
field.onBlur();
|
|
145
|
+
}}
|
|
146
|
+
invalid={fieldState.invalid}
|
|
147
|
+
errorMessage={fieldState.error?.message}
|
|
148
|
+
{...noAutofill}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
/>
|
|
152
|
+
</TrackedField>
|
|
153
|
+
<TrackedField formName="update_patient_form" fieldName="email" isOptional>
|
|
154
|
+
<Controller
|
|
155
|
+
control={control}
|
|
156
|
+
name="email"
|
|
157
|
+
render={({ field, fieldState }) => (
|
|
158
|
+
<Input
|
|
159
|
+
label="Email"
|
|
160
|
+
type="email"
|
|
161
|
+
inputMode="email"
|
|
162
|
+
name={field.name}
|
|
163
|
+
value={field.value}
|
|
164
|
+
onChange={field.onChange}
|
|
165
|
+
onBlur={field.onBlur}
|
|
166
|
+
invalid={fieldState.invalid}
|
|
167
|
+
errorMessage={fieldState.error?.message}
|
|
168
|
+
{...noAutofill}
|
|
169
|
+
/>
|
|
170
|
+
)}
|
|
171
|
+
/>
|
|
172
|
+
</TrackedField>
|
|
173
|
+
</Grid>
|
|
174
|
+
<Stack gap="3">
|
|
175
|
+
<Grid min="120px" gap="3">
|
|
176
|
+
<TrackedField formName="update_patient_form" fieldName="address_street1" isOptional>
|
|
177
|
+
<Controller
|
|
178
|
+
control={control}
|
|
179
|
+
name="address.street1"
|
|
180
|
+
render={({ field, fieldState }) => (
|
|
181
|
+
<Input
|
|
182
|
+
label="Street"
|
|
183
|
+
name={field.name}
|
|
184
|
+
value={field.value}
|
|
185
|
+
onChange={field.onChange}
|
|
186
|
+
onBlur={field.onBlur}
|
|
187
|
+
invalid={fieldState.invalid}
|
|
188
|
+
errorMessage={fieldState.error?.message}
|
|
189
|
+
{...noAutofill}
|
|
190
|
+
/>
|
|
191
|
+
)}
|
|
192
|
+
/>
|
|
193
|
+
</TrackedField>
|
|
194
|
+
<TrackedField formName="update_patient_form" fieldName="address_street2" isOptional>
|
|
195
|
+
<Controller
|
|
196
|
+
control={control}
|
|
197
|
+
name="address.street2"
|
|
198
|
+
render={({ field, fieldState }) => (
|
|
199
|
+
<Input
|
|
200
|
+
label="Apt / suite"
|
|
201
|
+
name={field.name}
|
|
202
|
+
value={field.value}
|
|
203
|
+
onChange={field.onChange}
|
|
204
|
+
onBlur={field.onBlur}
|
|
205
|
+
invalid={fieldState.invalid}
|
|
206
|
+
errorMessage={fieldState.error?.message}
|
|
207
|
+
{...noAutofill}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
/>
|
|
211
|
+
</TrackedField>
|
|
212
|
+
</Grid>
|
|
213
|
+
<Grid min="120px" gap="3">
|
|
214
|
+
<TrackedField formName="update_patient_form" fieldName="address_city" isOptional>
|
|
215
|
+
<Controller
|
|
216
|
+
control={control}
|
|
217
|
+
name="address.city"
|
|
218
|
+
render={({ field, fieldState }) => (
|
|
219
|
+
<Input
|
|
220
|
+
label="City"
|
|
221
|
+
name={field.name}
|
|
222
|
+
value={field.value}
|
|
223
|
+
onChange={field.onChange}
|
|
224
|
+
onBlur={field.onBlur}
|
|
225
|
+
invalid={fieldState.invalid}
|
|
226
|
+
errorMessage={fieldState.error?.message}
|
|
227
|
+
{...noAutofill}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
</TrackedField>
|
|
232
|
+
<TrackedField formName="update_patient_form" fieldName="address_state" isOptional>
|
|
233
|
+
<Controller
|
|
234
|
+
control={control}
|
|
235
|
+
name="address.state"
|
|
236
|
+
render={({ field, fieldState }) => (
|
|
237
|
+
<Input
|
|
238
|
+
label="State"
|
|
239
|
+
maxLength={2}
|
|
240
|
+
name={field.name}
|
|
241
|
+
value={field.value}
|
|
242
|
+
onChange={field.onChange}
|
|
243
|
+
onBlur={field.onBlur}
|
|
244
|
+
invalid={fieldState.invalid}
|
|
245
|
+
errorMessage={fieldState.error?.message}
|
|
246
|
+
{...noAutofill}
|
|
247
|
+
/>
|
|
248
|
+
)}
|
|
249
|
+
/>
|
|
250
|
+
</TrackedField>
|
|
251
|
+
<TrackedField formName="update_patient_form" fieldName="address_zip" isOptional>
|
|
252
|
+
<Controller
|
|
253
|
+
control={control}
|
|
254
|
+
name="address.postalCode"
|
|
255
|
+
render={({ field, fieldState }) => (
|
|
256
|
+
<Input
|
|
257
|
+
label="ZIP"
|
|
258
|
+
inputMode="numeric"
|
|
259
|
+
name={field.name}
|
|
260
|
+
value={field.value}
|
|
261
|
+
onChange={field.onChange}
|
|
262
|
+
onBlur={field.onBlur}
|
|
263
|
+
invalid={fieldState.invalid}
|
|
264
|
+
errorMessage={fieldState.error?.message}
|
|
265
|
+
{...noAutofill}
|
|
266
|
+
/>
|
|
267
|
+
)}
|
|
268
|
+
/>
|
|
269
|
+
</TrackedField>
|
|
270
|
+
</Grid>
|
|
271
|
+
</Stack>
|
|
272
|
+
</Stack>
|
|
273
|
+
<Row justify="end">
|
|
274
|
+
{/* Save waits for onSave, so it's disabled (`loading`) while the update is in flight. */}
|
|
275
|
+
<Button
|
|
276
|
+
variant="secondary"
|
|
277
|
+
loading={isSubmitting}
|
|
278
|
+
onClick={handleSubmit((details) => onSave(toPatientInput(details)))}
|
|
279
|
+
>
|
|
280
|
+
Save
|
|
281
|
+
</Button>
|
|
282
|
+
</Row>
|
|
283
|
+
</>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function formValuesFrom(patient: PatientRecord): PatientDetailsFormValues {
|
|
288
|
+
const demographic = patient.demographic;
|
|
289
|
+
const address = patient.contact?.address;
|
|
290
|
+
return {
|
|
291
|
+
firstName: demographic?.name.first ?? "",
|
|
292
|
+
lastName: demographic?.name.last ?? "",
|
|
293
|
+
dateOfBirth: demographic?.dateOfBirth ?? "",
|
|
294
|
+
sex: demographic?.sex ?? null,
|
|
295
|
+
phone: formatPhone(patient.contact?.phone),
|
|
296
|
+
email: patient.contact?.email ?? "",
|
|
297
|
+
address: {
|
|
298
|
+
street1: address?.street1 ?? "",
|
|
299
|
+
street2: address?.street2 ?? "",
|
|
300
|
+
city: address?.city ?? "",
|
|
301
|
+
state: address?.state ?? "",
|
|
302
|
+
postalCode: address?.postalCode ?? "",
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function toPatientInput(details: PatientDetails): PatientDetailsInput {
|
|
308
|
+
return {
|
|
309
|
+
demographic: {
|
|
310
|
+
name: { first: details.firstName, last: details.lastName },
|
|
311
|
+
dateOfBirth: details.dateOfBirth,
|
|
312
|
+
sex: details.sex,
|
|
313
|
+
},
|
|
314
|
+
contact: {
|
|
315
|
+
phone: details.phone,
|
|
316
|
+
email: details.email,
|
|
317
|
+
...(details.address && { address: details.address }),
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|