@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,80 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import type { PrescriptionRecord } from "@photonhealth/client";
|
|
3
|
+
import { treatment } from "@photonhealth/client/testing";
|
|
4
|
+
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { DraftOrderPrompt } from "./DraftOrderPrompt.tsx";
|
|
7
|
+
|
|
8
|
+
const record = (id: string, fields: Partial<PrescriptionRecord> = {}): PrescriptionRecord => ({
|
|
9
|
+
id,
|
|
10
|
+
prescriber: null,
|
|
11
|
+
fulfillment: null,
|
|
12
|
+
templateId: null,
|
|
13
|
+
patient: { id: "pat_1" },
|
|
14
|
+
treatment: { ...treatment(), templates: null },
|
|
15
|
+
instructions: "Take 1 capsule by mouth three times daily",
|
|
16
|
+
dispense: { quantity: 30, unit: "Capsule", daysSupply: 10, refillsAllowed: 0, dispenseAsWritten: false },
|
|
17
|
+
clinical: null,
|
|
18
|
+
screeningAlerts: [],
|
|
19
|
+
signing: { state: "UNSIGNED", contentHash: "hash_1", message: null, signedAt: null },
|
|
20
|
+
...fields,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const amoxicillin = record("rx_1", {
|
|
24
|
+
treatment: {
|
|
25
|
+
...treatment({ name: "Amoxicillin", prescribableName: "Amoxicillin 500 MG Oral Capsule" }),
|
|
26
|
+
templates: null,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const lisinopril = record("rx_2", {
|
|
30
|
+
treatment: { ...treatment({ id: "trt_2", name: "Lisinopril 10 MG Oral Tablet" }), templates: null },
|
|
31
|
+
instructions: "Take 1 tablet by mouth once daily",
|
|
32
|
+
signing: { state: "SIGNED", contentHash: "hash_2", message: null, signedAt: "2026-11-01T00:00:00Z" },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("DraftOrderPrompt", () => {
|
|
36
|
+
afterEach(() => cleanup());
|
|
37
|
+
|
|
38
|
+
it("shows each prescription on the draft, read-only, and asks whether to continue it", () => {
|
|
39
|
+
render(
|
|
40
|
+
<DraftOrderPrompt
|
|
41
|
+
draft={{ prescriptions: [amoxicillin, lisinopril] }}
|
|
42
|
+
onContinue={vi.fn()}
|
|
43
|
+
onStartNew={vi.fn()}
|
|
44
|
+
/>,
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByRole("heading", { name: "Amoxicillin" })).toBeTruthy();
|
|
47
|
+
expect(screen.getByRole("region", { name: "Amoxicillin" })).toBeTruthy(); // each card is named by its drug
|
|
48
|
+
expect(screen.getByRole("heading", { name: "Lisinopril" })).toBeTruthy();
|
|
49
|
+
expect(screen.getByText("Take 1 capsule by mouth three times daily")).toBeTruthy();
|
|
50
|
+
expect(screen.getByText("Signed")).toBeTruthy();
|
|
51
|
+
// Nothing to edit, sign or remove until the prescriber decides.
|
|
52
|
+
expect(screen.queryAllByRole("textbox")).toHaveLength(0);
|
|
53
|
+
expect(screen.queryByRole("button", { name: "Add" })).toBeNull();
|
|
54
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull();
|
|
55
|
+
expect(screen.getByText("Would you like to continue this order?")).toBeTruthy();
|
|
56
|
+
expect(screen.getAllByRole("button").map((b) => b.textContent)).toEqual(["Continue", "Start a new order"]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("Continue and Start a new order each call their own handler", () => {
|
|
60
|
+
const onContinue = vi.fn();
|
|
61
|
+
const onStartNew = vi.fn();
|
|
62
|
+
render(
|
|
63
|
+
<DraftOrderPrompt draft={{ prescriptions: [amoxicillin] }} onContinue={onContinue} onStartNew={onStartNew} />,
|
|
64
|
+
);
|
|
65
|
+
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
|
|
66
|
+
expect(onContinue).toHaveBeenCalledOnce();
|
|
67
|
+
expect(onStartNew).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("while a choice is in flight, neither button can be pressed again", async () => {
|
|
71
|
+
let settle!: () => void;
|
|
72
|
+
const onStartNew = vi.fn(() => new Promise<void>((resolve) => (settle = resolve)));
|
|
73
|
+
render(<DraftOrderPrompt draft={{ prescriptions: [amoxicillin] }} onContinue={vi.fn()} onStartNew={onStartNew} />);
|
|
74
|
+
await act(async () => fireEvent.click(screen.getByRole("button", { name: "Start a new order" })));
|
|
75
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: /Start a new order/ }).disabled).toBe(true);
|
|
76
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: "Continue" }).disabled).toBe(true);
|
|
77
|
+
await act(async () => settle());
|
|
78
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: "Continue" }).disabled).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { PrescriptionRecord } from "@photonhealth/client";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useComponents } from "../../primitives/index.ts";
|
|
4
|
+
import { treatmentHeading } from "../display.ts";
|
|
5
|
+
import { cardProps, focusProps } from "../flow.ts";
|
|
6
|
+
import { ReadOnlyRx, StatusBadge } from "../prescription/PrescriptionCard.tsx";
|
|
7
|
+
|
|
8
|
+
export interface DraftOrderPromptProps {
|
|
9
|
+
/** The patient's draft order: what's already on it, shown read-only until the prescriber decides. */
|
|
10
|
+
draft: { prescriptions: readonly PrescriptionRecord[] };
|
|
11
|
+
/** Go on with this draft: its prescriptions become the order's, and what's added goes on it. */
|
|
12
|
+
onContinue: () => void | Promise<unknown>;
|
|
13
|
+
/** Write a new order instead: the draft's prescriptions come off it, and the order starts over. */
|
|
14
|
+
onStartNew: () => void | Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A patient's draft order, found when they're chosen: its prescriptions, each on its own card as the order's lines
|
|
19
|
+
* are, then the question — continue it, or start a new order. Nothing changes until one is picked. Renders cards
|
|
20
|
+
* only, for PhotonOrder's flow.
|
|
21
|
+
*/
|
|
22
|
+
export function DraftOrderPrompt({ draft, onContinue, onStartNew }: DraftOrderPromptProps) {
|
|
23
|
+
const { Button, Card, CardBody, CardFooter, CardHeader, Row, Stack, Text } = useComponents();
|
|
24
|
+
// Which choice is in flight: that button spins, and neither can be pressed again until it settles.
|
|
25
|
+
const [choosing, setChoosing] = useState<"continue" | "new" | null>(null);
|
|
26
|
+
const choose = (which: "continue" | "new", act: () => void | Promise<unknown>) => {
|
|
27
|
+
setChoosing(which);
|
|
28
|
+
// A failure lands on the order (snapshot.error), where the card shows it.
|
|
29
|
+
void new Promise((resolve) => resolve(act())).catch(() => {}).finally(() => setChoosing(null));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{draft.prescriptions.map((rx) => {
|
|
35
|
+
const heading = treatmentHeading(rx.treatment.name, rx.treatment);
|
|
36
|
+
return (
|
|
37
|
+
<div key={rx.id} {...cardProps}>
|
|
38
|
+
<Card divided label={heading.title}>
|
|
39
|
+
<CardHeader title={heading.title} description={heading.detail} />
|
|
40
|
+
<CardBody>
|
|
41
|
+
<ReadOnlyRx rx={rx} status={<StatusBadge rx={rx} />} />
|
|
42
|
+
</CardBody>
|
|
43
|
+
</Card>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
})}
|
|
47
|
+
<div {...cardProps}>
|
|
48
|
+
<Card>
|
|
49
|
+
{/* The footer, not the body: a host's body text can be smaller (Photon Rx's is), and this is the card's
|
|
50
|
+
question. Stacked in `start`, so the buttons sit under it, on the left. */}
|
|
51
|
+
<CardFooter
|
|
52
|
+
start={
|
|
53
|
+
<Stack gap="3">
|
|
54
|
+
<Text>Would you like to continue this order?</Text>
|
|
55
|
+
<Row gap="2">
|
|
56
|
+
<span {...focusProps}>
|
|
57
|
+
<Button
|
|
58
|
+
loading={choosing === "continue"}
|
|
59
|
+
disabled={choosing !== null}
|
|
60
|
+
onClick={() => choose("continue", onContinue)}
|
|
61
|
+
>
|
|
62
|
+
Continue
|
|
63
|
+
</Button>
|
|
64
|
+
</span>
|
|
65
|
+
<Button
|
|
66
|
+
variant="secondary"
|
|
67
|
+
loading={choosing === "new"}
|
|
68
|
+
disabled={choosing !== null}
|
|
69
|
+
onClick={() => choose("new", onStartNew)}
|
|
70
|
+
>
|
|
71
|
+
Start a new order
|
|
72
|
+
</Button>
|
|
73
|
+
</Row>
|
|
74
|
+
</Stack>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
</Card>
|
|
78
|
+
</div>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { useComponents } from "../../primitives/index.ts";
|
|
4
4
|
import { noAutofill } from "./fields.tsx";
|
|
5
|
+
import { TrackedField } from "../../analytics/fieldInteraction.tsx";
|
|
5
6
|
|
|
6
7
|
export type BenefitInput = { id?: string; bin?: string; pcn?: string; groupId?: string; memberId?: string };
|
|
7
8
|
|
|
@@ -96,19 +97,26 @@ export function BenefitsSection({
|
|
|
96
97
|
}}
|
|
97
98
|
>
|
|
98
99
|
<Stack gap="2">
|
|
99
|
-
<
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
<TrackedField formName="update_patient_form" fieldName="insurance" isOptional>
|
|
101
|
+
<Grid min="72px" gap="2">
|
|
102
|
+
<Input
|
|
103
|
+
label="BIN"
|
|
104
|
+
value={bin}
|
|
105
|
+
onChange={(e) => setBin(e.target.value)}
|
|
106
|
+
inputMode="numeric"
|
|
107
|
+
autoFocus
|
|
108
|
+
{...noAutofill}
|
|
109
|
+
/>
|
|
110
|
+
<Input label="PCN" value={pcn} onChange={(e) => setPcn(e.target.value)} {...noAutofill} />
|
|
111
|
+
<Input label="Group" value={groupId} onChange={(e) => setGroupId(e.target.value)} {...noAutofill} />
|
|
112
|
+
<Input
|
|
113
|
+
label="Member ID"
|
|
114
|
+
value={memberId}
|
|
115
|
+
onChange={(e) => setMemberId(e.target.value)}
|
|
116
|
+
{...noAutofill}
|
|
117
|
+
/>
|
|
118
|
+
</Grid>
|
|
119
|
+
</TrackedField>
|
|
112
120
|
<Row justify="end" gap="2">
|
|
113
121
|
<Button variant="ghost" onClick={reset}>
|
|
114
122
|
Cancel
|
|
@@ -6,6 +6,7 @@ import { useHeldActivity } from "../activity.ts";
|
|
|
6
6
|
import { ChangeList } from "../ChangeList.tsx";
|
|
7
7
|
import { afterPress, searchKeys, useTypeAhead, type SearchHandle } from "../search.tsx";
|
|
8
8
|
import { noAutofill } from "./fields.tsx";
|
|
9
|
+
import { TrackedField } from "../../analytics/fieldInteraction.tsx";
|
|
9
10
|
|
|
10
11
|
/** Which clinical list a server change belongs to (keys look like "clinical.allergies.add.0" / "allergies.0"). */
|
|
11
12
|
const CLINICAL_SECTIONS = ["allergies", "medications", "diagnoses"] as const;
|
|
@@ -25,7 +26,7 @@ export const diagnosisRef = (text: string) =>
|
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* A clinical list (allergies, medications, diagnoses): chips for what's on file, plus "Add …" and "No …"
|
|
28
|
-
* (records none — `confirmedNone` is the record's `[]`; network-api can't read it back yet
|
|
29
|
+
* (records none — `confirmedNone` is the record's `[]`; network-api can't read it back yet).
|
|
29
30
|
*
|
|
30
31
|
* "Add …" is a search field (search.tsx) — type-ahead, its spinner, its results (the server's choices, e.g.
|
|
31
32
|
* which penicillin) and keys. Each search is an add, by design: what's typed, once it matches one entry, is that
|
|
@@ -34,6 +35,7 @@ export const diagnosisRef = (text: string) =>
|
|
|
34
35
|
*/
|
|
35
36
|
export function ClinicalList<T extends { id: string; name: string }>({
|
|
36
37
|
label,
|
|
38
|
+
fieldName,
|
|
37
39
|
items,
|
|
38
40
|
tone,
|
|
39
41
|
addLabel,
|
|
@@ -51,6 +53,7 @@ export function ClinicalList<T extends { id: string; name: string }>({
|
|
|
51
53
|
onChoose,
|
|
52
54
|
}: {
|
|
53
55
|
label: string;
|
|
56
|
+
fieldName: "allergies" | "medications" | "diagnoses";
|
|
54
57
|
items: T[];
|
|
55
58
|
tone: "warning" | "neutral";
|
|
56
59
|
addLabel: string;
|
|
@@ -150,7 +153,7 @@ export function ClinicalList<T extends { id: string; name: string }>({
|
|
|
150
153
|
);
|
|
151
154
|
})}
|
|
152
155
|
{none && noneLabel && <Badge tone="success">{noneLabel}</Badge>}
|
|
153
|
-
{/* network-api can't tell "never asked" from "none"
|
|
156
|
+
{/* network-api can't tell "never asked" from "none": say which we know. */}
|
|
154
157
|
{noneLabel && !none && items.length === 0 && !adding && <Text tone="tertiary">Not recorded</Text>}
|
|
155
158
|
</Row>
|
|
156
159
|
{noneLabel && onNone && !adding && items.length === 0 && !none && (
|
|
@@ -168,30 +171,32 @@ export function ClinicalList<T extends { id: string; name: string }>({
|
|
|
168
171
|
<div ref={field}>
|
|
169
172
|
<Stack gap="2">
|
|
170
173
|
{adding && (
|
|
171
|
-
<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
e.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
174
|
+
<TrackedField formName="update_patient_form" fieldName={fieldName} isOptional>
|
|
175
|
+
<Input
|
|
176
|
+
label={addLabel}
|
|
177
|
+
value={value}
|
|
178
|
+
autoFocus
|
|
179
|
+
loading={spinning}
|
|
180
|
+
{...noAutofill}
|
|
181
|
+
onChange={(e) => {
|
|
182
|
+
setValue(e.target.value);
|
|
183
|
+
typeAhead.typed("add", e.target.value);
|
|
184
|
+
}}
|
|
185
|
+
onBlur={(e) => {
|
|
186
|
+
// Into its results isn't leaving; anywhere else sends what's typed (or closes an empty field).
|
|
187
|
+
if (field.current?.contains(e.relatedTarget) || results.current?.pointing?.()) return;
|
|
188
|
+
afterPress(add); // e.g. pressing "Mark none" below: it mustn't move before the click lands
|
|
189
|
+
}}
|
|
190
|
+
onKeyDown={(e) => {
|
|
191
|
+
if (searchKeys(e, results.current, value.trim() === sent && !saving)) return;
|
|
192
|
+
if (e.key === "Enter") {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
add();
|
|
195
|
+
}
|
|
196
|
+
if (e.key === "Escape") close();
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
</TrackedField>
|
|
195
200
|
)}
|
|
196
201
|
{(choices.length > 0 || problems.length > 0) && (
|
|
197
202
|
<ChangeList
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { fakeNetworkApiClient, noMatch } from "@photonhealth/client/testing";
|
|
6
|
+
import { PhotonPatient } from "../../index.ts";
|
|
7
|
+
import {
|
|
8
|
+
edited,
|
|
9
|
+
leaveField,
|
|
10
|
+
meAsPrescriber,
|
|
11
|
+
recordAnalytics,
|
|
12
|
+
type RecordedAnalytics,
|
|
13
|
+
typeInto,
|
|
14
|
+
unmountAndRestoreFetch,
|
|
15
|
+
visitedWithoutEditing,
|
|
16
|
+
withAnalytics,
|
|
17
|
+
} from "../../../test/analytics.fixtures.tsx";
|
|
18
|
+
|
|
19
|
+
let analytics: RecordedAnalytics;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
analytics = recordAnalytics();
|
|
22
|
+
});
|
|
23
|
+
afterEach(unmountAndRestoreFetch);
|
|
24
|
+
|
|
25
|
+
const renderPatientCard = () =>
|
|
26
|
+
render(<PhotonPatient />, {
|
|
27
|
+
wrapper: withAnalytics(fakeNetworkApiClient({ ...meAsPrescriber, SyncPatient: noMatch }).client),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("PatientIntakeForm: Field Interaction", () => {
|
|
31
|
+
it("Find patient is find_patient's patientSearch: focus, one change, blur, and nothing typed", async () => {
|
|
32
|
+
renderPatientCard();
|
|
33
|
+
await typeInto("Find patient", "Zqxfirst Zqxlast");
|
|
34
|
+
|
|
35
|
+
await analytics.expectEventLog([
|
|
36
|
+
"Field Interaction patientSearch focus",
|
|
37
|
+
"Prescribe Workflow Viewed",
|
|
38
|
+
"Field Interaction patientSearch change",
|
|
39
|
+
"Field Interaction patientSearch blur",
|
|
40
|
+
]);
|
|
41
|
+
expect(analytics.sentFor("patientSearch")).toEqual([
|
|
42
|
+
expect.objectContaining({ formName: "find_patient", hasValue: false, isOptional: false }),
|
|
43
|
+
expect.objectContaining({ hasValue: true }),
|
|
44
|
+
expect.objectContaining({ hasValue: true, changed: true, durationMs: expect.any(Number) }),
|
|
45
|
+
]);
|
|
46
|
+
for (const body of analytics.bodies()) expect(body).not.toMatch(/Zqx/i);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("adding a patient: each field visited sends focus, one change and blur as new_patient_form", async () => {
|
|
50
|
+
renderPatientCard();
|
|
51
|
+
await typeInto("Find patient", "Zqxfirst Zqxlast");
|
|
52
|
+
await userEvent.click(await screen.findByRole("option", { name: /Add new patient/ }));
|
|
53
|
+
await typeInto("First name", "Zqxa");
|
|
54
|
+
await typeInto("Last name", "Zqxb");
|
|
55
|
+
await userEvent.click(screen.getByLabelText("Date of birth"));
|
|
56
|
+
fireEvent.change(screen.getByLabelText("Date of birth"), { target: { value: "1990-01-01" } });
|
|
57
|
+
leaveField();
|
|
58
|
+
await userEvent.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "FEMALE");
|
|
59
|
+
leaveField();
|
|
60
|
+
await typeInto("Phone", "5555550100");
|
|
61
|
+
await typeInto("Email", "zqx@example.com");
|
|
62
|
+
|
|
63
|
+
await analytics.expectEventLog([
|
|
64
|
+
"Field Interaction patientSearch focus",
|
|
65
|
+
"Prescribe Workflow Viewed",
|
|
66
|
+
"Field Interaction patientSearch change",
|
|
67
|
+
"Field Interaction patientSearch blur",
|
|
68
|
+
...visitedWithoutEditing("firstName"),
|
|
69
|
+
...visitedWithoutEditing("sex"),
|
|
70
|
+
...edited("firstName"),
|
|
71
|
+
...edited("lastName"),
|
|
72
|
+
...edited("dateOfBirth"),
|
|
73
|
+
...edited("sex"),
|
|
74
|
+
...edited("phone"),
|
|
75
|
+
...edited("email"),
|
|
76
|
+
]);
|
|
77
|
+
const sent = analytics.fieldInteractions().filter((s) => s.fieldName !== "patientSearch");
|
|
78
|
+
expect(new Set(sent.map((s) => s.formName))).toEqual(new Set(["new_patient_form"]));
|
|
79
|
+
expect(Object.fromEntries(sent.map((s) => [s.fieldName, s.isOptional]))).toEqual({
|
|
80
|
+
firstName: false,
|
|
81
|
+
lastName: false,
|
|
82
|
+
dateOfBirth: false,
|
|
83
|
+
sex: false,
|
|
84
|
+
phone: true,
|
|
85
|
+
email: true,
|
|
86
|
+
});
|
|
87
|
+
for (const body of analytics.bodies()) expect(body).not.toMatch(/Zqx|1990|5555550100|FEMALE/i);
|
|
88
|
+
});
|
|
89
|
+
});
|