@photonhealth/client 0.0.0-stage → 2.0.0-rc.1
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 +89 -2
- 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 +43 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +77 -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 +22 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +21 -0
- package/dist/api/index.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/patient.d.ts +33 -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 +31 -0
- package/dist/api/prescription.d.ts.map +1 -0
- package/dist/api/prescription.js +30 -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 +21 -0
- package/dist/gql/gql.d.ts.map +1 -0
- package/dist/gql/gql.js +13 -0
- package/dist/gql/gql.js.map +1 -0
- package/dist/gql/graphql.d.ts +9674 -0
- package/dist/gql/graphql.d.ts.map +1 -0
- package/dist/gql/graphql.js +4030 -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/photon/auth.d.ts +48 -0
- package/dist/photon/auth.d.ts.map +1 -0
- package/dist/photon/auth.js +34 -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 +26 -0
- package/dist/photon/environments.d.ts.map +1 -0
- package/dist/photon/environments.js +26 -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 +23 -0
- package/dist/photon/index.d.ts.map +1 -0
- package/dist/photon/index.js +11 -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/map.d.ts +10 -0
- package/dist/photon/map.d.ts.map +1 -0
- package/dist/photon/map.js +211 -0
- package/dist/photon/map.js.map +1 -0
- package/dist/photon/order.d.ts +148 -0
- package/dist/photon/order.d.ts.map +1 -0
- package/dist/photon/order.js +491 -0
- package/dist/photon/order.js.map +1 -0
- package/dist/photon/patient.d.ts +78 -0
- package/dist/photon/patient.d.ts.map +1 -0
- package/dist/photon/patient.js +316 -0
- package/dist/photon/patient.js.map +1 -0
- package/dist/photon/photon.d.ts +150 -0
- package/dist/photon/photon.d.ts.map +1 -0
- package/dist/photon/photon.js +315 -0
- package/dist/photon/photon.js.map +1 -0
- package/dist/photon/prescription.d.ts +132 -0
- package/dist/photon/prescription.d.ts.map +1 -0
- package/dist/photon/prescription.js +381 -0
- package/dist/photon/prescription.js.map +1 -0
- package/dist/photon/session.d.ts +84 -0
- package/dist/photon/session.d.ts.map +1 -0
- package/dist/photon/session.js +350 -0
- package/dist/photon/session.js.map +1 -0
- package/dist/photon/types.d.ts +411 -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/fixtures.d.ts +51 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +166 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/scriptedClient.d.ts +38 -0
- package/dist/testing/scriptedClient.d.ts.map +1 -0
- package/dist/testing/scriptedClient.js +52 -0
- package/dist/testing/scriptedClient.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/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 +124 -0
- package/src/api/health.ts +7 -0
- package/src/api/index.ts +22 -0
- package/src/api/order.ts +64 -0
- package/src/api/patient.ts +58 -0
- package/src/api/prescription.ts +68 -0
- package/src/api/results.ts +45 -0
- package/src/gql/gql.ts +56 -0
- package/src/gql/graphql.ts +5344 -0
- package/src/gql/index.ts +2 -0
- package/src/index.ts +14 -0
- package/src/operations/fragments.graphql +351 -0
- package/src/operations/health.graphql +4 -0
- package/src/operations/order.graphql +42 -0
- package/src/operations/patient.graphql +36 -0
- package/src/operations/prescription.graphql +70 -0
- package/src/photon/auth.ts +70 -0
- package/src/photon/choices.ts +79 -0
- package/src/photon/context.ts +30 -0
- package/src/photon/environments.ts +47 -0
- package/src/photon/errors.ts +56 -0
- package/src/photon/index.ts +35 -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/map.ts +255 -0
- package/src/photon/order.ts +581 -0
- package/src/photon/patient.ts +346 -0
- package/src/photon/photon.ts +513 -0
- package/src/photon/prescription.ts +447 -0
- package/src/photon/session.ts +445 -0
- package/src/photon/types.ts +329 -0
- package/src/test-utils/msw.ts +61 -0
- package/src/testing/fixtures.ts +191 -0
- package/src/testing/scriptedClient.ts +52 -0
- package/src/testing.ts +22 -0
package/src/gql/index.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @photonhealth/client — Photon Rx without a UI framework. Zero runtime dependencies; runs in browsers,
|
|
3
|
+
* Node, workers and agents.
|
|
4
|
+
*
|
|
5
|
+
* const ph = photon({ environment: "boson", auth: { getToken } });
|
|
6
|
+
* const { patient, candidates, changes } = await ph.patient({ demographic: { … } });
|
|
7
|
+
*
|
|
8
|
+
* network-api's three upsert mutations — patient, prescription, order — one call each, returning live
|
|
9
|
+
* objects (state you can subscribe to; methods that await the web calls) with the workflow rules
|
|
10
|
+
* inside. See docs/CORE.md.
|
|
11
|
+
*
|
|
12
|
+
* This is the whole public surface. The GraphQL layer (api/, gql/) is internal.
|
|
13
|
+
*/
|
|
14
|
+
export * from "./photon/index.ts";
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Shared selection sets. Every operation in this folder composes these, so a
|
|
2
|
+
# component that renders a Patient/Prescription/Order/Change can rely on the
|
|
3
|
+
# same fields no matter which intent produced the payload.
|
|
4
|
+
|
|
5
|
+
# A drug as the catalog describes it: on a prescription, and on each drug option a lookup offers.
|
|
6
|
+
fragment TreatmentFields on Treatment {
|
|
7
|
+
id
|
|
8
|
+
name
|
|
9
|
+
rxNormId
|
|
10
|
+
ndc
|
|
11
|
+
upc
|
|
12
|
+
entityKind
|
|
13
|
+
prescribableName
|
|
14
|
+
brandName
|
|
15
|
+
genericName
|
|
16
|
+
form
|
|
17
|
+
route
|
|
18
|
+
strength
|
|
19
|
+
medicationType
|
|
20
|
+
schedule
|
|
21
|
+
recommendedDispenseUnits
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fragment ChoiceFields on Choice {
|
|
25
|
+
__typename
|
|
26
|
+
displayName
|
|
27
|
+
reason
|
|
28
|
+
operation
|
|
29
|
+
argument
|
|
30
|
+
value
|
|
31
|
+
matchReasons {
|
|
32
|
+
type
|
|
33
|
+
label
|
|
34
|
+
confidence
|
|
35
|
+
}
|
|
36
|
+
entity {
|
|
37
|
+
__typename
|
|
38
|
+
... on Treatment {
|
|
39
|
+
...TreatmentFields
|
|
40
|
+
}
|
|
41
|
+
... on Pharmacy {
|
|
42
|
+
...PharmacyFields
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fragment PharmacyOfferFields on PharmacyOffer {
|
|
48
|
+
source
|
|
49
|
+
isPromoted
|
|
50
|
+
attributeTags {
|
|
51
|
+
kind
|
|
52
|
+
label
|
|
53
|
+
}
|
|
54
|
+
priceSummary {
|
|
55
|
+
priceType
|
|
56
|
+
totalAmount
|
|
57
|
+
totalRetailAmount
|
|
58
|
+
totalSavings
|
|
59
|
+
}
|
|
60
|
+
prescriptionDeliveryEstimates {
|
|
61
|
+
prescriptionId
|
|
62
|
+
deliveryPromise
|
|
63
|
+
deliveryPromiseRangeStart
|
|
64
|
+
deliveryPromiseRangeEnd
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fragment ChangeFields on Change {
|
|
69
|
+
key
|
|
70
|
+
label
|
|
71
|
+
status
|
|
72
|
+
severity
|
|
73
|
+
reason
|
|
74
|
+
category
|
|
75
|
+
operation
|
|
76
|
+
options {
|
|
77
|
+
...ChoiceFields
|
|
78
|
+
}
|
|
79
|
+
before {
|
|
80
|
+
...ChoiceFields
|
|
81
|
+
}
|
|
82
|
+
after {
|
|
83
|
+
...ChoiceFields
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fragment ChangeSetFields on ChangeSet {
|
|
88
|
+
changes {
|
|
89
|
+
...ChangeFields
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fragment OperationErrorFields on OperationError {
|
|
94
|
+
__typename
|
|
95
|
+
type
|
|
96
|
+
code
|
|
97
|
+
message
|
|
98
|
+
requiredPermission
|
|
99
|
+
service
|
|
100
|
+
retryable
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fragment PharmacyFields on Pharmacy {
|
|
104
|
+
id
|
|
105
|
+
name
|
|
106
|
+
address {
|
|
107
|
+
street1
|
|
108
|
+
street2
|
|
109
|
+
city
|
|
110
|
+
state
|
|
111
|
+
postalCode
|
|
112
|
+
}
|
|
113
|
+
latitude
|
|
114
|
+
longitude
|
|
115
|
+
fulfillmentType
|
|
116
|
+
offers {
|
|
117
|
+
...PharmacyOfferFields
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fragment PatientDemographicFields on PatientDemographic {
|
|
122
|
+
name {
|
|
123
|
+
first
|
|
124
|
+
middle
|
|
125
|
+
last
|
|
126
|
+
}
|
|
127
|
+
dateOfBirth
|
|
128
|
+
sex
|
|
129
|
+
gender
|
|
130
|
+
email
|
|
131
|
+
phone
|
|
132
|
+
address {
|
|
133
|
+
street1
|
|
134
|
+
street2
|
|
135
|
+
city
|
|
136
|
+
state
|
|
137
|
+
postalCode
|
|
138
|
+
country
|
|
139
|
+
}
|
|
140
|
+
benefits {
|
|
141
|
+
status
|
|
142
|
+
entries {
|
|
143
|
+
id
|
|
144
|
+
bin
|
|
145
|
+
pcn
|
|
146
|
+
groupId
|
|
147
|
+
memberId
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
preferredPharmacy {
|
|
151
|
+
...PharmacyFields
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fragment PatientFields on Patient {
|
|
156
|
+
id
|
|
157
|
+
demographic {
|
|
158
|
+
...PatientDemographicFields
|
|
159
|
+
}
|
|
160
|
+
clinical {
|
|
161
|
+
allergies {
|
|
162
|
+
status
|
|
163
|
+
entries {
|
|
164
|
+
id
|
|
165
|
+
name
|
|
166
|
+
rxNormId
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
medications {
|
|
170
|
+
status
|
|
171
|
+
entries {
|
|
172
|
+
id
|
|
173
|
+
name
|
|
174
|
+
rxNormId
|
|
175
|
+
status
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
diagnoses {
|
|
179
|
+
status
|
|
180
|
+
entries {
|
|
181
|
+
id
|
|
182
|
+
name
|
|
183
|
+
icd10Code
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
notes
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
fragment PatientRecordFields on PatientRecordResult {
|
|
191
|
+
__typename
|
|
192
|
+
... on Patient {
|
|
193
|
+
...PatientFields
|
|
194
|
+
}
|
|
195
|
+
... on OperationError {
|
|
196
|
+
...OperationErrorFields
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fragment ScreeningAlertFields on ScreeningAlert {
|
|
201
|
+
severity
|
|
202
|
+
type
|
|
203
|
+
description
|
|
204
|
+
category
|
|
205
|
+
involvedEntities {
|
|
206
|
+
id
|
|
207
|
+
name
|
|
208
|
+
}
|
|
209
|
+
options {
|
|
210
|
+
...ChoiceFields
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fragment PrescriptionFields on Prescription {
|
|
215
|
+
id
|
|
216
|
+
templateId
|
|
217
|
+
patient {
|
|
218
|
+
id
|
|
219
|
+
}
|
|
220
|
+
treatment {
|
|
221
|
+
...TreatmentFields
|
|
222
|
+
}
|
|
223
|
+
instructions
|
|
224
|
+
dispense {
|
|
225
|
+
quantity
|
|
226
|
+
unit
|
|
227
|
+
daysSupply
|
|
228
|
+
refillsAllowed
|
|
229
|
+
dispenseAsWritten
|
|
230
|
+
}
|
|
231
|
+
clinical {
|
|
232
|
+
diagnoses {
|
|
233
|
+
id
|
|
234
|
+
name
|
|
235
|
+
icd10Code
|
|
236
|
+
}
|
|
237
|
+
notes
|
|
238
|
+
}
|
|
239
|
+
screeningAlerts {
|
|
240
|
+
...ScreeningAlertFields
|
|
241
|
+
}
|
|
242
|
+
signing {
|
|
243
|
+
state
|
|
244
|
+
contentHash
|
|
245
|
+
message
|
|
246
|
+
signedAt
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
fragment OrderFields on Order {
|
|
251
|
+
id
|
|
252
|
+
state
|
|
253
|
+
patient {
|
|
254
|
+
...PatientRecordFields
|
|
255
|
+
}
|
|
256
|
+
prescriptions {
|
|
257
|
+
...PrescriptionFields
|
|
258
|
+
}
|
|
259
|
+
screeningAlerts {
|
|
260
|
+
...ScreeningAlertFields
|
|
261
|
+
}
|
|
262
|
+
pharmacy {
|
|
263
|
+
...PharmacyFields
|
|
264
|
+
}
|
|
265
|
+
exceptions {
|
|
266
|
+
id
|
|
267
|
+
type
|
|
268
|
+
message
|
|
269
|
+
createdAt
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
# ---- Result selections: one per mutation, reused by every intent on it ----
|
|
274
|
+
|
|
275
|
+
fragment PatientResultFields on PatientResult {
|
|
276
|
+
__typename
|
|
277
|
+
... on PatientPayload {
|
|
278
|
+
patient {
|
|
279
|
+
...PatientRecordFields
|
|
280
|
+
}
|
|
281
|
+
...ChangeSetFields
|
|
282
|
+
}
|
|
283
|
+
... on AmbiguousPatientMatch {
|
|
284
|
+
reason
|
|
285
|
+
candidates {
|
|
286
|
+
id
|
|
287
|
+
firstName
|
|
288
|
+
lastName
|
|
289
|
+
dateOfBirth
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
... on OperationError {
|
|
293
|
+
...OperationErrorFields
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fragment PrescriptionResultFields on PrescriptionResult {
|
|
298
|
+
__typename
|
|
299
|
+
... on PrescriptionPayload {
|
|
300
|
+
prescription {
|
|
301
|
+
...PrescriptionFields
|
|
302
|
+
}
|
|
303
|
+
...ChangeSetFields
|
|
304
|
+
}
|
|
305
|
+
... on AmbiguousPrescriptionMatch {
|
|
306
|
+
reason
|
|
307
|
+
candidates {
|
|
308
|
+
id
|
|
309
|
+
instructions
|
|
310
|
+
dispense {
|
|
311
|
+
quantity
|
|
312
|
+
unit
|
|
313
|
+
daysSupply
|
|
314
|
+
refillsAllowed
|
|
315
|
+
dispenseAsWritten
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
... on OperationError {
|
|
320
|
+
...OperationErrorFields
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
fragment OrderCandidateFields on OrderCandidate {
|
|
325
|
+
id
|
|
326
|
+
pharmacy {
|
|
327
|
+
...PharmacyFields
|
|
328
|
+
}
|
|
329
|
+
prescriptions {
|
|
330
|
+
...PrescriptionFields
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
fragment OrderResultFields on OrderResult {
|
|
335
|
+
__typename
|
|
336
|
+
... on OrderPayload {
|
|
337
|
+
order {
|
|
338
|
+
...OrderFields
|
|
339
|
+
}
|
|
340
|
+
...ChangeSetFields
|
|
341
|
+
}
|
|
342
|
+
... on AmbiguousOrderMatch {
|
|
343
|
+
reason
|
|
344
|
+
candidates {
|
|
345
|
+
...OrderCandidateFields
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
... on OperationError {
|
|
349
|
+
...OperationErrorFields
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Order: Get / Sync / Update — all on the one `order` upsert. An order is DRAFT (no downstream
|
|
2
|
+
# effects) until updated to SUBMITTED.
|
|
3
|
+
# Get id only: read it, with its patient, prescriptions and pharmacy; nothing changes.
|
|
4
|
+
# Sync whatever's known: continues the patient's DRAFT order or starts one (2+ drafts:
|
|
5
|
+
# AmbiguousOrderMatch), with the prescriptions to put on it.
|
|
6
|
+
# Update that one order (by id). Omit a variable to leave that field alone:
|
|
7
|
+
# prescriptions { add } / { remove } (remove disconnects, doesn't cancel)
|
|
8
|
+
# state SUBMITTED sends it; CANCELED only from SUBMITTED
|
|
9
|
+
# pharmacy one field: { pharmacy } routes it there; { none: true } unassigns it (the patient chooses)
|
|
10
|
+
|
|
11
|
+
mutation GetOrder($id: ID!, $metadata: RequestMetadata!) {
|
|
12
|
+
order(order: { id: $id }, metadata: $metadata) {
|
|
13
|
+
...OrderResultFields
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
mutation SyncOrder(
|
|
18
|
+
$id: ID
|
|
19
|
+
$patient: PatientReferenceInput
|
|
20
|
+
$prescriptions: OrderPrescriptionsPatch
|
|
21
|
+
$pharmacy: OrderPharmacyInput
|
|
22
|
+
$metadata: RequestMetadata!
|
|
23
|
+
) {
|
|
24
|
+
order(
|
|
25
|
+
order: { id: $id, patient: $patient, prescriptions: $prescriptions, pharmacy: $pharmacy }
|
|
26
|
+
metadata: $metadata
|
|
27
|
+
) {
|
|
28
|
+
...OrderResultFields
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
mutation UpdateOrder(
|
|
33
|
+
$id: ID!
|
|
34
|
+
$prescriptions: OrderPrescriptionsPatch
|
|
35
|
+
$state: OrderState
|
|
36
|
+
$pharmacy: OrderPharmacyInput
|
|
37
|
+
$metadata: RequestMetadata!
|
|
38
|
+
) {
|
|
39
|
+
order(order: { id: $id, prescriptions: $prescriptions, state: $state, pharmacy: $pharmacy }, metadata: $metadata) {
|
|
40
|
+
...OrderResultFields
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Patient: Get / Sync / Update — all on the one `patient` upsert.
|
|
2
|
+
# Get id only: read it; nothing changes.
|
|
3
|
+
# Sync whatever's known — an id or not: the server finds the patient, lists candidates
|
|
4
|
+
# (AmbiguousPatientMatch — the prescriber picks), says what's missing, or creates one when
|
|
5
|
+
# nothing matches and it has enough (today: first, last, DOB, sex).
|
|
6
|
+
# Update that one patient (by id): only the fields sent change.
|
|
7
|
+
|
|
8
|
+
mutation GetPatient($id: ID!, $metadata: RequestMetadata!) {
|
|
9
|
+
patient(patient: { id: $id }, metadata: $metadata) {
|
|
10
|
+
...PatientResultFields
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mutation SyncPatient(
|
|
15
|
+
$id: ID
|
|
16
|
+
$demographic: PatientDemographicInput
|
|
17
|
+
$clinical: PatientClinicalInput
|
|
18
|
+
$metadata: RequestMetadata!
|
|
19
|
+
) {
|
|
20
|
+
patient(patient: { id: $id, demographic: $demographic, clinical: $clinical }, metadata: $metadata) {
|
|
21
|
+
...PatientResultFields
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Demographics (incl. benefits) and/or clinical patches (allergies — `none: true` for NKDA —
|
|
26
|
+
# medications, diagnoses, notes).
|
|
27
|
+
mutation UpdatePatient(
|
|
28
|
+
$id: ID!
|
|
29
|
+
$demographic: PatientDemographicInput
|
|
30
|
+
$clinical: PatientClinicalInput
|
|
31
|
+
$metadata: RequestMetadata!
|
|
32
|
+
) {
|
|
33
|
+
patient(patient: { id: $id, demographic: $demographic, clinical: $clinical }, metadata: $metadata) {
|
|
34
|
+
...PatientResultFields
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Prescription: Get / Sync / Update — all on the one `prescription` upsert.
|
|
2
|
+
# Get id only: read it, draft or signed; nothing changes.
|
|
3
|
+
# Sync whatever's known. Without a patient it can only look the drug up: the server lists the
|
|
4
|
+
# matching treatments (a DISAMBIGUATION change with options) and rejects the missing patient.
|
|
5
|
+
# With a patient it continues their in-progress draft or starts one (2+ in progress:
|
|
6
|
+
# AmbiguousPrescriptionMatch). ⚠ Send a treatment or template — without one the server
|
|
7
|
+
# copies the patient's last Rx (seen on boson, 2026-09).
|
|
8
|
+
# Update that one prescription (by id): only the fields sent change — or sign it: `signing.signedHash`
|
|
9
|
+
# = the contentHash the prescriber reviewed. Signing can't be combined with content edits.
|
|
10
|
+
# Screening runs on every call; every response carries signing.contentHash.
|
|
11
|
+
|
|
12
|
+
mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {
|
|
13
|
+
prescription(prescription: { id: $id }, metadata: $metadata) {
|
|
14
|
+
...PrescriptionResultFields
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
mutation SyncPrescription(
|
|
19
|
+
$id: ID
|
|
20
|
+
$externalId: String
|
|
21
|
+
$patient: PatientReferenceInput
|
|
22
|
+
$treatment: TreatmentReferenceInput
|
|
23
|
+
$templateId: ID
|
|
24
|
+
$instructions: String
|
|
25
|
+
$dispense: DispenseInput
|
|
26
|
+
$clinical: PrescriptionClinicalInput
|
|
27
|
+
$metadata: RequestMetadata!
|
|
28
|
+
) {
|
|
29
|
+
prescription(
|
|
30
|
+
prescription: {
|
|
31
|
+
id: $id
|
|
32
|
+
externalId: $externalId
|
|
33
|
+
patient: $patient
|
|
34
|
+
treatment: $treatment
|
|
35
|
+
templateId: $templateId
|
|
36
|
+
instructions: $instructions
|
|
37
|
+
dispense: $dispense
|
|
38
|
+
clinical: $clinical
|
|
39
|
+
}
|
|
40
|
+
metadata: $metadata
|
|
41
|
+
) {
|
|
42
|
+
...PrescriptionResultFields
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
mutation UpdatePrescription(
|
|
47
|
+
$id: ID!
|
|
48
|
+
$externalId: String
|
|
49
|
+
$treatment: TreatmentReferenceInput
|
|
50
|
+
$instructions: String
|
|
51
|
+
$dispense: DispenseInput
|
|
52
|
+
$clinical: PrescriptionClinicalInput
|
|
53
|
+
$signing: PrescriptionSigningDetailsInput
|
|
54
|
+
$metadata: RequestMetadata!
|
|
55
|
+
) {
|
|
56
|
+
prescription(
|
|
57
|
+
prescription: {
|
|
58
|
+
id: $id
|
|
59
|
+
externalId: $externalId
|
|
60
|
+
treatment: $treatment
|
|
61
|
+
instructions: $instructions
|
|
62
|
+
dispense: $dispense
|
|
63
|
+
clinical: $clinical
|
|
64
|
+
signing: $signing
|
|
65
|
+
}
|
|
66
|
+
metadata: $metadata
|
|
67
|
+
) {
|
|
68
|
+
...PrescriptionResultFields
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { PhotonError } from "./errors.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How a photon instance gets its token.
|
|
5
|
+
*
|
|
6
|
+
* SPA `{ clientId }` — core signs the prescriber in itself, in the browser (session.ts): `ph.session`.
|
|
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. Core will run the
|
|
9
|
+
* client-credentials grant, cache the token until shortly before it expires, share one refresh
|
|
10
|
+
* between concurrent calls and retry once on a 401. Not built yet (Photon-Health/prescribe#18): the shape is
|
|
11
|
+
* fixed now so it doesn't change later. Servers only: `photon()` refuses a secret in a browser.
|
|
12
|
+
*/
|
|
13
|
+
export type PhotonAuth =
|
|
14
|
+
| { getToken: () => Promise<string> }
|
|
15
|
+
| { clientId: string }
|
|
16
|
+
| { clientId: string; clientSecret: string; organizationId: string };
|
|
17
|
+
|
|
18
|
+
/** Core's own browser sign-in: a client id alone. */
|
|
19
|
+
export const signsIn = (auth: PhotonAuth): auth is { clientId: string } => "clientId" in auth && !hasSecret(auth);
|
|
20
|
+
|
|
21
|
+
/** A client secret, in any shape it's given (M2M). */
|
|
22
|
+
export const hasSecret = (auth: object): boolean => "clientSecret" in auth || "client_secret" in auth;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether this code runs in a browser — a page, or a worker one started — where everything in it, a secret too,
|
|
26
|
+
* is readable by whoever opens the page.
|
|
27
|
+
*/
|
|
28
|
+
export const inBrowser = (): boolean =>
|
|
29
|
+
typeof document !== "undefined" || typeof (globalThis as { importScripts?: unknown }).importScripts === "function";
|
|
30
|
+
|
|
31
|
+
/** A client secret in a browser is a published secret: refused before anything else, and loudly. */
|
|
32
|
+
export function refuseSecretInBrowser(auth: object): void {
|
|
33
|
+
if (!hasSecret(auth) || !inBrowser()) return;
|
|
34
|
+
throw new PhotonError(
|
|
35
|
+
"invalid",
|
|
36
|
+
"SECURITY: a client secret was passed to photon() in a browser. Anyone who opens this page can read it and " +
|
|
37
|
+
"act as your backend — treat it as leaked and rotate it now. Client credentials (M2M) are for servers only; " +
|
|
38
|
+
"in a browser use { clientId } (core signs the prescriber in) or { getToken }.",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
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
|
+
/**
|
|
49
|
+
* How links from an instance sign in (`FlowLink.auth`): an embed signs the prescriber in with the host's own
|
|
50
|
+
* client — `{ clientId }`'s — and any link opens in the instance's organization, when it has one. An M2M client
|
|
51
|
+
* makes webapp links only: its credentials are a server's, so its client id and secret never go in a link.
|
|
52
|
+
*/
|
|
53
|
+
export interface LinkAuth {
|
|
54
|
+
/** The client an embed signs in with: the instance's `{ clientId }`. Never an M2M client's. */
|
|
55
|
+
clientId: string | null;
|
|
56
|
+
/** The organization links open in: `photon({ organization })`, or M2M's `organizationId`. */
|
|
57
|
+
organization: string | null;
|
|
58
|
+
/** M2M: `frame()` is refused. */
|
|
59
|
+
machine: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function linkAuthOf(auth: PhotonAuth, organization?: string): LinkAuth {
|
|
63
|
+
const machine = hasSecret(auth);
|
|
64
|
+
const orgOfMachine = machine ? (auth as { organizationId?: string }).organizationId : undefined;
|
|
65
|
+
return {
|
|
66
|
+
clientId: signsIn(auth) ? auth.clientId : null,
|
|
67
|
+
organization: organization || orgOfMachine || null,
|
|
68
|
+
machine,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { applyAt } from "../api/index.ts";
|
|
2
|
+
import type { Change, ChangeOption, Changes } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Acting on what the server said (a ChangeSet), without parsing its prose.
|
|
6
|
+
*
|
|
7
|
+
* needsChoice AMBIGUOUS — nothing was written; the caller picks an option and sends again
|
|
8
|
+
* blocking REJECTED, or applied but BLOCKING — can't proceed until fixed
|
|
9
|
+
* advisories applied, but worth showing (COST_SAVINGS, PRODUCT_PREFERENCE, …)
|
|
10
|
+
* applied everything else that took effect
|
|
11
|
+
*/
|
|
12
|
+
export interface ClassifiedChanges {
|
|
13
|
+
needsChoice: Change[];
|
|
14
|
+
blocking: Change[];
|
|
15
|
+
advisories: Change[];
|
|
16
|
+
applied: Change[];
|
|
17
|
+
/** Nothing left open: no choice to make, nothing blocking. */
|
|
18
|
+
settled: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function classify(changes: Changes): ClassifiedChanges {
|
|
22
|
+
const result: ClassifiedChanges = { needsChoice: [], blocking: [], advisories: [], applied: [], settled: true };
|
|
23
|
+
for (const c of changes.unapplied) (c.status === "AMBIGUOUS" ? result.needsChoice : result.blocking).push(c);
|
|
24
|
+
for (const c of changes.applied) {
|
|
25
|
+
if (c.severity === "BLOCKING") result.blocking.push(c);
|
|
26
|
+
else if (c.severity === "ADVISORY") result.advisories.push(c);
|
|
27
|
+
else result.applied.push(c);
|
|
28
|
+
}
|
|
29
|
+
result.settled = result.needsChoice.length === 0 && result.blocking.length === 0;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The changes waiting for a pick (e.g. which lisinopril), each with its options. Nothing was written for them. */
|
|
34
|
+
export const choicesIn = (changes: Changes): Change[] => changes.unapplied.filter((c) => c.status === "AMBIGUOUS");
|
|
35
|
+
|
|
36
|
+
const DECLARED = ["EXACT_NAME_MATCH", "RXNORM_CODE_MATCH"];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The one option the server has *declared* the match: a choice with a single option marked an exact name
|
|
40
|
+
* or RxNorm match. Taken without asking; anything else — fuzzy, several options, no match type — is the
|
|
41
|
+
* caller's (the prescriber's) pick.
|
|
42
|
+
*/
|
|
43
|
+
export function declaredChoice(changes: Changes): ChangeOption | null {
|
|
44
|
+
for (const change of choicesIn(changes)) {
|
|
45
|
+
const [only, ...rest] = change.options;
|
|
46
|
+
if (only && !rest.length && only.matchReasons.some((r) => DECLARED.includes(r.type))) return only;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The input to send again with a pick applied — the option says where it goes (`path`) and what (`value`).
|
|
53
|
+
* Never parse an option's prose. (On a live object, `obj.choose(option)` does this for you.)
|
|
54
|
+
*
|
|
55
|
+
* const { changes } = await ph.prescription({ treatment: { name: "lisinopril" } });
|
|
56
|
+
* const option = choicesIn(changes)[0]!.options[1]!;
|
|
57
|
+
* await ph.prescription(withChoice({ patient: { id }, treatment: { name: "lisinopril" } }, option));
|
|
58
|
+
*/
|
|
59
|
+
export function withChoice<T>(input: T, option: ChangeOption): T {
|
|
60
|
+
if (!option.path) throw new Error(`"${option.displayName}" calls ${option.operation}; it doesn't go in this input.`);
|
|
61
|
+
return applyAt(input, option.path, option.value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A key for an option — the same pick gives the same key. */
|
|
65
|
+
export const optionKey = (option: ChangeOption) => `${option.path}=${JSON.stringify(option.value)}`;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Does the server want a mailing address for this patient? network-api says so either as an unapplied
|
|
69
|
+
* change under demographic.address (patient upserts) or in an error ("patient … has no address", at
|
|
70
|
+
* submit). Ask for one only when it does — a phone is often enough.
|
|
71
|
+
*/
|
|
72
|
+
export function asksForAddress(changes?: Changes | null, message?: string | null): boolean {
|
|
73
|
+
const fromChanges = (changes?.unapplied ?? []).some(
|
|
74
|
+
(c) =>
|
|
75
|
+
c.key.startsWith("demographic.address") ||
|
|
76
|
+
(c.category === "MISSING_INPUT" && /address/i.test(`${c.label} ${c.reason ?? ""}`)),
|
|
77
|
+
);
|
|
78
|
+
return fromChanges || /\baddress\b/i.test(message ?? "");
|
|
79
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { NetworkClient } from "../api/index.ts";
|
|
2
|
+
import type { Order } from "./order.ts";
|
|
3
|
+
import type { Patient } from "./patient.ts";
|
|
4
|
+
import type { Prescription } from "./prescription.ts";
|
|
5
|
+
import type { Changes, OrderRecord, PatientRecord, PrescriptionRecord } from "./types.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What a photon instance's objects share: the client, and one object per record. `patient(record)` gives
|
|
9
|
+
* the object for that record — the one already held (which takes this copy, if it's idle) or a new one.
|
|
10
|
+
*/
|
|
11
|
+
export interface Context {
|
|
12
|
+
client: NetworkClient;
|
|
13
|
+
patient(record: PatientRecord, changes?: Changes): Patient;
|
|
14
|
+
prescription(record: PrescriptionRecord, changes?: Changes): Prescription;
|
|
15
|
+
order(record: OrderRecord, changes?: Changes): Order;
|
|
16
|
+
/** The object for a record by id: the one held, or read (null when there's no such record). */
|
|
17
|
+
openPatient(id: string): Promise<Patient | null>;
|
|
18
|
+
openPrescription(id: string): Promise<Prescription | null>;
|
|
19
|
+
/** The app's link to an object's flow, and the embeddable one (ph.url / ph.frame). */
|
|
20
|
+
url(obj: Patient | Prescription | Order): string;
|
|
21
|
+
frame(obj: Patient | Prescription | Order): string;
|
|
22
|
+
/** An object made before its record just got one: hold it as that record's object (unless one is held). */
|
|
23
|
+
|
|
24
|
+
register(obj: Patient | Prescription | Order): void;
|
|
25
|
+
held: {
|
|
26
|
+
patients: Map<string, Patient>;
|
|
27
|
+
prescriptions: Map<string, Prescription>;
|
|
28
|
+
orders: Map<string, Order>;
|
|
29
|
+
};
|
|
30
|
+
}
|