@photonhealth/react 0.0.0-stage → 2.0.0-rc.1
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/LICENSE +15 -0
- package/README.md +84 -2
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/tailwind.d.ts +3 -0
- package/dist/adapters/tailwind.d.ts.map +1 -0
- package/dist/adapters/tailwind.js +123 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/components/ChangeList.d.ts +21 -0
- package/dist/components/ChangeList.d.ts.map +1 -0
- package/dist/components/ChangeList.js +40 -0
- package/dist/components/ChangeList.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts +46 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -0
- package/dist/components/PhotonOrder.js +270 -0
- package/dist/components/PhotonOrder.js.map +1 -0
- package/dist/components/PhotonPatient.d.ts +48 -0
- package/dist/components/PhotonPatient.d.ts.map +1 -0
- package/dist/components/PhotonPatient.js +83 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +43 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +364 -0
- package/dist/components/PhotonPrescription.js.map +1 -0
- package/dist/components/ScreeningAlerts.d.ts +6 -0
- package/dist/components/ScreeningAlerts.d.ts.map +1 -0
- package/dist/components/ScreeningAlerts.js +11 -0
- package/dist/components/ScreeningAlerts.js.map +1 -0
- package/dist/components/SignedIn.d.ts +12 -0
- package/dist/components/SignedIn.d.ts.map +1 -0
- package/dist/components/SignedIn.js +84 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/TreatmentPicker.d.ts +45 -0
- package/dist/components/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/TreatmentPicker.js +279 -0
- package/dist/components/TreatmentPicker.js.map +1 -0
- package/dist/components/activity.d.ts +7 -0
- package/dist/components/activity.d.ts.map +1 -0
- package/dist/components/activity.js +24 -0
- package/dist/components/activity.js.map +1 -0
- package/dist/components/display.d.ts +90 -0
- package/dist/components/display.d.ts.map +1 -0
- package/dist/components/display.js +223 -0
- package/dist/components/display.js.map +1 -0
- package/dist/components/flow.d.ts +35 -0
- package/dist/components/flow.d.ts.map +1 -0
- package/dist/components/flow.js +53 -0
- package/dist/components/flow.js.map +1 -0
- package/dist/components/format.d.ts +26 -0
- package/dist/components/format.d.ts.map +1 -0
- package/dist/components/format.js +61 -0
- package/dist/components/format.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/open.d.ts +47 -0
- package/dist/components/open.d.ts.map +1 -0
- package/dist/components/open.js +73 -0
- package/dist/components/open.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts +25 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -0
- package/dist/components/patient/Benefits.js +47 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +55 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +117 -0
- package/dist/components/patient/Clinical.js.map +1 -0
- package/dist/components/patient/IntakeForm.d.ts +10 -0
- package/dist/components/patient/IntakeForm.d.ts.map +1 -0
- package/dist/components/patient/IntakeForm.js +324 -0
- package/dist/components/patient/IntakeForm.js.map +1 -0
- package/dist/components/patient/Summary.d.ts +48 -0
- package/dist/components/patient/Summary.d.ts.map +1 -0
- package/dist/components/patient/Summary.js +80 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +43 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +71 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +23 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +65 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/search.d.ts +154 -0
- package/dist/components/search.d.ts.map +1 -0
- package/dist/components/search.js +295 -0
- package/dist/components/search.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useLatestCallback.d.ts +7 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useLatestCallback.js +14 -0
- package/dist/hooks/useLatestCallback.js.map +1 -0
- package/dist/hooks/useLive.d.ts +15 -0
- package/dist/hooks/useLive.d.ts.map +1 -0
- package/dist/hooks/useLive.js +6 -0
- package/dist/hooks/useLive.js.map +1 -0
- package/dist/hooks/useOnChange.d.ts +11 -0
- package/dist/hooks/useOnChange.d.ts.map +1 -0
- package/dist/hooks/useOnChange.js +28 -0
- package/dist/hooks/useOnChange.js.map +1 -0
- package/dist/hooks/useSession.d.ts +7 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +10 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +58 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +91 -0
- package/dist/primitives/PhotonProvider.js.map +1 -0
- package/dist/primitives/defaults.d.ts +3 -0
- package/dist/primitives/defaults.d.ts.map +1 -0
- package/dist/primitives/defaults.js +67 -0
- package/dist/primitives/defaults.js.map +1 -0
- package/dist/primitives/icons.d.ts +6 -0
- package/dist/primitives/icons.d.ts.map +1 -0
- package/dist/primitives/icons.js +6 -0
- package/dist/primitives/icons.js.map +1 -0
- package/dist/primitives/index.d.ts +5 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +5 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/select.d.ts +7 -0
- package/dist/primitives/select.d.ts.map +1 -0
- package/dist/primitives/select.js +16 -0
- package/dist/primitives/select.js.map +1 -0
- package/dist/primitives/types.d.ts +276 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/primitives/types.js +3 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/styles.css +611 -0
- package/dist/test-utils/contract.d.ts +17 -0
- package/dist/test-utils/contract.d.ts.map +1 -0
- package/dist/test-utils/contract.js +261 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +74 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +544 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.tsx +493 -0
- package/src/components/PhotonPatient.tsx +184 -0
- package/src/components/PhotonPrescription.tsx +605 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -0
- package/src/components/TreatmentPicker.tsx +350 -0
- package/src/components/activity.ts +23 -0
- package/src/components/display.ts +278 -0
- package/src/components/flow.ts +67 -0
- package/src/components/format.ts +73 -0
- package/src/components/index.ts +5 -0
- package/src/components/open.ts +100 -0
- package/src/components/patient/Benefits.tsx +125 -0
- package/src/components/patient/Clinical.tsx +210 -0
- package/src/components/patient/IntakeForm.tsx +532 -0
- package/src/components/patient/Summary.tsx +310 -0
- package/src/components/patient/fields.tsx +144 -0
- package/src/components/patient/query.ts +77 -0
- package/src/components/search.tsx +377 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useLatestCallback.ts +16 -0
- package/src/hooks/useLive.ts +21 -0
- package/src/hooks/useOnChange.ts +34 -0
- package/src/hooks/useSession.ts +11 -0
- package/src/index.ts +19 -0
- package/src/primitives/PhotonProvider.tsx +153 -0
- package/src/primitives/defaults.tsx +409 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +276 -0
- package/src/styles.css +611 -0
- package/src/test-utils/contract.tsx +410 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/** The patient's clinical lists — allergies, medications, diagnoses — and which server changes belong to them. */
|
|
2
|
+
import { type ChangeOption, type ClassifiedChanges } from "@photonhealth/client";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
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
|
+
|
|
10
|
+
/** Which clinical list a server change belongs to (keys look like "clinical.allergies.add.0" / "allergies.0"). */
|
|
11
|
+
const CLINICAL_SECTIONS = ["allergies", "medications", "diagnoses"] as const;
|
|
12
|
+
export const sectionOf = (key: string) => CLINICAL_SECTIONS.find((section) => key.includes(section)) ?? null;
|
|
13
|
+
export const choicesIn = (choices: ClassifiedChanges["needsChoice"], section: (typeof CLINICAL_SECTIONS)[number]) =>
|
|
14
|
+
choices.filter((c) => sectionOf(c.key) === section);
|
|
15
|
+
/** Everything but what a clinical list shows under its own field — its choices and its problems (e.g. a rejected name). */
|
|
16
|
+
export const withoutInline = (changes: ClassifiedChanges): ClassifiedChanges => ({
|
|
17
|
+
...changes,
|
|
18
|
+
needsChoice: changes.needsChoice.filter((c) => !sectionOf(c.key)),
|
|
19
|
+
blocking: changes.blocking.filter((c) => !sectionOf(c.key)),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/** An ICD-10 code ("J02.0") goes as a code; anything else as free text for the server to resolve. */
|
|
23
|
+
export const diagnosisRef = (text: string) =>
|
|
24
|
+
/^[A-TV-Z]\d{2}(\.[0-9A-Z]{1,4})?$/i.test(text) ? { icd10Code: text.toUpperCase() } : { name: text };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 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, docs/api-gaps.md).
|
|
29
|
+
*
|
|
30
|
+
* "Add …" is a search field (search.tsx) — type-ahead, its spinner, its results (the server's choices, e.g.
|
|
31
|
+
* which penicillin) and keys. Each search is an add, by design: what's typed, once it matches one entry, is that
|
|
32
|
+
* 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,
|
|
33
|
+
* leaving it, a choice) is answered. Escape closes it.
|
|
34
|
+
*/
|
|
35
|
+
export function ClinicalList<T extends { id: string; name: string }>({
|
|
36
|
+
label,
|
|
37
|
+
items,
|
|
38
|
+
tone,
|
|
39
|
+
addLabel,
|
|
40
|
+
noneLabel,
|
|
41
|
+
noneAction,
|
|
42
|
+
confirmedNone,
|
|
43
|
+
unknownLabel,
|
|
44
|
+
pickedNames,
|
|
45
|
+
saving,
|
|
46
|
+
onAdd,
|
|
47
|
+
onRemove,
|
|
48
|
+
onNone,
|
|
49
|
+
choices,
|
|
50
|
+
problems = [],
|
|
51
|
+
onChoose,
|
|
52
|
+
}: {
|
|
53
|
+
label: string;
|
|
54
|
+
items: T[];
|
|
55
|
+
tone: "warning" | "neutral";
|
|
56
|
+
addLabel: string;
|
|
57
|
+
/** Offer "none" (e.g. No known allergies). Omit for lists where "none" isn't worth recording. */
|
|
58
|
+
noneLabel?: string;
|
|
59
|
+
/** The button that records "none" (e.g. "Mark NKDA") — an action, so it can't be read as a status. */
|
|
60
|
+
noneAction?: string;
|
|
61
|
+
/** "None" was recorded this session. */
|
|
62
|
+
confirmedNone?: boolean;
|
|
63
|
+
/** Shown when the server returns no real name (today allergies come back with name = id). */
|
|
64
|
+
unknownLabel: string;
|
|
65
|
+
/** Names the prescriber picked this session, by id — shown when the server returns only the id. */
|
|
66
|
+
pickedNames: Readonly<Record<string, string>>;
|
|
67
|
+
saving: boolean;
|
|
68
|
+
onAdd: (name: string) => void;
|
|
69
|
+
onRemove: (item: T) => void;
|
|
70
|
+
onNone?: () => void;
|
|
71
|
+
/** The server's choices for what was just entered (e.g. which penicillin) — shown right under the field. */
|
|
72
|
+
choices: ClassifiedChanges["needsChoice"];
|
|
73
|
+
/** What the server rejected for this list (e.g. a name nothing matches) — shown in the same place. */
|
|
74
|
+
problems?: ClassifiedChanges["blocking"];
|
|
75
|
+
onChoose: (option: ChangeOption) => void;
|
|
76
|
+
}) {
|
|
77
|
+
const { Badge, Button, Input, Row, Stack, Text } = useComponents();
|
|
78
|
+
const [adding, setAdding] = useState(false);
|
|
79
|
+
const [value, setValue] = useState("");
|
|
80
|
+
const [sent, setSent] = useState("");
|
|
81
|
+
// This list's call (an add, or a choice) is in flight: its field spins. Answered with nothing left to
|
|
82
|
+
// choose after the prescriber committed (not just paused typing), the entry is on the list: it closes.
|
|
83
|
+
const [asked, setAsked] = useState(false);
|
|
84
|
+
const [committed, setCommitted] = useState(false);
|
|
85
|
+
// How many entries were on the list when this field first sent: one more, and it's added.
|
|
86
|
+
const [before, setBefore] = useState<number | null>(null);
|
|
87
|
+
// Done with the field (state only — also from render, once an answer lands; a search still waiting finds
|
|
88
|
+
// it empty and sends nothing).
|
|
89
|
+
const reset = () => {
|
|
90
|
+
setValue("");
|
|
91
|
+
setSent("");
|
|
92
|
+
setCommitted(false);
|
|
93
|
+
setBefore(null);
|
|
94
|
+
setAdding(false);
|
|
95
|
+
};
|
|
96
|
+
if (asked && !saving) {
|
|
97
|
+
setAsked(false);
|
|
98
|
+
if (committed && !choices.length && !problems.length) reset(); // rejected: stays, to fix what's typed
|
|
99
|
+
}
|
|
100
|
+
if (adding && before !== null && items.length > before && !saving && !choices.length) reset();
|
|
101
|
+
// Spins while what it sent — and a match core takes after it — is in flight.
|
|
102
|
+
const spinning = useHeldActivity(adding && before !== null && saving ? "add" : null) === "add";
|
|
103
|
+
const results = useRef<SearchHandle | null>(null);
|
|
104
|
+
const field = useRef<HTMLDivElement>(null);
|
|
105
|
+
const none = Boolean(confirmedNone) && items.length === 0;
|
|
106
|
+
|
|
107
|
+
/** Add what's typed — unless it was just sent. */
|
|
108
|
+
const send = (name: string) => {
|
|
109
|
+
if (name === sent) return false;
|
|
110
|
+
setSent(name);
|
|
111
|
+
setAsked(true);
|
|
112
|
+
if (before === null) setBefore(items.length);
|
|
113
|
+
onAdd(name);
|
|
114
|
+
return true;
|
|
115
|
+
};
|
|
116
|
+
const typeAhead = useTypeAhead(() => value.trim() && send(value.trim()), { minChars: 3 });
|
|
117
|
+
const close = () => {
|
|
118
|
+
typeAhead.cancel();
|
|
119
|
+
reset();
|
|
120
|
+
};
|
|
121
|
+
/** Enter or leaving the field: add it now; once it's on the list, the field closes. */
|
|
122
|
+
const add = () => {
|
|
123
|
+
typeAhead.cancel();
|
|
124
|
+
const name = value.trim();
|
|
125
|
+
if (!name) return close();
|
|
126
|
+
setCommitted(true);
|
|
127
|
+
// Typing already added it, and that's answered: nothing left to wait for.
|
|
128
|
+
if (!send(name) && !saving && !choices.length && !problems.length) close();
|
|
129
|
+
};
|
|
130
|
+
const choose = (option: ChangeOption) => {
|
|
131
|
+
setCommitted(true);
|
|
132
|
+
setAsked(true);
|
|
133
|
+
onChoose(option);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Stack gap="2">
|
|
138
|
+
<Row gap="2" justify="between">
|
|
139
|
+
<Row gap="2">
|
|
140
|
+
<strong>{label}</strong>
|
|
141
|
+
{!adding && (
|
|
142
|
+
<Button variant="ghost" aria-label={addLabel} title={addLabel} onClick={() => setAdding(true)} icon="add" />
|
|
143
|
+
)}
|
|
144
|
+
{items.map((item) => {
|
|
145
|
+
const name = item.name && item.name !== item.id ? item.name : (pickedNames[item.id] ?? unknownLabel);
|
|
146
|
+
return (
|
|
147
|
+
<Badge key={item.id} tone={tone} onRemove={() => onRemove(item)} removeLabel={`Remove ${name}`}>
|
|
148
|
+
{name}
|
|
149
|
+
</Badge>
|
|
150
|
+
);
|
|
151
|
+
})}
|
|
152
|
+
{none && noneLabel && <Badge tone="success">{noneLabel}</Badge>}
|
|
153
|
+
{/* network-api can't tell "never asked" from "none" (docs/api-gaps.md): say which we know. */}
|
|
154
|
+
{noneLabel && !none && items.length === 0 && !adding && <Text tone="tertiary">Not recorded</Text>}
|
|
155
|
+
</Row>
|
|
156
|
+
{noneLabel && onNone && !adding && items.length === 0 && !none && (
|
|
157
|
+
<Button
|
|
158
|
+
variant="ghost"
|
|
159
|
+
onClick={onNone} // never disabled by another save: calls are queued
|
|
160
|
+
// "Mark none" on several lists: each named for its own.
|
|
161
|
+
aria-label={noneAction === "Mark none" ? `Mark no ${label.toLowerCase()}` : undefined}
|
|
162
|
+
>
|
|
163
|
+
{noneAction ?? noneLabel}
|
|
164
|
+
</Button>
|
|
165
|
+
)}
|
|
166
|
+
</Row>
|
|
167
|
+
{(adding || choices.length > 0 || problems.length > 0) && (
|
|
168
|
+
<div ref={field}>
|
|
169
|
+
<Stack gap="2">
|
|
170
|
+
{adding && (
|
|
171
|
+
<Input
|
|
172
|
+
label={addLabel}
|
|
173
|
+
value={value}
|
|
174
|
+
autoFocus
|
|
175
|
+
loading={spinning}
|
|
176
|
+
{...noAutofill}
|
|
177
|
+
onChange={(e) => {
|
|
178
|
+
setValue(e.target.value);
|
|
179
|
+
typeAhead.typed("add", e.target.value);
|
|
180
|
+
}}
|
|
181
|
+
onBlur={(e) => {
|
|
182
|
+
// Into its results isn't leaving; anywhere else sends what's typed (or closes an empty field).
|
|
183
|
+
if (field.current?.contains(e.relatedTarget) || results.current?.pointing?.()) return;
|
|
184
|
+
afterPress(add); // e.g. pressing "Mark none" below: it mustn't move before the click lands
|
|
185
|
+
}}
|
|
186
|
+
onKeyDown={(e) => {
|
|
187
|
+
if (searchKeys(e, results.current, value.trim() === sent && !saving)) return;
|
|
188
|
+
if (e.key === "Enter") {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
add();
|
|
191
|
+
}
|
|
192
|
+
if (e.key === "Escape") close();
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
{(choices.length > 0 || problems.length > 0) && (
|
|
197
|
+
<ChangeList
|
|
198
|
+
changes={{ needsChoice: choices, blocking: problems, advisories: [], applied: [], settled: false }}
|
|
199
|
+
onChoose={choose}
|
|
200
|
+
busy={saving}
|
|
201
|
+
handleRef={results}
|
|
202
|
+
onBack={() => field.current?.querySelector("input")?.focus()}
|
|
203
|
+
/>
|
|
204
|
+
)}
|
|
205
|
+
</Stack>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
</Stack>
|
|
209
|
+
);
|
|
210
|
+
}
|