@photonhealth/client 0.0.0-stage → 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/LICENSE +15 -0
- package/README.md +234 -2
- 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/changes/applyOption.d.ts +41 -0
- package/dist/api/changes/applyOption.d.ts.map +1 -0
- package/dist/api/changes/applyOption.js +76 -0
- package/dist/api/changes/applyOption.js.map +1 -0
- package/dist/api/changes/classifyChanges.d.ts +9 -0
- package/dist/api/changes/classifyChanges.d.ts.map +1 -0
- package/dist/api/changes/classifyChanges.js +2 -0
- package/dist/api/changes/classifyChanges.js.map +1 -0
- package/dist/api/changes/index.d.ts +3 -0
- package/dist/api/changes/index.d.ts.map +1 -0
- package/dist/api/changes/index.js +3 -0
- package/dist/api/changes/index.js.map +1 -0
- package/dist/api/client.d.ts +48 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +91 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/health.d.ts +4 -0
- package/dist/api/health.d.ts.map +1 -0
- package/dist/api/health.js +6 -0
- package/dist/api/health.js.map +1 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +1 -0
- 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/order.d.ts +33 -0
- package/dist/api/order.d.ts.map +1 -0
- package/dist/api/order.js +33 -0
- package/dist/api/order.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 +36 -0
- package/dist/api/patient.d.ts.map +1 -0
- package/dist/api/patient.js +33 -0
- package/dist/api/patient.js.map +1 -0
- package/dist/api/prescription.d.ts +37 -0
- package/dist/api/prescription.d.ts.map +1 -0
- package/dist/api/prescription.js +39 -0
- package/dist/api/prescription.js.map +1 -0
- package/dist/api/results.d.ts +30 -0
- package/dist/api/results.d.ts.map +1 -0
- package/dist/api/results.js +26 -0
- package/dist/api/results.js.map +1 -0
- package/dist/gql/gql.d.ts +29 -0
- package/dist/gql/gql.d.ts.map +1 -0
- package/dist/gql/gql.js +15 -0
- package/dist/gql/gql.js.map +1 -0
- package/dist/gql/graphql.d.ts +18618 -0
- package/dist/gql/graphql.d.ts.map +1 -0
- package/dist/gql/graphql.js +6579 -0
- package/dist/gql/graphql.js.map +1 -0
- package/dist/gql/index.d.ts +2 -0
- package/dist/gql/index.d.ts.map +1 -0
- package/dist/gql/index.js +3 -0
- package/dist/gql/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- 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 +52 -0
- package/dist/photon/auth.d.ts.map +1 -0
- package/dist/photon/auth.js +30 -0
- package/dist/photon/auth.js.map +1 -0
- package/dist/photon/choices.d.ts +44 -0
- package/dist/photon/choices.d.ts.map +1 -0
- package/dist/photon/choices.js +58 -0
- package/dist/photon/choices.js.map +1 -0
- package/dist/photon/context.d.ts +29 -0
- package/dist/photon/context.d.ts.map +1 -0
- package/dist/photon/context.js +2 -0
- package/dist/photon/context.js.map +1 -0
- package/dist/photon/environments.d.ts +27 -0
- package/dist/photon/environments.d.ts.map +1 -0
- package/dist/photon/environments.js +27 -0
- package/dist/photon/environments.js.map +1 -0
- package/dist/photon/errors.d.ts +26 -0
- package/dist/photon/errors.d.ts.map +1 -0
- package/dist/photon/errors.js +42 -0
- package/dist/photon/errors.js.map +1 -0
- package/dist/photon/index.d.ts +26 -0
- package/dist/photon/index.d.ts.map +1 -0
- package/dist/photon/index.js +12 -0
- package/dist/photon/index.js.map +1 -0
- package/dist/photon/inputs.d.ts +7 -0
- package/dist/photon/inputs.d.ts.map +1 -0
- package/dist/photon/inputs.js +25 -0
- package/dist/photon/inputs.js.map +1 -0
- package/dist/photon/links.d.ts +68 -0
- package/dist/photon/links.d.ts.map +1 -0
- package/dist/photon/links.js +187 -0
- package/dist/photon/links.js.map +1 -0
- package/dist/photon/live.d.ts +62 -0
- package/dist/photon/live.d.ts.map +1 -0
- package/dist/photon/live.js +107 -0
- package/dist/photon/live.js.map +1 -0
- 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 +14 -0
- package/dist/photon/map.d.ts.map +1 -0
- package/dist/photon/map.js +311 -0
- package/dist/photon/map.js.map +1 -0
- package/dist/photon/order.d.ts +168 -0
- package/dist/photon/order.d.ts.map +1 -0
- package/dist/photon/order.js +558 -0
- package/dist/photon/order.js.map +1 -0
- 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 +80 -0
- package/dist/photon/patient.d.ts.map +1 -0
- package/dist/photon/patient.js +347 -0
- package/dist/photon/patient.js.map +1 -0
- package/dist/photon/photon.d.ts +188 -0
- package/dist/photon/photon.d.ts.map +1 -0
- package/dist/photon/photon.js +395 -0
- package/dist/photon/photon.js.map +1 -0
- package/dist/photon/prescription.d.ts +145 -0
- package/dist/photon/prescription.d.ts.map +1 -0
- package/dist/photon/prescription.js +418 -0
- package/dist/photon/prescription.js.map +1 -0
- package/dist/photon/session.d.ts +89 -0
- package/dist/photon/session.d.ts.map +1 -0
- package/dist/photon/session.js +352 -0
- package/dist/photon/session.js.map +1 -0
- package/dist/photon/types.d.ts +643 -0
- package/dist/photon/types.d.ts.map +1 -0
- package/dist/photon/types.js +7 -0
- package/dist/photon/types.js.map +1 -0
- package/dist/test-utils/msw.d.ts +23 -0
- package/dist/test-utils/msw.d.ts.map +1 -0
- package/dist/test-utils/msw.js +51 -0
- package/dist/test-utils/msw.js.map +1 -0
- package/dist/testing/fakeNetworkApiClient.d.ts +39 -0
- package/dist/testing/fakeNetworkApiClient.d.ts.map +1 -0
- package/dist/testing/fakeNetworkApiClient.js +56 -0
- package/dist/testing/fakeNetworkApiClient.js.map +1 -0
- package/dist/testing/fixtures.d.ts +1098 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +200 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/package.json +67 -4
- package/src/analytics/lifecycleEvents.test.ts +417 -0
- package/src/analytics/lifecycleEvents.ts +155 -0
- package/src/api/changes/applyOption.ts +103 -0
- package/src/api/changes/classifyChanges.ts +10 -0
- package/src/api/changes/index.ts +2 -0
- package/src/api/client.ts +149 -0
- package/src/api/health.ts +7 -0
- package/src/api/index.ts +24 -0
- package/src/api/me.ts +7 -0
- package/src/api/order.ts +64 -0
- package/src/api/orders.ts +8 -0
- package/src/api/patient.ts +67 -0
- package/src/api/prescription.ts +86 -0
- package/src/api/results.ts +45 -0
- package/src/gql/gql.ts +68 -0
- package/src/gql/graphql.ts +9027 -0
- package/src/gql/index.ts +2 -0
- package/src/index.ts +14 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +1 -0
- package/src/operations/fragments.graphql +497 -0
- package/src/operations/health.graphql +4 -0
- package/src/operations/me.graphql +38 -0
- package/src/operations/order.graphql +42 -0
- package/src/operations/orders.graphql +35 -0
- package/src/operations/patient.graphql +62 -0
- package/src/operations/prescription.graphql +90 -0
- package/src/photon/analytics.ts +129 -0
- package/src/photon/auth.ts +69 -0
- package/src/photon/choices.ts +79 -0
- package/src/photon/context.ts +30 -0
- package/src/photon/environments.ts +49 -0
- package/src/photon/errors.ts +56 -0
- package/src/photon/index.ts +49 -0
- package/src/photon/inputs.ts +24 -0
- package/src/photon/links.ts +197 -0
- package/src/photon/live.ts +135 -0
- package/src/photon/machine.ts +90 -0
- package/src/photon/map.ts +371 -0
- package/src/photon/order.test.ts +142 -0
- package/src/photon/order.ts +661 -0
- package/src/photon/orders.ts +42 -0
- package/src/photon/patient.ts +386 -0
- package/src/photon/photon.ts +646 -0
- package/src/photon/prescription.ts +506 -0
- package/src/photon/session.ts +454 -0
- package/src/photon/types.ts +583 -0
- package/src/test-utils/msw.ts +72 -0
- package/src/testing/fakeNetworkApiClient.ts +56 -0
- package/src/testing/fixtures.ts +233 -0
- package/src/testing.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Photon Health
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,235 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @photonhealth/client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Photon's prescribing API for JavaScript: `photon()` gives you patients, prescriptions and orders as **live
|
|
4
|
+
objects**. Their state stays current, you can subscribe to them, and their methods await the web calls. The
|
|
5
|
+
workflow rules live inside them. Framework-agnostic, with zero runtime dependencies: it runs in the browser, Node
|
|
6
|
+
and Deno.
|
|
7
|
+
|
|
8
|
+
React cards built on it: [`@photonhealth/react`](https://www.npmjs.com/package/@photonhealth/react).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Release candidates are published under the `rc` tag:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @photonhealth/client@rc
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { photon } from "@photonhealth/client";
|
|
22
|
+
|
|
23
|
+
const ph = photon({ environment: "neutron", auth: { clientId } }); // or { getToken }: your own sign-in
|
|
24
|
+
|
|
25
|
+
const { patient } = await ph.patient.sync({
|
|
26
|
+
demographic: { name: { first: "Paige", last: "Turner" }, dateOfBirth: "1990-01-01", sex: "FEMALE" },
|
|
27
|
+
});
|
|
28
|
+
patient.subscribe(() => render(patient.state)); // UIs; a backend just awaits
|
|
29
|
+
|
|
30
|
+
const { prescription: rx } = await ph.prescription.sync({ patient: { id: patient.id }, treatment: { id: "med_10" } });
|
|
31
|
+
await rx.update({ instructions: "1 tab PO daily", dispense: { quantity: 30, daysSupply: 30 } });
|
|
32
|
+
await rx.sign(); // the prescriber's approval of exactly what they saw
|
|
33
|
+
|
|
34
|
+
const { order } = await ph.order.sync({ patient: { id: patient.id }, prescriptions: { add: [{ id: rx.id }] } });
|
|
35
|
+
await order.submit(); // the patient chooses a pharmacy
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## The instance and auth
|
|
39
|
+
|
|
40
|
+
`photon({ environment, auth, organization?, appUrl?, disableAnalytics? })` returns an instance. Every URL is inferred from
|
|
41
|
+
`environment`: `neutron` (sandbox) or `photon` (production). `auth` is one of:
|
|
42
|
+
|
|
43
|
+
- **`{ clientId }`**: the client signs the prescriber in, in the browser (Auth0 authorization code with PKCE).
|
|
44
|
+
`ph.session` is a live object with `status`, `user`, `start()`, `signIn()` and `signOut()`. The access token stays
|
|
45
|
+
in memory; `localStorage` keeps the refresh token so a reload signs back in. A script on your page can read that
|
|
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> }`**: 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`).
|
|
53
|
+
|
|
54
|
+
An instance built on a person's token is for that person. On a server, make one per request, never at module level.
|
|
55
|
+
`ph.ping()` checks the token without touching a record.
|
|
56
|
+
|
|
57
|
+
## Get, sync, update
|
|
58
|
+
|
|
59
|
+
`ph.patient`, `ph.prescription` and `ph.order` each have the same three calls:
|
|
60
|
+
|
|
61
|
+
| Call | Means |
|
|
62
|
+
| ------------------- | -------------------------------------------------------------------------------------------- |
|
|
63
|
+
| `get(id)` | Read the record. Changes nothing. Returns the live object, or `null` when there's no record. |
|
|
64
|
+
| `sync(input)` | Send what's known, with or without an id: the server finds, matches, creates or updates. |
|
|
65
|
+
| `update(id, input)` | Change that one record: only the fields given change. |
|
|
66
|
+
|
|
67
|
+
`sync` and `update` return `{ <object>, candidates, changes }`:
|
|
68
|
+
|
|
69
|
+
- **the live object**, with the record the server settled on, or still without one (`id: null`).
|
|
70
|
+
- **`candidates`**: the records it might be, when the server isn't certain. The client never picks one for you:
|
|
71
|
+
pick with `patient.pick(id)`, `prescription.continueDraft(id)` or `order.pick(id)`.
|
|
72
|
+
- **`changes`**: what was written, what wasn't and why, and any choices offered.
|
|
73
|
+
|
|
74
|
+
## Live objects
|
|
75
|
+
|
|
76
|
+
`Patient`, `Prescription` and `Order` each have `id`, `state` (the record), `status` (`idle` / `loading` / `saving` /
|
|
77
|
+
`error`), `changes`, `subscribe(listener)`, `sync(input)`, `update(input)` and `reload()`, plus their workflow
|
|
78
|
+
methods (`rx.sign()`, `order.submit()`, …). An instance holds one object per record: the same patient opened twice,
|
|
79
|
+
or through an order, is the same object.
|
|
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` |
|
|
220
|
+
| `orderSent(order)` | Order Sent | `orderId`, `prescriptionCount`, `prescriptionIds`, `fulfillmentType` (`SEND_TO_PATIENT` when the patient chooses) |
|
|
221
|
+
|
|
222
|
+
## Errors
|
|
223
|
+
|
|
224
|
+
Anything the server answers about the data is a result, not an exception. Only failures that different data can't
|
|
225
|
+
fix throw a `PhotonError`, with `kind`: `network` (retryable), `unauthorized`, `upstream` (`retryable` says),
|
|
226
|
+
`invalid` (a request shape the server rejected) or `refused` (an object's rule said no).
|
|
227
|
+
|
|
228
|
+
## Testing
|
|
229
|
+
|
|
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.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
ISC
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AnalyticsProperties } from "../photon/analytics.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 OrderForLifecycleAnalytics = Pick<OrderRecord, "id"> & {
|
|
13
|
+
prescriptions: readonly PrescriptionForLifecycleAnalytics[];
|
|
14
|
+
pharmacy: Pick<NonNullable<OrderRecord["pharmacy"]>, "fulfillmentType"> | null;
|
|
15
|
+
};
|
|
16
|
+
export interface LifecycleAnalytics {
|
|
17
|
+
patientCreated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
18
|
+
patientUpdated(patient: PatientForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
19
|
+
draftPrescriptionAdded(prescription: DraftPrescriptionForLifecycleAnalytics, source: DraftPrescriptionSource, properties?: AnalyticsProperties): Promise<void>;
|
|
20
|
+
draftPrescriptionDeleted(prescriptionId: string, properties?: AnalyticsProperties): Promise<void>;
|
|
21
|
+
screeningAlertAcknowledged(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
|
|
22
|
+
screeningAlertCanceled(alerts: readonly ScreeningAlert[], buttonText: string, properties?: AnalyticsProperties): Promise<void>;
|
|
23
|
+
prescriptionSigned(prescription: PrescriptionForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
24
|
+
orderSent(order: OrderForLifecycleAnalytics, properties?: AnalyticsProperties): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
type Track = (event: string, properties?: AnalyticsProperties) => Promise<void>;
|
|
27
|
+
export declare function lifecycleAnalyticsSentWith(track: Track): LifecycleAnalytics;
|
|
28
|
+
export {};
|
|
29
|
+
//# 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,wBAAwB,CAAC;AAClE,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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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,CAwC3E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 }, 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 fulfillmentTypeOf(order) {
|
|
28
|
+
if (!order.pharmacy)
|
|
29
|
+
return SEND_TO_PATIENT;
|
|
30
|
+
const offeredTypes = order.pharmacy.fulfillmentType ?? [];
|
|
31
|
+
return offeredTypes.length === 1 ? offeredTypes[0] : null;
|
|
32
|
+
}
|
|
33
|
+
function patientFormSnapshot(patient) {
|
|
34
|
+
const { demographic, contact, preferredPharmacy } = patient;
|
|
35
|
+
return completedFieldSnapshot({
|
|
36
|
+
firstName: demographic?.name.first,
|
|
37
|
+
lastName: demographic?.name.last,
|
|
38
|
+
dateOfBirth: demographic?.dateOfBirth,
|
|
39
|
+
phone: contact?.phone,
|
|
40
|
+
sex: demographic?.sex,
|
|
41
|
+
gender: demographic?.gender,
|
|
42
|
+
email: contact?.email,
|
|
43
|
+
address_street1: contact?.address?.street1,
|
|
44
|
+
address_street2: contact?.address?.street2,
|
|
45
|
+
address_city: contact?.address?.city,
|
|
46
|
+
address_state: contact?.address?.state,
|
|
47
|
+
address_zip: contact?.address?.postalCode,
|
|
48
|
+
preferredPharmacy,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function prescriptionFormSnapshot(prescription) {
|
|
52
|
+
const { treatment, dispense, instructions, clinical } = prescription;
|
|
53
|
+
return completedFieldSnapshot({
|
|
54
|
+
treatment,
|
|
55
|
+
dispenseQuantity: dispense?.quantity,
|
|
56
|
+
dispenseUnit: dispense?.unit,
|
|
57
|
+
daysSupply: dispense?.daysSupply,
|
|
58
|
+
refills: dispense?.refillsAllowed,
|
|
59
|
+
instructions,
|
|
60
|
+
notes: clinical?.notes,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function completedFieldSnapshot(valuesByFieldName) {
|
|
64
|
+
return Object.fromEntries(Object.entries(valuesByFieldName).map(([fieldName, value]) => [snapshotPropertyName(fieldName), isFilled(value)]));
|
|
65
|
+
}
|
|
66
|
+
function snapshotPropertyName(fieldName) {
|
|
67
|
+
return `snap_${fieldName.replace(/([A-Z])/g, "_$1").toLowerCase()}`;
|
|
68
|
+
}
|
|
69
|
+
function isFilled(value) {
|
|
70
|
+
return value !== undefined && value !== null && value !== "" && value !== false;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=lifecycleEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEvents.js","sourceRoot":"","sources":["../../src/analytics/lifecycleEvents.ts"],"names":[],"mappings":"AAwDA,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,sBAAsB,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,CAC3D,cAAc,CACZ,0BAA0B,EAC1B;YACE,cAAc,EAAE,YAAY,CAAC,EAAE;YAC/B,uBAAuB,EAAE,MAAM;YAC/B,GAAG,wBAAwB,CAAC,YAAY,CAAC;SAC1C,EACD,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AAc;QACjC,YAAY;QACZ,KAAK,EAAE,QAAQ,EAAE,KAAK;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB,CAAC,iBAA0C;IACxE,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAClH,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,OAAO,QAAQ,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,KAAK,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ChoiceFieldsFragment } from "../../gql/graphql.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Apply a Choice to the input you sent, producing the input to send next.
|
|
4
|
+
*
|
|
5
|
+
* A Change's options are structured next actions: `argument` is a dotted path
|
|
6
|
+
* into the operation's input (numeric segments index arrays) and `value` is
|
|
7
|
+
* what to set there. Picking "Amoxicillin 500 MG Oral Capsule" from a
|
|
8
|
+
* DISAMBIGUATION change is just: applyOption(input, option) → re-send.
|
|
9
|
+
*
|
|
10
|
+
* Options with a null `argument` mean "call a different operation" — they
|
|
11
|
+
* can't be applied inline; check `isInlineOption` first.
|
|
12
|
+
*
|
|
13
|
+
* Pure and immutable: the original input is never modified.
|
|
14
|
+
*/
|
|
15
|
+
type ApplicableOption = Pick<ChoiceFieldsFragment, "argument" | "value" | "operation"> & {
|
|
16
|
+
/** How the option is shown ("Lisinopril Oral Tablet 10 MG"). */
|
|
17
|
+
displayName?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const isInlineOption: (option: ApplicableOption) => option is ApplicableOption & {
|
|
20
|
+
argument: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `value` arrives as a string. Structured values (objects, arrays, booleans,
|
|
24
|
+
* null) are JSON-encoded; anything else — including numeric-looking ids — is
|
|
25
|
+
* kept as a string so an id like "0123" is never turned into 123.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseOptionValue(value: string | null | undefined): unknown;
|
|
28
|
+
export declare function setAtPath<T>(input: T, path: string, value: unknown): T;
|
|
29
|
+
/**
|
|
30
|
+
* An option's argument path, relative to the mutation's input. network-api sometimes roots it at the
|
|
31
|
+
* argument name — `patient.clinical.allergies.add.0.id` for the `patient` mutation (boson,
|
|
32
|
+
* 2026-09-29) — and sometimes not (`treatment.id` for `prescription`); drop that leading name.
|
|
33
|
+
*/
|
|
34
|
+
export declare function optionPath(option: ApplicableOption & {
|
|
35
|
+
argument: string;
|
|
36
|
+
}): string;
|
|
37
|
+
export declare function applyOption<T>(input: T, option: ApplicableOption): T;
|
|
38
|
+
/** Put a picked value at its path in the input; a locator (`….id`) replaces its siblings (the typed name). */
|
|
39
|
+
export declare function applyAt<T>(input: T, path: string, value: unknown): T;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=applyOption.d.ts.map
|
|
@@ -0,0 +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,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAsBtE;AAUD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAKlF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAKpE;AAED,8GAA8G;AAC9G,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAQpE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const isInlineOption = (option) => typeof option.argument === "string" && option.argument.length > 0;
|
|
2
|
+
/**
|
|
3
|
+
* `value` arrives as a string. Structured values (objects, arrays, booleans,
|
|
4
|
+
* null) are JSON-encoded; anything else — including numeric-looking ids — is
|
|
5
|
+
* kept as a string so an id like "0123" is never turned into 123.
|
|
6
|
+
*/
|
|
7
|
+
export function parseOptionValue(value) {
|
|
8
|
+
if (value == null)
|
|
9
|
+
return null;
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
if (/^[[{]/.test(trimmed) || trimmed === "true" || trimmed === "false" || trimmed === "null") {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(trimmed);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export function setAtPath(input, path, value) {
|
|
22
|
+
const segments = path.split(".").filter(Boolean);
|
|
23
|
+
if (segments.length === 0)
|
|
24
|
+
return input;
|
|
25
|
+
const write = (node, depth) => {
|
|
26
|
+
const segment = segments[depth];
|
|
27
|
+
const index = /^\d+$/.test(segment) ? Number(segment) : null;
|
|
28
|
+
const isLast = depth === segments.length - 1;
|
|
29
|
+
if (index !== null) {
|
|
30
|
+
const array = Array.isArray(node) ? [...node] : [];
|
|
31
|
+
array[index] = isLast ? value : write(array[index], depth + 1);
|
|
32
|
+
return array;
|
|
33
|
+
}
|
|
34
|
+
const object = node && typeof node === "object" && !Array.isArray(node) ? { ...node } : {};
|
|
35
|
+
object[segment] = isLast
|
|
36
|
+
? value
|
|
37
|
+
: write(object[segment], depth + 1);
|
|
38
|
+
return object;
|
|
39
|
+
};
|
|
40
|
+
return write(input, 0);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reference inputs (TreatmentReferenceInput, AllergyReferenceInput, …) take exactly ONE locator.
|
|
44
|
+
* Choosing an option like `treatment.id` must replace the free text `treatment.name` the user typed,
|
|
45
|
+
* not sit beside it — so setting a locator clears its sibling locators. (Seen on boson: a
|
|
46
|
+
* DISAMBIGUATION change returns options `{ argument: "treatment.id", value: "med_…" }`.)
|
|
47
|
+
*/
|
|
48
|
+
const LOCATORS = new Set(["id", "name", "rxNormId", "ndc", "upc", "icd10Code", "externalId"]);
|
|
49
|
+
/**
|
|
50
|
+
* An option's argument path, relative to the mutation's input. network-api sometimes roots it at the
|
|
51
|
+
* argument name — `patient.clinical.allergies.add.0.id` for the `patient` mutation (boson,
|
|
52
|
+
* 2026-09-29) — and sometimes not (`treatment.id` for `prescription`); drop that leading name.
|
|
53
|
+
*/
|
|
54
|
+
export function optionPath(option) {
|
|
55
|
+
const root = `${option.operation}.`;
|
|
56
|
+
const path = option.argument.startsWith(root) ? option.argument.slice(root.length) : option.argument;
|
|
57
|
+
// network-api's pharmacy options omit the OrderPharmacyInput wrapper.
|
|
58
|
+
return option.operation === "order" && path === "pharmacy.id" ? "pharmacy.pharmacy.id" : path;
|
|
59
|
+
}
|
|
60
|
+
export function applyOption(input, option) {
|
|
61
|
+
if (!isInlineOption(option)) {
|
|
62
|
+
throw new Error(`Option "${option.operation}" has no argument path; it calls a different operation.`);
|
|
63
|
+
}
|
|
64
|
+
return applyAt(input, optionPath(option), parseOptionValue(option.value));
|
|
65
|
+
}
|
|
66
|
+
/** Put a picked value at its path in the input; a locator (`….id`) replaces its siblings (the typed name). */
|
|
67
|
+
export function applyAt(input, path, value) {
|
|
68
|
+
const segments = path.split(".").filter(Boolean);
|
|
69
|
+
const last = segments.at(-1);
|
|
70
|
+
if (segments.length > 1 && LOCATORS.has(last)) {
|
|
71
|
+
const parentPath = segments.slice(0, -1).join(".");
|
|
72
|
+
return setAtPath(input, parentPath, { [last]: value });
|
|
73
|
+
}
|
|
74
|
+
return setAtPath(input, path, value);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=applyOption.js.map
|
|
@@ -0,0 +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,I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CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,8GAA8G;AAC9G,MAAM,UAAU,OAAO,CAAI,KAAQ,EAAE,IAAY,EAAE,KAAc;IAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnD,OAAO,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChangeFieldsFragment } from "../../gql/graphql.ts";
|
|
2
|
+
export type Change = ChangeFieldsFragment;
|
|
3
|
+
/** Every payload's changes; `status` says which took effect. */
|
|
4
|
+
export interface ChangeSet {
|
|
5
|
+
changes: Change[];
|
|
6
|
+
/** The input that produced these changes: network-api doesn't echo what it tried to resolve. */
|
|
7
|
+
sent?: unknown;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=classifyChanges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifyChanges.d.ts","sourceRoot":"","sources":["../../../src/api/changes/classifyChanges.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,MAAM,MAAM,MAAM,GAAG,oBAAoB,CAAC;AAE1C,gEAAgE;AAChE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifyChanges.js","sourceRoot":"","sources":["../../../src/api/changes/classifyChanges.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/changes/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/changes/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RequestSource } from "../gql/graphql.ts";
|
|
2
|
+
import type { TypedDocumentString } from "../gql/graphql.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The only thing that talks HTTP. Framework-agnostic and auth-library-agnostic:
|
|
5
|
+
* tokens come in through `getToken`, and every call gets RequestMetadata stamped
|
|
6
|
+
* with the operation's name, so the server can tell a SyncPrescription from an
|
|
7
|
+
* UpdatePrescription even though both hit `prescription`.
|
|
8
|
+
*/
|
|
9
|
+
interface NetworkClientOptions {
|
|
10
|
+
/** e.g. https://network.boson.health/graphql */
|
|
11
|
+
url: string;
|
|
12
|
+
/** Returns a token accepted by network-api, including a patient token or a prescriber's access token. */
|
|
13
|
+
getToken: () => Promise<string>;
|
|
14
|
+
/** How this client is surfaced. Embeds should pass EMBEDDABLE_COMPONENT. */
|
|
15
|
+
source?: RequestSource;
|
|
16
|
+
/** Prefix for RequestMetadata.client; the operation name is appended: "photon-rx/UpdateOrder". */
|
|
17
|
+
clientName?: string;
|
|
18
|
+
sourceVersion?: string;
|
|
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;
|
|
25
|
+
}
|
|
26
|
+
/** Variables for an operation, minus the metadata the client fills in. */
|
|
27
|
+
export type OperationVariables<V> = Omit<V, "metadata">;
|
|
28
|
+
export interface NetworkClient {
|
|
29
|
+
execute<R, V>(document: TypedDocumentString<R, V>, variables: OperationVariables<V>, options?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<R>;
|
|
32
|
+
}
|
|
33
|
+
/** Transport / GraphQL-level failure: bad token, network down, invalid document. */
|
|
34
|
+
export declare class NetworkTransportError extends Error {
|
|
35
|
+
readonly operationName: string;
|
|
36
|
+
readonly status?: number | undefined;
|
|
37
|
+
readonly code?: string | undefined;
|
|
38
|
+
readonly errors?: unknown[] | undefined;
|
|
39
|
+
constructor(message: string, operationName: string, status?: number | undefined, code?: string | undefined, errors?: unknown[] | undefined);
|
|
40
|
+
}
|
|
41
|
+
export declare function operationNameOf(document: {
|
|
42
|
+
toString(): string;
|
|
43
|
+
}): string;
|
|
44
|
+
/** Every string in the variables, trimmed — so no field ever reaches network-api with stray whitespace. */
|
|
45
|
+
export declare function trimStrings<T>(value: T): T;
|
|
46
|
+
export declare function createNetworkClient(options: NetworkClientOptions): NetworkClient;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +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,MAA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