@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/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* network-api's three upsert mutations — patient, prescription, order — one call each, returning live
|
|
9
9
|
* objects (state you can subscribe to; methods that await the web calls) with the workflow rules
|
|
10
|
-
* inside. See
|
|
10
|
+
* inside. See the package README.
|
|
11
11
|
*
|
|
12
12
|
* This is the whole public surface. The GraphQL layer (api/, gql/) is internal.
|
|
13
13
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { clientVersion } from "../index.ts";
|
|
4
|
+
|
|
5
|
+
describe("clientVersion", () => {
|
|
6
|
+
it("is package.json's version: bump both together", () => {
|
|
7
|
+
const manifest = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
8
|
+
expect(clientVersion).toBe(manifest.version);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const clientVersion: string = "0.14.9";
|
|
@@ -18,7 +18,6 @@ fragment TreatmentFields on Treatment {
|
|
|
18
18
|
strength
|
|
19
19
|
medicationType
|
|
20
20
|
schedule
|
|
21
|
-
recommendedDispenseUnits
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
fragment ChoiceFields on Choice {
|
|
@@ -32,11 +31,19 @@ fragment ChoiceFields on Choice {
|
|
|
32
31
|
type
|
|
33
32
|
label
|
|
34
33
|
confidence
|
|
34
|
+
value {
|
|
35
|
+
displayValue
|
|
36
|
+
value
|
|
37
|
+
unit
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
entity {
|
|
37
41
|
__typename
|
|
38
42
|
... on Treatment {
|
|
39
43
|
...TreatmentFields
|
|
44
|
+
templates {
|
|
45
|
+
...PrescriptionTemplateFields
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
... on Pharmacy {
|
|
42
49
|
...PharmacyFields
|
|
@@ -46,23 +53,44 @@ fragment ChoiceFields on Choice {
|
|
|
46
53
|
|
|
47
54
|
fragment PharmacyOfferFields on PharmacyOffer {
|
|
48
55
|
source
|
|
56
|
+
prescriptionId
|
|
57
|
+
priceType
|
|
49
58
|
isPromoted
|
|
50
59
|
attributeTags {
|
|
51
60
|
kind
|
|
52
61
|
label
|
|
53
62
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
price {
|
|
64
|
+
amount
|
|
65
|
+
retailAmount
|
|
66
|
+
promotions {
|
|
67
|
+
type
|
|
68
|
+
baseAmount
|
|
69
|
+
amountSaved
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
prescriptionId
|
|
72
|
+
deliveryEstimate {
|
|
62
73
|
deliveryPromise
|
|
63
74
|
deliveryPromiseRangeStart
|
|
64
75
|
deliveryPromiseRangeEnd
|
|
65
76
|
}
|
|
77
|
+
redemptionState
|
|
78
|
+
redemptionMethods {
|
|
79
|
+
...RedemptionMethodFields
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fragment RedemptionMethodFields on RedemptionMethod {
|
|
84
|
+
__typename
|
|
85
|
+
... on PharmacyDiscountCard {
|
|
86
|
+
id
|
|
87
|
+
prescriptionId
|
|
88
|
+
bin
|
|
89
|
+
pcn
|
|
90
|
+
group
|
|
91
|
+
memberId
|
|
92
|
+
externalUrl
|
|
93
|
+
}
|
|
66
94
|
}
|
|
67
95
|
|
|
68
96
|
fragment ChangeFields on Change {
|
|
@@ -103,6 +131,24 @@ fragment OperationErrorFields on OperationError {
|
|
|
103
131
|
fragment PharmacyFields on Pharmacy {
|
|
104
132
|
id
|
|
105
133
|
name
|
|
134
|
+
logo
|
|
135
|
+
phone
|
|
136
|
+
hours {
|
|
137
|
+
openFrom
|
|
138
|
+
openUntil
|
|
139
|
+
dayOfWeek
|
|
140
|
+
is24Hr
|
|
141
|
+
timezone
|
|
142
|
+
}
|
|
143
|
+
isOpen
|
|
144
|
+
nextEvents {
|
|
145
|
+
open {
|
|
146
|
+
...PharmacyEventFields
|
|
147
|
+
}
|
|
148
|
+
close {
|
|
149
|
+
...PharmacyEventFields
|
|
150
|
+
}
|
|
151
|
+
}
|
|
106
152
|
address {
|
|
107
153
|
street1
|
|
108
154
|
street2
|
|
@@ -118,6 +164,42 @@ fragment PharmacyFields on Pharmacy {
|
|
|
118
164
|
}
|
|
119
165
|
}
|
|
120
166
|
|
|
167
|
+
fragment PharmacyEventFields on PharmacyEvent {
|
|
168
|
+
__typename
|
|
169
|
+
... on PharmacyOpenEvent {
|
|
170
|
+
type
|
|
171
|
+
datetime
|
|
172
|
+
}
|
|
173
|
+
... on PharmacyCloseEvent {
|
|
174
|
+
type
|
|
175
|
+
datetime
|
|
176
|
+
}
|
|
177
|
+
... on PharmacyOpen24HrEvent {
|
|
178
|
+
type
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
fragment OrganizationFields on Organization {
|
|
183
|
+
id
|
|
184
|
+
name
|
|
185
|
+
customer {
|
|
186
|
+
__typename
|
|
187
|
+
... on Customer {
|
|
188
|
+
id
|
|
189
|
+
name
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
settings {
|
|
193
|
+
brandColor
|
|
194
|
+
brandLogo
|
|
195
|
+
priorAuthorizationExceptionMessage
|
|
196
|
+
patientUx {
|
|
197
|
+
enablePatientRerouting
|
|
198
|
+
enableAutomatedOps
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
121
203
|
fragment PatientDemographicFields on PatientDemographic {
|
|
122
204
|
name {
|
|
123
205
|
first
|
|
@@ -127,6 +209,9 @@ fragment PatientDemographicFields on PatientDemographic {
|
|
|
127
209
|
dateOfBirth
|
|
128
210
|
sex
|
|
129
211
|
gender
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fragment PatientContactFields on PatientContact {
|
|
130
215
|
email
|
|
131
216
|
phone
|
|
132
217
|
address {
|
|
@@ -137,6 +222,16 @@ fragment PatientDemographicFields on PatientDemographic {
|
|
|
137
222
|
postalCode
|
|
138
223
|
country
|
|
139
224
|
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
fragment PatientFields on Patient {
|
|
228
|
+
id
|
|
229
|
+
demographic {
|
|
230
|
+
...PatientDemographicFields
|
|
231
|
+
}
|
|
232
|
+
contact {
|
|
233
|
+
...PatientContactFields
|
|
234
|
+
}
|
|
140
235
|
benefits {
|
|
141
236
|
status
|
|
142
237
|
entries {
|
|
@@ -150,13 +245,6 @@ fragment PatientDemographicFields on PatientDemographic {
|
|
|
150
245
|
preferredPharmacy {
|
|
151
246
|
...PharmacyFields
|
|
152
247
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
fragment PatientFields on Patient {
|
|
156
|
-
id
|
|
157
|
-
demographic {
|
|
158
|
-
...PatientDemographicFields
|
|
159
|
-
}
|
|
160
248
|
clinical {
|
|
161
249
|
allergies {
|
|
162
250
|
status
|
|
@@ -213,6 +301,24 @@ fragment ScreeningAlertFields on ScreeningAlert {
|
|
|
213
301
|
|
|
214
302
|
fragment PrescriptionFields on Prescription {
|
|
215
303
|
id
|
|
304
|
+
prescriber {
|
|
305
|
+
id
|
|
306
|
+
name {
|
|
307
|
+
first
|
|
308
|
+
middle
|
|
309
|
+
last
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
fulfillment {
|
|
313
|
+
state
|
|
314
|
+
pharmacyEstimatedReadyAt
|
|
315
|
+
exceptions {
|
|
316
|
+
id
|
|
317
|
+
type
|
|
318
|
+
message
|
|
319
|
+
createdAt
|
|
320
|
+
}
|
|
321
|
+
}
|
|
216
322
|
templateId
|
|
217
323
|
patient {
|
|
218
324
|
id
|
|
@@ -250,6 +356,17 @@ fragment PrescriptionFields on Prescription {
|
|
|
250
356
|
fragment OrderFields on Order {
|
|
251
357
|
id
|
|
252
358
|
state
|
|
359
|
+
offers {
|
|
360
|
+
atPharmacy {
|
|
361
|
+
...PharmacyOfferFields
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
organization {
|
|
365
|
+
__typename
|
|
366
|
+
... on Organization {
|
|
367
|
+
...OrganizationFields
|
|
368
|
+
}
|
|
369
|
+
}
|
|
253
370
|
patient {
|
|
254
371
|
...PatientRecordFields
|
|
255
372
|
}
|
|
@@ -262,11 +379,40 @@ fragment OrderFields on Order {
|
|
|
262
379
|
pharmacy {
|
|
263
380
|
...PharmacyFields
|
|
264
381
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
382
|
+
fulfillment {
|
|
383
|
+
state
|
|
384
|
+
history {
|
|
385
|
+
pharmacy {
|
|
386
|
+
...PharmacyFields
|
|
387
|
+
}
|
|
388
|
+
selector
|
|
389
|
+
reason
|
|
390
|
+
createdAt
|
|
391
|
+
}
|
|
392
|
+
routability {
|
|
393
|
+
allowed
|
|
394
|
+
reason
|
|
395
|
+
}
|
|
396
|
+
exceptions {
|
|
397
|
+
id
|
|
398
|
+
type
|
|
399
|
+
message
|
|
400
|
+
createdAt
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
fragment PrescriptionTemplateFields on PrescriptionTemplate {
|
|
406
|
+
id
|
|
407
|
+
source
|
|
408
|
+
name
|
|
409
|
+
instructions
|
|
410
|
+
dispense {
|
|
411
|
+
quantity
|
|
412
|
+
unit
|
|
413
|
+
daysSupply
|
|
414
|
+
refillsAllowed
|
|
415
|
+
dispenseAsWritten
|
|
270
416
|
}
|
|
271
417
|
}
|
|
272
418
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
query Me {
|
|
2
|
+
me {
|
|
3
|
+
__typename
|
|
4
|
+
... on User {
|
|
5
|
+
id
|
|
6
|
+
name {
|
|
7
|
+
first
|
|
8
|
+
last
|
|
9
|
+
}
|
|
10
|
+
organization {
|
|
11
|
+
__typename
|
|
12
|
+
... on Organization {
|
|
13
|
+
id
|
|
14
|
+
name
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
permissions
|
|
18
|
+
}
|
|
19
|
+
... on Patient {
|
|
20
|
+
id
|
|
21
|
+
name {
|
|
22
|
+
first
|
|
23
|
+
last
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
... on Machine {
|
|
27
|
+
organization {
|
|
28
|
+
__typename
|
|
29
|
+
... on Organization {
|
|
30
|
+
id
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
permissions
|
|
35
|
+
}
|
|
36
|
+
...OperationErrorFields
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Read-only order snapshots and pharmacy choices. A sole match is still a choice;
|
|
2
|
+
# selecting it remains an explicit UpdateOrder mutation.
|
|
3
|
+
query Orders(
|
|
4
|
+
$filter: OrdersFilterInput
|
|
5
|
+
$limit: Int
|
|
6
|
+
$pharmacy: PharmacyReferenceInput
|
|
7
|
+
$page: PageInput
|
|
8
|
+
$includePharmacies: Boolean!
|
|
9
|
+
) {
|
|
10
|
+
orders(filter: $filter, limit: $limit) {
|
|
11
|
+
__typename
|
|
12
|
+
... on OrdersPayload {
|
|
13
|
+
orders {
|
|
14
|
+
...OrderFields
|
|
15
|
+
routablePharmacies(pharmacy: $pharmacy, page: $page) @include(if: $includePharmacies) {
|
|
16
|
+
options {
|
|
17
|
+
...ChoiceFields
|
|
18
|
+
}
|
|
19
|
+
totalCount
|
|
20
|
+
nextOffset
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
... on AmbiguousPatientMatch {
|
|
25
|
+
reason
|
|
26
|
+
candidates {
|
|
27
|
+
id
|
|
28
|
+
firstName
|
|
29
|
+
lastName
|
|
30
|
+
dateOfBirth
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
...OperationErrorFields
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -14,23 +14,49 @@ mutation GetPatient($id: ID!, $metadata: RequestMetadata!) {
|
|
|
14
14
|
mutation SyncPatient(
|
|
15
15
|
$id: ID
|
|
16
16
|
$demographic: PatientDemographicInput
|
|
17
|
+
$contact: PatientContactInput
|
|
17
18
|
$clinical: PatientClinicalInput
|
|
19
|
+
$benefits: BenefitsPatch
|
|
20
|
+
$preferredPharmacy: PharmacyReferenceInput
|
|
18
21
|
$metadata: RequestMetadata!
|
|
19
22
|
) {
|
|
20
|
-
patient(
|
|
23
|
+
patient(
|
|
24
|
+
patient: {
|
|
25
|
+
id: $id
|
|
26
|
+
demographic: $demographic
|
|
27
|
+
contact: $contact
|
|
28
|
+
clinical: $clinical
|
|
29
|
+
benefits: $benefits
|
|
30
|
+
preferredPharmacy: $preferredPharmacy
|
|
31
|
+
}
|
|
32
|
+
metadata: $metadata
|
|
33
|
+
) {
|
|
21
34
|
...PatientResultFields
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
37
|
|
|
25
|
-
# Demographics
|
|
38
|
+
# Demographics, contact, benefits, preferred pharmacy and/or clinical patches (allergies — `none: true` for NKDA —
|
|
26
39
|
# medications, diagnoses, notes).
|
|
27
40
|
mutation UpdatePatient(
|
|
28
41
|
$id: ID!
|
|
29
42
|
$demographic: PatientDemographicInput
|
|
43
|
+
$contact: PatientContactInput
|
|
30
44
|
$clinical: PatientClinicalInput
|
|
45
|
+
$benefits: BenefitsPatch
|
|
46
|
+
$preferredPharmacy: PharmacyReferenceInput
|
|
31
47
|
$metadata: RequestMetadata!
|
|
32
48
|
) {
|
|
33
|
-
patient(
|
|
49
|
+
patient(
|
|
50
|
+
patient: {
|
|
51
|
+
id: $id
|
|
52
|
+
demographic: $demographic
|
|
53
|
+
contact: $contact
|
|
54
|
+
clinical: $clinical
|
|
55
|
+
benefits: $benefits
|
|
56
|
+
preferredPharmacy: $preferredPharmacy
|
|
57
|
+
}
|
|
58
|
+
metadata: $metadata
|
|
59
|
+
) {
|
|
34
60
|
...PatientResultFields
|
|
35
61
|
}
|
|
36
62
|
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# Update that one prescription (by id): only the fields sent change — or sign it: `signing.signedHash`
|
|
9
9
|
# = the contentHash the prescriber reviewed. Signing can't be combined with content edits.
|
|
10
10
|
# Screening runs on every call; every response carries signing.contentHash.
|
|
11
|
+
# Templates: like Get (id only, nothing changes), but selects only its treatment's templates — their Medi-Span
|
|
12
|
+
# sig lookup runs only when asked for, not on every save.
|
|
11
13
|
|
|
12
14
|
mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {
|
|
13
15
|
prescription(prescription: { id: $id }, metadata: $metadata) {
|
|
@@ -15,6 +17,24 @@ mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
mutation GetPrescriptionTemplates($id: ID!, $metadata: RequestMetadata!) {
|
|
21
|
+
prescription(prescription: { id: $id }, metadata: $metadata) {
|
|
22
|
+
__typename
|
|
23
|
+
... on PrescriptionPayload {
|
|
24
|
+
prescription {
|
|
25
|
+
treatment {
|
|
26
|
+
templates {
|
|
27
|
+
...PrescriptionTemplateFields
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
... on OperationError {
|
|
33
|
+
...OperationErrorFields
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
mutation SyncPrescription(
|
|
19
39
|
$id: ID
|
|
20
40
|
$externalId: String
|
package/src/photon/auth.ts
CHANGED
|
@@ -5,10 +5,9 @@ import { PhotonError } from "./errors.ts";
|
|
|
5
5
|
*
|
|
6
6
|
* SPA `{ clientId }` — core signs the prescriber in itself, in the browser (session.ts): `ph.session`.
|
|
7
7
|
* SPA `{ getToken }` — the host signs in (e.g. its own Auth0 SDK) and supplies the org-scoped token.
|
|
8
|
-
* M2M `{ clientId, clientSecret, organizationId }` — a backend's own credentials.
|
|
9
|
-
* client-credentials grant,
|
|
10
|
-
*
|
|
11
|
-
* fixed now so it doesn't change later. Servers only: `photon()` refuses a secret in a browser.
|
|
8
|
+
* M2M `{ clientId, clientSecret, organizationId }` — a backend's own credentials (machine.ts): core runs the
|
|
9
|
+
* client-credentials grant, keeps the token until shortly before it expires, shares one request between
|
|
10
|
+
* concurrent calls and retries once on a 401. Servers only: `photon()` refuses a secret in a browser.
|
|
12
11
|
*/
|
|
13
12
|
export type PhotonAuth =
|
|
14
13
|
| { getToken: () => Promise<string> }
|
|
@@ -18,6 +17,12 @@ export type PhotonAuth =
|
|
|
18
17
|
/** Core's own browser sign-in: a client id alone. */
|
|
19
18
|
export const signsIn = (auth: PhotonAuth): auth is { clientId: string } => "clientId" in auth && !hasSecret(auth);
|
|
20
19
|
|
|
20
|
+
/** A backend's own credentials (M2M). */
|
|
21
|
+
export const isMachine = (
|
|
22
|
+
auth: PhotonAuth,
|
|
23
|
+
): auth is { clientId: string; clientSecret: string; organizationId: string } =>
|
|
24
|
+
"clientId" in auth && "clientSecret" in auth;
|
|
25
|
+
|
|
21
26
|
/** A client secret, in any shape it's given (M2M). */
|
|
22
27
|
export const hasSecret = (auth: object): boolean => "clientSecret" in auth || "client_secret" in auth;
|
|
23
28
|
|
|
@@ -39,12 +44,6 @@ export function refuseSecretInBrowser(auth: object): void {
|
|
|
39
44
|
);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
export function tokenSource(auth: PhotonAuth): () => Promise<string> {
|
|
43
|
-
if ("getToken" in auth) return auth.getToken;
|
|
44
|
-
refuseSecretInBrowser(auth);
|
|
45
|
-
throw new PhotonError("invalid", "Client-credentials (M2M) auth isn't supported yet — pass { getToken }.");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
47
|
/**
|
|
49
48
|
* How links from an instance sign in (`FlowLink.auth`): an embed signs the prescriber in with the host's own
|
|
50
49
|
* client — `{ clientId }`'s — and any link opens in the instance's organization, when it has one. An M2M client
|
package/src/photon/choices.ts
CHANGED
|
@@ -66,13 +66,13 @@ export const optionKey = (option: ChangeOption) => `${option.path}=${JSON.string
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Does the server want a mailing address for this patient? network-api says so either as an unapplied
|
|
69
|
-
* change under
|
|
69
|
+
* change under contact.address (patient upserts) or in an error ("patient … has no address", at
|
|
70
70
|
* submit). Ask for one only when it does — a phone is often enough.
|
|
71
71
|
*/
|
|
72
72
|
export function asksForAddress(changes?: Changes | null, message?: string | null): boolean {
|
|
73
73
|
const fromChanges = (changes?.unapplied ?? []).some(
|
|
74
74
|
(c) =>
|
|
75
|
-
c.key.startsWith("
|
|
75
|
+
c.key.startsWith("contact.address") ||
|
|
76
76
|
(c.category === "MISSING_INPUT" && /address/i.test(`${c.label} ${c.reason ?? ""}`)),
|
|
77
77
|
);
|
|
78
78
|
return fromChanges || /\baddress\b/i.test(message ?? "");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Photon environments, in code. Every URL is inferred from the environment name —
|
|
3
3
|
* `<service>.<env>.health` — so there's nothing to configure per deploy, in a browser or on a server.
|
|
4
|
-
*
|
|
4
|
+
* tau is locally running services; it signs in through
|
|
5
5
|
* boson's Auth0 tenant.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -21,6 +21,7 @@ export interface EnvironmentUrls {
|
|
|
21
21
|
* `rx.new` in production, `rx.<env>.health` otherwise; tau's is the local dev server (`npm run dev:tau`).
|
|
22
22
|
*/
|
|
23
23
|
appUrl: string;
|
|
24
|
+
analyticsApiUrl: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/** Environments without their own Auth0 tenant. Local services (tau) sign in through boson's. */
|
|
@@ -43,5 +44,6 @@ export function environmentUrls(name: PhotonEnvironment): EnvironmentUrls {
|
|
|
43
44
|
auth0Domain: `auth.${authEnv}.health`,
|
|
44
45
|
auth0Audience: `https://api.${authEnv}.health`,
|
|
45
46
|
appUrl: APP_URL[name] ?? `https://rx.${name}.health`,
|
|
47
|
+
analyticsApiUrl: `${scheme(name)}://analytics-api.${name}.health`,
|
|
46
48
|
};
|
|
47
49
|
}
|
package/src/photon/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The public API: `photon()` and what it returns. network-api's three upsert mutations, one call each,
|
|
3
3
|
* returning live objects with the workflow rules inside — objects that can exist before their record. See
|
|
4
|
-
*
|
|
4
|
+
* the package README.
|
|
5
5
|
*/
|
|
6
6
|
export { photon, Patient, Prescription, Order } from "./photon.ts";
|
|
7
7
|
export type {
|
|
@@ -17,14 +17,29 @@ export type {
|
|
|
17
17
|
PatientSnapshot,
|
|
18
18
|
PrescriptionSnapshot,
|
|
19
19
|
OrderSnapshot,
|
|
20
|
+
Caller,
|
|
21
|
+
CallerName,
|
|
22
|
+
CallerOrganization,
|
|
20
23
|
} from "./photon.ts";
|
|
24
|
+
export { clientVersion } from "../meta/version.ts";
|
|
25
|
+
export type { Analytics, AnalyticsTarget, AnalyticsProperties } from "../analytics/track.ts";
|
|
26
|
+
export type {
|
|
27
|
+
DraftPrescriptionForLifecycleAnalytics,
|
|
28
|
+
DraftPrescriptionSource,
|
|
29
|
+
LifecycleAnalytics,
|
|
30
|
+
LifecycleEventName,
|
|
31
|
+
OrderForLifecycleAnalytics,
|
|
32
|
+
PatientForLifecycleAnalytics,
|
|
33
|
+
PrescriptionForLifecycleAnalytics,
|
|
34
|
+
SignedPrescriptionForLifecycleAnalytics,
|
|
35
|
+
} from "../analytics/lifecycleEvents.ts";
|
|
21
36
|
export type { PatientExtra } from "./patient.ts";
|
|
22
37
|
export type { PrescriptionExtra, PrescriptionUpdate } from "./prescription.ts";
|
|
23
38
|
export type { OrderExtra, OrderUpdate } from "./order.ts";
|
|
24
39
|
export type { LiveStatus, LiveSnapshot, LiveBase } from "./live.ts";
|
|
25
40
|
export type { PhotonAuth } from "./auth.ts";
|
|
26
41
|
export { Session } from "./session.ts";
|
|
27
|
-
export type { SessionStatus, SessionSnapshot, SessionUser, SessionConfig } from "./session.ts";
|
|
42
|
+
export type { SessionStatus, SessionSnapshot, SessionUser, SessionConfig, SignInOptions } from "./session.ts";
|
|
28
43
|
export { PhotonError } from "./errors.ts";
|
|
29
44
|
export type { Flow, FlowLink } from "./links.ts";
|
|
30
45
|
export type { PhotonErrorKind } from "./errors.ts";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PhotonError } from "./errors.ts";
|
|
2
|
+
import { claimsOf } from "./session.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A backend's own sign-in: OAuth 2 client credentials against the environment's Auth0 tenant, with the M2M client
|
|
6
|
+
* Photon made for the organization (`client_metadata.org_id`, which Auth0 puts on the token as its org claim).
|
|
7
|
+
* Servers only — `photon()` refuses a secret in a browser before it gets here.
|
|
8
|
+
*
|
|
9
|
+
* token() the access token: one from Auth0, kept until shortly before it expires; concurrent calls share one
|
|
10
|
+
* request.
|
|
11
|
+
* forget() drop it, so the next call gets a new one (network-api refused it: a 401).
|
|
12
|
+
*
|
|
13
|
+
* The token's organization must be `organizationId`: links name that organization, so calls made in another would
|
|
14
|
+
* go somewhere the links don't.
|
|
15
|
+
*/
|
|
16
|
+
export interface MachineConfig {
|
|
17
|
+
/** The Auth0 tenant (`auth.<env>.health`). */
|
|
18
|
+
domain: string;
|
|
19
|
+
/** The token audience network-api accepts. */
|
|
20
|
+
audience: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
clientSecret: string;
|
|
23
|
+
organizationId: string;
|
|
24
|
+
fetch?: typeof fetch;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MachineCredentials {
|
|
28
|
+
token(): Promise<string>;
|
|
29
|
+
forget(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Renew this long before the token expires. */
|
|
33
|
+
const EARLY_MS = 60_000;
|
|
34
|
+
/** Where Photon's Auth0 action puts the organization on a machine token. */
|
|
35
|
+
const ORG_CLAIM = "http://photon.health/org_id";
|
|
36
|
+
|
|
37
|
+
export function machineCredentials(config: MachineConfig): MachineCredentials {
|
|
38
|
+
let held: { token: string; expiresAt: number } | null = null;
|
|
39
|
+
let pending: Promise<string> | null = null;
|
|
40
|
+
|
|
41
|
+
const request = async (): Promise<string> => {
|
|
42
|
+
const response = await (config.fetch ?? fetch)(`https://${config.domain}/oauth/token`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
grant_type: "client_credentials",
|
|
47
|
+
client_id: config.clientId,
|
|
48
|
+
client_secret: config.clientSecret,
|
|
49
|
+
audience: config.audience,
|
|
50
|
+
}),
|
|
51
|
+
}).catch((e: unknown) => {
|
|
52
|
+
throw new PhotonError("network", "Couldn't reach Photon's sign-in for a machine token.", true, { cause: e });
|
|
53
|
+
});
|
|
54
|
+
const json = (await response.json().catch(() => ({}))) as {
|
|
55
|
+
access_token?: string;
|
|
56
|
+
expires_in?: number;
|
|
57
|
+
error?: string;
|
|
58
|
+
error_description?: string;
|
|
59
|
+
};
|
|
60
|
+
if (!response.ok || !json.access_token) {
|
|
61
|
+
const reason = json.error_description ?? json.error ?? `Auth0 responded ${response.status}`;
|
|
62
|
+
if (response.status >= 500) throw new PhotonError("network", reason, true);
|
|
63
|
+
throw new PhotonError("unauthorized", `The client credentials were refused: ${reason}`);
|
|
64
|
+
}
|
|
65
|
+
const claims = claimsOf(json.access_token);
|
|
66
|
+
const organization = claims[ORG_CLAIM] ?? claims.org_id;
|
|
67
|
+
if (organization !== config.organizationId) {
|
|
68
|
+
throw new PhotonError(
|
|
69
|
+
"unauthorized",
|
|
70
|
+
`This client's tokens are for ${typeof organization === "string" ? organization : "no organization"}, ` +
|
|
71
|
+
`not ${config.organizationId}: use the client Photon made for that organization.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
held = { token: json.access_token, expiresAt: Date.now() + (json.expires_in ?? 0) * 1000 };
|
|
75
|
+
return json.access_token;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
token() {
|
|
80
|
+
if (held && held.expiresAt - EARLY_MS > Date.now()) return Promise.resolve(held.token);
|
|
81
|
+
pending ??= request().finally(() => {
|
|
82
|
+
pending = null;
|
|
83
|
+
});
|
|
84
|
+
return pending;
|
|
85
|
+
},
|
|
86
|
+
forget() {
|
|
87
|
+
held = null;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|