@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,99 @@
|
|
|
1
|
+
import type { PrescriptionEdits } from "@photonhealth/client";
|
|
2
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
3
|
+
import { TrackedField, useFieldInteractions } from "../../../analytics/fieldInteraction.tsx";
|
|
4
|
+
|
|
5
|
+
export type DispenseField = "quantity" | "unit" | "daysSupply" | "refills";
|
|
6
|
+
export type DispenseValues = Record<DispenseField, string> & { dispenseAsWritten: boolean };
|
|
7
|
+
export type DispensePatch = NonNullable<PrescriptionEdits["dispense"]>;
|
|
8
|
+
|
|
9
|
+
/** Quantity / unit / days / refills, then DAW. Their values are kept by PrescriptionDetailsForm, which saves them. */
|
|
10
|
+
export interface DispenseInputsProps {
|
|
11
|
+
values: DispenseValues;
|
|
12
|
+
/** What's wrong with a field, shown under it. */
|
|
13
|
+
errors?: Partial<Record<DispenseField, string>>;
|
|
14
|
+
/** The units the picked drug is dispensed in; without them the unit is typed. */
|
|
15
|
+
units: readonly string[];
|
|
16
|
+
/** Fields typed in since they were last saved. */
|
|
17
|
+
edited: ReadonlySet<DispenseField>;
|
|
18
|
+
/** The field whose save is in flight. */
|
|
19
|
+
spinning: string | null;
|
|
20
|
+
onEdit: (field: DispenseField, value: string) => void;
|
|
21
|
+
/** Only the field that changed: network-api merges a partial dispense. */
|
|
22
|
+
save: (field: DispenseField | "daw", patch: DispensePatch) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const num = (value: string) => (value.trim() === "" ? undefined : Number(value));
|
|
26
|
+
|
|
27
|
+
export function DispenseInputs({ values, errors = {}, units, edited, spinning, onEdit, save }: DispenseInputsProps) {
|
|
28
|
+
const { Checkbox, Grid, Input, Select } = useComponents();
|
|
29
|
+
const fieldInteraction = useFieldInteractions("add_prescription_form");
|
|
30
|
+
const unitPicked = fieldInteraction("dispenseUnit", { isOptional: false, hasValue: Boolean(values.unit.trim()) });
|
|
31
|
+
const dispenseAsWritten = fieldInteraction("dispenseAsWritten", {
|
|
32
|
+
isOptional: true,
|
|
33
|
+
hasValue: values.dispenseAsWritten,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const typed = (field: DispenseField, toPatch: (value: string) => DispensePatch) => ({
|
|
37
|
+
value: values[field],
|
|
38
|
+
invalid: Boolean(errors[field]),
|
|
39
|
+
errorMessage: errors[field],
|
|
40
|
+
// A value the server filled in (e.g. quantity 30) is selected, so typing replaces it.
|
|
41
|
+
onFocus: (e: { currentTarget: HTMLInputElement }) => {
|
|
42
|
+
if (!edited.has(field)) e.currentTarget.select();
|
|
43
|
+
},
|
|
44
|
+
onChange: (e: { target: HTMLInputElement }) => onEdit(field, e.target.value),
|
|
45
|
+
onBlur: () => {
|
|
46
|
+
if (edited.has(field)) save(field, toPatch(values[field]));
|
|
47
|
+
},
|
|
48
|
+
loading: spinning === field,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// The prescription's own unit stays listed, even when it isn't one the drug is dispensed in.
|
|
52
|
+
const unit = values.unit.trim();
|
|
53
|
+
const listedUnit = units.find((u) => u.toLowerCase() === unit.toLowerCase());
|
|
54
|
+
const unitOptions = [...units, ...(unit && !listedUnit ? [values.unit] : [])].map((u) => ({ value: u, label: u }));
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<Grid min="64px" gap="2">
|
|
59
|
+
<TrackedField formName="add_prescription_form" fieldName="dispenseQuantity" isOptional={false}>
|
|
60
|
+
<Input label="Quantity" inputMode="decimal" {...typed("quantity", (v) => ({ quantity: num(v) }))} />
|
|
61
|
+
</TrackedField>
|
|
62
|
+
{units.length > 0 ? (
|
|
63
|
+
<div style={{ display: "contents" }} onFocus={unitPicked.onFocus} onBlur={unitPicked.onBlur}>
|
|
64
|
+
<Select
|
|
65
|
+
label="Unit"
|
|
66
|
+
options={unitOptions}
|
|
67
|
+
value={listedUnit ?? (values.unit || null)}
|
|
68
|
+
onChange={(value) => {
|
|
69
|
+
unitPicked.onChange(true);
|
|
70
|
+
onEdit("unit", value);
|
|
71
|
+
save("unit", { unit: value });
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
75
|
+
) : (
|
|
76
|
+
<TrackedField formName="add_prescription_form" fieldName="dispenseUnit" isOptional={false}>
|
|
77
|
+
<Input label="Unit" {...typed("unit", (v) => ({ unit: v || undefined }))} />
|
|
78
|
+
</TrackedField>
|
|
79
|
+
)}
|
|
80
|
+
<TrackedField formName="add_prescription_form" fieldName="daysSupply" isOptional>
|
|
81
|
+
<Input label="Days supply" inputMode="numeric" {...typed("daysSupply", (v) => ({ daysSupply: num(v) }))} />
|
|
82
|
+
</TrackedField>
|
|
83
|
+
<TrackedField formName="add_prescription_form" fieldName="refills" isOptional>
|
|
84
|
+
<Input label="Refills" inputMode="numeric" {...typed("refills", (v) => ({ refillsAllowed: num(v) }))} />
|
|
85
|
+
</TrackedField>
|
|
86
|
+
</Grid>
|
|
87
|
+
<div onFocus={dispenseAsWritten.onFocus} onBlur={dispenseAsWritten.onBlur}>
|
|
88
|
+
<Checkbox
|
|
89
|
+
label="Dispense as written"
|
|
90
|
+
checked={values.dispenseAsWritten}
|
|
91
|
+
onChange={(checked) => {
|
|
92
|
+
dispenseAsWritten.onChange(checked);
|
|
93
|
+
save("daw", { dispenseAsWritten: checked });
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import type { Prescription, PrescriptionRecord, PrescriptionTemplate, TemplateSource } from "@photonhealth/client";
|
|
3
|
+
import { treatment } from "@photonhealth/client/testing";
|
|
4
|
+
import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { PrescriptionDetailsForm, type PrescriptionDetailsFormProps } from "./PrescriptionDetailsForm.tsx";
|
|
7
|
+
|
|
8
|
+
const directions = "Take 1 capsule by mouth 3 times per day";
|
|
9
|
+
|
|
10
|
+
const noDispense = { quantity: null, unit: null, daysSupply: null, refillsAllowed: null, dispenseAsWritten: null };
|
|
11
|
+
|
|
12
|
+
const prescriptionTemplate = (
|
|
13
|
+
source: TemplateSource,
|
|
14
|
+
fields: Partial<Omit<PrescriptionTemplate, "source">> = {},
|
|
15
|
+
): PrescriptionTemplate => ({
|
|
16
|
+
id: null,
|
|
17
|
+
source,
|
|
18
|
+
name: null,
|
|
19
|
+
instructions: null,
|
|
20
|
+
dispense: null,
|
|
21
|
+
...fields,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const renderFields = ({
|
|
25
|
+
dispense,
|
|
26
|
+
open = true,
|
|
27
|
+
instructions = directions,
|
|
28
|
+
templates = [],
|
|
29
|
+
pickedTemplates = null,
|
|
30
|
+
}: {
|
|
31
|
+
dispense?: Partial<NonNullable<PrescriptionRecord["dispense"]>>;
|
|
32
|
+
open?: boolean;
|
|
33
|
+
instructions?: string | null;
|
|
34
|
+
templates?: PrescriptionTemplate[];
|
|
35
|
+
pickedTemplates?: PrescriptionTemplate[] | null;
|
|
36
|
+
} = {}) => {
|
|
37
|
+
const drug = { ...treatment(), templates: pickedTemplates };
|
|
38
|
+
// PrescriptionDetailsForm reads only these from the live prescription.
|
|
39
|
+
const live = { treatment: drug, entered: {} } as Pick<Prescription, "treatment" | "entered"> as Prescription;
|
|
40
|
+
let record: PrescriptionRecord = {
|
|
41
|
+
id: "rx_1",
|
|
42
|
+
prescriber: null,
|
|
43
|
+
fulfillment: null,
|
|
44
|
+
templateId: null,
|
|
45
|
+
patient: null,
|
|
46
|
+
treatment: drug,
|
|
47
|
+
instructions,
|
|
48
|
+
dispense: {
|
|
49
|
+
quantity: 30,
|
|
50
|
+
unit: "Capsule",
|
|
51
|
+
daysSupply: 10,
|
|
52
|
+
refillsAllowed: 0,
|
|
53
|
+
dispenseAsWritten: false,
|
|
54
|
+
...dispense,
|
|
55
|
+
},
|
|
56
|
+
clinical: null,
|
|
57
|
+
screeningAlerts: [],
|
|
58
|
+
signing: { state: "UNSIGNED", contentHash: "hash_0", message: null, signedAt: null },
|
|
59
|
+
};
|
|
60
|
+
const save = vi.fn<PrescriptionDetailsFormProps["save"]>();
|
|
61
|
+
const onAdd = vi.fn<PrescriptionDetailsFormProps["onAdd"]>();
|
|
62
|
+
const props = (): PrescriptionDetailsFormProps => ({
|
|
63
|
+
live,
|
|
64
|
+
rx: record,
|
|
65
|
+
open,
|
|
66
|
+
focusable: false,
|
|
67
|
+
templates,
|
|
68
|
+
spinning: null,
|
|
69
|
+
save,
|
|
70
|
+
onAdd,
|
|
71
|
+
adding: false,
|
|
72
|
+
addDisabled: false,
|
|
73
|
+
});
|
|
74
|
+
const { rerender } = render(<PrescriptionDetailsForm {...props()} />);
|
|
75
|
+
return {
|
|
76
|
+
save,
|
|
77
|
+
onAdd,
|
|
78
|
+
clickAdd: () => fireEvent.click(screen.getByRole("button", { name: "Add" })),
|
|
79
|
+
setOpen: (isOpen: boolean) => {
|
|
80
|
+
open = isOpen;
|
|
81
|
+
rerender(<PrescriptionDetailsForm {...props()} />);
|
|
82
|
+
},
|
|
83
|
+
// A new contentHash, as Photon gives every changed copy, is what makes the fields take it up.
|
|
84
|
+
receiveDirections: (instructions: string) => {
|
|
85
|
+
record = { ...record, instructions, signing: { ...record.signing, contentHash: "hash_1" } };
|
|
86
|
+
rerender(<PrescriptionDetailsForm {...props()} />);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const field = (label: string) => screen.getByLabelText<HTMLInputElement | HTMLTextAreaElement>(label);
|
|
92
|
+
|
|
93
|
+
const type = (label: string, value: string) => fireEvent.change(field(label), { target: { value } });
|
|
94
|
+
|
|
95
|
+
const leave = (label: string) => fireEvent.blur(field(label));
|
|
96
|
+
|
|
97
|
+
const options = () => screen.queryByRole("list", { name: "Templates" });
|
|
98
|
+
|
|
99
|
+
// Directions, quantity and days supply — the fields Add needs — all empty.
|
|
100
|
+
const empty = { instructions: null, dispense: { quantity: null, daysSupply: null } };
|
|
101
|
+
|
|
102
|
+
const dispenseAsWritten = () => screen.getByRole<HTMLInputElement>("checkbox", { name: "Dispense as written" });
|
|
103
|
+
|
|
104
|
+
describe("PrescriptionDetailsForm", () => {
|
|
105
|
+
afterEach(() => cleanup());
|
|
106
|
+
|
|
107
|
+
describe("showing the prescription", () => {
|
|
108
|
+
it("shows the stored directions and dispense", () => {
|
|
109
|
+
renderFields();
|
|
110
|
+
expect(field("Directions (sig)").value).toBe(directions);
|
|
111
|
+
expect(field("Quantity").value).toBe("30");
|
|
112
|
+
expect(field("Unit").value).toBe("Capsule");
|
|
113
|
+
expect(field("Days supply").value).toBe("10");
|
|
114
|
+
expect(field("Refills").value).toBe("0");
|
|
115
|
+
expect(dispenseAsWritten().checked).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("saving edits", () => {
|
|
120
|
+
it("saves only the changed field when I leave the field", () => {
|
|
121
|
+
const { save } = renderFields();
|
|
122
|
+
type("Directions (sig)", "Take 1 capsule by mouth daily");
|
|
123
|
+
leave("Directions (sig)");
|
|
124
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ instructions: "Take 1 capsule by mouth daily" }, "instructions");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("doesn't save field that is unchanged when I leave the field", () => {
|
|
128
|
+
const { save } = renderFields();
|
|
129
|
+
type("Directions (sig)", "Take 1 capsule by mouth daily");
|
|
130
|
+
type("Directions (sig)", directions);
|
|
131
|
+
leave("Directions (sig)");
|
|
132
|
+
expect(save).not.toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it.each([
|
|
136
|
+
["Quantity", "sd"],
|
|
137
|
+
["Quantity", "0"],
|
|
138
|
+
["Quantity", ""],
|
|
139
|
+
["Days supply", "abc"],
|
|
140
|
+
["Days supply", "-1"],
|
|
141
|
+
["Directions (sig)", " "],
|
|
142
|
+
])("doesn't save %s of %j: it isn't valid, so it's never sent", (label, value) => {
|
|
143
|
+
const { save } = renderFields();
|
|
144
|
+
type(label, value);
|
|
145
|
+
leave(label);
|
|
146
|
+
expect(save).not.toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("saves a field once it's valid again", () => {
|
|
150
|
+
const { save } = renderFields();
|
|
151
|
+
type("Quantity", "sd");
|
|
152
|
+
leave("Quantity");
|
|
153
|
+
type("Quantity", "45");
|
|
154
|
+
leave("Quantity");
|
|
155
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ dispense: { quantity: 45 } }, "quantity");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("saves a valid field while another field isn't valid", () => {
|
|
159
|
+
const { save } = renderFields({ dispense: { daysSupply: null } });
|
|
160
|
+
type("Quantity", "60");
|
|
161
|
+
leave("Quantity");
|
|
162
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ dispense: { quantity: 60 } }, "quantity");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('saves "Dispense as written" and keeps it checked', () => {
|
|
166
|
+
const { save } = renderFields();
|
|
167
|
+
fireEvent.click(dispenseAsWritten());
|
|
168
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ dispense: { dispenseAsWritten: true } }, "daw");
|
|
169
|
+
expect(dispenseAsWritten().checked).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("dispense units", () => {
|
|
174
|
+
it("offers the units the recommended templates set", () => {
|
|
175
|
+
renderFields({
|
|
176
|
+
templates: [
|
|
177
|
+
prescriptionTemplate("RECOMMENDED", {
|
|
178
|
+
instructions: "Take 1 capsule by mouth daily",
|
|
179
|
+
dispense: { ...noDispense, unit: "Capsule" },
|
|
180
|
+
}),
|
|
181
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Bottle" } }),
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
const options = within(screen.getByRole("combobox", { name: "Unit" })).getAllByRole<HTMLOptionElement>("option");
|
|
185
|
+
expect(options.filter((option) => !option.disabled).map((option) => option.textContent)).toEqual([
|
|
186
|
+
"Capsule",
|
|
187
|
+
"Bottle",
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("doesn't offer a catalog template's unit", () => {
|
|
192
|
+
renderFields({
|
|
193
|
+
templates: [
|
|
194
|
+
prescriptionTemplate("ORG_CATALOG", { id: "tmp_1", dispense: { ...noDispense, unit: "Pack" } }),
|
|
195
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Capsule" } }),
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
const options = within(screen.getByRole("combobox", { name: "Unit" })).getAllByRole<HTMLOptionElement>("option");
|
|
199
|
+
expect(options.filter((option) => !option.disabled).map((option) => option.textContent)).toEqual(["Capsule"]);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("offers the picked drug's units before the draft's templates load", () => {
|
|
203
|
+
const { save } = renderFields({
|
|
204
|
+
dispense: { unit: null },
|
|
205
|
+
pickedTemplates: [prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Capsule" } })],
|
|
206
|
+
});
|
|
207
|
+
expect(field("Unit").value).toBe("Capsule");
|
|
208
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ dispense: { unit: "Capsule" } }, "unit");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("fills in and saves the first recommended unit when there's no unit", () => {
|
|
212
|
+
const { save } = renderFields({
|
|
213
|
+
dispense: { unit: null },
|
|
214
|
+
templates: [
|
|
215
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Capsule" } }),
|
|
216
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Bottle" } }),
|
|
217
|
+
],
|
|
218
|
+
});
|
|
219
|
+
expect(field("Unit").value).toBe("Capsule");
|
|
220
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ dispense: { unit: "Capsule" } }, "unit");
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("updates from Photon", () => {
|
|
225
|
+
it("doesn't replace directions being typed", () => {
|
|
226
|
+
const { receiveDirections } = renderFields();
|
|
227
|
+
type("Directions (sig)", "Take 2 capsules");
|
|
228
|
+
receiveDirections("Take as directed");
|
|
229
|
+
expect(field("Directions (sig)").value).toBe("Take 2 capsules");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("show in a field that isn't being edited", () => {
|
|
233
|
+
const { receiveDirections } = renderFields();
|
|
234
|
+
receiveDirections("Take as directed");
|
|
235
|
+
expect(field("Directions (sig)").value).toBe("Take as directed");
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("template options", () => {
|
|
240
|
+
it("offers ORG_CATALOG, PERSONAL_CATALOG, and RECOMMENDED templates", () => {
|
|
241
|
+
renderFields({
|
|
242
|
+
instructions: null,
|
|
243
|
+
templates: [
|
|
244
|
+
prescriptionTemplate("PERSONAL_CATALOG", { id: "tmp_1", name: "My sinusitis" }),
|
|
245
|
+
prescriptionTemplate("ORG_CATALOG", { id: "tmp_2", name: "Sinusitis" }),
|
|
246
|
+
prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" }),
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
const offered = within(options()!)
|
|
250
|
+
.getAllByRole("button")
|
|
251
|
+
.map((button) => button.textContent);
|
|
252
|
+
expect(offered).toEqual(["My sinusitis", "Sinusitis", "Take 1 capsule by mouth daily"]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("doesn't offer a unit-only RECOMMENDED template as a template option", () => {
|
|
256
|
+
renderFields({
|
|
257
|
+
instructions: null,
|
|
258
|
+
templates: [
|
|
259
|
+
prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" }),
|
|
260
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Bottle" } }),
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
const offered = within(options()!)
|
|
264
|
+
.getAllByRole("button")
|
|
265
|
+
.map((button) => button.textContent);
|
|
266
|
+
expect(offered).toEqual(["Take 1 capsule by mouth daily"]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("uses unit-only RECOMMENDED templates to populate dispense unit options", () => {
|
|
270
|
+
renderFields({
|
|
271
|
+
instructions: null,
|
|
272
|
+
templates: [
|
|
273
|
+
prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" }),
|
|
274
|
+
prescriptionTemplate("RECOMMENDED", { dispense: { ...noDispense, unit: "Bottle" } }),
|
|
275
|
+
],
|
|
276
|
+
});
|
|
277
|
+
const units = within(screen.getByRole("combobox", { name: "Unit" })).getAllByRole<HTMLOptionElement>("option");
|
|
278
|
+
expect(units.filter((unit) => !unit.disabled).map((unit) => unit.textContent)).toContain("Bottle");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("fills in and saves the option I choose", () => {
|
|
282
|
+
const { save } = renderFields({
|
|
283
|
+
instructions: null,
|
|
284
|
+
templates: [prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" })],
|
|
285
|
+
});
|
|
286
|
+
fireEvent.click(screen.getByRole("button", { name: "Take 1 capsule by mouth daily" }));
|
|
287
|
+
expect(field("Directions (sig)").value).toBe("Take 1 capsule by mouth daily");
|
|
288
|
+
expect(save).toHaveBeenCalledExactlyOnceWith({ instructions: "Take 1 capsule by mouth daily" }, "instructions");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// A dispense value the new option leaves empty keeps the previous option's: network-api can't clear
|
|
292
|
+
// quantity or unit on a draft (TECH-1247)
|
|
293
|
+
it("replaces the directions and the dispense values it sets when I choose another option", () => {
|
|
294
|
+
const once = prescriptionTemplate("RECOMMENDED", {
|
|
295
|
+
instructions: "Take 1 capsule by mouth daily",
|
|
296
|
+
dispense: { ...noDispense, quantity: 30, unit: "Capsule", daysSupply: 30 },
|
|
297
|
+
});
|
|
298
|
+
const twice = prescriptionTemplate("RECOMMENDED", {
|
|
299
|
+
instructions: "Take 1 capsule by mouth 2 times per day",
|
|
300
|
+
dispense: { ...noDispense, quantity: 60, unit: "Capsule", daysSupply: 30 },
|
|
301
|
+
});
|
|
302
|
+
const { save } = renderFields({ instructions: null, templates: [once, twice] });
|
|
303
|
+
fireEvent.click(screen.getByRole("button", { name: "Take 1 capsule by mouth daily" }));
|
|
304
|
+
fireEvent.click(screen.getByRole("button", { name: "Templates" }));
|
|
305
|
+
fireEvent.click(screen.getByRole("button", { name: "Take 1 capsule by mouth 2 times per day" }));
|
|
306
|
+
|
|
307
|
+
expect(field("Directions (sig)").value).toBe("Take 1 capsule by mouth 2 times per day");
|
|
308
|
+
expect(field("Quantity").value).toBe("60");
|
|
309
|
+
expect(field("Days supply").value).toBe("30");
|
|
310
|
+
expect(save).toHaveBeenLastCalledWith(
|
|
311
|
+
{
|
|
312
|
+
instructions: "Take 1 capsule by mouth 2 times per day",
|
|
313
|
+
dispense: { quantity: 60, unit: "Capsule", daysSupply: 30 },
|
|
314
|
+
},
|
|
315
|
+
"instructions",
|
|
316
|
+
);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("fills in and saves every field a catalog template sets, in one save, and leaves the rest alone", () => {
|
|
320
|
+
const catalog = prescriptionTemplate("ORG_CATALOG", {
|
|
321
|
+
id: "tmp_1",
|
|
322
|
+
name: "Sinusitis",
|
|
323
|
+
instructions: "Take 1 capsule by mouth twice daily for 10 days",
|
|
324
|
+
dispense: { ...noDispense, quantity: 20, daysSupply: 10 },
|
|
325
|
+
});
|
|
326
|
+
const { save } = renderFields({ instructions: null, templates: [catalog] });
|
|
327
|
+
|
|
328
|
+
fireEvent.click(screen.getByRole("button", { name: /Sinusitis/ }));
|
|
329
|
+
|
|
330
|
+
expect(field("Directions (sig)").value).toBe("Take 1 capsule by mouth twice daily for 10 days");
|
|
331
|
+
expect(field("Quantity").value).toBe("20");
|
|
332
|
+
expect(field("Days supply").value).toBe("10");
|
|
333
|
+
expect(field("Unit").value).toBe("Capsule");
|
|
334
|
+
expect(save).toHaveBeenCalledExactlyOnceWith(
|
|
335
|
+
{ instructions: "Take 1 capsule by mouth twice daily for 10 days", dispense: { quantity: 20, daysSupply: 10 } },
|
|
336
|
+
"instructions",
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("hides the options once I choose one", () => {
|
|
341
|
+
renderFields({
|
|
342
|
+
instructions: null,
|
|
343
|
+
templates: [prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" })],
|
|
344
|
+
});
|
|
345
|
+
fireEvent.click(screen.getByRole("button", { name: "Take 1 capsule by mouth daily" }));
|
|
346
|
+
expect(options()).toBeNull();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("shows the templates above the directions", () => {
|
|
350
|
+
renderFields({
|
|
351
|
+
instructions: null,
|
|
352
|
+
templates: [prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" })],
|
|
353
|
+
});
|
|
354
|
+
const templates = screen.getByRole("button", { name: "Templates" });
|
|
355
|
+
expect(
|
|
356
|
+
templates.compareDocumentPosition(field("Directions (sig)")) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
357
|
+
).toBeTruthy();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("lets me edit directions after I choose a template", () => {
|
|
361
|
+
const { save } = renderFields({
|
|
362
|
+
instructions: null,
|
|
363
|
+
templates: [prescriptionTemplate("RECOMMENDED", { instructions: "Take 1 capsule by mouth daily" })],
|
|
364
|
+
});
|
|
365
|
+
fireEvent.click(screen.getByRole("button", { name: "Take 1 capsule by mouth daily" }));
|
|
366
|
+
type("Directions (sig)", "Take 1 capsule by mouth daily with food");
|
|
367
|
+
leave("Directions (sig)");
|
|
368
|
+
expect(save).toHaveBeenLastCalledWith(
|
|
369
|
+
{ instructions: "Take 1 capsule by mouth daily with food" },
|
|
370
|
+
"instructions",
|
|
371
|
+
);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe("field validation", () => {
|
|
376
|
+
const isInvalid = (label: string) => field(label).getAttribute("aria-invalid") === "true";
|
|
377
|
+
// Get error message for the field with `label`
|
|
378
|
+
const errorOf = (label: string) => {
|
|
379
|
+
if (!isInvalid(label)) return null;
|
|
380
|
+
const note = field(label).getAttribute("aria-describedby");
|
|
381
|
+
return note ? document.getElementById(note)?.textContent : null;
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
it("shows no validation errors before Add is clicked", () => {
|
|
385
|
+
renderFields(empty);
|
|
386
|
+
expect(isInvalid("Directions (sig)")).toBe(false);
|
|
387
|
+
expect(isInvalid("Quantity")).toBe(false);
|
|
388
|
+
expect(isInvalid("Days supply")).toBe(false);
|
|
389
|
+
expect(screen.queryByText("Required")).toBeNull();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("on Add, shows errors for directions, quantity and days supply when they're empty", () => {
|
|
393
|
+
const { clickAdd } = renderFields(empty);
|
|
394
|
+
clickAdd();
|
|
395
|
+
expect(errorOf("Directions (sig)")).toBe("Required");
|
|
396
|
+
expect(errorOf("Quantity")).toBe("Required");
|
|
397
|
+
expect(errorOf("Days supply")).toBe("Required");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("on Add, shows no errors for unit and refills", () => {
|
|
401
|
+
const { clickAdd } = renderFields({ ...empty, dispense: { ...empty.dispense, refillsAllowed: null } });
|
|
402
|
+
clickAdd();
|
|
403
|
+
expect(isInvalid("Unit")).toBe(false);
|
|
404
|
+
expect(isInvalid("Refills")).toBe(false);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("on Add, shows no errors when every required field is valid", () => {
|
|
408
|
+
const { clickAdd } = renderFields();
|
|
409
|
+
clickAdd();
|
|
410
|
+
expect(isInvalid("Directions (sig)")).toBe(false);
|
|
411
|
+
expect(isInvalid("Quantity")).toBe(false);
|
|
412
|
+
expect(isInvalid("Days supply")).toBe(false);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("clears a field's error once it's valid, and keeps the others'", () => {
|
|
416
|
+
const { clickAdd } = renderFields(empty);
|
|
417
|
+
clickAdd();
|
|
418
|
+
type("Quantity", "30");
|
|
419
|
+
expect(isInvalid("Quantity")).toBe(false);
|
|
420
|
+
expect(errorOf("Days supply")).toBe("Required");
|
|
421
|
+
expect(errorOf("Directions (sig)")).toBe("Required");
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("shows a field's new error when its value changes to another invalid one", () => {
|
|
425
|
+
const { clickAdd } = renderFields({ dispense: { quantity: null } });
|
|
426
|
+
clickAdd();
|
|
427
|
+
expect(errorOf("Quantity")).toBe("Required");
|
|
428
|
+
type("Quantity", "0");
|
|
429
|
+
expect(errorOf("Quantity")).toBe("Must be greater than 0");
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
describe("clicking Add", () => {
|
|
434
|
+
it("doesn't add while a field has an error", () => {
|
|
435
|
+
const { clickAdd, onAdd } = renderFields({ dispense: { daysSupply: null } });
|
|
436
|
+
clickAdd();
|
|
437
|
+
expect(onAdd).not.toHaveBeenCalled();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it("adds once every field is valid", () => {
|
|
441
|
+
const { clickAdd, onAdd } = renderFields(empty);
|
|
442
|
+
clickAdd();
|
|
443
|
+
type("Directions (sig)", directions);
|
|
444
|
+
type("Quantity", "30");
|
|
445
|
+
type("Days supply", "10");
|
|
446
|
+
clickAdd();
|
|
447
|
+
expect(onAdd).toHaveBeenCalledOnce();
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("adds at once when the prescription already has every required field", () => {
|
|
451
|
+
const { clickAdd, onAdd } = renderFields();
|
|
452
|
+
clickAdd();
|
|
453
|
+
expect(onAdd).toHaveBeenCalledOnce();
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|