@photonhealth/react 2.0.0-rc.2 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +5 -2
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.js +34 -15
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -1
- package/dist/analytics/cardLifecycle.d.ts +10 -0
- package/dist/analytics/cardLifecycle.d.ts.map +1 -0
- package/dist/analytics/cardLifecycle.js +43 -0
- package/dist/analytics/cardLifecycle.js.map +1 -0
- package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
- package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
- package/dist/analytics/lifecycleOutcomes.js +16 -0
- package/dist/analytics/lifecycleOutcomes.js.map +1 -0
- package/dist/analytics/tracker.d.ts +5 -3
- package/dist/analytics/tracker.d.ts.map +1 -1
- package/dist/analytics/tracker.js +10 -5
- package/dist/analytics/tracker.js.map +1 -1
- package/dist/components/PhotonOrder.d.ts +18 -18
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +17 -6
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts +7 -35
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +3 -77
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +14 -14
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +0 -1
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/open.d.ts +11 -13
- package/dist/components/open.d.ts.map +1 -1
- package/dist/components/open.js +7 -2
- package/dist/components/open.js.map +1 -1
- package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
- package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/PatientCard.js +101 -0
- package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
- package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
- package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
- package/dist/components/patient/PatientIntakeForm.js +114 -0
- package/dist/components/patient/PatientIntakeForm.js.map +1 -0
- package/dist/components/patient/PatientSearch.d.ts +12 -0
- package/dist/components/patient/PatientSearch.d.ts.map +1 -0
- package/dist/components/patient/PatientSearch.js +148 -0
- package/dist/components/patient/PatientSearch.js.map +1 -0
- package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
- package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +5 -5
- package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
- package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +13 -15
- package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +11 -11
- package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
- package/dist/components/patient/fields.d.ts +7 -25
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +11 -53
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
- package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
- package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -15
- package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +14 -8
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -1
- package/dist/components/prescription/PrescriptionCard.js +10 -3
- package/dist/components/prescription/PrescriptionCard.js.map +1 -1
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +6 -6
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -1
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +6 -6
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -1
- package/dist/components/schemaErrors.d.ts +3 -2
- package/dist/components/schemaErrors.d.ts.map +1 -1
- package/dist/components/schemaErrors.js +2 -1
- package/dist/components/schemaErrors.js.map +1 -1
- package/dist/components/search.d.ts +1 -1
- package/dist/components/search.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/meta/version.js +1 -1
- package/package.json +5 -2
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +0 -1
- package/src/analytics/PhotonAnalyticsProvider.tsx +75 -20
- package/src/analytics/cardLifecycle.test.tsx +272 -0
- package/src/analytics/cardLifecycle.ts +44 -0
- package/src/analytics/fieldInteraction.test.tsx +11 -9
- package/src/analytics/lifecycleOutcomes.test.ts +78 -0
- package/src/analytics/lifecycleOutcomes.ts +29 -0
- package/src/analytics/tracker.test.ts +1 -1
- package/src/analytics/tracker.ts +13 -6
- package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
- package/src/components/PhotonOrder.test.tsx +146 -8
- package/src/components/PhotonOrder.tsx +37 -26
- package/src/components/PhotonPatient.tsx +8 -163
- package/src/components/PhotonPrescription.test.tsx +22 -18
- package/src/components/PhotonPrescription.tsx +14 -14
- package/src/components/ScreeningAlerts.test.tsx +81 -0
- package/src/components/open.ts +13 -16
- package/src/components/order/DraftOrderPrompt.test.tsx +3 -6
- package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
- package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
- package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
- package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
- package/src/components/patient/PatientIntakeForm.tsx +222 -0
- package/src/components/patient/PatientSearch.test.tsx +204 -0
- package/src/components/patient/PatientSearch.tsx +221 -0
- package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
- package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +4 -4
- package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
- package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +23 -23
- package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
- package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
- package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
- package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
- package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
- package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
- package/src/components/patient/fields.tsx +12 -138
- package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
- package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -21
- package/src/components/prescription/PrescriptionCard.test.tsx +174 -12
- package/src/components/prescription/PrescriptionCard.tsx +28 -14
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +2 -5
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +3 -6
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +34 -37
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +14 -14
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +2 -5
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +3 -7
- package/src/components/schemaErrors.ts +3 -2
- package/src/components/search.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/meta/version.test.ts +1 -0
- package/src/meta/version.ts +1 -1
- package/dist/components/patient/Benefits.d.ts.map +0 -1
- package/dist/components/patient/Benefits.js.map +0 -1
- package/dist/components/patient/Clinical.d.ts.map +0 -1
- package/dist/components/patient/Clinical.js.map +0 -1
- package/dist/components/patient/IntakeForm.d.ts +0 -10
- package/dist/components/patient/IntakeForm.d.ts.map +0 -1
- package/dist/components/patient/IntakeForm.js +0 -333
- package/dist/components/patient/IntakeForm.js.map +0 -1
- package/dist/components/patient/Summary.d.ts +0 -48
- package/dist/components/patient/Summary.d.ts.map +0 -1
- package/dist/components/patient/Summary.js +0 -90
- package/dist/components/patient/Summary.js.map +0 -1
- package/dist/components/patient/query.d.ts +0 -37
- package/dist/components/patient/query.d.ts.map +0 -1
- package/dist/components/patient/query.js.map +0 -1
- package/src/components/patient/IntakeForm.test.tsx +0 -89
- package/src/components/patient/IntakeForm.tsx +0 -564
- package/src/components/patient/Summary.test.tsx +0 -106
- package/src/components/patient/Summary.tsx +0 -330
|
@@ -1,106 +0,0 @@
|
|
|
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, payload } from "@photonhealth/client/testing";
|
|
6
|
-
import { PhotonPatient } from "../../index.ts";
|
|
7
|
-
import { patient } from "../../../test/cards.fixtures.tsx";
|
|
8
|
-
import {
|
|
9
|
-
edited,
|
|
10
|
-
leaveField,
|
|
11
|
-
meAsPrescriber,
|
|
12
|
-
recordAnalytics,
|
|
13
|
-
type RecordedAnalytics,
|
|
14
|
-
typeInto,
|
|
15
|
-
unmountAndRestoreFetch,
|
|
16
|
-
withAnalytics,
|
|
17
|
-
} from "../../../test/analytics.fixtures.tsx";
|
|
18
|
-
|
|
19
|
-
let analytics: RecordedAnalytics;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
analytics = recordAnalytics();
|
|
22
|
-
});
|
|
23
|
-
afterEach(unmountAndRestoreFetch);
|
|
24
|
-
|
|
25
|
-
const editPatient = async () => {
|
|
26
|
-
render(<PhotonPatient patient="pat_1" />, {
|
|
27
|
-
wrapper: withAnalytics(
|
|
28
|
-
fakeNetworkApiClient({
|
|
29
|
-
...meAsPrescriber,
|
|
30
|
-
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
31
|
-
UpdatePatient: () => payload("patient", "PatientPayload", patient),
|
|
32
|
-
}).client,
|
|
33
|
-
),
|
|
34
|
-
});
|
|
35
|
-
await userEvent.click(await screen.findByRole("button", { name: "Edit patient" }));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
describe("PatientSummary: Field Interaction", () => {
|
|
39
|
-
it("editing a patient: each field visited sends focus, one change and blur as update_patient_form", async () => {
|
|
40
|
-
await editPatient();
|
|
41
|
-
await typeInto("First name", "Zqx");
|
|
42
|
-
await typeInto("Last name", "Zqx");
|
|
43
|
-
await userEvent.click(screen.getByLabelText("Date of birth"));
|
|
44
|
-
fireEvent.change(screen.getByLabelText("Date of birth"), { target: { value: "1991-02-03" } });
|
|
45
|
-
leaveField();
|
|
46
|
-
await userEvent.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "FEMALE");
|
|
47
|
-
leaveField();
|
|
48
|
-
await typeInto("Phone", "5555550100");
|
|
49
|
-
await typeInto("Email", "zqx@example.com");
|
|
50
|
-
await typeInto("Street", "Zqx");
|
|
51
|
-
await typeInto("Apt / suite", "Zqx");
|
|
52
|
-
await typeInto("City", "Zqx");
|
|
53
|
-
await typeInto("State", "{Backspace}Q");
|
|
54
|
-
await typeInto("ZIP", "99999");
|
|
55
|
-
for (const addLabel of ["Add allergy", "Add medication", "Add diagnosis"]) {
|
|
56
|
-
await userEvent.click(screen.getByRole("button", { name: addLabel }));
|
|
57
|
-
await userEvent.keyboard("Zqxentry");
|
|
58
|
-
leaveField();
|
|
59
|
-
}
|
|
60
|
-
await userEvent.click(screen.getByRole("button", { name: "Add insurance" }));
|
|
61
|
-
await userEvent.keyboard("987654");
|
|
62
|
-
await userEvent.tab();
|
|
63
|
-
await userEvent.keyboard("ZQXPCN");
|
|
64
|
-
leaveField();
|
|
65
|
-
|
|
66
|
-
const fields = {
|
|
67
|
-
firstName: false,
|
|
68
|
-
lastName: false,
|
|
69
|
-
dateOfBirth: false,
|
|
70
|
-
sex: false,
|
|
71
|
-
phone: true,
|
|
72
|
-
email: true,
|
|
73
|
-
address_street1: true,
|
|
74
|
-
address_street2: true,
|
|
75
|
-
address_city: true,
|
|
76
|
-
address_state: true,
|
|
77
|
-
address_zip: true,
|
|
78
|
-
allergies: true,
|
|
79
|
-
medications: true,
|
|
80
|
-
diagnoses: true,
|
|
81
|
-
insurance: true,
|
|
82
|
-
};
|
|
83
|
-
await analytics.expectEventLog([
|
|
84
|
-
"Prescribe Workflow Viewed",
|
|
85
|
-
...edited("firstName"),
|
|
86
|
-
...edited("lastName"),
|
|
87
|
-
...edited("dateOfBirth"),
|
|
88
|
-
...edited("sex"),
|
|
89
|
-
...edited("phone"),
|
|
90
|
-
...edited("email"),
|
|
91
|
-
...edited("address_street1"),
|
|
92
|
-
...edited("address_street2"),
|
|
93
|
-
...edited("address_city"),
|
|
94
|
-
...edited("address_state"),
|
|
95
|
-
...edited("address_zip"),
|
|
96
|
-
...edited("allergies"),
|
|
97
|
-
...edited("medications"),
|
|
98
|
-
...edited("diagnoses"),
|
|
99
|
-
...edited("insurance"),
|
|
100
|
-
]);
|
|
101
|
-
const sent = analytics.fieldInteractions();
|
|
102
|
-
expect(new Set(sent.map((s) => s.formName))).toEqual(new Set(["update_patient_form"]));
|
|
103
|
-
expect(Object.fromEntries(sent.map((s) => [s.fieldName, s.isOptional]))).toEqual(fields);
|
|
104
|
-
for (const body of analytics.bodies()) expect(body).not.toMatch(/Zqx|1991|5555550100|99999|987654|FEMALE/i);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/** PhotonPatient with a record: the summary and its details editor, with the clinical lists and benefits. */
|
|
2
|
-
import { useComponents } from "../../primitives/index.ts";
|
|
3
|
-
import {
|
|
4
|
-
type ChangeOption,
|
|
5
|
-
type ClassifiedChanges,
|
|
6
|
-
type MedicationStatus,
|
|
7
|
-
type PatientInput,
|
|
8
|
-
type PatientRecord,
|
|
9
|
-
} from "@photonhealth/client";
|
|
10
|
-
import { Fragment, useState, type ReactNode } from "react";
|
|
11
|
-
import { ageOn, displayName, shortDate } from "../format.ts";
|
|
12
|
-
|
|
13
|
-
type PatientDemographicInput = NonNullable<PatientInput["demographic"]>;
|
|
14
|
-
type AddressInput = NonNullable<NonNullable<PatientInput["contact"]>["address"]>;
|
|
15
|
-
import { BenefitsSection, type BenefitInput } from "./Benefits.tsx";
|
|
16
|
-
import { choicesIn, ClinicalList, sectionOf } from "./Clinical.tsx";
|
|
17
|
-
import { noAutofill, SEX_OPTIONS, ContactFields } from "./fields.tsx";
|
|
18
|
-
import { focusProps } from "../flow.ts";
|
|
19
|
-
import { TrackedField, useFieldInteractions } from "../../analytics/fieldInteraction.tsx";
|
|
20
|
-
|
|
21
|
-
const fullName = (p: PatientRecord) =>
|
|
22
|
-
[p.demographic?.name.first, p.demographic?.name.last].filter(Boolean).join(" ") || "Unnamed patient";
|
|
23
|
-
|
|
24
|
-
export function PatientSummary({
|
|
25
|
-
patient,
|
|
26
|
-
pickedNames,
|
|
27
|
-
saving,
|
|
28
|
-
changes,
|
|
29
|
-
choices,
|
|
30
|
-
problems,
|
|
31
|
-
onChoose,
|
|
32
|
-
onAddAllergy,
|
|
33
|
-
onConfirmNone,
|
|
34
|
-
onRemoveAllergy,
|
|
35
|
-
onRemoveMedication,
|
|
36
|
-
onAddMedication,
|
|
37
|
-
onAddDiagnosis,
|
|
38
|
-
onRemoveDiagnosis,
|
|
39
|
-
onAddBenefit,
|
|
40
|
-
onRemoveBenefit,
|
|
41
|
-
onConfirmNoBenefits,
|
|
42
|
-
onSaveContact,
|
|
43
|
-
onSaveDetails,
|
|
44
|
-
addressRequest,
|
|
45
|
-
onChangePatient,
|
|
46
|
-
readOnly,
|
|
47
|
-
}: {
|
|
48
|
-
patient: PatientRecord;
|
|
49
|
-
pickedNames: Readonly<Record<string, string>>;
|
|
50
|
-
saving: boolean;
|
|
51
|
-
changes: ReactNode;
|
|
52
|
-
/** Server choices (AMBIGUOUS changes) — each clinical list shows its own under its field. */
|
|
53
|
-
choices: ClassifiedChanges["needsChoice"];
|
|
54
|
-
/** What the server rejected — each clinical list shows its own under its field (e.g. a name nothing matches). */
|
|
55
|
-
problems: ClassifiedChanges["blocking"];
|
|
56
|
-
onChoose: (option: ChangeOption) => void;
|
|
57
|
-
onAddAllergy: (name: string) => void;
|
|
58
|
-
/** Record "none" for a clinical list (NKDA, no medications, no diagnoses). */
|
|
59
|
-
onConfirmNone: (list: "allergies" | "medications" | "diagnoses") => void;
|
|
60
|
-
onRemoveAllergy: (allergy: { id: string }) => void;
|
|
61
|
-
onRemoveMedication: (medication: { id: string; status: MedicationStatus }) => void;
|
|
62
|
-
onAddMedication: (name: string) => void;
|
|
63
|
-
onAddDiagnosis: (text: string) => void;
|
|
64
|
-
onRemoveDiagnosis: (diagnosis: { id: string }) => void;
|
|
65
|
-
onAddBenefit: (benefit: BenefitInput) => void;
|
|
66
|
-
onRemoveBenefit: (benefit: { id: string }) => void;
|
|
67
|
-
onConfirmNoBenefits: () => void;
|
|
68
|
-
onSaveContact: (contact: { phone?: string; email?: string; address?: AddressInput }) => void;
|
|
69
|
-
onSaveDetails: (details: PatientDemographicInput) => void;
|
|
70
|
-
addressRequest: string | null;
|
|
71
|
-
onChangePatient?: () => void;
|
|
72
|
-
/** Read-only (e.g. on a sent order): the summary alone — no editors, no pencil. */
|
|
73
|
-
readOnly?: boolean;
|
|
74
|
-
}) {
|
|
75
|
-
const { Badge, Button, Card, CardBody, CardHeader, Row, Stack, Text } = useComponents();
|
|
76
|
-
// Allergies / medications / diagnoses / insurance are summarised in the header; the pencil opens their
|
|
77
|
-
// lists to add or remove, and they open by themselves when the server asks the prescriber to choose
|
|
78
|
-
// (e.g. which penicillin).
|
|
79
|
-
// A list with something to pick or fix opens by itself, and shows it under its field.
|
|
80
|
-
const clinicalChoices = [...choices, ...problems].filter((c) => sectionOf(c.key));
|
|
81
|
-
// One card, two states. Shut, it says who the patient is; open, it is everything about them that can be
|
|
82
|
-
// changed — the fields they were added with, their contact details, and their clinical lists. Each saves
|
|
83
|
-
// as it is answered (`UpdatePatient` on a record that already exists), so there is nothing to confirm.
|
|
84
|
-
// It also opens itself when a send fails for want of an address, and shuts again once that is answered.
|
|
85
|
-
const [editing, setEditing] = useState(Boolean(addressRequest));
|
|
86
|
-
const [seenRequest, setSeenRequest] = useState(addressRequest);
|
|
87
|
-
if (addressRequest !== seenRequest) {
|
|
88
|
-
setSeenRequest(addressRequest);
|
|
89
|
-
setEditing(Boolean(addressRequest));
|
|
90
|
-
}
|
|
91
|
-
const d = patient.demographic;
|
|
92
|
-
const contact = patient.contact;
|
|
93
|
-
// Each list: null when nothing is recorded, [] when "none" is (core's PatientRecord).
|
|
94
|
-
const recorded = {
|
|
95
|
-
allergies: patient.clinical?.allergies ?? null,
|
|
96
|
-
medications: patient.clinical?.medications ?? null,
|
|
97
|
-
diagnoses: patient.clinical?.diagnoses ?? null,
|
|
98
|
-
benefits: patient.benefits,
|
|
99
|
-
};
|
|
100
|
-
const confirmedNkda = recorded.allergies?.length === 0;
|
|
101
|
-
const allergies = recorded.allergies ?? [];
|
|
102
|
-
const meds = (recorded.medications ?? []).filter((m) => m.status === "ACTIVE");
|
|
103
|
-
const diagnoses = (recorded.diagnoses ?? []).map((x) => ({ ...x, name: x.name ?? x.icd10Code ?? "" }));
|
|
104
|
-
const benefits = recorded.benefits ?? [];
|
|
105
|
-
const nameOf = (item: { id: string; name: string }, unknown: string) =>
|
|
106
|
-
item.name && item.name !== item.id ? item.name : (pickedNames[item.id] ?? unknown);
|
|
107
|
-
const listed = (items: { id: string; name: string }[], unknown: string, none: string) =>
|
|
108
|
-
items.length ? items.map((x) => nameOf(x, unknown)).join(", ") : none;
|
|
109
|
-
// Under the name, like a prescription's product under its drug: "Male · Adult (35) · 7/8/91".
|
|
110
|
-
const age = ageOn(d?.dateOfBirth);
|
|
111
|
-
const sex = d?.sex === "FEMALE" ? "Female" : d?.sex === "MALE" ? "Male" : null;
|
|
112
|
-
const ageGroup = age != null ? `${age >= 18 ? "Adult" : "Pediatric"} (${age})` : null;
|
|
113
|
-
const line = [sex, ageGroup, d?.dateOfBirth ? shortDate(d.dateOfBirth) : null].filter(Boolean).join(" · ");
|
|
114
|
-
// A choice the server is waiting on (which penicillin?) opens the card too — the answer lives in here.
|
|
115
|
-
const expanded = !readOnly && (editing || clinicalChoices.length > 0);
|
|
116
|
-
// The clinical picture, below the line, said once like a prescription's dispense line: allergies · meds ·
|
|
117
|
-
// diagnoses · insurance. An allergy stands out. A recorded "none" is said plainly ("No active meds"); a list
|
|
118
|
-
// not recorded isn't shown — except allergies, where not knowing matters.
|
|
119
|
-
const named = (items: { id: string; name: string }[], unknown: string) => listed(items, unknown, "");
|
|
120
|
-
const facts = [
|
|
121
|
-
allergies.length ? (
|
|
122
|
-
<Badge tone="warning">
|
|
123
|
-
{allergies.length === 1 ? "Allergy" : "Allergies"}: {named(allergies, "Unknown allergy")}
|
|
124
|
-
</Badge>
|
|
125
|
-
) : confirmedNkda ? (
|
|
126
|
-
"No known allergies"
|
|
127
|
-
) : (
|
|
128
|
-
"Allergies not recorded"
|
|
129
|
-
),
|
|
130
|
-
meds.length ? `Active meds: ${named(meds, "Unknown medication")}` : recorded.medications && "No active meds",
|
|
131
|
-
diagnoses.length ? `Diagnoses: ${named(diagnoses, "Unknown diagnosis")}` : recorded.diagnoses && "No diagnoses",
|
|
132
|
-
benefits.length
|
|
133
|
-
? `Insurance: ${benefits.map((b) => `BIN ${b.bin}`).join(", ")}`
|
|
134
|
-
: recorded.benefits && "No insurance",
|
|
135
|
-
].filter(Boolean);
|
|
136
|
-
const factLine = (
|
|
137
|
-
<Text tone="secondary">
|
|
138
|
-
{facts.map((fact, i) => (
|
|
139
|
-
<Fragment key={i}>
|
|
140
|
-
{i > 0 && " · "}
|
|
141
|
-
<span>{fact}</span>
|
|
142
|
-
</Fragment>
|
|
143
|
-
))}
|
|
144
|
-
</Text>
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<Card divided>
|
|
149
|
-
<CardHeader
|
|
150
|
-
title={displayName(fullName(patient))}
|
|
151
|
-
description={line || undefined}
|
|
152
|
-
action={
|
|
153
|
-
<Row gap="1">
|
|
154
|
-
{!readOnly && (
|
|
155
|
-
<span {...focusProps}>
|
|
156
|
-
<Button
|
|
157
|
-
variant="ghost"
|
|
158
|
-
icon={expanded ? "check" : "edit"}
|
|
159
|
-
aria-label={expanded ? "Done editing patient" : "Edit patient"}
|
|
160
|
-
title={expanded ? "Done" : "Edit patient"}
|
|
161
|
-
aria-expanded={expanded}
|
|
162
|
-
onClick={() => setEditing(!expanded)}
|
|
163
|
-
/>
|
|
164
|
-
</span>
|
|
165
|
-
)}
|
|
166
|
-
{onChangePatient && (
|
|
167
|
-
<Button
|
|
168
|
-
variant="ghost"
|
|
169
|
-
onClick={onChangePatient}
|
|
170
|
-
aria-label="Change patient"
|
|
171
|
-
title="Change patient"
|
|
172
|
-
icon="close"
|
|
173
|
-
/>
|
|
174
|
-
)}
|
|
175
|
-
</Row>
|
|
176
|
-
}
|
|
177
|
-
/>
|
|
178
|
-
<CardBody>
|
|
179
|
-
<Stack gap="4">
|
|
180
|
-
{!expanded && factLine}
|
|
181
|
-
{expanded && (
|
|
182
|
-
<Stack gap="4">
|
|
183
|
-
<DetailsEditor patient={patient} onSave={onSaveDetails} />
|
|
184
|
-
<ContactFields
|
|
185
|
-
phone={contact?.phone ?? null}
|
|
186
|
-
email={contact?.email ?? null}
|
|
187
|
-
address={contact?.address ?? null}
|
|
188
|
-
onSave={onSaveContact}
|
|
189
|
-
addressRequest={addressRequest}
|
|
190
|
-
/>
|
|
191
|
-
<ClinicalList
|
|
192
|
-
label="Allergies"
|
|
193
|
-
fieldName="allergies"
|
|
194
|
-
choices={choicesIn(choices, "allergies")}
|
|
195
|
-
problems={choicesIn(problems, "allergies")}
|
|
196
|
-
onChoose={onChoose}
|
|
197
|
-
items={allergies}
|
|
198
|
-
tone="warning"
|
|
199
|
-
addLabel="Add allergy"
|
|
200
|
-
noneLabel="No known allergies"
|
|
201
|
-
noneAction="Mark NKDA"
|
|
202
|
-
confirmedNone={confirmedNkda}
|
|
203
|
-
unknownLabel="Unknown allergy"
|
|
204
|
-
pickedNames={pickedNames}
|
|
205
|
-
saving={saving}
|
|
206
|
-
onAdd={onAddAllergy}
|
|
207
|
-
onRemove={onRemoveAllergy}
|
|
208
|
-
onNone={() => onConfirmNone("allergies")}
|
|
209
|
-
/>
|
|
210
|
-
<ClinicalList
|
|
211
|
-
label="Medications"
|
|
212
|
-
fieldName="medications"
|
|
213
|
-
choices={choicesIn(choices, "medications")}
|
|
214
|
-
problems={choicesIn(problems, "medications")}
|
|
215
|
-
onChoose={onChoose}
|
|
216
|
-
items={meds}
|
|
217
|
-
tone="neutral"
|
|
218
|
-
addLabel="Add medication"
|
|
219
|
-
noneLabel="No active meds"
|
|
220
|
-
noneAction="Mark none"
|
|
221
|
-
confirmedNone={recorded.medications?.length === 0}
|
|
222
|
-
onNone={() => onConfirmNone("medications")}
|
|
223
|
-
unknownLabel="Unknown medication"
|
|
224
|
-
pickedNames={pickedNames}
|
|
225
|
-
saving={saving}
|
|
226
|
-
onAdd={onAddMedication}
|
|
227
|
-
onRemove={onRemoveMedication}
|
|
228
|
-
/>
|
|
229
|
-
<ClinicalList
|
|
230
|
-
label="Diagnoses"
|
|
231
|
-
fieldName="diagnoses"
|
|
232
|
-
choices={choicesIn(choices, "diagnoses")}
|
|
233
|
-
problems={choicesIn(problems, "diagnoses")}
|
|
234
|
-
onChoose={onChoose}
|
|
235
|
-
items={diagnoses}
|
|
236
|
-
tone="neutral"
|
|
237
|
-
addLabel="Add diagnosis"
|
|
238
|
-
noneLabel="No diagnoses"
|
|
239
|
-
noneAction="Mark none"
|
|
240
|
-
confirmedNone={recorded.diagnoses?.length === 0}
|
|
241
|
-
onNone={() => onConfirmNone("diagnoses")}
|
|
242
|
-
unknownLabel="Unknown diagnosis"
|
|
243
|
-
pickedNames={pickedNames}
|
|
244
|
-
saving={saving}
|
|
245
|
-
onAdd={onAddDiagnosis}
|
|
246
|
-
onRemove={onRemoveDiagnosis}
|
|
247
|
-
/>
|
|
248
|
-
<BenefitsSection
|
|
249
|
-
benefits={recorded.benefits}
|
|
250
|
-
saving={saving}
|
|
251
|
-
onAdd={onAddBenefit}
|
|
252
|
-
onRemove={onRemoveBenefit}
|
|
253
|
-
onNone={onConfirmNoBenefits}
|
|
254
|
-
/>
|
|
255
|
-
</Stack>
|
|
256
|
-
)}
|
|
257
|
-
{changes}
|
|
258
|
-
</Stack>
|
|
259
|
-
</CardBody>
|
|
260
|
-
</Card>
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/** Name / DOB / sex of a saved patient — each saves when you leave it (save early, fix in place). */
|
|
265
|
-
function DetailsEditor({
|
|
266
|
-
patient,
|
|
267
|
-
onSave,
|
|
268
|
-
}: {
|
|
269
|
-
patient: PatientRecord;
|
|
270
|
-
onSave: (details: PatientDemographicInput) => void;
|
|
271
|
-
}) {
|
|
272
|
-
const { Grid, Input, Select } = useComponents();
|
|
273
|
-
const d = patient.demographic;
|
|
274
|
-
const sexPicked = useFieldInteractions("update_patient_form")("sex", {
|
|
275
|
-
isOptional: false,
|
|
276
|
-
hasValue: Boolean(d?.sex),
|
|
277
|
-
});
|
|
278
|
-
const [first, setFirst] = useState(d?.name.first ?? "");
|
|
279
|
-
const [last, setLast] = useState(d?.name.last ?? "");
|
|
280
|
-
const [dob, setDob] = useState(d?.dateOfBirth ?? "");
|
|
281
|
-
const saveName = () => {
|
|
282
|
-
if (first.trim() && last.trim() && (first.trim() !== d?.name.first || last.trim() !== d?.name.last)) {
|
|
283
|
-
onSave({ name: { first: first.trim(), last: last.trim() } });
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
return (
|
|
287
|
-
<Grid min="200px" gap="3">
|
|
288
|
-
<TrackedField formName="update_patient_form" fieldName="firstName" isOptional={false}>
|
|
289
|
-
<Input
|
|
290
|
-
label="First name"
|
|
291
|
-
value={first}
|
|
292
|
-
onChange={(e) => setFirst(e.target.value)}
|
|
293
|
-
onBlur={saveName}
|
|
294
|
-
{...noAutofill}
|
|
295
|
-
/>
|
|
296
|
-
</TrackedField>
|
|
297
|
-
<TrackedField formName="update_patient_form" fieldName="lastName" isOptional={false}>
|
|
298
|
-
<Input
|
|
299
|
-
label="Last name"
|
|
300
|
-
value={last}
|
|
301
|
-
onChange={(e) => setLast(e.target.value)}
|
|
302
|
-
onBlur={saveName}
|
|
303
|
-
{...noAutofill}
|
|
304
|
-
/>
|
|
305
|
-
</TrackedField>
|
|
306
|
-
<TrackedField formName="update_patient_form" fieldName="dateOfBirth" isOptional={false}>
|
|
307
|
-
<Input
|
|
308
|
-
label="Date of birth"
|
|
309
|
-
type="date"
|
|
310
|
-
{...noAutofill}
|
|
311
|
-
value={dob}
|
|
312
|
-
onChange={(e) => setDob(e.target.value)}
|
|
313
|
-
onBlur={() => dob && dob !== d?.dateOfBirth && onSave({ dateOfBirth: dob })}
|
|
314
|
-
/>
|
|
315
|
-
</TrackedField>
|
|
316
|
-
<div style={{ display: "contents" }} onFocus={sexPicked.onFocus} onBlur={sexPicked.onBlur}>
|
|
317
|
-
<Select
|
|
318
|
-
label="Sex"
|
|
319
|
-
placeholder="Select…"
|
|
320
|
-
options={SEX_OPTIONS}
|
|
321
|
-
value={d?.sex ?? null}
|
|
322
|
-
onChange={(sex) => {
|
|
323
|
-
sexPicked.onChange(true);
|
|
324
|
-
if (sex !== d?.sex) onSave({ sex });
|
|
325
|
-
}}
|
|
326
|
-
/>
|
|
327
|
-
</div>
|
|
328
|
-
</Grid>
|
|
329
|
-
);
|
|
330
|
-
}
|