@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,330 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/** Fields both the intake form and the details editor use: sex, contact, no autofill. */
|
|
2
|
+
import { useComponents } from "../../primitives/index.ts";
|
|
3
|
+
import { type PatientInput, type Sex } from "@photonhealth/client";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { formatPhone, PHONE_PATTERN, toE164 } from "../format.ts";
|
|
6
|
+
import { TrackedField } from "../../analytics/fieldInteraction.tsx";
|
|
7
|
+
|
|
8
|
+
type AddressInput = NonNullable<NonNullable<PatientInput["contact"]>["address"]>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* These fields describe the patient, not the prescriber: keep the browser's autofill and password managers
|
|
12
|
+
* (1Password, LastPass, Bitwarden, Dashlane) from offering the prescriber's own name, birthday, phone or address.
|
|
13
|
+
*/
|
|
14
|
+
export const noAutofill = {
|
|
15
|
+
autoComplete: "off",
|
|
16
|
+
"data-1p-ignore": "true",
|
|
17
|
+
"data-lpignore": "true",
|
|
18
|
+
"data-bwignore": "true",
|
|
19
|
+
"data-form-type": "other",
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
/** Male first: it's the first thing a keyboard user reaches, and "m" / "f" / "u" each pick one. */
|
|
23
|
+
export const SEX_OPTIONS: { value: Sex; label: string }[] = [
|
|
24
|
+
{ value: "MALE", label: "Male" },
|
|
25
|
+
{ value: "FEMALE", label: "Female" },
|
|
26
|
+
{ value: "UNKNOWN", label: "Unknown" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Phone / email / address, inside the demographics editor. Nothing here is required up front: the server
|
|
31
|
+
* decides (a send needs a phone), and the editor opens itself when a send fails for want of one —
|
|
32
|
+
* `addressRequest`.
|
|
33
|
+
*/
|
|
34
|
+
export function ContactFields({
|
|
35
|
+
phone,
|
|
36
|
+
email,
|
|
37
|
+
address,
|
|
38
|
+
onSave,
|
|
39
|
+
addressRequest,
|
|
40
|
+
}: {
|
|
41
|
+
phone: string | null;
|
|
42
|
+
email: string | null;
|
|
43
|
+
address: {
|
|
44
|
+
street1: string | null;
|
|
45
|
+
street2: string | null;
|
|
46
|
+
city: string | null;
|
|
47
|
+
state: string | null;
|
|
48
|
+
postalCode: string | null;
|
|
49
|
+
} | null;
|
|
50
|
+
onSave: (contact: { phone?: string; email?: string; address?: AddressInput }) => void;
|
|
51
|
+
addressRequest: string | null;
|
|
52
|
+
}) {
|
|
53
|
+
const { Alert, Grid, Input, Stack } = useComponents();
|
|
54
|
+
const [phoneValue, setPhone] = useState(formatPhone(phone));
|
|
55
|
+
const [emailValue, setEmail] = useState(email ?? "");
|
|
56
|
+
const [street1, setStreet1] = useState(address?.street1 ?? "");
|
|
57
|
+
const [street2, setStreet2] = useState(address?.street2 ?? "");
|
|
58
|
+
const [city, setCity] = useState(address?.city ?? "");
|
|
59
|
+
const [state, setState] = useState(address?.state ?? "");
|
|
60
|
+
const [postalCode, setPostalCode] = useState(address?.postalCode ?? "");
|
|
61
|
+
|
|
62
|
+
// Save early: each field saves when you leave it (the browser validates phone / email first);
|
|
63
|
+
// the address saves once it's complete and you leave it.
|
|
64
|
+
const addressComplete = Boolean(street1.trim() && city.trim() && state.trim() && postalCode.trim());
|
|
65
|
+
const savePhone = (input: HTMLInputElement) => {
|
|
66
|
+
setPhone(formatPhone(phoneValue));
|
|
67
|
+
if (input.checkValidity() && toE164(phoneValue) !== (phone || undefined))
|
|
68
|
+
onSave({ phone: toE164(phoneValue) ?? "" });
|
|
69
|
+
};
|
|
70
|
+
const saveEmail = (input: HTMLInputElement) => {
|
|
71
|
+
if (input.checkValidity() && emailValue.trim() !== (email ?? "")) onSave({ email: emailValue.trim() });
|
|
72
|
+
};
|
|
73
|
+
const saveAddress = () => {
|
|
74
|
+
if (!addressComplete) return;
|
|
75
|
+
const next = {
|
|
76
|
+
street1: street1.trim(),
|
|
77
|
+
street2: street2.trim() || undefined,
|
|
78
|
+
city: city.trim(),
|
|
79
|
+
state: state.trim().toUpperCase(),
|
|
80
|
+
postalCode: postalCode.trim(),
|
|
81
|
+
country: "US",
|
|
82
|
+
};
|
|
83
|
+
const same =
|
|
84
|
+
next.street1 === (address?.street1 ?? "") &&
|
|
85
|
+
(next.street2 ?? "") === (address?.street2 ?? "") &&
|
|
86
|
+
next.city === (address?.city ?? "") &&
|
|
87
|
+
next.state === (address?.state ?? "") &&
|
|
88
|
+
next.postalCode === (address?.postalCode ?? "");
|
|
89
|
+
if (!same) onSave({ address: next });
|
|
90
|
+
};
|
|
91
|
+
return (
|
|
92
|
+
<Stack gap="2">
|
|
93
|
+
{/* The server's message can name internal ids ("patient pat_… has no address"); the title says it. A send
|
|
94
|
+
needs a phone; an address only when the server still asks with a phone on file. */}
|
|
95
|
+
{addressRequest && <Alert tone="warning" title={phone ? "Address needed to send" : "Phone needed to send"} />}
|
|
96
|
+
<Grid min="120px" gap="3">
|
|
97
|
+
<TrackedField formName="update_patient_form" fieldName="phone" isOptional>
|
|
98
|
+
<Input
|
|
99
|
+
label="Phone"
|
|
100
|
+
type="tel"
|
|
101
|
+
inputMode="tel"
|
|
102
|
+
pattern={PHONE_PATTERN}
|
|
103
|
+
value={phoneValue}
|
|
104
|
+
onChange={(e) => setPhone(e.target.value)}
|
|
105
|
+
onBlur={(e) => savePhone(e.currentTarget)}
|
|
106
|
+
{...noAutofill}
|
|
107
|
+
/>
|
|
108
|
+
</TrackedField>
|
|
109
|
+
<TrackedField formName="update_patient_form" fieldName="email" isOptional>
|
|
110
|
+
<Input
|
|
111
|
+
label="Email"
|
|
112
|
+
type="email"
|
|
113
|
+
inputMode="email"
|
|
114
|
+
value={emailValue}
|
|
115
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
116
|
+
onBlur={(e) => saveEmail(e.currentTarget)}
|
|
117
|
+
{...noAutofill}
|
|
118
|
+
/>
|
|
119
|
+
</TrackedField>
|
|
120
|
+
</Grid>
|
|
121
|
+
<div onBlur={saveAddress}>
|
|
122
|
+
<Stack gap="3">
|
|
123
|
+
<Grid min="120px" gap="3">
|
|
124
|
+
<TrackedField formName="update_patient_form" fieldName="address_street1" isOptional>
|
|
125
|
+
<Input label="Street" value={street1} onChange={(e) => setStreet1(e.target.value)} {...noAutofill} />
|
|
126
|
+
</TrackedField>
|
|
127
|
+
<TrackedField formName="update_patient_form" fieldName="address_street2" isOptional>
|
|
128
|
+
<Input label="Apt / suite" value={street2} onChange={(e) => setStreet2(e.target.value)} {...noAutofill} />
|
|
129
|
+
</TrackedField>
|
|
130
|
+
</Grid>
|
|
131
|
+
<Grid min="120px" gap="3">
|
|
132
|
+
<TrackedField formName="update_patient_form" fieldName="address_city" isOptional>
|
|
133
|
+
<Input label="City" value={city} onChange={(e) => setCity(e.target.value)} {...noAutofill} />
|
|
134
|
+
</TrackedField>
|
|
135
|
+
<TrackedField formName="update_patient_form" fieldName="address_state" isOptional>
|
|
136
|
+
<Input
|
|
137
|
+
label="State"
|
|
138
|
+
value={state}
|
|
139
|
+
onChange={(e) => setState(e.target.value)}
|
|
140
|
+
maxLength={2}
|
|
141
|
+
{...noAutofill}
|
|
142
|
+
/>
|
|
143
|
+
</TrackedField>
|
|
144
|
+
<TrackedField formName="update_patient_form" fieldName="address_zip" isOptional>
|
|
145
|
+
<Input
|
|
146
|
+
label="ZIP"
|
|
147
|
+
value={postalCode}
|
|
148
|
+
onChange={(e) => setPostalCode(e.target.value)}
|
|
149
|
+
inputMode="numeric"
|
|
150
|
+
{...noAutofill}
|
|
151
|
+
/>
|
|
152
|
+
</TrackedField>
|
|
153
|
+
</Grid>
|
|
154
|
+
</Stack>
|
|
155
|
+
</div>
|
|
156
|
+
</Stack>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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.ts";
|
|
12
|
+
|
|
13
|
+
export interface ParsedQuery {
|
|
14
|
+
name?: { first?: string; last?: string };
|
|
15
|
+
dateOfBirth?: string;
|
|
16
|
+
phone?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
21
|
+
/** 1990-01-01, 01/01/1990 or 01-01-1990 — the ways a date gets typed. */
|
|
22
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
23
|
+
const US = /^(\d{1,2})[/-](\d{1,2})[/-](\d{4})$/;
|
|
24
|
+
|
|
25
|
+
/** A date as network-api takes it, or nothing if this isn't one. */
|
|
26
|
+
function asDate(token: string): string | undefined {
|
|
27
|
+
if (ISO.test(token)) return token;
|
|
28
|
+
const us = US.exec(token);
|
|
29
|
+
return us ? `${us[3]}-${us[1]!.padStart(2, "0")}-${us[2]!.padStart(2, "0")}` : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 10+ digits, however they're punctuated: (415) 555-0172, 415-555-0172, +14155550172 — sent as E.164. */
|
|
33
|
+
function asPhone(token: string): string | undefined {
|
|
34
|
+
const digits = token.replace(/[\s().+-]/g, "");
|
|
35
|
+
return /^\d{10,11}$/.test(digits) ? toE164(token) : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* What was typed, as the server takes it. Anything that reads as a date, a phone or an email is taken as
|
|
40
|
+
* one; what's left is the name, first word first. A single word is a first name — `searchBoth` says when
|
|
41
|
+
* it's worth trying as a last name too.
|
|
42
|
+
*/
|
|
43
|
+
export function parseQuery(text: string): ParsedQuery {
|
|
44
|
+
const parsed: ParsedQuery = {};
|
|
45
|
+
const words: string[] = [];
|
|
46
|
+
for (const token of text.trim().split(/\s+/).filter(Boolean)) {
|
|
47
|
+
const date = asDate(token);
|
|
48
|
+
if (date && !parsed.dateOfBirth) {
|
|
49
|
+
parsed.dateOfBirth = date;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (EMAIL.test(token) && !parsed.email) {
|
|
53
|
+
parsed.email = token;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const phone = asPhone(token);
|
|
57
|
+
if (phone && !parsed.phone) {
|
|
58
|
+
parsed.phone = phone;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
words.push(token);
|
|
62
|
+
}
|
|
63
|
+
const [first, ...rest] = words;
|
|
64
|
+
if (first) parsed.name = rest.length ? { first, last: rest.join(" ") } : { first };
|
|
65
|
+
return parsed;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** query as patient input */
|
|
69
|
+
export const toSearchInput = ({ phone, email, ...demographic }: ParsedQuery) => ({
|
|
70
|
+
demographic,
|
|
71
|
+
contact: { ...(phone ? { phone } : {}), ...(email ? { email } : {}) },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** Whether a query says anything the server can match on. */
|
|
75
|
+
export const isSearchable = (q: ParsedQuery) =>
|
|
76
|
+
Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One word could be either name. It goes as a first name; if nothing comes back, it's worth asking again
|
|
80
|
+
* as a last name — "Lovelace" is as likely as "Ada".
|
|
81
|
+
*/
|
|
82
|
+
export const searchBoth = (q: ParsedQuery): ParsedQuery | null =>
|
|
83
|
+
q.name?.first && !q.name.last && !q.dateOfBirth && !q.phone && !q.email ? { name: { last: q.name.first } } : null;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { fakeNetworkApiClient, payload } from "@photonhealth/client/testing";
|
|
5
|
+
import { PrescriptionCard } from "./PrescriptionCard.tsx";
|
|
6
|
+
import { fakeNetworkApi, patient, tapDrug, withPhoton } from "../../../test/cards.fixtures.tsx";
|
|
7
|
+
|
|
8
|
+
// The prescription card end to end; its parts are tested beside them (TreatmentSearch, PrescriptionDetailsForm).
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
|
|
12
|
+
describe("PrescriptionCard", () => {
|
|
13
|
+
it("finds a drug, picks its form and strength, takes the server's directions, and is signed", async () => {
|
|
14
|
+
const { client, names } = fakeNetworkApiClient({
|
|
15
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
16
|
+
...fakeNetworkApi({
|
|
17
|
+
prescriptions: {
|
|
18
|
+
amox: [
|
|
19
|
+
["Amoxicillin", "Capsule", "250 MG"],
|
|
20
|
+
["Amoxicillin", "Capsule", "500 MG"],
|
|
21
|
+
["Amoxicillin", "Tablet", "875 MG"],
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
render(<PrescriptionCard patient="pat_1" />, { wrapper: withPhoton(client) });
|
|
27
|
+
|
|
28
|
+
const treatment = await screen.findByLabelText("Treatment");
|
|
29
|
+
treatment.focus();
|
|
30
|
+
fireEvent.change(treatment, { target: { value: "amox" } });
|
|
31
|
+
await tapDrug(/^Amoxicillin/);
|
|
32
|
+
fireEvent.click(within(screen.getByRole("group", { name: "Form" })).getByText("Capsule"));
|
|
33
|
+
fireEvent.click(within(screen.getByRole("group", { name: "Strength" })).getByText("500 mg"));
|
|
34
|
+
|
|
35
|
+
expect(await screen.findByRole("heading", { name: "Amoxicillin" })).toBeTruthy();
|
|
36
|
+
expect(((await screen.findByLabelText("Directions (sig)")) as HTMLTextAreaElement).value).toBe("Take as directed");
|
|
37
|
+
expect((screen.getByLabelText("Quantity") as HTMLInputElement).value).toBe("30");
|
|
38
|
+
|
|
39
|
+
fireEvent.click(await screen.findByRole("button", { name: "Add" }));
|
|
40
|
+
expect(await screen.findByText("Signed")).toBeTruthy();
|
|
41
|
+
await waitFor(() => expect(screen.queryByLabelText("Directions (sig)")).toBeNull()); // signed is read-only
|
|
42
|
+
expect(names()).toContain("SignPrescription");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("doesn't sign while a required field has an error", async () => {
|
|
46
|
+
const { client, names } = fakeNetworkApiClient({
|
|
47
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
48
|
+
...fakeNetworkApi({ prescriptions: { amox: [["Amoxicillin", "Capsule", "500 MG"]] } }),
|
|
49
|
+
});
|
|
50
|
+
render(<PrescriptionCard patient="pat_1" />, { wrapper: withPhoton(client) });
|
|
51
|
+
|
|
52
|
+
const treatment = await screen.findByLabelText("Treatment");
|
|
53
|
+
treatment.focus();
|
|
54
|
+
fireEvent.change(treatment, { target: { value: "amox" } });
|
|
55
|
+
await tapDrug(/^Amoxicillin/);
|
|
56
|
+
await screen.findByLabelText("Directions (sig)");
|
|
57
|
+
fireEvent.change(screen.getByLabelText("Quantity"), { target: { value: "" } });
|
|
58
|
+
|
|
59
|
+
fireEvent.click(screen.getByRole("button", { name: "Add" }));
|
|
60
|
+
expect(await screen.findByText("Required")).toBeTruthy();
|
|
61
|
+
expect(names()).not.toContain("SignPrescription");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("offers Add once a product is picked before there's a patient, and says a patient is required", async () => {
|
|
65
|
+
const { client, names } = fakeNetworkApiClient({
|
|
66
|
+
...fakeNetworkApi({ prescriptions: { amox: [["Amoxicillin", "Capsule", "500 MG"]] } }),
|
|
67
|
+
});
|
|
68
|
+
render(<PrescriptionCard />, { wrapper: withPhoton(client) });
|
|
69
|
+
|
|
70
|
+
const treatment = await screen.findByLabelText("Treatment");
|
|
71
|
+
treatment.focus();
|
|
72
|
+
fireEvent.change(treatment, { target: { value: "amox" } });
|
|
73
|
+
await tapDrug(/^Amoxicillin/);
|
|
74
|
+
await screen.findByLabelText("Directions (sig)");
|
|
75
|
+
// Nothing is drafted without a patient, so the required fields start empty.
|
|
76
|
+
fireEvent.change(screen.getByLabelText("Directions (sig)"), { target: { value: "1 cap PO TID" } });
|
|
77
|
+
fireEvent.change(screen.getByLabelText("Quantity"), { target: { value: "21" } });
|
|
78
|
+
fireEvent.change(screen.getByLabelText("Days supply"), { target: { value: "7" } });
|
|
79
|
+
|
|
80
|
+
fireEvent.click(screen.getByRole("button", { name: "Add" }));
|
|
81
|
+
expect(await screen.findByText("A patient is required for signing")).toBeTruthy();
|
|
82
|
+
expect(names()).not.toContain("SyncPrescription");
|
|
83
|
+
expect(names()).not.toContain("SignPrescription");
|
|
84
|
+
});
|
|
85
|
+
});
|