@photonhealth/react 2.0.0-rc.1 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -8
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -4
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +20 -16
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +4 -2
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +1 -12
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +7 -360
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/format.d.ts +2 -2
- package/dist/components/format.js +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -1
- package/dist/components/patient/Benefits.js +2 -1
- package/dist/components/patient/Benefits.js.map +1 -1
- package/dist/components/patient/Clinical.d.ts +3 -2
- package/dist/components/patient/Clinical.d.ts.map +1 -1
- package/dist/components/patient/Clinical.js +21 -20
- package/dist/components/patient/Clinical.js.map +1 -1
- package/dist/components/patient/IntakeForm.d.ts.map +1 -1
- package/dist/components/patient/IntakeForm.js +52 -43
- package/dist/components/patient/IntakeForm.js.map +1 -1
- package/dist/components/patient/Summary.d.ts +1 -1
- package/dist/components/patient/Summary.d.ts.map +1 -1
- package/dist/components/patient/Summary.js +13 -3
- package/dist/components/patient/Summary.js.map +1 -1
- package/dist/components/patient/fields.d.ts +1 -2
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +2 -1
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/query.d.ts +14 -0
- package/dist/components/patient/query.d.ts.map +1 -1
- package/dist/components/patient/query.js +5 -0
- package/dist/components/patient/query.js.map +1 -1
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +3 -1
- package/dist/primitives/PhotonProvider.d.ts.map +1 -1
- package/dist/primitives/PhotonProvider.js +23 -11
- package/dist/primitives/PhotonProvider.js.map +1 -1
- package/dist/primitives/defaults.d.ts.map +1 -1
- package/dist/primitives/defaults.js +6 -3
- package/dist/primitives/defaults.js.map +1 -1
- package/dist/primitives/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.js.map +1 -0
- package/dist/primitives/types.d.ts +15 -3
- package/dist/primitives/types.d.ts.map +1 -1
- package/dist/primitives/types.js.map +1 -1
- package/dist/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +45 -3
- package/dist/test-utils/contract.d.ts.map +1 -1
- package/dist/test-utils/contract.js +23 -2
- package/dist/test-utils/contract.js.map +1 -1
- package/package.json +5 -3
- package/src/adapters/tailwind.tsx +52 -24
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +45 -30
- package/src/components/PhotonPatient.tsx +11 -7
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +10 -570
- package/src/components/format.ts +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +21 -13
- package/src/components/patient/Clinical.tsx +31 -26
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +168 -136
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +54 -34
- package/src/components/patient/fields.tsx +52 -38
- package/src/components/patient/query.ts +6 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -0
- package/src/index.ts +2 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +30 -15
- package/src/primitives/defaults.tsx +44 -21
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/types.ts +15 -3
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +45 -3
- package/src/test-utils/contract.tsx +45 -2
- package/dist/components/TreatmentPicker.d.ts +0 -45
- package/dist/components/TreatmentPicker.d.ts.map +0 -1
- package/dist/components/TreatmentPicker.js.map +0 -1
- package/src/components/TreatmentPicker.tsx +0 -350
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
change,
|
|
6
|
+
fakeNetworkApiClient,
|
|
7
|
+
listedOrder,
|
|
8
|
+
orders,
|
|
9
|
+
payload,
|
|
10
|
+
rx,
|
|
11
|
+
treatment,
|
|
12
|
+
} from "@photonhealth/client/testing";
|
|
13
|
+
import { PhotonOrder, type PhotonOrderProps } from "../index.ts";
|
|
14
|
+
import {
|
|
15
|
+
choices,
|
|
16
|
+
draftOrder,
|
|
17
|
+
option,
|
|
18
|
+
order,
|
|
19
|
+
patient,
|
|
20
|
+
pickDrug,
|
|
21
|
+
typeIdentity,
|
|
22
|
+
withPhoton,
|
|
23
|
+
} from "../../test/cards.fixtures.tsx";
|
|
24
|
+
|
|
25
|
+
// The order around its prescriptions: Send, Remove, and a line searched before the order has a patient.
|
|
26
|
+
|
|
27
|
+
afterEach(cleanup);
|
|
28
|
+
|
|
29
|
+
const lisinoprilTablets10And20Mg = choices(
|
|
30
|
+
option("Lisinopril Oral Tablet 10 MG", "med_10"),
|
|
31
|
+
option("Lisinopril Oral Tablet 20 MG", "med_20"),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
describe("PhotonOrder prescriptions", () => {
|
|
35
|
+
it("a picked product waits for Add before the order can be sent; Remove leaves a fresh line to search in", async () => {
|
|
36
|
+
const component = renderComponent({
|
|
37
|
+
lookupPrescriptions: lisinoprilTablets10And20Mg,
|
|
38
|
+
script: {
|
|
39
|
+
SyncPrescription: () =>
|
|
40
|
+
payload(
|
|
41
|
+
"prescription",
|
|
42
|
+
"PrescriptionPayload",
|
|
43
|
+
rx({ id: "rx_lis", treatment: { ...rx().treatment, id: "med_10", name: "Lisinopril", ndc: null } }),
|
|
44
|
+
),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
await component.typeIntoTreatment("lisinopril");
|
|
48
|
+
await pickDrug("Lisinopril Oral Tablet 10 MG");
|
|
49
|
+
await screen.findByLabelText("Directions (sig)");
|
|
50
|
+
// No primary yet: Send waits for Add.
|
|
51
|
+
expect(document.querySelectorAll('.prx-button[data-variant="primary"]')).toHaveLength(0);
|
|
52
|
+
expect(screen.queryByRole("button", { name: /^Send prescriptions? to patient$/ })).toBeNull();
|
|
53
|
+
|
|
54
|
+
fireEvent.click(screen.getByRole("button", { name: "Remove prescription" }));
|
|
55
|
+
expect((await component.findTreatmentField()).value).toBe("");
|
|
56
|
+
expect(screen.queryByRole("heading", { name: "Lisinopril" })).toBeNull();
|
|
57
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull(); // nothing to take off yet
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("while a line chooses a drug, ⌘↵ doesn't send — the order would go without that line", async () => {
|
|
61
|
+
const component = renderComponent({
|
|
62
|
+
photonOrderProps: { order: "ord_1" },
|
|
63
|
+
lookupPrescriptions: lisinoprilTablets10And20Mg,
|
|
64
|
+
script: {
|
|
65
|
+
GetOrder: () => payload("order", "OrderPayload", order()),
|
|
66
|
+
SubmitOrder: () => payload("order", "OrderPayload", order("SUBMITTED")),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const send = await screen.findByRole("button", { name: /^Send prescriptions? to patient$/ });
|
|
70
|
+
await waitFor(() => expect(send).toHaveProperty("disabled", false)); // the one line is signed
|
|
71
|
+
|
|
72
|
+
fireEvent.click(screen.getByRole("button", { name: "Add another prescription" }));
|
|
73
|
+
const meds = await screen.findAllByLabelText("Treatment");
|
|
74
|
+
fireEvent.change(meds.at(-1)!, { target: { value: "lisinopril" } });
|
|
75
|
+
await screen.findByRole("list", { name: "Pick a treatment" });
|
|
76
|
+
expect(screen.queryByRole("button", { name: /^Send prescriptions? to patient$/ })).toBeNull();
|
|
77
|
+
fireEvent.keyDown(window, { key: "Enter", metaKey: true });
|
|
78
|
+
fireEvent.keyDown(window, { key: "Enter", ctrlKey: true });
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, 0)); // a send would have started by now
|
|
80
|
+
expect(component.names()).not.toContain("SubmitOrder");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("searches drugs before a patient is set (never drafts), then attaches the pick once a patient is chosen", async () => {
|
|
84
|
+
const metformin = payload("prescription", "PrescriptionPayload", null, {
|
|
85
|
+
changes: [
|
|
86
|
+
// Expected without a patient, and not shown.
|
|
87
|
+
change({
|
|
88
|
+
key: "patient",
|
|
89
|
+
label: "Patient",
|
|
90
|
+
status: "REJECTED",
|
|
91
|
+
severity: "BLOCKING",
|
|
92
|
+
reason: "patient is required.",
|
|
93
|
+
}),
|
|
94
|
+
change({
|
|
95
|
+
status: "AMBIGUOUS",
|
|
96
|
+
severity: "BLOCKING",
|
|
97
|
+
category: "DISAMBIGUATION",
|
|
98
|
+
options: [
|
|
99
|
+
option("metFORMIN HCl Oral Tablet 500 MG", "med_met500"),
|
|
100
|
+
option("metFORMIN HCl Oral Tablet 1000 MG", "med_met1000"),
|
|
101
|
+
],
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
} as never);
|
|
105
|
+
const component = renderComponent({
|
|
106
|
+
photonOrderProps: {},
|
|
107
|
+
lookupPrescriptions: metformin,
|
|
108
|
+
script: {
|
|
109
|
+
SyncPatient: () => ({
|
|
110
|
+
patient: {
|
|
111
|
+
__typename: "AmbiguousPatientMatch",
|
|
112
|
+
reason: "weak",
|
|
113
|
+
candidates: [{ id: "pat_1", firstName: "Ada", lastName: "Lovelace", dateOfBirth: "1990-01-01" }],
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
SyncPrescription: () => payload("prescription", "PrescriptionPayload", rx({ id: "rx_attached" })),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// No patient yet — the line is already there and searches.
|
|
121
|
+
const med = await component.findTreatmentField();
|
|
122
|
+
expect(screen.queryByLabelText("Quantity")).toBeNull(); // dispense details wait for a drug
|
|
123
|
+
expect(screen.queryByLabelText("Directions (sig)")).toBeNull();
|
|
124
|
+
expect(screen.queryByRole("button", { name: "Add another prescription" })).toBeNull(); // not until it has a drug
|
|
125
|
+
fireEvent.change(med, { target: { value: "metformin" } });
|
|
126
|
+
fireEvent.keyDown(med, { key: "Enter" });
|
|
127
|
+
await pickDrug("metFORMIN HCl Oral Tablet 500 MG");
|
|
128
|
+
expect(await screen.findByRole("heading", { name: "metFORMIN HCl" })).toBeTruthy();
|
|
129
|
+
expect(screen.queryByText("patient is required.")).toBeNull();
|
|
130
|
+
expect(screen.getByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
131
|
+
// Directions (sig), then quantity / unit / days / refills, then DAW.
|
|
132
|
+
const [sig, qty, daw] = ["Directions (sig)", "Quantity", "Dispense as written"].map((l) =>
|
|
133
|
+
screen.getByLabelText(l),
|
|
134
|
+
);
|
|
135
|
+
expect(sig!.compareDocumentPosition(qty!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
136
|
+
expect(qty!.compareDocumentPosition(daw!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
137
|
+
|
|
138
|
+
fireEvent.change(sig!, { target: { value: "1 tab PO BID" } });
|
|
139
|
+
fireEvent.blur(sig!);
|
|
140
|
+
expect(component.wasPrescriptionDrafted()).toBe(false); // nothing drafted without a patient
|
|
141
|
+
|
|
142
|
+
await typeIdentity("Ada", "Lovelace", "1990-01-01");
|
|
143
|
+
fireEvent.click(await screen.findByRole("option", { name: /Ada Lovelace/ }));
|
|
144
|
+
expect(await component.waitForDraftedPrescription()).toMatchObject({
|
|
145
|
+
patient: { id: "pat_1" },
|
|
146
|
+
treatment: { id: "med_met500" },
|
|
147
|
+
instructions: "1 tab PO BID",
|
|
148
|
+
});
|
|
149
|
+
expect(component.calls.filter((c) => c.name === "LookupPrescription").every((c) => !("patient" in c.vars))).toBe(
|
|
150
|
+
true,
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("PhotonOrder and the patient's draft order", () => {
|
|
156
|
+
const metoprolol = rx({ id: "rx_9", treatment: treatment({ id: "trt_9", name: "Metoprolol Tartrate" }) });
|
|
157
|
+
const withDraft: NetworkScript = {
|
|
158
|
+
Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [metoprolol] })]),
|
|
159
|
+
GetOrder: () => payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [metoprolol] }),
|
|
160
|
+
GetPrescription: () => payload("prescription", "PrescriptionPayload", metoprolol),
|
|
161
|
+
UpdateOrder: () => payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [] }),
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
it("shows the draft's prescriptions read-only and asks first; Continue makes them the order's lines", async () => {
|
|
165
|
+
const component = renderComponent({ script: withDraft });
|
|
166
|
+
expect(await screen.findByText("Would you like to continue this order?")).toBeTruthy();
|
|
167
|
+
expect(screen.getByRole("heading", { name: "Metoprolol Tartrate" })).toBeTruthy();
|
|
168
|
+
expect(screen.queryByLabelText("Treatment")).toBeNull(); // nothing to write in until the prescriber decides
|
|
169
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull();
|
|
170
|
+
|
|
171
|
+
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
|
|
172
|
+
// The draft as it is, with a way to add to it — no empty line in the way.
|
|
173
|
+
expect(await screen.findByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
174
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
175
|
+
expect(screen.getByRole("heading", { name: "Metoprolol Tartrate" })).toBeTruthy();
|
|
176
|
+
expect(screen.queryByLabelText("Treatment")).toBeNull();
|
|
177
|
+
expect(component.names()).toContain("GetOrder");
|
|
178
|
+
expect(component.names()).not.toContain("SyncOrder");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("a continued draft whose prescriptions are signed can be sent as it is", async () => {
|
|
182
|
+
const signedMetoprolol = { ...metoprolol, signing: { ...metoprolol.signing, state: "SIGNED" as const } };
|
|
183
|
+
renderComponent({
|
|
184
|
+
script: {
|
|
185
|
+
...withDraft,
|
|
186
|
+
Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [signedMetoprolol] })]),
|
|
187
|
+
GetOrder: () =>
|
|
188
|
+
payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [signedMetoprolol] }),
|
|
189
|
+
GetPrescription: () => payload("prescription", "PrescriptionPayload", signedMetoprolol),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
fireEvent.click(await screen.findByRole("button", { name: "Continue" }));
|
|
193
|
+
expect(await screen.findByRole("button", { name: "Send prescription to patient" })).toBeTruthy();
|
|
194
|
+
expect(screen.getByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("a draft with no prescriptions isn't shown: the order starts with its empty line", async () => {
|
|
198
|
+
const component = renderComponent({
|
|
199
|
+
script: { ...withDraft, Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [] })]) },
|
|
200
|
+
});
|
|
201
|
+
await component.findTreatmentField();
|
|
202
|
+
await waitFor(() => expect(component.names()).toContain("Orders"));
|
|
203
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("Start a new order empties the draft and goes on with an empty line", async () => {
|
|
207
|
+
const component = renderComponent({ script: withDraft });
|
|
208
|
+
fireEvent.click(await screen.findByRole("button", { name: "Start a new order" }));
|
|
209
|
+
await component.findTreatmentField();
|
|
210
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
211
|
+
expect(screen.queryByRole("heading", { name: "Metoprolol Tartrate" })).toBeNull();
|
|
212
|
+
expect(component.calls.find((c) => c.op === "UpdateOrder")?.vars).toMatchObject({ prescriptions: { none: true } });
|
|
213
|
+
expect(component.names()).not.toContain("GetOrder");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
type NetworkScript = Parameters<typeof fakeNetworkApiClient>[0];
|
|
218
|
+
|
|
219
|
+
type RenderComponentOptions = {
|
|
220
|
+
photonOrderProps?: PhotonOrderProps;
|
|
221
|
+
lookupPrescriptions?: unknown;
|
|
222
|
+
script?: NetworkScript;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
function renderComponent({
|
|
226
|
+
photonOrderProps = { patient: "pat_1" },
|
|
227
|
+
lookupPrescriptions = null,
|
|
228
|
+
script = {},
|
|
229
|
+
}: RenderComponentOptions = {}) {
|
|
230
|
+
const { client, calls, names } = fakeNetworkApiClient({
|
|
231
|
+
...draftOrder(),
|
|
232
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
233
|
+
LookupPrescription: () => lookupPrescriptions,
|
|
234
|
+
SyncPrescription: () => payload("prescription", "PrescriptionPayload", rx({ id: "rx_1" })),
|
|
235
|
+
...script,
|
|
236
|
+
});
|
|
237
|
+
render(<PhotonOrder {...photonOrderProps} />, { wrapper: withPhoton(client) });
|
|
238
|
+
|
|
239
|
+
const findTreatmentField = () => screen.findByLabelText("Treatment") as Promise<HTMLInputElement>;
|
|
240
|
+
return {
|
|
241
|
+
calls,
|
|
242
|
+
names,
|
|
243
|
+
findTreatmentField,
|
|
244
|
+
typeIntoTreatment: async (text: string) => {
|
|
245
|
+
const med = await findTreatmentField();
|
|
246
|
+
med.focus();
|
|
247
|
+
fireEvent.change(med, { target: { value: text } });
|
|
248
|
+
return med;
|
|
249
|
+
},
|
|
250
|
+
wasPrescriptionDrafted: () => names().includes("SyncPrescription"),
|
|
251
|
+
waitForDraftedPrescription: async () => {
|
|
252
|
+
await waitFor(() => expect(names()).toContain("SyncPrescription"));
|
|
253
|
+
return calls.find((c) => c.name === "SyncPrescription")!.vars;
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useComponents, usePhoton } from "../primitives/index.ts";
|
|
2
|
+
import { AnalyticsWorkflow } from "../analytics/PhotonAnalyticsProvider.tsx";
|
|
3
|
+
import { viewedPropertiesFromCardProps } from "../analytics/viewed.ts";
|
|
2
4
|
import { SignedIn } from "./SignedIn.tsx";
|
|
3
5
|
import {
|
|
4
6
|
asksForAddress,
|
|
@@ -15,7 +17,8 @@ import { useEffect, useRef, useState } from "react";
|
|
|
15
17
|
import { displayName } from "./format.ts";
|
|
16
18
|
import { callFor, NotFound, openFailed, openGiven, shared, toOpen, type Given } from "./open.ts";
|
|
17
19
|
import { PatientCard } from "./PhotonPatient.tsx";
|
|
18
|
-
import {
|
|
20
|
+
import { PrescriptionCard } from "./prescription/PrescriptionCard.tsx";
|
|
21
|
+
import { DraftOrderPrompt } from "./order/DraftOrderPrompt.tsx";
|
|
19
22
|
import { ScreeningAlerts } from "./ScreeningAlerts.tsx";
|
|
20
23
|
import { SearchResults } from "./search.tsx";
|
|
21
24
|
import { cardFlowKeys, cardProps, focusProps } from "./flow.ts";
|
|
@@ -79,9 +82,11 @@ const orderRecords = (order: Order) => {
|
|
|
79
82
|
|
|
80
83
|
export function PhotonOrder(props: PhotonOrderProps) {
|
|
81
84
|
return (
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
+
<AnalyticsWorkflow card="PhotonOrder" viewedProperties={viewedPropertiesFromCardProps(props)}>
|
|
86
|
+
<SignedIn>
|
|
87
|
+
<OrderCard {...props} />
|
|
88
|
+
</SignedIn>
|
|
89
|
+
</AnalyticsWorkflow>
|
|
85
90
|
);
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -274,31 +279,41 @@ function OrderView({
|
|
|
274
279
|
</div>
|
|
275
280
|
)}
|
|
276
281
|
|
|
277
|
-
{
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
282
|
+
{!final && snap.draft && (
|
|
283
|
+
// The patient's draft order, found when they were chosen: shown as it is until the prescriber decides.
|
|
284
|
+
<DraftOrderPrompt
|
|
285
|
+
draft={snap.draft}
|
|
286
|
+
onContinue={() => order.continueDraft()}
|
|
287
|
+
onStartNew={() => order.startNew()}
|
|
288
|
+
/>
|
|
289
|
+
)}
|
|
290
|
+
|
|
291
|
+
{!snap.draft &&
|
|
292
|
+
lines.map((line) => (
|
|
293
|
+
<div key={keyOf(line)} {...cardProps}>
|
|
294
|
+
<PrescriptionCard
|
|
295
|
+
prescription={line}
|
|
296
|
+
locked={final} // a signed line is read-only on its own
|
|
297
|
+
// A line comes off; the only one, once it has a drug, gives way to a fresh line (a different drug).
|
|
298
|
+
onRemove={
|
|
299
|
+
final
|
|
300
|
+
? undefined
|
|
301
|
+
: lines.length > 1
|
|
302
|
+
? () => void change(order, { prescriptions: { remove: [line] } })
|
|
303
|
+
: filled(line)
|
|
304
|
+
? () => {
|
|
305
|
+
void change(order, { prescriptions: { remove: [line], add: [{ templateId }] } });
|
|
306
|
+
setAdded(order.prescriptions.at(-1) ?? null); // the fresh line, at once
|
|
307
|
+
}
|
|
308
|
+
: undefined
|
|
309
|
+
}
|
|
310
|
+
autoFocus={line === added}
|
|
311
|
+
focusSignal={focus?.line === line ? focus.signal : undefined}
|
|
312
|
+
/>
|
|
313
|
+
</div>
|
|
314
|
+
))}
|
|
300
315
|
|
|
301
|
-
{!final && allFilled && (
|
|
316
|
+
{!final && !snap.draft && allFilled && (
|
|
302
317
|
<div data-prx-card="">
|
|
303
318
|
<span {...focusProps}>
|
|
304
319
|
<Button
|
|
@@ -403,7 +418,7 @@ function SendSection({
|
|
|
403
418
|
Sent
|
|
404
419
|
</Badge>
|
|
405
420
|
</Row>
|
|
406
|
-
{record.exceptions.map((x) => (
|
|
421
|
+
{record.fulfillment?.exceptions.map((x) => (
|
|
407
422
|
<Alert
|
|
408
423
|
key={x.id}
|
|
409
424
|
tone="warning"
|
|
@@ -479,7 +494,7 @@ function SendSection({
|
|
|
479
494
|
* when something else explains why it wasn't sent (network-api adds "a sibling change was rejected").
|
|
480
495
|
*/
|
|
481
496
|
function reasons(unapplied: readonly Change[]): Change[] {
|
|
482
|
-
const own = unapplied.filter((c) => !c.key.startsWith("patient.
|
|
497
|
+
const own = unapplied.filter((c) => !c.key.startsWith("patient.contact."));
|
|
483
498
|
const explained = own.some((c) => c.key !== "state") || own.length < unapplied.length;
|
|
484
499
|
return explained ? own.filter((c) => c.key !== "state") : own;
|
|
485
500
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useComponents, usePhoton } from "../primitives/index.ts";
|
|
2
|
+
import { AnalyticsWorkflow } from "../analytics/PhotonAnalyticsProvider.tsx";
|
|
3
|
+
import { viewedPropertiesFromCardProps } from "../analytics/viewed.ts";
|
|
2
4
|
import { SignedIn } from "./SignedIn.tsx";
|
|
3
5
|
import { classify, Patient, type ChangeOption, type PatientInput, type PatientResult } from "@photonhealth/client";
|
|
4
6
|
import { useLive, useOnChange } from "../hooks/index.ts";
|
|
@@ -43,9 +45,11 @@ export interface PhotonPatientProps {
|
|
|
43
45
|
/** A patient card. */
|
|
44
46
|
export function PhotonPatient(props: PhotonPatientProps) {
|
|
45
47
|
return (
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
48
|
+
<AnalyticsWorkflow card="PhotonPatient" viewedProperties={viewedPropertiesFromCardProps(props)}>
|
|
49
|
+
<SignedIn>
|
|
50
|
+
<PatientCard {...props} />
|
|
51
|
+
</SignedIn>
|
|
52
|
+
</AnalyticsWorkflow>
|
|
49
53
|
);
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -145,11 +149,11 @@ export function PatientCard({
|
|
|
145
149
|
onRemoveMedication={(m) => patchClinical({ medications: { remove: [{ id: m.id, status: m.status }] } })}
|
|
146
150
|
onAddDiagnosis={(text) => patchClinical({ diagnoses: { add: [diagnosisRef(text)] } })}
|
|
147
151
|
onRemoveDiagnosis={(d) => patchClinical({ diagnoses: { remove: [{ id: d.id }] } })}
|
|
148
|
-
onAddBenefit={(b) => update({
|
|
149
|
-
onRemoveBenefit={(b) => update({
|
|
150
|
-
onConfirmNoBenefits={() => update({
|
|
152
|
+
onAddBenefit={(b) => update({ benefits: { add: [b] } })}
|
|
153
|
+
onRemoveBenefit={(b) => update({ benefits: { remove: [{ id: b.id }] } })}
|
|
154
|
+
onConfirmNoBenefits={() => update({ benefits: { none: true } })}
|
|
151
155
|
onAddMedication={(name) => patchClinical({ medications: { add: [{ name, status: "ACTIVE" }] } })}
|
|
152
|
-
onSaveContact={(contact) => update({
|
|
156
|
+
onSaveContact={(contact) => update({ contact })}
|
|
153
157
|
onSaveDetails={(details) => update({ demographic: details })}
|
|
154
158
|
addressRequest={locked ? null : (addressRequest ?? null)}
|
|
155
159
|
readOnly={locked}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen, waitFor, within } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { fakeNetworkApiClient, payload } from "@photonhealth/client/testing";
|
|
6
|
+
import { PhotonPrescription } from "../index.ts";
|
|
7
|
+
import { fakeNetworkApi, patient } from "../../test/cards.fixtures.tsx";
|
|
8
|
+
import {
|
|
9
|
+
edited,
|
|
10
|
+
leaveField,
|
|
11
|
+
meAsPrescriber,
|
|
12
|
+
recordAnalytics,
|
|
13
|
+
type RecordedAnalytics,
|
|
14
|
+
typeInto,
|
|
15
|
+
unmountAndRestoreFetch,
|
|
16
|
+
withAnalytics,
|
|
17
|
+
} from "../../test/analytics.fixtures.tsx";
|
|
18
|
+
|
|
19
|
+
// The card as a workflow: its analytics. The card itself is tested in prescription/PrescriptionCard.test.tsx.
|
|
20
|
+
|
|
21
|
+
afterEach(cleanup);
|
|
22
|
+
|
|
23
|
+
const settledDrugRow = (row: RegExp) =>
|
|
24
|
+
waitFor(() => {
|
|
25
|
+
const button = screen.getByRole<HTMLButtonElement>("button", { name: row });
|
|
26
|
+
expect(button.disabled).toBe(false);
|
|
27
|
+
return button;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const clickDrugRowOnceSettled = async (row: RegExp) => {
|
|
31
|
+
await userEvent.click(await settledDrugRow(row));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("PhotonPrescription: Field Interaction", () => {
|
|
35
|
+
let analytics: RecordedAnalytics;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
analytics = recordAnalytics();
|
|
38
|
+
});
|
|
39
|
+
afterEach(unmountAndRestoreFetch);
|
|
40
|
+
|
|
41
|
+
it("searching Treatment and picking a one-product drug from its list is one visit: focus, change, blur", async () => {
|
|
42
|
+
const { client } = fakeNetworkApiClient({
|
|
43
|
+
...meAsPrescriber,
|
|
44
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
45
|
+
...fakeNetworkApi({
|
|
46
|
+
prescriptions: {
|
|
47
|
+
amo: [
|
|
48
|
+
["Amondys", "Injection", "45 MG"],
|
|
49
|
+
["Amoxicillin", "Capsule", "500 MG"],
|
|
50
|
+
["Amoxicillin", "Tablet", "875 MG"],
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
render(<PhotonPrescription patient="pat_1" />, { wrapper: withAnalytics(client) });
|
|
56
|
+
|
|
57
|
+
await userEvent.click(await screen.findByLabelText("Treatment"));
|
|
58
|
+
await userEvent.keyboard("Amo");
|
|
59
|
+
await clickDrugRowOnceSettled(/^Amondys/);
|
|
60
|
+
await screen.findByLabelText("Directions (sig)");
|
|
61
|
+
leaveField();
|
|
62
|
+
|
|
63
|
+
await analytics.expectEventLog(["Prescribe Workflow Viewed", ...edited("treatment")]);
|
|
64
|
+
expect(analytics.sentFor("treatment").at(-1)).toMatchObject({ hasValue: true, changed: true });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("each field sends focus, one change and blur with its documented name, and nothing typed", async () => {
|
|
68
|
+
const { client } = fakeNetworkApiClient({
|
|
69
|
+
...meAsPrescriber,
|
|
70
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
71
|
+
...fakeNetworkApi({
|
|
72
|
+
prescriptions: {
|
|
73
|
+
amox: [
|
|
74
|
+
["Amoxicillin", "Capsule", "250 MG"],
|
|
75
|
+
["Amoxicillin", "Capsule", "500 MG"],
|
|
76
|
+
["Amoxicillin", "Tablet", "875 MG"],
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
render(<PhotonPrescription patient="pat_1" />, { wrapper: withAnalytics(client) });
|
|
82
|
+
|
|
83
|
+
await userEvent.click(await screen.findByLabelText("Treatment"));
|
|
84
|
+
await userEvent.keyboard("amox");
|
|
85
|
+
await clickDrugRowOnceSettled(/^Amoxicillin/);
|
|
86
|
+
await userEvent.click(within(await screen.findByRole("group", { name: "Form" })).getByText("Capsule"));
|
|
87
|
+
await userEvent.click(within(screen.getByRole("group", { name: "Strength" })).getByText("500 mg"));
|
|
88
|
+
await screen.findByLabelText("Directions (sig)");
|
|
89
|
+
await typeInto("Directions (sig)", "Zqx once daily");
|
|
90
|
+
await typeInto("Quantity", "14");
|
|
91
|
+
await typeInto("Unit", "Zqxunit");
|
|
92
|
+
await typeInto("Days supply", "7");
|
|
93
|
+
await typeInto("Refills", "1");
|
|
94
|
+
await userEvent.click(screen.getByRole("checkbox", { name: "Dispense as written" }));
|
|
95
|
+
leaveField();
|
|
96
|
+
|
|
97
|
+
await analytics.expectEventLog([
|
|
98
|
+
"Prescribe Workflow Viewed",
|
|
99
|
+
...edited("treatment"),
|
|
100
|
+
...edited("form"),
|
|
101
|
+
...edited("strength"),
|
|
102
|
+
...edited("instructions"),
|
|
103
|
+
...edited("dispenseQuantity"),
|
|
104
|
+
...edited("dispenseUnit"),
|
|
105
|
+
...edited("daysSupply"),
|
|
106
|
+
...edited("refills"),
|
|
107
|
+
...edited("dispenseAsWritten"),
|
|
108
|
+
]);
|
|
109
|
+
expect(new Set(analytics.fieldInteractions().map((sent) => sent.formName))).toEqual(
|
|
110
|
+
new Set(["add_prescription_form"]),
|
|
111
|
+
);
|
|
112
|
+
expect(analytics.sentFor("daysSupply").map((sent) => sent.isOptional)).toEqual([true, true, true]);
|
|
113
|
+
expect(analytics.sentFor("instructions").at(-1)).toMatchObject({ durationMs: expect.any(Number), changed: true });
|
|
114
|
+
for (const body of analytics.bodies()) expect(body).not.toMatch(/amox|Zqx|"14"/);
|
|
115
|
+
});
|
|
116
|
+
});
|