@photonhealth/react 2.0.0-rc.1 → 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/README.md +35 -8
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -4
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +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/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +20 -16
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +4 -2
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +1 -12
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +7 -360
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/format.d.ts +2 -2
- package/dist/components/format.js +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/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.map +1 -1
- package/dist/components/patient/Benefits.js +2 -1
- package/dist/components/patient/Benefits.js.map +1 -1
- package/dist/components/patient/Clinical.d.ts +3 -2
- package/dist/components/patient/Clinical.d.ts.map +1 -1
- package/dist/components/patient/Clinical.js +21 -20
- package/dist/components/patient/Clinical.js.map +1 -1
- package/dist/components/patient/IntakeForm.d.ts.map +1 -1
- package/dist/components/patient/IntakeForm.js +52 -43
- package/dist/components/patient/IntakeForm.js.map +1 -1
- package/dist/components/patient/Summary.d.ts +1 -1
- package/dist/components/patient/Summary.d.ts.map +1 -1
- package/dist/components/patient/Summary.js +13 -3
- package/dist/components/patient/Summary.js.map +1 -1
- package/dist/components/patient/fields.d.ts +1 -2
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +2 -1
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/query.d.ts +14 -0
- package/dist/components/patient/query.d.ts.map +1 -1
- package/dist/components/patient/query.js +5 -0
- package/dist/components/patient/query.js.map +1 -1
- 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/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +3 -1
- package/dist/primitives/PhotonProvider.d.ts.map +1 -1
- package/dist/primitives/PhotonProvider.js +23 -11
- package/dist/primitives/PhotonProvider.js.map +1 -1
- package/dist/primitives/defaults.d.ts.map +1 -1
- package/dist/primitives/defaults.js +6 -3
- package/dist/primitives/defaults.js.map +1 -1
- package/dist/primitives/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.js.map +1 -0
- package/dist/primitives/types.d.ts +15 -3
- package/dist/primitives/types.d.ts.map +1 -1
- package/dist/primitives/types.js.map +1 -1
- package/dist/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +45 -3
- package/dist/test-utils/contract.d.ts.map +1 -1
- package/dist/test-utils/contract.js +23 -2
- package/dist/test-utils/contract.js.map +1 -1
- package/package.json +5 -3
- package/src/adapters/tailwind.tsx +52 -24
- 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/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +45 -30
- package/src/components/PhotonPatient.tsx +11 -7
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +10 -570
- package/src/components/format.ts +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +21 -13
- package/src/components/patient/Clinical.tsx +31 -26
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +168 -136
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +54 -34
- package/src/components/patient/fields.tsx +52 -38
- package/src/components/patient/query.ts +6 -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/index.ts +2 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +30 -15
- package/src/primitives/defaults.tsx +44 -21
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/types.ts +15 -3
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +45 -3
- package/src/test-utils/contract.tsx +45 -2
- package/dist/components/TreatmentPicker.d.ts +0 -45
- package/dist/components/TreatmentPicker.d.ts.map +0 -1
- package/dist/components/TreatmentPicker.js.map +0 -1
- package/src/components/TreatmentPicker.tsx +0 -350
|
@@ -11,11 +11,12 @@ import { Fragment, useState, type ReactNode } from "react";
|
|
|
11
11
|
import { ageOn, displayName, shortDate } from "../format.ts";
|
|
12
12
|
|
|
13
13
|
type PatientDemographicInput = NonNullable<PatientInput["demographic"]>;
|
|
14
|
-
type AddressInput = NonNullable<
|
|
14
|
+
type AddressInput = NonNullable<NonNullable<PatientInput["contact"]>["address"]>;
|
|
15
15
|
import { BenefitsSection, type BenefitInput } from "./Benefits.tsx";
|
|
16
16
|
import { choicesIn, ClinicalList, sectionOf } from "./Clinical.tsx";
|
|
17
17
|
import { noAutofill, SEX_OPTIONS, ContactFields } from "./fields.tsx";
|
|
18
18
|
import { focusProps } from "../flow.ts";
|
|
19
|
+
import { TrackedField, useFieldInteractions } from "../../analytics/fieldInteraction.tsx";
|
|
19
20
|
|
|
20
21
|
const fullName = (p: PatientRecord) =>
|
|
21
22
|
[p.demographic?.name.first, p.demographic?.name.last].filter(Boolean).join(" ") || "Unnamed patient";
|
|
@@ -88,12 +89,13 @@ export function PatientSummary({
|
|
|
88
89
|
setEditing(Boolean(addressRequest));
|
|
89
90
|
}
|
|
90
91
|
const d = patient.demographic;
|
|
92
|
+
const contact = patient.contact;
|
|
91
93
|
// Each list: null when nothing is recorded, [] when "none" is (core's PatientRecord).
|
|
92
94
|
const recorded = {
|
|
93
95
|
allergies: patient.clinical?.allergies ?? null,
|
|
94
96
|
medications: patient.clinical?.medications ?? null,
|
|
95
97
|
diagnoses: patient.clinical?.diagnoses ?? null,
|
|
96
|
-
benefits:
|
|
98
|
+
benefits: patient.benefits,
|
|
97
99
|
};
|
|
98
100
|
const confirmedNkda = recorded.allergies?.length === 0;
|
|
99
101
|
const allergies = recorded.allergies ?? [];
|
|
@@ -180,14 +182,15 @@ export function PatientSummary({
|
|
|
180
182
|
<Stack gap="4">
|
|
181
183
|
<DetailsEditor patient={patient} onSave={onSaveDetails} />
|
|
182
184
|
<ContactFields
|
|
183
|
-
phone={
|
|
184
|
-
email={
|
|
185
|
-
address={
|
|
185
|
+
phone={contact?.phone ?? null}
|
|
186
|
+
email={contact?.email ?? null}
|
|
187
|
+
address={contact?.address ?? null}
|
|
186
188
|
onSave={onSaveContact}
|
|
187
189
|
addressRequest={addressRequest}
|
|
188
190
|
/>
|
|
189
191
|
<ClinicalList
|
|
190
192
|
label="Allergies"
|
|
193
|
+
fieldName="allergies"
|
|
191
194
|
choices={choicesIn(choices, "allergies")}
|
|
192
195
|
problems={choicesIn(problems, "allergies")}
|
|
193
196
|
onChoose={onChoose}
|
|
@@ -206,6 +209,7 @@ export function PatientSummary({
|
|
|
206
209
|
/>
|
|
207
210
|
<ClinicalList
|
|
208
211
|
label="Medications"
|
|
212
|
+
fieldName="medications"
|
|
209
213
|
choices={choicesIn(choices, "medications")}
|
|
210
214
|
problems={choicesIn(problems, "medications")}
|
|
211
215
|
onChoose={onChoose}
|
|
@@ -224,6 +228,7 @@ export function PatientSummary({
|
|
|
224
228
|
/>
|
|
225
229
|
<ClinicalList
|
|
226
230
|
label="Diagnoses"
|
|
231
|
+
fieldName="diagnoses"
|
|
227
232
|
choices={choicesIn(choices, "diagnoses")}
|
|
228
233
|
problems={choicesIn(problems, "diagnoses")}
|
|
229
234
|
onChoose={onChoose}
|
|
@@ -266,6 +271,10 @@ function DetailsEditor({
|
|
|
266
271
|
}) {
|
|
267
272
|
const { Grid, Input, Select } = useComponents();
|
|
268
273
|
const d = patient.demographic;
|
|
274
|
+
const sexPicked = useFieldInteractions("update_patient_form")("sex", {
|
|
275
|
+
isOptional: false,
|
|
276
|
+
hasValue: Boolean(d?.sex),
|
|
277
|
+
});
|
|
269
278
|
const [first, setFirst] = useState(d?.name.first ?? "");
|
|
270
279
|
const [last, setLast] = useState(d?.name.last ?? "");
|
|
271
280
|
const [dob, setDob] = useState(d?.dateOfBirth ?? "");
|
|
@@ -276,35 +285,46 @@ function DetailsEditor({
|
|
|
276
285
|
};
|
|
277
286
|
return (
|
|
278
287
|
<Grid min="200px" gap="3">
|
|
279
|
-
<
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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>
|
|
308
328
|
</Grid>
|
|
309
329
|
);
|
|
310
330
|
}
|
|
@@ -3,9 +3,9 @@ import { useComponents } from "../../primitives/index.ts";
|
|
|
3
3
|
import { type PatientInput, type Sex } from "@photonhealth/client";
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
import { formatPhone, PHONE_PATTERN, toE164 } from "../format.ts";
|
|
6
|
+
import { TrackedField } from "../../analytics/fieldInteraction.tsx";
|
|
6
7
|
|
|
7
|
-
type
|
|
8
|
-
type AddressInput = NonNullable<PatientDemographicInput["address"]>;
|
|
8
|
+
type AddressInput = NonNullable<NonNullable<PatientInput["contact"]>["address"]>;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* These fields describe the patient, not the prescriber: keep the browser's autofill and password managers
|
|
@@ -94,48 +94,62 @@ export function ContactFields({
|
|
|
94
94
|
needs a phone; an address only when the server still asks with a phone on file. */}
|
|
95
95
|
{addressRequest && <Alert tone="warning" title={phone ? "Address needed to send" : "Phone needed to send"} />}
|
|
96
96
|
<Grid min="120px" gap="3">
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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>
|
|
116
120
|
</Grid>
|
|
117
121
|
<div onBlur={saveAddress}>
|
|
118
122
|
<Stack gap="3">
|
|
119
123
|
<Grid min="120px" gap="3">
|
|
120
|
-
<
|
|
121
|
-
|
|
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>
|
|
122
130
|
</Grid>
|
|
123
131
|
<Grid min="120px" gap="3">
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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>
|
|
139
153
|
</Grid>
|
|
140
154
|
</Stack>
|
|
141
155
|
</div>
|
|
@@ -65,6 +65,12 @@ export function parseQuery(text: string): ParsedQuery {
|
|
|
65
65
|
return parsed;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/** query as patient input */
|
|
69
|
+
export const toSearchInput = ({ phone, email, ...demographic }: ParsedQuery) => ({
|
|
70
|
+
demographic,
|
|
71
|
+
contact: { ...(phone ? { phone } : {}), ...(email ? { email } : {}) },
|
|
72
|
+
});
|
|
73
|
+
|
|
68
74
|
/** Whether a query says anything the server can match on. */
|
|
69
75
|
export const isSearchable = (q: ParsedQuery) =>
|
|
70
76
|
Boolean(q.name?.first || q.name?.last || q.dateOfBirth || q.phone || q.email);
|
|
@@ -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
|
+
});
|