@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,394 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
alert,
|
|
5
|
+
change,
|
|
6
|
+
fakeNetworkApiClient,
|
|
7
|
+
listedOrder,
|
|
8
|
+
orders,
|
|
9
|
+
payload,
|
|
10
|
+
rx,
|
|
11
|
+
treatment,
|
|
12
|
+
} from "@photonhealth/client/testing";
|
|
13
|
+
import { PhotonOrder, type PhotonOrderProps } from "../index.ts";
|
|
14
|
+
import {
|
|
15
|
+
choices,
|
|
16
|
+
draftOrder,
|
|
17
|
+
option,
|
|
18
|
+
order,
|
|
19
|
+
patient,
|
|
20
|
+
pickDrug,
|
|
21
|
+
signed,
|
|
22
|
+
typeIdentity,
|
|
23
|
+
withPhoton,
|
|
24
|
+
} from "../../test/cards.fixtures.tsx";
|
|
25
|
+
|
|
26
|
+
// The order around its prescriptions: Send, Remove, and a line searched before the order has a patient.
|
|
27
|
+
const lisinoprilTablets10And20Mg = choices(
|
|
28
|
+
option("Lisinopril Oral Tablet 10 MG", "med_10"),
|
|
29
|
+
option("Lisinopril Oral Tablet 20 MG", "med_20"),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
describe("PhotonOrder prescriptions", () => {
|
|
33
|
+
it("a picked product waits for Sign before the order can be sent; Remove leaves a fresh line to search in", async () => {
|
|
34
|
+
const component = renderComponent({
|
|
35
|
+
lookupPrescriptions: lisinoprilTablets10And20Mg,
|
|
36
|
+
script: {
|
|
37
|
+
SyncPrescription: () =>
|
|
38
|
+
payload(
|
|
39
|
+
"prescription",
|
|
40
|
+
"PrescriptionPayload",
|
|
41
|
+
rx({ id: "rx_lis", treatment: { ...rx().treatment, id: "med_10", name: "Lisinopril", ndc: null } }),
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
await component.typeIntoTreatment("lisinopril");
|
|
46
|
+
await pickDrug("Lisinopril Oral Tablet 10 MG");
|
|
47
|
+
await screen.findByLabelText("Directions (sig)");
|
|
48
|
+
// No primary yet: Send waits for Sign.
|
|
49
|
+
expect(document.querySelectorAll('.prx-button[data-variant="primary"]')).toHaveLength(0);
|
|
50
|
+
expect(screen.queryByRole("button", { name: /^Send prescriptions? to patient$/ })).toBeNull();
|
|
51
|
+
|
|
52
|
+
fireEvent.click(screen.getByRole("button", { name: "Remove prescription" }));
|
|
53
|
+
expect((await component.findTreatmentField()).value).toBe("");
|
|
54
|
+
expect(screen.queryByRole("heading", { name: "Lisinopril" })).toBeNull();
|
|
55
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull(); // nothing to take off yet
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("while a line chooses a drug, ⌘↵ doesn't send — the order would go without that line", async () => {
|
|
59
|
+
const component = renderComponent({
|
|
60
|
+
photonOrderProps: { order: "ord_1" },
|
|
61
|
+
lookupPrescriptions: lisinoprilTablets10And20Mg,
|
|
62
|
+
script: {
|
|
63
|
+
GetOrder: () => payload("order", "OrderPayload", order()),
|
|
64
|
+
SubmitOrder: () => payload("order", "OrderPayload", order("SUBMITTED")),
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const send = await screen.findByRole("button", { name: /^Send prescriptions? to patient$/ });
|
|
68
|
+
await waitFor(() => expect(send).toHaveProperty("disabled", false)); // the one line is signed
|
|
69
|
+
|
|
70
|
+
fireEvent.click(screen.getByRole("button", { name: "Add another prescription" }));
|
|
71
|
+
const meds = await screen.findAllByLabelText("Treatment");
|
|
72
|
+
fireEvent.change(meds.at(-1)!, { target: { value: "lisinopril" } });
|
|
73
|
+
await screen.findByRole("list", { name: "Pick a treatment" });
|
|
74
|
+
expect(screen.queryByRole("button", { name: /^Send prescriptions? to patient$/ })).toBeNull();
|
|
75
|
+
fireEvent.keyDown(window, { key: "Enter", metaKey: true });
|
|
76
|
+
fireEvent.keyDown(window, { key: "Enter", ctrlKey: true });
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 0)); // a send would have started by now
|
|
78
|
+
expect(component.names()).not.toContain("SubmitOrder");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("searches drugs before a patient is set (never drafts), then attaches the pick once a patient is chosen", async () => {
|
|
82
|
+
const metformin = payload("prescription", "PrescriptionPayload", null, {
|
|
83
|
+
changes: [
|
|
84
|
+
// Expected without a patient, and not shown.
|
|
85
|
+
change({
|
|
86
|
+
key: "patient",
|
|
87
|
+
label: "Patient",
|
|
88
|
+
status: "REJECTED",
|
|
89
|
+
severity: "BLOCKING",
|
|
90
|
+
reason: "patient is required.",
|
|
91
|
+
}),
|
|
92
|
+
change({
|
|
93
|
+
status: "AMBIGUOUS",
|
|
94
|
+
severity: "BLOCKING",
|
|
95
|
+
category: "DISAMBIGUATION",
|
|
96
|
+
options: [
|
|
97
|
+
option("metFORMIN HCl Oral Tablet 500 MG", "med_met500"),
|
|
98
|
+
option("metFORMIN HCl Oral Tablet 1000 MG", "med_met1000"),
|
|
99
|
+
],
|
|
100
|
+
}),
|
|
101
|
+
],
|
|
102
|
+
} as never);
|
|
103
|
+
const component = renderComponent({
|
|
104
|
+
photonOrderProps: {},
|
|
105
|
+
lookupPrescriptions: metformin,
|
|
106
|
+
script: {
|
|
107
|
+
SyncPatient: () => ({
|
|
108
|
+
patient: {
|
|
109
|
+
__typename: "AmbiguousPatientMatch",
|
|
110
|
+
reason: "weak",
|
|
111
|
+
candidates: [{ id: "pat_1", firstName: "Ada", lastName: "Lovelace", dateOfBirth: "1990-01-01" }],
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
SyncPrescription: () => payload("prescription", "PrescriptionPayload", rx({ id: "rx_attached" })),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// No patient yet — the line is already there and searches.
|
|
119
|
+
const med = await component.findTreatmentField();
|
|
120
|
+
expect(screen.queryByLabelText("Quantity")).toBeNull(); // dispense details wait for a drug
|
|
121
|
+
expect(screen.queryByLabelText("Directions (sig)")).toBeNull();
|
|
122
|
+
expect(screen.queryByRole("button", { name: "Add another prescription" })).toBeNull(); // not until it has a drug
|
|
123
|
+
fireEvent.change(med, { target: { value: "metformin" } });
|
|
124
|
+
fireEvent.keyDown(med, { key: "Enter" });
|
|
125
|
+
await pickDrug("metFORMIN HCl Oral Tablet 500 MG");
|
|
126
|
+
expect(await screen.findByRole("heading", { name: "metFORMIN HCl" })).toBeTruthy();
|
|
127
|
+
expect(screen.queryByText("patient is required.")).toBeNull();
|
|
128
|
+
expect(screen.getByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
129
|
+
// Directions (sig), then quantity / unit / days / refills, then DAW.
|
|
130
|
+
const [sig, qty, daw] = ["Directions (sig)", "Quantity", "Dispense as written"].map((l) =>
|
|
131
|
+
screen.getByLabelText(l),
|
|
132
|
+
);
|
|
133
|
+
expect(sig!.compareDocumentPosition(qty!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
134
|
+
expect(qty!.compareDocumentPosition(daw!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
135
|
+
|
|
136
|
+
fireEvent.change(sig!, { target: { value: "1 tab PO BID" } });
|
|
137
|
+
fireEvent.blur(sig!);
|
|
138
|
+
expect(component.wasPrescriptionDrafted()).toBe(false); // nothing drafted without a patient
|
|
139
|
+
|
|
140
|
+
await typeIdentity("Ada", "Lovelace", "1990-01-01");
|
|
141
|
+
fireEvent.click(await screen.findByRole("option", { name: /Ada Lovelace/ }));
|
|
142
|
+
expect(await component.waitForDraftedPrescription()).toMatchObject({
|
|
143
|
+
patient: { id: "pat_1" },
|
|
144
|
+
treatment: { id: "med_met500" },
|
|
145
|
+
instructions: "1 tab PO BID",
|
|
146
|
+
});
|
|
147
|
+
expect(component.calls.filter((c) => c.name === "LookupPrescription").every((c) => !("patient" in c.vars))).toBe(
|
|
148
|
+
true,
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("PhotonOrder and the patient's draft order", () => {
|
|
154
|
+
const metoprolol = rx({ id: "rx_9", treatment: treatment({ id: "trt_9", name: "Metoprolol Tartrate" }) });
|
|
155
|
+
const withDraft: NetworkScript = {
|
|
156
|
+
Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [metoprolol] })]),
|
|
157
|
+
GetOrder: () => payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [metoprolol] }),
|
|
158
|
+
GetPrescription: () => payload("prescription", "PrescriptionPayload", metoprolol),
|
|
159
|
+
UpdateOrder: () => payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [] }),
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
it("shows the draft's prescriptions read-only and asks first; Continue makes them the order's lines", async () => {
|
|
163
|
+
const component = renderComponent({ script: withDraft });
|
|
164
|
+
expect(await screen.findByText("Would you like to continue this order?")).toBeTruthy();
|
|
165
|
+
expect(screen.getByRole("heading", { name: "Metoprolol Tartrate" })).toBeTruthy();
|
|
166
|
+
expect(screen.queryByLabelText("Treatment")).toBeNull(); // nothing to write in until the prescriber decides
|
|
167
|
+
expect(screen.queryByRole("button", { name: "Remove prescription" })).toBeNull();
|
|
168
|
+
|
|
169
|
+
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
|
|
170
|
+
// The draft as it is, with a way to add to it — no empty line in the way.
|
|
171
|
+
expect(await screen.findByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
172
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
173
|
+
expect(screen.getByRole("heading", { name: "Metoprolol Tartrate" })).toBeTruthy();
|
|
174
|
+
expect(screen.queryByLabelText("Treatment")).toBeNull();
|
|
175
|
+
expect(component.names()).toContain("GetOrder");
|
|
176
|
+
expect(component.names()).not.toContain("SyncOrder");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("a continued draft whose prescriptions are signed can be sent as it is", async () => {
|
|
180
|
+
const signedMetoprolol = { ...metoprolol, signing: { ...metoprolol.signing, state: "SIGNED" as const } };
|
|
181
|
+
renderComponent({
|
|
182
|
+
script: {
|
|
183
|
+
...withDraft,
|
|
184
|
+
Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [signedMetoprolol] })]),
|
|
185
|
+
GetOrder: () =>
|
|
186
|
+
payload("order", "OrderPayload", { ...order(), id: "ord_9", prescriptions: [signedMetoprolol] }),
|
|
187
|
+
GetPrescription: () => payload("prescription", "PrescriptionPayload", signedMetoprolol),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
fireEvent.click(await screen.findByRole("button", { name: "Continue" }));
|
|
191
|
+
expect(await screen.findByRole("button", { name: "Send prescription to patient" })).toBeTruthy();
|
|
192
|
+
expect(screen.getByRole("button", { name: "Add another prescription" })).toBeTruthy();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("a draft with no prescriptions isn't shown: the order starts with its empty line", async () => {
|
|
196
|
+
const component = renderComponent({
|
|
197
|
+
script: { ...withDraft, Orders: () => orders([listedOrder({ id: "ord_9", prescriptions: [] })]) },
|
|
198
|
+
});
|
|
199
|
+
await component.findTreatmentField();
|
|
200
|
+
await waitFor(() => expect(component.names()).toContain("Orders"));
|
|
201
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("Start a new order empties the draft and goes on with an empty line", async () => {
|
|
205
|
+
const component = renderComponent({ script: withDraft });
|
|
206
|
+
fireEvent.click(await screen.findByRole("button", { name: "Start a new order" }));
|
|
207
|
+
await component.findTreatmentField();
|
|
208
|
+
expect(screen.queryByText("Would you like to continue this order?")).toBeNull();
|
|
209
|
+
expect(screen.queryByRole("heading", { name: "Metoprolol Tartrate" })).toBeNull();
|
|
210
|
+
expect(component.calls.find((c) => c.op === "UpdateOrder")?.vars).toMatchObject({ prescriptions: { none: true } });
|
|
211
|
+
expect(component.names()).not.toContain("GetOrder");
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("PhotonOrder: screening alerts before Send", () => {
|
|
216
|
+
const interactionBetweenPrescriptions = {
|
|
217
|
+
...alert,
|
|
218
|
+
type: "DRUG" as const,
|
|
219
|
+
severity: "MAJOR" as const,
|
|
220
|
+
description: "Increases the risk of bleeding.",
|
|
221
|
+
involvedEntities: [{ __typename: "InvolvedEntity" as const, id: "med_2", name: "warfarin" }],
|
|
222
|
+
};
|
|
223
|
+
const unsignedWithAllergy = rx({ id: "rx_unsigned", screeningAlerts: [alert] });
|
|
224
|
+
const signedWithAllergy = { ...signed, screeningAlerts: [alert] };
|
|
225
|
+
|
|
226
|
+
it("an interaction between the order's signed prescriptions shows above Send", async () => {
|
|
227
|
+
renderOrderWithAlerts({ prescriptions: [signed], screeningAlerts: [interactionBetweenPrescriptions] });
|
|
228
|
+
const send = await findSend();
|
|
229
|
+
const alertTitle = await screen.findByText("drug · major");
|
|
230
|
+
expect(alertTitle.compareDocumentPosition(send) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
231
|
+
expect(screen.getByText("Increases the risk of bleeding. (warfarin)")).toBeInTheDocument();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("Send goes straight to the patient with an alert showing, without asking for confirmation", async () => {
|
|
235
|
+
const component = renderOrderWithAlerts({
|
|
236
|
+
prescriptions: [signed],
|
|
237
|
+
screeningAlerts: [interactionBetweenPrescriptions],
|
|
238
|
+
});
|
|
239
|
+
await screen.findByText("drug · major");
|
|
240
|
+
const send = await findSend();
|
|
241
|
+
await waitFor(() => expect(send).toBeEnabled());
|
|
242
|
+
|
|
243
|
+
fireEvent.click(send);
|
|
244
|
+
|
|
245
|
+
await waitFor(() => expect(component.names()).toContain("SubmitOrder"));
|
|
246
|
+
expect(screen.queryByRole("dialog")).toBeNull();
|
|
247
|
+
expect(screen.queryByRole("alertdialog")).toBeNull();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("an alert a signed prescription carries isn't shown: its signature acknowledged it", async () => {
|
|
251
|
+
renderOrderWithAlerts({ prescriptions: [signedWithAllergy], screeningAlerts: [] });
|
|
252
|
+
await findSend();
|
|
253
|
+
expect(screen.queryByText("allergen · moderate")).toBeNull();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("an alert the order repeats from a signed prescription isn't shown either", async () => {
|
|
257
|
+
renderOrderWithAlerts({ prescriptions: [signedWithAllergy], screeningAlerts: [alert] });
|
|
258
|
+
await findSend();
|
|
259
|
+
expect(screen.queryByText("allergen · moderate")).toBeNull();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("reopening a draft order whose two signed prescriptions interact shows no alert, though each prescription and the order all report it", async () => {
|
|
263
|
+
const levonorgestrel = treatment({ id: "med_levonorgestrel", name: "Levonorgestrel" });
|
|
264
|
+
const ella = treatment({ id: "med_ella", name: "Ella" });
|
|
265
|
+
const ulipristalInteraction = {
|
|
266
|
+
...alert,
|
|
267
|
+
type: "DRUG" as const,
|
|
268
|
+
severity: "MAJOR" as const,
|
|
269
|
+
description: "Ulipristal may decrease the effectiveness of progestins.",
|
|
270
|
+
involvedEntities: [ella, levonorgestrel].map(({ id, name }) => ({
|
|
271
|
+
__typename: "InvolvedEntity" as const,
|
|
272
|
+
id,
|
|
273
|
+
name,
|
|
274
|
+
})),
|
|
275
|
+
};
|
|
276
|
+
const signedAndInteracting = (id: string, drug: typeof ella) => ({
|
|
277
|
+
...signed,
|
|
278
|
+
id,
|
|
279
|
+
treatment: drug,
|
|
280
|
+
screeningAlerts: [ulipristalInteraction],
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
renderOrderWithAlerts({
|
|
284
|
+
prescriptions: [signedAndInteracting("rx_levonorgestrel", levonorgestrel), signedAndInteracting("rx_ella", ella)],
|
|
285
|
+
screeningAlerts: [ulipristalInteraction],
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const send = await screen.findByRole("button", { name: "Send prescriptions to patient" });
|
|
289
|
+
await waitFor(() => expect(send).toBeEnabled());
|
|
290
|
+
expect(screen.getByRole("heading", { name: "Levonorgestrel" })).toBeInTheDocument();
|
|
291
|
+
expect(screen.getByRole("heading", { name: "Ella" })).toBeInTheDocument();
|
|
292
|
+
expect(screen.queryByText("drug · major")).toBeNull();
|
|
293
|
+
expect(screen.queryByText(/Ulipristal may decrease/)).toBeNull();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("an unsigned prescription's alert shows once, on that prescription's card", async () => {
|
|
297
|
+
renderOrderWithAlerts({ prescriptions: [signed, unsignedWithAllergy], screeningAlerts: [] });
|
|
298
|
+
await screen.findAllByText("allergen · moderate");
|
|
299
|
+
await screen.findByRole("button", { name: "Sign" });
|
|
300
|
+
expectAlertOnPrescriptionCards("allergen · moderate", 1);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("an unsigned prescription with an alert keeps Send away until it is signed", async () => {
|
|
304
|
+
renderOrderWithAlerts({ prescriptions: [signed, unsignedWithAllergy], screeningAlerts: [] });
|
|
305
|
+
await screen.findAllByText("allergen · moderate");
|
|
306
|
+
expect(screen.getByRole("button", { name: "Sign" })).toBeEnabled();
|
|
307
|
+
expect(screen.queryByRole("button", { name: /^Send prescriptions? to patient$/ })).toBeNull();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("order screening that failed on the server shows no alerts, the same as a clean screening", async () => {
|
|
311
|
+
renderOrderWithAlerts({ prescriptions: [signed], screeningAlerts: null });
|
|
312
|
+
await findSend();
|
|
313
|
+
expect(screen.queryByText(/^(allergen|drug|condition) · /)).toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
type NetworkScript = Parameters<typeof fakeNetworkApiClient>[0];
|
|
318
|
+
|
|
319
|
+
type RenderComponentOptions = {
|
|
320
|
+
photonOrderProps?: PhotonOrderProps;
|
|
321
|
+
lookupPrescriptions?: unknown;
|
|
322
|
+
script?: NetworkScript;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
function renderComponent({
|
|
326
|
+
photonOrderProps = { patient: "pat_1" },
|
|
327
|
+
lookupPrescriptions = null,
|
|
328
|
+
script = {},
|
|
329
|
+
}: RenderComponentOptions = {}) {
|
|
330
|
+
const { client, calls, names } = fakeNetworkApiClient({
|
|
331
|
+
...draftOrder(),
|
|
332
|
+
GetPatient: () => payload("patient", "PatientPayload", patient),
|
|
333
|
+
LookupPrescription: () => lookupPrescriptions,
|
|
334
|
+
SyncPrescription: () => payload("prescription", "PrescriptionPayload", rx({ id: "rx_1" })),
|
|
335
|
+
...script,
|
|
336
|
+
});
|
|
337
|
+
render(<PhotonOrder {...photonOrderProps} />, { wrapper: withPhoton(client) });
|
|
338
|
+
|
|
339
|
+
const findTreatmentField = () => screen.findByLabelText("Treatment") as Promise<HTMLInputElement>;
|
|
340
|
+
return {
|
|
341
|
+
calls,
|
|
342
|
+
names,
|
|
343
|
+
findTreatmentField,
|
|
344
|
+
typeIntoTreatment: async (text: string) => {
|
|
345
|
+
const med = await findTreatmentField();
|
|
346
|
+
med.focus();
|
|
347
|
+
fireEvent.change(med, { target: { value: text } });
|
|
348
|
+
return med;
|
|
349
|
+
},
|
|
350
|
+
wasPrescriptionDrafted: () => names().includes("SyncPrescription"),
|
|
351
|
+
waitForDraftedPrescription: async () => {
|
|
352
|
+
await waitFor(() => expect(names()).toContain("SyncPrescription"));
|
|
353
|
+
return calls.find((c) => c.name === "SyncPrescription")!.vars;
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
type FakePrescription = ReturnType<typeof rx>;
|
|
359
|
+
|
|
360
|
+
function renderOrderWithAlerts({
|
|
361
|
+
prescriptions,
|
|
362
|
+
screeningAlerts,
|
|
363
|
+
}: {
|
|
364
|
+
prescriptions: FakePrescription[];
|
|
365
|
+
screeningAlerts: FakePrescription["screeningAlerts"];
|
|
366
|
+
}) {
|
|
367
|
+
const orderWithAlerts = (state?: string) => ({ ...order(state), prescriptions, screeningAlerts });
|
|
368
|
+
return renderComponent({
|
|
369
|
+
photonOrderProps: { order: "ord_1" },
|
|
370
|
+
script: {
|
|
371
|
+
GetOrder: () => payload("order", "OrderPayload", orderWithAlerts()),
|
|
372
|
+
GetPrescription: ({ id }: { id: string }) =>
|
|
373
|
+
payload(
|
|
374
|
+
"prescription",
|
|
375
|
+
"PrescriptionPayload",
|
|
376
|
+
prescriptions.find((prescription) => prescription.id === id) ?? null,
|
|
377
|
+
),
|
|
378
|
+
SubmitOrder: () => payload("order", "OrderPayload", orderWithAlerts("SUBMITTED")),
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function findSend() {
|
|
384
|
+
return screen.findByRole("button", { name: /^Send prescriptions? to patient$/ });
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function expectAlertOnPrescriptionCards(alertTitle: string, prescriptionCardsCarryingIt: number) {
|
|
388
|
+
const shown = screen.getAllByText(alertTitle);
|
|
389
|
+
expect(shown).toHaveLength(prescriptionCardsCarryingIt);
|
|
390
|
+
const endOfPrescriptionCards = screen.getByRole("button", { name: "Add another prescription" });
|
|
391
|
+
shown.forEach((alertShown) =>
|
|
392
|
+
expect(alertShown.compareDocumentPosition(endOfPrescriptionCards) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(),
|
|
393
|
+
);
|
|
394
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useComponents, usePhoton } from "../primitives/index.ts";
|
|
2
|
+
import { AnalyticsWorkflow, usePhotonAnalytics } from "../analytics/PhotonAnalyticsProvider.tsx";
|
|
3
|
+
import { viewedPropertiesFromCardProps } from "../analytics/viewed.ts";
|
|
2
4
|
import { SignedIn } from "./SignedIn.tsx";
|
|
3
5
|
import {
|
|
4
6
|
asksForAddress,
|
|
@@ -13,35 +15,37 @@ import {
|
|
|
13
15
|
import { useLive, useOnChange } from "../hooks/index.ts";
|
|
14
16
|
import { useEffect, useRef, useState } from "react";
|
|
15
17
|
import { displayName } from "./format.ts";
|
|
16
|
-
import { callFor, NotFound, openFailed, openGiven, shared, toOpen
|
|
17
|
-
import { PatientCard } from "./
|
|
18
|
-
import {
|
|
18
|
+
import { callFor, NotFound, openFailed, openGiven, shared, toOpen } from "./open.ts";
|
|
19
|
+
import { PatientCard } from "./patient/PatientCard/PatientCard.tsx";
|
|
20
|
+
import { PrescriptionCard } from "./prescription/PrescriptionCard.tsx";
|
|
21
|
+
import { DraftOrderPrompt } from "./order/DraftOrderPrompt.tsx";
|
|
19
22
|
import { ScreeningAlerts } from "./ScreeningAlerts.tsx";
|
|
20
23
|
import { SearchResults } from "./search.tsx";
|
|
21
24
|
import { cardFlowKeys, cardProps, focusProps } from "./flow.ts";
|
|
22
25
|
|
|
23
|
-
/**
|
|
24
|
-
* The order is the treatment: who it's for, their prescriptions, and sending them — on one card, bound to a
|
|
25
|
-
* live Order from @photonhealth/client: the one given (live, used as given; or opened from what's given, see `Given`),
|
|
26
|
-
* else a new order for the patient given, or for someone to find or add. The rules are the objects'; this renders
|
|
27
|
-
* them, plus what's only about the screen: which line is focused, and the Sent summary. Send shows once the order
|
|
28
|
-
* is ready and everything is saved.
|
|
29
|
-
*
|
|
30
|
-
* It renders only cards: no page, landmark or app chrome, so it sits in a page, a dialog or a side panel.
|
|
31
|
-
*/
|
|
32
26
|
export interface PhotonOrderProps {
|
|
33
27
|
/**
|
|
34
|
-
* The order
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
28
|
+
* The order, one of:
|
|
29
|
+
* - a live `Order`: used as is
|
|
30
|
+
* - its id, `"ord_…"` or `{ id }`: gets the order
|
|
31
|
+
* - its id with fields, `{ id, … }`: updates the order (e.g. prescriptions added)
|
|
32
|
+
* - fields without an id: upserts the order, e.g.
|
|
33
|
+
* `{ patient: { id }, prescriptions: { add: [{ templateId: "tmp_…" }, { id: "rx_…" }] } }` — new lines from
|
|
34
|
+
* a template and existing prescriptions (the order takes their patient)
|
|
35
|
+
*
|
|
36
|
+
* Without prescriptions, it starts with one empty line.
|
|
38
37
|
*/
|
|
39
|
-
order?: Order |
|
|
38
|
+
order?: Order | OrderInput | string | null;
|
|
40
39
|
/**
|
|
41
|
-
* Who a new order is for, when `order` doesn't say
|
|
42
|
-
*
|
|
40
|
+
* Who a new order is for, when `order` doesn't say, one of:
|
|
41
|
+
* - a live `Patient`: used as is
|
|
42
|
+
* - its id, `"pat_…"` or `{ id }`: gets the patient
|
|
43
|
+
* - its id with fields, `{ id, … }`: updates the patient
|
|
44
|
+
* - fields without an id: upserts the patient
|
|
45
|
+
*
|
|
46
|
+
* Without one, someone to find or add.
|
|
43
47
|
*/
|
|
44
|
-
patient?: Patient |
|
|
48
|
+
patient?: Patient | PatientInput | string | null;
|
|
45
49
|
/**
|
|
46
50
|
* The order's patient, once it has a record and each time that record changes from the backend; `null` on
|
|
47
51
|
* "Change patient".
|
|
@@ -79,9 +83,11 @@ const orderRecords = (order: Order) => {
|
|
|
79
83
|
|
|
80
84
|
export function PhotonOrder(props: PhotonOrderProps) {
|
|
81
85
|
return (
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
|
|
86
|
+
<AnalyticsWorkflow card="PhotonOrder" viewedProperties={viewedPropertiesFromCardProps(props)}>
|
|
87
|
+
<SignedIn>
|
|
88
|
+
<OrderCard {...props} />
|
|
89
|
+
</SignedIn>
|
|
90
|
+
</AnalyticsWorkflow>
|
|
85
91
|
);
|
|
86
92
|
}
|
|
87
93
|
|
|
@@ -117,7 +123,7 @@ function OrderCard(props: PhotonOrderProps) {
|
|
|
117
123
|
useEffect(() => {
|
|
118
124
|
if (sharedOrder) return;
|
|
119
125
|
let live = true;
|
|
120
|
-
const [wanted, forPatient] = JSON.parse(key) as [
|
|
126
|
+
const [wanted, forPatient] = JSON.parse(key) as [OrderInput | string | null, PatientInput | string | null];
|
|
121
127
|
// Shared while it's in flight: StrictMode runs this twice, and a new order's draft is saved as it opens.
|
|
122
128
|
shared(sharedPatient ?? ph, key, async () => {
|
|
123
129
|
const opening = wanted ? callFor(wanted) : null;
|
|
@@ -195,6 +201,7 @@ function OrderView({
|
|
|
195
201
|
}) {
|
|
196
202
|
const { Alert, Button, Stack } = useComponents();
|
|
197
203
|
const ph = usePhoton();
|
|
204
|
+
const analytics = usePhotonAnalytics();
|
|
198
205
|
const snap = useLive(order)!;
|
|
199
206
|
const final = order.final;
|
|
200
207
|
const [sentHere, setSentHere] = useState(false);
|
|
@@ -232,6 +239,14 @@ function OrderView({
|
|
|
232
239
|
);
|
|
233
240
|
};
|
|
234
241
|
|
|
242
|
+
const removeLine = (line: Prescription, removal: OrderUpdate) => {
|
|
243
|
+
const removedId = line.id;
|
|
244
|
+
void change(order, removal).then((saved) => {
|
|
245
|
+
const removed = Boolean(saved) && !order.prescriptions.includes(line);
|
|
246
|
+
if (removed && removedId) void analytics.draftPrescriptionDeleted(removedId);
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
|
|
235
250
|
const flow = useRef<HTMLDivElement>(null);
|
|
236
251
|
// ← / → move between the cards: the patient, each prescription, "Add another", Send (flow.ts).
|
|
237
252
|
return (
|
|
@@ -242,8 +257,8 @@ function OrderView({
|
|
|
242
257
|
<div {...cardProps}>
|
|
243
258
|
<PatientCard
|
|
244
259
|
patient={patient}
|
|
245
|
-
|
|
246
|
-
|
|
260
|
+
readOnly={final} // a sent order's patient is read-only
|
|
261
|
+
hideChangePatient={handoff}
|
|
247
262
|
addressRequest={final ? null : snap.contactRequest}
|
|
248
263
|
notFound={snap.patient?.id ? null : missingPatient}
|
|
249
264
|
onPatient={(next) => {
|
|
@@ -274,31 +289,41 @@ function OrderView({
|
|
|
274
289
|
</div>
|
|
275
290
|
)}
|
|
276
291
|
|
|
277
|
-
{
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
292
|
+
{!final && snap.draft && (
|
|
293
|
+
// The patient's draft order, found when they were chosen: shown as it is until the prescriber decides.
|
|
294
|
+
<DraftOrderPrompt
|
|
295
|
+
draft={snap.draft}
|
|
296
|
+
onContinue={() => order.continueDraft()}
|
|
297
|
+
onStartNew={() => order.startNew()}
|
|
298
|
+
/>
|
|
299
|
+
)}
|
|
300
|
+
|
|
301
|
+
{!snap.draft &&
|
|
302
|
+
lines.map((line) => (
|
|
303
|
+
<div key={keyOf(line)} {...cardProps}>
|
|
304
|
+
<PrescriptionCard
|
|
305
|
+
prescription={line}
|
|
306
|
+
locked={final} // a signed line is read-only on its own
|
|
307
|
+
// A line comes off; the only one, once it has a drug, gives way to a fresh line (a different drug).
|
|
308
|
+
onRemove={
|
|
309
|
+
final
|
|
310
|
+
? undefined
|
|
311
|
+
: lines.length > 1
|
|
312
|
+
? () => removeLine(line, { prescriptions: { remove: [line] } })
|
|
313
|
+
: filled(line)
|
|
314
|
+
? () => {
|
|
315
|
+
removeLine(line, { prescriptions: { remove: [line], add: [{ templateId }] } });
|
|
316
|
+
setAdded(order.prescriptions.at(-1) ?? null); // the fresh line, at once
|
|
317
|
+
}
|
|
318
|
+
: undefined
|
|
319
|
+
}
|
|
320
|
+
autoFocus={line === added}
|
|
321
|
+
focusSignal={focus?.line === line ? focus.signal : undefined}
|
|
322
|
+
/>
|
|
323
|
+
</div>
|
|
324
|
+
))}
|
|
300
325
|
|
|
301
|
-
{!final && allFilled && (
|
|
326
|
+
{!final && !snap.draft && allFilled && (
|
|
302
327
|
<div data-prx-card="">
|
|
303
328
|
<span {...focusProps}>
|
|
304
329
|
<Button
|
|
@@ -323,6 +348,7 @@ function OrderView({
|
|
|
323
348
|
ready={order.readyToSend}
|
|
324
349
|
onSubmitted={() => {
|
|
325
350
|
setSentHere(true);
|
|
351
|
+
if (order.state) void analytics.orderSent(order.state);
|
|
326
352
|
events.onSent?.(order);
|
|
327
353
|
}}
|
|
328
354
|
/>
|
|
@@ -403,7 +429,7 @@ function SendSection({
|
|
|
403
429
|
Sent
|
|
404
430
|
</Badge>
|
|
405
431
|
</Row>
|
|
406
|
-
{record.exceptions.map((x) => (
|
|
432
|
+
{record.fulfillment?.exceptions.map((x) => (
|
|
407
433
|
<Alert
|
|
408
434
|
key={x.id}
|
|
409
435
|
tone="warning"
|
|
@@ -424,7 +450,7 @@ function SendSection({
|
|
|
424
450
|
const contact = Boolean(snap.contactRequest);
|
|
425
451
|
const failure = snap.error;
|
|
426
452
|
const showSend = ready || sending;
|
|
427
|
-
//
|
|
453
|
+
// The order's alerts no prescription carries, before Send.
|
|
428
454
|
const alerts = order.unacknowledgedAlerts;
|
|
429
455
|
if (!alerts.length && !notSent.length && !notSaved.length && !failure && !showSend) return null;
|
|
430
456
|
return (
|
|
@@ -479,7 +505,7 @@ function SendSection({
|
|
|
479
505
|
* when something else explains why it wasn't sent (network-api adds "a sibling change was rejected").
|
|
480
506
|
*/
|
|
481
507
|
function reasons(unapplied: readonly Change[]): Change[] {
|
|
482
|
-
const own = unapplied.filter((c) => !c.key.startsWith("patient.
|
|
508
|
+
const own = unapplied.filter((c) => !c.key.startsWith("patient.contact."));
|
|
483
509
|
const explained = own.some((c) => c.key !== "state") || own.length < unapplied.length;
|
|
484
510
|
return explained ? own.filter((c) => c.key !== "state") : own;
|
|
485
511
|
}
|