@photonhealth/react 0.0.0-stage → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +111 -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 +126 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.js.map +1 -0
- package/dist/components/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 +274 -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 +85 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +32 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +11 -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/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/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts +25 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -0
- package/dist/components/patient/Benefits.js +48 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +56 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +118 -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 +333 -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 +90 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +42 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +72 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +37 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +70 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js +287 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/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 +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- 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 +60 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +103 -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 +70 -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/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/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 +288 -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/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 +653 -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 +282 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +76 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +572 -0
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +508 -0
- package/src/components/PhotonPatient.tsx +188 -0
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +45 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -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/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +133 -0
- package/src/components/patient/Clinical.tsx +215 -0
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +564 -0
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +330 -0
- package/src/components/patient/fields.tsx +158 -0
- package/src/components/patient/query.ts +83 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -0
- package/src/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 +21 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +168 -0
- package/src/primitives/defaults.tsx +432 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +288 -0
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +653 -0
- package/src/test-utils/contract.tsx +453 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** PhotonPatient with a record: the summary and its details editor, with the clinical lists and benefits. */
|
|
3
|
+
import { useComponents } from "../../primitives/index.js";
|
|
4
|
+
import {} from "@photonhealth/client";
|
|
5
|
+
import { Fragment, useState } from "react";
|
|
6
|
+
import { ageOn, displayName, shortDate } from "../format.js";
|
|
7
|
+
import { BenefitsSection } from "./Benefits.js";
|
|
8
|
+
import { choicesIn, ClinicalList, sectionOf } from "./Clinical.js";
|
|
9
|
+
import { noAutofill, SEX_OPTIONS, ContactFields } from "./fields.js";
|
|
10
|
+
import { focusProps } from "../flow.js";
|
|
11
|
+
import { TrackedField, useFieldInteractions } from "../../analytics/fieldInteraction.js";
|
|
12
|
+
const fullName = (p) => [p.demographic?.name.first, p.demographic?.name.last].filter(Boolean).join(" ") || "Unnamed patient";
|
|
13
|
+
export function PatientSummary({ patient, pickedNames, saving, changes, choices, problems, onChoose, onAddAllergy, onConfirmNone, onRemoveAllergy, onRemoveMedication, onAddMedication, onAddDiagnosis, onRemoveDiagnosis, onAddBenefit, onRemoveBenefit, onConfirmNoBenefits, onSaveContact, onSaveDetails, addressRequest, onChangePatient, readOnly, }) {
|
|
14
|
+
const { Badge, Button, Card, CardBody, CardHeader, Row, Stack, Text } = useComponents();
|
|
15
|
+
// Allergies / medications / diagnoses / insurance are summarised in the header; the pencil opens their
|
|
16
|
+
// lists to add or remove, and they open by themselves when the server asks the prescriber to choose
|
|
17
|
+
// (e.g. which penicillin).
|
|
18
|
+
// A list with something to pick or fix opens by itself, and shows it under its field.
|
|
19
|
+
const clinicalChoices = [...choices, ...problems].filter((c) => sectionOf(c.key));
|
|
20
|
+
// One card, two states. Shut, it says who the patient is; open, it is everything about them that can be
|
|
21
|
+
// changed — the fields they were added with, their contact details, and their clinical lists. Each saves
|
|
22
|
+
// as it is answered (`UpdatePatient` on a record that already exists), so there is nothing to confirm.
|
|
23
|
+
// It also opens itself when a send fails for want of an address, and shuts again once that is answered.
|
|
24
|
+
const [editing, setEditing] = useState(Boolean(addressRequest));
|
|
25
|
+
const [seenRequest, setSeenRequest] = useState(addressRequest);
|
|
26
|
+
if (addressRequest !== seenRequest) {
|
|
27
|
+
setSeenRequest(addressRequest);
|
|
28
|
+
setEditing(Boolean(addressRequest));
|
|
29
|
+
}
|
|
30
|
+
const d = patient.demographic;
|
|
31
|
+
const contact = patient.contact;
|
|
32
|
+
// Each list: null when nothing is recorded, [] when "none" is (core's PatientRecord).
|
|
33
|
+
const recorded = {
|
|
34
|
+
allergies: patient.clinical?.allergies ?? null,
|
|
35
|
+
medications: patient.clinical?.medications ?? null,
|
|
36
|
+
diagnoses: patient.clinical?.diagnoses ?? null,
|
|
37
|
+
benefits: patient.benefits,
|
|
38
|
+
};
|
|
39
|
+
const confirmedNkda = recorded.allergies?.length === 0;
|
|
40
|
+
const allergies = recorded.allergies ?? [];
|
|
41
|
+
const meds = (recorded.medications ?? []).filter((m) => m.status === "ACTIVE");
|
|
42
|
+
const diagnoses = (recorded.diagnoses ?? []).map((x) => ({ ...x, name: x.name ?? x.icd10Code ?? "" }));
|
|
43
|
+
const benefits = recorded.benefits ?? [];
|
|
44
|
+
const nameOf = (item, unknown) => item.name && item.name !== item.id ? item.name : (pickedNames[item.id] ?? unknown);
|
|
45
|
+
const listed = (items, unknown, none) => items.length ? items.map((x) => nameOf(x, unknown)).join(", ") : none;
|
|
46
|
+
// Under the name, like a prescription's product under its drug: "Male · Adult (35) · 7/8/91".
|
|
47
|
+
const age = ageOn(d?.dateOfBirth);
|
|
48
|
+
const sex = d?.sex === "FEMALE" ? "Female" : d?.sex === "MALE" ? "Male" : null;
|
|
49
|
+
const ageGroup = age != null ? `${age >= 18 ? "Adult" : "Pediatric"} (${age})` : null;
|
|
50
|
+
const line = [sex, ageGroup, d?.dateOfBirth ? shortDate(d.dateOfBirth) : null].filter(Boolean).join(" · ");
|
|
51
|
+
// A choice the server is waiting on (which penicillin?) opens the card too — the answer lives in here.
|
|
52
|
+
const expanded = !readOnly && (editing || clinicalChoices.length > 0);
|
|
53
|
+
// The clinical picture, below the line, said once like a prescription's dispense line: allergies · meds ·
|
|
54
|
+
// diagnoses · insurance. An allergy stands out. A recorded "none" is said plainly ("No active meds"); a list
|
|
55
|
+
// not recorded isn't shown — except allergies, where not knowing matters.
|
|
56
|
+
const named = (items, unknown) => listed(items, unknown, "");
|
|
57
|
+
const facts = [
|
|
58
|
+
allergies.length ? (_jsxs(Badge, { tone: "warning", children: [allergies.length === 1 ? "Allergy" : "Allergies", ": ", named(allergies, "Unknown allergy")] })) : confirmedNkda ? ("No known allergies") : ("Allergies not recorded"),
|
|
59
|
+
meds.length ? `Active meds: ${named(meds, "Unknown medication")}` : recorded.medications && "No active meds",
|
|
60
|
+
diagnoses.length ? `Diagnoses: ${named(diagnoses, "Unknown diagnosis")}` : recorded.diagnoses && "No diagnoses",
|
|
61
|
+
benefits.length
|
|
62
|
+
? `Insurance: ${benefits.map((b) => `BIN ${b.bin}`).join(", ")}`
|
|
63
|
+
: recorded.benefits && "No insurance",
|
|
64
|
+
].filter(Boolean);
|
|
65
|
+
const factLine = (_jsx(Text, { tone: "secondary", children: facts.map((fact, i) => (_jsxs(Fragment, { children: [i > 0 && " · ", _jsx("span", { children: fact })] }, i))) }));
|
|
66
|
+
return (_jsxs(Card, { divided: true, children: [_jsx(CardHeader, { title: displayName(fullName(patient)), description: line || undefined, action: _jsxs(Row, { gap: "1", children: [!readOnly && (_jsx("span", { ...focusProps, children: _jsx(Button, { variant: "ghost", icon: expanded ? "check" : "edit", "aria-label": expanded ? "Done editing patient" : "Edit patient", title: expanded ? "Done" : "Edit patient", "aria-expanded": expanded, onClick: () => setEditing(!expanded) }) })), onChangePatient && (_jsx(Button, { variant: "ghost", onClick: onChangePatient, "aria-label": "Change patient", title: "Change patient", icon: "close" }))] }) }), _jsx(CardBody, { children: _jsxs(Stack, { gap: "4", children: [!expanded && factLine, expanded && (_jsxs(Stack, { gap: "4", children: [_jsx(DetailsEditor, { patient: patient, onSave: onSaveDetails }), _jsx(ContactFields, { phone: contact?.phone ?? null, email: contact?.email ?? null, address: contact?.address ?? null, onSave: onSaveContact, addressRequest: addressRequest }), _jsx(ClinicalList, { label: "Allergies", fieldName: "allergies", choices: choicesIn(choices, "allergies"), problems: choicesIn(problems, "allergies"), onChoose: onChoose, items: allergies, tone: "warning", addLabel: "Add allergy", noneLabel: "No known allergies", noneAction: "Mark NKDA", confirmedNone: confirmedNkda, unknownLabel: "Unknown allergy", pickedNames: pickedNames, saving: saving, onAdd: onAddAllergy, onRemove: onRemoveAllergy, onNone: () => onConfirmNone("allergies") }), _jsx(ClinicalList, { label: "Medications", fieldName: "medications", choices: choicesIn(choices, "medications"), problems: choicesIn(problems, "medications"), onChoose: onChoose, items: meds, tone: "neutral", addLabel: "Add medication", noneLabel: "No active meds", noneAction: "Mark none", confirmedNone: recorded.medications?.length === 0, onNone: () => onConfirmNone("medications"), unknownLabel: "Unknown medication", pickedNames: pickedNames, saving: saving, onAdd: onAddMedication, onRemove: onRemoveMedication }), _jsx(ClinicalList, { label: "Diagnoses", fieldName: "diagnoses", choices: choicesIn(choices, "diagnoses"), problems: choicesIn(problems, "diagnoses"), onChoose: onChoose, items: diagnoses, tone: "neutral", addLabel: "Add diagnosis", noneLabel: "No diagnoses", noneAction: "Mark none", confirmedNone: recorded.diagnoses?.length === 0, onNone: () => onConfirmNone("diagnoses"), unknownLabel: "Unknown diagnosis", pickedNames: pickedNames, saving: saving, onAdd: onAddDiagnosis, onRemove: onRemoveDiagnosis }), _jsx(BenefitsSection, { benefits: recorded.benefits, saving: saving, onAdd: onAddBenefit, onRemove: onRemoveBenefit, onNone: onConfirmNoBenefits })] })), changes] }) })] }));
|
|
67
|
+
}
|
|
68
|
+
/** Name / DOB / sex of a saved patient — each saves when you leave it (save early, fix in place). */
|
|
69
|
+
function DetailsEditor({ patient, onSave, }) {
|
|
70
|
+
const { Grid, Input, Select } = useComponents();
|
|
71
|
+
const d = patient.demographic;
|
|
72
|
+
const sexPicked = useFieldInteractions("update_patient_form")("sex", {
|
|
73
|
+
isOptional: false,
|
|
74
|
+
hasValue: Boolean(d?.sex),
|
|
75
|
+
});
|
|
76
|
+
const [first, setFirst] = useState(d?.name.first ?? "");
|
|
77
|
+
const [last, setLast] = useState(d?.name.last ?? "");
|
|
78
|
+
const [dob, setDob] = useState(d?.dateOfBirth ?? "");
|
|
79
|
+
const saveName = () => {
|
|
80
|
+
if (first.trim() && last.trim() && (first.trim() !== d?.name.first || last.trim() !== d?.name.last)) {
|
|
81
|
+
onSave({ name: { first: first.trim(), last: last.trim() } });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return (_jsxs(Grid, { min: "200px", gap: "3", children: [_jsx(TrackedField, { formName: "update_patient_form", fieldName: "firstName", isOptional: false, children: _jsx(Input, { label: "First name", value: first, onChange: (e) => setFirst(e.target.value), onBlur: saveName, ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "lastName", isOptional: false, children: _jsx(Input, { label: "Last name", value: last, onChange: (e) => setLast(e.target.value), onBlur: saveName, ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "dateOfBirth", isOptional: false, children: _jsx(Input, { label: "Date of birth", type: "date", ...noAutofill, value: dob, onChange: (e) => setDob(e.target.value), onBlur: () => dob && dob !== d?.dateOfBirth && onSave({ dateOfBirth: dob }) }) }), _jsx("div", { style: { display: "contents" }, onFocus: sexPicked.onFocus, onBlur: sexPicked.onBlur, children: _jsx(Select, { label: "Sex", placeholder: "Select\u2026", options: SEX_OPTIONS, value: d?.sex ?? null, onChange: (sex) => {
|
|
85
|
+
sexPicked.onChange(true);
|
|
86
|
+
if (sex !== d?.sex)
|
|
87
|
+
onSave({ sex });
|
|
88
|
+
} }) })] }));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=Summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Summary.js","sourceRoot":"","sources":["../../../src/components/patient/Summary.tsx"],"names":[],"mappings":";AAAA,6GAA6G;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAMN,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI7D,OAAO,EAAE,eAAe,EAAqB,MAAM,eAAgB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAgB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAc,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qCAAsC,CAAC;AAE1F,MAAM,QAAQ,GAAG,CAAC,CAAgB,EAAE,EAAE,CACpC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC;AAEvG,MAAM,UAAU,cAAc,CAAC,EAC7B,OAAO,EACP,WAAW,EACX,MAAM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GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,EAAE,WAAW,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,GAC3E,GACW,EACf,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,YACvF,KAAC,MAAM,IACL,KAAK,EAAC,KAAK,EACX,WAAW,EAAC,cAAS,EACrB,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,IAAI,EACrB,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE;wBAChB,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;wBACzB,IAAI,GAAG,KAAK,CAAC,EAAE,GAAG;4BAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;oBACtC,CAAC,GACD,GACE,IACD,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type PatientInput, type Sex } from "@photonhealth/client";
|
|
2
|
+
type AddressInput = NonNullable<NonNullable<PatientInput["contact"]>["address"]>;
|
|
3
|
+
/**
|
|
4
|
+
* These fields describe the patient, not the prescriber: keep the browser's autofill and password managers
|
|
5
|
+
* (1Password, LastPass, Bitwarden, Dashlane) from offering the prescriber's own name, birthday, phone or address.
|
|
6
|
+
*/
|
|
7
|
+
export declare const noAutofill: {
|
|
8
|
+
readonly autoComplete: "off";
|
|
9
|
+
readonly "data-1p-ignore": "true";
|
|
10
|
+
readonly "data-lpignore": "true";
|
|
11
|
+
readonly "data-bwignore": "true";
|
|
12
|
+
readonly "data-form-type": "other";
|
|
13
|
+
};
|
|
14
|
+
/** Male first: it's the first thing a keyboard user reaches, and "m" / "f" / "u" each pick one. */
|
|
15
|
+
export declare const SEX_OPTIONS: {
|
|
16
|
+
value: Sex;
|
|
17
|
+
label: string;
|
|
18
|
+
}[];
|
|
19
|
+
/**
|
|
20
|
+
* Phone / email / address, inside the demographics editor. Nothing here is required up front: the server
|
|
21
|
+
* decides (a send needs a phone), and the editor opens itself when a send fails for want of one —
|
|
22
|
+
* `addressRequest`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ContactFields({ phone, email, address, onSave, addressRequest, }: {
|
|
25
|
+
phone: string | null;
|
|
26
|
+
email: string | null;
|
|
27
|
+
address: {
|
|
28
|
+
street1: string | null;
|
|
29
|
+
street2: string | null;
|
|
30
|
+
city: string | null;
|
|
31
|
+
state: string | null;
|
|
32
|
+
postalCode: string | null;
|
|
33
|
+
} | null;
|
|
34
|
+
onSave: (contact: {
|
|
35
|
+
phone?: string;
|
|
36
|
+
email?: string;
|
|
37
|
+
address?: AddressInput;
|
|
38
|
+
}) => void;
|
|
39
|
+
addressRequest: string | null;
|
|
40
|
+
}): import("react").JSX.Element;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/components/patient/fields.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAKnE,KAAK,YAAY,GAAG,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAEjF;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC;AAEX,mGAAmG;AACnG,eAAO,MAAM,WAAW,EAAE;IAAE,KAAK,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAItD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,cAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;KAC3B,GAAG,IAAI,CAAC;IACT,MAAM,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,YAAY,CAAA;KAAE,KAAK,IAAI,CAAC;IACtF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,+BA0GA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Fields both the intake form and the details editor use: sex, contact, no autofill. */
|
|
3
|
+
import { useComponents } from "../../primitives/index.js";
|
|
4
|
+
import {} from "@photonhealth/client";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { formatPhone, PHONE_PATTERN, toE164 } from "../format.js";
|
|
7
|
+
import { TrackedField } from "../../analytics/fieldInteraction.js";
|
|
8
|
+
/**
|
|
9
|
+
* These fields describe the patient, not the prescriber: keep the browser's autofill and password managers
|
|
10
|
+
* (1Password, LastPass, Bitwarden, Dashlane) from offering the prescriber's own name, birthday, phone or address.
|
|
11
|
+
*/
|
|
12
|
+
export const noAutofill = {
|
|
13
|
+
autoComplete: "off",
|
|
14
|
+
"data-1p-ignore": "true",
|
|
15
|
+
"data-lpignore": "true",
|
|
16
|
+
"data-bwignore": "true",
|
|
17
|
+
"data-form-type": "other",
|
|
18
|
+
};
|
|
19
|
+
/** Male first: it's the first thing a keyboard user reaches, and "m" / "f" / "u" each pick one. */
|
|
20
|
+
export const SEX_OPTIONS = [
|
|
21
|
+
{ value: "MALE", label: "Male" },
|
|
22
|
+
{ value: "FEMALE", label: "Female" },
|
|
23
|
+
{ value: "UNKNOWN", label: "Unknown" },
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Phone / email / address, inside the demographics editor. Nothing here is required up front: the server
|
|
27
|
+
* decides (a send needs a phone), and the editor opens itself when a send fails for want of one —
|
|
28
|
+
* `addressRequest`.
|
|
29
|
+
*/
|
|
30
|
+
export function ContactFields({ phone, email, address, onSave, addressRequest, }) {
|
|
31
|
+
const { Alert, Grid, Input, Stack } = useComponents();
|
|
32
|
+
const [phoneValue, setPhone] = useState(formatPhone(phone));
|
|
33
|
+
const [emailValue, setEmail] = useState(email ?? "");
|
|
34
|
+
const [street1, setStreet1] = useState(address?.street1 ?? "");
|
|
35
|
+
const [street2, setStreet2] = useState(address?.street2 ?? "");
|
|
36
|
+
const [city, setCity] = useState(address?.city ?? "");
|
|
37
|
+
const [state, setState] = useState(address?.state ?? "");
|
|
38
|
+
const [postalCode, setPostalCode] = useState(address?.postalCode ?? "");
|
|
39
|
+
// Save early: each field saves when you leave it (the browser validates phone / email first);
|
|
40
|
+
// the address saves once it's complete and you leave it.
|
|
41
|
+
const addressComplete = Boolean(street1.trim() && city.trim() && state.trim() && postalCode.trim());
|
|
42
|
+
const savePhone = (input) => {
|
|
43
|
+
setPhone(formatPhone(phoneValue));
|
|
44
|
+
if (input.checkValidity() && toE164(phoneValue) !== (phone || undefined))
|
|
45
|
+
onSave({ phone: toE164(phoneValue) ?? "" });
|
|
46
|
+
};
|
|
47
|
+
const saveEmail = (input) => {
|
|
48
|
+
if (input.checkValidity() && emailValue.trim() !== (email ?? ""))
|
|
49
|
+
onSave({ email: emailValue.trim() });
|
|
50
|
+
};
|
|
51
|
+
const saveAddress = () => {
|
|
52
|
+
if (!addressComplete)
|
|
53
|
+
return;
|
|
54
|
+
const next = {
|
|
55
|
+
street1: street1.trim(),
|
|
56
|
+
street2: street2.trim() || undefined,
|
|
57
|
+
city: city.trim(),
|
|
58
|
+
state: state.trim().toUpperCase(),
|
|
59
|
+
postalCode: postalCode.trim(),
|
|
60
|
+
country: "US",
|
|
61
|
+
};
|
|
62
|
+
const same = next.street1 === (address?.street1 ?? "") &&
|
|
63
|
+
(next.street2 ?? "") === (address?.street2 ?? "") &&
|
|
64
|
+
next.city === (address?.city ?? "") &&
|
|
65
|
+
next.state === (address?.state ?? "") &&
|
|
66
|
+
next.postalCode === (address?.postalCode ?? "");
|
|
67
|
+
if (!same)
|
|
68
|
+
onSave({ address: next });
|
|
69
|
+
};
|
|
70
|
+
return (_jsxs(Stack, { gap: "2", children: [addressRequest && _jsx(Alert, { tone: "warning", title: phone ? "Address needed to send" : "Phone needed to send" }), _jsxs(Grid, { min: "120px", gap: "3", children: [_jsx(TrackedField, { formName: "update_patient_form", fieldName: "phone", isOptional: true, children: _jsx(Input, { label: "Phone", type: "tel", inputMode: "tel", pattern: PHONE_PATTERN, value: phoneValue, onChange: (e) => setPhone(e.target.value), onBlur: (e) => savePhone(e.currentTarget), ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "email", isOptional: true, children: _jsx(Input, { label: "Email", type: "email", inputMode: "email", value: emailValue, onChange: (e) => setEmail(e.target.value), onBlur: (e) => saveEmail(e.currentTarget), ...noAutofill }) })] }), _jsx("div", { onBlur: saveAddress, children: _jsxs(Stack, { gap: "3", children: [_jsxs(Grid, { min: "120px", gap: "3", children: [_jsx(TrackedField, { formName: "update_patient_form", fieldName: "address_street1", isOptional: true, children: _jsx(Input, { label: "Street", value: street1, onChange: (e) => setStreet1(e.target.value), ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "address_street2", isOptional: true, children: _jsx(Input, { label: "Apt / suite", value: street2, onChange: (e) => setStreet2(e.target.value), ...noAutofill }) })] }), _jsxs(Grid, { min: "120px", gap: "3", children: [_jsx(TrackedField, { formName: "update_patient_form", fieldName: "address_city", isOptional: true, children: _jsx(Input, { label: "City", value: city, onChange: (e) => setCity(e.target.value), ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "address_state", isOptional: true, children: _jsx(Input, { label: "State", value: state, onChange: (e) => setState(e.target.value), maxLength: 2, ...noAutofill }) }), _jsx(TrackedField, { formName: "update_patient_form", fieldName: "address_zip", isOptional: true, children: _jsx(Input, { label: "ZIP", value: postalCode, onChange: (e) => setPostalCode(e.target.value), inputMode: "numeric", ...noAutofill }) })] })] }) })] }));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/components/patient/fields.tsx"],"names":[],"mappings":";AAAA,yFAAyF;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAA+B,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAsC,CAAC;AAIpE;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY,EAAE,KAAK;IACnB,gBAAgB,EAAE,MAAM;IACxB,eAAe,EAAE,MAAM;IACvB,eAAe,EAAE,MAAM;IACvB,gBAAgB,EAAE,OAAO;CACjB,CAAC;AAEX,mGAAmG;AACnG,MAAM,CAAC,MAAM,WAAW,GAAoC;IAC1D,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAChC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACpC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;CACvC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B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AAC,qBAAqB,EAAC,SAAS,EAAC,aAAa,EAAC,UAAU,kBAC7E,KAAC,KAAK,IACJ,KAAK,EAAC,KAAK,EACX,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC9C,SAAS,EAAC,SAAS,KACf,UAAU,GACd,GACW,IACV,IACD,GACJ,IACA,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ParsedQuery {
|
|
2
|
+
name?: {
|
|
3
|
+
first?: string;
|
|
4
|
+
last?: string;
|
|
5
|
+
};
|
|
6
|
+
dateOfBirth?: string;
|
|
7
|
+
phone?: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What was typed, as the server takes it. Anything that reads as a date, a phone or an email is taken as
|
|
12
|
+
* one; what's left is the name, first word first. A single word is a first name — `searchBoth` says when
|
|
13
|
+
* it's worth trying as a last name too.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseQuery(text: string): ParsedQuery;
|
|
16
|
+
/** query as patient input */
|
|
17
|
+
export declare const toSearchInput: ({ phone, email, ...demographic }: ParsedQuery) => {
|
|
18
|
+
demographic: {
|
|
19
|
+
name?: {
|
|
20
|
+
first?: string;
|
|
21
|
+
last?: string;
|
|
22
|
+
};
|
|
23
|
+
dateOfBirth?: string;
|
|
24
|
+
};
|
|
25
|
+
contact: {
|
|
26
|
+
email?: string | undefined;
|
|
27
|
+
phone?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** Whether a query says anything the server can match on. */
|
|
31
|
+
export declare const isSearchable: (q: ParsedQuery) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
|
|
34
|
+
* as a last name — "Lovelace" is as likely as "Ada".
|
|
35
|
+
*/
|
|
36
|
+
export declare const searchBoth: (q: ParsedQuery) => ParsedQuery | null;
|
|
37
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/components/patient/query.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAoBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAuBpD;AAED,6BAA6B;AAC7B,eAAO,MAAM,aAAa,GAAI,kCAAkC,WAAW;;eAvDlE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE;sBAC1B,MAAM;;;;;;CAyDpB,CAAC;AAEH,6DAA6D;AAC7D,eAAO,MAAM,YAAY,GAAI,GAAG,WAAW,YACoC,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,WAAW,KAAG,WAAW,GAAG,IACyD,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One field to find a patient: what the prescriber typed, split into what network-api matches on.
|
|
3
|
+
*
|
|
4
|
+
* The server matches on first name, last name and date of birth independently — prefix, case-insensitive,
|
|
5
|
+
* and with no tolerance for a typo ("Poly" finds nobody). Phone, email and address are in its match
|
|
6
|
+
* vocabulary too (`MatchReasonType`), so they go along when they're typed.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here decides anything: a query is only ever `search`ed (sent without `sex`, so it can never
|
|
9
|
+
* create), and what comes back is the prescriber's pick.
|
|
10
|
+
*/
|
|
11
|
+
import { toE164 } from "../format.js";
|
|
12
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13
|
+
/** 1990-01-01, 01/01/1990 or 01-01-1990 — the ways a date gets typed. */
|
|
14
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
15
|
+
const US = /^(\d{1,2})[/-](\d{1,2})[/-](\d{4})$/;
|
|
16
|
+
/** A date as network-api takes it, or nothing if this isn't one. */
|
|
17
|
+
function asDate(token) {
|
|
18
|
+
if (ISO.test(token))
|
|
19
|
+
return token;
|
|
20
|
+
const us = US.exec(token);
|
|
21
|
+
return us ? `${us[3]}-${us[1].padStart(2, "0")}-${us[2].padStart(2, "0")}` : undefined;
|
|
22
|
+
}
|
|
23
|
+
/** 10+ digits, however they're punctuated: (415) 555-0172, 415-555-0172, +14155550172 — sent as E.164. */
|
|
24
|
+
function asPhone(token) {
|
|
25
|
+
const digits = token.replace(/[\s().+-]/g, "");
|
|
26
|
+
return /^\d{10,11}$/.test(digits) ? toE164(token) : undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What was typed, as the server takes it. Anything that reads as a date, a phone or an email is taken as
|
|
30
|
+
* one; what's left is the name, first word first. A single word is a first name — `searchBoth` says when
|
|
31
|
+
* it's worth trying as a last name too.
|
|
32
|
+
*/
|
|
33
|
+
export function parseQuery(text) {
|
|
34
|
+
const parsed = {};
|
|
35
|
+
const words = [];
|
|
36
|
+
for (const token of text.trim().split(/\s+/).filter(Boolean)) {
|
|
37
|
+
const date = asDate(token);
|
|
38
|
+
if (date && !parsed.dateOfBirth) {
|
|
39
|
+
parsed.dateOfBirth = date;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (EMAIL.test(token) && !parsed.email) {
|
|
43
|
+
parsed.email = token;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const phone = asPhone(token);
|
|
47
|
+
if (phone && !parsed.phone) {
|
|
48
|
+
parsed.phone = phone;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
words.push(token);
|
|
52
|
+
}
|
|
53
|
+
const [first, ...rest] = words;
|
|
54
|
+
if (first)
|
|
55
|
+
parsed.name = rest.length ? { first, last: rest.join(" ") } : { first };
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
/** query as patient input */
|
|
59
|
+
export const toSearchInput = ({ phone, email, ...demographic }) => ({
|
|
60
|
+
demographic,
|
|
61
|
+
contact: { ...(phone ? { phone } : {}), ...(email ? { email } : {}) },
|
|
62
|
+
});
|
|
63
|
+
/** Whether a query says anything the server can match on. */
|
|
64
|
+
export const isSearchable = (q) => Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
|
|
65
|
+
/**
|
|
66
|
+
* One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
|
|
67
|
+
* as a last name — "Lovelace" is as likely as "Ada".
|
|
68
|
+
*/
|
|
69
|
+
export const searchBoth = (q) => q.name?.first && !q.name.last && !q.dateOfBirth && !q.phone && !q.email ? { name: { last: q.name.first } } : null;
|
|
70
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/components/patient/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAStC,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,yEAAyE;AACzE,MAAM,GAAG,GAAG,2BAA2B,CAAC;AACxC,MAAM,EAAE,GAAG,qCAAqC,CAAC;AAEjD,oEAAoE;AACpE,SAAS,MAAM,CAAC,KAAa;IAC3B,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAClC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,CAAC,G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,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Patient, Prescription, type PatientInput, type PrescriptionInput, type PrescriptionRecord } from "@photonhealth/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type Given } from "../open.ts";
|
|
4
|
+
/**
|
|
5
|
+
* One prescription line, bound to a live Prescription: PhotonPrescription's card (which adds the analytics workflow
|
|
6
|
+
* and the sign-in), and each line of PhotonOrder. Internal: the package index exports only PhotonPrescription.
|
|
7
|
+
*/
|
|
8
|
+
export interface PrescriptionCardProps {
|
|
9
|
+
/**
|
|
10
|
+
* The prescription: a live Prescription (used as given; anything else holding it sees the same changes), its
|
|
11
|
+
* id (`"rx_…"` or `{ id }`: read), its id with fields (that prescription updated), or fields without one
|
|
12
|
+
* (synced — e.g. `{ templateId }` or `{ treatment: { name } }`).
|
|
13
|
+
*/
|
|
14
|
+
prescription?: Prescription | Given<PrescriptionInput> | null;
|
|
15
|
+
/**
|
|
16
|
+
* Who it's for — given as a patient card's `patient` is. Until it's known, a new line only looks drugs up
|
|
17
|
+
* (a line from an order already knows).
|
|
18
|
+
*/
|
|
19
|
+
patient?: Patient | Given<PatientInput> | null;
|
|
20
|
+
/** Read-only (e.g. on a finalized order). A signed prescription is always read-only. */
|
|
21
|
+
locked?: boolean;
|
|
22
|
+
/** The prescriber signed it on this card — once per prescription. */
|
|
23
|
+
onSigned?: (prescription: Prescription) => void;
|
|
24
|
+
/**
|
|
25
|
+
* The card's prescription, once it has a record and each time that record changes from the backend
|
|
26
|
+
* (created, saved, signed).
|
|
27
|
+
*/
|
|
28
|
+
onPrescription?: (prescription: Prescription) => void;
|
|
29
|
+
/** Shows a Remove button (an order's line). */
|
|
30
|
+
onRemove?: () => void;
|
|
31
|
+
/** Put the cursor in Treatment (a line the prescriber just added). */
|
|
32
|
+
autoFocus?: boolean;
|
|
33
|
+
/** Put the cursor in Treatment each time this changes (e.g. a patient was just picked). */
|
|
34
|
+
focusSignal?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function StatusBadge({ rx }: {
|
|
37
|
+
rx: PrescriptionRecord | null;
|
|
38
|
+
}): import("react").JSX.Element | null;
|
|
39
|
+
export declare function PrescriptionCard({ patient, prescription, locked, onSigned, onPrescription, onRemove, autoFocus, focusSignal, }: PrescriptionCardProps): import("react").JSX.Element;
|
|
40
|
+
/** A saved prescription: its instructions — with its status tag at the end of that line — then what's dispensed. */
|
|
41
|
+
export declare function ReadOnlyRx({ rx, status }: {
|
|
42
|
+
rx: PrescriptionRecord | null;
|
|
43
|
+
status: ReactNode;
|
|
44
|
+
}): import("react").JSX.Element;
|
|
45
|
+
//# sourceMappingURL=PrescriptionCard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrescriptionCard.d.ts","sourceRoot":"","sources":["../../../src/components/prescription/PrescriptionCard.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,EACP,YAAY,EACZ,KAAK,YAAY,EAGjB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAGxB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGpE,OAAO,EAA2C,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAQjF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,YAAY,CAAC,EAAE,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IAC9D;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAC/C,wFAAwF;IACxF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAChD;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IACtD,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAAE,sCAcpE;AAOD,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,EACP,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,EAAE,qBAAqB,+BAwOvB;AAED,oHAAoH;AACpH,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;IAAE,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,+BAmB9F"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useComponents, usePhoton } from "../../primitives/index.js";
|
|
3
|
+
import { classify, Patient, Prescription, } from "@photonhealth/client";
|
|
4
|
+
import { useLive, useOnChange } from "../../hooks/index.js";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { useHeldActivity } from "../activity.js";
|
|
7
|
+
import { SearchResults } from "../search.js";
|
|
8
|
+
import { NotFound, openFailed, toOpen, useOpened } from "../open.js";
|
|
9
|
+
import { treatmentHeading } from "../display.js";
|
|
10
|
+
import { dispenseSummary } from "../format.js";
|
|
11
|
+
import { ChangeList } from "../ChangeList.js";
|
|
12
|
+
import { PrescriptionDetailsForm } from "./PrescriptionDetailsForm/PrescriptionDetailsForm.js";
|
|
13
|
+
import { ScreeningAlerts } from "../ScreeningAlerts.js";
|
|
14
|
+
import { TreatmentSearch } from "./TreatmentSearch/TreatmentSearch.js";
|
|
15
|
+
export function StatusBadge({ rx }) {
|
|
16
|
+
const { Badge } = useComponents();
|
|
17
|
+
if (!rx)
|
|
18
|
+
return null;
|
|
19
|
+
if (rx.signing.state === "SIGNED")
|
|
20
|
+
return (_jsx(Badge, { tone: "success", icon: "check", children: "Signed" }));
|
|
21
|
+
if (rx.signing.state === "INVALIDATED_SIGN")
|
|
22
|
+
return _jsx(Badge, { tone: "warning", children: "Changed since signing" });
|
|
23
|
+
// No tag for screening: its alerts are listed above the sig. Nor for nothing found: network-api doesn't screen
|
|
24
|
+
// allergies without an RxNorm id (and doesn't say which), so "No alerts" could read as a clinical check that
|
|
25
|
+
// didn't happen.
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// One empty list, so a line with no templates doesn't hand PrescriptionDetailsForm new options every render.
|
|
29
|
+
const NO_TEMPLATES = [];
|
|
30
|
+
const prescriptionOf = (r) => r.prescription;
|
|
31
|
+
const patientOf = (r) => r.patient;
|
|
32
|
+
export function PrescriptionCard({ patient, prescription, locked, onSigned, onPrescription, onRemove, autoFocus, focusSignal, }) {
|
|
33
|
+
const { Alert, Button, Card, CardBody, CardHeader, Spinner, Stack } = useComponents();
|
|
34
|
+
const ph = usePhoton();
|
|
35
|
+
// A new line when the host gives no prescription (and none to open).
|
|
36
|
+
const shared = prescription instanceof Prescription ? prescription : null;
|
|
37
|
+
const given = toOpen(prescription, Boolean(shared));
|
|
38
|
+
const [own] = useState(() => (shared || given ? null : ph.prescription()));
|
|
39
|
+
const { opened, error: rxError } = useOpened(ph.prescription, given, prescriptionOf, "prescription");
|
|
40
|
+
// Who it's for, opened the same way; its id once it has a record.
|
|
41
|
+
const sharedPatient = patient instanceof Patient ? patient : null;
|
|
42
|
+
const { opened: openedPatient, error: patientError } = useOpened(ph.patient, toOpen(patient, Boolean(sharedPatient)), patientOf, "patient");
|
|
43
|
+
const patientSnap = useLive(sharedPatient ?? openedPatient);
|
|
44
|
+
// Not given: leave it (a line from an order has its own). Given: its id once it has one; null clears it.
|
|
45
|
+
const patientId = patient === undefined ? undefined : patient === null ? null : patientSnap?.state?.id;
|
|
46
|
+
const openError = rxError ?? patientError;
|
|
47
|
+
const live = shared ?? opened ?? own;
|
|
48
|
+
const snap = useLive(live);
|
|
49
|
+
useOnChange(live, (rx) => rx.state, onPrescription);
|
|
50
|
+
const signedHere = useRef(new Set()); // onSigned: once per prescription
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (live && patientId !== undefined)
|
|
53
|
+
void live.sync({ patient: patientId ? { id: patientId } : null }).catch(() => { });
|
|
54
|
+
}, [live, patientId]);
|
|
55
|
+
const rx = snap?.state ?? null;
|
|
56
|
+
const changes = classify(snap?.changes ?? { applied: [], unapplied: [] });
|
|
57
|
+
const [signing, setSigning] = useState(false);
|
|
58
|
+
// The error showing came from Add, which signs (its title says so); the next save's error is a save's again.
|
|
59
|
+
const [signFailed, setSignFailed] = useState(false);
|
|
60
|
+
const busy = signing || snap?.status === "saving" || snap?.status === "loading";
|
|
61
|
+
// Signing is per prescription, and a signed one is final here: no edits (any change would void the
|
|
62
|
+
// signature). A different drug or sig is a new line.
|
|
63
|
+
const readOnly = Boolean(locked) || Boolean(live?.signed);
|
|
64
|
+
// Add (the signature) is offered once the server left nothing open. Screening alerts don't stop it: signing is the
|
|
65
|
+
// prescriber's acknowledgement of what they show (network-api can't acknowledge an alert yet).
|
|
66
|
+
const canSign = Boolean(rx) && changes.settled;
|
|
67
|
+
// The field whose change sent the call in flight shows a spinner — nowhere else, so nothing opens and
|
|
68
|
+
// closes while the prescriber works (held briefly, so it doesn't flicker).
|
|
69
|
+
const [sentFrom, setSentFrom] = useState(null);
|
|
70
|
+
const working = snap?.status === "saving" || snap?.status === "loading";
|
|
71
|
+
if (sentFrom && !working)
|
|
72
|
+
setSentFrom(null); // answered: a later call (e.g. signing) isn't that field's
|
|
73
|
+
const spinning = useHeldActivity(sentFrom);
|
|
74
|
+
const save = (edits, from) => {
|
|
75
|
+
if (readOnly || !live)
|
|
76
|
+
return;
|
|
77
|
+
setSignFailed(false);
|
|
78
|
+
// Its id known: update that prescription; before, sync what's known.
|
|
79
|
+
void (live.id ? live.update(edits) : live.sync(edits)).catch(() => { }); // a failure lands on the object (snap.error)
|
|
80
|
+
if (from && live.busy)
|
|
81
|
+
setSentFrom(from);
|
|
82
|
+
};
|
|
83
|
+
const add = () => {
|
|
84
|
+
if (!live)
|
|
85
|
+
return;
|
|
86
|
+
setSigning(true);
|
|
87
|
+
setSignFailed(false);
|
|
88
|
+
void live
|
|
89
|
+
.sign()
|
|
90
|
+
.then(() => {
|
|
91
|
+
if (!live.signed || !live.id || signedHere.current.has(live.id))
|
|
92
|
+
return;
|
|
93
|
+
signedHere.current.add(live.id);
|
|
94
|
+
onSigned?.(live);
|
|
95
|
+
})
|
|
96
|
+
.catch(() => setSignFailed(true)) // a refusal or failure lands on the object (snap.error)
|
|
97
|
+
.finally(() => setSigning(false));
|
|
98
|
+
};
|
|
99
|
+
const pick = snap?.pick ?? null;
|
|
100
|
+
// A drug chosen, until the server answers: the picker stays as it was picked (a spinner on the drug's row), and
|
|
101
|
+
// the directions and dispense wait — a moment to see what was picked before the form changes under it.
|
|
102
|
+
const [choosing, setChoosing] = useState(null);
|
|
103
|
+
const chooseTreatment = (choice) => {
|
|
104
|
+
if (!live)
|
|
105
|
+
return;
|
|
106
|
+
setChoosing(choice);
|
|
107
|
+
void live
|
|
108
|
+
.choose(choice.option)
|
|
109
|
+
.catch(() => { }) // a failure lands on the object (snap.error)
|
|
110
|
+
.finally(() => setChoosing(null));
|
|
111
|
+
};
|
|
112
|
+
// The title is the resolved treatment — not what the provider is typing (or an unresolved choice).
|
|
113
|
+
const drugChoices = changes.needsChoice.filter((c) => c.key.startsWith("treatment"));
|
|
114
|
+
const otherChoices = changes.needsChoice.filter((c) => !c.key.startsWith("treatment"));
|
|
115
|
+
const treatmentPending = drugChoices.length > 0;
|
|
116
|
+
// Choosing among the drugs: the picker's up (none while a product chosen saves: it heads the card at once).
|
|
117
|
+
const pickerUp = treatmentPending && !choosing;
|
|
118
|
+
const resolvedName = (rx ? !treatmentPending : pick) && !choosing ? (live?.name ?? null) : null;
|
|
119
|
+
// Sig / dispense can be filled once a drug is picked (and its choice has saved) — before a patient too (kept
|
|
120
|
+
// until the line attaches).
|
|
121
|
+
const fieldsOpen = Boolean(rx || pick) && !choosing;
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (fieldsOpen && !readOnly)
|
|
124
|
+
live?.loadTemplates();
|
|
125
|
+
}, [live, fieldsOpen, readOnly]);
|
|
126
|
+
// "Lisinopril 10 mg tablet" over "Oral tablet · 10 mg" — the picked product, said once. A product chosen heads the
|
|
127
|
+
// card as soon as it's picked, from the option itself, while the server drafts it.
|
|
128
|
+
const heading = choosing
|
|
129
|
+
? treatmentHeading(choosing.option.displayName, choosing.option.treatment)
|
|
130
|
+
: resolvedName
|
|
131
|
+
? treatmentHeading(resolvedName, live?.treatment)
|
|
132
|
+
: null;
|
|
133
|
+
// The Treatment field is for finding a drug: shown until one is picked. A different drug is a new line.
|
|
134
|
+
const searching = !choosing && (!fieldsOpen || pickerUp);
|
|
135
|
+
// A failed call: shown where the drug list drops down (under Treatment), with the card's other messages — and so
|
|
136
|
+
// is a prescription this line stands in for that the server doesn't have (an order link's `rx=`), until it's filled.
|
|
137
|
+
const missing = live?.missing && !rx ? new NotFound("prescription", live.missing) : null;
|
|
138
|
+
const opening = openError ?? missing;
|
|
139
|
+
const error = snap?.error ?? opening;
|
|
140
|
+
const failure = error && (_jsx(Alert, { tone: "critical", title: !snap?.error && opening
|
|
141
|
+
? openFailed(opening === patientError ? "patient" : "prescription", opening)
|
|
142
|
+
: signFailed
|
|
143
|
+
? "Couldn't sign this prescription"
|
|
144
|
+
: snap?.error?.kind === "refused" && !rx
|
|
145
|
+
? "Can't start a new prescription"
|
|
146
|
+
: "Couldn't save this prescription", description: error.message }));
|
|
147
|
+
// The body above the form shows only when something is in it. A divided card draws a line above each section, so an
|
|
148
|
+
// empty one (Treatment closed once a drug is picked, nothing to say) would show as a double line. Keep this in step
|
|
149
|
+
// with what the body renders.
|
|
150
|
+
const hasBody = readOnly ||
|
|
151
|
+
searching ||
|
|
152
|
+
Boolean(error) ||
|
|
153
|
+
otherChoices.length + changes.blocking.length + changes.advisories.length > 0 ||
|
|
154
|
+
Boolean(snap?.drafts) ||
|
|
155
|
+
openAlerts(rx).length > 0 ||
|
|
156
|
+
Boolean(choosing);
|
|
157
|
+
return (_jsxs(Card, { divided: true, label: heading?.title ?? "Prescription", children: [_jsx(CardHeader, { title: heading?.title ?? "Prescription",
|
|
158
|
+
// The product in parts — a brand's ingredients, its form · strength, a controlled substance's schedule —
|
|
159
|
+
// with no NDC / RxNorm stand-ins.
|
|
160
|
+
description: heading?.detail, action: !locked &&
|
|
161
|
+
onRemove && (_jsx(Button, { variant: "ghost", size: "sm", tone: "critical", icon: "trash", "aria-label": "Remove prescription", title: "Remove prescription", onClick: onRemove })) }), hasBody && (_jsx(CardBody, { children: _jsx(Stack, { gap: "4", children: readOnly ? (_jsxs(_Fragment, { children: [failure, _jsx(ReadOnlyRx, { rx: rx, status: _jsx(StatusBadge, { rx: rx }) }), _jsx(ScreeningAlerts, { alerts: openAlerts(rx) })] })) : (_jsxs(_Fragment, { children: [_jsx(TreatmentSearch, { live: live, rx: rx, pickId: pick?.id ?? null, drugChoices: drugChoices, choosing: choosing, open: searching, busy: busy, spinning: spinning, autoFocus: autoFocus, focusSignal: focusSignal, save: save, onChoose: chooseTreatment }), failure, _jsx(ChangeList, { changes: { ...changes, needsChoice: otherChoices }, onChoose: (o) => void live?.choose(o).catch(() => { }), busy: busy }), snap?.drafts && (_jsx(SearchResults, { label: "Continue a draft", busy: busy, results: snap.drafts.map((d) => ({
|
|
162
|
+
key: d.id,
|
|
163
|
+
label: d.treatment.name,
|
|
164
|
+
description: [d.instructions, dispenseSummary(d)].filter(Boolean).join(" · ") || undefined,
|
|
165
|
+
})), onPick: (id) => void live?.continueDraft(id).catch(() => { }) })), _jsx(ScreeningAlerts, { alerts: openAlerts(rx) }), choosing && _jsx(Spinner, {})] })) }) })), !readOnly && (_jsx(PrescriptionDetailsForm, { live: live, rx: rx, open: fieldsOpen, focusable: !searching, templates: snap?.templates ?? NO_TEMPLATES, spinning: spinning, save: save, status: _jsx(StatusBadge, { rx: rx }), onAdd: add, adding: signing, addDisabled: snap?.status === "loading" || (Boolean(rx) && !canSign) }))] }));
|
|
166
|
+
}
|
|
167
|
+
/** A saved prescription: its instructions — with its status tag at the end of that line — then what's dispensed. */
|
|
168
|
+
export function ReadOnlyRx({ rx, status }) {
|
|
169
|
+
const { Row, Stack, Text } = useComponents();
|
|
170
|
+
// Locked before there's anything in it: say so, rather than an empty card.
|
|
171
|
+
if (!rx)
|
|
172
|
+
return _jsx(Text, { tone: "tertiary", children: "No prescription" });
|
|
173
|
+
const dispense = dispenseSummary(rx);
|
|
174
|
+
const first = rx.instructions ? (_jsx("span", { children: rx.instructions })) : dispense ? (_jsx(Text, { tone: "secondary", children: dispense })) : null;
|
|
175
|
+
return (_jsxs(Stack, { gap: "1", children: [_jsxs(Row, { gap: "2", justify: "between", children: [first ?? _jsx("span", {}), status] }), rx.instructions && dispense && _jsx(Text, { tone: "secondary", children: dispense })] }));
|
|
176
|
+
}
|
|
177
|
+
/** What screening found, until it's signed: the signature acknowledges them. */
|
|
178
|
+
const openAlerts = (rx) => rx?.signing.state === "SIGNED" ? [] : (rx?.screeningAlerts ?? []);
|
|
179
|
+
//# sourceMappingURL=PrescriptionCard.js.map
|