@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.
- package/README.md +52 -9
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -4
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +19 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +76 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/cardLifecycle.d.ts +10 -0
- package/dist/analytics/cardLifecycle.d.ts.map +1 -0
- package/dist/analytics/cardLifecycle.js +43 -0
- package/dist/analytics/cardLifecycle.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/lifecycleOutcomes.d.ts +8 -0
- package/dist/analytics/lifecycleOutcomes.d.ts.map +1 -0
- package/dist/analytics/lifecycleOutcomes.js +16 -0
- package/dist/analytics/lifecycleOutcomes.js.map +1 -0
- package/dist/analytics/tracker.d.ts +19 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +41 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts +18 -18
- package/dist/components/PhotonOrder.d.ts.map +1 -1
- package/dist/components/PhotonOrder.js +34 -19
- package/dist/components/PhotonOrder.js.map +1 -1
- package/dist/components/PhotonPatient.d.ts +7 -35
- package/dist/components/PhotonPatient.d.ts.map +1 -1
- package/dist/components/PhotonPatient.js +6 -78
- package/dist/components/PhotonPatient.js.map +1 -1
- package/dist/components/PhotonPrescription.d.ts +15 -26
- package/dist/components/PhotonPrescription.d.ts.map +1 -1
- package/dist/components/PhotonPrescription.js +6 -360
- package/dist/components/PhotonPrescription.js.map +1 -1
- package/dist/components/format.d.ts +2 -2
- package/dist/components/format.js +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/open.d.ts +11 -13
- package/dist/components/open.d.ts.map +1 -1
- package/dist/components/open.js +7 -2
- package/dist/components/open.js.map +1 -1
- package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.js.map +1 -0
- package/dist/components/patient/PatientCard/PatientCard.d.ts +30 -0
- package/dist/components/patient/PatientCard/PatientCard.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/PatientCard.js +101 -0
- package/dist/components/patient/PatientCard/PatientCard.js.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts +22 -0
- package/dist/components/patient/PatientCard/usePatientToShow.d.ts.map +1 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js +40 -0
- package/dist/components/patient/PatientCard/usePatientToShow.js.map +1 -0
- package/dist/components/patient/PatientIntakeForm.d.ts +16 -0
- package/dist/components/patient/PatientIntakeForm.d.ts.map +1 -0
- package/dist/components/patient/PatientIntakeForm.js +114 -0
- package/dist/components/patient/PatientIntakeForm.js.map +1 -0
- package/dist/components/patient/PatientSearch.d.ts +12 -0
- package/dist/components/patient/PatientSearch.d.ts.map +1 -0
- package/dist/components/patient/PatientSearch.js +148 -0
- package/dist/components/patient/PatientSearch.js.map +1 -0
- package/dist/components/patient/{Benefits.d.ts → PatientSummary/BenefitsInputForm.d.ts} +2 -2
- package/dist/components/patient/PatientSummary/BenefitsInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Benefits.js → PatientSummary/BenefitsInputForm.js} +6 -5
- package/dist/components/patient/PatientSummary/BenefitsInputForm.js.map +1 -0
- package/dist/components/patient/{Clinical.d.ts → PatientSummary/ClinicalInputForm.d.ts} +15 -16
- package/dist/components/patient/PatientSummary/ClinicalInputForm.d.ts.map +1 -0
- package/dist/components/patient/{Clinical.js → PatientSummary/ClinicalInputForm.js} +29 -28
- package/dist/components/patient/PatientSummary/ClinicalInputForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts +5 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js +30 -0
- package/dist/components/patient/PatientSummary/CollapsedSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts +10 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js +65 -0
- package/dist/components/patient/PatientSummary/PatientDetailsForm.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts +53 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js +78 -0
- package/dist/components/patient/PatientSummary/PatientDetailsSchema.js.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts +46 -0
- package/dist/components/patient/PatientSummary/PatientSummary.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js +57 -0
- package/dist/components/patient/PatientSummary/PatientSummary.js.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts +19 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.d.ts.map +1 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js +22 -0
- package/dist/components/patient/PatientSummary/SummaryHeader.js.map +1 -0
- package/dist/components/patient/fields.d.ts +7 -26
- package/dist/components/patient/fields.d.ts.map +1 -1
- package/dist/components/patient/fields.js +11 -52
- package/dist/components/patient/fields.js.map +1 -1
- package/dist/components/patient/parsePatientSearchQuery.d.ts +16 -0
- package/dist/components/patient/parsePatientSearchQuery.d.ts.map +1 -0
- package/dist/components/patient/{query.js → parsePatientSearchQuery.js} +3 -10
- package/dist/components/patient/parsePatientSearchQuery.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +51 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +186 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/{TreatmentPicker.js → prescription/TreatmentSearch/TreatmentPicker.js} +113 -105
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +13 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +25 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/components/search.d.ts +1 -1
- package/dist/components/search.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +3 -1
- package/dist/primitives/PhotonProvider.d.ts.map +1 -1
- package/dist/primitives/PhotonProvider.js +23 -11
- package/dist/primitives/PhotonProvider.js.map +1 -1
- package/dist/primitives/defaults.d.ts.map +1 -1
- package/dist/primitives/defaults.js +6 -3
- package/dist/primitives/defaults.js.map +1 -1
- package/dist/primitives/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.js.map +1 -0
- package/dist/primitives/types.d.ts +15 -3
- package/dist/primitives/types.d.ts.map +1 -1
- package/dist/primitives/types.js.map +1 -1
- package/dist/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +45 -3
- package/dist/test-utils/contract.d.ts.map +1 -1
- package/dist/test-utils/contract.js +23 -2
- package/dist/test-utils/contract.js.map +1 -1
- package/package.json +8 -3
- package/src/adapters/tailwind.tsx +52 -24
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +190 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +151 -0
- package/src/analytics/cardLifecycle.test.tsx +272 -0
- package/src/analytics/cardLifecycle.ts +44 -0
- package/src/analytics/fieldInteraction.test.tsx +186 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/lifecycleOutcomes.test.ts +78 -0
- package/src/analytics/lifecycleOutcomes.ts +29 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +49 -0
- package/src/analytics/usePhotonAnalytics.test.tsx +106 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/PhotonOrder.test.tsx +394 -0
- package/src/components/PhotonOrder.tsx +79 -53
- package/src/components/PhotonPatient.tsx +15 -166
- package/src/components/PhotonPrescription.test.tsx +120 -0
- package/src/components/PhotonPrescription.tsx +23 -583
- package/src/components/ScreeningAlerts.test.tsx +81 -0
- package/src/components/format.ts +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/open.ts +13 -16
- package/src/components/order/DraftOrderPrompt.test.tsx +77 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/PatientCard/PatientCard.test.tsx +255 -0
- package/src/components/patient/PatientCard/PatientCard.tsx +177 -0
- package/src/components/patient/PatientCard/usePatientToShow.ts +44 -0
- package/src/components/patient/PatientIntakeForm.test.tsx +262 -0
- package/src/components/patient/PatientIntakeForm.tsx +222 -0
- package/src/components/patient/PatientSearch.test.tsx +204 -0
- package/src/components/patient/PatientSearch.tsx +221 -0
- package/src/components/patient/PatientSummary/BenefitsInputForm.test.tsx +164 -0
- package/src/components/patient/{Benefits.tsx → PatientSummary/BenefitsInputForm.tsx} +24 -16
- package/src/components/patient/PatientSummary/ClinicalInputForm.test.tsx +247 -0
- package/src/components/patient/{Clinical.tsx → PatientSummary/ClinicalInputForm.tsx} +53 -48
- package/src/components/patient/PatientSummary/CollapsedSummary.test.tsx +90 -0
- package/src/components/patient/PatientSummary/CollapsedSummary.tsx +46 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.test.tsx +201 -0
- package/src/components/patient/PatientSummary/PatientDetailsForm.tsx +320 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.test.ts +296 -0
- package/src/components/patient/PatientSummary/PatientDetailsSchema.ts +95 -0
- package/src/components/patient/PatientSummary/PatientSummary.test.tsx +194 -0
- package/src/components/patient/PatientSummary/PatientSummary.tsx +225 -0
- package/src/components/patient/PatientSummary/SummaryHeader.test.tsx +183 -0
- package/src/components/patient/PatientSummary/SummaryHeader.tsx +85 -0
- package/src/components/patient/fields.tsx +12 -124
- package/src/components/patient/parsePatientSearchQuery.test.ts +107 -0
- package/src/components/patient/{query.ts → parsePatientSearchQuery.ts} +4 -15
- package/src/components/prescription/PrescriptionCard.test.tsx +247 -0
- package/src/components/prescription/PrescriptionCard.tsx +361 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +82 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +206 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +453 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +72 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +695 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +34 -0
- package/src/components/search.tsx +1 -1
- package/src/index.ts +2 -0
- package/src/meta/version.test.ts +11 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +30 -15
- package/src/primitives/defaults.tsx +44 -21
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/types.ts +15 -3
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +45 -3
- package/src/test-utils/contract.tsx +45 -2
- package/dist/components/TreatmentPicker.d.ts +0 -45
- package/dist/components/TreatmentPicker.d.ts.map +0 -1
- package/dist/components/TreatmentPicker.js.map +0 -1
- package/dist/components/patient/Benefits.d.ts.map +0 -1
- package/dist/components/patient/Benefits.js.map +0 -1
- package/dist/components/patient/Clinical.d.ts.map +0 -1
- package/dist/components/patient/Clinical.js.map +0 -1
- package/dist/components/patient/IntakeForm.d.ts +0 -10
- package/dist/components/patient/IntakeForm.d.ts.map +0 -1
- package/dist/components/patient/IntakeForm.js +0 -324
- package/dist/components/patient/IntakeForm.js.map +0 -1
- package/dist/components/patient/Summary.d.ts +0 -48
- package/dist/components/patient/Summary.d.ts.map +0 -1
- package/dist/components/patient/Summary.js +0 -80
- package/dist/components/patient/Summary.js.map +0 -1
- package/dist/components/patient/query.d.ts +0 -23
- package/dist/components/patient/query.d.ts.map +0 -1
- package/dist/components/patient/query.js.map +0 -1
- package/src/components/TreatmentPicker.tsx +0 -350
- package/src/components/patient/IntakeForm.tsx +0 -532
- package/src/components/patient/Summary.tsx +0 -310
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import type { PatientRecord } from "@photonhealth/client";
|
|
4
|
+
import { CollapsedSummary } from "./CollapsedSummary.tsx";
|
|
5
|
+
import { patientRecord as record } from "../../../../test/patientRecord.fixtures.ts";
|
|
6
|
+
|
|
7
|
+
const renderSummary = (patient: PatientRecord) => render(<CollapsedSummary patient={patient} />);
|
|
8
|
+
|
|
9
|
+
describe("CollapsedSummary", () => {
|
|
10
|
+
/** The whole collapsed summary line, as one string. */
|
|
11
|
+
const text = () => document.body.textContent;
|
|
12
|
+
|
|
13
|
+
// Pins today's behavior
|
|
14
|
+
// TODO: This default copy confused our doctor consultant a few weeks ago, and we should reconsider the copy
|
|
15
|
+
it('no clinical lists recorded: shows only "Allergies not recorded"', () => {
|
|
16
|
+
renderSummary(record());
|
|
17
|
+
expect(text()).toBe("Allergies not recorded");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Pins today's behavior
|
|
21
|
+
// Question: Is it correct to say no known allergies for a 0-size allergies array?
|
|
22
|
+
// I thought we had a separate flag for NKDA
|
|
23
|
+
it("every list recorded as none: says so for each list, in order allergies · meds · diagnoses · insurance", () => {
|
|
24
|
+
renderSummary(record({ clinical: { allergies: [], medications: [], diagnoses: [] }, benefits: [] }));
|
|
25
|
+
expect(text()).toBe("No known allergies · No active meds · No diagnoses · No insurance");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("an entry in every list: names each entry, in order allergies · meds · diagnoses · insurance", () => {
|
|
29
|
+
renderSummary(
|
|
30
|
+
record({
|
|
31
|
+
clinical: {
|
|
32
|
+
allergies: [{ id: "alg_1", name: "Penicillin", rxNormId: null }],
|
|
33
|
+
medications: [{ id: "med_1", name: "Lisinopril", rxNormId: null, status: "ACTIVE" }],
|
|
34
|
+
diagnoses: [{ id: "dx_1", name: "Hypertension", icd10Code: "I10" }],
|
|
35
|
+
},
|
|
36
|
+
benefits: [{ id: "ben_1", bin: "610014", pcn: null, groupId: null, memberId: "M1" }],
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
expect(text()).toBe(
|
|
40
|
+
"Allergy: Penicillin · Active meds: Lisinopril · Diagnoses: Hypertension · Insurance: BIN 610014",
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('medications that aren\'t ACTIVE: shows "No active meds"', () => {
|
|
45
|
+
renderSummary(
|
|
46
|
+
record({
|
|
47
|
+
clinical: {
|
|
48
|
+
medications: [
|
|
49
|
+
{ id: "med_1", name: "Lisinopril", rxNormId: null, status: "HISTORICAL" },
|
|
50
|
+
{ id: "med_2", name: "Metformin", rxNormId: null, status: "UNKNOWN" },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
expect(text()).toBe("Allergies not recorded · No active meds");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("diagnosis without a name: shows the ICD-10 code", () => {
|
|
59
|
+
renderSummary(record({ clinical: { diagnoses: [{ id: "dx_1", name: null, icd10Code: "I10" }] } }));
|
|
60
|
+
expect(text()).toBe("Allergies not recorded · Diagnoses: I10");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Pins today's behavior
|
|
64
|
+
// Question: why BIN number as the display?
|
|
65
|
+
// Jake says insurance provider name and active status is probably more useful
|
|
66
|
+
it("several insurance plans: shows each plan's BIN only", () => {
|
|
67
|
+
renderSummary(
|
|
68
|
+
record({
|
|
69
|
+
benefits: [
|
|
70
|
+
{ id: "ben_1", bin: "610014", pcn: "PCN", groupId: "G", memberId: "M1" },
|
|
71
|
+
{ id: "ben_2", bin: "004336", pcn: null, groupId: null, memberId: "M2" },
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
expect(text()).toBe("Allergies not recorded · Insurance: BIN 610014, BIN 004336");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('entry without a name: shows "Unknown <list item>"', () => {
|
|
79
|
+
renderSummary(
|
|
80
|
+
record({
|
|
81
|
+
clinical: {
|
|
82
|
+
allergies: [{ id: "alg_1", name: "", rxNormId: null }],
|
|
83
|
+
medications: [{ id: "med_1", name: "", rxNormId: null, status: "ACTIVE" }],
|
|
84
|
+
diagnoses: [{ id: "dx_1", name: null, icd10Code: null }],
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
expect(text()).toBe("Allergy: Unknown allergy · Active meds: Unknown medication · Diagnoses: Unknown diagnosis");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** PatientSummary's collapsed summary: the patient's allergies, active meds, diagnoses and insurance, in one line. */
|
|
2
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
3
|
+
import { type PatientRecord } from "@photonhealth/client";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
|
|
6
|
+
export function CollapsedSummary({ patient }: { patient: PatientRecord }) {
|
|
7
|
+
const { Badge, Text } = useComponents();
|
|
8
|
+
// Each list: null when nothing is recorded, [] when "none" is (core's PatientRecord).
|
|
9
|
+
const recorded = {
|
|
10
|
+
allergies: patient.clinical?.allergies ?? null,
|
|
11
|
+
medications: patient.clinical?.medications ?? null,
|
|
12
|
+
diagnoses: patient.clinical?.diagnoses ?? null,
|
|
13
|
+
benefits: patient.benefits,
|
|
14
|
+
};
|
|
15
|
+
const allergies = recorded.allergies ?? [];
|
|
16
|
+
const meds = (recorded.medications ?? []).filter((m) => m.status === "ACTIVE");
|
|
17
|
+
const diagnoses = (recorded.diagnoses ?? []).map((x) => ({ ...x, name: x.name ?? x.icd10Code ?? "" }));
|
|
18
|
+
const benefits = recorded.benefits ?? [];
|
|
19
|
+
const named = (items: { name: string }[], unknown: string) => items.map((x) => x.name || unknown).join(", ");
|
|
20
|
+
const facts = [
|
|
21
|
+
allergies.length ? (
|
|
22
|
+
<Badge tone="warning">
|
|
23
|
+
{allergies.length === 1 ? "Allergy" : "Allergies"}: {named(allergies, "Unknown allergy")}
|
|
24
|
+
</Badge>
|
|
25
|
+
) : recorded.allergies?.length === 0 ? (
|
|
26
|
+
"No known allergies"
|
|
27
|
+
) : (
|
|
28
|
+
"Allergies not recorded"
|
|
29
|
+
),
|
|
30
|
+
meds.length ? `Active meds: ${named(meds, "Unknown medication")}` : recorded.medications && "No active meds",
|
|
31
|
+
diagnoses.length ? `Diagnoses: ${named(diagnoses, "Unknown diagnosis")}` : recorded.diagnoses && "No diagnoses",
|
|
32
|
+
benefits.length
|
|
33
|
+
? `Insurance: ${benefits.map((b) => `BIN ${b.bin}`).join(", ")}`
|
|
34
|
+
: recorded.benefits && "No insurance",
|
|
35
|
+
].filter(Boolean);
|
|
36
|
+
return (
|
|
37
|
+
<Text tone="secondary">
|
|
38
|
+
{facts.map((fact, i) => (
|
|
39
|
+
<Fragment key={i}>
|
|
40
|
+
{i > 0 && " · "}
|
|
41
|
+
<span>{fact}</span>
|
|
42
|
+
</Fragment>
|
|
43
|
+
))}
|
|
44
|
+
</Text>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it, vi, type Mock } from "vitest";
|
|
4
|
+
import type { PatientRecord } from "@photonhealth/client";
|
|
5
|
+
import { PatientDetailsForm, type PatientDetailsInput } from "./PatientDetailsForm.tsx";
|
|
6
|
+
import { patientRecord as record } from "../../../../test/patientRecord.fixtures.ts";
|
|
7
|
+
|
|
8
|
+
type Contact = NonNullable<PatientRecord["contact"]>;
|
|
9
|
+
|
|
10
|
+
/** Ada Lovelace, born 1990-01-01, female, with the contact details a test passes. */
|
|
11
|
+
const ada = (contact: Partial<Contact> | null = null): PatientRecord => ({
|
|
12
|
+
...record({ demographic: { dateOfBirth: "1990-01-01", sex: "FEMALE" } }),
|
|
13
|
+
contact: contact && { phone: null, email: null, address: null, ...contact },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const address = { street1: "1 Main St", street2: null, city: "Boston", state: "MA", postalCode: "02101" };
|
|
17
|
+
|
|
18
|
+
const renderForm = ({
|
|
19
|
+
patient = ada(),
|
|
20
|
+
addressRequest = null,
|
|
21
|
+
}: { patient?: PatientRecord; addressRequest?: string | null } = {}) => {
|
|
22
|
+
const onSave = vi.fn();
|
|
23
|
+
const user = userEvent.setup();
|
|
24
|
+
render(<PatientDetailsForm patient={patient} addressRequest={addressRequest} onSave={onSave} />);
|
|
25
|
+
return { user, onSave };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const field = (label: string) => screen.getByLabelText(label);
|
|
29
|
+
|
|
30
|
+
/** Replace a field's text, then move the cursor out of it. */
|
|
31
|
+
const retype = async (user: ReturnType<typeof userEvent.setup>, label: string, text: string) => {
|
|
32
|
+
await user.clear(field(label));
|
|
33
|
+
if (text) await user.type(field(label), text);
|
|
34
|
+
await user.tab();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** What the one call to onSave sent. */
|
|
38
|
+
const sent = (onSave: Mock) => {
|
|
39
|
+
expect(onSave).toHaveBeenCalledOnce();
|
|
40
|
+
return onSave.mock.calls[0]![0] as PatientDetailsInput;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const clickSave = (user: ReturnType<typeof userEvent.setup>) =>
|
|
44
|
+
user.click(screen.getByRole("button", { name: "Save" }));
|
|
45
|
+
|
|
46
|
+
describe("PatientDetailsForm", () => {
|
|
47
|
+
describe("initial values", () => {
|
|
48
|
+
it("saved patient: fills in every field from the record, with the phone number formatted", () => {
|
|
49
|
+
renderForm({ patient: ada({ phone: "+14155550172", email: "ada@example.com", address }) });
|
|
50
|
+
expect(field("First name")).toHaveValue("Ada");
|
|
51
|
+
expect(field("Last name")).toHaveValue("Lovelace");
|
|
52
|
+
expect(field("Date of birth")).toHaveValue("1990-01-01");
|
|
53
|
+
expect(screen.getByRole("combobox", { name: "Sex" })).toHaveValue("FEMALE");
|
|
54
|
+
expect(field("Phone")).toHaveValue("+1 (415) 555-0172");
|
|
55
|
+
expect(field("Email")).toHaveValue("ada@example.com");
|
|
56
|
+
expect(field("Street")).toHaveValue("1 Main St");
|
|
57
|
+
expect(field("Apt / suite")).toHaveValue("");
|
|
58
|
+
expect(field("City")).toHaveValue("Boston");
|
|
59
|
+
expect(field("State")).toHaveValue("MA");
|
|
60
|
+
expect(field("ZIP")).toHaveValue("02101");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("no demographic or contact details: every field starts empty", () => {
|
|
64
|
+
renderForm({ patient: record({ demographic: null }) });
|
|
65
|
+
for (const label of ["First name", "Last name", "Date of birth", "Phone", "Email", "Street", "City", "ZIP"]) {
|
|
66
|
+
expect(field(label)).toHaveValue("");
|
|
67
|
+
}
|
|
68
|
+
expect(screen.getByRole("combobox", { name: "Sex" })).toHaveValue("");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("phone", () => {
|
|
73
|
+
it("phone typed, then leaving the field: formats the phone number", async () => {
|
|
74
|
+
const { user } = renderForm();
|
|
75
|
+
await retype(user, "Phone", "415-555-0172");
|
|
76
|
+
expect(field("Phone")).toHaveValue("+1 (415) 555-0172");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Pins today's behavior
|
|
81
|
+
// Question: The form checks a field once the prescriber has left it (react-hook-form's "onTouched"
|
|
82
|
+
// mode), then again on every keystroke. This was an arbitrary choice - open to only showing validation
|
|
83
|
+
// errors on Save instead.
|
|
84
|
+
describe("errors while typing", () => {
|
|
85
|
+
it("phone typed: no error until leaving the field, then the error updates on every keystroke", async () => {
|
|
86
|
+
const { user } = renderForm();
|
|
87
|
+
await user.type(field("Phone"), "415");
|
|
88
|
+
expect(field("Phone")).not.toHaveAccessibleDescription("Enter a valid phone number");
|
|
89
|
+
|
|
90
|
+
await user.tab();
|
|
91
|
+
expect(field("Phone")).toHaveAccessibleDescription("Enter a valid phone number");
|
|
92
|
+
|
|
93
|
+
await user.type(field("Phone"), "5550172");
|
|
94
|
+
expect(field("Phone")).not.toHaveAccessibleDescription("Enter a valid phone number");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// How Save connects the form to PatientDetailsSchema and changesToSave
|
|
99
|
+
describe("Save", () => {
|
|
100
|
+
it("nothing changed, clicking Save: calls onSave once with every field filled in, changed or not", async () => {
|
|
101
|
+
const { user, onSave } = renderForm({ patient: ada({ phone: "+14155550172" }) });
|
|
102
|
+
await clickSave(user);
|
|
103
|
+
expect(onSave).toHaveBeenCalledExactlyOnceWith({
|
|
104
|
+
demographic: { name: { first: "Ada", last: "Lovelace" }, dateOfBirth: "1990-01-01", sex: "FEMALE" },
|
|
105
|
+
contact: { phone: "+14155550172", email: "" },
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("every field changed, clicking Save: sends every field as PatientDetailsSchema parses it", async () => {
|
|
110
|
+
const { user, onSave } = renderForm();
|
|
111
|
+
await retype(user, "First name", "Augusta");
|
|
112
|
+
await retype(user, "Last name", "Byron");
|
|
113
|
+
await retype(user, "Date of birth", "1991-02-03");
|
|
114
|
+
await user.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "MALE");
|
|
115
|
+
await retype(user, "Phone", "415-555-0172");
|
|
116
|
+
await retype(user, "Email", "ada@example.com");
|
|
117
|
+
await retype(user, "Street", " 1 Main St ");
|
|
118
|
+
await retype(user, "Apt / suite", "Apt 2");
|
|
119
|
+
await retype(user, "City", "Boston");
|
|
120
|
+
await retype(user, "State", "ma");
|
|
121
|
+
await retype(user, "ZIP", "02101");
|
|
122
|
+
await clickSave(user);
|
|
123
|
+
expect(onSave).toHaveBeenCalledExactlyOnceWith({
|
|
124
|
+
demographic: { name: { first: "Augusta", last: "Byron" }, dateOfBirth: "1991-02-03", sex: "MALE" },
|
|
125
|
+
contact: {
|
|
126
|
+
phone: "+14155550172",
|
|
127
|
+
email: "ada@example.com",
|
|
128
|
+
address: {
|
|
129
|
+
street1: "1 Main St",
|
|
130
|
+
street2: "Apt 2",
|
|
131
|
+
city: "Boston",
|
|
132
|
+
state: "MA",
|
|
133
|
+
postalCode: "02101",
|
|
134
|
+
country: "US",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("phone on file cleared, clicking Save: sends an empty phone to clear it in network-api", async () => {
|
|
141
|
+
const { user, onSave } = renderForm({ patient: ada({ phone: "+14155550172" }) });
|
|
142
|
+
await retype(user, "Phone", "");
|
|
143
|
+
await clickSave(user);
|
|
144
|
+
expect(sent(onSave)).toMatchObject({ contact: { phone: "" } });
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("email on file cleared, clicking Save: sends an empty email to clear it in network-api", async () => {
|
|
148
|
+
const { user, onSave } = renderForm({ patient: ada({ email: "ada@example.com" }) });
|
|
149
|
+
await retype(user, "Email", "");
|
|
150
|
+
await clickSave(user);
|
|
151
|
+
expect(sent(onSave)).toMatchObject({ contact: { email: "" } });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Documents that clearing a required field and clicking Save runs PatientDetailsSchema,
|
|
155
|
+
// shows its "Required" error on that field, and stops Save from sending anything.
|
|
156
|
+
it('last name cleared, clicking Save: shows "Required" on the last name, and onSave is not called', async () => {
|
|
157
|
+
const { user, onSave } = renderForm();
|
|
158
|
+
await user.clear(field("Last name"));
|
|
159
|
+
await clickSave(user);
|
|
160
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
161
|
+
expect(field("Last name")).toHaveAccessibleDescription("Required");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Documents that filling out a single address field causes
|
|
165
|
+
// other address fields to become required
|
|
166
|
+
it('only street filled in, clicking Save: shows "Required" on the untouched city, state and ZIP fields', async () => {
|
|
167
|
+
const { user, onSave } = renderForm();
|
|
168
|
+
await user.type(field("Street"), "1 Main St");
|
|
169
|
+
await clickSave(user);
|
|
170
|
+
expect(onSave).not.toHaveBeenCalled();
|
|
171
|
+
for (const label of ["City", "State", "ZIP"]) expect(field(label)).toHaveAccessibleDescription("Required");
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Pins today's behavior
|
|
176
|
+
// Sending an order the server refuses until the patient can be reached (a missing phone, email or address)
|
|
177
|
+
// expands PatientSummary and shows this warning above the contact fields. PhotonOrder passes the request down
|
|
178
|
+
// as `addressRequest`.
|
|
179
|
+
// TODO(TECH-1491): find a better place for this error than the patient's details form.
|
|
180
|
+
describe("contact request", () => {
|
|
181
|
+
it('order send refused until the patient can be reached, phone on file: shows "Address needed to send"', () => {
|
|
182
|
+
renderForm({ patient: ada({ phone: "+14155550172" }), addressRequest: "patient pat_1 has no address" });
|
|
183
|
+
expect(screen.getByText("Address needed to send")).toBeInTheDocument();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('order send refused until the patient can be reached, no phone on file: shows "Phone needed to send"', () => {
|
|
187
|
+
renderForm({ addressRequest: "patient pat_1 has no address" });
|
|
188
|
+
expect(screen.getByText("Phone needed to send")).toBeInTheDocument();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("order send refused until the patient can be reached: doesn't show the server's message, which can name internal ids", () => {
|
|
192
|
+
renderForm({ addressRequest: "patient pat_1 has no address" });
|
|
193
|
+
expect(screen.queryByText(/pat_1/)).not.toBeInTheDocument();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("no contact request: shows no message", () => {
|
|
197
|
+
renderForm();
|
|
198
|
+
expect(screen.queryByText(/needed to send/)).not.toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { useComponents } from "../../../primitives/index.ts";
|
|
2
|
+
import { type PatientInput, type PatientRecord } from "@photonhealth/client";
|
|
3
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
|
+
import { Controller, useForm, type Resolver } from "react-hook-form";
|
|
5
|
+
import { formatPhone } from "../../format.ts";
|
|
6
|
+
import { noAutofill, SEX_OPTIONS } from "../fields.tsx";
|
|
7
|
+
import { TrackedField, useFieldInteractions } from "../../../analytics/fieldInteraction.tsx";
|
|
8
|
+
import { PatientDetailsSchema, type PatientDetails, type PatientDetailsFormValues } from "./PatientDetailsSchema.ts";
|
|
9
|
+
|
|
10
|
+
/** The part of an UpdatePatient that PatientDetailsForm sends. */
|
|
11
|
+
export type PatientDetailsInput = Pick<PatientInput, "demographic" | "contact">;
|
|
12
|
+
|
|
13
|
+
export function PatientDetailsForm({
|
|
14
|
+
patient,
|
|
15
|
+
addressRequest,
|
|
16
|
+
onSave,
|
|
17
|
+
}: {
|
|
18
|
+
patient: PatientRecord;
|
|
19
|
+
addressRequest: string | null;
|
|
20
|
+
/** Called by Save once every field is valid, with every field to send. */
|
|
21
|
+
onSave: (input: PatientDetailsInput) => void | Promise<void>;
|
|
22
|
+
}) {
|
|
23
|
+
const { Alert, Button, Grid, Input, Row, Select, Stack } = useComponents();
|
|
24
|
+
const phone = patient.contact?.phone ?? null;
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
control,
|
|
28
|
+
handleSubmit,
|
|
29
|
+
formState: { isSubmitting },
|
|
30
|
+
} = useForm<PatientDetailsFormValues, unknown, PatientDetails>({
|
|
31
|
+
resolver: zodResolver(PatientDetailsSchema) as unknown as Resolver<
|
|
32
|
+
PatientDetailsFormValues,
|
|
33
|
+
unknown,
|
|
34
|
+
PatientDetails
|
|
35
|
+
>,
|
|
36
|
+
defaultValues: formValuesFrom(patient),
|
|
37
|
+
mode: "onTouched",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const fieldInteraction = useFieldInteractions("update_patient_form");
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<Grid min="200px" gap="3">
|
|
45
|
+
<TrackedField formName="update_patient_form" fieldName="firstName" isOptional={false}>
|
|
46
|
+
<Controller
|
|
47
|
+
control={control}
|
|
48
|
+
name="firstName"
|
|
49
|
+
render={({ field, fieldState }) => (
|
|
50
|
+
<Input
|
|
51
|
+
label="First name"
|
|
52
|
+
name={field.name}
|
|
53
|
+
value={field.value}
|
|
54
|
+
onChange={field.onChange}
|
|
55
|
+
onBlur={field.onBlur}
|
|
56
|
+
invalid={fieldState.invalid}
|
|
57
|
+
errorMessage={fieldState.error?.message}
|
|
58
|
+
{...noAutofill}
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
</TrackedField>
|
|
63
|
+
<TrackedField formName="update_patient_form" fieldName="lastName" isOptional={false}>
|
|
64
|
+
<Controller
|
|
65
|
+
control={control}
|
|
66
|
+
name="lastName"
|
|
67
|
+
render={({ field, fieldState }) => (
|
|
68
|
+
<Input
|
|
69
|
+
label="Last name"
|
|
70
|
+
name={field.name}
|
|
71
|
+
value={field.value}
|
|
72
|
+
onChange={field.onChange}
|
|
73
|
+
onBlur={field.onBlur}
|
|
74
|
+
invalid={fieldState.invalid}
|
|
75
|
+
errorMessage={fieldState.error?.message}
|
|
76
|
+
{...noAutofill}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
</TrackedField>
|
|
81
|
+
<TrackedField formName="update_patient_form" fieldName="dateOfBirth" isOptional={false}>
|
|
82
|
+
<Controller
|
|
83
|
+
control={control}
|
|
84
|
+
name="dateOfBirth"
|
|
85
|
+
render={({ field, fieldState }) => (
|
|
86
|
+
<Input
|
|
87
|
+
label="Date of birth"
|
|
88
|
+
type="date"
|
|
89
|
+
{...noAutofill}
|
|
90
|
+
name={field.name}
|
|
91
|
+
value={field.value}
|
|
92
|
+
onChange={field.onChange}
|
|
93
|
+
onBlur={field.onBlur}
|
|
94
|
+
invalid={fieldState.invalid}
|
|
95
|
+
errorMessage={fieldState.error?.message}
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
98
|
+
/>
|
|
99
|
+
</TrackedField>
|
|
100
|
+
<Controller
|
|
101
|
+
control={control}
|
|
102
|
+
name="sex"
|
|
103
|
+
render={({ field, fieldState }) => {
|
|
104
|
+
const sexInteractions = fieldInteraction("sex", { isOptional: false, hasValue: Boolean(field.value) });
|
|
105
|
+
return (
|
|
106
|
+
<div style={{ display: "contents" }} onFocus={sexInteractions.onFocus} onBlur={sexInteractions.onBlur}>
|
|
107
|
+
<Select
|
|
108
|
+
label="Sex"
|
|
109
|
+
placeholder="Select…"
|
|
110
|
+
options={SEX_OPTIONS}
|
|
111
|
+
value={field.value}
|
|
112
|
+
onChange={(sex) => {
|
|
113
|
+
sexInteractions.onChange(true);
|
|
114
|
+
field.onChange(sex);
|
|
115
|
+
}}
|
|
116
|
+
invalid={fieldState.invalid}
|
|
117
|
+
errorMessage={fieldState.error?.message}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
</Grid>
|
|
124
|
+
<Stack gap="2">
|
|
125
|
+
{/* The server's message can name internal ids ("patient pat_… has no address"); the title says it. A send
|
|
126
|
+
needs a phone; an address only when the server still asks with a phone on file. */}
|
|
127
|
+
{addressRequest && <Alert tone="warning" title={phone ? "Address needed to send" : "Phone needed to send"} />}
|
|
128
|
+
<Grid min="120px" gap="3">
|
|
129
|
+
<TrackedField formName="update_patient_form" fieldName="phone" isOptional>
|
|
130
|
+
<Controller
|
|
131
|
+
control={control}
|
|
132
|
+
name="phone"
|
|
133
|
+
render={({ field, fieldState }) => (
|
|
134
|
+
<Input
|
|
135
|
+
label="Phone"
|
|
136
|
+
type="tel"
|
|
137
|
+
inputMode="tel"
|
|
138
|
+
name={field.name}
|
|
139
|
+
value={field.value}
|
|
140
|
+
onChange={field.onChange}
|
|
141
|
+
// Leaving the field shows the number formatted, e.g. "+1 (415) 555-0172".
|
|
142
|
+
onBlur={() => {
|
|
143
|
+
field.onChange(formatPhone(field.value));
|
|
144
|
+
field.onBlur();
|
|
145
|
+
}}
|
|
146
|
+
invalid={fieldState.invalid}
|
|
147
|
+
errorMessage={fieldState.error?.message}
|
|
148
|
+
{...noAutofill}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
/>
|
|
152
|
+
</TrackedField>
|
|
153
|
+
<TrackedField formName="update_patient_form" fieldName="email" isOptional>
|
|
154
|
+
<Controller
|
|
155
|
+
control={control}
|
|
156
|
+
name="email"
|
|
157
|
+
render={({ field, fieldState }) => (
|
|
158
|
+
<Input
|
|
159
|
+
label="Email"
|
|
160
|
+
type="email"
|
|
161
|
+
inputMode="email"
|
|
162
|
+
name={field.name}
|
|
163
|
+
value={field.value}
|
|
164
|
+
onChange={field.onChange}
|
|
165
|
+
onBlur={field.onBlur}
|
|
166
|
+
invalid={fieldState.invalid}
|
|
167
|
+
errorMessage={fieldState.error?.message}
|
|
168
|
+
{...noAutofill}
|
|
169
|
+
/>
|
|
170
|
+
)}
|
|
171
|
+
/>
|
|
172
|
+
</TrackedField>
|
|
173
|
+
</Grid>
|
|
174
|
+
<Stack gap="3">
|
|
175
|
+
<Grid min="120px" gap="3">
|
|
176
|
+
<TrackedField formName="update_patient_form" fieldName="address_street1" isOptional>
|
|
177
|
+
<Controller
|
|
178
|
+
control={control}
|
|
179
|
+
name="address.street1"
|
|
180
|
+
render={({ field, fieldState }) => (
|
|
181
|
+
<Input
|
|
182
|
+
label="Street"
|
|
183
|
+
name={field.name}
|
|
184
|
+
value={field.value}
|
|
185
|
+
onChange={field.onChange}
|
|
186
|
+
onBlur={field.onBlur}
|
|
187
|
+
invalid={fieldState.invalid}
|
|
188
|
+
errorMessage={fieldState.error?.message}
|
|
189
|
+
{...noAutofill}
|
|
190
|
+
/>
|
|
191
|
+
)}
|
|
192
|
+
/>
|
|
193
|
+
</TrackedField>
|
|
194
|
+
<TrackedField formName="update_patient_form" fieldName="address_street2" isOptional>
|
|
195
|
+
<Controller
|
|
196
|
+
control={control}
|
|
197
|
+
name="address.street2"
|
|
198
|
+
render={({ field, fieldState }) => (
|
|
199
|
+
<Input
|
|
200
|
+
label="Apt / suite"
|
|
201
|
+
name={field.name}
|
|
202
|
+
value={field.value}
|
|
203
|
+
onChange={field.onChange}
|
|
204
|
+
onBlur={field.onBlur}
|
|
205
|
+
invalid={fieldState.invalid}
|
|
206
|
+
errorMessage={fieldState.error?.message}
|
|
207
|
+
{...noAutofill}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
/>
|
|
211
|
+
</TrackedField>
|
|
212
|
+
</Grid>
|
|
213
|
+
<Grid min="120px" gap="3">
|
|
214
|
+
<TrackedField formName="update_patient_form" fieldName="address_city" isOptional>
|
|
215
|
+
<Controller
|
|
216
|
+
control={control}
|
|
217
|
+
name="address.city"
|
|
218
|
+
render={({ field, fieldState }) => (
|
|
219
|
+
<Input
|
|
220
|
+
label="City"
|
|
221
|
+
name={field.name}
|
|
222
|
+
value={field.value}
|
|
223
|
+
onChange={field.onChange}
|
|
224
|
+
onBlur={field.onBlur}
|
|
225
|
+
invalid={fieldState.invalid}
|
|
226
|
+
errorMessage={fieldState.error?.message}
|
|
227
|
+
{...noAutofill}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
</TrackedField>
|
|
232
|
+
<TrackedField formName="update_patient_form" fieldName="address_state" isOptional>
|
|
233
|
+
<Controller
|
|
234
|
+
control={control}
|
|
235
|
+
name="address.state"
|
|
236
|
+
render={({ field, fieldState }) => (
|
|
237
|
+
<Input
|
|
238
|
+
label="State"
|
|
239
|
+
maxLength={2}
|
|
240
|
+
name={field.name}
|
|
241
|
+
value={field.value}
|
|
242
|
+
onChange={field.onChange}
|
|
243
|
+
onBlur={field.onBlur}
|
|
244
|
+
invalid={fieldState.invalid}
|
|
245
|
+
errorMessage={fieldState.error?.message}
|
|
246
|
+
{...noAutofill}
|
|
247
|
+
/>
|
|
248
|
+
)}
|
|
249
|
+
/>
|
|
250
|
+
</TrackedField>
|
|
251
|
+
<TrackedField formName="update_patient_form" fieldName="address_zip" isOptional>
|
|
252
|
+
<Controller
|
|
253
|
+
control={control}
|
|
254
|
+
name="address.postalCode"
|
|
255
|
+
render={({ field, fieldState }) => (
|
|
256
|
+
<Input
|
|
257
|
+
label="ZIP"
|
|
258
|
+
inputMode="numeric"
|
|
259
|
+
name={field.name}
|
|
260
|
+
value={field.value}
|
|
261
|
+
onChange={field.onChange}
|
|
262
|
+
onBlur={field.onBlur}
|
|
263
|
+
invalid={fieldState.invalid}
|
|
264
|
+
errorMessage={fieldState.error?.message}
|
|
265
|
+
{...noAutofill}
|
|
266
|
+
/>
|
|
267
|
+
)}
|
|
268
|
+
/>
|
|
269
|
+
</TrackedField>
|
|
270
|
+
</Grid>
|
|
271
|
+
</Stack>
|
|
272
|
+
</Stack>
|
|
273
|
+
<Row justify="end">
|
|
274
|
+
{/* Save waits for onSave, so it's disabled (`loading`) while the update is in flight. */}
|
|
275
|
+
<Button
|
|
276
|
+
variant="secondary"
|
|
277
|
+
loading={isSubmitting}
|
|
278
|
+
onClick={handleSubmit((details) => onSave(toPatientInput(details)))}
|
|
279
|
+
>
|
|
280
|
+
Save
|
|
281
|
+
</Button>
|
|
282
|
+
</Row>
|
|
283
|
+
</>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function formValuesFrom(patient: PatientRecord): PatientDetailsFormValues {
|
|
288
|
+
const demographic = patient.demographic;
|
|
289
|
+
const address = patient.contact?.address;
|
|
290
|
+
return {
|
|
291
|
+
firstName: demographic?.name.first ?? "",
|
|
292
|
+
lastName: demographic?.name.last ?? "",
|
|
293
|
+
dateOfBirth: demographic?.dateOfBirth ?? "",
|
|
294
|
+
sex: demographic?.sex ?? null,
|
|
295
|
+
phone: formatPhone(patient.contact?.phone),
|
|
296
|
+
email: patient.contact?.email ?? "",
|
|
297
|
+
address: {
|
|
298
|
+
street1: address?.street1 ?? "",
|
|
299
|
+
street2: address?.street2 ?? "",
|
|
300
|
+
city: address?.city ?? "",
|
|
301
|
+
state: address?.state ?? "",
|
|
302
|
+
postalCode: address?.postalCode ?? "",
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function toPatientInput(details: PatientDetails): PatientDetailsInput {
|
|
308
|
+
return {
|
|
309
|
+
demographic: {
|
|
310
|
+
name: { first: details.firstName, last: details.lastName },
|
|
311
|
+
dateOfBirth: details.dateOfBirth,
|
|
312
|
+
sex: details.sex,
|
|
313
|
+
},
|
|
314
|
+
contact: {
|
|
315
|
+
phone: details.phone,
|
|
316
|
+
email: details.email,
|
|
317
|
+
...(details.address && { address: details.address }),
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|