@photonhealth/react 2.0.0-rc.1 → 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 +52 -9
- 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 +19 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +76 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- 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/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/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 +19 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +41 -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 +18 -18
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +34 -19
- 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 +6 -78
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +15 -26
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +6 -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/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/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/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} +6 -5
- package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
- package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +15 -16
- package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +29 -28
- 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 -26
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +11 -52
- 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 -10
- package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +51 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +186 -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 +13 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +25 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/components/search.d.ts +1 -1
- package/dist/components/search.js +1 -1
- 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 +8 -3
- package/src/adapters/tailwind.tsx +52 -24
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +190 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +151 -0
- package/src/analytics/cardLifecycle.test.tsx +272 -0
- package/src/analytics/cardLifecycle.ts +44 -0
- package/src/analytics/fieldInteraction.test.tsx +186 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/lifecycleOutcomes.test.ts +78 -0
- package/src/analytics/lifecycleOutcomes.ts +29 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +49 -0
- package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/PhotonOrder.test.tsx +394 -0
- package/src/components/PhotonOrder.tsx +79 -53
- package/src/components/PhotonPatient.tsx +15 -166
- package/src/components/PhotonPrescription.test.tsx +120 -0
- package/src/components/PhotonPrescription.tsx +23 -583
- package/src/components/ScreeningAlerts.test.tsx +81 -0
- package/src/components/format.ts +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/open.ts +13 -16
- package/src/components/order/DraftOrderPrompt.test.tsx +77 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- 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} +24 -16
- package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
- package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +53 -48
- 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 -124
- package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
- package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -15
- package/src/components/prescription/PrescriptionCard.test.tsx +247 -0
- package/src/components/prescription/PrescriptionCard.tsx +361 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +82 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +206 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +453 -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 +72 -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 +695 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +34 -0
- package/src/components/search.tsx +1 -1
- package/src/index.ts +2 -0
- package/src/meta/version.test.ts +11 -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/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 -324
- 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 -80
- package/dist/components/patient/Summary.js.map +0 -1
- package/dist/components/patient/query.d.ts +0 -23
- package/dist/components/patient/query.d.ts.map +0 -1
- package/dist/components/patient/query.js.map +0 -1
- package/src/components/TreatmentPicker.tsx +0 -350
- package/src/components/patient/IntakeForm.tsx +0 -532
- package/src/components/patient/Summary.tsx +0 -310
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { Change, ChangeOption, Prescription, PrescriptionEdits, PrescriptionRecord } from "@photonhealth/client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useLatestCallback } from "../../../hooks/index.ts";
|
|
4
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
5
|
+
import { focusProps, searchProps } from "../../flow.ts";
|
|
6
|
+
import { FEW, searchKeys, useTypeAhead } from "../../search.tsx";
|
|
7
|
+
import { TreatmentPicker, type TreatmentPickerHandle } from "./TreatmentPicker.tsx";
|
|
8
|
+
import { useFieldInteractions } from "../../../analytics/fieldInteraction.tsx";
|
|
9
|
+
|
|
10
|
+
/** A drug chosen from one of the server's choices: the choice, and the option taken. */
|
|
11
|
+
export interface TreatmentChoice {
|
|
12
|
+
change: Change;
|
|
13
|
+
option: ChangeOption;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TreatmentSearchProps {
|
|
17
|
+
live: Prescription | null;
|
|
18
|
+
rx: PrescriptionRecord | null;
|
|
19
|
+
/** The drug picked before the line has a record (the server drafts it once the patient is known). */
|
|
20
|
+
pickId: string | null;
|
|
21
|
+
/** The server's choices for the drug typed. */
|
|
22
|
+
drugChoices: readonly Change[];
|
|
23
|
+
/** A product chosen, saving: nothing to pick until the server answers. */
|
|
24
|
+
choosing: TreatmentChoice | null;
|
|
25
|
+
/** Shown until a product is set. Kept mounted while closed. */
|
|
26
|
+
open: boolean;
|
|
27
|
+
busy: boolean;
|
|
28
|
+
/** The field whose save is in flight. */
|
|
29
|
+
spinning: string | null;
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
/** Put the cursor in Treatment each time this changes. */
|
|
32
|
+
focusSignal?: number;
|
|
33
|
+
save: (edits: PrescriptionEdits, from?: string) => void;
|
|
34
|
+
onChoose: (choice: TreatmentChoice) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function TreatmentSearch({
|
|
38
|
+
live,
|
|
39
|
+
rx,
|
|
40
|
+
pickId,
|
|
41
|
+
drugChoices,
|
|
42
|
+
choosing,
|
|
43
|
+
open,
|
|
44
|
+
busy,
|
|
45
|
+
spinning,
|
|
46
|
+
autoFocus,
|
|
47
|
+
focusSignal,
|
|
48
|
+
save,
|
|
49
|
+
onChoose,
|
|
50
|
+
}: TreatmentSearchProps) {
|
|
51
|
+
const { Input } = useComponents();
|
|
52
|
+
const treatmentField = useFieldInteractions("add_prescription_form")("treatment", { isOptional: false });
|
|
53
|
+
const [treatment, setTreatment] = useState(rx?.treatment.name ?? "");
|
|
54
|
+
// Only send free-text medication when it actually changed (see submitTreatment).
|
|
55
|
+
const [sentTreatment, setSentTreatment] = useState(rx?.treatment.name ?? "");
|
|
56
|
+
|
|
57
|
+
// When the server's copy changes (a hydrate, a chosen option, signing), show its drug.
|
|
58
|
+
// Adjusted during render, keyed on id + contentHash — React's pattern for deriving state from props.
|
|
59
|
+
const serverKey = rx ? `${rx.id}:${rx.signing.contentHash}:${rx.signing.state}` : null;
|
|
60
|
+
const [syncedKey, setSyncedKey] = useState(serverKey);
|
|
61
|
+
if (rx && serverKey !== syncedKey) {
|
|
62
|
+
setSyncedKey(serverKey);
|
|
63
|
+
const shownName = live?.name ?? rx.treatment.name;
|
|
64
|
+
setTreatment(shownName);
|
|
65
|
+
setSentTreatment(shownName); // what's shown was the pick — leaving the field mustn't re-send it as text
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A line without a record shows the drug entered on it — e.g. given as props: once per object.
|
|
69
|
+
const [filledFrom, setFilledFrom] = useState<Prescription | null>(null);
|
|
70
|
+
if (live && live !== filledFrom) {
|
|
71
|
+
setFilledFrom(live);
|
|
72
|
+
const text = live.name ?? (rx ? undefined : live.entered.treatment?.name);
|
|
73
|
+
if (!rx && text) {
|
|
74
|
+
setTreatment(text);
|
|
75
|
+
setSentTreatment(text); // already sent: leaving the field mustn't send it again
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The pick's name — never its id (a drug given by id alone is named once it's drafted).
|
|
80
|
+
const [shownPick, setShownPick] = useState(pickId);
|
|
81
|
+
if (pickId !== shownPick) {
|
|
82
|
+
setShownPick(pickId);
|
|
83
|
+
const name = pickId && live?.name;
|
|
84
|
+
if (name) {
|
|
85
|
+
setTreatment(name);
|
|
86
|
+
setSentTreatment(name);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const picker = useRef<TreatmentPickerHandle | null>(null);
|
|
91
|
+
// Treatment works like a select: the drug picked from the list (its name is the field's value), and whether the
|
|
92
|
+
// list of drugs is open — else the picked drug's form and strength show under the field.
|
|
93
|
+
const [drug, setDrug] = useState<string | null>(null);
|
|
94
|
+
const [listOpen, setListOpen] = useState(true);
|
|
95
|
+
// The Input building block takes no ref, so focus reaches its field through a wrapper.
|
|
96
|
+
const searchBox = useRef<HTMLDivElement>(null);
|
|
97
|
+
const focusField = () => searchBox.current?.querySelector("input")?.focus();
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (focusSignal) focusField();
|
|
100
|
+
}, [focusSignal]);
|
|
101
|
+
|
|
102
|
+
// Only send free-text medication when it actually changed. Otherwise clicking one of the server's
|
|
103
|
+
// choices blurs this field first, re-sends the same text, and the "saving" state swallows the click.
|
|
104
|
+
const submitTreatment = () => {
|
|
105
|
+
const text = treatment.trim();
|
|
106
|
+
if (!text || text === sentTreatment || text === rx?.treatment.name) return;
|
|
107
|
+
setSentTreatment(text);
|
|
108
|
+
save({ treatment: { name: text } }, "treatment");
|
|
109
|
+
};
|
|
110
|
+
// Type-ahead: once there are 3+ characters, the medication text is sent when typing pauses — before the
|
|
111
|
+
// record it's a lookup (the object aborts the one for older text), and the server's choices render live
|
|
112
|
+
// below. Enter / blur send at once; unchanged text is never re-sent (so a wait that ends after them is a no-op).
|
|
113
|
+
// Not two, as a patient's name: two letters of a drug match thousands of products.
|
|
114
|
+
const typeAhead = useTypeAhead(submitTreatment, { minChars: 3 });
|
|
115
|
+
|
|
116
|
+
// A drug picked: its name in the field (already looked up — leaving the field mustn't send it), the list closed.
|
|
117
|
+
const showDrug = (name: string | null) => {
|
|
118
|
+
typeAhead.cancel();
|
|
119
|
+
setDrug(name);
|
|
120
|
+
setListOpen(false);
|
|
121
|
+
setTreatment(name ?? "");
|
|
122
|
+
setSentTreatment(name ?? "");
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// The drugs to pick from: none while a product chosen saves (it heads the card at once).
|
|
126
|
+
const shownChoices = choosing ? [] : drugChoices;
|
|
127
|
+
const pickerUp = shownChoices.length > 0;
|
|
128
|
+
|
|
129
|
+
// A few drugs for what's typed, and the prescriber is still in Treatment: focus goes to the first, ready to
|
|
130
|
+
// pick — typing carries on in Treatment (search.tsx). Once per answer.
|
|
131
|
+
const choicesFor = drugChoices[0]
|
|
132
|
+
? `${drugChoices[0].inputText}|${drugChoices[0].options.map((o) => o.displayName).join("|")}`
|
|
133
|
+
: null;
|
|
134
|
+
// A new answer opens the list on its drugs, nothing picked.
|
|
135
|
+
const [listedFor, setListedFor] = useState(choicesFor);
|
|
136
|
+
if (choicesFor !== listedFor) {
|
|
137
|
+
setListedFor(choicesFor);
|
|
138
|
+
if (choicesFor) {
|
|
139
|
+
setDrug(null);
|
|
140
|
+
setListOpen(true);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const focusedFor = useRef<string | null>(null);
|
|
144
|
+
const focusFew = useLatestCallback(() => {
|
|
145
|
+
const field = searchBox.current?.querySelector("input");
|
|
146
|
+
const answered = treatment.trim() === sentTreatment && !busy && !typeAhead.waiting();
|
|
147
|
+
if (!choicesFor || !answered || !field || document.activeElement !== field) return;
|
|
148
|
+
if (focusedFor.current === choicesFor || (picker.current?.total ?? FEW) >= FEW) return;
|
|
149
|
+
focusedFor.current = choicesFor;
|
|
150
|
+
picker.current!.focus(true);
|
|
151
|
+
});
|
|
152
|
+
useEffect(() => focusFew(), [choicesFor, busy, focusFew]);
|
|
153
|
+
|
|
154
|
+
if (!open) return null;
|
|
155
|
+
return (
|
|
156
|
+
<div style={{ display: "contents" }} {...treatmentField}>
|
|
157
|
+
{/* Where the card flow (← / →) lands: the drug list while choosing, else Treatment. */}
|
|
158
|
+
<div ref={searchBox} {...searchProps} {...(pickerUp ? {} : focusProps)}>
|
|
159
|
+
<Input
|
|
160
|
+
label="Treatment"
|
|
161
|
+
autoFocus={autoFocus}
|
|
162
|
+
value={treatment}
|
|
163
|
+
onChange={(e) => {
|
|
164
|
+
setTreatment(e.target.value);
|
|
165
|
+
setDrug(null); // typing searches anew: the list, with no drug picked
|
|
166
|
+
setListOpen(true);
|
|
167
|
+
typeAhead.typed("treatment", e.target.value);
|
|
168
|
+
}}
|
|
169
|
+
// The picked drug's field, clicked: the last search's drugs again, without searching.
|
|
170
|
+
onClick={() => drug && !listOpen && setListOpen(true)}
|
|
171
|
+
onBlur={submitTreatment}
|
|
172
|
+
loading={spinning === "treatment"}
|
|
173
|
+
clearLabel="Clear treatment"
|
|
174
|
+
onClear={() => {
|
|
175
|
+
showDrug(null);
|
|
176
|
+
focusField();
|
|
177
|
+
}}
|
|
178
|
+
onKeyDown={(e) => {
|
|
179
|
+
// Esc with the list open over a picked drug: closed again, back to its form and strength.
|
|
180
|
+
if (e.key === "Escape" && drug && listOpen) {
|
|
181
|
+
setListOpen(false);
|
|
182
|
+
return e.preventDefault();
|
|
183
|
+
}
|
|
184
|
+
const choices = pickerUp ? picker.current : null;
|
|
185
|
+
// A search field over the drugs (searchKeys); and Enter is on the open drug when the
|
|
186
|
+
// choices are for what's typed (chosen if it's one product, else on to its chips).
|
|
187
|
+
const answered = treatment.trim() === sentTreatment && !busy;
|
|
188
|
+
if (searchKeys(e, choices, answered)) return;
|
|
189
|
+
if (e.key === "Enter" && choices && treatment.trim() === sentTreatment) choices.enter();
|
|
190
|
+
else if (e.key === "Enter") submitTreatment();
|
|
191
|
+
else return;
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
{/* Which drug? — grouped by drug / form / strength. */}
|
|
197
|
+
{pickerUp && (
|
|
198
|
+
<div {...focusProps}>
|
|
199
|
+
{shownChoices.map((change) => (
|
|
200
|
+
<TreatmentPicker
|
|
201
|
+
// Each search's own: what's picked in one doesn't carry over to the next.
|
|
202
|
+
key={`${change.key}:${change.inputText ?? ""}`}
|
|
203
|
+
change={change}
|
|
204
|
+
drug={drug}
|
|
205
|
+
listOpen={listOpen}
|
|
206
|
+
onDrug={(name) => {
|
|
207
|
+
treatmentField.onChange(true);
|
|
208
|
+
showDrug(name);
|
|
209
|
+
}}
|
|
210
|
+
onChoose={(option) => onChoose({ change, option })}
|
|
211
|
+
busy={busy}
|
|
212
|
+
handleRef={picker}
|
|
213
|
+
onBack={focusField}
|
|
214
|
+
/>
|
|
215
|
+
))}
|
|
216
|
+
</div>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { schemaErrors } from "./schemaErrors.ts";
|
|
4
|
+
|
|
5
|
+
const name = z.string().min(1, "Required");
|
|
6
|
+
|
|
7
|
+
describe("schemaErrors", () => {
|
|
8
|
+
it("returns no errors when the input is valid", () => {
|
|
9
|
+
expect(schemaErrors(z.object({ name }), { name: "Ada" })).toEqual({});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns error messages in the same shape as the input", () => {
|
|
13
|
+
const schema = z.object({ first: name, last: name, age: z.number().gt(0, "Must be greater than 0") });
|
|
14
|
+
expect(schemaErrors(schema, { first: "", last: "Lovelace", age: 0 })).toEqual({
|
|
15
|
+
first: "Required",
|
|
16
|
+
age: "Must be greater than 0",
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("returns nested error message when the input is also nested", () => {
|
|
21
|
+
const schema = z.object({ patient: z.object({ name: z.object({ first: name, last: name }) }) });
|
|
22
|
+
expect(schemaErrors(schema, { patient: { name: { first: "", last: "Lovelace" } } })).toEqual({
|
|
23
|
+
patient: { name: { first: "Required" } },
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("returns messages that are for a parent and its nested children", () => {
|
|
28
|
+
const schema = z.object({
|
|
29
|
+
range: z
|
|
30
|
+
.object({ from: z.number(), to: z.number().gt(0, "Must be greater than 0") })
|
|
31
|
+
.refine((r) => r.from <= r.to, { message: "From must come first", path: [] }),
|
|
32
|
+
});
|
|
33
|
+
// zod checks the whole range only once its parts parse.
|
|
34
|
+
expect(schemaErrors(schema, { range: { from: 1, to: 0 } })).toEqual({ range: { to: "Must be greater than 0" } });
|
|
35
|
+
expect(schemaErrors(schema, { range: { from: 5, to: 2 } })).toEqual({ range: "From must come first" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("returns an array item's error messages at its index", () => {
|
|
39
|
+
const schema = z.object({ refills: z.array(z.object({ date: name })) });
|
|
40
|
+
expect(schemaErrors(schema, { refills: [{ date: "2026-11-06" }, { date: "" }] })).toEqual({
|
|
41
|
+
refills: { 1: { date: "Required" } },
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("returns only a field's first message when it has several", () => {
|
|
46
|
+
const schema = z.object({ code: z.string().min(3, "Too short").regex(/^\d+$/, "Digits only") });
|
|
47
|
+
expect(schemaErrors(schema, { code: "a" })).toEqual({ code: "Too short" });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Simplified error object shape that mirros the Zod schema shape */
|
|
4
|
+
export type SchemaErrors<T> = T extends readonly (infer Item)[]
|
|
5
|
+
? { [index: number]: SchemaErrors<Item> | undefined }
|
|
6
|
+
: T extends object
|
|
7
|
+
? { [K in keyof T]?: SchemaErrors<T[K]> }
|
|
8
|
+
: string;
|
|
9
|
+
|
|
10
|
+
type Node = Record<PropertyKey, unknown>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return errors from Zod schema.parse in a friendlier shape. The input is `unknown`: it is what the form holds before
|
|
14
|
+
* validation, which the schema must be able to refuse.
|
|
15
|
+
*/
|
|
16
|
+
export function schemaErrors<S extends z.ZodType<unknown, object>>(
|
|
17
|
+
schema: S,
|
|
18
|
+
input: unknown,
|
|
19
|
+
): SchemaErrors<z.input<S>> {
|
|
20
|
+
const errors: Node = {};
|
|
21
|
+
const result = schema.safeParse(input);
|
|
22
|
+
if (result.success) return errors as SchemaErrors<z.input<S>>;
|
|
23
|
+
for (const issue of result.error.issues) {
|
|
24
|
+
if (issue.path.length === 0) continue;
|
|
25
|
+
let node: Node | undefined = errors;
|
|
26
|
+
for (const key of issue.path.slice(0, -1)) {
|
|
27
|
+
const next: unknown = (node[key] ??= {});
|
|
28
|
+
node = typeof next === "object" ? (next as Node) : undefined;
|
|
29
|
+
if (!node) break;
|
|
30
|
+
}
|
|
31
|
+
if (node) node[issue.path.at(-1)!] ??= issue.message;
|
|
32
|
+
}
|
|
33
|
+
return errors as SchemaErrors<z.input<S>>;
|
|
34
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* patient search 2, drugs and clinical entries 3) and typing pauses, it searches; each
|
|
7
7
|
* keystroke cancels the search waiting, and the live object aborts one in flight. Leaving the field (or
|
|
8
8
|
* Enter) sends at once. Patients and drugs search without writing; for allergies, meds and diagnoses a
|
|
9
|
-
* search is an add — a unique match is the entry (see
|
|
9
|
+
* search is an add — a unique match is the entry (see ClinicalInputForm).
|
|
10
10
|
* - Results (`SearchResults`): the first five, then "Show N more". In the list, 1–9 and 0 pick one (of those shown),
|
|
11
11
|
* ↑ ↓ (or K J) move, Home / End (or g / G) go to the first / last, and Esc goes back to the field that searched
|
|
12
12
|
* (← → and h l are the card flow's, / its search box: flow.ts).
|
package/src/index.ts
CHANGED
|
@@ -15,5 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export * from "./primitives/index.ts";
|
|
17
17
|
export { useLive, useSession } from "./hooks/index.ts";
|
|
18
|
+
export { PhotonAnalyticsProvider, usePhotonAnalytics } from "./analytics/PhotonAnalyticsProvider.tsx";
|
|
19
|
+
export type { AnalyticsProperties } from "./analytics/tracker.ts";
|
|
18
20
|
export { PhotonOrder, PhotonPatient, PhotonPrescription } from "./components/index.ts";
|
|
19
21
|
export type { PhotonOrderProps, PhotonPatientProps, PhotonPrescriptionProps } from "./components/index.ts";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { reactPackage } from "./version.ts";
|
|
5
|
+
|
|
6
|
+
describe("reactPackage", () => {
|
|
7
|
+
it("is package.json's name and version: bump both together", () => {
|
|
8
|
+
const manifest = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
9
|
+
expect(reactPackage).toEqual({ name: manifest.name, version: manifest.version });
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Photon, type PhotonEnvironment, type PhotonError, type SessionUser } from "@photonhealth/client";
|
|
2
|
+
import { PhotonContext } from "./photonContext.ts";
|
|
2
3
|
import { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
3
4
|
import { useLatestCallback } from "../hooks/useLatestCallback.ts";
|
|
5
|
+
import { PhotonAnalyticsProvider } from "../analytics/PhotonAnalyticsProvider.tsx";
|
|
6
|
+
import { trackerFor } from "../analytics/tracker.ts";
|
|
4
7
|
import { defaultComponents } from "./defaults.tsx";
|
|
5
8
|
import type { PhotonComponents } from "./types.ts";
|
|
9
|
+
import { useProvidedPhoton } from "./useProvidedPhoton.ts";
|
|
6
10
|
|
|
7
11
|
const ComponentsContext = createContext<PhotonComponents>(defaultComponents);
|
|
8
|
-
const PhotonContext = createContext<Photon | null>(null);
|
|
9
12
|
|
|
10
13
|
/** What `onAuth` reports: network-api took the instance's token, or why not. */
|
|
11
14
|
export type PhotonAuthCheck = { ok: true; error: null } | { ok: false; error: PhotonError };
|
|
@@ -52,6 +55,7 @@ const OrganizationContext = createContext<string | null>(null);
|
|
|
52
55
|
* when the host signs in itself).
|
|
53
56
|
* components optional — map any building blocks to your design system; the rest are unstyled defaults.
|
|
54
57
|
* onAuth optional — once signed in, whether network-api takes the token (one ping per instance).
|
|
58
|
+
* disableAnalytics optional — present or `true` turns analytics off; it's on by default.
|
|
55
59
|
*
|
|
56
60
|
* At any level of the page: a provider without a client inherits its parent's, and providers with the same
|
|
57
61
|
* `clientId` share one sign-in.
|
|
@@ -63,6 +67,7 @@ export function PhotonProvider({
|
|
|
63
67
|
organization,
|
|
64
68
|
components,
|
|
65
69
|
onAuth,
|
|
70
|
+
disableAnalytics,
|
|
66
71
|
children,
|
|
67
72
|
}: {
|
|
68
73
|
/** A Photon client of the host's own. Optional: a nested provider inherits its parent's. */
|
|
@@ -75,6 +80,7 @@ export function PhotonProvider({
|
|
|
75
80
|
organization?: string;
|
|
76
81
|
components?: Partial<PhotonComponents>;
|
|
77
82
|
onAuth?: (auth: PhotonAuthCheck) => void;
|
|
83
|
+
disableAnalytics?: boolean;
|
|
78
84
|
children: ReactNode;
|
|
79
85
|
}) {
|
|
80
86
|
const outerComponents = useContext(ComponentsContext);
|
|
@@ -85,15 +91,10 @@ export function PhotonProvider({
|
|
|
85
91
|
() => (components ? { ...outerComponents, ...components } : outerComponents),
|
|
86
92
|
[outerComponents, components],
|
|
87
93
|
);
|
|
88
|
-
|
|
89
|
-
const made = useMemo(
|
|
90
|
-
() => (!client && clientId ? photon({ environment, auth: { clientId }, organization }) : null),
|
|
91
|
-
[client, clientId, environment, organization],
|
|
92
|
-
);
|
|
93
|
-
const own = client ?? made;
|
|
94
|
+
const providedPhoton = useProvidedPhoton({ client, clientId, environment, organization });
|
|
94
95
|
|
|
95
96
|
// Sign-in, opportunistically: once per page however many providers share it.
|
|
96
|
-
const session =
|
|
97
|
+
const session = providedPhoton?.session ?? null;
|
|
97
98
|
useEffect(() => void session?.start(), [session]);
|
|
98
99
|
const signedIn = useSyncExternalStore(session?.subscribe ?? noSubscribe, () =>
|
|
99
100
|
session ? (session.status === "signed-in" ? session.user : null) : true,
|
|
@@ -104,31 +105,45 @@ export function PhotonProvider({
|
|
|
104
105
|
const [failed, setFailed] = useState<PhotonError | null>(null);
|
|
105
106
|
const [attempt, setAttempt] = useState(0);
|
|
106
107
|
const [checked, setChecked] = useState(0);
|
|
108
|
+
const [signInAcceptedByNetworkApi, setSignInAcceptedByNetworkApi] = useState<SessionUser | true | null>(null);
|
|
107
109
|
const report = useLatestCallback(onAuth);
|
|
108
110
|
const listening = Boolean(onAuth) || Boolean(session);
|
|
109
111
|
useEffect(() => {
|
|
110
|
-
if (!
|
|
112
|
+
if (!providedPhoton || !listening || !signedIn) return;
|
|
111
113
|
let live = true;
|
|
112
|
-
void checkAuth(
|
|
114
|
+
void checkAuth(providedPhoton, signedIn, attempt).then((auth) => {
|
|
113
115
|
if (!live) return;
|
|
114
116
|
setFailed(auth.error);
|
|
115
117
|
setChecked(attempt);
|
|
118
|
+
setSignInAcceptedByNetworkApi(auth.ok ? signedIn : null);
|
|
116
119
|
report(auth);
|
|
117
120
|
});
|
|
118
121
|
return () => {
|
|
119
122
|
live = false;
|
|
120
123
|
};
|
|
121
|
-
}, [
|
|
124
|
+
}, [providedPhoton, listening, signedIn, attempt, report]);
|
|
125
|
+
const coreManagesSignIn = session !== null;
|
|
126
|
+
const signedInToOrganization = Boolean(signedIn && session?.user?.organization);
|
|
127
|
+
const networkApiAcceptedSignIn = signedIn !== null && signInAcceptedByNetworkApi === signedIn;
|
|
128
|
+
const analyticsReady = !coreManagesSignIn || (signedInToOrganization && networkApiAcceptedSignIn);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (providedPhoton) trackerFor(providedPhoton).setReady(analyticsReady);
|
|
131
|
+
}, [providedPhoton, analyticsReady]);
|
|
132
|
+
|
|
122
133
|
const failure = useMemo(
|
|
123
134
|
() => (failed ? { error: failed, checking: checked !== attempt, retry: () => setAttempt((n) => n + 1) } : null),
|
|
124
135
|
[failed, checked, attempt],
|
|
125
136
|
);
|
|
126
137
|
|
|
127
138
|
return (
|
|
128
|
-
<PhotonContext.Provider value={
|
|
129
|
-
<CheckFailureContext.Provider value={
|
|
139
|
+
<PhotonContext.Provider value={providedPhoton ?? outerPhoton}>
|
|
140
|
+
<CheckFailureContext.Provider value={providedPhoton ? failure : outerFailure}>
|
|
130
141
|
<OrganizationContext.Provider value={organization ?? outerOrganization}>
|
|
131
|
-
<ComponentsContext.Provider value={blocks}>
|
|
142
|
+
<ComponentsContext.Provider value={blocks}>
|
|
143
|
+
<PhotonAnalyticsProvider enabled={disableAnalytics === undefined ? undefined : !disableAnalytics}>
|
|
144
|
+
{children}
|
|
145
|
+
</PhotonAnalyticsProvider>
|
|
146
|
+
</ComponentsContext.Provider>
|
|
132
147
|
</OrganizationContext.Provider>
|
|
133
148
|
</CheckFailureContext.Provider>
|
|
134
149
|
</PhotonContext.Provider>
|
|
@@ -75,8 +75,8 @@ export const defaultComponents: PhotonComponents = {
|
|
|
75
75
|
{children}
|
|
76
76
|
</span>
|
|
77
77
|
),
|
|
78
|
-
Card: ({ divided, children }) => (
|
|
79
|
-
<section className="prx-card" data-divided={divided || undefined}>
|
|
78
|
+
Card: ({ divided, label, children }) => (
|
|
79
|
+
<section className="prx-card" data-divided={divided || undefined} aria-label={label}>
|
|
80
80
|
{children}
|
|
81
81
|
</section>
|
|
82
82
|
),
|
|
@@ -124,23 +124,39 @@ export const defaultComponents: PhotonComponents = {
|
|
|
124
124
|
{children}
|
|
125
125
|
</button>
|
|
126
126
|
),
|
|
127
|
-
Input: ({ label, helper, invalid, errorMessage, className, loading, ...rest }) =>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
Input: ({ label, helper, invalid, errorMessage, className, loading, onClear, clearLabel = "Clear", ...rest }) => {
|
|
128
|
+
const clearable = Boolean(onClear) && !loading && String(rest.value ?? "") !== "";
|
|
129
|
+
return (
|
|
130
|
+
<Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
|
|
131
|
+
{({ id, describedBy }) => (
|
|
132
|
+
<span className="prx-input-wrap">
|
|
133
|
+
<input
|
|
134
|
+
{...rest}
|
|
135
|
+
id={id}
|
|
136
|
+
className={cx("prx-input", className)}
|
|
137
|
+
data-clearable={clearable || undefined}
|
|
138
|
+
aria-invalid={invalid || undefined}
|
|
139
|
+
aria-describedby={describedBy}
|
|
140
|
+
aria-busy={loading || undefined}
|
|
141
|
+
/>
|
|
142
|
+
{loading && <span className="prx-spinner" aria-hidden="true" />}
|
|
143
|
+
{clearable && (
|
|
144
|
+
<button
|
|
145
|
+
type="button"
|
|
146
|
+
className="prx-input-clear"
|
|
147
|
+
aria-label={clearLabel}
|
|
148
|
+
title={clearLabel}
|
|
149
|
+
disabled={rest.disabled}
|
|
150
|
+
onClick={onClear}
|
|
151
|
+
>
|
|
152
|
+
<Icon name="close" className="prx-icon" />
|
|
153
|
+
</button>
|
|
154
|
+
)}
|
|
155
|
+
</span>
|
|
156
|
+
)}
|
|
157
|
+
</Field>
|
|
158
|
+
);
|
|
159
|
+
},
|
|
144
160
|
Textarea: ({ label, helper, invalid, errorMessage, className, ...rest }) => (
|
|
145
161
|
<Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
|
|
146
162
|
{({ id, describedBy }) => (
|
|
@@ -284,10 +300,17 @@ export const defaultComponents: PhotonComponents = {
|
|
|
284
300
|
aria-current="true"
|
|
285
301
|
aria-busy={o.loading || undefined}
|
|
286
302
|
>
|
|
287
|
-
<
|
|
303
|
+
<button
|
|
304
|
+
type="button"
|
|
305
|
+
className="prx-option-row"
|
|
306
|
+
aria-expanded="true"
|
|
307
|
+
aria-label={o.ariaLabel}
|
|
308
|
+
disabled={disabled}
|
|
309
|
+
onClick={() => onSelect(o.key)}
|
|
310
|
+
>
|
|
288
311
|
{text}
|
|
289
312
|
{o.loading && <span className="prx-spinner prx-option-chevron" aria-hidden="true" />}
|
|
290
|
-
</
|
|
313
|
+
</button>
|
|
291
314
|
{children}
|
|
292
315
|
</div>
|
|
293
316
|
) : (
|
package/src/primitives/types.ts
CHANGED
|
@@ -53,6 +53,8 @@ export interface TextProps {
|
|
|
53
53
|
export interface CardProps {
|
|
54
54
|
/** Separate header / body / footer with rules. */
|
|
55
55
|
divided?: boolean;
|
|
56
|
+
/** Names the card: it's a region by this name (e.g. a prescription card, by its drug). */
|
|
57
|
+
label?: string;
|
|
56
58
|
children?: ReactNode;
|
|
57
59
|
}
|
|
58
60
|
export interface CardHeaderProps {
|
|
@@ -66,9 +68,12 @@ export interface CardFooterProps {
|
|
|
66
68
|
start?: ReactNode;
|
|
67
69
|
children?: ReactNode;
|
|
68
70
|
}
|
|
69
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* A small spinner, with a visible label saying what's happening ("Searching…", "Saving…") — or alone, where what's
|
|
73
|
+
* loading is plain from where it is (a card's body filling in). role="status".
|
|
74
|
+
*/
|
|
70
75
|
export interface SpinnerProps {
|
|
71
|
-
label
|
|
76
|
+
label?: string;
|
|
72
77
|
}
|
|
73
78
|
export interface CardSectionProps {
|
|
74
79
|
children?: ReactNode;
|
|
@@ -106,6 +111,13 @@ export type InputProps = FieldProps &
|
|
|
106
111
|
InputHTMLAttributes<HTMLInputElement> & {
|
|
107
112
|
/** Work is in flight for this field (e.g. its value is being searched): show a spinner in the field, set aria-busy. */
|
|
108
113
|
loading?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* A × button at the end of the field, named `clearLabel` ("Clear" unless said), shown while the field has a
|
|
116
|
+
* value and isn't loading (the spinner takes that place). Clicking it calls `onClear`; the caller empties the
|
|
117
|
+
* value.
|
|
118
|
+
*/
|
|
119
|
+
onClear?: () => void;
|
|
120
|
+
clearLabel?: string;
|
|
109
121
|
};
|
|
110
122
|
export type TextareaProps = FieldProps & TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
111
123
|
|
|
@@ -168,7 +180,7 @@ export const CHOICE_ACTION = "__action";
|
|
|
168
180
|
|
|
169
181
|
/**
|
|
170
182
|
* Options to pick from, one open at a time (e.g. the drugs matching what was typed). `label` names the
|
|
171
|
-
* list for assistive tech — not shown: the field that searched says what it's for. The `activeKey` row is open
|
|
183
|
+
* list for assistive tech — not shown: the field that searched says what it's for. The `activeKey` row is open and shows `children` (its details) under its heading — itself a button (`aria-expanded`) reporting the row's key, so the open row can be picked too;
|
|
172
184
|
* closed rows are buttons with a chevron. A `direct` row has no details: it's the choice itself, so it's a
|
|
173
185
|
* button with no chevron, open or not (open, it's drawn as the active row). A `loading` row (its choice is being
|
|
174
186
|
* saved) shows a spinner top right, where the chevron goes — on an open row too — and is aria-busy. `activeSelected` marks the open
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { photon, type Photon, type PhotonEnvironment } from "@photonhealth/client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
|
|
4
|
+
export function useProvidedPhoton({
|
|
5
|
+
client,
|
|
6
|
+
clientId,
|
|
7
|
+
environment,
|
|
8
|
+
organization,
|
|
9
|
+
}: {
|
|
10
|
+
client?: Photon;
|
|
11
|
+
clientId?: string;
|
|
12
|
+
environment: PhotonEnvironment;
|
|
13
|
+
organization?: string;
|
|
14
|
+
}): Photon | null {
|
|
15
|
+
// `organization` makes `frame()` links sign in to it without the picker.
|
|
16
|
+
const photonFromClientId = useMemo(
|
|
17
|
+
() => (!client && clientId ? photon({ environment, auth: { clientId }, organization }) : null),
|
|
18
|
+
[client, clientId, environment, organization],
|
|
19
|
+
);
|
|
20
|
+
return client ?? photonFromClientId;
|
|
21
|
+
}
|