@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,78 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { Change, Changes } from "@photonhealth/client";
|
|
3
|
+
import { draftedNewPrescription, patientWriteOutcome } from "./lifecycleOutcomes.ts";
|
|
4
|
+
|
|
5
|
+
describe("patientWriteOutcome: which lifecycle event a patient write is", () => {
|
|
6
|
+
it("a patient without a record whose first name was added is created", () => {
|
|
7
|
+
const changes = changesWith({ applied: [applied("demographic.name.first", "ADDED")] });
|
|
8
|
+
expect(patientWriteOutcome({ hadRecord: false, changes })).toBe("created");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("a patient that already had a record is updated, even when a first name is added", () => {
|
|
12
|
+
const changes = changesWith({ applied: [applied("demographic.name.first", "ADDED")] });
|
|
13
|
+
expect(patientWriteOutcome({ hadRecord: true, changes })).toBe("updated");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("a patient found rather than added, with a field filled in, is updated", () => {
|
|
17
|
+
const changes = changesWith({ applied: [applied("contact.phone", "ADDED")] });
|
|
18
|
+
expect(patientWriteOutcome({ hadRecord: false, changes })).toBe("updated");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("a first name added alongside a rejected field is updated, not created", () => {
|
|
22
|
+
const changes = changesWith({
|
|
23
|
+
applied: [applied("demographic.name.first", "ADDED")],
|
|
24
|
+
unapplied: [{ ...applied("contact.phone", "ADDED"), status: "REJECTED" }],
|
|
25
|
+
});
|
|
26
|
+
expect(patientWriteOutcome({ hadRecord: false, changes })).toBe("updated");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("a write the server applied nothing from is unchanged", () => {
|
|
30
|
+
expect(patientWriteOutcome({ hadRecord: true, changes: changesWith({}) })).toBe("unchanged");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("draftedNewPrescription: whether a prescription's record is a new draft", () => {
|
|
35
|
+
it("is true when its treatment was added", () => {
|
|
36
|
+
expect(draftedNewPrescription(changesWith({ applied: [applied("treatment", "ADDED")] }))).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("is false for a draft that was continued: its treatment was already there", () => {
|
|
40
|
+
expect(draftedNewPrescription(changesWith({ applied: [applied("instructions", "MODIFIED")] }))).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("is false when the server rejected something in the same write", () => {
|
|
44
|
+
const changes = changesWith({
|
|
45
|
+
applied: [applied("treatment", "ADDED")],
|
|
46
|
+
unapplied: [{ ...applied("dispense.quantity", "ADDED"), status: "REJECTED" }],
|
|
47
|
+
});
|
|
48
|
+
expect(draftedNewPrescription(changes)).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("is true alongside an advisory the server applied anyway", () => {
|
|
52
|
+
const changes = changesWith({
|
|
53
|
+
applied: [applied("treatment", "ADDED")],
|
|
54
|
+
unapplied: [{ ...applied("clinical.screeningAlerts", "ADDED"), severity: "ADVISORY" }],
|
|
55
|
+
});
|
|
56
|
+
expect(draftedNewPrescription(changes)).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function changesWith({ applied = [], unapplied = [] }: Partial<Changes>): Changes {
|
|
61
|
+
return { applied, unapplied };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function applied(key: string, operation: Change["operation"]): Change {
|
|
65
|
+
return {
|
|
66
|
+
key,
|
|
67
|
+
label: key,
|
|
68
|
+
status: "APPLIED",
|
|
69
|
+
severity: "INFO",
|
|
70
|
+
reason: null,
|
|
71
|
+
category: null,
|
|
72
|
+
operation,
|
|
73
|
+
options: [],
|
|
74
|
+
after: null,
|
|
75
|
+
inputText: null,
|
|
76
|
+
resolvedId: null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Changes } from "@photonhealth/client";
|
|
2
|
+
|
|
3
|
+
export type PatientWriteOutcome = "created" | "updated" | "unchanged";
|
|
4
|
+
|
|
5
|
+
export function patientWriteOutcome({
|
|
6
|
+
hadRecord,
|
|
7
|
+
changes,
|
|
8
|
+
}: {
|
|
9
|
+
hadRecord: boolean;
|
|
10
|
+
changes: Changes;
|
|
11
|
+
}): PatientWriteOutcome {
|
|
12
|
+
if (!changes.applied.length) return "unchanged";
|
|
13
|
+
return !hadRecord && addedWithNothingRejected(changes, FIELD_ONLY_A_NEW_PATIENT_ADDS) ? "created" : "updated";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function draftedNewPrescription(changes: Changes): boolean {
|
|
17
|
+
return addedWithNothingRejected(changes, FIELD_ONLY_A_NEW_PRESCRIPTION_ADDS);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const FIELD_ONLY_A_NEW_PATIENT_ADDS = "demographic.name.first";
|
|
21
|
+
const FIELD_ONLY_A_NEW_PRESCRIPTION_ADDS = "treatment";
|
|
22
|
+
|
|
23
|
+
function addedWithNothingRejected(changes: Changes, key: string): boolean {
|
|
24
|
+
const nothingRejected = changes.unapplied.every((change) => change.status === "APPLIED");
|
|
25
|
+
const added = changes.applied.some(
|
|
26
|
+
(change) => change.key === key && change.status === "APPLIED" && change.operation === "ADDED",
|
|
27
|
+
);
|
|
28
|
+
return nothingRejected && added;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { environmentUrls, type Photon } from "@photonhealth/client";
|
|
3
|
+
import { fakeNetworkApiClient, photonOver } from "@photonhealth/client/testing";
|
|
4
|
+
import { MAX_QUEUED_EVENTS, Tracker } from "./tracker.ts";
|
|
5
|
+
|
|
6
|
+
// Sending — the token, providerId, analytics-api — is @photonhealth/client's (`ph.analytics.track`, its
|
|
7
|
+
// src/analytics/track.test.ts). The Tracker only holds events until the sign-in is accepted.
|
|
8
|
+
|
|
9
|
+
const photonWithTrackSpy = () => {
|
|
10
|
+
const ph = photonOver(fakeNetworkApiClient({}).client, environmentUrls("boson"), {
|
|
11
|
+
analytics: { url: "https://analytics-api.boson.health", token: async () => "tok", clientName: null },
|
|
12
|
+
});
|
|
13
|
+
const track = vi.spyOn(ph.analytics!, "track").mockResolvedValue();
|
|
14
|
+
return { ph, track };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const event = (n: number) => `Event ${String.fromCharCode(65 + (n % 26))}`;
|
|
18
|
+
|
|
19
|
+
describe("Tracker", () => {
|
|
20
|
+
it("holds events until the sign-in is accepted, then hands them to ph.analytics.track in order", async () => {
|
|
21
|
+
const { ph, track } = photonWithTrackSpy();
|
|
22
|
+
const tracker = new Tracker(ph);
|
|
23
|
+
tracker.track({ event: "Event A", properties: { n: 1 } });
|
|
24
|
+
tracker.track({ event: "Event B", properties: {} });
|
|
25
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
26
|
+
expect(track).not.toHaveBeenCalled();
|
|
27
|
+
tracker.setReady(true);
|
|
28
|
+
expect(track.mock.calls).toEqual([
|
|
29
|
+
["Event A", { n: 1 }],
|
|
30
|
+
["Event B", {}],
|
|
31
|
+
]);
|
|
32
|
+
tracker.track({ event: "Event C", properties: {} });
|
|
33
|
+
expect(track).toHaveBeenLastCalledWith("Event C", {});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it(`keeps at most ${MAX_QUEUED_EVENTS} while waiting`, () => {
|
|
37
|
+
const { ph, track } = photonWithTrackSpy();
|
|
38
|
+
const tracker = new Tracker(ph);
|
|
39
|
+
for (let i = 0; i < MAX_QUEUED_EVENTS + 10; i++) tracker.track({ event: event(i), properties: { i } });
|
|
40
|
+
tracker.setReady(true);
|
|
41
|
+
expect(track).toHaveBeenCalledTimes(MAX_QUEUED_EVENTS);
|
|
42
|
+
expect(track.mock.calls[0]).toEqual([event(0), { i: 0 }]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("holds nothing for an instance with nowhere to send", () => {
|
|
46
|
+
const ph: Photon = photonOver(fakeNetworkApiClient({}).client);
|
|
47
|
+
expect(ph.analytics).toBeNull();
|
|
48
|
+
const tracker = new Tracker(ph);
|
|
49
|
+
tracker.track({ event: "Event A", properties: {} });
|
|
50
|
+
expect(() => tracker.setReady(true)).not.toThrow();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Analytics, AnalyticsProperties, Photon } from "@photonhealth/client";
|
|
2
|
+
|
|
3
|
+
export type { AnalyticsProperties };
|
|
4
|
+
|
|
5
|
+
export interface QueuedEvent {
|
|
6
|
+
event: string;
|
|
7
|
+
properties: AnalyticsProperties;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type AnalyticsSend = (analytics: Analytics) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export const MAX_QUEUED_EVENTS = 50;
|
|
13
|
+
|
|
14
|
+
/** Holds the cards' events until the prescriber's sign-in is accepted, then sends them through `ph.analytics`. */
|
|
15
|
+
export class Tracker {
|
|
16
|
+
#ready = false;
|
|
17
|
+
#queue: AnalyticsSend[] = [];
|
|
18
|
+
|
|
19
|
+
constructor(private readonly ph: Photon) {}
|
|
20
|
+
|
|
21
|
+
setReady(ready: boolean) {
|
|
22
|
+
this.#ready = ready;
|
|
23
|
+
if (ready) this.#flush();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
track({ event, properties }: QueuedEvent) {
|
|
27
|
+
this.send((analytics) => analytics.track(event, properties));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
send(sendThroughAnalytics: AnalyticsSend) {
|
|
31
|
+
if (!this.ph.analytics) return;
|
|
32
|
+
if (this.#queue.length >= MAX_QUEUED_EVENTS) return;
|
|
33
|
+
this.#queue.push(sendThroughAnalytics);
|
|
34
|
+
if (this.#ready) this.#flush();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#flush() {
|
|
38
|
+
const analytics = this.ph.analytics;
|
|
39
|
+
for (const sendThroughAnalytics of this.#queue.splice(0)) if (analytics) void sendThroughAnalytics(analytics);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const trackersByPhoton = new WeakMap<Photon, Tracker>();
|
|
44
|
+
|
|
45
|
+
export function trackerFor(ph: Photon): Tracker {
|
|
46
|
+
let tracker = trackersByPhoton.get(ph);
|
|
47
|
+
if (!tracker) trackersByPhoton.set(ph, (tracker = new Tracker(ph)));
|
|
48
|
+
return tracker;
|
|
49
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { useEffect, type ReactNode } from "react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
+
import type { LifecycleAnalytics } from "@photonhealth/client";
|
|
5
|
+
import { fakeNetworkApiClient } from "@photonhealth/client/testing";
|
|
6
|
+
import { PhotonAnalyticsProvider, PhotonProvider, usePhotonAnalytics } from "../index.ts";
|
|
7
|
+
import { reactPackage } from "../meta/version.ts";
|
|
8
|
+
import { AnalyticsWorkflow } from "./PhotonAnalyticsProvider.tsx";
|
|
9
|
+
import {
|
|
10
|
+
meAsPrescriber,
|
|
11
|
+
photonWithAnalytics,
|
|
12
|
+
recordAnalytics,
|
|
13
|
+
type RecordedAnalytics,
|
|
14
|
+
unmountAndRestoreFetch,
|
|
15
|
+
} from "../../test/analytics.fixtures.tsx";
|
|
16
|
+
|
|
17
|
+
let analytics: RecordedAnalytics;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
analytics = recordAnalytics();
|
|
20
|
+
});
|
|
21
|
+
afterEach(unmountAndRestoreFetch);
|
|
22
|
+
|
|
23
|
+
const signedInClient = () => fakeNetworkApiClient({ Ping: () => ({ ping: "pong" }), ...meAsPrescriber }).client;
|
|
24
|
+
|
|
25
|
+
function SendsOnMount({ send }: { send: (lifecycle: LifecycleAnalytics) => Promise<void> }) {
|
|
26
|
+
const lifecycle = usePhotonAnalytics();
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
void send(lifecycle);
|
|
29
|
+
}, [lifecycle, send]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const deleteDraft = (lifecycle: LifecycleAnalytics) => lifecycle.draftPrescriptionDeleted("rx_1");
|
|
34
|
+
|
|
35
|
+
const inProvider = (children: ReactNode, { disableAnalytics }: { disableAnalytics?: boolean } = {}) => (
|
|
36
|
+
<PhotonProvider client={photonWithAnalytics(signedInClient())} disableAnalytics={disableAnalytics}>
|
|
37
|
+
{children}
|
|
38
|
+
</PhotonProvider>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const sent = () =>
|
|
42
|
+
analytics.bodies().map((body) => JSON.parse(body) as { event: string; properties: Record<string, unknown> });
|
|
43
|
+
const sentEvent = (name: string) => sent().find(({ event }) => event === name)!.properties;
|
|
44
|
+
|
|
45
|
+
describe("usePhotonAnalytics: ph.analytics's lifecycle events, sent as the cards send theirs", () => {
|
|
46
|
+
it("sends the event once the sign-in is accepted, with the record's properties and React's", async () => {
|
|
47
|
+
render(inProvider(<SendsOnMount send={deleteDraft} />));
|
|
48
|
+
await analytics.expectEventLog(["Draft Prescription Deleted"]);
|
|
49
|
+
expect(sentEvent("Draft Prescription Deleted")).toMatchObject({
|
|
50
|
+
prescriptionId: "rx_1",
|
|
51
|
+
category: "ctaClicked",
|
|
52
|
+
integration: "react",
|
|
53
|
+
packageName: reactPackage.name,
|
|
54
|
+
packageVersion: reactPackage.version,
|
|
55
|
+
providerId: "usr_prescriber_1",
|
|
56
|
+
timestamp: expect.any(String),
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("inside a card's workflow, carries that workflow's sessionId, the same as its Prescribe Workflow Viewed", async () => {
|
|
61
|
+
render(
|
|
62
|
+
inProvider(
|
|
63
|
+
<AnalyticsWorkflow card="PhotonOrder" viewedProperties={{}}>
|
|
64
|
+
<SendsOnMount send={deleteDraft} />
|
|
65
|
+
</AnalyticsWorkflow>,
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
await analytics.expectEventLog(["Draft Prescription Deleted", "Prescribe Workflow Viewed"]);
|
|
69
|
+
const workflowSessionId = sentEvent("Prescribe Workflow Viewed").sessionId;
|
|
70
|
+
expect(workflowSessionId).toEqual(expect.any(String));
|
|
71
|
+
expect(sentEvent("Draft Prescription Deleted").sessionId).toBe(workflowSessionId);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("outside a card, sends with no sessionId", async () => {
|
|
75
|
+
render(inProvider(<SendsOnMount send={deleteDraft} />));
|
|
76
|
+
await analytics.expectEventLog(["Draft Prescription Deleted"]);
|
|
77
|
+
expect(sentEvent("Draft Prescription Deleted").sessionId).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("PhotonAnalyticsProvider's properties go on lifecycle events too, and win", async () => {
|
|
81
|
+
render(
|
|
82
|
+
inProvider(
|
|
83
|
+
<PhotonAnalyticsProvider properties={{ integration: "web-app", testRun: "react-tests" }}>
|
|
84
|
+
<SendsOnMount send={(lifecycle) => lifecycle.screeningAlertCanceled([], "Cancel")} />
|
|
85
|
+
</PhotonAnalyticsProvider>,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
await analytics.expectEventLog(["Screening Alert Canceled"]);
|
|
89
|
+
expect(sentEvent("Screening Alert Canceled")).toMatchObject({
|
|
90
|
+
integration: "web-app",
|
|
91
|
+
testRun: "react-tests",
|
|
92
|
+
screeningAlertCount: 0,
|
|
93
|
+
buttonText: "Cancel",
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("disableAnalytics sends nothing", async () => {
|
|
98
|
+
render(inProvider(<SendsOnMount send={deleteDraft} />, { disableAnalytics: true }));
|
|
99
|
+
await analytics.expectEventLog([]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("outside a PhotonProvider, it's there to call and sends nothing", async () => {
|
|
103
|
+
render(<SendsOnMount send={deleteDraft} />);
|
|
104
|
+
await analytics.expectEventLog([]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnalyticsProperties } from "./tracker.ts";
|
|
2
|
+
|
|
3
|
+
interface CardProps {
|
|
4
|
+
order?: unknown;
|
|
5
|
+
patient?: unknown;
|
|
6
|
+
prescription?: unknown;
|
|
7
|
+
locked?: boolean;
|
|
8
|
+
fixed?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function viewedPropertiesFromCardProps(props: CardProps): AnalyticsProperties {
|
|
12
|
+
const order = asObject(props.order);
|
|
13
|
+
const linesToAdd = asObject(order?.prescriptions)?.add;
|
|
14
|
+
const lines = Array.isArray(linesToAdd) ? linesToAdd.map(asObject) : [];
|
|
15
|
+
return {
|
|
16
|
+
hasOrderPrefill: props.order != null,
|
|
17
|
+
hasPatientPrefill: props.patient != null || order?.patient != null,
|
|
18
|
+
hasPrescriptionPrefill: props.prescription != null,
|
|
19
|
+
numTemplateIds: lines.filter((line) => typeof line?.templateId === "string").length,
|
|
20
|
+
numPrescriptionIds: lines.filter((line) => typeof line?.id === "string").length,
|
|
21
|
+
locked: Boolean(props.locked),
|
|
22
|
+
fixed: Boolean(props.fixed),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const asObject = (value: unknown): Record<string, unknown> | null =>
|
|
27
|
+
value && typeof value === "object" ? (value as Record<string, unknown>) : null;
|