@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,310 +0,0 @@
1
- /** PhotonPatient with a record: the summary and its details editor, with the clinical lists and benefits. */
2
- import { useComponents } from "../../primitives/index.ts";
3
- import {
4
- type ChangeOption,
5
- type ClassifiedChanges,
6
- type MedicationStatus,
7
- type PatientInput,
8
- type PatientRecord,
9
- } from "@photonhealth/client";
10
- import { Fragment, useState, type ReactNode } from "react";
11
- import { ageOn, displayName, shortDate } from "../format.ts";
12
-
13
- type PatientDemographicInput = NonNullable<PatientInput["demographic"]>;
14
- type AddressInput = NonNullable<PatientDemographicInput["address"]>;
15
- import { BenefitsSection, type BenefitInput } from "./Benefits.tsx";
16
- import { choicesIn, ClinicalList, sectionOf } from "./Clinical.tsx";
17
- import { noAutofill, SEX_OPTIONS, ContactFields } from "./fields.tsx";
18
- import { focusProps } from "../flow.ts";
19
-
20
- const fullName = (p: PatientRecord) =>
21
- [p.demographic?.name.first, p.demographic?.name.last].filter(Boolean).join(" ") || "Unnamed patient";
22
-
23
- export function PatientSummary({
24
- patient,
25
- pickedNames,
26
- saving,
27
- changes,
28
- choices,
29
- problems,
30
- onChoose,
31
- onAddAllergy,
32
- onConfirmNone,
33
- onRemoveAllergy,
34
- onRemoveMedication,
35
- onAddMedication,
36
- onAddDiagnosis,
37
- onRemoveDiagnosis,
38
- onAddBenefit,
39
- onRemoveBenefit,
40
- onConfirmNoBenefits,
41
- onSaveContact,
42
- onSaveDetails,
43
- addressRequest,
44
- onChangePatient,
45
- readOnly,
46
- }: {
47
- patient: PatientRecord;
48
- pickedNames: Readonly<Record<string, string>>;
49
- saving: boolean;
50
- changes: ReactNode;
51
- /** Server choices (AMBIGUOUS changes) — each clinical list shows its own under its field. */
52
- choices: ClassifiedChanges["needsChoice"];
53
- /** What the server rejected — each clinical list shows its own under its field (e.g. a name nothing matches). */
54
- problems: ClassifiedChanges["blocking"];
55
- onChoose: (option: ChangeOption) => void;
56
- onAddAllergy: (name: string) => void;
57
- /** Record "none" for a clinical list (NKDA, no medications, no diagnoses). */
58
- onConfirmNone: (list: "allergies" | "medications" | "diagnoses") => void;
59
- onRemoveAllergy: (allergy: { id: string }) => void;
60
- onRemoveMedication: (medication: { id: string; status: MedicationStatus }) => void;
61
- onAddMedication: (name: string) => void;
62
- onAddDiagnosis: (text: string) => void;
63
- onRemoveDiagnosis: (diagnosis: { id: string }) => void;
64
- onAddBenefit: (benefit: BenefitInput) => void;
65
- onRemoveBenefit: (benefit: { id: string }) => void;
66
- onConfirmNoBenefits: () => void;
67
- onSaveContact: (contact: { phone?: string; email?: string; address?: AddressInput }) => void;
68
- onSaveDetails: (details: PatientDemographicInput) => void;
69
- addressRequest: string | null;
70
- onChangePatient?: () => void;
71
- /** Read-only (e.g. on a sent order): the summary alone — no editors, no pencil. */
72
- readOnly?: boolean;
73
- }) {
74
- const { Badge, Button, Card, CardBody, CardHeader, Row, Stack, Text } = useComponents();
75
- // Allergies / medications / diagnoses / insurance are summarised in the header; the pencil opens their
76
- // lists to add or remove, and they open by themselves when the server asks the prescriber to choose
77
- // (e.g. which penicillin).
78
- // A list with something to pick or fix opens by itself, and shows it under its field.
79
- const clinicalChoices = [...choices, ...problems].filter((c) => sectionOf(c.key));
80
- // One card, two states. Shut, it says who the patient is; open, it is everything about them that can be
81
- // changed — the fields they were added with, their contact details, and their clinical lists. Each saves
82
- // as it is answered (`UpdatePatient` on a record that already exists), so there is nothing to confirm.
83
- // It also opens itself when a send fails for want of an address, and shuts again once that is answered.
84
- const [editing, setEditing] = useState(Boolean(addressRequest));
85
- const [seenRequest, setSeenRequest] = useState(addressRequest);
86
- if (addressRequest !== seenRequest) {
87
- setSeenRequest(addressRequest);
88
- setEditing(Boolean(addressRequest));
89
- }
90
- const d = patient.demographic;
91
- // Each list: null when nothing is recorded, [] when "none" is (core's PatientRecord).
92
- const recorded = {
93
- allergies: patient.clinical?.allergies ?? null,
94
- medications: patient.clinical?.medications ?? null,
95
- diagnoses: patient.clinical?.diagnoses ?? null,
96
- benefits: d?.benefits ?? null,
97
- };
98
- const confirmedNkda = recorded.allergies?.length === 0;
99
- const allergies = recorded.allergies ?? [];
100
- const meds = (recorded.medications ?? []).filter((m) => m.status === "ACTIVE");
101
- const diagnoses = (recorded.diagnoses ?? []).map((x) => ({ ...x, name: x.name ?? x.icd10Code ?? "" }));
102
- const benefits = recorded.benefits ?? [];
103
- const nameOf = (item: { id: string; name: string }, unknown: string) =>
104
- item.name && item.name !== item.id ? item.name : (pickedNames[item.id] ?? unknown);
105
- const listed = (items: { id: string; name: string }[], unknown: string, none: string) =>
106
- items.length ? items.map((x) => nameOf(x, unknown)).join(", ") : none;
107
- // Under the name, like a prescription's product under its drug: "Male · Adult (35) · 7/8/91".
108
- const age = ageOn(d?.dateOfBirth);
109
- const sex = d?.sex === "FEMALE" ? "Female" : d?.sex === "MALE" ? "Male" : null;
110
- const ageGroup = age != null ? `${age >= 18 ? "Adult" : "Pediatric"} (${age})` : null;
111
- const line = [sex, ageGroup, d?.dateOfBirth ? shortDate(d.dateOfBirth) : null].filter(Boolean).join(" · ");
112
- // A choice the server is waiting on (which penicillin?) opens the card too — the answer lives in here.
113
- const expanded = !readOnly && (editing || clinicalChoices.length > 0);
114
- // The clinical picture, below the line, said once like a prescription's dispense line: allergies · meds ·
115
- // diagnoses · insurance. An allergy stands out. A recorded "none" is said plainly ("No active meds"); a list
116
- // not recorded isn't shown — except allergies, where not knowing matters.
117
- const named = (items: { id: string; name: string }[], unknown: string) => listed(items, unknown, "");
118
- const facts = [
119
- allergies.length ? (
120
- <Badge tone="warning">
121
- {allergies.length === 1 ? "Allergy" : "Allergies"}: {named(allergies, "Unknown allergy")}
122
- </Badge>
123
- ) : confirmedNkda ? (
124
- "No known allergies"
125
- ) : (
126
- "Allergies not recorded"
127
- ),
128
- meds.length ? `Active meds: ${named(meds, "Unknown medication")}` : recorded.medications && "No active meds",
129
- diagnoses.length ? `Diagnoses: ${named(diagnoses, "Unknown diagnosis")}` : recorded.diagnoses && "No diagnoses",
130
- benefits.length
131
- ? `Insurance: ${benefits.map((b) => `BIN ${b.bin}`).join(", ")}`
132
- : recorded.benefits && "No insurance",
133
- ].filter(Boolean);
134
- const factLine = (
135
- <Text tone="secondary">
136
- {facts.map((fact, i) => (
137
- <Fragment key={i}>
138
- {i > 0 && " · "}
139
- <span>{fact}</span>
140
- </Fragment>
141
- ))}
142
- </Text>
143
- );
144
-
145
- return (
146
- <Card divided>
147
- <CardHeader
148
- title={displayName(fullName(patient))}
149
- description={line || undefined}
150
- action={
151
- <Row gap="1">
152
- {!readOnly && (
153
- <span {...focusProps}>
154
- <Button
155
- variant="ghost"
156
- icon={expanded ? "check" : "edit"}
157
- aria-label={expanded ? "Done editing patient" : "Edit patient"}
158
- title={expanded ? "Done" : "Edit patient"}
159
- aria-expanded={expanded}
160
- onClick={() => setEditing(!expanded)}
161
- />
162
- </span>
163
- )}
164
- {onChangePatient && (
165
- <Button
166
- variant="ghost"
167
- onClick={onChangePatient}
168
- aria-label="Change patient"
169
- title="Change patient"
170
- icon="close"
171
- />
172
- )}
173
- </Row>
174
- }
175
- />
176
- <CardBody>
177
- <Stack gap="4">
178
- {!expanded && factLine}
179
- {expanded && (
180
- <Stack gap="4">
181
- <DetailsEditor patient={patient} onSave={onSaveDetails} />
182
- <ContactFields
183
- phone={d?.phone ?? null}
184
- email={d?.email ?? null}
185
- address={d?.address ?? null}
186
- onSave={onSaveContact}
187
- addressRequest={addressRequest}
188
- />
189
- <ClinicalList
190
- label="Allergies"
191
- choices={choicesIn(choices, "allergies")}
192
- problems={choicesIn(problems, "allergies")}
193
- onChoose={onChoose}
194
- items={allergies}
195
- tone="warning"
196
- addLabel="Add allergy"
197
- noneLabel="No known allergies"
198
- noneAction="Mark NKDA"
199
- confirmedNone={confirmedNkda}
200
- unknownLabel="Unknown allergy"
201
- pickedNames={pickedNames}
202
- saving={saving}
203
- onAdd={onAddAllergy}
204
- onRemove={onRemoveAllergy}
205
- onNone={() => onConfirmNone("allergies")}
206
- />
207
- <ClinicalList
208
- label="Medications"
209
- choices={choicesIn(choices, "medications")}
210
- problems={choicesIn(problems, "medications")}
211
- onChoose={onChoose}
212
- items={meds}
213
- tone="neutral"
214
- addLabel="Add medication"
215
- noneLabel="No active meds"
216
- noneAction="Mark none"
217
- confirmedNone={recorded.medications?.length === 0}
218
- onNone={() => onConfirmNone("medications")}
219
- unknownLabel="Unknown medication"
220
- pickedNames={pickedNames}
221
- saving={saving}
222
- onAdd={onAddMedication}
223
- onRemove={onRemoveMedication}
224
- />
225
- <ClinicalList
226
- label="Diagnoses"
227
- choices={choicesIn(choices, "diagnoses")}
228
- problems={choicesIn(problems, "diagnoses")}
229
- onChoose={onChoose}
230
- items={diagnoses}
231
- tone="neutral"
232
- addLabel="Add diagnosis"
233
- noneLabel="No diagnoses"
234
- noneAction="Mark none"
235
- confirmedNone={recorded.diagnoses?.length === 0}
236
- onNone={() => onConfirmNone("diagnoses")}
237
- unknownLabel="Unknown diagnosis"
238
- pickedNames={pickedNames}
239
- saving={saving}
240
- onAdd={onAddDiagnosis}
241
- onRemove={onRemoveDiagnosis}
242
- />
243
- <BenefitsSection
244
- benefits={recorded.benefits}
245
- saving={saving}
246
- onAdd={onAddBenefit}
247
- onRemove={onRemoveBenefit}
248
- onNone={onConfirmNoBenefits}
249
- />
250
- </Stack>
251
- )}
252
- {changes}
253
- </Stack>
254
- </CardBody>
255
- </Card>
256
- );
257
- }
258
-
259
- /** Name / DOB / sex of a saved patient — each saves when you leave it (save early, fix in place). */
260
- function DetailsEditor({
261
- patient,
262
- onSave,
263
- }: {
264
- patient: PatientRecord;
265
- onSave: (details: PatientDemographicInput) => void;
266
- }) {
267
- const { Grid, Input, Select } = useComponents();
268
- const d = patient.demographic;
269
- const [first, setFirst] = useState(d?.name.first ?? "");
270
- const [last, setLast] = useState(d?.name.last ?? "");
271
- const [dob, setDob] = useState(d?.dateOfBirth ?? "");
272
- const saveName = () => {
273
- if (first.trim() && last.trim() && (first.trim() !== d?.name.first || last.trim() !== d?.name.last)) {
274
- onSave({ name: { first: first.trim(), last: last.trim() } });
275
- }
276
- };
277
- return (
278
- <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
- />
308
- </Grid>
309
- );
310
- }