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