@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,149 @@
1
+ import type { RequestMetadata, RequestSource } from "../gql/graphql.ts";
2
+ import type { TypedDocumentString } from "../gql/graphql.ts";
3
+
4
+ /**
5
+ * The only thing that talks HTTP. Framework-agnostic and auth-library-agnostic:
6
+ * tokens come in through `getToken`, and every call gets RequestMetadata stamped
7
+ * with the operation's name, so the server can tell a SyncPrescription from an
8
+ * UpdatePrescription even though both hit `prescription`.
9
+ */
10
+
11
+ interface NetworkClientOptions {
12
+ /** e.g. https://network.boson.health/graphql */
13
+ url: string;
14
+ /** Returns a token accepted by network-api, including a patient token or a prescriber's access token. */
15
+ getToken: () => Promise<string>;
16
+ /** How this client is surfaced. Embeds should pass EMBEDDABLE_COMPONENT. */
17
+ source?: RequestSource;
18
+ /** Prefix for RequestMetadata.client; the operation name is appended: "photon-rx/UpdateOrder". */
19
+ clientName?: string;
20
+ sourceVersion?: string;
21
+ fetch?: typeof fetch;
22
+ /**
23
+ * When network-api refuses the token (401, UNAUTHENTICATED): drop it — the call is then tried once more, with a new one. For a
24
+ * token core gets itself (client credentials); a host's `getToken` or a prescriber's session doesn't retry.
25
+ */
26
+ onUnauthorized?: () => void;
27
+ }
28
+
29
+ /** Variables for an operation, minus the metadata the client fills in. */
30
+ export type OperationVariables<V> = Omit<V, "metadata">;
31
+
32
+ export interface NetworkClient {
33
+ execute<R, V>(
34
+ document: TypedDocumentString<R, V>,
35
+ variables: OperationVariables<V>,
36
+ options?: { signal?: AbortSignal },
37
+ ): Promise<R>;
38
+ }
39
+
40
+ /** Transport / GraphQL-level failure: bad token, network down, invalid document. */
41
+ export class NetworkTransportError extends Error {
42
+ constructor(
43
+ message: string,
44
+ readonly operationName: string,
45
+ readonly status?: number,
46
+ readonly code?: string,
47
+ readonly errors?: unknown[],
48
+ ) {
49
+ super(message);
50
+ this.name = "NetworkTransportError";
51
+ }
52
+ }
53
+
54
+ const OPERATION_NAME = /\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/;
55
+
56
+ export function operationNameOf(document: { toString(): string }): string {
57
+ return OPERATION_NAME.exec(document.toString())?.[1] ?? "anonymous";
58
+ }
59
+
60
+ /** Every string in the variables, trimmed — so no field ever reaches network-api with stray whitespace. */
61
+ export function trimStrings<T>(value: T): T {
62
+ if (typeof value === "string") return value.trim() as T;
63
+ if (Array.isArray(value)) return value.map(trimStrings) as T;
64
+ if (value && typeof value === "object") {
65
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, trimStrings(v)])) as T;
66
+ }
67
+ return value;
68
+ }
69
+
70
+ function requestId(): string {
71
+ return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
72
+ }
73
+
74
+ export function createNetworkClient(options: NetworkClientOptions): NetworkClient {
75
+ // The global fetch is looked up on each call, not when the client is made: a fetch patched later (a mock
76
+ // like MSW's, a polyfill) is the one used.
77
+ const doFetch: typeof fetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
78
+ const clientName = options.clientName ?? "photon-rx";
79
+
80
+ const client: NetworkClient = {
81
+ async execute(document, variables, { signal } = {}) {
82
+ try {
83
+ return await once(document, variables, signal);
84
+ } catch (e) {
85
+ if (
86
+ !options.onUnauthorized ||
87
+ !(e instanceof NetworkTransportError) ||
88
+ (e.status !== 401 && e.code !== "UNAUTHENTICATED")
89
+ )
90
+ throw e;
91
+ options.onUnauthorized();
92
+ return once(document, variables, signal);
93
+ }
94
+ },
95
+ };
96
+ return client;
97
+
98
+ async function once<R, V>(
99
+ document: TypedDocumentString<R, V>,
100
+ variables: OperationVariables<V>,
101
+ signal?: AbortSignal,
102
+ ): Promise<R> {
103
+ const operationName = operationNameOf(document);
104
+ const metadata: RequestMetadata = {
105
+ source: options.source ?? "WEB_APP",
106
+ client: `${clientName}/${operationName}`,
107
+ sourceVersion: options.sourceVersion,
108
+ requestId: requestId(),
109
+ };
110
+ const token = await options.getToken();
111
+
112
+ const response = await doFetch(options.url, {
113
+ method: "POST",
114
+ signal,
115
+ headers: {
116
+ "content-type": "application/json",
117
+ accept: "application/graphql-response+json, application/json",
118
+ // Standard Bearer (network-api also still takes x-photon-auth-token). CORS allows only
119
+ // Authorization, Content-Type and x-photon-auth-token — any other custom header fails preflight.
120
+ authorization: `Bearer ${token}`,
121
+ },
122
+ body: JSON.stringify({
123
+ operationName,
124
+ query: document.toString(),
125
+ // Every mutation takes RequestMetadata; queries (Ping) just ignore it.
126
+ variables: document.toString().includes("$metadata")
127
+ ? { ...trimStrings(variables), metadata }
128
+ : trimStrings(variables),
129
+ }),
130
+ });
131
+
132
+ const body = (await response.json().catch(() => null)) as {
133
+ data?: unknown;
134
+ errors?: { message: string; extensions?: { code?: string } }[];
135
+ } | null;
136
+
137
+ if (body?.errors?.length || !body?.data) {
138
+ const first = body?.errors?.[0];
139
+ throw new NetworkTransportError(
140
+ first?.message ?? `network-api responded ${response.status}`,
141
+ operationName,
142
+ response.status,
143
+ first?.extensions?.code,
144
+ body?.errors,
145
+ );
146
+ }
147
+ return body.data as never;
148
+ }
149
+ }
@@ -0,0 +1,7 @@
1
+ import type { NetworkClient } from "./client.ts";
2
+ import { PingDocument } from "../gql/graphql.ts";
3
+
4
+ /** Confirms network-api is reachable and accepts our token. */
5
+ export async function ping(client: NetworkClient): Promise<string> {
6
+ return (await client.execute(PingDocument, {})).ping;
7
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The network-api layer: the only code that talks HTTP.
3
+ *
4
+ * client createNetworkClient: fetch + auth header + RequestMetadata
5
+ * Every resource has the same three operations on its one upsert mutation:
6
+ * patient getPatient · syncPatient · updatePatient
7
+ * prescription getPrescription · syncPrescription · updatePrescription (no patient → a drug lookup)
8
+ * order getOrder · syncOrder · updateOrder (+ submitOrder = update state SUBMITTED)
9
+ * health ping
10
+ * changes classifyChanges, applyOption — how to act on any ChangeSet
11
+ *
12
+ * Internal: photon/ builds the public API on it.
13
+ */
14
+ export * from "./client.ts";
15
+ export * from "./results.ts";
16
+ export * from "./health.ts";
17
+ export * from "./me.ts";
18
+ export * from "./patient.ts";
19
+ export * from "./prescription.ts";
20
+ export * from "./order.ts";
21
+ export * from "./orders.ts";
22
+ export * from "./changes/index.ts";
23
+ // Schema types (inputs, enums, fragments) generated from network-api.
24
+ export type * from "../gql/graphql.ts";
package/src/api/me.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { NetworkClient } from "./client.ts";
2
+ import { MeDocument, type MeQuery } from "../gql/graphql.ts";
3
+ import { assertNotOperationError } from "./results.ts";
4
+
5
+ export async function me(client: NetworkClient) {
6
+ return assertNotOperationError<MeQuery["me"]>((await client.execute(MeDocument, {})).me);
7
+ }
@@ -0,0 +1,64 @@
1
+ import type { ChangeSet } from "./changes/index.ts";
2
+ import type { NetworkClient, OperationVariables } from "./client.ts";
3
+ import {
4
+ GetOrderDocument,
5
+ SyncOrderDocument,
6
+ UpdateOrderDocument,
7
+ type OrderFieldsFragment,
8
+ type OrderResultFieldsFragment,
9
+ type SyncOrderMutationVariables,
10
+ type UpdateOrderMutationVariables,
11
+ } from "../gql/graphql.ts";
12
+ import { assertNotOperationError, type Outcome } from "./results.ts";
13
+
14
+ export type Order = OrderFieldsFragment;
15
+ export type OrderCandidate = Extract<
16
+ OrderResultFieldsFragment,
17
+ { __typename: "AmbiguousOrderMatch" }
18
+ >["candidates"][number];
19
+
20
+ export type OrderOutcome = Outcome<
21
+ { order: Order | null; changes: ChangeSet },
22
+ { reason: string; candidates: OrderCandidate[] }
23
+ >;
24
+
25
+ function settle(result: OrderResultFieldsFragment, sent: unknown): OrderOutcome {
26
+ const r = assertNotOperationError(result);
27
+ if (r.__typename === "AmbiguousOrderMatch") {
28
+ return { kind: "ambiguous", reason: r.reason, candidates: r.candidates };
29
+ }
30
+ return {
31
+ kind: "ok",
32
+ order: r.order,
33
+ changes: { changes: r.changes, sent },
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Fields you can patch on an order. Omit one to leave it alone; `pharmacy: { none: true }` unassigns it
39
+ * (the patient chooses again — works after submit too).
40
+ */
41
+ type OrderPatch = Omit<OperationVariables<UpdateOrderMutationVariables>, "id">;
42
+
43
+ /** GetOrder — read a known order with its patient, prescriptions and pharmacy. */
44
+ export async function getOrder(client: NetworkClient, id: string) {
45
+ return settle((await client.execute(GetOrderDocument, { id })).order, { id });
46
+ }
47
+
48
+ /**
49
+ * SyncOrder — whatever's known: the patient's DRAFT order (continued) or a new one, with the prescriptions to
50
+ * put on it; with an id, that order. Nothing is sent until submitOrder.
51
+ */
52
+ export async function syncOrder(client: NetworkClient, input: OperationVariables<SyncOrderMutationVariables>) {
53
+ return settle((await client.execute(SyncOrderDocument, input)).order, input);
54
+ }
55
+
56
+ /** UpdateOrder — e.g. `{ prescriptions: { add } }`, `{ pharmacy: { pharmacy } }`, `{ pharmacy: { none: true } }`, `{ state: "CANCELED" }`. */
57
+ export async function updateOrder(client: NetworkClient, id: string, patch: OrderPatch) {
58
+ return settle((await client.execute(UpdateOrderDocument, { id, ...patch })).order, patch);
59
+ }
60
+
61
+ /** Send = UpdateOrder to SUBMITTED. Pharmacy untouched: none → the patient chooses; an existing choice is kept. */
62
+ export function submitOrder(client: NetworkClient, id: string) {
63
+ return updateOrder(client, id, { state: "SUBMITTED" });
64
+ }
@@ -0,0 +1,8 @@
1
+ import type { NetworkClient, OperationVariables } from "./client.ts";
2
+ import { OrdersDocument, type OrdersQueryVariables } from "../gql/graphql.ts";
3
+ import { assertNotOperationError } from "./results.ts";
4
+
5
+ /** The read-only Orders query. It never routes an order, including a lone pharmacy match. */
6
+ export async function orders(client: NetworkClient, input: OperationVariables<OrdersQueryVariables>) {
7
+ return assertNotOperationError((await client.execute(OrdersDocument, input)).orders);
8
+ }
@@ -0,0 +1,67 @@
1
+ import type { ChangeSet } from "./changes/index.ts";
2
+ import type { NetworkClient } from "./client.ts";
3
+ import {
4
+ GetPatientDocument,
5
+ SyncPatientDocument,
6
+ UpdatePatientDocument,
7
+ type BenefitsPatch,
8
+ type PatientClinicalInput,
9
+ type PatientContactInput,
10
+ type PatientDemographicInput,
11
+ type PatientFieldsFragment,
12
+ type PatientResultFieldsFragment,
13
+ type PharmacyReferenceInput,
14
+ } from "../gql/graphql.ts";
15
+ import { OperationFailure, assertNotOperationError, type Outcome } from "./results.ts";
16
+
17
+ export type Patient = PatientFieldsFragment;
18
+ export type PatientCandidate = Extract<
19
+ PatientResultFieldsFragment,
20
+ { __typename: "AmbiguousPatientMatch" }
21
+ >["candidates"][number];
22
+
23
+ export type PatientOutcome = Outcome<
24
+ { patient: Patient | null; changes: ChangeSet },
25
+ { reason: string; candidates: PatientCandidate[] }
26
+ >;
27
+
28
+ function settle(result: PatientResultFieldsFragment, sent: unknown): PatientOutcome {
29
+ const r = assertNotOperationError(result);
30
+ if (r.__typename === "AmbiguousPatientMatch") {
31
+ return { kind: "ambiguous", reason: r.reason, candidates: r.candidates };
32
+ }
33
+ const record = r.patient;
34
+ if (record?.__typename === "OperationError") throw new OperationFailure(record);
35
+ return {
36
+ kind: "ok",
37
+ patient: record ?? null,
38
+ changes: { changes: r.changes, sent },
39
+ };
40
+ }
41
+
42
+ /** GetPatient — read a known patient. */
43
+ export async function getPatient(client: NetworkClient, id: string) {
44
+ return settle((await client.execute(GetPatientDocument, { id })).patient, { id });
45
+ }
46
+
47
+ type PatientFields = {
48
+ demographic?: PatientDemographicInput;
49
+ contact?: PatientContactInput;
50
+ clinical?: PatientClinicalInput;
51
+ benefits?: BenefitsPatch;
52
+ preferredPharmacy?: PharmacyReferenceInput;
53
+ };
54
+
55
+ /**
56
+ * SyncPatient — whatever's known, an id or not: the server finds the patient, lists candidates (the prescriber
57
+ * picks), says what's missing, or creates one when nothing matches and it has enough (today: first, last, DOB,
58
+ * sex — leave `sex` out to look without creating).
59
+ */
60
+ export async function syncPatient(client: NetworkClient, input: PatientFields & { id?: string }, signal?: AbortSignal) {
61
+ return settle((await client.execute(SyncPatientDocument, input, { signal })).patient, input);
62
+ }
63
+
64
+ /** UpdatePatient — change that one patient: demographics, contact, benefits, preferred pharmacy and/or clinical lists. NKDA: `clinical: { allergies: { none: true } }`. */
65
+ export async function updatePatient(client: NetworkClient, id: string, patch: PatientFields) {
66
+ return settle((await client.execute(UpdatePatientDocument, { id, ...patch })).patient, patch);
67
+ }
@@ -0,0 +1,86 @@
1
+ import type { ChangeSet } from "./changes/index.ts";
2
+ import type { NetworkClient, OperationVariables } from "./client.ts";
3
+ import {
4
+ GetPrescriptionDocument,
5
+ GetPrescriptionTemplatesDocument,
6
+ SyncPrescriptionDocument,
7
+ UpdatePrescriptionDocument,
8
+ type SyncPrescriptionMutationVariables,
9
+ type UpdatePrescriptionMutationVariables,
10
+ type PrescriptionFieldsFragment,
11
+ type PrescriptionResultFieldsFragment,
12
+ type PrescriptionTemplateFieldsFragment,
13
+ } from "../gql/graphql.ts";
14
+ import { assertNotOperationError, type Outcome } from "./results.ts";
15
+
16
+ export type Prescription = PrescriptionFieldsFragment;
17
+ export type PrescriptionCandidate = Extract<
18
+ PrescriptionResultFieldsFragment,
19
+ { __typename: "AmbiguousPrescriptionMatch" }
20
+ >["candidates"][number];
21
+
22
+ export type PrescriptionOutcome = Outcome<
23
+ { prescription: Prescription | null; changes: ChangeSet },
24
+ { reason: string; candidates: PrescriptionCandidate[] }
25
+ >;
26
+
27
+ function settle(result: PrescriptionResultFieldsFragment, sent: unknown): PrescriptionOutcome {
28
+ const r = assertNotOperationError(result);
29
+ if (r.__typename === "AmbiguousPrescriptionMatch") {
30
+ return { kind: "ambiguous", reason: r.reason, candidates: r.candidates };
31
+ }
32
+ return {
33
+ kind: "ok",
34
+ prescription: r.prescription,
35
+ changes: { changes: r.changes, sent },
36
+ };
37
+ }
38
+
39
+ /** What a sync sends: an id or not, a patient or not, and the fields known. */
40
+ type PrescriptionSync = OperationVariables<SyncPrescriptionMutationVariables>;
41
+ /** Fields you can change on a draft (everything but the id), or the signing. */
42
+ type PrescriptionPatch = Omit<OperationVariables<UpdatePrescriptionMutationVariables>, "id">;
43
+
44
+ /** GetPrescription — read a known prescription, draft or signed. */
45
+ export async function getPrescription(client: NetworkClient, id: string) {
46
+ return settle((await client.execute(GetPrescriptionDocument, { id })).prescription, { id });
47
+ }
48
+
49
+ /**
50
+ * GetPrescriptionTemplates — the templates for a prescription's drug: the caller's catalog templates, then recommended
51
+ * ones (sigs worded for its patient, and units). null when network-api has none to offer (not a draft, or the catalog
52
+ * lookup failed).
53
+ */
54
+ export async function getPrescriptionTemplates(
55
+ client: NetworkClient,
56
+ id: string,
57
+ signal?: AbortSignal,
58
+ ): Promise<readonly PrescriptionTemplateFieldsFragment[] | null> {
59
+ const result = assertNotOperationError(
60
+ (await client.execute(GetPrescriptionTemplatesDocument, { id }, { signal })).prescription,
61
+ );
62
+ return result.__typename === "PrescriptionPayload" ? (result.prescription?.treatment.templates ?? null) : null;
63
+ }
64
+
65
+ /**
66
+ * SyncPrescription — whatever's known. Without a patient it can only look the drug up (its choices, or why
67
+ * nothing matched); with one it continues their in-progress draft or starts one. Always send a treatment or
68
+ * template with a patient (without one the server copies the patient's last Rx).
69
+ */
70
+ export async function syncPrescription(client: NetworkClient, input: PrescriptionSync, signal?: AbortSignal) {
71
+ return settle(
72
+ (
73
+ await client.execute(
74
+ SyncPrescriptionDocument,
75
+ { ...input, templateId: input.templateId ?? undefined },
76
+ { signal },
77
+ )
78
+ ).prescription,
79
+ input,
80
+ );
81
+ }
82
+
83
+ /** UpdatePrescription — change only the fields sent, or sign; screening re-runs and contentHash changes. */
84
+ export async function updatePrescription(client: NetworkClient, id: string, patch: PrescriptionPatch) {
85
+ return settle((await client.execute(UpdatePrescriptionDocument, { id, ...patch })).prescription, patch);
86
+ }
@@ -0,0 +1,45 @@
1
+ import type { OperationErrorFieldsFragment, OperationErrorType } from "../gql/graphql.ts";
2
+
3
+ /**
4
+ * network-api results are tiered unions:
5
+ * Payload — the business outcome (may still carry REJECTED/BLOCKING changes)
6
+ * Ambiguous*Match — a likely duplicate; nothing was written, pick a candidate and retry
7
+ * OperationError — a real failure (`type`: UNAUTHORIZED or UPSTREAM_SERVICE)
8
+ *
9
+ * We return the first two as a discriminated `Outcome` (the UI must handle
10
+ * both) and throw the last as `OperationFailure` (the UI shows an error).
11
+ */
12
+
13
+ export type Outcome<TOk, TAmbiguous> = ({ kind: "ok" } & TOk) | ({ kind: "ambiguous" } & TAmbiguous);
14
+
15
+ export class OperationFailure extends Error {
16
+ readonly code: string;
17
+ readonly type: OperationErrorType;
18
+ readonly requiredPermission?: string | null;
19
+ readonly service?: string | null;
20
+ readonly retryable: boolean;
21
+
22
+ constructor(error: OperationErrorFieldsFragment) {
23
+ super(error.message);
24
+ this.name = "OperationFailure";
25
+ this.code = error.code;
26
+ this.type = error.type;
27
+ this.requiredPermission = error.requiredPermission;
28
+ this.service = error.service;
29
+ this.retryable = error.retryable;
30
+ }
31
+ }
32
+
33
+ function isOperationError<T extends { __typename: string }>(
34
+ result: T,
35
+ ): result is Extract<T, { __typename: "OperationError" }> {
36
+ return result.__typename === "OperationError";
37
+ }
38
+
39
+ /** Throws on real failures so callers only ever see business outcomes. */
40
+ export function assertNotOperationError<T extends { __typename: string }>(
41
+ result: T,
42
+ ): Exclude<T, { __typename: "OperationError" }> {
43
+ if (isOperationError(result)) throw new OperationFailure(result as unknown as OperationErrorFieldsFragment);
44
+ return result as never;
45
+ }
package/src/gql/gql.ts ADDED
@@ -0,0 +1,68 @@
1
+ /* eslint-disable */
2
+ import * as types from './graphql.js';
3
+
4
+
5
+
6
+ /**
7
+ * Map of all GraphQL operations in the project.
8
+ *
9
+ * This map has several performance disadvantages:
10
+ * 1. It is not tree-shakeable, so it will include all operations in the project.
11
+ * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
12
+ * 3. It does not support dead code elimination, so it will add unused operations.
13
+ *
14
+ * Therefore it is highly recommended to use the babel or swc plugin for production.
15
+ * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
16
+ */
17
+ type Documents = {
18
+ "fragment TreatmentFields on Treatment {\n id\n name\n rxNormId\n ndc\n upc\n entityKind\n prescribableName\n brandName\n genericName\n form\n route\n strength\n medicationType\n schedule\n}\n\nfragment ChoiceFields on Choice {\n __typename\n displayName\n reason\n operation\n argument\n value\n matchReasons {\n type\n label\n confidence\n value {\n displayValue\n value\n unit\n }\n }\n entity {\n __typename\n ... on Treatment {\n ...TreatmentFields\n templates {\n ...PrescriptionTemplateFields\n }\n }\n ... on Pharmacy {\n ...PharmacyFields\n }\n }\n}\n\nfragment PharmacyOfferFields on PharmacyOffer {\n source\n prescriptionId\n priceType\n isPromoted\n attributeTags {\n kind\n label\n }\n price {\n amount\n retailAmount\n promotions {\n type\n baseAmount\n amountSaved\n }\n }\n deliveryEstimate {\n deliveryPromise\n deliveryPromiseRangeStart\n deliveryPromiseRangeEnd\n }\n redemptionState\n redemptionMethods {\n ...RedemptionMethodFields\n }\n}\n\nfragment RedemptionMethodFields on RedemptionMethod {\n __typename\n ... on PharmacyDiscountCard {\n id\n prescriptionId\n bin\n pcn\n group\n memberId\n externalUrl\n }\n}\n\nfragment ChangeFields on Change {\n key\n label\n status\n severity\n reason\n category\n operation\n options {\n ...ChoiceFields\n }\n before {\n ...ChoiceFields\n }\n after {\n ...ChoiceFields\n }\n}\n\nfragment ChangeSetFields on ChangeSet {\n changes {\n ...ChangeFields\n }\n}\n\nfragment OperationErrorFields on OperationError {\n __typename\n type\n code\n message\n requiredPermission\n service\n retryable\n}\n\nfragment PharmacyFields on Pharmacy {\n id\n name\n logo\n phone\n hours {\n openFrom\n openUntil\n dayOfWeek\n is24Hr\n timezone\n }\n isOpen\n nextEvents {\n open {\n ...PharmacyEventFields\n }\n close {\n ...PharmacyEventFields\n }\n }\n address {\n street1\n street2\n city\n state\n postalCode\n }\n latitude\n longitude\n fulfillmentType\n offers {\n ...PharmacyOfferFields\n }\n}\n\nfragment PharmacyEventFields on PharmacyEvent {\n __typename\n ... on PharmacyOpenEvent {\n type\n datetime\n }\n ... on PharmacyCloseEvent {\n type\n datetime\n }\n ... on PharmacyOpen24HrEvent {\n type\n }\n}\n\nfragment OrganizationFields on Organization {\n id\n name\n customer {\n __typename\n ... on Customer {\n id\n name\n }\n }\n settings {\n brandColor\n brandLogo\n priorAuthorizationExceptionMessage\n patientUx {\n enablePatientRerouting\n enableAutomatedOps\n }\n }\n}\n\nfragment PatientDemographicFields on PatientDemographic {\n name {\n first\n middle\n last\n }\n dateOfBirth\n sex\n gender\n}\n\nfragment PatientContactFields on PatientContact {\n email\n phone\n address {\n street1\n street2\n city\n state\n postalCode\n country\n }\n}\n\nfragment PatientFields on Patient {\n id\n demographic {\n ...PatientDemographicFields\n }\n contact {\n ...PatientContactFields\n }\n benefits {\n status\n entries {\n id\n bin\n pcn\n groupId\n memberId\n }\n }\n preferredPharmacy {\n ...PharmacyFields\n }\n clinical {\n allergies {\n status\n entries {\n id\n name\n rxNormId\n }\n }\n medications {\n status\n entries {\n id\n name\n rxNormId\n status\n }\n }\n diagnoses {\n status\n entries {\n id\n name\n icd10Code\n }\n }\n notes\n }\n}\n\nfragment PatientRecordFields on PatientRecordResult {\n __typename\n ... on Patient {\n ...PatientFields\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment ScreeningAlertFields on ScreeningAlert {\n severity\n type\n description\n category\n involvedEntities {\n id\n name\n }\n options {\n ...ChoiceFields\n }\n}\n\nfragment PrescriptionFields on Prescription {\n id\n prescriber {\n id\n name {\n first\n middle\n last\n }\n }\n fulfillment {\n state\n pharmacyEstimatedReadyAt\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n templateId\n patient {\n id\n }\n treatment {\n ...TreatmentFields\n }\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n clinical {\n diagnoses {\n id\n name\n icd10Code\n }\n notes\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n signing {\n state\n contentHash\n message\n signedAt\n }\n}\n\nfragment OrderFields on Order {\n id\n state\n offers {\n atPharmacy {\n ...PharmacyOfferFields\n }\n }\n organization {\n __typename\n ... on Organization {\n ...OrganizationFields\n }\n }\n patient {\n ...PatientRecordFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n pharmacy {\n ...PharmacyFields\n }\n fulfillment {\n state\n history {\n pharmacy {\n ...PharmacyFields\n }\n selector\n reason\n createdAt\n }\n routability {\n allowed\n reason\n }\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n}\n\nfragment PrescriptionTemplateFields on PrescriptionTemplate {\n id\n source\n name\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n}\n\nfragment PatientResultFields on PatientResult {\n __typename\n ... on PatientPayload {\n patient {\n ...PatientRecordFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment PrescriptionResultFields on PrescriptionResult {\n __typename\n ... on PrescriptionPayload {\n prescription {\n ...PrescriptionFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPrescriptionMatch {\n reason\n candidates {\n id\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment OrderCandidateFields on OrderCandidate {\n id\n pharmacy {\n ...PharmacyFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n}\n\nfragment OrderResultFields on OrderResult {\n __typename\n ... on OrderPayload {\n order {\n ...OrderFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousOrderMatch {\n reason\n candidates {\n ...OrderCandidateFields\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}": typeof types.TreatmentFieldsFragmentDoc,
19
+ "query Ping {\n ping\n}": typeof types.PingDocument,
20
+ "query Me {\n me {\n __typename\n ... on User {\n id\n name {\n first\n last\n }\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ... on Patient {\n id\n name {\n first\n last\n }\n }\n ... on Machine {\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ...OperationErrorFields\n }\n}": typeof types.MeDocument,
21
+ "mutation GetOrder($id: ID!, $metadata: RequestMetadata!) {\n order(order: {id: $id}, metadata: $metadata) {\n ...OrderResultFields\n }\n}\n\nmutation SyncOrder($id: ID, $patient: PatientReferenceInput, $prescriptions: OrderPrescriptionsPatch, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, patient: $patient, prescriptions: $prescriptions, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}\n\nmutation UpdateOrder($id: ID!, $prescriptions: OrderPrescriptionsPatch, $state: OrderState, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, prescriptions: $prescriptions, state: $state, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}": typeof types.GetOrderDocument,
22
+ "query Orders($filter: OrdersFilterInput, $limit: Int, $pharmacy: PharmacyReferenceInput, $page: PageInput, $includePharmacies: Boolean!) {\n orders(filter: $filter, limit: $limit) {\n __typename\n ... on OrdersPayload {\n orders {\n ...OrderFields\n routablePharmacies(pharmacy: $pharmacy, page: $page) @include(if: $includePharmacies) {\n options {\n ...ChoiceFields\n }\n totalCount\n nextOffset\n }\n }\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ...OperationErrorFields\n }\n}": typeof types.OrdersDocument,
23
+ "mutation GetPatient($id: ID!, $metadata: RequestMetadata!) {\n patient(patient: {id: $id}, metadata: $metadata) {\n ...PatientResultFields\n }\n}\n\nmutation SyncPatient($id: ID, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}\n\nmutation UpdatePatient($id: ID!, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}": typeof types.GetPatientDocument,
24
+ "mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n ...PrescriptionResultFields\n }\n}\n\nmutation GetPrescriptionTemplates($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n __typename\n ... on PrescriptionPayload {\n prescription {\n treatment {\n templates {\n ...PrescriptionTemplateFields\n }\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n }\n}\n\nmutation SyncPrescription($id: ID, $externalId: String, $patient: PatientReferenceInput, $treatment: TreatmentReferenceInput, $templateId: ID, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, patient: $patient, treatment: $treatment, templateId: $templateId, instructions: $instructions, dispense: $dispense, clinical: $clinical}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}\n\nmutation UpdatePrescription($id: ID!, $externalId: String, $treatment: TreatmentReferenceInput, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $signing: PrescriptionSigningDetailsInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, treatment: $treatment, instructions: $instructions, dispense: $dispense, clinical: $clinical, signing: $signing}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}": typeof types.GetPrescriptionDocument,
25
+ };
26
+ const documents: Documents = {
27
+ "fragment TreatmentFields on Treatment {\n id\n name\n rxNormId\n ndc\n upc\n entityKind\n prescribableName\n brandName\n genericName\n form\n route\n strength\n medicationType\n schedule\n}\n\nfragment ChoiceFields on Choice {\n __typename\n displayName\n reason\n operation\n argument\n value\n matchReasons {\n type\n label\n confidence\n value {\n displayValue\n value\n unit\n }\n }\n entity {\n __typename\n ... on Treatment {\n ...TreatmentFields\n templates {\n ...PrescriptionTemplateFields\n }\n }\n ... on Pharmacy {\n ...PharmacyFields\n }\n }\n}\n\nfragment PharmacyOfferFields on PharmacyOffer {\n source\n prescriptionId\n priceType\n isPromoted\n attributeTags {\n kind\n label\n }\n price {\n amount\n retailAmount\n promotions {\n type\n baseAmount\n amountSaved\n }\n }\n deliveryEstimate {\n deliveryPromise\n deliveryPromiseRangeStart\n deliveryPromiseRangeEnd\n }\n redemptionState\n redemptionMethods {\n ...RedemptionMethodFields\n }\n}\n\nfragment RedemptionMethodFields on RedemptionMethod {\n __typename\n ... on PharmacyDiscountCard {\n id\n prescriptionId\n bin\n pcn\n group\n memberId\n externalUrl\n }\n}\n\nfragment ChangeFields on Change {\n key\n label\n status\n severity\n reason\n category\n operation\n options {\n ...ChoiceFields\n }\n before {\n ...ChoiceFields\n }\n after {\n ...ChoiceFields\n }\n}\n\nfragment ChangeSetFields on ChangeSet {\n changes {\n ...ChangeFields\n }\n}\n\nfragment OperationErrorFields on OperationError {\n __typename\n type\n code\n message\n requiredPermission\n service\n retryable\n}\n\nfragment PharmacyFields on Pharmacy {\n id\n name\n logo\n phone\n hours {\n openFrom\n openUntil\n dayOfWeek\n is24Hr\n timezone\n }\n isOpen\n nextEvents {\n open {\n ...PharmacyEventFields\n }\n close {\n ...PharmacyEventFields\n }\n }\n address {\n street1\n street2\n city\n state\n postalCode\n }\n latitude\n longitude\n fulfillmentType\n offers {\n ...PharmacyOfferFields\n }\n}\n\nfragment PharmacyEventFields on PharmacyEvent {\n __typename\n ... on PharmacyOpenEvent {\n type\n datetime\n }\n ... on PharmacyCloseEvent {\n type\n datetime\n }\n ... on PharmacyOpen24HrEvent {\n type\n }\n}\n\nfragment OrganizationFields on Organization {\n id\n name\n customer {\n __typename\n ... on Customer {\n id\n name\n }\n }\n settings {\n brandColor\n brandLogo\n priorAuthorizationExceptionMessage\n patientUx {\n enablePatientRerouting\n enableAutomatedOps\n }\n }\n}\n\nfragment PatientDemographicFields on PatientDemographic {\n name {\n first\n middle\n last\n }\n dateOfBirth\n sex\n gender\n}\n\nfragment PatientContactFields on PatientContact {\n email\n phone\n address {\n street1\n street2\n city\n state\n postalCode\n country\n }\n}\n\nfragment PatientFields on Patient {\n id\n demographic {\n ...PatientDemographicFields\n }\n contact {\n ...PatientContactFields\n }\n benefits {\n status\n entries {\n id\n bin\n pcn\n groupId\n memberId\n }\n }\n preferredPharmacy {\n ...PharmacyFields\n }\n clinical {\n allergies {\n status\n entries {\n id\n name\n rxNormId\n }\n }\n medications {\n status\n entries {\n id\n name\n rxNormId\n status\n }\n }\n diagnoses {\n status\n entries {\n id\n name\n icd10Code\n }\n }\n notes\n }\n}\n\nfragment PatientRecordFields on PatientRecordResult {\n __typename\n ... on Patient {\n ...PatientFields\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment ScreeningAlertFields on ScreeningAlert {\n severity\n type\n description\n category\n involvedEntities {\n id\n name\n }\n options {\n ...ChoiceFields\n }\n}\n\nfragment PrescriptionFields on Prescription {\n id\n prescriber {\n id\n name {\n first\n middle\n last\n }\n }\n fulfillment {\n state\n pharmacyEstimatedReadyAt\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n templateId\n patient {\n id\n }\n treatment {\n ...TreatmentFields\n }\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n clinical {\n diagnoses {\n id\n name\n icd10Code\n }\n notes\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n signing {\n state\n contentHash\n message\n signedAt\n }\n}\n\nfragment OrderFields on Order {\n id\n state\n offers {\n atPharmacy {\n ...PharmacyOfferFields\n }\n }\n organization {\n __typename\n ... on Organization {\n ...OrganizationFields\n }\n }\n patient {\n ...PatientRecordFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n pharmacy {\n ...PharmacyFields\n }\n fulfillment {\n state\n history {\n pharmacy {\n ...PharmacyFields\n }\n selector\n reason\n createdAt\n }\n routability {\n allowed\n reason\n }\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n}\n\nfragment PrescriptionTemplateFields on PrescriptionTemplate {\n id\n source\n name\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n}\n\nfragment PatientResultFields on PatientResult {\n __typename\n ... on PatientPayload {\n patient {\n ...PatientRecordFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment PrescriptionResultFields on PrescriptionResult {\n __typename\n ... on PrescriptionPayload {\n prescription {\n ...PrescriptionFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPrescriptionMatch {\n reason\n candidates {\n id\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment OrderCandidateFields on OrderCandidate {\n id\n pharmacy {\n ...PharmacyFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n}\n\nfragment OrderResultFields on OrderResult {\n __typename\n ... on OrderPayload {\n order {\n ...OrderFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousOrderMatch {\n reason\n candidates {\n ...OrderCandidateFields\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}": types.TreatmentFieldsFragmentDoc,
28
+ "query Ping {\n ping\n}": types.PingDocument,
29
+ "query Me {\n me {\n __typename\n ... on User {\n id\n name {\n first\n last\n }\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ... on Patient {\n id\n name {\n first\n last\n }\n }\n ... on Machine {\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ...OperationErrorFields\n }\n}": types.MeDocument,
30
+ "mutation GetOrder($id: ID!, $metadata: RequestMetadata!) {\n order(order: {id: $id}, metadata: $metadata) {\n ...OrderResultFields\n }\n}\n\nmutation SyncOrder($id: ID, $patient: PatientReferenceInput, $prescriptions: OrderPrescriptionsPatch, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, patient: $patient, prescriptions: $prescriptions, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}\n\nmutation UpdateOrder($id: ID!, $prescriptions: OrderPrescriptionsPatch, $state: OrderState, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, prescriptions: $prescriptions, state: $state, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}": types.GetOrderDocument,
31
+ "query Orders($filter: OrdersFilterInput, $limit: Int, $pharmacy: PharmacyReferenceInput, $page: PageInput, $includePharmacies: Boolean!) {\n orders(filter: $filter, limit: $limit) {\n __typename\n ... on OrdersPayload {\n orders {\n ...OrderFields\n routablePharmacies(pharmacy: $pharmacy, page: $page) @include(if: $includePharmacies) {\n options {\n ...ChoiceFields\n }\n totalCount\n nextOffset\n }\n }\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ...OperationErrorFields\n }\n}": types.OrdersDocument,
32
+ "mutation GetPatient($id: ID!, $metadata: RequestMetadata!) {\n patient(patient: {id: $id}, metadata: $metadata) {\n ...PatientResultFields\n }\n}\n\nmutation SyncPatient($id: ID, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}\n\nmutation UpdatePatient($id: ID!, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}": types.GetPatientDocument,
33
+ "mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n ...PrescriptionResultFields\n }\n}\n\nmutation GetPrescriptionTemplates($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n __typename\n ... on PrescriptionPayload {\n prescription {\n treatment {\n templates {\n ...PrescriptionTemplateFields\n }\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n }\n}\n\nmutation SyncPrescription($id: ID, $externalId: String, $patient: PatientReferenceInput, $treatment: TreatmentReferenceInput, $templateId: ID, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, patient: $patient, treatment: $treatment, templateId: $templateId, instructions: $instructions, dispense: $dispense, clinical: $clinical}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}\n\nmutation UpdatePrescription($id: ID!, $externalId: String, $treatment: TreatmentReferenceInput, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $signing: PrescriptionSigningDetailsInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, treatment: $treatment, instructions: $instructions, dispense: $dispense, clinical: $clinical, signing: $signing}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}": types.GetPrescriptionDocument,
34
+ };
35
+
36
+ /**
37
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
38
+ */
39
+ export function graphql(source: "fragment TreatmentFields on Treatment {\n id\n name\n rxNormId\n ndc\n upc\n entityKind\n prescribableName\n brandName\n genericName\n form\n route\n strength\n medicationType\n schedule\n}\n\nfragment ChoiceFields on Choice {\n __typename\n displayName\n reason\n operation\n argument\n value\n matchReasons {\n type\n label\n confidence\n value {\n displayValue\n value\n unit\n }\n }\n entity {\n __typename\n ... on Treatment {\n ...TreatmentFields\n templates {\n ...PrescriptionTemplateFields\n }\n }\n ... on Pharmacy {\n ...PharmacyFields\n }\n }\n}\n\nfragment PharmacyOfferFields on PharmacyOffer {\n source\n prescriptionId\n priceType\n isPromoted\n attributeTags {\n kind\n label\n }\n price {\n amount\n retailAmount\n promotions {\n type\n baseAmount\n amountSaved\n }\n }\n deliveryEstimate {\n deliveryPromise\n deliveryPromiseRangeStart\n deliveryPromiseRangeEnd\n }\n redemptionState\n redemptionMethods {\n ...RedemptionMethodFields\n }\n}\n\nfragment RedemptionMethodFields on RedemptionMethod {\n __typename\n ... on PharmacyDiscountCard {\n id\n prescriptionId\n bin\n pcn\n group\n memberId\n externalUrl\n }\n}\n\nfragment ChangeFields on Change {\n key\n label\n status\n severity\n reason\n category\n operation\n options {\n ...ChoiceFields\n }\n before {\n ...ChoiceFields\n }\n after {\n ...ChoiceFields\n }\n}\n\nfragment ChangeSetFields on ChangeSet {\n changes {\n ...ChangeFields\n }\n}\n\nfragment OperationErrorFields on OperationError {\n __typename\n type\n code\n message\n requiredPermission\n service\n retryable\n}\n\nfragment PharmacyFields on Pharmacy {\n id\n name\n logo\n phone\n hours {\n openFrom\n openUntil\n dayOfWeek\n is24Hr\n timezone\n }\n isOpen\n nextEvents {\n open {\n ...PharmacyEventFields\n }\n close {\n ...PharmacyEventFields\n }\n }\n address {\n street1\n street2\n city\n state\n postalCode\n }\n latitude\n longitude\n fulfillmentType\n offers {\n ...PharmacyOfferFields\n }\n}\n\nfragment PharmacyEventFields on PharmacyEvent {\n __typename\n ... on PharmacyOpenEvent {\n type\n datetime\n }\n ... on PharmacyCloseEvent {\n type\n datetime\n }\n ... on PharmacyOpen24HrEvent {\n type\n }\n}\n\nfragment OrganizationFields on Organization {\n id\n name\n customer {\n __typename\n ... on Customer {\n id\n name\n }\n }\n settings {\n brandColor\n brandLogo\n priorAuthorizationExceptionMessage\n patientUx {\n enablePatientRerouting\n enableAutomatedOps\n }\n }\n}\n\nfragment PatientDemographicFields on PatientDemographic {\n name {\n first\n middle\n last\n }\n dateOfBirth\n sex\n gender\n}\n\nfragment PatientContactFields on PatientContact {\n email\n phone\n address {\n street1\n street2\n city\n state\n postalCode\n country\n }\n}\n\nfragment PatientFields on Patient {\n id\n demographic {\n ...PatientDemographicFields\n }\n contact {\n ...PatientContactFields\n }\n benefits {\n status\n entries {\n id\n bin\n pcn\n groupId\n memberId\n }\n }\n preferredPharmacy {\n ...PharmacyFields\n }\n clinical {\n allergies {\n status\n entries {\n id\n name\n rxNormId\n }\n }\n medications {\n status\n entries {\n id\n name\n rxNormId\n status\n }\n }\n diagnoses {\n status\n entries {\n id\n name\n icd10Code\n }\n }\n notes\n }\n}\n\nfragment PatientRecordFields on PatientRecordResult {\n __typename\n ... on Patient {\n ...PatientFields\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment ScreeningAlertFields on ScreeningAlert {\n severity\n type\n description\n category\n involvedEntities {\n id\n name\n }\n options {\n ...ChoiceFields\n }\n}\n\nfragment PrescriptionFields on Prescription {\n id\n prescriber {\n id\n name {\n first\n middle\n last\n }\n }\n fulfillment {\n state\n pharmacyEstimatedReadyAt\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n templateId\n patient {\n id\n }\n treatment {\n ...TreatmentFields\n }\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n clinical {\n diagnoses {\n id\n name\n icd10Code\n }\n notes\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n signing {\n state\n contentHash\n message\n signedAt\n }\n}\n\nfragment OrderFields on Order {\n id\n state\n offers {\n atPharmacy {\n ...PharmacyOfferFields\n }\n }\n organization {\n __typename\n ... on Organization {\n ...OrganizationFields\n }\n }\n patient {\n ...PatientRecordFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n screeningAlerts {\n ...ScreeningAlertFields\n }\n pharmacy {\n ...PharmacyFields\n }\n fulfillment {\n state\n history {\n pharmacy {\n ...PharmacyFields\n }\n selector\n reason\n createdAt\n }\n routability {\n allowed\n reason\n }\n exceptions {\n id\n type\n message\n createdAt\n }\n }\n}\n\nfragment PrescriptionTemplateFields on PrescriptionTemplate {\n id\n source\n name\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n}\n\nfragment PatientResultFields on PatientResult {\n __typename\n ... on PatientPayload {\n patient {\n ...PatientRecordFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment PrescriptionResultFields on PrescriptionResult {\n __typename\n ... on PrescriptionPayload {\n prescription {\n ...PrescriptionFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousPrescriptionMatch {\n reason\n candidates {\n id\n instructions\n dispense {\n quantity\n unit\n daysSupply\n refillsAllowed\n dispenseAsWritten\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}\n\nfragment OrderCandidateFields on OrderCandidate {\n id\n pharmacy {\n ...PharmacyFields\n }\n prescriptions {\n ...PrescriptionFields\n }\n}\n\nfragment OrderResultFields on OrderResult {\n __typename\n ... on OrderPayload {\n order {\n ...OrderFields\n }\n ...ChangeSetFields\n }\n ... on AmbiguousOrderMatch {\n reason\n candidates {\n ...OrderCandidateFields\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n}"): typeof import('./graphql.js').TreatmentFieldsFragmentDoc;
40
+ /**
41
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
42
+ */
43
+ export function graphql(source: "query Ping {\n ping\n}"): typeof import('./graphql.js').PingDocument;
44
+ /**
45
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
46
+ */
47
+ export function graphql(source: "query Me {\n me {\n __typename\n ... on User {\n id\n name {\n first\n last\n }\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ... on Patient {\n id\n name {\n first\n last\n }\n }\n ... on Machine {\n organization {\n __typename\n ... on Organization {\n id\n name\n }\n }\n permissions\n }\n ...OperationErrorFields\n }\n}"): typeof import('./graphql.js').MeDocument;
48
+ /**
49
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
50
+ */
51
+ export function graphql(source: "mutation GetOrder($id: ID!, $metadata: RequestMetadata!) {\n order(order: {id: $id}, metadata: $metadata) {\n ...OrderResultFields\n }\n}\n\nmutation SyncOrder($id: ID, $patient: PatientReferenceInput, $prescriptions: OrderPrescriptionsPatch, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, patient: $patient, prescriptions: $prescriptions, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}\n\nmutation UpdateOrder($id: ID!, $prescriptions: OrderPrescriptionsPatch, $state: OrderState, $pharmacy: OrderPharmacyInput, $metadata: RequestMetadata!) {\n order(\n order: {id: $id, prescriptions: $prescriptions, state: $state, pharmacy: $pharmacy}\n metadata: $metadata\n ) {\n ...OrderResultFields\n }\n}"): typeof import('./graphql.js').GetOrderDocument;
52
+ /**
53
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
54
+ */
55
+ export function graphql(source: "query Orders($filter: OrdersFilterInput, $limit: Int, $pharmacy: PharmacyReferenceInput, $page: PageInput, $includePharmacies: Boolean!) {\n orders(filter: $filter, limit: $limit) {\n __typename\n ... on OrdersPayload {\n orders {\n ...OrderFields\n routablePharmacies(pharmacy: $pharmacy, page: $page) @include(if: $includePharmacies) {\n options {\n ...ChoiceFields\n }\n totalCount\n nextOffset\n }\n }\n }\n ... on AmbiguousPatientMatch {\n reason\n candidates {\n id\n firstName\n lastName\n dateOfBirth\n }\n }\n ...OperationErrorFields\n }\n}"): typeof import('./graphql.js').OrdersDocument;
56
+ /**
57
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
58
+ */
59
+ export function graphql(source: "mutation GetPatient($id: ID!, $metadata: RequestMetadata!) {\n patient(patient: {id: $id}, metadata: $metadata) {\n ...PatientResultFields\n }\n}\n\nmutation SyncPatient($id: ID, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}\n\nmutation UpdatePatient($id: ID!, $demographic: PatientDemographicInput, $contact: PatientContactInput, $clinical: PatientClinicalInput, $benefits: BenefitsPatch, $preferredPharmacy: PharmacyReferenceInput, $metadata: RequestMetadata!) {\n patient(\n patient: {id: $id, demographic: $demographic, contact: $contact, clinical: $clinical, benefits: $benefits, preferredPharmacy: $preferredPharmacy}\n metadata: $metadata\n ) {\n ...PatientResultFields\n }\n}"): typeof import('./graphql.js').GetPatientDocument;
60
+ /**
61
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
62
+ */
63
+ export function graphql(source: "mutation GetPrescription($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n ...PrescriptionResultFields\n }\n}\n\nmutation GetPrescriptionTemplates($id: ID!, $metadata: RequestMetadata!) {\n prescription(prescription: {id: $id}, metadata: $metadata) {\n __typename\n ... on PrescriptionPayload {\n prescription {\n treatment {\n templates {\n ...PrescriptionTemplateFields\n }\n }\n }\n }\n ... on OperationError {\n ...OperationErrorFields\n }\n }\n}\n\nmutation SyncPrescription($id: ID, $externalId: String, $patient: PatientReferenceInput, $treatment: TreatmentReferenceInput, $templateId: ID, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, patient: $patient, treatment: $treatment, templateId: $templateId, instructions: $instructions, dispense: $dispense, clinical: $clinical}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}\n\nmutation UpdatePrescription($id: ID!, $externalId: String, $treatment: TreatmentReferenceInput, $instructions: String, $dispense: DispenseInput, $clinical: PrescriptionClinicalInput, $signing: PrescriptionSigningDetailsInput, $metadata: RequestMetadata!) {\n prescription(\n prescription: {id: $id, externalId: $externalId, treatment: $treatment, instructions: $instructions, dispense: $dispense, clinical: $clinical, signing: $signing}\n metadata: $metadata\n ) {\n ...PrescriptionResultFields\n }\n}"): typeof import('./graphql.js').GetPrescriptionDocument;
64
+
65
+
66
+ export function graphql(source: string) {
67
+ return (documents as any)[source] ?? {};
68
+ }