@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,204 @@
|
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { ambiguous, change, fakeNetworkApiClient, noMatch, payload, photonOver } from "@photonhealth/client/testing";
|
|
5
|
+
import { PatientSearch } from "./PatientSearch.tsx";
|
|
6
|
+
import { patient, withPhoton } from "../../../test/cards.fixtures.tsx";
|
|
7
|
+
|
|
8
|
+
// PatientSearch's own logic: what triggers a search, what the results show, and what choosing does. How the list
|
|
9
|
+
// renders and moves under the keys is SearchResults'; how the server's messages render is ChangeList's.
|
|
10
|
+
|
|
11
|
+
type NetworkScript = Parameters<typeof fakeNetworkApiClient>[0];
|
|
12
|
+
type Candidate = Parameters<typeof ambiguous>[0][number];
|
|
13
|
+
|
|
14
|
+
/** A patient a search can return: Ada Lovelace (pat_1), with any fields overridden. */
|
|
15
|
+
const fakeCandidate = (overrides: Partial<Candidate> = {}): Candidate => ({
|
|
16
|
+
id: "pat_1",
|
|
17
|
+
firstName: "Ada",
|
|
18
|
+
lastName: "Lovelace",
|
|
19
|
+
dateOfBirth: "1990-01-01",
|
|
20
|
+
...overrides,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A network-api whose patient search returns `matchesByName`: the candidates for the first or last name searched for
|
|
25
|
+
* (nobody, when a name isn't there). Picking a candidate reads Ada.
|
|
26
|
+
*/
|
|
27
|
+
const fakeServer = (matchesByName: Record<string, Candidate[]> = {}, script: NetworkScript = {}) =>
|
|
28
|
+
fakeNetworkApiClient({
|
|
29
|
+
SyncPatient: (vars: { demographic?: { name?: { first?: string; last?: string } } }) => {
|
|
30
|
+
const name = vars.demographic?.name;
|
|
31
|
+
const found = matchesByName[name?.first ?? name?.last ?? ""];
|
|
32
|
+
return found ? ambiguous(found) : noMatch();
|
|
33
|
+
},
|
|
34
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
35
|
+
...script,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const renderPatientSearch = ({
|
|
39
|
+
matchesByName,
|
|
40
|
+
script,
|
|
41
|
+
notice,
|
|
42
|
+
}: {
|
|
43
|
+
matchesByName?: Record<string, Candidate[]>;
|
|
44
|
+
script?: NetworkScript;
|
|
45
|
+
notice?: { title: string; description: string };
|
|
46
|
+
} = {}) => {
|
|
47
|
+
const { client } = fakeServer(matchesByName, script);
|
|
48
|
+
const live = photonOver(client).patient();
|
|
49
|
+
const onAddNew = vi.fn();
|
|
50
|
+
const user = userEvent.setup();
|
|
51
|
+
render(<PatientSearch patient={live} notice={notice} onAddNew={onAddNew} />, { wrapper: withPhoton(client) });
|
|
52
|
+
return { live, onAddNew, user, field: screen.getByLabelText("Find patient") };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The search results: named "Matching patients" or "No matching patients". */
|
|
56
|
+
const SEARCH_RESULTS = /^(Matching|No matching) patients$/;
|
|
57
|
+
const findSearchResults = (name: string | RegExp = SEARCH_RESULTS) => screen.findByRole("listbox", { name });
|
|
58
|
+
const querySearchResults = () => screen.queryByRole("listbox", { name: SEARCH_RESULTS });
|
|
59
|
+
|
|
60
|
+
/** Longer than the type-ahead's pause: time for a search request to be sent and its response to come back. */
|
|
61
|
+
const pause = () => new Promise((done) => setTimeout(done, 500));
|
|
62
|
+
|
|
63
|
+
describe("PatientSearch", () => {
|
|
64
|
+
describe("searching", () => {
|
|
65
|
+
it("before anything is typed: no results", () => {
|
|
66
|
+
renderPatientSearch();
|
|
67
|
+
expect(querySearchResults()).not.toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("two or more characters typed: searches once typing pauses, and shows the results", async () => {
|
|
71
|
+
const { user, field } = renderPatientSearch({ matchesByName: { Ada: [fakeCandidate()] } });
|
|
72
|
+
await user.type(field, "Ada");
|
|
73
|
+
expect(await findSearchResults("Matching patients")).toBeInTheDocument();
|
|
74
|
+
expect(screen.getByText("Ada Lovelace")).toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("one character typed: doesn't search while typing", async () => {
|
|
78
|
+
const { user, field } = renderPatientSearch({ matchesByName: { A: [fakeCandidate()] } });
|
|
79
|
+
await user.type(field, "A");
|
|
80
|
+
await pause();
|
|
81
|
+
expect(querySearchResults()).not.toBeInTheDocument();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("one character, then Return: searches it now", async () => {
|
|
85
|
+
const { user, field } = renderPatientSearch({ matchesByName: { A: [fakeCandidate()] } });
|
|
86
|
+
await user.type(field, "A{Enter}");
|
|
87
|
+
expect(await screen.findByText("Ada Lovelace")).toBeInTheDocument();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("one character, then leaving the field: searches it now", async () => {
|
|
91
|
+
const { user, field } = renderPatientSearch({ matchesByName: { A: [fakeCandidate()] } });
|
|
92
|
+
await user.type(field, "A");
|
|
93
|
+
await user.tab();
|
|
94
|
+
expect(await screen.findByText("Ada Lovelace")).toBeInTheDocument();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("two characters, then Backspace both: shows the results, then removes them", async () => {
|
|
98
|
+
const { user, field } = renderPatientSearch({ matchesByName: { Ada: [fakeCandidate()] } });
|
|
99
|
+
await user.type(field, "Ada");
|
|
100
|
+
await findSearchResults();
|
|
101
|
+
await user.type(field, "{Backspace}{Backspace}");
|
|
102
|
+
expect(querySearchResults()).not.toBeInTheDocument();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("one word that matches no first name: searched again as a last name", async () => {
|
|
106
|
+
// network-api matches first and last names separately: Lovelace is only ever a last name here.
|
|
107
|
+
const { user, field } = renderPatientSearch({
|
|
108
|
+
script: {
|
|
109
|
+
SyncPatient: (vars: { demographic?: { name?: { last?: string } } }) =>
|
|
110
|
+
vars.demographic?.name?.last === "Lovelace" ? ambiguous([fakeCandidate()]) : noMatch(),
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
await user.type(field, "Lovelace");
|
|
114
|
+
expect(await screen.findByText("Ada Lovelace")).toBeInTheDocument();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("displaying results", () => {
|
|
119
|
+
it("no results: displays no results, warns that that spelling has to be exact, and offers Add new patient", async () => {
|
|
120
|
+
const { user, field } = renderPatientSearch();
|
|
121
|
+
await user.type(field, "Zqx");
|
|
122
|
+
expect(await findSearchResults("No matching patients")).toBeInTheDocument();
|
|
123
|
+
expect(screen.getByText("Spelling has to be exact.")).toBeInTheDocument();
|
|
124
|
+
expect(screen.getByText("Add new patient")).toBeInTheDocument();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("fewer than 5 results: the first is highlighted, the cursor stays in the field, and offers Add new patient", async () => {
|
|
128
|
+
const { user, field } = renderPatientSearch({
|
|
129
|
+
matchesByName: { Ada: [fakeCandidate(), fakeCandidate({ id: "pat_2", lastName: "Lovelace2" })] },
|
|
130
|
+
});
|
|
131
|
+
await user.type(field, "Ada");
|
|
132
|
+
await waitFor(() => expect(field).toHaveAttribute("aria-activedescendant"));
|
|
133
|
+
expect(field).toHaveFocus();
|
|
134
|
+
expect(screen.getByText("Add new patient")).toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("5 or more results: nothing is highlighted, and offers Add new patient", async () => {
|
|
138
|
+
const { user, field } = renderPatientSearch({
|
|
139
|
+
matchesByName: { Ada: [1, 2, 3, 4, 5].map((n) => fakeCandidate({ id: `pat_${n}`, lastName: `Lovelace${n}` })) },
|
|
140
|
+
});
|
|
141
|
+
await user.type(field, "Ada");
|
|
142
|
+
await findSearchResults();
|
|
143
|
+
await pause();
|
|
144
|
+
expect(field).not.toHaveAttribute("aria-activedescendant");
|
|
145
|
+
expect(screen.getByText("Add new patient")).toBeInTheDocument();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("a search that fails: says why", async () => {
|
|
149
|
+
const { user, field } = renderPatientSearch({
|
|
150
|
+
script: {
|
|
151
|
+
SyncPatient: () => {
|
|
152
|
+
throw new Error("network-api is down");
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
await user.type(field, "Ada");
|
|
157
|
+
expect(await screen.findByText("network-api is down")).toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// TODO: Leaving this test in to document the weird behavior around displaying PatientSearch or PatientIntakeForm
|
|
161
|
+
// depending on initial input to PatientCard
|
|
162
|
+
// We should replace it with a test that confirms we don't show any weird server messages
|
|
163
|
+
it("the server's messages: shown, except that name, date of birth or sex are still needed", async () => {
|
|
164
|
+
const needs = (key: string, reason: string) =>
|
|
165
|
+
change({ key, label: key, status: "REJECTED", severity: "BLOCKING", reason });
|
|
166
|
+
const { client } = fakeServer(
|
|
167
|
+
{},
|
|
168
|
+
{
|
|
169
|
+
SyncPatient: () =>
|
|
170
|
+
payload("patient", "PatientPayload", null, {
|
|
171
|
+
changes: [
|
|
172
|
+
needs("demographic.dateOfBirth", "Date of birth is needed"),
|
|
173
|
+
needs("contact.phone", "Phone isn't valid"),
|
|
174
|
+
],
|
|
175
|
+
}),
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
// A patient the server has already said this about (e.g. details a host passed).
|
|
179
|
+
const live = photonOver(client).patient();
|
|
180
|
+
await live.sync({ contact: { phone: "1" } }).catch(() => {});
|
|
181
|
+
render(<PatientSearch patient={live} onAddNew={vi.fn()} />, { wrapper: withPhoton(client) });
|
|
182
|
+
expect(await screen.findByText(/Phone isn't valid/)).toBeInTheDocument();
|
|
183
|
+
expect(screen.queryByText(/Date of birth is needed/)).not.toBeInTheDocument();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("choosing", () => {
|
|
188
|
+
// TODO: pins behavior, want to replace this with something else
|
|
189
|
+
// once we remove the client from the react components
|
|
190
|
+
it("a result: the patient becomes that one", async () => {
|
|
191
|
+
const { user, field, live } = renderPatientSearch({ matchesByName: { Ada: [fakeCandidate()] } });
|
|
192
|
+
await user.type(field, "Ada");
|
|
193
|
+
await user.click(await screen.findByText("Ada Lovelace"));
|
|
194
|
+
await waitFor(() => expect(live.id).toBe("pat_1"));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("Add new patient: hands over what was typed", async () => {
|
|
198
|
+
const { user, field, onAddNew } = renderPatientSearch();
|
|
199
|
+
await user.type(field, "Grace Hopper");
|
|
200
|
+
await user.click(await screen.findByText("Add new patient"));
|
|
201
|
+
expect(onAddNew).toHaveBeenCalledWith("Grace Hopper");
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/** PhotonPatient before a record, finding them: one field that searches as it's typed in, and who they might be. */
|
|
2
|
+
import { useComponents } from "../../primitives/index.ts";
|
|
3
|
+
import { classify, type Patient } from "@photonhealth/client";
|
|
4
|
+
import { useLatestCallback, useLive } from "../../hooks/index.ts";
|
|
5
|
+
import { useEffect, useRef, useState, type KeyboardEvent } from "react";
|
|
6
|
+
import { useHeldActivity } from "../activity.ts";
|
|
7
|
+
import { ChangeList } from "../ChangeList.tsx";
|
|
8
|
+
import { formatDate } from "../format.ts";
|
|
9
|
+
import { FEW, searchKeys, SearchResults, useTypeAhead, type SearchHandle } from "../search.tsx";
|
|
10
|
+
import { focusProps, searchProps } from "../flow.ts";
|
|
11
|
+
import { IDENTITY_KEYS, noAutofill } from "./fields.tsx";
|
|
12
|
+
import { parsePatientSearchQuery, type ParsedPatientSearchQuery } from "./parsePatientSearchQuery.ts";
|
|
13
|
+
import { TrackedField } from "../../analytics/fieldInteraction.tsx";
|
|
14
|
+
|
|
15
|
+
/** query as patient input */
|
|
16
|
+
const toSearchInput = ({ phone, email, ...demographic }: ParsedPatientSearchQuery) => ({
|
|
17
|
+
demographic,
|
|
18
|
+
contact: { ...(phone ? { phone } : {}), ...(email ? { email } : {}) },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** Whether a query says anything the server can match on. */
|
|
22
|
+
const isSearchable = (q: ParsedPatientSearchQuery) =>
|
|
23
|
+
Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
|
|
27
|
+
* as a last name — "Lovelace" is as likely as "Ada".
|
|
28
|
+
*/
|
|
29
|
+
const searchBoth = (q: ParsedPatientSearchQuery): ParsedPatientSearchQuery | null =>
|
|
30
|
+
q.name?.first && !q.name.last && !q.dateOfBirth && !q.phone && !q.email ? { name: { last: q.name.first } } : null;
|
|
31
|
+
|
|
32
|
+
export function PatientSearch({
|
|
33
|
+
patient,
|
|
34
|
+
notice,
|
|
35
|
+
onAddNew,
|
|
36
|
+
}: {
|
|
37
|
+
patient: Patient;
|
|
38
|
+
/** Why someone else is being found (e.g. the patient given by id isn't there): shown with the matches. */
|
|
39
|
+
notice?: { title: string; description: string } | null;
|
|
40
|
+
/** "Add new patient": none of these. Gets what was typed, to fill PatientIntakeForm from. */
|
|
41
|
+
onAddNew: (query: string) => void;
|
|
42
|
+
}) {
|
|
43
|
+
const { Alert, Badge, Card, CardBody, CardHeader, Input, Stack } = useComponents();
|
|
44
|
+
const snap = useLive(patient)!;
|
|
45
|
+
const [query, setQuery] = useState("");
|
|
46
|
+
/** What the matches below answer — the query as it was typed when the search went out. */
|
|
47
|
+
const [searched, setSearched] = useState<string | null>(null);
|
|
48
|
+
/** The row the keys are on, by DOM id: the field says so with `aria-activedescendant`. */
|
|
49
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
|
50
|
+
const busy = snap.status === "loading" || snap.status === "saving";
|
|
51
|
+
const candidates = snap.candidates;
|
|
52
|
+
// What the server says. While searching, nothing about the patient's name, date of birth or sex is missing yet:
|
|
53
|
+
// the search only lists who it might be.
|
|
54
|
+
const changes = classify({
|
|
55
|
+
...snap.changes,
|
|
56
|
+
unapplied: snap.changes.unapplied.filter((c) => !IDENTITY_KEYS.includes(c.key)),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// The field shows a spinner while its search is out (held briefly, so it doesn't flicker).
|
|
60
|
+
const [searching, setSearching] = useState(false);
|
|
61
|
+
if (searching && !busy) setSearching(false); // answered
|
|
62
|
+
const spinning = useHeldActivity(searching ? "query" : null) === "query";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The search, answered. Only ever `search`: it can't create, and it can't change whoever it finds. One word
|
|
66
|
+
* could be either name, so if it draws a blank as a first name it's asked again as a last name — "Lovelace"
|
|
67
|
+
* is as likely to be typed as "Ada".
|
|
68
|
+
*/
|
|
69
|
+
const runSearch = useLatestCallback(() => {
|
|
70
|
+
const text = query.trim();
|
|
71
|
+
const parsed = parsePatientSearchQuery(text);
|
|
72
|
+
if (!isSearchable(parsed)) return;
|
|
73
|
+
setSearching(true);
|
|
74
|
+
void (async () => {
|
|
75
|
+
try {
|
|
76
|
+
await patient.search(toSearchInput(parsed));
|
|
77
|
+
const alsoLast = searchBoth(parsed);
|
|
78
|
+
if (alsoLast && patient.snapshot.candidates.length === 0) await patient.search(toSearchInput(alsoLast));
|
|
79
|
+
} catch {
|
|
80
|
+
// failures land on the object
|
|
81
|
+
}
|
|
82
|
+
setSearched(text);
|
|
83
|
+
})();
|
|
84
|
+
});
|
|
85
|
+
// Two characters: network-api matches "a first/last name prefix of 2+ characters" (`AmbiguousPatientMatch`),
|
|
86
|
+
// and short surnames are real — Ng, Wu, Li. Not one: that would match thousands, and the server returns at
|
|
87
|
+
// most twenty candidates, so it would hand back an arbitrary slice — a list without your patient in it reads
|
|
88
|
+
// as "not here", which is how a duplicate gets made.
|
|
89
|
+
const typeAhead = useTypeAhead<"query">(() => runSearch(), { minChars: 2 });
|
|
90
|
+
|
|
91
|
+
// A few matches listed: they're the next thing to look at.
|
|
92
|
+
const few = candidates.length > 0 && candidates.length < FEW;
|
|
93
|
+
const answered = () => !typeAhead.waiting() && !busy && searched === query.trim();
|
|
94
|
+
/** The search is answered, and nobody came back. Not the same as nobody being there. */
|
|
95
|
+
const answeredNothing =
|
|
96
|
+
searched !== null && searched === query.trim() && candidates.length === 0 && !busy && !typeAhead.waiting();
|
|
97
|
+
const matches = useRef<SearchHandle | null>(null);
|
|
98
|
+
// The search field: Esc in the matches goes back to it.
|
|
99
|
+
const field = useRef<HTMLInputElement | null>(null);
|
|
100
|
+
|
|
101
|
+
// The field is a search field over the matches (searchKeys): ↑ ↓ move a highlight, Return takes it. Return
|
|
102
|
+
// with nothing to take searches now, rather than after the pause.
|
|
103
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
104
|
+
if (searchKeys(e, matches.current, answered())) return;
|
|
105
|
+
if (e.key !== "Enter") return;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
typeAhead.cancel();
|
|
108
|
+
runSearch();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// A few matches for what's being typed, and the prescriber is still in the field: focus goes to the first,
|
|
112
|
+
// ready to pick — typing carries on in the field (search.tsx). Once per answer.
|
|
113
|
+
const matchesFor = candidates.map((c) => c.id).join();
|
|
114
|
+
const focusedFor = useRef<string | null>(null);
|
|
115
|
+
const focusFew = useLatestCallback(() => {
|
|
116
|
+
if (!few || !answered() || !field.current || document.activeElement !== field.current) return;
|
|
117
|
+
if (focusedFor.current === matchesFor) return;
|
|
118
|
+
focusedFor.current = matchesFor;
|
|
119
|
+
matches.current?.focus(true);
|
|
120
|
+
});
|
|
121
|
+
// Also on `searched`: the matches can land before the card has noted which query they answer, and until
|
|
122
|
+
// it has, they aren't an answer to move to.
|
|
123
|
+
useEffect(() => focusFew(), [matchesFor, busy, searched, focusFew]);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<Card divided>
|
|
127
|
+
<CardHeader title="Patient" />
|
|
128
|
+
<CardBody>
|
|
129
|
+
<Stack gap="3">
|
|
130
|
+
<div
|
|
131
|
+
{...focusProps}
|
|
132
|
+
{...searchProps}
|
|
133
|
+
onFocus={(e) => {
|
|
134
|
+
if (e.target instanceof HTMLInputElement) field.current = e.target;
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<TrackedField formName="find_patient" fieldName="patientSearch" isOptional={false}>
|
|
138
|
+
<Input
|
|
139
|
+
label="Find patient"
|
|
140
|
+
placeholder="Name, date of birth, phone or email"
|
|
141
|
+
value={query}
|
|
142
|
+
onChange={(e) => {
|
|
143
|
+
setQuery(e.target.value);
|
|
144
|
+
typeAhead.typed("query", e.target.value);
|
|
145
|
+
// Too little left to search on: the matches on screen answer a query that isn't there any more,
|
|
146
|
+
// so they go, and the card is back where it started — including what it has already moved the
|
|
147
|
+
// cursor to, or typing the same name again would land nowhere.
|
|
148
|
+
if (typeAhead.tooShort(e.target.value)) {
|
|
149
|
+
setSearched(null);
|
|
150
|
+
focusedFor.current = null;
|
|
151
|
+
}
|
|
152
|
+
}}
|
|
153
|
+
onBlur={() => {
|
|
154
|
+
// Leaving asks now rather than after the pause — a search, never a sync: it can't create anyone
|
|
155
|
+
// and it can't change whoever it finds.
|
|
156
|
+
typeAhead.cancel();
|
|
157
|
+
if (query.trim() !== searched) runSearch();
|
|
158
|
+
}}
|
|
159
|
+
onKeyDown={onKeyDown}
|
|
160
|
+
loading={spinning}
|
|
161
|
+
role="combobox"
|
|
162
|
+
aria-expanded={searched !== null}
|
|
163
|
+
aria-autocomplete="list"
|
|
164
|
+
aria-activedescendant={activeId ?? undefined}
|
|
165
|
+
autoFocus
|
|
166
|
+
{...noAutofill}
|
|
167
|
+
/>
|
|
168
|
+
</TrackedField>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{/* Nothing came back. That the list is empty needs no saying — the prescriber can see it. What they can't
|
|
172
|
+
see is that matching has no tolerance for a typo, so an empty list is not "they aren't here", and adding
|
|
173
|
+
someone already on file is how a duplicate is made. This stands in for a gap: network-api doesn't match
|
|
174
|
+
names fuzzily yet, and when it does an empty list means what it looks like and these words should go. */}
|
|
175
|
+
{answeredNothing && (
|
|
176
|
+
<Alert
|
|
177
|
+
title="Spelling has to be exact."
|
|
178
|
+
description="Try another spelling, fewer letters, or a date of birth."
|
|
179
|
+
/>
|
|
180
|
+
)}
|
|
181
|
+
|
|
182
|
+
{/* Never disabled while a search runs: typing searches, and Tab may have just put focus here. Shown for
|
|
183
|
+
every answered search: with nobody matching, "Add new patient" is the only row — still a row, still
|
|
184
|
+
reached by ↓ from the field, still taken with Return. */}
|
|
185
|
+
{searched !== null && (
|
|
186
|
+
<SearchResults
|
|
187
|
+
label={candidates.length > 0 ? "Matching patients" : "No matching patients"}
|
|
188
|
+
results={candidates.map((m) => ({
|
|
189
|
+
key: m.id,
|
|
190
|
+
label: [m.firstName, m.lastName].filter(Boolean).join(" "),
|
|
191
|
+
meta: m.dateOfBirth ? formatDate(m.dateOfBirth) : undefined,
|
|
192
|
+
}))}
|
|
193
|
+
onPick={(id) => void patient.pick(id).catch(() => {})}
|
|
194
|
+
busy={busy}
|
|
195
|
+
handleRef={matches}
|
|
196
|
+
onBack={() => field.current?.focus()}
|
|
197
|
+
// The cursor stays in the field: ↑ ↓ move a highlight, Return takes it, and a letter or a Backspace
|
|
198
|
+
// always lands in the field — the prescriber can narrow or start over mid-list.
|
|
199
|
+
inField
|
|
200
|
+
onActive={setActiveId}
|
|
201
|
+
// The last row: ↓ past the final match lands on it, and Return takes it.
|
|
202
|
+
action={{
|
|
203
|
+
label: "Add new patient",
|
|
204
|
+
icon: "add",
|
|
205
|
+
onChoose: () => {
|
|
206
|
+
typeAhead.cancel();
|
|
207
|
+
onAddNew(query);
|
|
208
|
+
},
|
|
209
|
+
}}
|
|
210
|
+
/>
|
|
211
|
+
)}
|
|
212
|
+
|
|
213
|
+
{/* With the matches: why someone else is being found, what the server said, and what failed. */}
|
|
214
|
+
{notice && <Alert tone="critical" title={notice.title} description={notice.description} />}
|
|
215
|
+
<ChangeList changes={changes} />
|
|
216
|
+
{snap.error && <Badge tone="critical">{snap.error.message}</Badge>}
|
|
217
|
+
</Stack>
|
|
218
|
+
</CardBody>
|
|
219
|
+
</Card>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { BenefitsInputForm } from "./BenefitsInputForm.tsx";
|
|
5
|
+
|
|
6
|
+
type Props = Parameters<typeof BenefitsInputForm>[0];
|
|
7
|
+
|
|
8
|
+
const plan = { id: "ben_1", bin: "610014", pcn: "PCN1", groupId: "GRP1", memberId: "M123" };
|
|
9
|
+
|
|
10
|
+
const renderForm = (overrides: Partial<Props> = {}) => {
|
|
11
|
+
const props: Props = {
|
|
12
|
+
benefits: null,
|
|
13
|
+
saving: false,
|
|
14
|
+
onAdd: vi.fn(),
|
|
15
|
+
onRemove: vi.fn(),
|
|
16
|
+
onNone: vi.fn(),
|
|
17
|
+
...overrides,
|
|
18
|
+
};
|
|
19
|
+
const user = userEvent.setup();
|
|
20
|
+
render(<BenefitsInputForm {...props} />);
|
|
21
|
+
return { user, props };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const button = (name: string) => screen.queryByRole("button", { name });
|
|
25
|
+
const field = (label: string) => screen.getByLabelText(label);
|
|
26
|
+
|
|
27
|
+
describe("BenefitsInputForm", () => {
|
|
28
|
+
describe("insurance on file", () => {
|
|
29
|
+
// Pins today's behavior
|
|
30
|
+
// Question: what do we think about this display?
|
|
31
|
+
it('plan with every field: shows a chip "BIN <bin> · PCN <pcn> · Group <group> · Member <member id>"', () => {
|
|
32
|
+
renderForm({ benefits: [plan] });
|
|
33
|
+
expect(screen.getByText("BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("plan without a PCN or group: leaves them out of the chip", () => {
|
|
37
|
+
renderForm({ benefits: [{ ...plan, pcn: null, groupId: null }] });
|
|
38
|
+
expect(screen.getByText("BIN 610014 · Member M123")).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("several plans: shows a chip for each plan", () => {
|
|
42
|
+
renderForm({ benefits: [plan, { ...plan, id: "ben_2", bin: "004336", memberId: "M456" }] });
|
|
43
|
+
expect(screen.getByText("BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")).toBeInTheDocument();
|
|
44
|
+
expect(screen.getByText("BIN 004336 · PCN PCN1 · Group GRP1 · Member M456")).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("clicking a plan's remove button: calls onRemove with that plan", async () => {
|
|
48
|
+
const { user, props } = renderForm({ benefits: [plan] });
|
|
49
|
+
await user.click(button("Remove BIN 610014 · PCN PCN1 · Group GRP1 · Member M123")!);
|
|
50
|
+
expect(props.onRemove).toHaveBeenCalledExactlyOnceWith(plan);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("none", () => {
|
|
55
|
+
it('insurance not recorded: shows "Not recorded" and the "Mark no insurance" button', () => {
|
|
56
|
+
renderForm({ benefits: null });
|
|
57
|
+
expect(screen.getByText("Not recorded")).toBeInTheDocument();
|
|
58
|
+
expect(button("Mark no insurance")).toHaveTextContent("Mark none");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('clicking "Mark no insurance": calls onNone', async () => {
|
|
62
|
+
const { user, props } = renderForm({ benefits: null });
|
|
63
|
+
await user.click(button("Mark no insurance")!);
|
|
64
|
+
expect(props.onNone).toHaveBeenCalledOnce();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('no insurance recorded: shows "No insurance" instead of "Not recorded" and the none button', () => {
|
|
68
|
+
renderForm({ benefits: [] });
|
|
69
|
+
expect(screen.getByText("No insurance")).toBeInTheDocument();
|
|
70
|
+
expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
|
|
71
|
+
expect(button("Mark no insurance")).not.toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('plans on file: shows no "Not recorded" and no none button', () => {
|
|
75
|
+
renderForm({ benefits: [plan] });
|
|
76
|
+
expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
|
|
77
|
+
expect(button("Mark no insurance")).not.toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("adding a plan", () => {
|
|
82
|
+
it('clicking "Add insurance": opens the form with the cursor in BIN, in place of the add button', async () => {
|
|
83
|
+
const { user } = renderForm();
|
|
84
|
+
await user.click(button("Add insurance")!);
|
|
85
|
+
expect(field("BIN")).toHaveFocus();
|
|
86
|
+
expect(button("Add insurance")).not.toBeInTheDocument();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('form open: hides "Not recorded" and the none button', async () => {
|
|
90
|
+
const { user } = renderForm();
|
|
91
|
+
await user.click(button("Add insurance")!);
|
|
92
|
+
expect(screen.queryByText("Not recorded")).not.toBeInTheDocument();
|
|
93
|
+
expect(button("Mark no insurance")).not.toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('BIN or member ID empty, or only spaces: "Save insurance" is disabled', async () => {
|
|
97
|
+
const { user } = renderForm();
|
|
98
|
+
await user.click(button("Add insurance")!);
|
|
99
|
+
expect(button("Save insurance")).toBeDisabled();
|
|
100
|
+
await user.type(field("BIN"), "610014");
|
|
101
|
+
expect(button("Save insurance")).toBeDisabled();
|
|
102
|
+
await user.type(field("Member ID"), " ");
|
|
103
|
+
expect(button("Save insurance")).toBeDisabled();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('BIN and member ID filled in, then "Save insurance": calls onAdd with them trimmed, without PCN or group', async () => {
|
|
107
|
+
const { user, props } = renderForm();
|
|
108
|
+
await user.click(button("Add insurance")!);
|
|
109
|
+
await user.type(field("BIN"), " 610014 ");
|
|
110
|
+
await user.type(field("Member ID"), " M123 ");
|
|
111
|
+
await user.click(button("Save insurance")!);
|
|
112
|
+
expect(props.onAdd).toHaveBeenCalledExactlyOnceWith({
|
|
113
|
+
bin: "610014",
|
|
114
|
+
memberId: "M123",
|
|
115
|
+
pcn: undefined,
|
|
116
|
+
groupId: undefined,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("every field filled in: calls onAdd with the PCN and group too", async () => {
|
|
121
|
+
const { user, props } = renderForm();
|
|
122
|
+
await user.click(button("Add insurance")!);
|
|
123
|
+
await user.type(field("BIN"), "610014");
|
|
124
|
+
await user.type(field("PCN"), "PCN1");
|
|
125
|
+
await user.type(field("Group"), "GRP1");
|
|
126
|
+
await user.type(field("Member ID"), "M123");
|
|
127
|
+
await user.click(button("Save insurance")!);
|
|
128
|
+
expect(props.onAdd).toHaveBeenCalledExactlyOnceWith({
|
|
129
|
+
bin: "610014",
|
|
130
|
+
memberId: "M123",
|
|
131
|
+
pcn: "PCN1",
|
|
132
|
+
groupId: "GRP1",
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("Enter in any field, with BIN and member ID filled in: calls onAdd", async () => {
|
|
137
|
+
const { user, props } = renderForm();
|
|
138
|
+
await user.click(button("Add insurance")!);
|
|
139
|
+
await user.type(field("BIN"), "610014");
|
|
140
|
+
await user.type(field("Member ID"), "M123");
|
|
141
|
+
await user.type(field("PCN"), "{Enter}");
|
|
142
|
+
expect(props.onAdd).toHaveBeenCalledOnce();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("Enter with member ID empty: doesn't call onAdd, and the form stays open", async () => {
|
|
146
|
+
const { user, props } = renderForm();
|
|
147
|
+
await user.click(button("Add insurance")!);
|
|
148
|
+
await user.type(field("BIN"), "610014{Enter}");
|
|
149
|
+
expect(props.onAdd).not.toHaveBeenCalled();
|
|
150
|
+
expect(field("BIN")).toHaveValue("610014");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("Cancel: closes the form without calling onAdd, and the form renders with fields cleared the next time it is opened", async () => {
|
|
154
|
+
const { user, props } = renderForm();
|
|
155
|
+
await user.click(button("Add insurance")!);
|
|
156
|
+
await user.type(field("BIN"), "610014");
|
|
157
|
+
await user.click(button("Cancel")!);
|
|
158
|
+
expect(props.onAdd).not.toHaveBeenCalled();
|
|
159
|
+
expect(screen.queryByLabelText("BIN")).not.toBeInTheDocument();
|
|
160
|
+
await user.click(button("Add insurance")!);
|
|
161
|
+
expect(field("BIN")).toHaveValue("");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** The patient's insurance on file. */
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
import { useComponents } from "
|
|
4
|
-
import { noAutofill } from "
|
|
5
|
-
import { TrackedField } from "
|
|
3
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
4
|
+
import { noAutofill } from "../fields.tsx";
|
|
5
|
+
import { TrackedField } from "../../../analytics/fieldInteraction.tsx";
|
|
6
6
|
|
|
7
7
|
export type BenefitInput = { id?: string; bin?: string; pcn?: string; groupId?: string; memberId?: string };
|
|
8
8
|
|
|
9
9
|
/** Insurance on file: chips, "Add insurance" (BIN + member id required, PCN / group optional), "No insurance". */
|
|
10
|
-
export function
|
|
10
|
+
export function BenefitsInputForm({
|
|
11
11
|
benefits,
|
|
12
12
|
saving,
|
|
13
13
|
onAdd,
|