@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.
Files changed (218) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +234 -2
  3. package/dist/analytics/lifecycleEvents.d.ts +29 -0
  4. package/dist/analytics/lifecycleEvents.d.ts.map +1 -0
  5. package/dist/analytics/lifecycleEvents.js +72 -0
  6. package/dist/analytics/lifecycleEvents.js.map +1 -0
  7. package/dist/api/changes/applyOption.d.ts +41 -0
  8. package/dist/api/changes/applyOption.d.ts.map +1 -0
  9. package/dist/api/changes/applyOption.js +76 -0
  10. package/dist/api/changes/applyOption.js.map +1 -0
  11. package/dist/api/changes/classifyChanges.d.ts +9 -0
  12. package/dist/api/changes/classifyChanges.d.ts.map +1 -0
  13. package/dist/api/changes/classifyChanges.js +2 -0
  14. package/dist/api/changes/classifyChanges.js.map +1 -0
  15. package/dist/api/changes/index.d.ts +3 -0
  16. package/dist/api/changes/index.d.ts.map +1 -0
  17. package/dist/api/changes/index.js +3 -0
  18. package/dist/api/changes/index.js.map +1 -0
  19. package/dist/api/client.d.ts +48 -0
  20. package/dist/api/client.d.ts.map +1 -0
  21. package/dist/api/client.js +91 -0
  22. package/dist/api/client.js.map +1 -0
  23. package/dist/api/health.d.ts +4 -0
  24. package/dist/api/health.d.ts.map +1 -0
  25. package/dist/api/health.js +6 -0
  26. package/dist/api/health.js.map +1 -0
  27. package/dist/api/index.d.ts +24 -0
  28. package/dist/api/index.d.ts.map +1 -0
  29. package/dist/api/index.js +23 -0
  30. package/dist/api/index.js.map +1 -0
  31. package/dist/api/me.d.ts +37 -0
  32. package/dist/api/me.d.ts.map +1 -0
  33. package/dist/api/me.js +6 -0
  34. package/dist/api/me.js.map +1 -0
  35. package/dist/api/order.d.ts +33 -0
  36. package/dist/api/order.d.ts.map +1 -0
  37. package/dist/api/order.js +33 -0
  38. package/dist/api/order.js.map +1 -0
  39. package/dist/api/orders.d.ts +1047 -0
  40. package/dist/api/orders.d.ts.map +1 -0
  41. package/dist/api/orders.js +7 -0
  42. package/dist/api/orders.js.map +1 -0
  43. package/dist/api/patient.d.ts +36 -0
  44. package/dist/api/patient.d.ts.map +1 -0
  45. package/dist/api/patient.js +33 -0
  46. package/dist/api/patient.js.map +1 -0
  47. package/dist/api/prescription.d.ts +37 -0
  48. package/dist/api/prescription.d.ts.map +1 -0
  49. package/dist/api/prescription.js +39 -0
  50. package/dist/api/prescription.js.map +1 -0
  51. package/dist/api/results.d.ts +30 -0
  52. package/dist/api/results.d.ts.map +1 -0
  53. package/dist/api/results.js +26 -0
  54. package/dist/api/results.js.map +1 -0
  55. package/dist/gql/gql.d.ts +29 -0
  56. package/dist/gql/gql.d.ts.map +1 -0
  57. package/dist/gql/gql.js +15 -0
  58. package/dist/gql/gql.js.map +1 -0
  59. package/dist/gql/graphql.d.ts +18618 -0
  60. package/dist/gql/graphql.d.ts.map +1 -0
  61. package/dist/gql/graphql.js +6579 -0
  62. package/dist/gql/graphql.js.map +1 -0
  63. package/dist/gql/index.d.ts +2 -0
  64. package/dist/gql/index.d.ts.map +1 -0
  65. package/dist/gql/index.js +3 -0
  66. package/dist/gql/index.js.map +1 -0
  67. package/dist/index.d.ts +15 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +15 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/meta/version.d.ts +2 -0
  72. package/dist/meta/version.d.ts.map +1 -0
  73. package/dist/meta/version.js +2 -0
  74. package/dist/meta/version.js.map +1 -0
  75. package/dist/photon/analytics.d.ts +39 -0
  76. package/dist/photon/analytics.d.ts.map +1 -0
  77. package/dist/photon/analytics.js +91 -0
  78. package/dist/photon/analytics.js.map +1 -0
  79. package/dist/photon/auth.d.ts +52 -0
  80. package/dist/photon/auth.d.ts.map +1 -0
  81. package/dist/photon/auth.js +30 -0
  82. package/dist/photon/auth.js.map +1 -0
  83. package/dist/photon/choices.d.ts +44 -0
  84. package/dist/photon/choices.d.ts.map +1 -0
  85. package/dist/photon/choices.js +58 -0
  86. package/dist/photon/choices.js.map +1 -0
  87. package/dist/photon/context.d.ts +29 -0
  88. package/dist/photon/context.d.ts.map +1 -0
  89. package/dist/photon/context.js +2 -0
  90. package/dist/photon/context.js.map +1 -0
  91. package/dist/photon/environments.d.ts +27 -0
  92. package/dist/photon/environments.d.ts.map +1 -0
  93. package/dist/photon/environments.js +27 -0
  94. package/dist/photon/environments.js.map +1 -0
  95. package/dist/photon/errors.d.ts +26 -0
  96. package/dist/photon/errors.d.ts.map +1 -0
  97. package/dist/photon/errors.js +42 -0
  98. package/dist/photon/errors.js.map +1 -0
  99. package/dist/photon/index.d.ts +26 -0
  100. package/dist/photon/index.d.ts.map +1 -0
  101. package/dist/photon/index.js +12 -0
  102. package/dist/photon/index.js.map +1 -0
  103. package/dist/photon/inputs.d.ts +7 -0
  104. package/dist/photon/inputs.d.ts.map +1 -0
  105. package/dist/photon/inputs.js +25 -0
  106. package/dist/photon/inputs.js.map +1 -0
  107. package/dist/photon/links.d.ts +68 -0
  108. package/dist/photon/links.d.ts.map +1 -0
  109. package/dist/photon/links.js +187 -0
  110. package/dist/photon/links.js.map +1 -0
  111. package/dist/photon/live.d.ts +62 -0
  112. package/dist/photon/live.d.ts.map +1 -0
  113. package/dist/photon/live.js +107 -0
  114. package/dist/photon/live.js.map +1 -0
  115. package/dist/photon/machine.d.ts +28 -0
  116. package/dist/photon/machine.d.ts.map +1 -0
  117. package/dist/photon/machine.js +53 -0
  118. package/dist/photon/machine.js.map +1 -0
  119. package/dist/photon/map.d.ts +14 -0
  120. package/dist/photon/map.d.ts.map +1 -0
  121. package/dist/photon/map.js +311 -0
  122. package/dist/photon/map.js.map +1 -0
  123. package/dist/photon/order.d.ts +168 -0
  124. package/dist/photon/order.d.ts.map +1 -0
  125. package/dist/photon/order.js +558 -0
  126. package/dist/photon/order.js.map +1 -0
  127. package/dist/photon/orders.d.ts +5 -0
  128. package/dist/photon/orders.d.ts.map +1 -0
  129. package/dist/photon/orders.js +39 -0
  130. package/dist/photon/orders.js.map +1 -0
  131. package/dist/photon/patient.d.ts +80 -0
  132. package/dist/photon/patient.d.ts.map +1 -0
  133. package/dist/photon/patient.js +347 -0
  134. package/dist/photon/patient.js.map +1 -0
  135. package/dist/photon/photon.d.ts +188 -0
  136. package/dist/photon/photon.d.ts.map +1 -0
  137. package/dist/photon/photon.js +395 -0
  138. package/dist/photon/photon.js.map +1 -0
  139. package/dist/photon/prescription.d.ts +145 -0
  140. package/dist/photon/prescription.d.ts.map +1 -0
  141. package/dist/photon/prescription.js +418 -0
  142. package/dist/photon/prescription.js.map +1 -0
  143. package/dist/photon/session.d.ts +89 -0
  144. package/dist/photon/session.d.ts.map +1 -0
  145. package/dist/photon/session.js +352 -0
  146. package/dist/photon/session.js.map +1 -0
  147. package/dist/photon/types.d.ts +643 -0
  148. package/dist/photon/types.d.ts.map +1 -0
  149. package/dist/photon/types.js +7 -0
  150. package/dist/photon/types.js.map +1 -0
  151. package/dist/test-utils/msw.d.ts +23 -0
  152. package/dist/test-utils/msw.d.ts.map +1 -0
  153. package/dist/test-utils/msw.js +51 -0
  154. package/dist/test-utils/msw.js.map +1 -0
  155. package/dist/testing/fakeNetworkApiClient.d.ts +39 -0
  156. package/dist/testing/fakeNetworkApiClient.d.ts.map +1 -0
  157. package/dist/testing/fakeNetworkApiClient.js +56 -0
  158. package/dist/testing/fakeNetworkApiClient.js.map +1 -0
  159. package/dist/testing/fixtures.d.ts +1098 -0
  160. package/dist/testing/fixtures.d.ts.map +1 -0
  161. package/dist/testing/fixtures.js +200 -0
  162. package/dist/testing/fixtures.js.map +1 -0
  163. package/dist/testing.d.ts +11 -0
  164. package/dist/testing.d.ts.map +1 -0
  165. package/dist/testing.js +10 -0
  166. package/dist/testing.js.map +1 -0
  167. package/package.json +67 -4
  168. package/src/analytics/lifecycleEvents.test.ts +417 -0
  169. package/src/analytics/lifecycleEvents.ts +155 -0
  170. package/src/api/changes/applyOption.ts +103 -0
  171. package/src/api/changes/classifyChanges.ts +10 -0
  172. package/src/api/changes/index.ts +2 -0
  173. package/src/api/client.ts +149 -0
  174. package/src/api/health.ts +7 -0
  175. package/src/api/index.ts +24 -0
  176. package/src/api/me.ts +7 -0
  177. package/src/api/order.ts +64 -0
  178. package/src/api/orders.ts +8 -0
  179. package/src/api/patient.ts +67 -0
  180. package/src/api/prescription.ts +86 -0
  181. package/src/api/results.ts +45 -0
  182. package/src/gql/gql.ts +68 -0
  183. package/src/gql/graphql.ts +9027 -0
  184. package/src/gql/index.ts +2 -0
  185. package/src/index.ts +14 -0
  186. package/src/meta/version.test.ts +10 -0
  187. package/src/meta/version.ts +1 -0
  188. package/src/operations/fragments.graphql +497 -0
  189. package/src/operations/health.graphql +4 -0
  190. package/src/operations/me.graphql +38 -0
  191. package/src/operations/order.graphql +42 -0
  192. package/src/operations/orders.graphql +35 -0
  193. package/src/operations/patient.graphql +62 -0
  194. package/src/operations/prescription.graphql +90 -0
  195. package/src/photon/analytics.ts +129 -0
  196. package/src/photon/auth.ts +69 -0
  197. package/src/photon/choices.ts +79 -0
  198. package/src/photon/context.ts +30 -0
  199. package/src/photon/environments.ts +49 -0
  200. package/src/photon/errors.ts +56 -0
  201. package/src/photon/index.ts +49 -0
  202. package/src/photon/inputs.ts +24 -0
  203. package/src/photon/links.ts +197 -0
  204. package/src/photon/live.ts +135 -0
  205. package/src/photon/machine.ts +90 -0
  206. package/src/photon/map.ts +371 -0
  207. package/src/photon/order.test.ts +142 -0
  208. package/src/photon/order.ts +661 -0
  209. package/src/photon/orders.ts +42 -0
  210. package/src/photon/patient.ts +386 -0
  211. package/src/photon/photon.ts +646 -0
  212. package/src/photon/prescription.ts +506 -0
  213. package/src/photon/session.ts +454 -0
  214. package/src/photon/types.ts +583 -0
  215. package/src/test-utils/msw.ts +72 -0
  216. package/src/testing/fakeNetworkApiClient.ts +56 -0
  217. package/src/testing/fixtures.ts +233 -0
  218. package/src/testing.ts +25 -0
@@ -0,0 +1,558 @@
1
+ import { getOrder, submitOrder, syncOrder, updateOrder } from "../api/index.js";
2
+ import { asksForAddress, choicesIn, withChoice } from "./choices.js";
3
+ import { PhotonError, refuse, toPhotonError } from "./errors.js";
4
+ import { LiveRecord } from "./live.js";
5
+ import { noChanges, toChanges, toOrder, toOrderCandidate, toPrescription } from "./map.js";
6
+ import { Patient } from "./patient.js";
7
+ import { readOrders } from "./orders.js";
8
+ import { Prescription } from "./prescription.js";
9
+ /** What makes a patient reachable — the contact request clears when this changes. */
10
+ const contactOf = (p) => {
11
+ const c = p?.state?.contact;
12
+ return JSON.stringify([
13
+ c?.phone ?? null,
14
+ c?.email ?? null,
15
+ c?.address?.street1 ?? null,
16
+ c?.address?.postalCode ?? null,
17
+ ]);
18
+ };
19
+ /** One alert, comparable: the same finding from the order's screening and a prescription's. */
20
+ const alertKey = (a) => JSON.stringify([a.type, a.severity, a.description, a.involvedEntities.map((e) => e.id).sort()]);
21
+ /** A new line nothing was written in: no record, no drug picked, no template, nothing entered. */
22
+ const untouched = (line) => !line.id && !line.snapshot.pick && !line.templateId && Object.keys(line.entered).length === 0;
23
+ /** network-api won't start another order for a patient whose last one was sent. */
24
+ const alreadySent = () => refuse("This patient's last order was already sent, and Photon can't start another for them yet.");
25
+ /**
26
+ * The order is the treatment: a patient, its prescriptions, and sending them. Its draft is saved as it goes,
27
+ * like the other objects: once its patient and a prescription have records, it's synced to the server (the
28
+ * patient's draft order, or a new one) — `id` fills in — and every prescription that gets a record goes on
29
+ * it (UpdateOrder). `submit()` sends it. Opened from an id (e.g. an order an agent drafted), it comes with its
30
+ * patient and prescriptions.
31
+ */
32
+ export class Order extends LiveRecord {
33
+ #ctx;
34
+ #unsubscribePatient = null;
35
+ #unsubscribeLines = [];
36
+ #contactAtRequest = null;
37
+ /** A save the server turned down for this patient and these prescriptions: not retried until they change. */
38
+ #declined = null;
39
+ /**
40
+ * Prescriptions given by your system's id: there's no read by it, so they go on the server's order as they
41
+ * are, and become lines when it answers.
42
+ */
43
+ #refs = [];
44
+ /** The patient whose draft orders were looked for: once per patient. */
45
+ #lookedFor = null;
46
+ /** Held before the record, so a draft created once its lines are ready includes the pharmacy input. */
47
+ #pharmacy;
48
+ constructor(ctx, record, extra = {}) {
49
+ super(record, { patient: null, prescriptions: [], candidates: [], draft: null, contactRequest: null }, extra.changes);
50
+ this.#ctx = ctx;
51
+ this.#setLines(extra.prescriptions ?? []);
52
+ if (extra.patient)
53
+ this.#follow(extra.patient);
54
+ }
55
+ onRecord() {
56
+ this.#ctx.register(this);
57
+ }
58
+ get patient() {
59
+ return this.snapshot.patient;
60
+ }
61
+ get prescriptions() {
62
+ return this.snapshot.prescriptions;
63
+ }
64
+ /** Sent (or canceled): its patient and prescriptions are final. A submitted order can still choose a pharmacy. */
65
+ get final() {
66
+ return Boolean(this.state && this.state.state !== "DRAFT");
67
+ }
68
+ /** Pharmacy choices from the latest response, with addresses and offers; take one with `choose`. */
69
+ get pharmacyOptions() {
70
+ return choicesIn(this.changes).flatMap((change) => change.options.filter((option) => option.pharmacy !== null));
71
+ }
72
+ /** Everything's saved: no call in flight on the order, its patient or any of its prescriptions. */
73
+ get saved() {
74
+ const busy = (o) => o?.snapshot.status === "loading" || o?.snapshot.status === "saving";
75
+ return !busy(this) && !busy(this.patient) && !this.prescriptions.some(busy);
76
+ }
77
+ /**
78
+ * Screening alerts no one has acknowledged: the order's own (its prescriptions screened together) and each
79
+ * unsigned prescription's, less any a signed prescription carries — its signature acknowledged that one. A
80
+ * caller that never reads the prescriptions still sees every open alert here; a page shows them by Send.
81
+ * They never stop a send.
82
+ */
83
+ get unacknowledgedAlerts() {
84
+ const acknowledged = new Set(this.prescriptions.flatMap((rx) => (rx.signed ? rx.state.screeningAlerts.map(alertKey) : [])));
85
+ const open = [
86
+ ...(this.state?.screeningAlerts ?? []),
87
+ ...this.prescriptions.flatMap((rx) => (rx.signed ? [] : (rx.state?.screeningAlerts ?? []))),
88
+ ];
89
+ const seen = new Set();
90
+ return open.filter((a) => {
91
+ const key = alertKey(a);
92
+ if (acknowledged.has(key) || seen.has(key))
93
+ return false;
94
+ seen.add(key);
95
+ return true;
96
+ });
97
+ }
98
+ /**
99
+ * Ready to submit: a patient with a record, at least one prescription, every one signed, no contact the
100
+ * server asked for still missing — and everything saved.
101
+ */
102
+ get readyToSend() {
103
+ const lines = this.prescriptions;
104
+ return (!this.final &&
105
+ Boolean(this.patient?.id) &&
106
+ lines.length > 0 &&
107
+ lines.every((rx) => rx.signed) &&
108
+ !this.snapshot.contactRequest &&
109
+ this.saved);
110
+ }
111
+ /**
112
+ * Its patient and lines change here at once; what has records is saved to the server's draft order (synced
113
+ * first, if it has none yet). See `OrderUpdate`.
114
+ */
115
+ sync(input) {
116
+ return this.#change(input);
117
+ }
118
+ /** The same, for an order that has its id (it must): its lines go on or off it with UpdateOrder. */
119
+ update(input) {
120
+ if (!this.id)
121
+ return Promise.reject(new PhotonError("invalid", "update() needs the order's id; until it has one, sync()."));
122
+ return this.#change(input);
123
+ }
124
+ async #change(input) {
125
+ if (this.final) {
126
+ if (this.state.state !== "SUBMITTED" ||
127
+ !input.pharmacy ||
128
+ input.patient !== undefined ||
129
+ input.prescriptions !== undefined)
130
+ throw refuse(`This order is ${this.state.state.toLowerCase()}; only a submitted order's pharmacy can change.`);
131
+ return this.#save([], input.pharmacy);
132
+ }
133
+ if (!this.id && input.pharmacy !== undefined)
134
+ this.#pharmacy = input.pharmacy;
135
+ // What's local applies at once (a card shows it in the same render); only ids wait for a read.
136
+ if (input.patient !== undefined) {
137
+ const patient = this.#patientFor(input.patient);
138
+ this.#setPatient(patient instanceof Promise ? await patient : patient);
139
+ }
140
+ const { add: given = [], remove = [] } = input.prescriptions ?? {};
141
+ const lines = given.flatMap((rx) => {
142
+ if (rx instanceof Prescription || !("externalId" in rx))
143
+ return [this.#lineFor(rx)];
144
+ this.#refs = [...this.#refs, { externalId: rx.externalId }];
145
+ return [];
146
+ });
147
+ const adding = lines.some((l) => l instanceof Promise) ? await Promise.all(lines) : lines;
148
+ const removing = remove.flatMap((rx) => this.prescriptions.filter((line) => line === rx || (!(rx instanceof Prescription) && line.id === rx.id)));
149
+ const kept = this.prescriptions.filter((line) => !removing.includes(line));
150
+ // A prescription is one line, however many times it's given (`rx=rx_1&rx=rx_1`); each template line is its own.
151
+ this.#setLines([...kept, ...adding.filter((line, i) => !kept.includes(line) && adding.indexOf(line) === i)]);
152
+ // No patient yet: a prescription added for one brings them.
153
+ const theirs = this.patient ? null : adding.find((line) => line.patientId)?.patientId;
154
+ if (theirs) {
155
+ const patient = this.#patientFor({ id: theirs });
156
+ this.#setPatient(patient instanceof Promise ? await patient : patient);
157
+ }
158
+ if (this.patient?.id)
159
+ for (const line of adding)
160
+ void line.sync({ patient: { id: this.patient.id } }).catch(() => { });
161
+ return this.#save(removing.filter((line) => this.#onServer(line.id)).map((line) => ({ id: line.id })), input.pharmacy);
162
+ }
163
+ /** Apply a pharmacy option through the same order mutation; no additional client-side matching. */
164
+ async choose(option) {
165
+ if (option.operation !== "order" || option.path !== "pharmacy.pharmacy.id")
166
+ throw new PhotonError("invalid", "Choose a pharmacy option returned for this order.");
167
+ const input = withChoice({}, option);
168
+ return this.id ? this.update(input) : this.sync(input);
169
+ }
170
+ /**
171
+ * One of `candidates`: this becomes that draft order (read), and this order's prescriptions go on it — a line
172
+ * nothing was written in yet gives way to the draft's, so it can be sent as it is.
173
+ */
174
+ pick(orderId) {
175
+ return this.run("loading", async () => {
176
+ const result = await this.#settle(await getOrder(this.#ctx.client, orderId));
177
+ this.patch({ candidates: [], draft: null });
178
+ if (this.prescriptions.some((l) => l.id))
179
+ this.#setLines(this.prescriptions.filter((l) => !untouched(l)));
180
+ return result;
181
+ }).then(() => this.#save());
182
+ }
183
+ /** Go on with the patient's draft order (`draft`): this becomes that order, and what's added goes on it. */
184
+ continueDraft() {
185
+ if (!this.snapshot.draft)
186
+ return Promise.reject(new PhotonError("invalid", "This order has no draft to continue."));
187
+ return this.pick(this.snapshot.draft.id);
188
+ }
189
+ /**
190
+ * Start over instead of continuing the patient's draft order (`draft`): its prescriptions come off it (taken off,
191
+ * not canceled) and this order is that draft, holding only what's written here. network-api continues a patient's
192
+ * draft whenever an order is saved, so emptying it is how a new order starts. Turned down, the draft is still
193
+ * there to decide on (its reason in `changes`).
194
+ */
195
+ startNew() {
196
+ const draft = this.snapshot.draft;
197
+ if (!draft)
198
+ return Promise.resolve({ changes: this.changes });
199
+ return this.run("saving", async () => {
200
+ const result = await this.#settle(await updateOrder(this.#ctx.client, draft.id, { prescriptions: { none: true } }));
201
+ if (this.id)
202
+ this.patch({ draft: null });
203
+ return result;
204
+ }).then(() => this.#save());
205
+ }
206
+ /**
207
+ * Send it to the patient. Refused until it's ready (see `readyToSend`). Saves what isn't saved yet first.
208
+ * Never sets a pharmacy: the patient chooses (one already on the order is kept). If the server's order
209
+ * holds prescriptions this order doesn't show (e.g. an agent's), they become lines and nothing is sent —
210
+ * the prescriber reviews them first. If the server won't send it, it says why in `changes` (and, when it
211
+ * needs a way to reach the patient, `contactRequest`).
212
+ */
213
+ submit() {
214
+ return this.run("saving", async () => {
215
+ if (this.final)
216
+ throw refuse(`This order is already ${this.state.state.toLowerCase()}.`);
217
+ const lines = this.prescriptions;
218
+ if (!this.patient?.id)
219
+ throw refuse("This order has no patient yet.");
220
+ if (!lines.length)
221
+ throw refuse("This order has no prescriptions.");
222
+ if (!lines.every((rx) => rx.signed))
223
+ throw refuse("Every prescription must be signed before the order is sent.");
224
+ const ids = lines.map((rx) => rx.id);
225
+ try {
226
+ if (!this.id) {
227
+ const result = await this.#syncDraft();
228
+ if (this.snapshot.candidates.length)
229
+ throw refuse("This patient has several draft orders: pick the one to send.");
230
+ if (!this.id)
231
+ return result; // the server said why (changes)
232
+ }
233
+ else
234
+ await this.#saveLines();
235
+ // Never send prescriptions the prescriber wasn't shown (e.g. an agent's, on the patient's draft order):
236
+ // they're lines now; nothing is sent until they're reviewed.
237
+ if (this.state.prescriptions.some((rx) => !ids.includes(rx.id)))
238
+ throw refuse("This order holds prescriptions you haven't reviewed. They're shown now; review them, then send.");
239
+ const result = await this.#settle(await submitOrder(this.#ctx.client, this.id));
240
+ if (this.state?.state !== "SUBMITTED")
241
+ this.#askForContact(result.changes);
242
+ return result;
243
+ }
244
+ catch (e) {
245
+ const error = toPhotonError(e);
246
+ if (error.kind !== "refused" && asksForAddress(null, error.message))
247
+ this.#askForContact(noChanges, error.message);
248
+ throw error;
249
+ }
250
+ });
251
+ }
252
+ /**
253
+ * The Photon Rx app's link to this record's flow (`/<flow>/<id>`); before the record, to a new one from the ids it
254
+ * hangs off (its patient, and its lines by id or template). `ph.url(this)`.
255
+ */
256
+ url() {
257
+ return this.#ctx.url(this);
258
+ }
259
+ /** The same, embeddable in an iframe; `ph.frame(this)`. */
260
+ frame() {
261
+ return this.#ctx.frame(this);
262
+ }
263
+ /** Read it again, with each prescription read on its own. */
264
+ reload() {
265
+ if (!this.id)
266
+ return Promise.resolve({ changes: this.changes });
267
+ return this.run("loading", async () => this.#settle(await getOrder(this.#ctx.client, this.id)));
268
+ }
269
+ // ---- Saving the draft as it goes ----
270
+ #onServer(id) {
271
+ return Boolean(id && this.state?.prescriptions.some((rx) => rx.id === id));
272
+ }
273
+ /** The patient and the prescriptions with records — what the server's draft order should hold. */
274
+ #draftKey() {
275
+ const ids = this.prescriptions.flatMap((line) => (line.id ? [line.id] : []));
276
+ return JSON.stringify([this.patient?.id ?? null, ids, this.#refs, this.#pharmacy]);
277
+ }
278
+ /** What goes on the server's order: the prescriptions with records it lacks, and those given by your id. */
279
+ #toAdd() {
280
+ const ids = this.prescriptions.flatMap((line) => (line.id && !this.#onServer(line.id) ? [{ id: line.id }] : []));
281
+ return [...ids, ...this.#refs];
282
+ }
283
+ /** A rejected pharmacy match leaves the entire patch unapplied, including removed lines. */
284
+ #toRemove() {
285
+ return (this.state?.prescriptions ?? [])
286
+ .filter((rx) => !this.prescriptions.some((line) => line.id === rx.id))
287
+ .map(({ id }) => ({ id }));
288
+ }
289
+ /**
290
+ * Save what's changed: before the record, sync the draft order once the patient and a prescription have
291
+ * records; after, put on what it lacks and take off what was removed. Nothing to do: no call.
292
+ */
293
+ #save(remove = [], pharmacy = this.id ? undefined : this.#pharmacy) {
294
+ const nothing = { changes: this.changes };
295
+ if (this.final && !pharmacy)
296
+ return Promise.resolve(nothing);
297
+ if (!this.id) {
298
+ if (this.#toLookFor())
299
+ return this.run("loading", () => this.#findDraft()).then(() => this.#save(remove, pharmacy));
300
+ if (!this.#readyToSync())
301
+ return Promise.resolve(nothing);
302
+ // Queued behind other calls: by its turn, another save may have made the order — then just add to it.
303
+ return this.run("saving", async () => this.id
304
+ ? this.#saveLines([], pharmacy)
305
+ : this.#readyToSync()
306
+ ? this.#syncDraft(pharmacy)
307
+ : { changes: this.changes });
308
+ }
309
+ if (!this.#toAdd().length && !remove.length && !this.#toRemove().length && pharmacy === undefined)
310
+ return Promise.resolve(nothing);
311
+ return this.run("saving", () => this.#saveLines(remove, pharmacy));
312
+ }
313
+ /** A patient and a prescription with records, no pick pending, and not what the server just turned down. */
314
+ #readyToSync() {
315
+ return (Boolean(this.patient?.id) &&
316
+ (this.prescriptions.some((line) => line.id) || this.#refs.length > 0) &&
317
+ !this.snapshot.candidates.length &&
318
+ !this.snapshot.draft &&
319
+ this.#declined !== this.#draftKey());
320
+ }
321
+ /** A new order's patient, not looked for yet: nothing on this order has a record that would decide which order. */
322
+ #toLookFor() {
323
+ const id = this.patient?.id ?? null;
324
+ if (!id || this.id || this.#lookedFor === id || this.#refs.length || this.prescriptions.some((l) => l.id))
325
+ return null;
326
+ return id;
327
+ }
328
+ /**
329
+ * The patient's draft orders (the read-only Orders query): one is `draft`, several are `candidates`. A read that
330
+ * fails leaves the order as it was — the server's sync still continues a draft.
331
+ */
332
+ async #findDraft() {
333
+ const patientId = this.#toLookFor();
334
+ if (!patientId)
335
+ return { changes: this.changes };
336
+ this.#lookedFor = patientId;
337
+ const found = await readOrders(this.#ctx.client, { filter: { patient: { id: patientId }, state: "DRAFT" } }).catch(() => null);
338
+ // Moved on while it read: another patient, or a record now decides.
339
+ const decided = Boolean(this.id || this.#refs.length || this.prescriptions.some((l) => l.id));
340
+ if (!found || decided || this.patient?.id !== patientId)
341
+ return { changes: this.changes };
342
+ // A draft with nothing on it isn't worth asking about: the server's sync continues it, as a new order would start.
343
+ const drafts = found.orders
344
+ .filter((order) => order.prescriptions.length > 0)
345
+ .map(({ routablePharmacies: _, ...order }) => order);
346
+ if (drafts.length === 1)
347
+ this.patch({ draft: drafts[0] });
348
+ else if (drafts.length > 1)
349
+ this.patch({
350
+ candidates: drafts.map((o) => ({ id: o.id, pharmacy: o.pharmacy, prescriptions: o.prescriptions })),
351
+ });
352
+ return { changes: this.changes };
353
+ }
354
+ /** SyncOrder with the patient and every prescription that has a record: the patient's draft order, or a new one. */
355
+ async #syncDraft(pharmacy) {
356
+ const key = this.#draftKey();
357
+ const add = this.#toAdd();
358
+ const outcome = await syncOrder(this.#ctx.client, {
359
+ patient: { id: this.patient.id },
360
+ prescriptions: add.length ? { add } : undefined,
361
+ ...(pharmacy !== undefined ? { pharmacy } : {}),
362
+ });
363
+ if (outcome.kind === "ok" && outcome.order)
364
+ this.#sent(add);
365
+ if (outcome.kind === "ambiguous") {
366
+ this.patch({ candidates: outcome.candidates.map(toOrderCandidate) });
367
+ return { changes: noChanges };
368
+ }
369
+ if (outcome.order && outcome.order.state !== "DRAFT") {
370
+ this.#declined = key;
371
+ throw alreadySent();
372
+ }
373
+ const result = await this.#settle(outcome);
374
+ if (!this.id)
375
+ this.#declined = key; // the server said why (changes); not again until something changes
376
+ return result;
377
+ }
378
+ /** On the server's order: the prescriptions with records it lacks, and those to take off. */
379
+ async #saveLines(remove = [], pharmacy) {
380
+ const add = this.#toAdd();
381
+ const off = [...new Set([...remove, ...this.#toRemove()].map((rx) => rx.id))]
382
+ .filter((id) => this.#onServer(id))
383
+ .map((id) => ({ id }));
384
+ if (this.final && (this.state.state !== "SUBMITTED" || add.length || off.length))
385
+ throw refuse(`This order is ${this.state.state.toLowerCase()}; only a submitted order's pharmacy can change.`);
386
+ if (!add.length && !off.length && pharmacy === undefined)
387
+ return { changes: this.changes };
388
+ const prescriptions = { ...(add.length ? { add } : {}), ...(off.length ? { remove: off } : {}) };
389
+ const outcome = await updateOrder(this.#ctx.client, this.id, {
390
+ ...(add.length || off.length ? { prescriptions } : {}),
391
+ ...(pharmacy !== undefined ? { pharmacy } : {}),
392
+ });
393
+ if (outcome.kind === "ok" && outcome.order)
394
+ this.#sent(add);
395
+ return this.#settle(outcome);
396
+ }
397
+ /** Prescriptions given by your id went to the server: what it found is on its order (its changes say what it didn't). */
398
+ #sent(add) {
399
+ this.#refs = this.#refs.filter((ref) => !add.includes(ref));
400
+ }
401
+ // ---- Its patient and lines ----
402
+ /** The live patient for what was given: as is, or opened by id. */
403
+ #patientFor(given) {
404
+ if (given === null || given instanceof Patient)
405
+ return given;
406
+ return this.#ctx.openPatient(given.id).then((p) => {
407
+ if (!p)
408
+ throw new PhotonError("invalid", `Patient ${given.id} not found.`);
409
+ return p;
410
+ });
411
+ }
412
+ /** Who it's for. A different patient starts over — prescriptions stay with the patient they were written for. */
413
+ #setPatient(patient) {
414
+ if (patient === this.patient || (patient?.id && patient.id === this.patient?.id))
415
+ return;
416
+ if (this.id)
417
+ throw refuse("This order's patient is fixed: for another patient, start a new order.");
418
+ const switching = Boolean(this.patient && patient && this.patient.id !== patient.id) || !patient;
419
+ // The old lines go first: following the new patient tells every line who it's for, and a line with a picked
420
+ // drug waiting for its patient would be created for this one.
421
+ if (switching) {
422
+ this.#contactAtRequest = null;
423
+ this.patch({ contactRequest: null, candidates: [], draft: null });
424
+ this.#setLines([this.#newLine(null, patient?.id ?? null)]);
425
+ }
426
+ this.#follow(patient);
427
+ }
428
+ /**
429
+ * The line for something to add: a live Prescription as given, one opened by id, or a new line — a drug by id
430
+ * looked up at once, a template line drafted once its patient is known.
431
+ */
432
+ #lineFor(rx) {
433
+ if (rx instanceof Prescription)
434
+ return rx;
435
+ // One the server doesn't have: an empty line in its place, saying so — the rest of the order still opens.
436
+ if ("id" in rx)
437
+ return this.#ctx.openPrescription(rx.id).then((opened) => opened ?? this.#newLine(null, undefined, rx.id));
438
+ const line = this.#newLine("templateId" in rx ? (rx.templateId ?? null) : null);
439
+ const drug = "treatment" in rx ? { treatment: { id: rx.treatment.id } } : {};
440
+ // A drug by id is looked up now; a template line is drafted once it has its patient (network-api doesn't expand
441
+ // a template without one).
442
+ if (drug.treatment)
443
+ void line.sync(drug).catch(() => { }); // a failure lands on the line
444
+ return line;
445
+ }
446
+ /** A new line for this order's patient (no record until its drug is picked). */
447
+ #newLine(templateId = null, patientId = this.patient?.id ?? null, missing) {
448
+ const line = new Prescription(this.#ctx, null, {
449
+ patientId,
450
+ templateId,
451
+ missing,
452
+ isTaken: (id) => this.prescriptions.some((other) => other !== line && other.id === id),
453
+ });
454
+ return line;
455
+ }
456
+ /**
457
+ * Its lines, followed: a change to one is a change to the order (a new snapshot), and one that gets a
458
+ * record goes on the draft order.
459
+ */
460
+ #setLines(lines) {
461
+ for (const stop of this.#unsubscribeLines)
462
+ stop();
463
+ this.patch({ prescriptions: lines });
464
+ this.#unsubscribeLines = lines.map((line) => {
465
+ let had = line.id;
466
+ let drug = line.state?.treatment.id;
467
+ return line.subscribe(() => {
468
+ this.touch();
469
+ const now = line.state?.treatment.id;
470
+ if (line.id === had) {
471
+ // Another drug on a line the order holds: the order's screening is out of date — read it again.
472
+ if (now !== drug && this.#onServer(line.id) && !this.final)
473
+ void this.reload().catch(() => { });
474
+ drug = now;
475
+ return;
476
+ }
477
+ had = line.id;
478
+ drug = now;
479
+ void this.#save().catch(() => { }); // a failure lands on the object (snapshot.error)
480
+ });
481
+ });
482
+ }
483
+ /** The server won't send it until the patient can be reached: a missing phone, email or address (its words). */
484
+ #askForContact(changes, message) {
485
+ const contact = changes.unapplied.find((c) => c.key.startsWith("patient.contact.") || asksForAddress({ applied: [], unapplied: [c] }));
486
+ const reason = message ?? contact?.reason ?? null;
487
+ if (!reason && !contact)
488
+ return;
489
+ this.#contactAtRequest = contactOf(this.patient);
490
+ this.patch({ contactRequest: reason ?? "The patient needs a phone." });
491
+ }
492
+ /**
493
+ * Follow the patient: a change to them is a change to the order (a new snapshot); lines learn their
494
+ * patient's id when it has one (and the draft is saved then); the contact request clears on new contact info.
495
+ */
496
+ #follow(patient) {
497
+ this.#unsubscribePatient?.();
498
+ this.patch({ patient });
499
+ if (!patient)
500
+ return;
501
+ let had = patient.id;
502
+ const sync = () => {
503
+ if (patient.id)
504
+ for (const line of this.prescriptions)
505
+ void line.sync({ patient: { id: patient.id } }).catch(() => { });
506
+ if (patient.id !== had) {
507
+ had = patient.id;
508
+ void this.#save().catch(() => { });
509
+ }
510
+ if (this.snapshot.contactRequest && contactOf(patient) !== this.#contactAtRequest) {
511
+ this.#contactAtRequest = null;
512
+ this.patch({ contactRequest: null });
513
+ }
514
+ };
515
+ this.#unsubscribePatient = patient.subscribe(() => {
516
+ this.touch();
517
+ sync();
518
+ });
519
+ sync();
520
+ }
521
+ async #settle(outcome) {
522
+ const changes = outcome.kind === "ok" ? toChanges(outcome.changes) : noChanges;
523
+ if (outcome.kind !== "ok" || !outcome.order) {
524
+ this.settle(null, changes);
525
+ return { changes };
526
+ }
527
+ const record = await adoptOrder(this.#ctx, outcome.order);
528
+ // Its patient, and any prescription it holds that no line shows yet, become this order's.
529
+ if (record.patient && !this.patient)
530
+ this.#follow(this.#ctx.patient(record.patient));
531
+ const shown = new Set(this.prescriptions.map((l) => l.id));
532
+ const added = record.prescriptions
533
+ .filter((rx) => !shown.has(rx.id))
534
+ .map((rx) => this.#ctx.held.prescriptions.get(rx.id) ?? this.#ctx.prescription(rx));
535
+ if (added.length)
536
+ this.#setLines([...this.prescriptions.filter((l) => l.id), ...added, ...this.prescriptions.filter((l) => !l.id)]);
537
+ this.settle(record, changes);
538
+ return { changes };
539
+ }
540
+ }
541
+ /**
542
+ * An order's record; its patient and any prescriptions not yet held become live objects — each prescription
543
+ * read on its own (the order's copy can be wrong), sharing a read already in flight; the order's copy if the
544
+ * read fails.
545
+ */
546
+ export async function adoptOrder(ctx, order) {
547
+ const record = toOrder(order);
548
+ if (record.patient)
549
+ ctx.patient(record.patient);
550
+ await Promise.all(order.prescriptions
551
+ .filter((rx) => !ctx.held.prescriptions.has(rx.id))
552
+ .map(async (rx) => {
553
+ const opened = await ctx.openPrescription(rx.id).catch(() => null);
554
+ return opened ?? ctx.prescription(toPrescription(rx));
555
+ }));
556
+ return record;
557
+ }
558
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../../src/photon/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAEnG,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA6DjD,qFAAqF;AACrF,MAAM,SAAS,GAAG,CAAC,CAAiB,EAAE,EAAE;IACtC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC;IAC5B,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,CAAC,EAAE,KAAK,IAAI,IAAI;QAChB,CAAC,EAAE,KAAK,IAAI,IAAI;QAChB,CAAC,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AC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACpH,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAY,EAAE,KAA0B;IACvE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,MAAM,CAAC,OAAO;QAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,aAAa;SAChB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;SAClD,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QAChB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACnE,OAAO,MAAM,IAAI,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CACL,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type NetworkClient } from "../api/index.ts";
2
+ import type { OrdersInput, OrdersResult } from "./types.ts";
3
+ /** Map the query directly: no live-object hydration, follow-up mutations, or local workflow effects. */
4
+ export declare function readOrders(client: NetworkClient, input?: OrdersInput): Promise<OrdersResult>;
5
+ //# sourceMappingURL=orders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../src/photon/orders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG7D,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5D,wGAAwG;AACxG,wBAAsB,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAmCtG"}
@@ -0,0 +1,39 @@
1
+ import { orders } from "../api/index.js";
2
+ import { guarded } from "./errors.js";
3
+ import { toChoice, toOrder } from "./map.js";
4
+ /** Map the query directly: no live-object hydration, follow-up mutations, or local workflow effects. */
5
+ export async function readOrders(client, input = {}) {
6
+ const result = await guarded(() => orders(client, {
7
+ filter: input.filter,
8
+ limit: input.limit,
9
+ pharmacy: input.routablePharmacies?.pharmacy,
10
+ page: input.routablePharmacies?.page,
11
+ includePharmacies: input.routablePharmacies !== undefined,
12
+ }));
13
+ if (result.__typename === "AmbiguousPatientMatch")
14
+ return {
15
+ orders: [],
16
+ candidates: result.candidates.map((c) => ({
17
+ id: c.id,
18
+ firstName: c.firstName,
19
+ lastName: c.lastName,
20
+ dateOfBirth: c.dateOfBirth,
21
+ })),
22
+ reason: result.reason,
23
+ };
24
+ return {
25
+ orders: result.orders.map((o) => ({
26
+ ...toOrder(o),
27
+ routablePharmacies: o.routablePharmacies
28
+ ? {
29
+ options: o.routablePharmacies.options.map(toChoice),
30
+ totalCount: o.routablePharmacies.totalCount,
31
+ nextOffset: o.routablePharmacies.nextOffset,
32
+ }
33
+ : null,
34
+ })),
35
+ candidates: [],
36
+ reason: null,
37
+ };
38
+ }
39
+ //# sourceMappingURL=orders.js.map