@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.
Files changed (185) hide show
  1. package/README.md +35 -8
  2. package/dist/adapters/tailwind.d.ts.map +1 -1
  3. package/dist/adapters/tailwind.js +7 -4
  4. package/dist/adapters/tailwind.js.map +1 -1
  5. package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
  6. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  7. package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
  8. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  9. package/dist/analytics/fieldInteraction.d.ts +18 -0
  10. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  11. package/dist/analytics/fieldInteraction.js +102 -0
  12. package/dist/analytics/fieldInteraction.js.map +1 -0
  13. package/dist/analytics/tracker.d.ts +17 -0
  14. package/dist/analytics/tracker.d.ts.map +1 -0
  15. package/dist/analytics/tracker.js +36 -0
  16. package/dist/analytics/tracker.js.map +1 -0
  17. package/dist/analytics/viewed.d.ts +11 -0
  18. package/dist/analytics/viewed.d.ts.map +1 -0
  19. package/dist/analytics/viewed.js +16 -0
  20. package/dist/analytics/viewed.js.map +1 -0
  21. package/dist/components/PhotonOrder.d.ts.map +1 -1
  22. package/dist/components/PhotonOrder.js +20 -16
  23. package/dist/components/PhotonOrder.js.map +1 -1
  24. package/dist/components/PhotonPatient.d.ts.map +1 -1
  25. package/dist/components/PhotonPatient.js +4 -2
  26. package/dist/components/PhotonPatient.js.map +1 -1
  27. package/dist/components/PhotonPrescription.d.ts +1 -12
  28. package/dist/components/PhotonPrescription.d.ts.map +1 -1
  29. package/dist/components/PhotonPrescription.js +7 -360
  30. package/dist/components/PhotonPrescription.js.map +1 -1
  31. package/dist/components/format.d.ts +2 -2
  32. package/dist/components/format.js +2 -2
  33. package/dist/components/index.d.ts +1 -1
  34. package/dist/components/index.d.ts.map +1 -1
  35. package/dist/components/index.js +1 -1
  36. package/dist/components/index.js.map +1 -1
  37. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  38. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  39. package/dist/components/order/DraftOrderPrompt.js +26 -0
  40. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  41. package/dist/components/patient/Benefits.d.ts.map +1 -1
  42. package/dist/components/patient/Benefits.js +2 -1
  43. package/dist/components/patient/Benefits.js.map +1 -1
  44. package/dist/components/patient/Clinical.d.ts +3 -2
  45. package/dist/components/patient/Clinical.d.ts.map +1 -1
  46. package/dist/components/patient/Clinical.js +21 -20
  47. package/dist/components/patient/Clinical.js.map +1 -1
  48. package/dist/components/patient/IntakeForm.d.ts.map +1 -1
  49. package/dist/components/patient/IntakeForm.js +52 -43
  50. package/dist/components/patient/IntakeForm.js.map +1 -1
  51. package/dist/components/patient/Summary.d.ts +1 -1
  52. package/dist/components/patient/Summary.d.ts.map +1 -1
  53. package/dist/components/patient/Summary.js +13 -3
  54. package/dist/components/patient/Summary.js.map +1 -1
  55. package/dist/components/patient/fields.d.ts +1 -2
  56. package/dist/components/patient/fields.d.ts.map +1 -1
  57. package/dist/components/patient/fields.js +2 -1
  58. package/dist/components/patient/fields.js.map +1 -1
  59. package/dist/components/patient/query.d.ts +14 -0
  60. package/dist/components/patient/query.d.ts.map +1 -1
  61. package/dist/components/patient/query.js +5 -0
  62. package/dist/components/patient/query.js.map +1 -1
  63. package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
  64. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  65. package/dist/components/prescription/PrescriptionCard.js +179 -0
  66. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  67. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  68. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  69. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  70. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  71. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  72. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  73. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  74. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  75. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  76. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  77. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  78. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  79. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  80. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  81. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  82. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  83. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  84. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  85. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  86. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  87. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  88. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  89. package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
  90. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  91. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  92. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  93. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  94. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  95. package/dist/components/schemaErrors.d.ts +12 -0
  96. package/dist/components/schemaErrors.d.ts.map +1 -0
  97. package/dist/components/schemaErrors.js +24 -0
  98. package/dist/components/schemaErrors.js.map +1 -0
  99. package/dist/index.d.ts +2 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +1 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/meta/version.d.ts +5 -0
  104. package/dist/meta/version.d.ts.map +1 -0
  105. package/dist/meta/version.js +5 -0
  106. package/dist/meta/version.js.map +1 -0
  107. package/dist/primitives/PhotonProvider.d.ts +3 -1
  108. package/dist/primitives/PhotonProvider.d.ts.map +1 -1
  109. package/dist/primitives/PhotonProvider.js +23 -11
  110. package/dist/primitives/PhotonProvider.js.map +1 -1
  111. package/dist/primitives/defaults.d.ts.map +1 -1
  112. package/dist/primitives/defaults.js +6 -3
  113. package/dist/primitives/defaults.js.map +1 -1
  114. package/dist/primitives/photonContext.d.ts +3 -0
  115. package/dist/primitives/photonContext.d.ts.map +1 -0
  116. package/dist/primitives/photonContext.js +3 -0
  117. package/dist/primitives/photonContext.js.map +1 -0
  118. package/dist/primitives/types.d.ts +15 -3
  119. package/dist/primitives/types.d.ts.map +1 -1
  120. package/dist/primitives/types.js.map +1 -1
  121. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  122. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  123. package/dist/primitives/useProvidedPhoton.js +8 -0
  124. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  125. package/dist/styles.css +45 -3
  126. package/dist/test-utils/contract.d.ts.map +1 -1
  127. package/dist/test-utils/contract.js +23 -2
  128. package/dist/test-utils/contract.js.map +1 -1
  129. package/package.json +5 -3
  130. package/src/adapters/tailwind.tsx +52 -24
  131. package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
  132. package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
  133. package/src/analytics/fieldInteraction.test.tsx +184 -0
  134. package/src/analytics/fieldInteraction.tsx +148 -0
  135. package/src/analytics/tracker.test.ts +52 -0
  136. package/src/analytics/tracker.ts +42 -0
  137. package/src/analytics/viewed.ts +27 -0
  138. package/src/components/PhotonOrder.test.tsx +256 -0
  139. package/src/components/PhotonOrder.tsx +45 -30
  140. package/src/components/PhotonPatient.tsx +11 -7
  141. package/src/components/PhotonPrescription.test.tsx +116 -0
  142. package/src/components/PhotonPrescription.tsx +10 -570
  143. package/src/components/format.ts +2 -2
  144. package/src/components/index.ts +1 -1
  145. package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
  146. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  147. package/src/components/patient/Benefits.tsx +21 -13
  148. package/src/components/patient/Clinical.tsx +31 -26
  149. package/src/components/patient/IntakeForm.test.tsx +89 -0
  150. package/src/components/patient/IntakeForm.tsx +168 -136
  151. package/src/components/patient/Summary.test.tsx +106 -0
  152. package/src/components/patient/Summary.tsx +54 -34
  153. package/src/components/patient/fields.tsx +52 -38
  154. package/src/components/patient/query.ts +6 -0
  155. package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
  156. package/src/components/prescription/PrescriptionCard.tsx +347 -0
  157. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
  158. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  159. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
  160. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  161. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
  162. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  163. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  164. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  165. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
  166. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  167. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  168. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
  169. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  170. package/src/components/schemaErrors.test.ts +49 -0
  171. package/src/components/schemaErrors.ts +33 -0
  172. package/src/index.ts +2 -0
  173. package/src/meta/version.test.ts +10 -0
  174. package/src/meta/version.ts +4 -0
  175. package/src/primitives/PhotonProvider.tsx +30 -15
  176. package/src/primitives/defaults.tsx +44 -21
  177. package/src/primitives/photonContext.ts +4 -0
  178. package/src/primitives/types.ts +15 -3
  179. package/src/primitives/useProvidedPhoton.ts +21 -0
  180. package/src/styles.css +45 -3
  181. package/src/test-utils/contract.tsx +45 -2
  182. package/dist/components/TreatmentPicker.d.ts +0 -45
  183. package/dist/components/TreatmentPicker.d.ts.map +0 -1
  184. package/dist/components/TreatmentPicker.js.map +0 -1
  185. 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<PatientDemographicInput["address"]>;
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: d?.benefits ?? null,
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={d?.phone ?? null}
184
- email={d?.email ?? null}
185
- address={d?.address ?? null}
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
- <Input
280
- label="First name"
281
- value={first}
282
- onChange={(e) => setFirst(e.target.value)}
283
- onBlur={saveName}
284
- {...noAutofill}
285
- />
286
- <Input
287
- label="Last name"
288
- value={last}
289
- onChange={(e) => setLast(e.target.value)}
290
- onBlur={saveName}
291
- {...noAutofill}
292
- />
293
- <Input
294
- label="Date of birth"
295
- type="date"
296
- {...noAutofill}
297
- value={dob}
298
- onChange={(e) => setDob(e.target.value)}
299
- onBlur={() => dob && dob !== d?.dateOfBirth && onSave({ dateOfBirth: dob })}
300
- />
301
- <Select
302
- label="Sex"
303
- placeholder="Select…"
304
- options={SEX_OPTIONS}
305
- value={d?.sex ?? null}
306
- onChange={(sex) => sex !== d?.sex && onSave({ sex })}
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 PatientDemographicInput = NonNullable<PatientInput["demographic"]>;
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
- <Input
98
- label="Phone"
99
- type="tel"
100
- inputMode="tel"
101
- pattern={PHONE_PATTERN}
102
- value={phoneValue}
103
- onChange={(e) => setPhone(e.target.value)}
104
- onBlur={(e) => savePhone(e.currentTarget)}
105
- {...noAutofill}
106
- />
107
- <Input
108
- label="Email"
109
- type="email"
110
- inputMode="email"
111
- value={emailValue}
112
- onChange={(e) => setEmail(e.target.value)}
113
- onBlur={(e) => saveEmail(e.currentTarget)}
114
- {...noAutofill}
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
- <Input label="Street" value={street1} onChange={(e) => setStreet1(e.target.value)} {...noAutofill} />
121
- <Input label="Apt / suite" value={street2} onChange={(e) => setStreet2(e.target.value)} {...noAutofill} />
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
- <Input label="City" value={city} onChange={(e) => setCity(e.target.value)} {...noAutofill} />
125
- <Input
126
- label="State"
127
- value={state}
128
- onChange={(e) => setState(e.target.value)}
129
- maxLength={2}
130
- {...noAutofill}
131
- />
132
- <Input
133
- label="ZIP"
134
- value={postalCode}
135
- onChange={(e) => setPostalCode(e.target.value)}
136
- inputMode="numeric"
137
- {...noAutofill}
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
+ });