@photonhealth/client 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 +150 -5
- package/dist/analytics/lifecycleEvents.d.ts +32 -0
- package/dist/analytics/lifecycleEvents.d.ts.map +1 -0
- package/dist/analytics/lifecycleEvents.js +75 -0
- package/dist/analytics/lifecycleEvents.js.map +1 -0
- package/dist/analytics/track.d.ts +39 -0
- package/dist/analytics/track.d.ts.map +1 -0
- package/dist/analytics/track.js +91 -0
- package/dist/analytics/track.js.map +1 -0
- package/dist/api/changes/applyOption.d.ts +4 -1
- package/dist/api/changes/applyOption.d.ts.map +1 -1
- package/dist/api/changes/applyOption.js +23 -2
- package/dist/api/changes/applyOption.js.map +1 -1
- 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/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 +24 -5
- package/dist/photon/order.d.ts.map +1 -1
- package/dist/photon/order.js +85 -23
- 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 +16 -10
- package/dist/photon/session.d.ts.map +1 -1
- package/dist/photon/session.js +26 -11
- 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 +437 -0
- package/src/analytics/lifecycleEvents.ts +172 -0
- package/src/analytics/track.test.ts +231 -0
- package/src/analytics/track.ts +129 -0
- package/src/api/changes/applyOption.ts +25 -2
- 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/auth.ts +9 -10
- package/src/photon/choices.ts +2 -2
- package/src/photon/environments.ts +3 -1
- package/src/photon/index.ts +17 -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 +99 -24
- 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 +39 -16
- 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
package/README.md
CHANGED
|
@@ -37,15 +37,19 @@ await order.submit(); // the patient chooses a pharmacy
|
|
|
37
37
|
|
|
38
38
|
## The instance and auth
|
|
39
39
|
|
|
40
|
-
`photon({ environment, auth, organization?, appUrl? })` returns an instance. Every URL is inferred from
|
|
40
|
+
`photon({ environment, auth, organization?, appUrl?, disableAnalytics? })` returns an instance. Every URL is inferred from
|
|
41
41
|
`environment`: `neutron` (sandbox) or `photon` (production). `auth` is one of:
|
|
42
42
|
|
|
43
43
|
- **`{ clientId }`**: the client signs the prescriber in, in the browser (Auth0 authorization code with PKCE).
|
|
44
44
|
`ph.session` is a live object with `status`, `user`, `start()`, `signIn()` and `signOut()`. The access token stays
|
|
45
45
|
in memory; `localStorage` keeps the refresh token so a reload signs back in. A script on your page can read that
|
|
46
46
|
refresh token, so treat XSS on the page as a token leak. Auth0's refresh token rotation is the guard.
|
|
47
|
-
- **`{ getToken: () => Promise<string> }`**:
|
|
48
|
-
request. `ph.session` is `null`.
|
|
47
|
+
- **`{ getToken: () => Promise<string> }`**: the host supplies a token accepted by network-api, including a
|
|
48
|
+
patient token for patient-authorized reads and writes. The client calls it before each request. `ph.session` is `null`.
|
|
49
|
+
- **`{ clientId, clientSecret, organizationId }`**: your backend's own credentials, the machine (M2M) client Photon
|
|
50
|
+
made for your organization. The client gets a token by client credentials, keeps it until shortly before it
|
|
51
|
+
expires, and gets a new one if network-api refuses it. Servers only: `photon()` throws if a client secret is
|
|
52
|
+
passed in a browser. A token for another organization than `organizationId` is refused (`unauthorized`).
|
|
49
53
|
|
|
50
54
|
An instance built on a person's token is for that person. On a server, make one per request, never at module level.
|
|
51
55
|
`ph.ping()` checks the token without touching a record.
|
|
@@ -74,6 +78,147 @@ An instance built on a person's token is for that person. On a server, make one
|
|
|
74
78
|
methods (`rx.sign()`, `order.submit()`, …). An instance holds one object per record: the same patient opened twice,
|
|
75
79
|
or through an order, is the same object.
|
|
76
80
|
|
|
81
|
+
An order's record exposes `fulfillment`: its pharmacy-reported `state`, routing `history` (oldest first),
|
|
82
|
+
`routability` (`allowed` and a blocking `reason`), and open `exceptions`. Fulfillment is `null` for drafts or when
|
|
83
|
+
it couldn't be read. Its state is `null` until reported, and routability is `null` when it couldn't be determined;
|
|
84
|
+
routability reflects the order's state only, not organization settings.
|
|
85
|
+
|
|
86
|
+
A new order looks for its patient's draft orders once it has the patient, before any prescription on it has a
|
|
87
|
+
record (the read-only `Orders` query, once per patient). One draft is `order.snapshot.draft`: nothing is saved until
|
|
88
|
+
the prescriber decides. `order.continueDraft()` makes the order that draft. `order.startNew()` takes the draft's
|
|
89
|
+
prescriptions off it (not canceled) and starts over on it: network-api continues a patient's draft whenever an order is
|
|
90
|
+
saved, so an emptied draft is how a new order starts. Several drafts are `candidates`, picked with `order.pick(id)`.
|
|
91
|
+
|
|
92
|
+
In client 0.8.0, `order.state.exceptions` moves to `order.state.fulfillment.exceptions`. Use
|
|
93
|
+
`order.state?.fulfillment?.exceptions ?? []` when rendering exceptions. React 0.3.0 supports this contract.
|
|
94
|
+
|
|
95
|
+
## Read orders and pharmacy choices
|
|
96
|
+
|
|
97
|
+
`ph.orders(input?)` calls network-api's read-only `Orders` query. It returns
|
|
98
|
+
`{ orders, candidates, reason }`: order **snapshots**, or patient candidates when a patient filter is ambiguous.
|
|
99
|
+
It does not open, refresh or subscribe live objects, read prescriptions separately, or assign a pharmacy.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const ph = photon({ environment: "boson", auth: { getToken: async () => patientToken } });
|
|
103
|
+
const result = await ph.orders({
|
|
104
|
+
filter: { state: "SUBMITTED" }, // patient tokens are scoped to their own patient by the server
|
|
105
|
+
limit: 25,
|
|
106
|
+
routablePharmacies: {
|
|
107
|
+
pharmacy: { near: { address: { postalCode: "10001" } }, fulfillmentType: "PICK_UP" },
|
|
108
|
+
page: { limit: 20, offset: 0 },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const record = result.orders[0];
|
|
112
|
+
const page = record?.routablePharmacies;
|
|
113
|
+
const option = page?.options[0];
|
|
114
|
+
// After the patient explicitly chooses:
|
|
115
|
+
if (record && option?.pharmacy) {
|
|
116
|
+
await ph.order.update(record.id, { pharmacy: { pharmacy: { id: option.pharmacy.id } } });
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Omit `routablePharmacies` to skip the search. Pass `{}` to read marketplace choices. A sole match remains an
|
|
121
|
+
option: only an explicit write assigns it. Pages carry `options`, `totalCount` and `nextOffset`; sponsored additions
|
|
122
|
+
are excluded from `totalCount`. Keep the same search arguments when paging and restart at offset zero when they
|
|
123
|
+
change. `ChangeOption.matchReasons[].value` preserves distance as `{ displayValue, value, unit }`.
|
|
124
|
+
|
|
125
|
+
Order filters accept `id`, `patient` (id or demographic reference) and `state`; every supplied filter must match.
|
|
126
|
+
Read a specific order with `ph.orders({ filter: { id: "ord_…" }, routablePharmacies: {} })`, including its pharmacy
|
|
127
|
+
choices. An id with no order in the caller's scope returns an empty `orders` array. ID filtering is available in
|
|
128
|
+
client 0.9.1.
|
|
129
|
+
|
|
130
|
+
Results are newest first, default to 25 and cap at 100. The backend has no order-list pagination.
|
|
131
|
+
`ph.order.get(id)` still uses the id-only `GetOrder` mutation. Pharmacy searches through `sync` or `update` retain
|
|
132
|
+
their existing behavior and can assign a sole match.
|
|
133
|
+
|
|
134
|
+
## Shop records and preferred pharmacy
|
|
135
|
+
|
|
136
|
+
- `PrescriptionRecord.prescriber`: the assigned prescriber's id and structured name, or `null`. It does not attest
|
|
137
|
+
who signed. `fulfillment` carries state, `pharmacyEstimatedReadyAt` and unresolved prescription exceptions.
|
|
138
|
+
- `Pharmacy`: `logo`, `phone`, `hours`, `isOpen`, and `nextEvents`, all nullable when unknown. Hours include an IANA
|
|
139
|
+
timezone. Events are `{ type: "open" | "close", datetime }` or `{ type: "24hr" }`; keep serialized instants for
|
|
140
|
+
conversion to the viewer's timezone.
|
|
141
|
+
- `OrderRecord.organization`: customer identity and branding/patient UX settings, or `null` if unavailable.
|
|
142
|
+
`enablePatientRerouting` is separate from the order's routability. `enableAutomatedOps` is the backend's support
|
|
143
|
+
behavior setting. There is no featured-pharmacy setting in this contract.
|
|
144
|
+
- `PharmacyOffer`: **one price, one source, one prescription**. A source pricing a two-drug order reports two
|
|
145
|
+
offers, each with its own `prescriptionId`, `priceType`, `price` (`amount`, `retailAmount`, `promotions`),
|
|
146
|
+
`deliveryEstimate` and discount card. Nothing on it is a per-pharmacy total.
|
|
147
|
+
- **Totals and ranking are the caller's.** network-api supplies no rank, and this package deliberately ships
|
|
148
|
+
no rollup: aggregation is display policy and belongs with the screen that renders it. When you do sum,
|
|
149
|
+
group by `source` + `priceType` first — mixing price types or sources gives a number no patient can pay —
|
|
150
|
+
and sum only over the offers that quote the field you are summing. `amount` and `retailAmount` can cover
|
|
151
|
+
different prescriptions, so a savings figure derived from two independent sums can come out negative.
|
|
152
|
+
- A source mints **one card per prescription**, so a two-drug order carries two cards from the same source;
|
|
153
|
+
render per drug rather than one card for the order.
|
|
154
|
+
- `OrderRecord.offers.atPharmacy`: the offers priced at the pharmacy this order is routed to — `null` until one
|
|
155
|
+
is chosen, `[]` when one is chosen but nothing applies. Each offer carries `redemptionMethods`: what the patient
|
|
156
|
+
presents at the counter, tagged `{ type: "discountCard", bin, pcn, group, memberId, externalUrl }`. Read
|
|
157
|
+
`redemptionState` before treating an empty list as "nothing to present" — only `SETTLED` means final.
|
|
158
|
+
`SKIPPED` means nothing was attempted and none is coming; `PENDING` means one may still arrive, which is
|
|
159
|
+
what a pharmacy search reports for a discount-card source, since the card is minted when the order routes
|
|
160
|
+
there.
|
|
161
|
+
- `Change.after`: the resolved choice with its pharmacy and offers, including when a mutation applies a match
|
|
162
|
+
immediately. `resolvedId` remains available. Order reads and pharmacy options preserve any offers the backend
|
|
163
|
+
returns; the SDK does not manufacture pricing when the backend returns none.
|
|
164
|
+
|
|
165
|
+
Save a preferred pharmacy with `ph.patient.update(patientId, { preferredPharmacy: { id } })`.
|
|
166
|
+
A pharmacy reference can also use a name or location. Ambiguous results remain choices; pass a selected option
|
|
167
|
+
to `patient.choose(option)`. The saved value is `patient.state.preferredPharmacy`.
|
|
168
|
+
|
|
169
|
+
Client 0.9.0 adds required nullable fields to record types and `after` to `Change`; hosts constructing typed test
|
|
170
|
+
records should update them or use the fixtures in `@photonhealth/client/testing`. React 0.4.0 takes client `^0.9.0`.
|
|
171
|
+
Coupon/discount-card details (TECH-1171) will follow in a later release.
|
|
172
|
+
|
|
173
|
+
## Analytics
|
|
174
|
+
|
|
175
|
+
`ph.analytics.track(event, properties)` sends one event to Photon's analytics (`analytics-api.<env>.health`) as the
|
|
176
|
+
signed-in prescriber, with their token:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
await ph.analytics?.track("Order Sent", { orderId: order.id, integration: "mcp" });
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- Each event carries `providerId` (the prescriber's `usr_` id, asked of network-api once per signed-in user), `orgId`,
|
|
183
|
+
`environment`, `clientName`, `clientVersion` and `timestamp`. Your properties can set `timestamp` and add their own,
|
|
184
|
+
but `providerId`, `orgId` and `environment` always come from the instance.
|
|
185
|
+
- An instance made with `source: "MCP_CONNECTOR"` tags every event `integration: "mcp"`. An event's own `integration`
|
|
186
|
+
property wins (React's cards send `"react"`).
|
|
187
|
+
- **Never PHI.** Send ids, enums, booleans, counts and durations, never what a prescriber or patient typed. An event is
|
|
188
|
+
dropped unless its name is Title Case and every value is a string of at most 128 characters, a number, a boolean,
|
|
189
|
+
`null`, or a list of at most 50 such strings (ids, e.g. an order's `prescriptionIds`). These checks catch mistakes, not abuse.
|
|
190
|
+
- `track` never throws and never rejects. It resolves once the event is sent, or once it's dropped (the token isn't a
|
|
191
|
+
prescriber's, network-api can't say who they are, or analytics-api fails). Await it, or don't.
|
|
192
|
+
- `ph.analytics` is `null` for M2M credentials, without an `environment`, and with `photon({ disableAnalytics: true })`.
|
|
193
|
+
Analytics is on by default.
|
|
194
|
+
|
|
195
|
+
### Lifecycle events
|
|
196
|
+
|
|
197
|
+
`ph.analytics` sends the prescribing milestones by name, so every surface (React, MCP, Node) sends the same events and
|
|
198
|
+
properties as `<photon-prescribe-workflow>`. Each method takes the record and derives every property from ids, counts
|
|
199
|
+
and which fields are filled, never their values. Like `track`, each never rejects:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
await ph.analytics?.orderSent(order.state!);
|
|
203
|
+
await ph.analytics?.orderSent(order.state!, { sessionId });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
A surface's own properties (the last argument) ride along, but never replace what the record says.
|
|
207
|
+
|
|
208
|
+
Each method takes only the fields it reads (`PatientForLifecycleAnalytics`, `DraftPrescriptionForLifecycleAnalytics`, `PrescriptionForLifecycleAnalytics`,
|
|
209
|
+
`OrderForLifecycleAnalytics`), so a core record fits, and so does a surface's own record type with those fields.
|
|
210
|
+
|
|
211
|
+
| Method | Event | Properties (all `category: "ctaClicked"`) |
|
|
212
|
+
| ------------------------------------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
213
|
+
| `patientCreated(patient)` | Patient Created | `patientId`, `snap_*` for each patient form field |
|
|
214
|
+
| `patientUpdated(patient)` | Patient Updated | `patientId`, `snap_*` |
|
|
215
|
+
| `draftPrescriptionAdded(prescription, source)` | Draft Prescription Added | `prescriptionId`, `draftPrescriptionSource`, `snap_*` |
|
|
216
|
+
| `draftPrescriptionDeleted(prescriptionId)` | Draft Prescription Deleted | `prescriptionId` |
|
|
217
|
+
| `screeningAlertAcknowledged(alerts, buttonText)` | Screening Alert Acknowledged | `screeningAlertCount`, `buttonText` |
|
|
218
|
+
| `screeningAlertCanceled(alerts, buttonText)` | Screening Alert Canceled | `screeningAlertCount`, `buttonText` |
|
|
219
|
+
| `prescriptionSigned(prescription)` | Prescription Signed | `prescriptionId`, `screeningAlertCount` (the alerts the signature acknowledged; left out when not given) |
|
|
220
|
+
| `orderSent(order)` | Order Sent | `orderId`, `prescriptionCount`, `prescriptionIds`, `fulfillmentType` (`SEND_TO_PATIENT` when the patient chooses) |
|
|
221
|
+
|
|
77
222
|
## Errors
|
|
78
223
|
|
|
79
224
|
Anything the server answers about the data is a result, not an exception. Only failures that different data can't
|
|
@@ -82,8 +227,8 @@ fix throw a `PhotonError`, with `kind`: `network` (retryable), `unauthorized`, `
|
|
|
82
227
|
|
|
83
228
|
## Testing
|
|
84
229
|
|
|
85
|
-
`@photonhealth/client/testing` is for your own tests: `photonOver(
|
|
86
|
-
|
|
230
|
+
`@photonhealth/client/testing` is for your own tests: `photonOver(fakeNetworkApiClient(...))` is an instance over a
|
|
231
|
+
fake network-api client, with fixtures (`patient`, `rx`, `order`, …) to script it with. It may change before 2.0.0.
|
|
87
232
|
|
|
88
233
|
## License
|
|
89
234
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnalyticsProperties } from "./track.ts";
|
|
2
|
+
import type { OrderRecord, PatientRecord, PrescriptionRecord, ScreeningAlert } from "../photon/types.ts";
|
|
3
|
+
export type LifecycleEventName = "Patient Created" | "Patient Updated" | "Draft Prescription Added" | "Draft Prescription Deleted" | "Screening Alert Acknowledged" | "Screening Alert Canceled" | "Prescription Signed" | "Order Sent";
|
|
4
|
+
export type DraftPrescriptionSource = "form" | "template_prefill" | "prescription_id_prefill";
|
|
5
|
+
export type PatientForLifecycleAnalytics = Pick<PatientRecord, "id" | "demographic" | "contact" | "preferredPharmacy">;
|
|
6
|
+
export type DraftPrescriptionForLifecycleAnalytics = Pick<PrescriptionRecord, "id" | "treatment" | "dispense" | "instructions"> & {
|
|
7
|
+
clinical: {
|
|
8
|
+
notes: string | null;
|
|
9
|
+
} | null;
|
|
10
|
+
};
|
|
11
|
+
export type PrescriptionForLifecycleAnalytics = Pick<PrescriptionRecord, "id">;
|
|
12
|
+
export type SignedPrescriptionForLifecycleAnalytics = PrescriptionForLifecycleAnalytics & {
|
|
13
|
+
screeningAlerts?: readonly unknown[] | null;
|
|
14
|
+
};
|
|
15
|
+
export type OrderForLifecycleAnalytics = Pick<OrderRecord, "id"> & {
|
|
16
|
+
prescriptions: readonly PrescriptionForLifecycleAnalytics[];
|
|
17
|
+
pharmacy: Pick<NonNullable<OrderRecord["pharmacy"]>, "fulfillmentType"> | null;
|
|
18
|
+
};
|
|
19
|
+
export interface LifecycleAnalytics {
|
|
20
|
+
patientCreated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
21
|
+
patientUpdated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
22
|
+
draftPrescriptionAdded(prescription: DraftPrescriptionForLifecycleAnalytics, source: DraftPrescriptionSource, properties?: AnalyticsProperties): Promise<void>;
|
|
23
|
+
draftPrescriptionDeleted(prescriptionId: string, properties?: AnalyticsProperties): Promise<void>;
|
|
24
|
+
screeningAlertAcknowledged(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
|
|
25
|
+
screeningAlertCanceled(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
|
|
26
|
+
prescriptionSigned(prescription: SignedPrescriptionForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
27
|
+
orderSent(order: OrderForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
type Track = (event: string, properties?: AnalyticsProperties) => Promise<void>;
|
|
30
|
+
export declare function lifecycleAnalyticsSentWith(track: Track): LifecycleAnalytics;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=lifecycleEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEvents.d.ts","sourceRoot":"","sources":["../../src/analytics/lifecycleEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzG,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB,iBAAiB,GACjB,0BAA0B,GAC1B,4BAA4B,GAC5B,8BAA8B,GAC9B,0BAA0B,GAC1B,qBAAqB,GACrB,YAAY,CAAC;AAEjB,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAE9F,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS,GAAG,mBAAmB,CAAC,CAAC;AAEvH,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,kBAAkB,EAClB,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,cAAc,CACjD,GAAG;IACF,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;AAE/E,MAAM,MAAM,uCAAuC,GAAG,iCAAiC,GAAG;IACxF,eAAe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AAE,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/F;AAED,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAIhF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB,CA4C3E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const SEND_TO_PATIENT = "SEND_TO_PATIENT";
|
|
2
|
+
export function lifecycleAnalyticsSentWith(track) {
|
|
3
|
+
const sendCtaClicked = (event, derivedProperties, callerProperties = {}) => track(event, { ...callerProperties, category: "ctaClicked", ...derivedProperties });
|
|
4
|
+
return {
|
|
5
|
+
patientCreated: (patient, properties) => sendCtaClicked("Patient Created", patientProperties(patient), properties),
|
|
6
|
+
patientUpdated: (patient, properties) => sendCtaClicked("Patient Updated", patientProperties(patient), properties),
|
|
7
|
+
draftPrescriptionAdded: (prescription, source, properties) => sendCtaClicked("Draft Prescription Added", {
|
|
8
|
+
prescriptionId: prescription.id,
|
|
9
|
+
draftPrescriptionSource: source,
|
|
10
|
+
...prescriptionFormSnapshot(prescription),
|
|
11
|
+
}, properties),
|
|
12
|
+
draftPrescriptionDeleted: (prescriptionId, properties) => sendCtaClicked("Draft Prescription Deleted", { prescriptionId }, properties),
|
|
13
|
+
screeningAlertAcknowledged: (alerts, buttonText, properties) => sendCtaClicked("Screening Alert Acknowledged", { screeningAlertCount: alerts.length, buttonText }, properties),
|
|
14
|
+
screeningAlertCanceled: (alerts, buttonText, properties) => sendCtaClicked("Screening Alert Canceled", { screeningAlertCount: alerts.length, buttonText }, properties),
|
|
15
|
+
prescriptionSigned: (prescription, properties) => sendCtaClicked("Prescription Signed", { prescriptionId: prescription.id, ...screeningAlertsAcknowledgedBySigning(prescription) }, properties),
|
|
16
|
+
orderSent: (order, properties) => sendCtaClicked("Order Sent", {
|
|
17
|
+
orderId: order.id,
|
|
18
|
+
prescriptionCount: order.prescriptions.length,
|
|
19
|
+
prescriptionIds: order.prescriptions.map((prescription) => prescription.id),
|
|
20
|
+
fulfillmentType: fulfillmentTypeOf(order),
|
|
21
|
+
}, properties),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function patientProperties(patient) {
|
|
25
|
+
return { patientId: patient.id, ...patientFormSnapshot(patient) };
|
|
26
|
+
}
|
|
27
|
+
function screeningAlertsAcknowledgedBySigning(prescription) {
|
|
28
|
+
return prescription.screeningAlerts ? { screeningAlertCount: prescription.screeningAlerts.length } : {};
|
|
29
|
+
}
|
|
30
|
+
function fulfillmentTypeOf(order) {
|
|
31
|
+
if (!order.pharmacy)
|
|
32
|
+
return SEND_TO_PATIENT;
|
|
33
|
+
const offeredTypes = order.pharmacy.fulfillmentType ?? [];
|
|
34
|
+
return offeredTypes.length === 1 ? offeredTypes[0] : null;
|
|
35
|
+
}
|
|
36
|
+
function patientFormSnapshot(patient) {
|
|
37
|
+
const { demographic, contact, preferredPharmacy } = patient;
|
|
38
|
+
return completedFieldSnapshot({
|
|
39
|
+
firstName: demographic?.name.first,
|
|
40
|
+
lastName: demographic?.name.last,
|
|
41
|
+
dateOfBirth: demographic?.dateOfBirth,
|
|
42
|
+
phone: contact?.phone,
|
|
43
|
+
sex: demographic?.sex,
|
|
44
|
+
gender: demographic?.gender,
|
|
45
|
+
email: contact?.email,
|
|
46
|
+
address_street1: contact?.address?.street1,
|
|
47
|
+
address_street2: contact?.address?.street2,
|
|
48
|
+
address_city: contact?.address?.city,
|
|
49
|
+
address_state: contact?.address?.state,
|
|
50
|
+
address_zip: contact?.address?.postalCode,
|
|
51
|
+
preferredPharmacy,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function prescriptionFormSnapshot(prescription) {
|
|
55
|
+
const { treatment, dispense, instructions, clinical } = prescription;
|
|
56
|
+
return completedFieldSnapshot({
|
|
57
|
+
treatment,
|
|
58
|
+
dispenseQuantity: dispense?.quantity,
|
|
59
|
+
dispenseUnit: dispense?.unit,
|
|
60
|
+
daysSupply: dispense?.daysSupply,
|
|
61
|
+
refills: dispense?.refillsAllowed,
|
|
62
|
+
instructions,
|
|
63
|
+
notes: clinical?.notes,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function completedFieldSnapshot(valuesByFieldName) {
|
|
67
|
+
return Object.fromEntries(Object.entries(valuesByFieldName).map(([fieldName, value]) => [snapshotPropertyName(fieldName), isFilled(value)]));
|
|
68
|
+
}
|
|
69
|
+
function snapshotPropertyName(fieldName) {
|
|
70
|
+
return `snap_${fieldName.replace(/([A-Z])/g, "_$1").toLowerCase()}`;
|
|
71
|
+
}
|
|
72
|
+
function isFilled(value) {
|
|
73
|
+
return value !== undefined && value !== null && value !== "" && value !== false;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=lifecycleEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEvents.js","sourceRoot":"","sources":["../../src/analytics/lifecycleEvents.ts"],"names":[],"mappings":"AA+DA,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAE1C,MAAM,UAAU,0BAA0B,CAAC,KAAY;IACrD,MAAM,cAAc,GAAG,CACrB,KAAyB,EACzB,iBAAsC,EACtC,mBAAwC,EAAE,EAC1C,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,iBAAiB,EAAE,CAAC,CAAC;IAEzF,OAAO;QACL,cAAc,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,cAAc,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;QAClH,cAAc,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,cAAc,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;QAClH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
|
+
* An event's properties: ids, enums, booleans, counts, durations, timestamps, and lists of ids (an order's
|
|
5
|
+
* prescriptions). Never PHI, never a value typed.
|
|
6
|
+
*/
|
|
7
|
+
export type AnalyticsProperties = Record<string, string | number | boolean | null | string[]>;
|
|
8
|
+
/** Where an instance's events go: analytics-api and the token to send them with. */
|
|
9
|
+
export interface AnalyticsTarget {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
token(): Promise<string>;
|
|
12
|
+
readonly clientName: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Which Photon surface the events come from (`"mcp"`), when the instance knows: every event carries it as
|
|
15
|
+
* `integration`, unless the event's properties set their own (React's cards send `"react"`).
|
|
16
|
+
*/
|
|
17
|
+
readonly integration?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** `ph.analytics`: send prescribing events to Photon's analytics, as the signed-in prescriber. */
|
|
20
|
+
export interface Analytics extends AnalyticsTarget, LifecycleAnalytics {
|
|
21
|
+
/**
|
|
22
|
+
* Sends one event as the signed-in prescriber, with `providerId`, `orgId`, `environment`, `clientName`,
|
|
23
|
+
* `clientVersion`, `timestamp` and, when the instance knows it, `integration` added. Never rejects, and never throws: it resolves once the event is sent, or
|
|
24
|
+
* once it's dropped — no prescriber behind the token, network-api can't say who it is, analytics-api fails, or the
|
|
25
|
+
* event breaks the guards (a Title Case name; string, number, boolean or null values, or lists of at most
|
|
26
|
+
* {@link MAX_LIST_LENGTH} strings; strings of at most {@link MAX_PROPERTY_LENGTH} characters). The guards catch mistakes, not abuse: analytics-api checks only the token.
|
|
27
|
+
*/
|
|
28
|
+
track(event: string, properties?: AnalyticsProperties): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare const MAX_PROPERTY_LENGTH = 128;
|
|
31
|
+
export declare const MAX_LIST_LENGTH = 50;
|
|
32
|
+
interface Instance {
|
|
33
|
+
environment: EnvironmentUrls | null;
|
|
34
|
+
/** The instance's caller's `usr_` id, or null when it isn't a prescriber. Throws when network-api can't say. */
|
|
35
|
+
providerId(): Promise<string | null>;
|
|
36
|
+
}
|
|
37
|
+
export declare function analyticsFor(target: AnalyticsTarget, instance: Instance): Analytics;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../src/analytics/track.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAA8B,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE3F;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC,CAAC;AAE9F,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,kGAAkG;AAClG,MAAM,WAAW,SAAU,SAAQ,eAAe,EAAE,kBAAkB;IACpE;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,eAAe,KAAK,CAAC;AAGlC,UAAU,QAAQ;IAChB,WAAW,EAAE,eAAe,GAAG,IAAI,CAAC;IACpC,gHAAgH;IAChH,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACtC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CA2DnF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { clientVersion } from "../meta/version.js";
|
|
2
|
+
import { lifecycleAnalyticsSentWith } from "./lifecycleEvents.js";
|
|
3
|
+
export const MAX_PROPERTY_LENGTH = 128;
|
|
4
|
+
export const MAX_LIST_LENGTH = 50;
|
|
5
|
+
const TITLE_CASE = /^[A-Z][A-Za-z]*( [A-Z][A-Za-z]*)*$/;
|
|
6
|
+
export function analyticsFor(target, instance) {
|
|
7
|
+
const providerIdsBySub = new Map();
|
|
8
|
+
const providerIdFor = (sub) => {
|
|
9
|
+
let providerId = providerIdsBySub.get(sub);
|
|
10
|
+
if (!providerId) {
|
|
11
|
+
providerId = instance.providerId();
|
|
12
|
+
providerId.catch(() => providerIdsBySub.delete(sub)); // ask again next time
|
|
13
|
+
providerIdsBySub.set(sub, providerId);
|
|
14
|
+
}
|
|
15
|
+
return providerId;
|
|
16
|
+
};
|
|
17
|
+
const track = async (event, properties = {}) => {
|
|
18
|
+
try {
|
|
19
|
+
if (!wellFormed(event, properties))
|
|
20
|
+
return;
|
|
21
|
+
const timestamp = new Date().toISOString();
|
|
22
|
+
const token = await target.token();
|
|
23
|
+
const claims = unverifiedJwtClaims(token);
|
|
24
|
+
if (typeof claims.sub !== "string")
|
|
25
|
+
return;
|
|
26
|
+
const providerId = await providerIdFor(claims.sub);
|
|
27
|
+
if (!providerId)
|
|
28
|
+
return;
|
|
29
|
+
const orgId = typeof claims.org_id === "string" ? claims.org_id : null;
|
|
30
|
+
await fetch(`${target.url}/event`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
"x-photon-auth-token": token,
|
|
35
|
+
"x-photon-auth-token-type": "auth0", // analytics-api returns 400 without it
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
event,
|
|
39
|
+
userId: providerId,
|
|
40
|
+
properties: {
|
|
41
|
+
clientName: target.clientName,
|
|
42
|
+
clientVersion,
|
|
43
|
+
timestamp,
|
|
44
|
+
...(target.integration ? { integration: target.integration } : {}),
|
|
45
|
+
...properties,
|
|
46
|
+
// Who and where come from the instance, never the caller.
|
|
47
|
+
providerId,
|
|
48
|
+
orgId,
|
|
49
|
+
environment: instance.environment?.name ?? null,
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
keepalive: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// never block the prescriber
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
url: target.url,
|
|
61
|
+
token: () => target.token(),
|
|
62
|
+
clientName: target.clientName,
|
|
63
|
+
integration: target.integration ?? null,
|
|
64
|
+
track,
|
|
65
|
+
...lifecycleAnalyticsSentWith(track),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function wellFormed(event, properties) {
|
|
69
|
+
if (typeof event !== "string" || !TITLE_CASE.test(event))
|
|
70
|
+
return false;
|
|
71
|
+
if (!properties || typeof properties !== "object")
|
|
72
|
+
return false;
|
|
73
|
+
const shortString = (value) => typeof value === "string" && value.length <= MAX_PROPERTY_LENGTH;
|
|
74
|
+
return Object.values(properties).every((value) => value === null ||
|
|
75
|
+
value === undefined ||
|
|
76
|
+
typeof value === "number" ||
|
|
77
|
+
typeof value === "boolean" ||
|
|
78
|
+
shortString(value) ||
|
|
79
|
+
(Array.isArray(value) && value.length <= MAX_LIST_LENGTH && value.every(shortString)));
|
|
80
|
+
}
|
|
81
|
+
function unverifiedJwtClaims(jwt) {
|
|
82
|
+
try {
|
|
83
|
+
const payload = jwt.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
84
|
+
const bytes = Uint8Array.from(atob(payload), (c) => c.charCodeAt(0));
|
|
85
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return {};
|
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C,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAA4B,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -35,7 +35,10 @@ export declare function optionPath(option: ApplicableOption & {
|
|
|
35
35
|
argument: string;
|
|
36
36
|
}): string;
|
|
37
37
|
export declare function applyOption<T>(input: T, option: ApplicableOption): T;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Put a picked value at its path in the input. A locator (`….id`) replaces its siblings (the typed name and
|
|
40
|
+
* any search criteria, such as a pharmacy's `near`) but keeps the fields in KEPT_BESIDE_LOCATOR.
|
|
41
|
+
*/
|
|
39
42
|
export declare function applyAt<T>(input: T, path: string, value: unknown): T;
|
|
40
43
|
export {};
|
|
41
44
|
//# sourceMappingURL=applyOption.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyOption.d.ts","sourceRoot":"","sources":["../../../src/api/changes/applyOption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AAEH,KAAK,gBAAgB,GAAG,IAAI,CAAC,oBAAoB,EAAE,UAAU,GAAG,OAAO,GAAG,WAAW,CAAC,GAAG;IACvF,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,gBAAgB,KAAG,MAAM,IAAI,gBAAgB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CACtC,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAW1E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,K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;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAapE"}
|
|
@@ -63,14 +63,35 @@ export function applyOption(input, option) {
|
|
|
63
63
|
}
|
|
64
64
|
return applyAt(input, optionPath(option), parseOptionValue(option.value));
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Fields beside a locator that describe the entry rather than find it, so a pick keeps them. A medication
|
|
68
|
+
* history entry's `status` is required (MedicationHistoryEntryInput), so dropping it fails the write.
|
|
69
|
+
*/
|
|
70
|
+
const KEPT_BESIDE_LOCATOR = new Set(["status"]);
|
|
71
|
+
/**
|
|
72
|
+
* Put a picked value at its path in the input. A locator (`….id`) replaces its siblings (the typed name and
|
|
73
|
+
* any search criteria, such as a pharmacy's `near`) but keeps the fields in KEPT_BESIDE_LOCATOR.
|
|
74
|
+
*/
|
|
67
75
|
export function applyAt(input, path, value) {
|
|
68
76
|
const segments = path.split(".").filter(Boolean);
|
|
69
77
|
const last = segments.at(-1);
|
|
70
78
|
if (segments.length > 1 && LOCATORS.has(last)) {
|
|
71
79
|
const parentPath = segments.slice(0, -1).join(".");
|
|
72
|
-
|
|
80
|
+
const parent = valueAt(input, segments.slice(0, -1));
|
|
81
|
+
const kept = parent && typeof parent === "object" && !Array.isArray(parent)
|
|
82
|
+
? Object.fromEntries(Object.entries(parent).filter(([key]) => KEPT_BESIDE_LOCATOR.has(key)))
|
|
83
|
+
: {};
|
|
84
|
+
return setAtPath(input, parentPath, { ...kept, [last]: value });
|
|
73
85
|
}
|
|
74
86
|
return setAtPath(input, path, value);
|
|
75
87
|
}
|
|
88
|
+
function valueAt(input, segments) {
|
|
89
|
+
let node = input;
|
|
90
|
+
for (const segment of segments) {
|
|
91
|
+
if (!node || typeof node !== "object")
|
|
92
|
+
return undefined;
|
|
93
|
+
node = node[segment];
|
|
94
|
+
}
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
76
97
|
//# sourceMappingURL=applyOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyOption.js","sourceRoot":"","sources":["../../../src/api/changes/applyOption.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAwB,EAAqD,EAAE,CAC5G,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAgC;IAC/D,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,OAAO,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC7F,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,KAAQ,EAAE,IAAY,EAAE,KAAc;IACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,KAAa,EAAW,EAAE;QACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC;QACjC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM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AAkB;IACjD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACxD,IAAI,GAAI,IAAgC,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/api/client.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { TypedDocumentString } from "../gql/graphql.ts";
|
|
|
9
9
|
interface NetworkClientOptions {
|
|
10
10
|
/** e.g. https://network.boson.health/graphql */
|
|
11
11
|
url: string;
|
|
12
|
-
/** Returns
|
|
12
|
+
/** Returns a token accepted by network-api, including a patient token or a prescriber's access token. */
|
|
13
13
|
getToken: () => Promise<string>;
|
|
14
14
|
/** How this client is surfaced. Embeds should pass EMBEDDABLE_COMPONENT. */
|
|
15
15
|
source?: RequestSource;
|
|
@@ -17,6 +17,11 @@ interface NetworkClientOptions {
|
|
|
17
17
|
clientName?: string;
|
|
18
18
|
sourceVersion?: string;
|
|
19
19
|
fetch?: typeof fetch;
|
|
20
|
+
/**
|
|
21
|
+
* When network-api refuses the token (401, UNAUTHENTICATED): drop it — the call is then tried once more, with a new one. For a
|
|
22
|
+
* token core gets itself (client credentials); a host's `getToken` or a prescriber's session doesn't retry.
|
|
23
|
+
*/
|
|
24
|
+
onUnauthorized?: () => void;
|
|
20
25
|
}
|
|
21
26
|
/** Variables for an operation, minus the metadata the client fills in. */
|
|
22
27
|
export type OperationVariables<V> = Omit<V, "metadata">;
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,M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