@crvouga/mockingbird-service-junction 0.1.1 → 0.1.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 (62) hide show
  1. package/README.md +23 -11
  2. package/dist/index.d.ts +492 -21
  3. package/dist/index.js +6086 -107
  4. package/dist/index.js.map +7 -1
  5. package/package.json +11 -10
  6. package/dist/catalog.d.ts +0 -63
  7. package/dist/catalog.d.ts.map +0 -1
  8. package/dist/catalog.js +0 -736
  9. package/dist/catalog.js.map +0 -1
  10. package/dist/coverage-corpus.d.ts +0 -76
  11. package/dist/coverage-corpus.d.ts.map +0 -1
  12. package/dist/coverage-corpus.js +0 -166
  13. package/dist/coverage-corpus.js.map +0 -1
  14. package/dist/generated/openapi.d.ts +0 -7
  15. package/dist/generated/openapi.d.ts.map +0 -1
  16. package/dist/generated/openapi.js +0 -5
  17. package/dist/generated/openapi.js.map +0 -1
  18. package/dist/index.d.ts.map +0 -1
  19. package/dist/lab-accounts.d.ts +0 -38
  20. package/dist/lab-accounts.d.ts.map +0 -1
  21. package/dist/lab-accounts.js +0 -213
  22. package/dist/lab-accounts.js.map +0 -1
  23. package/dist/orders.d.ts +0 -18
  24. package/dist/orders.d.ts.map +0 -1
  25. package/dist/orders.js +0 -1247
  26. package/dist/orders.js.map +0 -1
  27. package/dist/prefetch.d.ts +0 -43
  28. package/dist/prefetch.d.ts.map +0 -1
  29. package/dist/prefetch.js +0 -131
  30. package/dist/prefetch.js.map +0 -1
  31. package/dist/reshape.d.ts +0 -22
  32. package/dist/reshape.d.ts.map +0 -1
  33. package/dist/reshape.js +0 -190
  34. package/dist/reshape.js.map +0 -1
  35. package/dist/results.d.ts +0 -19
  36. package/dist/results.d.ts.map +0 -1
  37. package/dist/results.js +0 -221
  38. package/dist/results.js.map +0 -1
  39. package/dist/scheduling.d.ts +0 -113
  40. package/dist/scheduling.d.ts.map +0 -1
  41. package/dist/scheduling.js +0 -1508
  42. package/dist/scheduling.js.map +0 -1
  43. package/dist/sealed-corpus.d.ts +0 -28
  44. package/dist/sealed-corpus.d.ts.map +0 -1
  45. package/dist/sealed-corpus.js +0 -17
  46. package/dist/sealed-corpus.js.map +0 -1
  47. package/dist/seed-from.d.ts +0 -27
  48. package/dist/seed-from.d.ts.map +0 -1
  49. package/dist/seed-from.js +0 -523
  50. package/dist/seed-from.js.map +0 -1
  51. package/dist/seeds.d.ts +0 -9
  52. package/dist/seeds.d.ts.map +0 -1
  53. package/dist/seeds.js +0 -9
  54. package/dist/seeds.js.map +0 -1
  55. package/dist/state.d.ts +0 -270
  56. package/dist/state.d.ts.map +0 -1
  57. package/dist/state.js +0 -448
  58. package/dist/state.js.map +0 -1
  59. package/dist/users.d.ts +0 -13
  60. package/dist/users.d.ts.map +0 -1
  61. package/dist/users.js +0 -669
  62. package/dist/users.js.map +0 -1
package/dist/results.js DELETED
@@ -1,221 +0,0 @@
1
- /** Lab-results surface: raw results, metadata, and deterministic PDF artifacts. */
2
- import { HttpError, jsonRes, opaqueToken, } from "@crvouga/mockingbird-service";
3
- import { applySimulateTransition, requireOrder } from "./scheduling.js";
4
- const RESULT_TYPES = ["numeric", "range", "comment", "coded_value"];
5
- const INTERPRETATIONS = ["normal", "abnormal", "critical", "unknown"];
6
- /** Statuses from which results exist (sample has been drawn and reported). */
7
- const RESULT_READY_STATUSES = ["sample_with_lab", "completed"];
8
- const resultsReady = (order) => RESULT_READY_STATUSES.some((prefix) => order.status.startsWith(prefix)) ||
9
- order.last_event.status.endsWith("draw_completed");
10
- const parseInterpretation = (value) => INTERPRETATIONS.includes(value) ? value : "normal";
11
- const pickResultType = (value, index) => {
12
- if (Array.isArray(value) && value.length > 0) {
13
- const entry = value[index % value.length];
14
- if (typeof entry === "string" && RESULT_TYPES.includes(entry))
15
- return entry;
16
- }
17
- return "numeric";
18
- };
19
- const numericValueFor = (slug) => {
20
- let hash = 0;
21
- for (let i = 0; i < slug.length; i++)
22
- hash = (hash * 31 + slug.charCodeAt(i)) % 1000;
23
- return Math.round((40 + (hash % 160)) * 10) / 10;
24
- };
25
- const biomarkerLines = (order, flags) => {
26
- const collected = order.last_event.created_at;
27
- return (order.lab_test.markers ?? []).map((marker, index) => {
28
- const type = pickResultType(flags.resultTypes, index);
29
- const base = {
30
- name: marker.name,
31
- slug: marker.slug,
32
- result: marker.slug,
33
- type,
34
- value: null,
35
- unit: marker.unit,
36
- timestamp: collected,
37
- reference_range: null,
38
- interpretation: flags.interpretation,
39
- performing_laboratory: "Mockingbird Central Lab",
40
- source_sample_id: order.sample_id,
41
- notes: null,
42
- string_value: null,
43
- coded_value: null,
44
- low_value: null,
45
- high_value: null,
46
- provider_id: marker.provider_id,
47
- };
48
- if (type === "numeric") {
49
- base.value = numericValueFor(marker.slug);
50
- base.result = String(base.value);
51
- base.reference_range = "0-200";
52
- base.low_value = 0;
53
- base.high_value = 200;
54
- }
55
- else if (type === "range") {
56
- base.low_value = 0;
57
- base.high_value = 200;
58
- base.value = numericValueFor(marker.slug);
59
- base.reference_range = "0-200";
60
- base.result = `${base.low_value}-${base.high_value}`;
61
- }
62
- else if (type === "comment") {
63
- base.string_value = "No abnormal findings reported.";
64
- base.result = base.string_value;
65
- }
66
- else {
67
- base.coded_value = flags.interpretation === "normal" ? "N" : "A";
68
- base.result = base.coded_value;
69
- }
70
- return base;
71
- });
72
- };
73
- const flagsOf = (order) => {
74
- const raw = order.result_types;
75
- const resultTypes = Array.isArray(raw) && raw.length > 0
76
- ? raw.filter((entry) => typeof entry === "string")
77
- : null;
78
- return {
79
- interpretation: parseInterpretation(order.interpretation),
80
- resultTypes,
81
- hasMissingResults: order.has_missing_results === true,
82
- };
83
- };
84
- const ageFromDob = (dob, nowIso) => {
85
- const born = Date.parse(`${dob}T00:00:00.000Z`);
86
- const now = Date.parse(nowIso);
87
- if (!Number.isFinite(born) || !Number.isFinite(now) || now < born)
88
- return "0";
89
- const years = Math.floor((now - born) / (365.25 * 24 * 60 * 60 * 1000));
90
- return String(Math.max(0, years));
91
- };
92
- const metadataOf = (order, _userClient) => {
93
- const details = order.patient_details ?? {};
94
- const first = typeof details.first_name === "string" && details.first_name.length > 0
95
- ? details.first_name
96
- : "Patient";
97
- const last = typeof details.last_name === "string" && details.last_name.length > 0 ? details.last_name : "";
98
- const dob = typeof details.dob === "string" && details.dob.length > 0 ? details.dob : "1990-01-01";
99
- const labName = order.lab_test.lab && typeof order.lab_test.lab.name === "string"
100
- ? order.lab_test.lab.name
101
- : "Labcorp";
102
- const reportedAt = order.last_event.created_at;
103
- return {
104
- age: ageFromDob(dob, reportedAt),
105
- dob,
106
- patient: `${first} ${last}`.trim(),
107
- date_reported: reportedAt,
108
- specimen_number: opaqueToken(`junction:specimen:${order.id}`, 24),
109
- status: "final",
110
- laboratory: labName,
111
- provider: order.physician
112
- ? `${order.physician.first_name} ${order.physician.last_name}`.trim()
113
- : null,
114
- interpretation: order.interpretation,
115
- patient_id: order.user_id,
116
- account_id: null,
117
- date_collected: reportedAt,
118
- date_received: reportedAt,
119
- "clia_#": null,
120
- };
121
- };
122
- /** Minimal single-page PDF with a deterministic title; valid enough for byte-shape checks. */
123
- const deterministicPdf = (title) => {
124
- const text = `BT /F1 14 Tf 72 720 Td (${title}) Tj ET`;
125
- const objects = [
126
- "<< /Type /Catalog /Pages 2 0 R >>",
127
- "<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
128
- "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>",
129
- `<< /Length ${text.length} >>\nstream\n${text}\nendstream`,
130
- "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>",
131
- ];
132
- let body = "%PDF-1.4\n";
133
- const offsets = [];
134
- objects.forEach((entry, index) => {
135
- offsets.push(body.length);
136
- body += `${index + 1} 0 obj\n${entry}\nendobj\n`;
137
- });
138
- const xrefStart = body.length;
139
- body += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`;
140
- for (const offset of offsets)
141
- body += `${String(offset).padStart(10, "0")} 00000 n \n`;
142
- body += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xrefStart}\n%%EOF\n`;
143
- return new TextEncoder().encode(body);
144
- };
145
- function resultsNotAvailable(orderId) {
146
- throw new HttpError(404, {
147
- detail: `Results are not available for order - ${orderId}. Did you receive a webhook for this order?`,
148
- });
149
- }
150
- export const resultsHandlers = (state) => ({
151
- get_result_raw_v3_order__order_id__result_get: async (context) => {
152
- const orderId = context.params.order_id ?? "";
153
- const order = requireOrder(state, orderId, context, "Order not found");
154
- const user = state.users.get(order.user_id);
155
- if (!resultsReady(order))
156
- resultsNotAvailable(order.id);
157
- const flags = flagsOf(order);
158
- const results = biomarkerLines(order, flags);
159
- const missing = flags.hasMissingResults
160
- ? [
161
- {
162
- name: (order.lab_test.markers ?? [])[0]?.name ?? "Unknown marker",
163
- slug: (order.lab_test.markers ?? [])[0]?.slug ?? "unknown-marker",
164
- inferred_failure_type: "quantity_not_sufficient_failure",
165
- note: "Specimen quantity was not sufficient to run this marker.",
166
- loinc: null,
167
- loinc_slug: null,
168
- provider_id: (order.lab_test.markers ?? [])[0]?.provider_id ?? null,
169
- source_markers: null,
170
- },
171
- ]
172
- : null;
173
- return jsonRes(200, {
174
- metadata: metadataOf(order, user?.client_user_id ?? order.user_id),
175
- results,
176
- missing_results: missing,
177
- sample_information: {
178
- [order.sample_id ?? opaqueToken(`junction:sample:${order.id}`, 16)]: {
179
- sample_id: order.sample_id ?? opaqueToken(`junction:sample:${order.id}`, 16),
180
- control_number: order.sample_id,
181
- date_collected: order.last_event.created_at,
182
- date_received: order.last_event.created_at,
183
- date_reported: order.last_event.created_at,
184
- performing_laboratories: null,
185
- clinical_information: null,
186
- },
187
- },
188
- order_transaction: order.order_transaction,
189
- });
190
- },
191
- get_result_metadata_v3_order__order_id__result_metadata_get: async (context) => {
192
- const orderId = context.params.order_id ?? "";
193
- const order = requireOrder(state, orderId, context, "Order not found");
194
- if (!resultsReady(order))
195
- resultsNotAvailable(order.id);
196
- const user = state.users.get(order.user_id);
197
- return jsonRes(200, metadataOf(order, user?.client_user_id ?? order.user_id));
198
- },
199
- get_result_pdf_v3_order__order_id__result_pdf_get: async (context) => {
200
- const orderId = context.params.order_id ?? "";
201
- const order = requireOrder(state, orderId, context, "Order not found");
202
- if (!resultsReady(order))
203
- resultsNotAvailable(order.id);
204
- const bytes = deterministicPdf(`Lab results ${order.id}`);
205
- return new Response(bytes, {
206
- status: 200,
207
- headers: { "content-type": "application/pdf" },
208
- });
209
- },
210
- get_order_requisition_pdf_v3_order__order_id__requisition_pdf_get: async (context) => {
211
- const orderId = context.params.order_id ?? "";
212
- const order = requireOrder(state, orderId, context, "This order doesn't exist");
213
- const bytes = deterministicPdf(`Requisition ${order.id}`);
214
- return new Response(bytes, {
215
- status: 200,
216
- headers: { "content-type": "application/pdf" },
217
- });
218
- },
219
- });
220
- export { applySimulateTransition };
221
- //# sourceMappingURL=results.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EACL,SAAS,EACT,OAAO,EAEP,WAAW,GACZ,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGvE,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAU,CAAA;AAG5E,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,CAAU,CAAA;AAG9E,8EAA8E;AAC9E,MAAM,qBAAqB,GAAG,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAA;AAE9D,MAAM,YAAY,GAAG,CAAC,KAAkB,EAAW,EAAE,CACnD,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC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AK,EACtE,OAAyB,EACzB,EAAE;QACF,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAA;QAC7C,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,0BAA0B,CAAC,CAAA;QAC/E,MAAM,KAAK,GAAG,gBAAgB,CAAC,eAAe,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;QACzD,OAAO,IAAI,QAAQ,CAAC,KAA4B,EAAE;YAChD,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,cAAc,EAAE,iBAAiB,EAAE;SAC/C,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
@@ -1,113 +0,0 @@
1
- /**
2
- * Appointment scheduling surface: phlebotomy + PSC availability/booking lifecycle,
3
- * cancellation reasons, area serviceability, and PSC site info.
4
- *
5
- * Slot data is generated deterministically (seeded by zip/site/date), so walks are
6
- * reproducible without any provider-side state.
7
- */
8
- import { type OperationContext } from "@crvouga/mockingbird-service";
9
- import type { AppointmentRecord, JunctionState } from "./state.js";
10
- export declare const addressFromAvailabilityRequest: (requestBody: Record<string, unknown>, zip: string) => Record<string, unknown>;
11
- export declare const CANCELLATION_REASONS: readonly [{
12
- readonly id: "5c0257ef-6fea-4a22-b20a-3ddab573d5c9";
13
- readonly name: "Did not fast for appointment";
14
- readonly is_refundable: true;
15
- }, {
16
- readonly id: "448c519c-64b4-4497-ae73-622fa93371b3";
17
- readonly name: "Do not trust company";
18
- readonly is_refundable: true;
19
- }, {
20
- readonly id: "d378e152-12d1-433e-9dd1-e0410f9331dc";
21
- readonly name: "Getlabs cannot deliver to my preferred lab";
22
- readonly is_refundable: true;
23
- }, {
24
- readonly id: "7be75f90-303d-4656-8eed-9bd3e20cb2cc";
25
- readonly name: "Getlabs - late";
26
- readonly is_refundable: true;
27
- }, {
28
- readonly id: "ae3ec4dc-387c-42ac-835a-bf88fc4e411b";
29
- readonly name: "Getlabs -Phleb Out Sick";
30
- readonly is_refundable: true;
31
- }, {
32
- readonly id: "e2396e00-dd49-4f38-a395-51d6304c3312";
33
- readonly name: "Getlabs rescheduled time does not work for patient";
34
- readonly is_refundable: true;
35
- }, {
36
- readonly id: "5330c863-ac80-4316-901b-d305d0df74d5";
37
- readonly name: "No longer interested";
38
- readonly is_refundable: true;
39
- }, {
40
- readonly id: "2b9f23fd-163e-4483-bb10-90c74a67e0dc";
41
- readonly name: "Other";
42
- readonly is_refundable: true;
43
- }, {
44
- readonly id: "98f861dd-fe61-4817-a9d6-1b99b19cd0fb";
45
- readonly name: "Provider asked me to cancel";
46
- readonly is_refundable: true;
47
- }, {
48
- readonly id: "7dfd7da5-ed6e-40bb-a7e4-c8003f0c10a9";
49
- readonly name: "Scheduled for wrong patient";
50
- readonly is_refundable: true;
51
- }, {
52
- readonly id: "796da8c8-e654-4347-8ded-1026410c1976";
53
- readonly name: "Scheduled time no longer works";
54
- readonly is_refundable: true;
55
- }, {
56
- readonly id: "ba02af35-a34f-4a7a-abe5-5f766e8f6cd1";
57
- readonly name: "Unable to get lab order from provider";
58
- readonly is_refundable: true;
59
- }, {
60
- readonly id: "0c9425db-f11e-49c5-b976-3c0d1d4a4ea8";
61
- readonly name: "Wanted to book in-person appointment";
62
- readonly is_refundable: true;
63
- }, {
64
- readonly id: "2599a0ea-0b4a-42fe-8df6-d8f7c68182e7";
65
- readonly name: "Went to lab for appointment";
66
- readonly is_refundable: true;
67
- }];
68
- /** PSC offers a single cancellation reason in the sandbox. */
69
- export declare const PSC_CANCELLATION_REASONS: readonly [{
70
- readonly id: "226a6520-667c-495f-8500-c20722d231d0";
71
- readonly name: "Other";
72
- readonly is_refundable: true;
73
- }];
74
- /** The phlebotomy reason named "Other" requires explanatory notes. */
75
- export declare const OTHER_CANCELLATION_REASON_ID = "2b9f23fd-163e-4483-bb10-90c74a67e0dc";
76
- /** Lab 3 (USSL) exists in the catalog but is excluded from PSC info in the sandbox. */
77
- export declare const UNSUPPORTED_PSC_LAB_ID = 3;
78
- declare const appointmentOfOrder: (state: JunctionState, orderId: string) => AppointmentRecord | undefined;
79
- declare const renderAppointment: (appointment: AppointmentRecord) => Record<string, unknown>;
80
- type Order = NonNullable<ReturnType<JunctionState["orders"]["get"]>>;
81
- declare const requireOrder: (state: JunctionState, orderId: string, context: OperationContext, missingMessage?: string) => Order;
82
- /**
83
- * Mirror api.sandbox.tryvital.io `/v3/order/{id}/test` semantics (probed 2026-09):
84
- * - First call on a fresh order always creates `received.{method}.requisition_created`.
85
- * - `at_home_phlebotomy` (and other non-walk-in methods): further `/test` calls are no-ops.
86
- * - `walk_in_test` after requisition:
87
- * - matching `appointment_*` / `requisition_created` → no-op
88
- * - matching `partial_results` → append partial only (default interpretation normal)
89
- * - matching `ordered` / `completed` / `cancelled`, or any mismatched-method status →
90
- * jump through partial then completed (+ result date fields)
91
- * - `failed.*` → append the failed status
92
- */
93
- declare const applySimulateTransition: (state: JunctionState, order: Order, finalStatus: string, flags: Record<string, unknown> | null, context: OperationContext) => void;
94
- export declare const schedulingHandlers: (state: JunctionState) => {
95
- get_phlebotomy_appointment_cancellation_reason_v3_order_phlebotomy_appointment_cancellation_reasons_get: () => Promise<Response>;
96
- get_psc_appointment_cancellation_reason_v3_order_psc_appointment_cancellation_reasons_get: () => Promise<Response>;
97
- get_area_info_v3_order_area_info_get: (context: OperationContext) => Promise<Response>;
98
- get_psc_info_v3_order_psc_info_get: (context: OperationContext) => Promise<Response>;
99
- get_phlebotomy_appointment_availability_v3_order_phlebotomy_appointment_availability_post: (context: OperationContext) => Promise<Response>;
100
- get_psc_appointment_availability_v3_order_psc_appointment_availability_post: (context: OperationContext) => Promise<Response>;
101
- get_phlebotomy_appointment_v3_order__order_id__phlebotomy_appointment_get: (context: OperationContext) => Promise<Response>;
102
- get_psc_appointment_v3_order__order_id__psc_appointment_get: (context: OperationContext) => Promise<Response>;
103
- book_phlebotomy_appointment_v3_order__order_id__phlebotomy_appointment_book_post: (context: OperationContext) => Promise<Response>;
104
- book_psc_appointment_v3_order__order_id__psc_appointment_book_post: (context: OperationContext) => Promise<Response>;
105
- reschedule_phlebotomy_appointment_v3_order__order_id__phlebotomy_appointment_reschedule_patch: (context: OperationContext) => Promise<Response>;
106
- reschedule_psc_appointment_v3_order__order_id__psc_appointment_reschedule_patch: (context: OperationContext) => Promise<Response>;
107
- cancel_phlebotomy_appointment_v3_order__order_id__phlebotomy_appointment_cancel_patch: (context: OperationContext) => Promise<Response>;
108
- cancel_psc_appointment_v3_order__order_id__psc_appointment_cancel_patch: (context: OperationContext) => Promise<Response>;
109
- };
110
- /** Cancels any active appointment linked to `orderId`; used by order cancellation cascade. */
111
- export declare const cascadeCancelAppointments: (state: JunctionState, orderId: string, nowMs: number) => void;
112
- export { applySimulateTransition, appointmentOfOrder, renderAppointment, requireOrder };
113
- //# sourceMappingURL=scheduling.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduling.d.ts","sourceRoot":"","sources":["../src/scheduling.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,8BAA8B,CAAA;AAErC,OAAO,KAAK,EAGV,iBAAiB,EAEjB,aAAa,EACd,MAAM,YAAY,CAAA;AAyOnB,eAAO,MAAM,8BAA8B,GACzC,aAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,KAAK,MAAM,KACV,MAAM,CAAC,MAAM,EAAE,OAAO,CA4BxB,CAAA;AAwCD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDvB,CAAA;AAEV,8DAA8D;AAC9D,eAAO,MAAM,wBAAwB;;;;EAE3B,CAAA;AAEV,sEAAsE;AACtE,eAAO,MAAM,4BAA4B,yCAAyC,CAAA;AA6BlF,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,IAA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