@photonhealth/client 2.0.0-rc.1 → 2.0.0-rc.2
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 +150 -5
- package/dist/analytics/lifecycleEvents.d.ts +29 -0
- package/dist/analytics/lifecycleEvents.d.ts.map +1 -0
- package/dist/analytics/lifecycleEvents.js +72 -0
- package/dist/analytics/lifecycleEvents.js.map +1 -0
- package/dist/api/client.d.ts +6 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +47 -33
- package/dist/api/client.js.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/me.d.ts +37 -0
- package/dist/api/me.d.ts.map +1 -0
- package/dist/api/me.js +6 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/orders.d.ts +1047 -0
- package/dist/api/orders.d.ts.map +1 -0
- package/dist/api/orders.js +7 -0
- package/dist/api/orders.js.map +1 -0
- package/dist/api/patient.d.ts +5 -2
- package/dist/api/patient.d.ts.map +1 -1
- package/dist/api/patient.js +1 -1
- package/dist/api/patient.js.map +1 -1
- package/dist/api/prescription.d.ts +7 -1
- package/dist/api/prescription.d.ts.map +1 -1
- package/dist/api/prescription.js +10 -1
- package/dist/api/prescription.js.map +1 -1
- package/dist/gql/gql.d.ts +11 -3
- package/dist/gql/gql.d.ts.map +1 -1
- package/dist/gql/gql.js +5 -3
- package/dist/gql/gql.js.map +1 -1
- package/dist/gql/graphql.d.ts +10507 -1563
- package/dist/gql/graphql.d.ts.map +1 -1
- package/dist/gql/graphql.js +2984 -435
- package/dist/gql/graphql.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/meta/version.d.ts +2 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +2 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/photon/analytics.d.ts +39 -0
- package/dist/photon/analytics.d.ts.map +1 -0
- package/dist/photon/analytics.js +91 -0
- package/dist/photon/analytics.js.map +1 -0
- package/dist/photon/auth.d.ts +9 -5
- package/dist/photon/auth.d.ts.map +1 -1
- package/dist/photon/auth.js +2 -6
- package/dist/photon/auth.js.map +1 -1
- package/dist/photon/choices.d.ts +1 -1
- package/dist/photon/choices.js +2 -2
- package/dist/photon/choices.js.map +1 -1
- package/dist/photon/environments.d.ts +2 -1
- package/dist/photon/environments.d.ts.map +1 -1
- package/dist/photon/environments.js +2 -1
- package/dist/photon/environments.js.map +1 -1
- package/dist/photon/index.d.ts +6 -3
- package/dist/photon/index.d.ts.map +1 -1
- package/dist/photon/index.js +2 -1
- package/dist/photon/index.js.map +1 -1
- package/dist/photon/machine.d.ts +28 -0
- package/dist/photon/machine.d.ts.map +1 -0
- package/dist/photon/machine.js +53 -0
- package/dist/photon/machine.js.map +1 -0
- package/dist/photon/map.d.ts +6 -2
- package/dist/photon/map.d.ts.map +1 -1
- package/dist/photon/map.js +133 -33
- package/dist/photon/map.js.map +1 -1
- package/dist/photon/order.d.ts +21 -1
- package/dist/photon/order.d.ts.map +1 -1
- package/dist/photon/order.js +79 -12
- package/dist/photon/order.js.map +1 -1
- package/dist/photon/orders.d.ts +5 -0
- package/dist/photon/orders.d.ts.map +1 -0
- package/dist/photon/orders.js +39 -0
- package/dist/photon/orders.js.map +1 -0
- package/dist/photon/patient.d.ts +8 -6
- package/dist/photon/patient.d.ts.map +1 -1
- package/dist/photon/patient.js +61 -30
- package/dist/photon/patient.js.map +1 -1
- package/dist/photon/photon.d.ts +39 -1
- package/dist/photon/photon.d.ts.map +1 -1
- package/dist/photon/photon.js +85 -5
- package/dist/photon/photon.js.map +1 -1
- package/dist/photon/prescription.d.ts +17 -4
- package/dist/photon/prescription.d.ts.map +1 -1
- package/dist/photon/prescription.js +48 -11
- package/dist/photon/prescription.js.map +1 -1
- package/dist/photon/session.d.ts +15 -10
- package/dist/photon/session.d.ts.map +1 -1
- package/dist/photon/session.js +5 -3
- package/dist/photon/session.js.map +1 -1
- package/dist/photon/types.d.ts +278 -46
- package/dist/photon/types.d.ts.map +1 -1
- package/dist/test-utils/msw.d.ts +2 -2
- package/dist/test-utils/msw.d.ts.map +1 -1
- package/dist/test-utils/msw.js +5 -5
- package/dist/test-utils/msw.js.map +1 -1
- package/dist/testing/{scriptedClient.d.ts → fakeNetworkApiClient.d.ts} +5 -4
- package/dist/testing/fakeNetworkApiClient.d.ts.map +1 -0
- package/dist/testing/{scriptedClient.js → fakeNetworkApiClient.js} +8 -4
- package/dist/testing/fakeNetworkApiClient.js.map +1 -0
- package/dist/testing/fixtures.d.ts +1047 -0
- package/dist/testing/fixtures.d.ts.map +1 -1
- package/dist/testing/fixtures.js +47 -13
- package/dist/testing/fixtures.js.map +1 -1
- package/dist/testing.d.ts +4 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +4 -4
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/analytics/lifecycleEvents.test.ts +417 -0
- package/src/analytics/lifecycleEvents.ts +155 -0
- package/src/api/client.ts +71 -46
- package/src/api/index.ts +2 -0
- package/src/api/me.ts +7 -0
- package/src/api/orders.ts +8 -0
- package/src/api/patient.ts +11 -2
- package/src/api/prescription.ts +18 -0
- package/src/gql/gql.ts +21 -9
- package/src/gql/graphql.ts +4280 -597
- package/src/index.ts +1 -1
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +1 -0
- package/src/operations/fragments.graphql +166 -20
- package/src/operations/me.graphql +38 -0
- package/src/operations/orders.graphql +35 -0
- package/src/operations/patient.graphql +29 -3
- package/src/operations/prescription.graphql +20 -0
- package/src/photon/analytics.ts +129 -0
- package/src/photon/auth.ts +9 -10
- package/src/photon/choices.ts +2 -2
- package/src/photon/environments.ts +3 -1
- package/src/photon/index.ts +16 -2
- package/src/photon/machine.ts +90 -0
- package/src/photon/map.ts +151 -35
- package/src/photon/order.test.ts +142 -0
- package/src/photon/order.ts +92 -12
- package/src/photon/orders.ts +42 -0
- package/src/photon/patient.ts +73 -33
- package/src/photon/photon.ts +139 -6
- package/src/photon/prescription.ts +71 -12
- package/src/photon/session.ts +18 -9
- package/src/photon/types.ts +280 -26
- package/src/test-utils/msw.ts +16 -5
- package/src/testing/{scriptedClient.ts → fakeNetworkApiClient.ts} +8 -4
- package/src/testing/fixtures.ts +55 -13
- package/src/testing.ts +6 -3
- package/dist/testing/scriptedClient.d.ts.map +0 -1
- package/dist/testing/scriptedClient.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/testing/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/testing/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,MAAM,GAAI,YAAW,OAAO,CAAC,MAAM,CAAM,KAAG,MAavD,CAAC;AAEH,KAAK,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3C,8DAA8D;AAC9D,eAAO,MAAM,MAAM,GAAI,Y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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7D,CAAC;AAEH,wFAAwF;AACxF,eAAO,MAAM,OAAO;;;;;;CAElB,CAAC;AAEH,kFAAkF;AAClF,eAAO,MAAM,SAAS,GACpB,YAAY;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,EACpG,eAA2C;;;;;gBADzB,MAAM;uBAAa,MAAM;sBAAY,MAAM,GAAG,IAAI;yBAAe,MAAM,GAAG,IAAI;;;;CAQhG,CAAC"}
|
package/dist/testing/fixtures.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Hand-written until M0 captures real boson responses
|
|
1
|
+
// Hand-written until M0 captures real boson responses.
|
|
2
2
|
export const change = (overrides = {}) => ({
|
|
3
3
|
__typename: "Change",
|
|
4
4
|
key: "treatment",
|
|
@@ -28,22 +28,38 @@ export const choice = (overrides = {}) => ({
|
|
|
28
28
|
export const pharmacyOffer = (overrides = {}) => ({
|
|
29
29
|
__typename: "PharmacyOffer",
|
|
30
30
|
source: "goodrx",
|
|
31
|
+
prescriptionId: "rx_1",
|
|
32
|
+
priceType: "CASH",
|
|
31
33
|
isPromoted: false,
|
|
32
34
|
attributeTags: [],
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
price: { __typename: "OfferPrice", amount: 12, retailAmount: 20, promotions: [] },
|
|
36
|
+
deliveryEstimate: null,
|
|
37
|
+
// A discount-card source priced this pharmacy but hasn't been routed to, so the card isn't minted yet.
|
|
38
|
+
redemptionState: "PENDING",
|
|
39
|
+
redemptionMethods: [],
|
|
40
|
+
...overrides,
|
|
41
|
+
});
|
|
42
|
+
/** A minted coupon, as an offer's redemption method. Pair it with `redemptionState: "SETTLED"`. */
|
|
43
|
+
export const discountCard = (overrides = {}) => ({
|
|
44
|
+
__typename: "PharmacyDiscountCard",
|
|
45
|
+
id: "dcrd_1",
|
|
46
|
+
prescriptionId: "rx_1",
|
|
47
|
+
bin: "017449",
|
|
48
|
+
pcn: "GRX",
|
|
49
|
+
group: "GR1234",
|
|
50
|
+
memberId: "M00000001",
|
|
51
|
+
externalUrl: null,
|
|
41
52
|
...overrides,
|
|
42
53
|
});
|
|
43
54
|
export const pharmacy = (overrides = {}) => ({
|
|
44
55
|
__typename: "Pharmacy",
|
|
45
56
|
id: "phr_1",
|
|
46
57
|
name: "CVS Pharmacy",
|
|
58
|
+
logo: null,
|
|
59
|
+
phone: null,
|
|
60
|
+
hours: null,
|
|
61
|
+
isOpen: null,
|
|
62
|
+
nextEvents: null,
|
|
47
63
|
address: {
|
|
48
64
|
__typename: "PharmacyAddress",
|
|
49
65
|
street1: "123 Main St",
|
|
@@ -75,12 +91,13 @@ export const treatment = (overrides = {}) => ({
|
|
|
75
91
|
strength: null,
|
|
76
92
|
medicationType: null,
|
|
77
93
|
schedule: null,
|
|
78
|
-
recommendedDispenseUnits: null,
|
|
79
94
|
...overrides,
|
|
80
95
|
});
|
|
81
96
|
export const rx = (overrides = {}) => ({
|
|
82
97
|
__typename: "Prescription",
|
|
83
98
|
id: "rx_1",
|
|
99
|
+
prescriber: null,
|
|
100
|
+
fulfillment: null,
|
|
84
101
|
templateId: null,
|
|
85
102
|
patient: { __typename: "PatientReference", id: "pat_1" },
|
|
86
103
|
treatment: treatment(),
|
|
@@ -117,6 +134,9 @@ export const patient = (overrides = {}) => ({
|
|
|
117
134
|
dateOfBirth: "1990-01-01",
|
|
118
135
|
sex: null,
|
|
119
136
|
gender: null,
|
|
137
|
+
},
|
|
138
|
+
contact: {
|
|
139
|
+
__typename: "PatientContact",
|
|
120
140
|
email: null,
|
|
121
141
|
phone: null,
|
|
122
142
|
address: {
|
|
@@ -128,9 +148,9 @@ export const patient = (overrides = {}) => ({
|
|
|
128
148
|
postalCode: "10001",
|
|
129
149
|
country: "US",
|
|
130
150
|
},
|
|
131
|
-
benefits: { __typename: "BenefitList", status: null, entries: [] },
|
|
132
|
-
preferredPharmacy: null,
|
|
133
151
|
},
|
|
152
|
+
benefits: { __typename: "BenefitList", status: null, entries: [] },
|
|
153
|
+
preferredPharmacy: null,
|
|
134
154
|
clinical: {
|
|
135
155
|
__typename: "PatientClinical",
|
|
136
156
|
allergies: { __typename: "AllergyList", status: "NOT_DOCUMENTED", entries: [] },
|
|
@@ -145,12 +165,26 @@ export const order = (overrides = {}) => ({
|
|
|
145
165
|
__typename: "Order",
|
|
146
166
|
id: "ord_1",
|
|
147
167
|
state: "DRAFT",
|
|
168
|
+
organization: null,
|
|
148
169
|
patient: patient(),
|
|
149
170
|
prescriptions: [rx()],
|
|
171
|
+
screeningAlerts: [],
|
|
150
172
|
pharmacy: null,
|
|
151
|
-
|
|
173
|
+
fulfillment: null,
|
|
174
|
+
// No pharmacy, so nothing is priced yet.
|
|
175
|
+
offers: { __typename: "OrderOffers", atPharmacy: null },
|
|
176
|
+
...overrides,
|
|
177
|
+
});
|
|
178
|
+
/** A query snapshot; pharmacy choices are requested separately from the record. */
|
|
179
|
+
export const listedOrder = (overrides = {}) => ({
|
|
180
|
+
...order(),
|
|
181
|
+
routablePharmacies: null,
|
|
152
182
|
...overrides,
|
|
153
183
|
});
|
|
184
|
+
/** Orders query response, including an empty result when passed []. */
|
|
185
|
+
export const orders = (records = [listedOrder()]) => ({
|
|
186
|
+
orders: { __typename: "OrdersPayload", orders: records },
|
|
187
|
+
});
|
|
154
188
|
/** A patient query nobody matches: no record, and nothing the server still asks for. */
|
|
155
189
|
export const noMatch = () => ({
|
|
156
190
|
patient: { __typename: "PatientPayload", patient: null, changes: [] },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../src/testing/fixtures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../src/testing/fixtures.ts"],"names":[],"mappings":"AAMA,uDAAuD;AAEvD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAA6B,EAAE,EAAU,EAAE,CAAC,CAAC;IAClE,UAAU,EAAE,QAAQ;IACpB,GAAG,EAAE,WAAW;IAChB,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,OAAO;IAClB,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,KAAK,EAAE,IAAI;IACX,GAAG,SAAS;CACb,CAAC,CAAC;AAIH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAA6B,EAAE,EAAU,EAAE,CAAC,CAAC;IAClE,UAAU,EAAE,QAAQ;IACpB,WAAW,EAAE,EAAE;IACf,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,cAAc;IACzB,QAAQ,EAAE,cAAc;IACxB,KAAK,EAAE,IAAI;IACX,YAAY,EAAE,EAAE;IAChB,MAAM,EAAE,IAAI;IACZ,GAAG,SAAS;CACb,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,YAAoC,EAAE,EAAiB,EAAE,CAAC,CAAC;IACvF,UAAU,EAAE,eAAe;IAC3B,MAAM,EAAE,QAAQ;IAChB,cAAc,EAAE,MAAM;IACtB,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,EAAE;IACjB,KAAK,EAAE,EAAE,UAAU,EAAE,YA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AAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;KAC9E;CACF,CAAC,CAAC"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* For tests only — a host's or ours: a photon instance over a
|
|
3
|
-
* payloads and records to script it with. Not the app's API:
|
|
2
|
+
* For tests only — a host's or ours: a photon instance over a fake network-api client, with network-api's
|
|
3
|
+
* payloads and records to script it with. Not the app's API: keep app
|
|
4
4
|
* code off it.
|
|
5
5
|
*/
|
|
6
6
|
export { photonOver, clientOf } from "./photon/photon.ts";
|
|
7
7
|
export { NetworkTransportError } from "./api/client.ts";
|
|
8
8
|
export type { NetworkClient } from "./api/index.ts";
|
|
9
|
-
export { intentOf,
|
|
10
|
-
export { change, choice, treatment, rx, alert, patient, order, pharmacy, pharmacyOffer, noMatch, ambiguous, } from "./testing/fixtures.ts";
|
|
9
|
+
export { intentOf, fakeNetworkApiClient, payload } from "./testing/fakeNetworkApiClient.ts";
|
|
10
|
+
export { change, choice, treatment, rx, alert, patient, order, listedOrder, orders, pharmacy, pharmacyOffer, discountCard, noMatch, ambiguous, } from "./testing/fixtures.ts";
|
|
11
11
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,EAAE,EACF,KAAK,EACL,OAAO,EACP,KAAK,EACL,WAAW,EACX,MAAM,EACN,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,OAAO,EACP,SAAS,GACV,MAAM,uBAAuB,CAAC"}
|
package/dist/testing.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* For tests only — a host's or ours: a photon instance over a
|
|
3
|
-
* payloads and records to script it with. Not the app's API:
|
|
2
|
+
* For tests only — a host's or ours: a photon instance over a fake network-api client, with network-api's
|
|
3
|
+
* payloads and records to script it with. Not the app's API: keep app
|
|
4
4
|
* code off it.
|
|
5
5
|
*/
|
|
6
6
|
export { photonOver, clientOf } from "./photon/photon.js";
|
|
7
7
|
export { NetworkTransportError } from "./api/client.js";
|
|
8
|
-
export { intentOf,
|
|
9
|
-
export { change, choice, treatment, rx, alert, patient, order, pharmacy, pharmacyOffer, noMatch, ambiguous, } from "./testing/fixtures.js";
|
|
8
|
+
export { intentOf, fakeNetworkApiClient, payload } from "./testing/fakeNetworkApiClient.js";
|
|
9
|
+
export { change, choice, treatment, rx, alert, patient, order, listedOrder, orders, pharmacy, pharmacyOffer, discountCard, noMatch, ambiguous, } from "./testing/fixtures.js";
|
|
10
10
|
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,EAAE,EACF,KAAK,EACL,OAAO,EACP,KAAK,EACL,WAAW,EACX,MAAM,EACN,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,OAAO,EACP,SAAS,GACV,MAAM,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@photonhealth/client",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "Photon's prescribing API for JavaScript: patients, prescriptions and orders as live objects with the workflow rules inside. Framework-agnostic, zero runtime dependencies.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"homepage": "https://docs.photon.health",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"node": ">=22"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"schema:pull": "node scripts/pull-schema.mjs",
|
|
46
45
|
"codegen": "graphql-codegen --config codegen.ts",
|
|
47
46
|
"typecheck": "tsc -p tsconfig.json",
|
|
48
47
|
"test": "vitest run",
|
|
49
48
|
"test:watch": "vitest",
|
|
49
|
+
"prebuild": "npm run codegen",
|
|
50
50
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
51
51
|
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
52
52
|
"check:dist": "npm run build && node scripts/check-dist.mjs"
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fakeNetworkApiClient, photonOver } from "../testing.ts";
|
|
3
|
+
import type { Analytics } from "../photon/analytics.ts";
|
|
4
|
+
import { environmentUrls } from "../photon/environments.ts";
|
|
5
|
+
import type { OrderRecord, Pharmacy, PatientRecord, PrescriptionRecord, ScreeningAlert } from "../photon/types.ts";
|
|
6
|
+
|
|
7
|
+
const typedByPrescriber = {
|
|
8
|
+
firstName: "Paige",
|
|
9
|
+
middleName: "Quincy",
|
|
10
|
+
lastName: "Turner",
|
|
11
|
+
dateOfBirth: "1984-02-29",
|
|
12
|
+
gender: "nonbinary",
|
|
13
|
+
email: "paige.turner@example.com",
|
|
14
|
+
phone: "+15555550123",
|
|
15
|
+
street1: "12 Sycamore Lane",
|
|
16
|
+
street2: "Apt 4B",
|
|
17
|
+
city: "Springfield",
|
|
18
|
+
state: "WY",
|
|
19
|
+
postalCode: "97477",
|
|
20
|
+
instructions: "Take one tablet by mouth nightly",
|
|
21
|
+
notes: "Patient prefers evening doses",
|
|
22
|
+
alertDescription: "Penicillin allergy reported",
|
|
23
|
+
pharmacyName: "Corner Drug",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const fullPatient = (): PatientRecord => ({
|
|
27
|
+
id: "pat_1",
|
|
28
|
+
demographic: {
|
|
29
|
+
name: {
|
|
30
|
+
first: typedByPrescriber.firstName,
|
|
31
|
+
middle: typedByPrescriber.middleName,
|
|
32
|
+
last: typedByPrescriber.lastName,
|
|
33
|
+
},
|
|
34
|
+
dateOfBirth: typedByPrescriber.dateOfBirth,
|
|
35
|
+
sex: "FEMALE",
|
|
36
|
+
gender: typedByPrescriber.gender,
|
|
37
|
+
},
|
|
38
|
+
contact: {
|
|
39
|
+
email: typedByPrescriber.email,
|
|
40
|
+
phone: typedByPrescriber.phone,
|
|
41
|
+
address: {
|
|
42
|
+
street1: typedByPrescriber.street1,
|
|
43
|
+
street2: typedByPrescriber.street2,
|
|
44
|
+
city: typedByPrescriber.city,
|
|
45
|
+
state: typedByPrescriber.state,
|
|
46
|
+
postalCode: typedByPrescriber.postalCode,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
benefits: null,
|
|
50
|
+
preferredPharmacy: pharmacy(),
|
|
51
|
+
clinical: null,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const barePatient = (): PatientRecord => ({
|
|
55
|
+
id: "pat_2",
|
|
56
|
+
demographic: {
|
|
57
|
+
name: { first: typedByPrescriber.firstName, middle: null, last: typedByPrescriber.lastName },
|
|
58
|
+
dateOfBirth: typedByPrescriber.dateOfBirth,
|
|
59
|
+
sex: null,
|
|
60
|
+
gender: null,
|
|
61
|
+
},
|
|
62
|
+
contact: { email: null, phone: "", address: null },
|
|
63
|
+
benefits: null,
|
|
64
|
+
preferredPharmacy: null,
|
|
65
|
+
clinical: null,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function pharmacy(fulfillmentType: Pharmacy["fulfillmentType"] = ["PICK_UP"]): Pharmacy {
|
|
69
|
+
return {
|
|
70
|
+
id: "phr_1",
|
|
71
|
+
name: typedByPrescriber.pharmacyName,
|
|
72
|
+
logo: null,
|
|
73
|
+
phone: null,
|
|
74
|
+
hours: null,
|
|
75
|
+
isOpen: null,
|
|
76
|
+
nextEvents: null,
|
|
77
|
+
address: null,
|
|
78
|
+
latitude: null,
|
|
79
|
+
longitude: null,
|
|
80
|
+
fulfillmentType,
|
|
81
|
+
offers: [],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const alert = (): ScreeningAlert => ({
|
|
86
|
+
severity: "MAJOR",
|
|
87
|
+
type: "ALLERGEN",
|
|
88
|
+
description: typedByPrescriber.alertDescription,
|
|
89
|
+
involvedEntities: [{ id: "med_1", name: "Amoxicillin" }],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const prescription = (id = "rx_1", overrides: Partial<PrescriptionRecord> = {}): PrescriptionRecord => ({
|
|
93
|
+
id,
|
|
94
|
+
prescriber: { id: "usr_1", name: { first: "Ada", middle: null, last: "Lovelace" } },
|
|
95
|
+
fulfillment: null,
|
|
96
|
+
templateId: null,
|
|
97
|
+
patient: { id: "pat_1" },
|
|
98
|
+
treatment: {
|
|
99
|
+
id: "med_1",
|
|
100
|
+
name: "Lisinopril",
|
|
101
|
+
prescribableName: "Lisinopril Oral Tablet 10 MG",
|
|
102
|
+
rxNormId: "314076",
|
|
103
|
+
ndc: null,
|
|
104
|
+
upc: null,
|
|
105
|
+
entityKind: "MEDICATION",
|
|
106
|
+
brandName: "Lisinopril",
|
|
107
|
+
genericName: "Lisinopril",
|
|
108
|
+
form: "Tablet",
|
|
109
|
+
route: "Oral",
|
|
110
|
+
strength: "10 MG",
|
|
111
|
+
medicationType: "RX",
|
|
112
|
+
schedule: null,
|
|
113
|
+
templates: null,
|
|
114
|
+
},
|
|
115
|
+
instructions: typedByPrescriber.instructions,
|
|
116
|
+
dispense: { quantity: 30, unit: "Tablet", daysSupply: 30, refillsAllowed: 0, dispenseAsWritten: false },
|
|
117
|
+
clinical: { diagnoses: [], notes: typedByPrescriber.notes },
|
|
118
|
+
screeningAlerts: [alert()],
|
|
119
|
+
signing: { state: "SIGNED", contentHash: "hash_1", message: null, signedAt: "2026-11-06T12:00:00.000Z" },
|
|
120
|
+
...overrides,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const order = (overrides: Partial<OrderRecord> = {}): OrderRecord => ({
|
|
124
|
+
id: "ord_1",
|
|
125
|
+
state: "SUBMITTED",
|
|
126
|
+
organization: null,
|
|
127
|
+
patient: fullPatient(),
|
|
128
|
+
prescriptions: [prescription("rx_1"), prescription("rx_2")],
|
|
129
|
+
screeningAlerts: [alert()],
|
|
130
|
+
pharmacy: null,
|
|
131
|
+
offers: { atPharmacy: null },
|
|
132
|
+
fulfillment: null,
|
|
133
|
+
...overrides,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const jwt = (claims: Record<string, unknown>) => `x.${btoa(JSON.stringify(claims)).replace(/=+$/, "")}.y`;
|
|
137
|
+
|
|
138
|
+
const analyticsAsPrescriber = (): Analytics => {
|
|
139
|
+
const network = fakeNetworkApiClient({
|
|
140
|
+
Me: () => ({
|
|
141
|
+
me: {
|
|
142
|
+
__typename: "User",
|
|
143
|
+
id: "usr_1",
|
|
144
|
+
name: { first: "Ada", last: "Lovelace" },
|
|
145
|
+
organization: { __typename: "Organization", id: "org_1", name: "Acme Clinic" },
|
|
146
|
+
permissions: [],
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
return photonOver(network.client, environmentUrls("boson"), {
|
|
151
|
+
analytics: {
|
|
152
|
+
url: "https://analytics-api.boson.health",
|
|
153
|
+
token: async () => jwt({ sub: "auth0|1", org_id: "org_1" }),
|
|
154
|
+
clientName: "photon-mcp",
|
|
155
|
+
},
|
|
156
|
+
}).analytics!;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
interface SentEvent {
|
|
160
|
+
event: string;
|
|
161
|
+
properties: Record<string, unknown>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let fetchSpy: ReturnType<typeof vi.fn>;
|
|
165
|
+
const sentEvents = (): SentEvent[] =>
|
|
166
|
+
fetchSpy.mock.calls.map(([, init]) => JSON.parse((init as RequestInit).body as string) as SentEvent);
|
|
167
|
+
const rawBodiesSent = () => fetchSpy.mock.calls.map(([, init]) => (init as RequestInit).body as string).join("\n");
|
|
168
|
+
|
|
169
|
+
const propertiesSentBy = async (send: (analytics: Analytics) => Promise<void>) => {
|
|
170
|
+
await send(analyticsAsPrescriber());
|
|
171
|
+
return sentEvents().at(-1)!.properties;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const commonProperties = ["providerId", "orgId", "environment", "clientName", "clientVersion", "timestamp"];
|
|
175
|
+
const ownProperties = (properties: Record<string, unknown>) =>
|
|
176
|
+
Object.fromEntries(Object.entries(properties).filter(([name]) => !commonProperties.includes(name)));
|
|
177
|
+
|
|
178
|
+
const sendEveryLifecycleEvent = async (analytics: Analytics) => {
|
|
179
|
+
await analytics.patientCreated(fullPatient());
|
|
180
|
+
await analytics.patientUpdated(fullPatient());
|
|
181
|
+
await analytics.draftPrescriptionAdded(prescription(), "form");
|
|
182
|
+
await analytics.draftPrescriptionDeleted("rx_1");
|
|
183
|
+
await analytics.screeningAlertAcknowledged([alert()], "Send");
|
|
184
|
+
await analytics.screeningAlertCanceled([alert()], "Cancel");
|
|
185
|
+
await analytics.prescriptionSigned(prescription());
|
|
186
|
+
await analytics.orderSent(order());
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
beforeEach(() => {
|
|
190
|
+
fetchSpy = vi.fn(async () => new Response(JSON.stringify({ status: "ok" })));
|
|
191
|
+
vi.stubGlobal("fetch", fetchSpy);
|
|
192
|
+
});
|
|
193
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
194
|
+
|
|
195
|
+
describe("ph.analytics lifecycle events use <photon-prescribe-workflow>'s names, so Mixpanel reports keep working", () => {
|
|
196
|
+
it("sends each one under its elements name, none dropped by the guards", async () => {
|
|
197
|
+
await sendEveryLifecycleEvent(analyticsAsPrescriber());
|
|
198
|
+
expect(sentEvents().map(({ event }) => event)).toEqual([
|
|
199
|
+
"Patient Created",
|
|
200
|
+
"Patient Updated",
|
|
201
|
+
"Draft Prescription Added",
|
|
202
|
+
"Draft Prescription Deleted",
|
|
203
|
+
"Screening Alert Acknowledged",
|
|
204
|
+
"Screening Alert Canceled",
|
|
205
|
+
"Prescription Signed",
|
|
206
|
+
"Order Sent",
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("every lifecycle event is a ctaClicked, as in elements", async () => {
|
|
211
|
+
await sendEveryLifecycleEvent(analyticsAsPrescriber());
|
|
212
|
+
expect(new Set(sentEvents().map(({ properties }) => properties.category))).toEqual(new Set(["ctaClicked"]));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("carries the prescriber, organization and environment like any tracked event", async () => {
|
|
216
|
+
expect(await propertiesSentBy((analytics) => analytics.draftPrescriptionDeleted("rx_1"))).toMatchObject({
|
|
217
|
+
providerId: "usr_1",
|
|
218
|
+
orgId: "org_1",
|
|
219
|
+
environment: "boson",
|
|
220
|
+
clientName: "photon-mcp",
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("patientCreated and patientUpdated", () => {
|
|
226
|
+
it("send the patient's id and which of the patient form's fields are filled, all filled", async () => {
|
|
227
|
+
expect(ownProperties(await propertiesSentBy((analytics) => analytics.patientCreated(fullPatient())))).toEqual({
|
|
228
|
+
category: "ctaClicked",
|
|
229
|
+
patientId: "pat_1",
|
|
230
|
+
snap_first_name: true,
|
|
231
|
+
snap_last_name: true,
|
|
232
|
+
snap_date_of_birth: true,
|
|
233
|
+
snap_phone: true,
|
|
234
|
+
snap_sex: true,
|
|
235
|
+
snap_gender: true,
|
|
236
|
+
snap_email: true,
|
|
237
|
+
snap_address_street1: true,
|
|
238
|
+
snap_address_street2: true,
|
|
239
|
+
snap_address_city: true,
|
|
240
|
+
snap_address_state: true,
|
|
241
|
+
snap_address_zip: true,
|
|
242
|
+
snap_preferred_pharmacy: true,
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("mark a field unfilled when the record has it null, empty or missing", async () => {
|
|
247
|
+
expect(ownProperties(await propertiesSentBy((analytics) => analytics.patientUpdated(barePatient())))).toEqual({
|
|
248
|
+
category: "ctaClicked",
|
|
249
|
+
patientId: "pat_2",
|
|
250
|
+
snap_first_name: true,
|
|
251
|
+
snap_last_name: true,
|
|
252
|
+
snap_date_of_birth: true,
|
|
253
|
+
snap_phone: false,
|
|
254
|
+
snap_sex: false,
|
|
255
|
+
snap_gender: false,
|
|
256
|
+
snap_email: false,
|
|
257
|
+
snap_address_street1: false,
|
|
258
|
+
snap_address_street2: false,
|
|
259
|
+
snap_address_city: false,
|
|
260
|
+
snap_address_state: false,
|
|
261
|
+
snap_address_zip: false,
|
|
262
|
+
snap_preferred_pharmacy: false,
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("draftPrescriptionAdded", () => {
|
|
268
|
+
it("sends the line's id, where it came from, and which prescription fields are filled", async () => {
|
|
269
|
+
const sent = await propertiesSentBy((analytics) =>
|
|
270
|
+
analytics.draftPrescriptionAdded(prescription(), "template_prefill"),
|
|
271
|
+
);
|
|
272
|
+
expect(ownProperties(sent)).toEqual({
|
|
273
|
+
category: "ctaClicked",
|
|
274
|
+
prescriptionId: "rx_1",
|
|
275
|
+
draftPrescriptionSource: "template_prefill",
|
|
276
|
+
snap_treatment: true,
|
|
277
|
+
snap_dispense_quantity: true,
|
|
278
|
+
snap_dispense_unit: true,
|
|
279
|
+
snap_days_supply: true,
|
|
280
|
+
snap_refills: true,
|
|
281
|
+
snap_instructions: true,
|
|
282
|
+
snap_notes: true,
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it("marks dispense fields and notes unfilled on a line that has none yet", async () => {
|
|
287
|
+
const sparse = prescription("rx_3", { dispense: null, instructions: null, clinical: null });
|
|
288
|
+
const sent = await propertiesSentBy((analytics) =>
|
|
289
|
+
analytics.draftPrescriptionAdded(sparse, "prescription_id_prefill"),
|
|
290
|
+
);
|
|
291
|
+
expect(sent).toMatchObject({
|
|
292
|
+
prescriptionId: "rx_3",
|
|
293
|
+
draftPrescriptionSource: "prescription_id_prefill",
|
|
294
|
+
snap_treatment: true,
|
|
295
|
+
snap_dispense_quantity: false,
|
|
296
|
+
snap_dispense_unit: false,
|
|
297
|
+
snap_days_supply: false,
|
|
298
|
+
snap_refills: false,
|
|
299
|
+
snap_instructions: false,
|
|
300
|
+
snap_notes: false,
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("draftPrescriptionDeleted and prescriptionSigned", () => {
|
|
306
|
+
it("send only the prescription's id", async () => {
|
|
307
|
+
expect(ownProperties(await propertiesSentBy((analytics) => analytics.draftPrescriptionDeleted("rx_9")))).toEqual({
|
|
308
|
+
category: "ctaClicked",
|
|
309
|
+
prescriptionId: "rx_9",
|
|
310
|
+
});
|
|
311
|
+
expect(
|
|
312
|
+
ownProperties(await propertiesSentBy((analytics) => analytics.prescriptionSigned(prescription("rx_4")))),
|
|
313
|
+
).toEqual({ category: "ctaClicked", prescriptionId: "rx_4" });
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe("screeningAlertAcknowledged and screeningAlertCanceled", () => {
|
|
318
|
+
it("count the alerts and send the button the prescriber pressed", async () => {
|
|
319
|
+
expect(
|
|
320
|
+
ownProperties(
|
|
321
|
+
await propertiesSentBy((analytics) => analytics.screeningAlertAcknowledged([alert(), alert()], "Send")),
|
|
322
|
+
),
|
|
323
|
+
).toEqual({ category: "ctaClicked", screeningAlertCount: 2, buttonText: "Send" });
|
|
324
|
+
expect(
|
|
325
|
+
ownProperties(await propertiesSentBy((analytics) => analytics.screeningAlertCanceled([alert()], "Cancel"))),
|
|
326
|
+
).toEqual({ category: "ctaClicked", screeningAlertCount: 1, buttonText: "Cancel" });
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe("orderSent", () => {
|
|
331
|
+
it("sends the order's id, its prescriptions, and SEND_TO_PATIENT when the patient chooses the pharmacy", async () => {
|
|
332
|
+
expect(ownProperties(await propertiesSentBy((analytics) => analytics.orderSent(order())))).toEqual({
|
|
333
|
+
category: "ctaClicked",
|
|
334
|
+
orderId: "ord_1",
|
|
335
|
+
prescriptionCount: 2,
|
|
336
|
+
prescriptionIds: ["rx_1", "rx_2"],
|
|
337
|
+
fulfillmentType: "SEND_TO_PATIENT",
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it.each([
|
|
342
|
+
["a pick-up pharmacy", pharmacy(["PICK_UP"]), "PICK_UP"],
|
|
343
|
+
["a mail-order pharmacy", pharmacy(["MAIL_ORDER"]), "MAIL_ORDER"],
|
|
344
|
+
["a pharmacy that does both", pharmacy(["PICK_UP", "MAIL_ORDER"]), null],
|
|
345
|
+
["a pharmacy that doesn't say", pharmacy(null), null],
|
|
346
|
+
])("sends the fulfillment type of %s", async (_why, chosen, expectedType) => {
|
|
347
|
+
const sent = await propertiesSentBy((analytics) => analytics.orderSent(order({ pharmacy: chosen })));
|
|
348
|
+
expect(sent.fulfillmentType).toBe(expectedType);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe("the caller's own properties", () => {
|
|
353
|
+
it("ride along, as a surface's sessionId and integration do", async () => {
|
|
354
|
+
const sent = await propertiesSentBy((analytics) =>
|
|
355
|
+
analytics.orderSent(order(), { sessionId: "ses_1", integration: "react" }),
|
|
356
|
+
);
|
|
357
|
+
expect(sent).toMatchObject({ sessionId: "ses_1", integration: "react", orderId: "ord_1" });
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("never replace what the record says", async () => {
|
|
361
|
+
const sent = await propertiesSentBy((analytics) =>
|
|
362
|
+
analytics.orderSent(order(), { orderId: "ord_forged", prescriptionCount: 99, category: "fieldInteraction" }),
|
|
363
|
+
);
|
|
364
|
+
expect(sent).toMatchObject({ orderId: "ord_1", prescriptionCount: 2, category: "ctaClicked" });
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe("never PHI", () => {
|
|
369
|
+
it("no value a prescriber typed or a record holds as free text appears in any lifecycle event", async () => {
|
|
370
|
+
await sendEveryLifecycleEvent(analyticsAsPrescriber());
|
|
371
|
+
for (const value of Object.values(typedByPrescriber)) expect(rawBodiesSent()).not.toContain(value);
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe("each method takes only the fields it reads, so a surface's own record types fit", () => {
|
|
376
|
+
it("sends from objects holding nothing but those fields", async () => {
|
|
377
|
+
const analytics = analyticsAsPrescriber();
|
|
378
|
+
await analytics.patientCreated({ id: "pat_9", demographic: null, contact: null, preferredPharmacy: null });
|
|
379
|
+
await analytics.draftPrescriptionAdded(
|
|
380
|
+
{
|
|
381
|
+
id: "rx_9",
|
|
382
|
+
treatment: prescription().treatment,
|
|
383
|
+
dispense: null,
|
|
384
|
+
instructions: null,
|
|
385
|
+
clinical: { notes: null },
|
|
386
|
+
},
|
|
387
|
+
"form",
|
|
388
|
+
);
|
|
389
|
+
await analytics.prescriptionSigned({ id: "rx_9" });
|
|
390
|
+
await analytics.orderSent({
|
|
391
|
+
id: "ord_9",
|
|
392
|
+
prescriptions: [{ id: "rx_9" }],
|
|
393
|
+
pharmacy: { fulfillmentType: ["MAIL_ORDER"] },
|
|
394
|
+
});
|
|
395
|
+
expect(sentEvents().map(({ event, properties }) => [event, ownProperties(properties)])).toEqual([
|
|
396
|
+
[
|
|
397
|
+
"Patient Created",
|
|
398
|
+
expect.objectContaining({ patientId: "pat_9", snap_first_name: false, snap_preferred_pharmacy: false }),
|
|
399
|
+
],
|
|
400
|
+
[
|
|
401
|
+
"Draft Prescription Added",
|
|
402
|
+
expect.objectContaining({ prescriptionId: "rx_9", snap_treatment: true, snap_notes: false }),
|
|
403
|
+
],
|
|
404
|
+
["Prescription Signed", { category: "ctaClicked", prescriptionId: "rx_9" }],
|
|
405
|
+
[
|
|
406
|
+
"Order Sent",
|
|
407
|
+
{
|
|
408
|
+
category: "ctaClicked",
|
|
409
|
+
orderId: "ord_9",
|
|
410
|
+
prescriptionCount: 1,
|
|
411
|
+
prescriptionIds: ["rx_9"],
|
|
412
|
+
fulfillmentType: "MAIL_ORDER",
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
]);
|
|
416
|
+
});
|
|
417
|
+
});
|