@photonhealth/react 2.0.0-rc.1 → 2.0.0-rc.3

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 (272) hide show
  1. package/README.md +52 -9
  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 +19 -0
  6. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  7. package/dist/analytics/PhotonAnalyticsProvider.js +76 -0
  8. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  9. package/dist/analytics/cardLifecycle.d.ts +10 -0
  10. package/dist/analytics/cardLifecycle.d.ts.map +1 -0
  11. package/dist/analytics/cardLifecycle.js +43 -0
  12. package/dist/analytics/cardLifecycle.js.map +1 -0
  13. package/dist/analytics/fieldInteraction.d.ts +18 -0
  14. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  15. package/dist/analytics/fieldInteraction.js +102 -0
  16. package/dist/analytics/fieldInteraction.js.map +1 -0
  17. package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
  18. package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
  19. package/dist/analytics/lifecycleOutcomes.js +16 -0
  20. package/dist/analytics/lifecycleOutcomes.js.map +1 -0
  21. package/dist/analytics/tracker.d.ts +19 -0
  22. package/dist/analytics/tracker.d.ts.map +1 -0
  23. package/dist/analytics/tracker.js +41 -0
  24. package/dist/analytics/tracker.js.map +1 -0
  25. package/dist/analytics/viewed.d.ts +11 -0
  26. package/dist/analytics/viewed.d.ts.map +1 -0
  27. package/dist/analytics/viewed.js +16 -0
  28. package/dist/analytics/viewed.js.map +1 -0
  29. package/dist/components/PhotonOrder.d.ts +18 -18
  30. package/dist/components/PhotonOrder.d.ts.map +1 -1
  31. package/dist/components/PhotonOrder.js +34 -19
  32. package/dist/components/PhotonOrder.js.map +1 -1
  33. package/dist/components/PhotonPatient.d.ts +7 -35
  34. package/dist/components/PhotonPatient.d.ts.map +1 -1
  35. package/dist/components/PhotonPatient.js +6 -78
  36. package/dist/components/PhotonPatient.js.map +1 -1
  37. package/dist/components/PhotonPrescription.d.ts +15 -26
  38. package/dist/components/PhotonPrescription.d.ts.map +1 -1
  39. package/dist/components/PhotonPrescription.js +6 -360
  40. package/dist/components/PhotonPrescription.js.map +1 -1
  41. package/dist/components/format.d.ts +2 -2
  42. package/dist/components/format.js +2 -2
  43. package/dist/components/index.d.ts +1 -1
  44. package/dist/components/index.d.ts.map +1 -1
  45. package/dist/components/index.js +1 -1
  46. package/dist/components/index.js.map +1 -1
  47. package/dist/components/open.d.ts +11 -13
  48. package/dist/components/open.d.ts.map +1 -1
  49. package/dist/components/open.js +7 -2
  50. package/dist/components/open.js.map +1 -1
  51. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  52. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  53. package/dist/components/order/DraftOrderPrompt.js +26 -0
  54. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  55. package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
  56. package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
  57. package/dist/components/patient/PatientCard/PatientCard.js +101 -0
  58. package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
  59. package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
  60. package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
  61. package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
  62. package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
  63. package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
  64. package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
  65. package/dist/components/patient/PatientIntakeForm.js +114 -0
  66. package/dist/components/patient/PatientIntakeForm.js.map +1 -0
  67. package/dist/components/patient/PatientSearch.d.ts +12 -0
  68. package/dist/components/patient/PatientSearch.d.ts.map +1 -0
  69. package/dist/components/patient/PatientSearch.js +148 -0
  70. package/dist/components/patient/PatientSearch.js.map +1 -0
  71. package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
  72. package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
  73. package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +6 -5
  74. package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
  75. package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +15 -16
  76. package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
  77. package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +29 -28
  78. package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
  79. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
  80. package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
  81. package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
  82. package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
  83. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
  84. package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
  85. package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
  86. package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
  87. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
  88. package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
  89. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
  90. package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
  91. package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
  92. package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
  93. package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
  94. package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
  95. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
  96. package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
  97. package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
  98. package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
  99. package/dist/components/patient/fields.d.ts +7 -26
  100. package/dist/components/patient/fields.d.ts.map +1 -1
  101. package/dist/components/patient/fields.js +11 -52
  102. package/dist/components/patient/fields.js.map +1 -1
  103. package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
  104. package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
  105. package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -10
  106. package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
  107. package/dist/components/prescription/PrescriptionCard.d.ts +51 -0
  108. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  109. package/dist/components/prescription/PrescriptionCard.js +186 -0
  110. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  111. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  112. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  113. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  114. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  115. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  116. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  117. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  118. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  119. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  120. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  121. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  122. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  123. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  124. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  125. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  126. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  127. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  128. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  129. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  130. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  131. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  132. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  133. package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
  134. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  135. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  136. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  137. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  138. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  139. package/dist/components/schemaErrors.d.ts +13 -0
  140. package/dist/components/schemaErrors.d.ts.map +1 -0
  141. package/dist/components/schemaErrors.js +25 -0
  142. package/dist/components/schemaErrors.js.map +1 -0
  143. package/dist/components/search.d.ts +1 -1
  144. package/dist/components/search.js +1 -1
  145. package/dist/index.d.ts +2 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +1 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/meta/version.d.ts +5 -0
  150. package/dist/meta/version.d.ts.map +1 -0
  151. package/dist/meta/version.js +5 -0
  152. package/dist/meta/version.js.map +1 -0
  153. package/dist/primitives/PhotonProvider.d.ts +3 -1
  154. package/dist/primitives/PhotonProvider.d.ts.map +1 -1
  155. package/dist/primitives/PhotonProvider.js +23 -11
  156. package/dist/primitives/PhotonProvider.js.map +1 -1
  157. package/dist/primitives/defaults.d.ts.map +1 -1
  158. package/dist/primitives/defaults.js +6 -3
  159. package/dist/primitives/defaults.js.map +1 -1
  160. package/dist/primitives/photonContext.d.ts +3 -0
  161. package/dist/primitives/photonContext.d.ts.map +1 -0
  162. package/dist/primitives/photonContext.js +3 -0
  163. package/dist/primitives/photonContext.js.map +1 -0
  164. package/dist/primitives/types.d.ts +15 -3
  165. package/dist/primitives/types.d.ts.map +1 -1
  166. package/dist/primitives/types.js.map +1 -1
  167. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  168. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  169. package/dist/primitives/useProvidedPhoton.js +8 -0
  170. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  171. package/dist/styles.css +45 -3
  172. package/dist/test-utils/contract.d.ts.map +1 -1
  173. package/dist/test-utils/contract.js +23 -2
  174. package/dist/test-utils/contract.js.map +1 -1
  175. package/package.json +8 -3
  176. package/src/adapters/tailwind.tsx +52 -24
  177. package/src/analytics/PhotonAnalyticsProvider.test.tsx +190 -0
  178. package/src/analytics/PhotonAnalyticsProvider.tsx +151 -0
  179. package/src/analytics/cardLifecycle.test.tsx +272 -0
  180. package/src/analytics/cardLifecycle.ts +44 -0
  181. package/src/analytics/fieldInteraction.test.tsx +186 -0
  182. package/src/analytics/fieldInteraction.tsx +148 -0
  183. package/src/analytics/lifecycleOutcomes.test.ts +78 -0
  184. package/src/analytics/lifecycleOutcomes.ts +29 -0
  185. package/src/analytics/tracker.test.ts +52 -0
  186. package/src/analytics/tracker.ts +49 -0
  187. package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
  188. package/src/analytics/viewed.ts +27 -0
  189. package/src/components/PhotonOrder.test.tsx +394 -0
  190. package/src/components/PhotonOrder.tsx +79 -53
  191. package/src/components/PhotonPatient.tsx +15 -166
  192. package/src/components/PhotonPrescription.test.tsx +120 -0
  193. package/src/components/PhotonPrescription.tsx +23 -583
  194. package/src/components/ScreeningAlerts.test.tsx +81 -0
  195. package/src/components/format.ts +2 -2
  196. package/src/components/index.ts +1 -1
  197. package/src/components/open.ts +13 -16
  198. package/src/components/order/DraftOrderPrompt.test.tsx +77 -0
  199. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  200. package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
  201. package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
  202. package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
  203. package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
  204. package/src/components/patient/PatientIntakeForm.tsx +222 -0
  205. package/src/components/patient/PatientSearch.test.tsx +204 -0
  206. package/src/components/patient/PatientSearch.tsx +221 -0
  207. package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
  208. package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +24 -16
  209. package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
  210. package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +53 -48
  211. package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
  212. package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
  213. package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
  214. package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
  215. package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
  216. package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
  217. package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
  218. package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
  219. package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
  220. package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
  221. package/src/components/patient/fields.tsx +12 -124
  222. package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
  223. package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -15
  224. package/src/components/prescription/PrescriptionCard.test.tsx +247 -0
  225. package/src/components/prescription/PrescriptionCard.tsx +361 -0
  226. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +82 -0
  227. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  228. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +206 -0
  229. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  230. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +453 -0
  231. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  232. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  233. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  234. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +72 -0
  235. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  236. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  237. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +695 -0
  238. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  239. package/src/components/schemaErrors.test.ts +49 -0
  240. package/src/components/schemaErrors.ts +34 -0
  241. package/src/components/search.tsx +1 -1
  242. package/src/index.ts +2 -0
  243. package/src/meta/version.test.ts +11 -0
  244. package/src/meta/version.ts +4 -0
  245. package/src/primitives/PhotonProvider.tsx +30 -15
  246. package/src/primitives/defaults.tsx +44 -21
  247. package/src/primitives/photonContext.ts +4 -0
  248. package/src/primitives/types.ts +15 -3
  249. package/src/primitives/useProvidedPhoton.ts +21 -0
  250. package/src/styles.css +45 -3
  251. package/src/test-utils/contract.tsx +45 -2
  252. package/dist/components/TreatmentPicker.d.ts +0 -45
  253. package/dist/components/TreatmentPicker.d.ts.map +0 -1
  254. package/dist/components/TreatmentPicker.js.map +0 -1
  255. package/dist/components/patient/Benefits.d.ts.map +0 -1
  256. package/dist/components/patient/Benefits.js.map +0 -1
  257. package/dist/components/patient/Clinical.d.ts.map +0 -1
  258. package/dist/components/patient/Clinical.js.map +0 -1
  259. package/dist/components/patient/IntakeForm.d.ts +0 -10
  260. package/dist/components/patient/IntakeForm.d.ts.map +0 -1
  261. package/dist/components/patient/IntakeForm.js +0 -324
  262. package/dist/components/patient/IntakeForm.js.map +0 -1
  263. package/dist/components/patient/Summary.d.ts +0 -48
  264. package/dist/components/patient/Summary.d.ts.map +0 -1
  265. package/dist/components/patient/Summary.js +0 -80
  266. package/dist/components/patient/Summary.js.map +0 -1
  267. package/dist/components/patient/query.d.ts +0 -23
  268. package/dist/components/patient/query.d.ts.map +0 -1
  269. package/dist/components/patient/query.js.map +0 -1
  270. package/src/components/TreatmentPicker.tsx +0 -350
  271. package/src/components/patient/IntakeForm.tsx +0 -532
  272. package/src/components/patient/Summary.tsx +0 -310
@@ -1,184 +1,33 @@
1
- import { useComponents, usePhoton } from "../primitives/index.ts";
1
+ import { AnalyticsWorkflow } from "../analytics/PhotonAnalyticsProvider.tsx";
2
+ import { viewedPropertiesFromCardProps } from "../analytics/viewed.ts";
2
3
  import { SignedIn } from "./SignedIn.tsx";
3
- import { classify, Patient, type ChangeOption, type PatientInput, type PatientResult } from "@photonhealth/client";
4
- import { useLive, useOnChange } from "../hooks/index.ts";
5
- import { useState } from "react";
6
- import { NotFound, openFailed, toOpen, useOpened, type Given } from "./open.ts";
7
- import { ChangeList } from "./ChangeList.tsx";
8
- import { PatientIntakeForm } from "./patient/IntakeForm.tsx";
9
- import { diagnosisRef, withoutInline } from "./patient/Clinical.tsx";
10
- import { PatientSummary } from "./patient/Summary.tsx";
4
+ import { type Patient, type PatientInput } from "@photonhealth/client";
5
+ import { PatientCard } from "./patient/PatientCard/PatientCard.tsx";
11
6
 
12
- type PatientClinicalInput = NonNullable<PatientInput["clinical"]>;
13
-
14
- /**
15
- * "Who is this patient?" — standalone or inside PhotonOrder. Bound to a live Patient from @photonhealth/client:
16
- * the one given (`patient`), one opened from what's given (get / update / sync, see `Given`), or a new one to
17
- * find or add. Before it has a record, every field the prescriber leaves is synced — the server decides: the
18
- * patient (found, or added), patients it might be (pick one), or what it still needs. Once it has one, edits
19
- * update it.
20
- */
21
7
  export interface PhotonPatientProps {
22
8
  /**
23
- * The patient: a live Patient (used as given; anything else holding it sees the same changes), its id
24
- * (`"pat_…"` or `{ id }`: read), its id with fields (that patient updated), or what's known of them without
25
- * one (synced: found, matched or added).
9
+ * The patient, one of:
10
+ * - a live `Patient`: used as is; anything else holding it sees the same changes
11
+ * - its id, `"pat_…"` or `{ id }`: gets the patient
12
+ * - its id with fields, `{ id, … }`: updates the patient
13
+ * - fields without an id: upserts the patient
26
14
  */
27
- patient?: Patient | Given<PatientInput> | null;
15
+ patient?: Patient | PatientInput | string | null;
28
16
  /**
29
17
  * The card's patient, once it has a record (found, picked, added, or opened with) and each time that record
30
18
  * changes from the backend. `null` on "Change patient": a card given `patient` leaves what's next to the
31
19
  * host (pass it a new one); otherwise it starts over itself.
32
20
  */
33
21
  onPatient?: (patient: Patient | null) => void;
34
- /** Read-only (e.g. on a sent order): nothing to edit, and no "Change patient". */
35
- locked?: boolean;
36
- /**
37
- * The patient is fixed — e.g. beside the host's own view of them: no "Change patient", but still editable.
38
- * (An embed whose link names the patient by id is fixed.)
39
- */
40
- fixed?: boolean;
41
22
  }
42
23
 
43
24
  /** A patient card. */
44
25
  export function PhotonPatient(props: PhotonPatientProps) {
45
26
  return (
46
- <SignedIn>
47
- <PatientCard {...props} />
48
- </SignedIn>
49
- );
50
- }
51
-
52
- /** A stable key per live object: a different patient object gets a fresh form. */
53
- const objectKeys = new WeakMap<object, number>();
54
- let nextKey = 0;
55
- const keyOf = (obj: object) => {
56
- if (!objectKeys.has(obj)) objectKeys.set(obj, ++nextKey);
57
- return objectKeys.get(obj)!;
58
- };
59
-
60
- const patientOf = (r: PatientResult) => r.patient;
61
-
62
- /**
63
- * PhotonPatient, and what only PhotonOrder gives it: the server's request for a way to reach the patient (its
64
- * reason), which opens the contact fields. Internal: the package index exports only PhotonPatient.
65
- */
66
- export function PatientCard({
67
- patient,
68
- onPatient,
69
- locked,
70
- fixed,
71
- addressRequest,
72
- notFound,
73
- }: PhotonPatientProps & {
74
- addressRequest?: string | null;
75
- /** The patient it was given by id isn't there (PhotonOrder's): said in the form, with the matches. */
76
- notFound?: NotFound | null;
77
- }) {
78
- const { Alert, Card, CardHeader } = useComponents();
79
- const ph = usePhoton();
80
- // A new patient to find or add when the host gives none (and none to open) — and after "Change patient",
81
- // when the host didn't give one.
82
- const shared = patient instanceof Patient ? patient : null;
83
- const given = toOpen<PatientInput>(patient, Boolean(shared));
84
- const [own, setOwn] = useState<Patient | null>(() => (shared || given ? null : ph.patient()));
85
- const { opened, error: openError } = useOpened(ph.patient, given, patientOf, "patient");
86
- // Given by id and not there: someone to find or add instead, the reason said in the form — where its matches,
87
- // and anything else the server says, show. (Read-only, there's nothing to find: just the reason.)
88
- const missing = openError instanceof NotFound && !locked ? openError : null;
89
- // One patient object, always: the one given, the one opened from what's given, or the card's own — made once
90
- // there's none to show (nothing given, "Change patient", or an id the server doesn't have).
91
- if (missing && !own && !shared) setOwn(ph.patient());
92
- // The host gives another patient: that one, not the card's own.
93
- const givenKey = JSON.stringify(given);
94
- const [ownFor, setOwnFor] = useState(givenKey);
95
- if (givenKey !== ownFor) {
96
- setOwnFor(givenKey);
97
- if (given && own) setOwn(null);
98
- }
99
- const live = shared ?? own ?? opened;
100
- const snap = useLive(live);
101
- const record = snap?.state ?? null;
102
- useOnChange(live, (p) => p.state, onPatient);
103
-
104
- if (openError && !missing)
105
- return <Alert tone="critical" title={openFailed("patient", openError)} description={openError.message} />;
106
- if (!live || !snap) {
107
- return (
108
- <Card divided>
109
- <CardHeader title="Patient" description="Loading…" />
110
- </Card>
111
- );
112
- }
113
-
114
- const changes = classify(snap.changes);
115
- const update = (input: Omit<PatientInput, "id">) => void live.update(input).catch(() => {}); // failures land on the object
116
- const patchClinical = (clinical: PatientClinicalInput) => update({ clinical });
117
- const choose = (option: ChangeOption) => void live.choose(option).catch(() => {});
118
-
119
- if (record) {
120
- const messages = withoutInline(changes);
121
- const hasMessages =
122
- messages.needsChoice.length + messages.blocking.length + messages.advisories.length > 0 || Boolean(snap.error);
123
- return (
124
- <PatientSummary
125
- key={record.id}
126
- patient={record}
127
- pickedNames={snap.pickedNames}
128
- saving={snap.status === "saving"}
129
- changes={
130
- // Only when there's something to say — the card has no body otherwise.
131
- hasMessages && (
132
- <>
133
- <ChangeList changes={messages} onChoose={choose} busy={snap.status === "saving"} />
134
- {/* A failed save must never be silent (e.g. a rejected clinical patch). */}
135
- {snap.error && <Alert tone="critical" title="Couldn't save" description={snap.error.message} />}
136
- </>
137
- )
138
- }
139
- choices={changes.needsChoice}
140
- problems={changes.blocking}
141
- onChoose={choose}
142
- onAddAllergy={(name) => patchClinical({ allergies: { add: [{ name }] } })}
143
- onConfirmNone={(list) => patchClinical({ [list]: { none: true } })}
144
- onRemoveAllergy={(a) => patchClinical({ allergies: { remove: [{ id: a.id }] } })}
145
- onRemoveMedication={(m) => patchClinical({ medications: { remove: [{ id: m.id, status: m.status }] } })}
146
- onAddDiagnosis={(text) => patchClinical({ diagnoses: { add: [diagnosisRef(text)] } })}
147
- onRemoveDiagnosis={(d) => patchClinical({ diagnoses: { remove: [{ id: d.id }] } })}
148
- onAddBenefit={(b) => update({ demographic: { benefits: { add: [b] } } })}
149
- onRemoveBenefit={(b) => update({ demographic: { benefits: { remove: [{ id: b.id }] } } })}
150
- onConfirmNoBenefits={() => update({ demographic: { benefits: { none: true } } })}
151
- onAddMedication={(name) => patchClinical({ medications: { add: [{ name, status: "ACTIVE" }] } })}
152
- onSaveContact={(contact) => update({ demographic: contact })}
153
- onSaveDetails={(details) => update({ demographic: details })}
154
- addressRequest={locked ? null : (addressRequest ?? null)}
155
- readOnly={locked}
156
- onChangePatient={
157
- locked || fixed
158
- ? undefined
159
- : () => {
160
- onPatient?.(null); // given a patient, the host decides what's next
161
- if (!shared) setOwn(ph.patient());
162
- }
163
- }
164
- />
165
- );
166
- }
167
-
168
- // A different patient object (e.g. after "Change patient") starts a fresh form.
169
- const why = notFound ?? missing;
170
- return (
171
- <PatientIntakeForm
172
- key={keyOf(live)}
173
- patient={live}
174
- notice={why && { title: openFailed("patient", why), description: why.message }}
175
- />
27
+ <AnalyticsWorkflow card="PhotonPatient" viewedProperties={viewedPropertiesFromCardProps(props)}>
28
+ <SignedIn>
29
+ <PatientCard {...props} />
30
+ </SignedIn>
31
+ </AnalyticsWorkflow>
176
32
  );
177
33
  }
178
-
179
- /**
180
- * Find or add the patient. Each field the prescriber leaves (and Enter) sends everything known so far to the
181
- * live Patient — one query that searches and syncs. The server decides: the patient, patients it might be
182
- * (listed to pick from), or what it still needs (shown; an address only when it asks). Fields left, not
183
- * keystrokes: a query with enough to add a patient adds them.
184
- */
@@ -0,0 +1,120 @@
1
+ import { render, screen, waitFor, within } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
+ import { fakeNetworkApiClient, payload } from "@photonhealth/client/testing";
5
+ import { PhotonPrescription } from "../index.ts";
6
+ import { fakeNetworkApi, patient } from "../../test/cards.fixtures.tsx";
7
+ import {
8
+ buildEditedEventsFor,
9
+ leaveField,
10
+ meAsPrescriber,
11
+ recordAnalytics,
12
+ type RecordedAnalytics,
13
+ typeInto,
14
+ unmountAndRestoreFetch,
15
+ withAnalytics,
16
+ } from "../../test/analytics.fixtures.tsx";
17
+
18
+ // The card as a workflow: its analytics. The card itself is tested in prescription/PrescriptionCard.test.tsx.
19
+ const settledDrugRow = (row: RegExp) =>
20
+ waitFor(() => {
21
+ const button = screen.getByRole<HTMLButtonElement>("button", { name: row });
22
+ expect(button.disabled).toBe(false);
23
+ return button;
24
+ });
25
+
26
+ const clickDrugRowOnceSettled = async (row: RegExp) => {
27
+ await userEvent.click(await settledDrugRow(row));
28
+ };
29
+
30
+ describe("PhotonPrescription: Field Interaction", () => {
31
+ let analytics: RecordedAnalytics;
32
+ beforeEach(() => {
33
+ analytics = recordAnalytics();
34
+ });
35
+ afterEach(unmountAndRestoreFetch);
36
+
37
+ it("searching Treatment and picking a one-product drug from its list is one visit: focus, change, blur", async () => {
38
+ const { client } = fakeNetworkApiClient({
39
+ ...meAsPrescriber,
40
+ GetPatient: () => payload("patient", "PatientPayload", patient),
41
+ ...fakeNetworkApi({
42
+ prescriptions: {
43
+ amo: [
44
+ ["Amondys", "Injection", "45 MG"],
45
+ ["Amoxicillin", "Capsule", "500 MG"],
46
+ ["Amoxicillin", "Tablet", "875 MG"],
47
+ ],
48
+ },
49
+ }),
50
+ });
51
+ render(<PhotonPrescription patient="pat_1" />, { wrapper: withAnalytics(client) });
52
+
53
+ await userEvent.click(await screen.findByLabelText("Treatment"));
54
+ await userEvent.keyboard("Amo");
55
+ await clickDrugRowOnceSettled(/^Amondys/);
56
+ await screen.findByLabelText("Directions (sig)");
57
+ leaveField();
58
+
59
+ await analytics.expectSentOnce("Prescribe Workflow Viewed");
60
+ await analytics.expectSentOnce("Field Interaction treatment focus");
61
+ await analytics.expectSentOnce("Field Interaction treatment change");
62
+ await analytics.expectSentOnce("Field Interaction treatment blur");
63
+ await analytics.expectSentOnce("Draft Prescription Added");
64
+ await analytics.expectEventCount(5);
65
+ expect(analytics.sentFor("treatment").at(-1)).toMatchObject({ hasValue: true, changed: true });
66
+ });
67
+
68
+ it("each field sends focus, one change and blur with its documented name, and nothing typed", async () => {
69
+ const { client } = fakeNetworkApiClient({
70
+ ...meAsPrescriber,
71
+ GetPatient: () => payload("patient", "PatientPayload", patient),
72
+ ...fakeNetworkApi({
73
+ prescriptions: {
74
+ amox: [
75
+ ["Amoxicillin", "Capsule", "250 MG"],
76
+ ["Amoxicillin", "Capsule", "500 MG"],
77
+ ["Amoxicillin", "Tablet", "875 MG"],
78
+ ],
79
+ },
80
+ }),
81
+ });
82
+ render(<PhotonPrescription patient="pat_1" />, { wrapper: withAnalytics(client) });
83
+
84
+ await userEvent.click(await screen.findByLabelText("Treatment"));
85
+ await userEvent.keyboard("amox");
86
+ await clickDrugRowOnceSettled(/^Amoxicillin/);
87
+ await userEvent.click(within(await screen.findByRole("group", { name: "Form" })).getByText("Capsule"));
88
+ await userEvent.click(within(screen.getByRole("group", { name: "Strength" })).getByText("500 mg"));
89
+ await screen.findByLabelText("Directions (sig)");
90
+ await typeInto("Directions (sig)", "Zqx once daily");
91
+ await typeInto("Quantity", "14");
92
+ await typeInto("Unit", "Zqxunit");
93
+ await typeInto("Days supply", "7");
94
+ await typeInto("Refills", "1");
95
+ await userEvent.click(screen.getByRole("checkbox", { name: "Dispense as written" }));
96
+ leaveField();
97
+
98
+ const eventsSentOnce = [
99
+ "Prescribe Workflow Viewed",
100
+ ...buildEditedEventsFor("treatment"),
101
+ ...buildEditedEventsFor("form"),
102
+ ...buildEditedEventsFor("strength"),
103
+ ...buildEditedEventsFor("instructions"),
104
+ ...buildEditedEventsFor("dispenseQuantity"),
105
+ ...buildEditedEventsFor("dispenseUnit"),
106
+ ...buildEditedEventsFor("daysSupply"),
107
+ ...buildEditedEventsFor("refills"),
108
+ ...buildEditedEventsFor("dispenseAsWritten"),
109
+ "Draft Prescription Added",
110
+ ];
111
+ for (const event of eventsSentOnce) await analytics.expectSentOnce(event);
112
+ await analytics.expectEventCount(eventsSentOnce.length);
113
+ expect(new Set(analytics.fieldInteractions().map((sent) => sent.formName))).toEqual(
114
+ new Set(["add_prescription_form"]),
115
+ );
116
+ expect(analytics.sentFor("daysSupply").map((sent) => sent.isOptional)).toEqual([true, true, true]);
117
+ expect(analytics.sentFor("instructions").at(-1)).toMatchObject({ durationMs: expect.any(Number), changed: true });
118
+ for (const body of analytics.bodies()) expect(body).not.toMatch(/amox|Zqx|"14"/);
119
+ });
120
+ });