@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,81 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import type { ScreeningAlert } from "@photonhealth/client";
|
|
4
|
+
import { fakeNetworkApiClient } from "@photonhealth/client/testing";
|
|
5
|
+
import { ScreeningAlerts } from "./ScreeningAlerts.tsx";
|
|
6
|
+
import { withPhoton } from "../../test/cards.fixtures.tsx";
|
|
7
|
+
|
|
8
|
+
const amoxicillinAllergy: ScreeningAlert = {
|
|
9
|
+
severity: "MODERATE",
|
|
10
|
+
type: "ALLERGEN",
|
|
11
|
+
description: "May result in an allergic reaction based on a reported history of allergy to amoxicillin.",
|
|
12
|
+
involvedEntities: [{ id: "alg_1", name: "amoxicillin" }],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const warfarinInteraction: ScreeningAlert = {
|
|
16
|
+
severity: "MAJOR",
|
|
17
|
+
type: "DRUG",
|
|
18
|
+
description: "Increases the risk of bleeding.",
|
|
19
|
+
involvedEntities: [
|
|
20
|
+
{ id: "med_1", name: "warfarin" },
|
|
21
|
+
{ id: "med_2", name: "aspirin" },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe("ScreeningAlerts: what the prescriber reads for each alert", () => {
|
|
26
|
+
it("no alerts: renders nothing", () => {
|
|
27
|
+
const { container } = renderAlerts([]);
|
|
28
|
+
expect(container).toBeEmptyDOMElement();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("titles an alert with its type and severity in lower case", () => {
|
|
32
|
+
renderAlerts([amoxicillinAllergy]);
|
|
33
|
+
expect(screen.getByText("allergen · moderate")).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("follows the description with the involved names in parentheses, separated by commas", () => {
|
|
37
|
+
renderAlerts([warfarinInteraction]);
|
|
38
|
+
expect(screen.getByText("Increases the risk of bleeding. (warfarin, aspirin)")).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("shows the description alone when nothing is involved", () => {
|
|
42
|
+
renderAlerts([{ ...warfarinInteraction, involvedEntities: [] }]);
|
|
43
|
+
expect(screen.getByText("Increases the risk of bleeding.")).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.each([
|
|
47
|
+
["MINOR", "info"],
|
|
48
|
+
["MODERATE", "warning"],
|
|
49
|
+
["MAJOR", "critical"],
|
|
50
|
+
] as const)("a %s alert is shown in the %s tone", (severity, tone) => {
|
|
51
|
+
renderAlerts([{ ...warfarinInteraction, severity }]);
|
|
52
|
+
expect(toneOfAlertTitled(`drug · ${severity.toLowerCase()}`)).toBe(tone);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("an allergy takes the tone of its severity, the same as any other alert", () => {
|
|
56
|
+
renderAlerts([{ ...amoxicillinAllergy, severity: "MINOR" }]);
|
|
57
|
+
expect(toneOfAlertTitled("allergen · minor")).toBe("info");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("a condition alert is titled as a condition", () => {
|
|
61
|
+
renderAlerts([{ ...warfarinInteraction, type: "CONDITION" }]);
|
|
62
|
+
expect(screen.getByText("condition · major")).toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("shows every alert it is given, in order, repeating identical ones", () => {
|
|
66
|
+
renderAlerts([warfarinInteraction, amoxicillinAllergy, amoxicillinAllergy]);
|
|
67
|
+
expect(alertTitles()).toEqual(["drug · major", "allergen · moderate", "allergen · moderate"]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
function renderAlerts(alerts: ScreeningAlert[]) {
|
|
72
|
+
return render(<ScreeningAlerts alerts={alerts} />, { wrapper: withPhoton(fakeNetworkApiClient({}).client) });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function toneOfAlertTitled(title: string) {
|
|
76
|
+
return screen.getByText(title).closest("[data-tone]")?.getAttribute("data-tone");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function alertTitles() {
|
|
80
|
+
return [...document.querySelectorAll(".prx-alert-title")].map((title) => title.textContent);
|
|
81
|
+
}
|
package/src/components/format.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Display formatting, plus the one normalisation we send back (phone → E.164). */
|
|
2
2
|
|
|
3
|
-
/** "+
|
|
3
|
+
/** "+13175550147" / "3175550147" → "+1 (317) 555-0147"; anything else is shown as given. */
|
|
4
4
|
export function formatPhone(phone: string | null | undefined): string {
|
|
5
5
|
if (!phone) return "";
|
|
6
6
|
const digits = phone.replace(/\D/g, "");
|
|
@@ -11,7 +11,7 @@ export function formatPhone(phone: string | null | undefined): string {
|
|
|
11
11
|
/** Native validation for type="tel": a US number, punctuated any common way (+1 optional). */
|
|
12
12
|
export const PHONE_PATTERN = String.raw`\+?1?[\s.\-]*\(?\d{3}\)?[\s.\-]*\d{3}[\s.\-]*\d{4}`;
|
|
13
13
|
|
|
14
|
-
/** "(317)
|
|
14
|
+
/** "(317) 555-0147" → "+13175550147" (what network-api stores); non-US kept as typed; blank → undefined. */
|
|
15
15
|
export function toE164(phone: string): string | undefined {
|
|
16
16
|
const trimmed = phone.trim();
|
|
17
17
|
if (!trimmed) return undefined;
|
package/src/components/index.ts
CHANGED
|
@@ -2,4 +2,4 @@ export * from "./ChangeList.tsx";
|
|
|
2
2
|
export { PhotonPatient, type PhotonPatientProps } from "./PhotonPatient.tsx";
|
|
3
3
|
export { PhotonPrescription, type PhotonPrescriptionProps } from "./PhotonPrescription.tsx";
|
|
4
4
|
export * from "./PhotonOrder.tsx";
|
|
5
|
-
export * from "./TreatmentPicker.tsx";
|
|
5
|
+
export * from "./prescription/TreatmentSearch/TreatmentPicker.tsx";
|
package/src/components/open.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import type { Calls } from "@photonhealth/client";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* What a card is given for one record — any of: its id (`"pat_…"` or `{ id }`: read, `get`), the record's fields
|
|
6
|
-
* with its id (`update(id, fields)`: only those change), or fields without one (`sync`: the server finds,
|
|
7
|
-
* matches or creates). A live object instead is used as given and never comes here. Links give records the same
|
|
8
|
-
* way.
|
|
9
|
-
*/
|
|
10
|
-
export type Given<I extends object> = I | string;
|
|
11
|
-
|
|
12
4
|
/**
|
|
13
5
|
* A record given by id that the server doesn't have — network-api opens records only in the prescriber's own
|
|
14
6
|
* organization, so a link from another one lands here too.
|
|
@@ -24,9 +16,14 @@ export class NotFound extends Error {
|
|
|
24
16
|
export const openFailed = (what: string, error: Error) =>
|
|
25
17
|
error instanceof NotFound ? `${what[0]!.toUpperCase()}${what.slice(1)} not found` : `Couldn't open this ${what}`;
|
|
26
18
|
|
|
27
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* How a record a card is given (an id, or an input) opens: `get`, `update` or `sync` — and with what. Its id
|
|
21
|
+
* (`"pat_…"` or `{ id }`) is read (`get`); the record's fields with its id update it (`update(id, fields)`: only
|
|
22
|
+
* those change); fields without one sync (`sync`: the server finds, matches or creates). A live object is used as
|
|
23
|
+
* given and never comes here. Links give records the same way.
|
|
24
|
+
*/
|
|
28
25
|
export function callFor<I extends object>(
|
|
29
|
-
value:
|
|
26
|
+
value: I | string,
|
|
30
27
|
): { call: "get"; id: string } | { call: "update"; id: string; fields: Omit<I, "id"> } | { call: "sync"; input: I } {
|
|
31
28
|
if (typeof value === "string") return { call: "get", id: value };
|
|
32
29
|
const { id, ...fields } = value as I & { id?: string };
|
|
@@ -34,10 +31,10 @@ export function callFor<I extends object>(
|
|
|
34
31
|
return Object.keys(fields).length ? { call: "update", id, fields: fields as Omit<I, "id"> } : { call: "get", id };
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
/** Open a given record (see `
|
|
34
|
+
/** Open a given record (see `callFor`); null when an id has no record. */
|
|
38
35
|
export function openGiven<T, I extends object, R>(
|
|
39
36
|
calls: Calls<T, I, Omit<I, "id">, R>,
|
|
40
|
-
value:
|
|
37
|
+
value: I | string,
|
|
41
38
|
objectOf: (result: R) => T | null,
|
|
42
39
|
): Promise<T | null> {
|
|
43
40
|
return shared(calls, JSON.stringify(value), async () => {
|
|
@@ -64,8 +61,8 @@ export function shared<T>(scope: object, key: string, run: () => Promise<T>): Pr
|
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/** A record given as something to open: an id, or an input with something in it (an empty input is none). */
|
|
67
|
-
export const toOpen = <I extends object>(value:
|
|
68
|
-
!isLive && value && (typeof value === "string" || Object.keys(value).length) ? (value as
|
|
64
|
+
export const toOpen = <I extends object>(value: I | string | object | null | undefined, isLive: boolean) =>
|
|
65
|
+
!isLive && value && (typeof value === "string" || Object.keys(value).length) ? (value as I | string) : null;
|
|
69
66
|
|
|
70
67
|
/**
|
|
71
68
|
* `openGiven` for a card: the object once it's open, or why it couldn't be. Opens again when what it's given
|
|
@@ -73,7 +70,7 @@ export const toOpen = <I extends object>(value: Given<I> | object | null | undef
|
|
|
73
70
|
*/
|
|
74
71
|
export function useOpened<T, I extends object, R>(
|
|
75
72
|
calls: Calls<T, I, Omit<I, "id">, R>,
|
|
76
|
-
value:
|
|
73
|
+
value: I | string | null,
|
|
77
74
|
objectOf: (result: R) => T | null,
|
|
78
75
|
what: string,
|
|
79
76
|
): { opened: T | null; error: Error | null } {
|
|
@@ -84,7 +81,7 @@ export function useOpened<T, I extends object, R>(
|
|
|
84
81
|
error: null,
|
|
85
82
|
});
|
|
86
83
|
useEffect(() => {
|
|
87
|
-
const wanted = JSON.parse(key) as
|
|
84
|
+
const wanted = JSON.parse(key) as I | string | null;
|
|
88
85
|
if (!wanted) return;
|
|
89
86
|
let live = true;
|
|
90
87
|
const id = typeof wanted === "string" ? wanted : ((wanted as { id?: string }).id ?? "");
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { PrescriptionRecord } from "@photonhealth/client";
|
|
2
|
+
import { treatment } from "@photonhealth/client/testing";
|
|
3
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { DraftOrderPrompt } from "./DraftOrderPrompt.tsx";
|
|
6
|
+
|
|
7
|
+
const record = (id: string, fields: Partial<PrescriptionRecord> = {}): PrescriptionRecord => ({
|
|
8
|
+
id,
|
|
9
|
+
prescriber: null,
|
|
10
|
+
fulfillment: null,
|
|
11
|
+
templateId: null,
|
|
12
|
+
patient: { id: "pat_1" },
|
|
13
|
+
treatment: { ...treatment(), templates: null },
|
|
14
|
+
instructions: "Take 1 capsule by mouth three times daily",
|
|
15
|
+
dispense: { quantity: 30, unit: "Capsule", daysSupply: 10, refillsAllowed: 0, dispenseAsWritten: false },
|
|
16
|
+
clinical: null,
|
|
17
|
+
screeningAlerts: [],
|
|
18
|
+
signing: { state: "UNSIGNED", contentHash: "hash_1", message: null, signedAt: null },
|
|
19
|
+
...fields,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const amoxicillin = record("rx_1", {
|
|
23
|
+
treatment: {
|
|
24
|
+
...treatment({ name: "Amoxicillin", prescribableName: "Amoxicillin 500 MG Oral Capsule" }),
|
|
25
|
+
templates: null,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const lisinopril = record("rx_2", {
|
|
29
|
+
treatment: { ...treatment({ id: "trt_2", name: "Lisinopril 10 MG Oral Tablet" }), templates: null },
|
|
30
|
+
instructions: "Take 1 tablet by mouth once daily",
|
|
31
|
+
signing: { state: "SIGNED", contentHash: "hash_2", message: null, signedAt: "2026-11-01T00:00:00Z" },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("DraftOrderPrompt", () => {
|
|
35
|
+
it("shows each prescription on the draft, read-only, and asks whether to continue it", () => {
|
|
36
|
+
render(
|
|
37
|
+
<DraftOrderPrompt
|
|
38
|
+
draft={{ prescriptions: [amoxicillin, lisinopril] }}
|
|
39
|
+
onContinue={vi.fn()}
|
|
40
|
+
onStartNew={vi.fn()}
|
|
41
|
+
/>,
|
|
42
|
+
);
|
|
43
|
+
expect(screen.getByRole("heading", { name: "Amoxicillin" })).toBeTruthy();
|
|
44
|
+
expect(screen.getByRole("region", { name: "Amoxicillin" })).toBeTruthy(); // each card is named by its drug
|
|
45
|
+
expect(screen.getByRole("heading", { name: "Lisinopril" })).toBeTruthy();
|
|
46
|
+
expect(screen.getByText("Take 1 capsule by mouth three times daily")).toBeTruthy();
|
|
47
|
+
expect(screen.getByText("Signed")).toBeTruthy();
|
|
48
|
+
// Nothing to edit, sign or remove until the prescriber decides.
|
|
49
|
+
expect(screen.queryAllByRole("textbox")).toHaveLength(0);
|
|
50
|
+
expect(screen.queryByRole("button", { name: "Sign" })).toBeNull();
|
|
51
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull();
|
|
52
|
+
expect(screen.getByText("Would you like to continue this order?")).toBeTruthy();
|
|
53
|
+
expect(screen.getAllByRole("button").map((b) => b.textContent)).toEqual(["Continue", "Start a new order"]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("Continue and Start a new order each call their own handler", () => {
|
|
57
|
+
const onContinue = vi.fn();
|
|
58
|
+
const onStartNew = vi.fn();
|
|
59
|
+
render(
|
|
60
|
+
<DraftOrderPrompt draft={{ prescriptions: [amoxicillin] }} onContinue={onContinue} onStartNew={onStartNew} />,
|
|
61
|
+
);
|
|
62
|
+
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
|
|
63
|
+
expect(onContinue).toHaveBeenCalledOnce();
|
|
64
|
+
expect(onStartNew).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("while a choice is in flight, neither button can be pressed again", async () => {
|
|
68
|
+
let settle!: () => void;
|
|
69
|
+
const onStartNew = vi.fn(() => new Promise<void>((resolve) => (settle = resolve)));
|
|
70
|
+
render(<DraftOrderPrompt draft={{ prescriptions: [amoxicillin] }} onContinue={vi.fn()} onStartNew={onStartNew} />);
|
|
71
|
+
await act(async () => fireEvent.click(screen.getByRole("button", { name: "Start a new order" })));
|
|
72
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: /Start a new order/ }).disabled).toBe(true);
|
|
73
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: "Continue" }).disabled).toBe(true);
|
|
74
|
+
await act(async () => settle());
|
|
75
|
+
expect(screen.getByRole<HTMLButtonElement>("button", { name: "Continue" }).disabled).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { PrescriptionRecord } from "@photonhealth/client";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useComponents } from "../../primitives/index.ts";
|
|
4
|
+
import { treatmentHeading } from "../display.ts";
|
|
5
|
+
import { cardProps, focusProps } from "../flow.ts";
|
|
6
|
+
import { ReadOnlyRx, StatusBadge } from "../prescription/PrescriptionCard.tsx";
|
|
7
|
+
|
|
8
|
+
export interface DraftOrderPromptProps {
|
|
9
|
+
/** The patient's draft order: what's already on it, shown read-only until the prescriber decides. */
|
|
10
|
+
draft: { prescriptions: readonly PrescriptionRecord[] };
|
|
11
|
+
/** Go on with this draft: its prescriptions become the order's, and what's added goes on it. */
|
|
12
|
+
onContinue: () => void | Promise<unknown>;
|
|
13
|
+
/** Write a new order instead: the draft's prescriptions come off it, and the order starts over. */
|
|
14
|
+
onStartNew: () => void | Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A patient's draft order, found when they're chosen: its prescriptions, each on its own card as the order's lines
|
|
19
|
+
* are, then the question — continue it, or start a new order. Nothing changes until one is picked. Renders cards
|
|
20
|
+
* only, for PhotonOrder's flow.
|
|
21
|
+
*/
|
|
22
|
+
export function DraftOrderPrompt({ draft, onContinue, onStartNew }: DraftOrderPromptProps) {
|
|
23
|
+
const { Button, Card, CardBody, CardFooter, CardHeader, Row, Stack, Text } = useComponents();
|
|
24
|
+
// Which choice is in flight: that button spins, and neither can be pressed again until it settles.
|
|
25
|
+
const [choosing, setChoosing] = useState<"continue" | "new" | null>(null);
|
|
26
|
+
const choose = (which: "continue" | "new", act: () => void | Promise<unknown>) => {
|
|
27
|
+
setChoosing(which);
|
|
28
|
+
// A failure lands on the order (snapshot.error), where the card shows it.
|
|
29
|
+
void new Promise((resolve) => resolve(act())).catch(() => {}).finally(() => setChoosing(null));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{draft.prescriptions.map((rx) => {
|
|
35
|
+
const heading = treatmentHeading(rx.treatment.name, rx.treatment);
|
|
36
|
+
return (
|
|
37
|
+
<div key={rx.id} {...cardProps}>
|
|
38
|
+
<Card divided label={heading.title}>
|
|
39
|
+
<CardHeader title={heading.title} description={heading.detail} />
|
|
40
|
+
<CardBody>
|
|
41
|
+
<ReadOnlyRx rx={rx} status={<StatusBadge rx={rx} />} />
|
|
42
|
+
</CardBody>
|
|
43
|
+
</Card>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
})}
|
|
47
|
+
<div {...cardProps}>
|
|
48
|
+
<Card>
|
|
49
|
+
{/* The footer, not the body: a host's body text can be smaller (Photon Rx's is), and this is the card's
|
|
50
|
+
question. Stacked in `start`, so the buttons sit under it, on the left. */}
|
|
51
|
+
<CardFooter
|
|
52
|
+
start={
|
|
53
|
+
<Stack gap="3">
|
|
54
|
+
<Text>Would you like to continue this order?</Text>
|
|
55
|
+
<Row gap="2">
|
|
56
|
+
<span {...focusProps}>
|
|
57
|
+
<Button
|
|
58
|
+
loading={choosing === "continue"}
|
|
59
|
+
disabled={choosing !== null}
|
|
60
|
+
onClick={() => choose("continue", onContinue)}
|
|
61
|
+
>
|
|
62
|
+
Continue
|
|
63
|
+
</Button>
|
|
64
|
+
</span>
|
|
65
|
+
<Button
|
|
66
|
+
variant="secondary"
|
|
67
|
+
loading={choosing === "new"}
|
|
68
|
+
disabled={choosing !== null}
|
|
69
|
+
onClick={() => choose("new", onStartNew)}
|
|
70
|
+
>
|
|
71
|
+
Start a new order
|
|
72
|
+
</Button>
|
|
73
|
+
</Row>
|
|
74
|
+
</Stack>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
</Card>
|
|
78
|
+
</div>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import userEvent, { type UserEvent } from "@testing-library/user-event";
|
|
4
|
+
import { ambiguous, fakeNetworkApiClient, noMatch, payload, photonOver } from "@photonhealth/client/testing";
|
|
5
|
+
import { PatientCard } from "./PatientCard.tsx";
|
|
6
|
+
import { patient, withPhoton } from "../../../../test/cards.fixtures.tsx";
|
|
7
|
+
|
|
8
|
+
type PatientCardProps = Parameters<typeof PatientCard>[0];
|
|
9
|
+
type NetworkScript = Parameters<typeof fakeNetworkApiClient>[0];
|
|
10
|
+
|
|
11
|
+
const fakePatientGrace = {
|
|
12
|
+
...patient,
|
|
13
|
+
id: "pat_2",
|
|
14
|
+
demographic: { ...patient.demographic, name: { ...patient.demographic.name, first: "Grace", last: "Hopper" } },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A fake network-api that answers each patient read and update by id from `patientsById` (an id not there has
|
|
19
|
+
* no record), plus any other calls in `script`.
|
|
20
|
+
*/
|
|
21
|
+
const fakeServer = (patientsById: Record<string, unknown> = { pat_1: patient }, script: NetworkScript = {}) => {
|
|
22
|
+
const byId = (vars: { id: string }) => payload("patient", "PatientPayload", patientsById[vars.id] ?? null);
|
|
23
|
+
return fakeNetworkApiClient({ GetPatient: byId, UpdatePatient: byId, ...script });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Time for any call a render would repeat to go out. */
|
|
27
|
+
const settle = () => new Promise((done) => setTimeout(done, 100));
|
|
28
|
+
|
|
29
|
+
/** PatientCard over `fakeServer`, with a `user` to type and click as a prescriber would. */
|
|
30
|
+
const renderPatientCard = (props: PatientCardProps, patientsById?: Record<string, unknown>, script?: NetworkScript) => {
|
|
31
|
+
const { client, names } = fakeServer(patientsById, script);
|
|
32
|
+
const user = userEvent.setup();
|
|
33
|
+
return { ...render(<PatientCard {...props} />, { wrapper: withPhoton(client) }), callNames: names, user };
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const findPatientSearchComponent = () => screen.findByLabelText("Find patient");
|
|
37
|
+
|
|
38
|
+
const findPatientSummaryComponent = (name = /Ada Lovelace/) => screen.findByRole("heading", { name });
|
|
39
|
+
|
|
40
|
+
describe("PatientCard", () => {
|
|
41
|
+
describe("initial display for patient reference with clear ID", () => {
|
|
42
|
+
it("nothing passed: shows PatientSearch", async () => {
|
|
43
|
+
renderPatientCard({});
|
|
44
|
+
expect(await findPatientSearchComponent()).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("an empty object: shows PatientSearch", async () => {
|
|
48
|
+
renderPatientCard({ patient: {} });
|
|
49
|
+
expect(await findPatientSearchComponent()).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("a live Patient with a record: shows its summary", async () => {
|
|
53
|
+
const { client } = fakeServer();
|
|
54
|
+
const live = (await photonOver(client).patient.get("pat_1"))!;
|
|
55
|
+
render(<PatientCard patient={live} />, { wrapper: withPhoton(client) });
|
|
56
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("an id: shows PatientSummary for patient with that id", async () => {
|
|
60
|
+
renderPatientCard({ patient: "pat_1" });
|
|
61
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("an id as { id }: shows PatientSummary, the same as the id alone", async () => {
|
|
65
|
+
renderPatientCard({ patient: { id: "pat_1" } });
|
|
66
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("an id that doesn't exist: shows PatientSearch, saying the patient wasn't found", async () => {
|
|
70
|
+
renderPatientCard({ patient: "pat_missing" });
|
|
71
|
+
expect(await findPatientSearchComponent()).toBeInTheDocument();
|
|
72
|
+
expect(screen.getByText("Patient not found")).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("an id that doesn't exist, read-only: says the patient wasn't found, with no search", async () => {
|
|
76
|
+
renderPatientCard({ patient: "pat_missing", readOnly: true });
|
|
77
|
+
expect(await screen.findByText("Patient not found")).toBeInTheDocument();
|
|
78
|
+
expect(screen.queryByLabelText("Find patient")).not.toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("an id the server fails to read: says the patient couldn't be opened", async () => {
|
|
82
|
+
renderPatientCard({ patient: "pat_1" }, undefined, {
|
|
83
|
+
GetPatient: () => {
|
|
84
|
+
throw new Error("network-api is down");
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
expect(await screen.findByText("Couldn't open this patient")).toBeInTheDocument();
|
|
88
|
+
expect(screen.queryByLabelText("Find patient")).not.toBeInTheDocument();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("an id with fields: updates the patient once, shows PatientSummary", async () => {
|
|
92
|
+
// The server reads Ada as she is (born 1/1/90), and answers the update with the date of birth it was given.
|
|
93
|
+
const updated = { ...patient, demographic: { ...patient.demographic, dateOfBirth: "1991-02-03" } };
|
|
94
|
+
const { callNames } = renderPatientCard(
|
|
95
|
+
{ patient: { id: "pat_1", demographic: { dateOfBirth: "1991-02-03" } } },
|
|
96
|
+
undefined,
|
|
97
|
+
{
|
|
98
|
+
UpdatePatient: () => payload("patient", "PatientPayload", updated),
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
102
|
+
expect(await screen.findByText(/2\/3\/91/)).toBeInTheDocument();
|
|
103
|
+
expect(screen.queryByText(/1\/1\/90/)).not.toBeInTheDocument();
|
|
104
|
+
await settle();
|
|
105
|
+
expect(callNames().filter((name) => name === "UpdatePatient")).toHaveLength(1);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Without a patient ID, we attempt to upsert a patient record using the other provided fields.
|
|
110
|
+
// TODO: update implementation it so that any case besides an exact match shows PatientSearch
|
|
111
|
+
describe("initial display for patient reference with no ID", () => {
|
|
112
|
+
it("fields that match a patient: shows its summary", async () => {
|
|
113
|
+
renderPatientCard({ patient: { demographic: { name: { first: "Ada", last: "Lovelace" } } } }, undefined, {
|
|
114
|
+
SyncPatient: () => payload("patient", "PatientPayload", patient),
|
|
115
|
+
});
|
|
116
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// TODO: update implementation it so that any case besides an exact match shows PatientSearch
|
|
120
|
+
it("a name or date of birth that match no one: shows PatientIntakeForm, filled in with the provided fields", async () => {
|
|
121
|
+
renderPatientCard({ patient: { demographic: { name: { first: "Grace", last: "Hopper" } } } }, undefined, {
|
|
122
|
+
SyncPatient: noMatch,
|
|
123
|
+
});
|
|
124
|
+
expect(await screen.findByLabelText("First name")).toHaveValue("Grace");
|
|
125
|
+
expect(screen.getByLabelText("Last name")).toHaveValue("Hopper");
|
|
126
|
+
expect(screen.getByRole("button", { name: "Save patient" })).toBeInTheDocument();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// TODO: update implementation it so that any case besides an exact match shows PatientSearch
|
|
130
|
+
it("a phone or email that match no one: shows an empty PatientSearch", async () => {
|
|
131
|
+
renderPatientCard({ patient: { contact: { phone: "+15555550100" } } }, undefined, { SyncPatient: noMatch });
|
|
132
|
+
expect(await findPatientSearchComponent()).toHaveValue("");
|
|
133
|
+
expect(screen.queryByLabelText("First name")).not.toBeInTheDocument();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// TODO: update implementation it so that any case besides an exact match shows PatientSearch
|
|
137
|
+
it("a phone or email that match multiple candidates: shows an empty PatientSearch, without the candidates", async () => {
|
|
138
|
+
renderPatientCard({ patient: { contact: { phone: "+15555550100" } } }, undefined, {
|
|
139
|
+
SyncPatient: () =>
|
|
140
|
+
ambiguous([
|
|
141
|
+
{ id: "pat_1", firstName: "Ada", lastName: "Lovelace", dateOfBirth: "1990-01-01" },
|
|
142
|
+
{ id: "pat_2", firstName: "Ada", lastName: "Byron", dateOfBirth: "1990-01-01" },
|
|
143
|
+
]),
|
|
144
|
+
});
|
|
145
|
+
expect(await findPatientSearchComponent()).toHaveValue("");
|
|
146
|
+
await settle();
|
|
147
|
+
expect(screen.queryByText("Ada Lovelace")).not.toBeInTheDocument();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("how display changes when the patient prop changes", () => {
|
|
152
|
+
it("nothing, then an id, then nothing again: shows PatientSearch, then PatientSummary, then PatientSearch", async () => {
|
|
153
|
+
const view = renderPatientCard({});
|
|
154
|
+
await findPatientSearchComponent();
|
|
155
|
+
view.rerender(<PatientCard patient="pat_1" />);
|
|
156
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
157
|
+
view.rerender(<PatientCard />);
|
|
158
|
+
expect(await findPatientSearchComponent()).toBeInTheDocument();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("an id, then another id: shows the second patient's summary", async () => {
|
|
162
|
+
const view = renderPatientCard({ patient: "pat_1" }, { pat_1: patient, pat_2: fakePatientGrace });
|
|
163
|
+
await findPatientSummaryComponent();
|
|
164
|
+
view.rerender(<PatientCard patient="pat_2" />);
|
|
165
|
+
expect(await findPatientSummaryComponent(/Grace Hopper/)).toBeInTheDocument();
|
|
166
|
+
expect(screen.queryByRole("heading", { name: /Ada Lovelace/ })).not.toBeInTheDocument();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("an id that doesn't exist, then one that does: shows PatientSummary for the id", async () => {
|
|
170
|
+
const view = renderPatientCard({ patient: "pat_missing" });
|
|
171
|
+
await findPatientSearchComponent();
|
|
172
|
+
view.rerender(<PatientCard patient="pat_1" />);
|
|
173
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
174
|
+
expect(screen.queryByText("Patient not found")).not.toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("fields without an id that match no one, then an id: shows PatientSummary for the id", async () => {
|
|
178
|
+
const view = renderPatientCard(
|
|
179
|
+
{ patient: { demographic: { name: { first: "Grace", last: "Hopper" } } } },
|
|
180
|
+
undefined,
|
|
181
|
+
{
|
|
182
|
+
SyncPatient: noMatch,
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
await screen.findByLabelText("First name");
|
|
186
|
+
view.rerender(<PatientCard patient="pat_1" />);
|
|
187
|
+
expect(await findPatientSummaryComponent()).toBeInTheDocument();
|
|
188
|
+
expect(screen.queryByLabelText("First name")).not.toBeInTheDocument();
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("transitioning between display components", () => {
|
|
193
|
+
/** starts at PatientSearch, types Grace Hopper, chooses Add new patient, fills in the rest of PatientIntakeForm and saves. */
|
|
194
|
+
const addGraceHopper = async (user: UserEvent) => {
|
|
195
|
+
await user.type(await findPatientSearchComponent(), "Grace Hopper");
|
|
196
|
+
await user.click(await screen.findByText("Add new patient"));
|
|
197
|
+
await user.type(await screen.findByLabelText("Date of birth"), "1906-12-09");
|
|
198
|
+
await user.selectOptions(screen.getByRole("combobox", { name: "Sex" }), "FEMALE");
|
|
199
|
+
await user.click(screen.getByRole("button", { name: "Save patient" }));
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
it("Add new patient from PatientSearch: shows PatientIntakeForm, filled in with what was typed", async () => {
|
|
203
|
+
const { user } = renderPatientCard({}, undefined, { SyncPatient: noMatch });
|
|
204
|
+
await user.type(await findPatientSearchComponent(), "Grace Hopper");
|
|
205
|
+
await user.click(await screen.findByText("Add new patient"));
|
|
206
|
+
expect(await screen.findByLabelText("First name")).toHaveValue("Grace");
|
|
207
|
+
expect(screen.getByLabelText("Last name")).toHaveValue("Hopper");
|
|
208
|
+
expect(screen.queryByLabelText("Find patient")).not.toBeInTheDocument();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("Save on PatientIntakeForm, and the server successfully adds the patient: shows PatientSummary for them", async () => {
|
|
212
|
+
const { user } = renderPatientCard({}, undefined, {
|
|
213
|
+
// Searching finds no one; Save (a sync with a sex) adds Grace.
|
|
214
|
+
SyncPatient: (vars: { demographic?: { sex?: string } }) =>
|
|
215
|
+
vars.demographic?.sex ? payload("patient", "PatientPayload", fakePatientGrace) : noMatch(),
|
|
216
|
+
});
|
|
217
|
+
await addGraceHopper(user);
|
|
218
|
+
expect(await findPatientSummaryComponent(/Grace Hopper/)).toBeInTheDocument();
|
|
219
|
+
expect(screen.queryByLabelText("First name")).not.toBeInTheDocument();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("Save on PatientIntakeForm, and the server fails to add the patient: stays on PatientIntakeForm, as filled in", async () => {
|
|
223
|
+
const { user } = renderPatientCard({}, undefined, {
|
|
224
|
+
// Searching finds no one; Save (a sync with a sex) fails.
|
|
225
|
+
SyncPatient: (vars: { demographic?: { sex?: string } }) => {
|
|
226
|
+
if (vars.demographic?.sex) throw new Error("network-api is down");
|
|
227
|
+
return noMatch();
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
await addGraceHopper(user);
|
|
231
|
+
expect(await screen.findByText("network-api is down")).toBeInTheDocument();
|
|
232
|
+
expect(screen.getByLabelText("First name")).toHaveValue("Grace");
|
|
233
|
+
expect(screen.getByLabelText("Last name")).toHaveValue("Hopper");
|
|
234
|
+
expect(screen.queryByLabelText("Find patient")).not.toBeInTheDocument();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// PatientCard remembers that the prescriber chose "Add new patient", and what they typed, so it can show
|
|
238
|
+
// PatientIntakeForm. Saving the patiient doesn't clear that: once the patient has a record, PatientSummary simply wins.
|
|
239
|
+
// So when "Change patient" swaps in a new blank patient, a card that kept that memory might open PatientIntakeForm again,
|
|
240
|
+
// filled in with the patient just added, instead of starting a fresh search for the next one.
|
|
241
|
+
// TODO: revisit code implementation so that this weird case can't happen
|
|
242
|
+
it("Change patient after adding a patient: shows PatientSearch, not the added patient's PatientIntakeForm", async () => {
|
|
243
|
+
const { user } = renderPatientCard({}, undefined, {
|
|
244
|
+
// Searching finds no one; Save (a sync with a sex) adds Grace.
|
|
245
|
+
SyncPatient: (vars: { demographic?: { sex?: string } }) =>
|
|
246
|
+
vars.demographic?.sex ? payload("patient", "PatientPayload", fakePatientGrace) : noMatch(),
|
|
247
|
+
});
|
|
248
|
+
await addGraceHopper(user);
|
|
249
|
+
await findPatientSummaryComponent(/Grace Hopper/);
|
|
250
|
+
await user.click(screen.getByRole("button", { name: "Change patient" }));
|
|
251
|
+
expect(await findPatientSearchComponent()).toBeInTheDocument();
|
|
252
|
+
expect(screen.queryByLabelText("First name")).not.toBeInTheDocument();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|