@photonhealth/react 2.0.0-rc.2 → 2.0.0-rc.4

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