@metriport/shared 0.29.0 → 0.30.0-alpha.0

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 (207) hide show
  1. package/dist/common/sql.d.ts +17 -0
  2. package/dist/common/sql.d.ts.map +1 -0
  3. package/dist/common/sql.js +3 -0
  4. package/dist/common/sql.js.map +1 -0
  5. package/dist/domain/cohort.d.ts +4 -4
  6. package/dist/domain/cohort.d.ts.map +1 -1
  7. package/dist/domain/cohort.js +7 -3
  8. package/dist/domain/cohort.js.map +1 -1
  9. package/dist/domain/contact/__tests__/phone.test.js +4 -0
  10. package/dist/domain/contact/__tests__/phone.test.js.map +1 -1
  11. package/dist/domain/cql-engine/transform.d.ts +2 -2
  12. package/dist/domain/db.d.ts +8 -0
  13. package/dist/domain/db.d.ts.map +1 -1
  14. package/dist/domain/db.js +1 -0
  15. package/dist/domain/db.js.map +1 -1
  16. package/dist/domain/network-query/__tests__/source.test.d.ts +2 -0
  17. package/dist/domain/network-query/__tests__/source.test.d.ts.map +1 -0
  18. package/dist/domain/network-query/__tests__/source.test.js +450 -0
  19. package/dist/domain/network-query/__tests__/source.test.js.map +1 -0
  20. package/dist/domain/network-query/index.d.ts +3 -0
  21. package/dist/domain/network-query/index.d.ts.map +1 -0
  22. package/dist/domain/network-query/index.js +19 -0
  23. package/dist/domain/network-query/index.js.map +1 -0
  24. package/dist/domain/network-query/query.d.ts +18 -3
  25. package/dist/domain/network-query/query.d.ts.map +1 -1
  26. package/dist/domain/network-query/source.d.ts +309 -19
  27. package/dist/domain/network-query/source.d.ts.map +1 -1
  28. package/dist/domain/network-query/source.js +257 -4
  29. package/dist/domain/network-query/source.js.map +1 -1
  30. package/dist/domain/organization.d.ts +3 -3
  31. package/dist/domain/organization.js +1 -1
  32. package/dist/domain/organization.js.map +1 -1
  33. package/dist/domain/patient/patient-monitoring/discharge-requery.d.ts +132 -0
  34. package/dist/domain/patient/patient-monitoring/discharge-requery.d.ts.map +1 -1
  35. package/dist/domain/patient/patient-monitoring/discharge-requery.js +10 -1
  36. package/dist/domain/patient/patient-monitoring/discharge-requery.js.map +1 -1
  37. package/dist/domain/patient/patient-monitoring/utils.d.ts +31 -0
  38. package/dist/domain/patient/patient-monitoring/utils.d.ts.map +1 -1
  39. package/dist/domain/patient/patient-monitoring/utils.js +68 -7
  40. package/dist/domain/patient/patient-monitoring/utils.js.map +1 -1
  41. package/dist/domain/roster/patient-roster.d.ts +5 -1
  42. package/dist/domain/roster/patient-roster.d.ts.map +1 -1
  43. package/dist/domain/tcm-encounter.d.ts +5 -2
  44. package/dist/domain/tcm-encounter.d.ts.map +1 -1
  45. package/dist/domain/tcm-encounter.js +1 -0
  46. package/dist/domain/tcm-encounter.js.map +1 -1
  47. package/dist/error/shared.js +1 -1
  48. package/dist/error/shared.js.map +1 -1
  49. package/dist/external/ehr/practicefusion/allergy-data-map.d.ts +34 -0
  50. package/dist/external/ehr/practicefusion/allergy-data-map.d.ts.map +1 -0
  51. package/dist/external/ehr/practicefusion/allergy-data-map.js +2612 -0
  52. package/dist/external/ehr/practicefusion/allergy-data-map.js.map +1 -0
  53. package/dist/external/ehr/practicefusion/index.d.ts +3 -0
  54. package/dist/external/ehr/practicefusion/index.d.ts.map +1 -0
  55. package/dist/external/ehr/practicefusion/index.js +19 -0
  56. package/dist/external/ehr/practicefusion/index.js.map +1 -0
  57. package/dist/external/ehr/practicefusion/shared.d.ts +18 -0
  58. package/dist/external/ehr/practicefusion/shared.d.ts.map +1 -0
  59. package/dist/external/ehr/practicefusion/shared.js +66 -0
  60. package/dist/external/ehr/practicefusion/shared.js.map +1 -0
  61. package/dist/external/ihe/constants.d.ts +11 -0
  62. package/dist/external/ihe/constants.d.ts.map +1 -1
  63. package/dist/external/ihe/constants.js +65 -1
  64. package/dist/external/ihe/constants.js.map +1 -1
  65. package/dist/external/ihe/index.d.ts +3 -0
  66. package/dist/external/ihe/index.d.ts.map +1 -0
  67. package/dist/external/ihe/index.js +19 -0
  68. package/dist/external/ihe/index.js.map +1 -0
  69. package/dist/external/ihe/shared.d.ts +8 -0
  70. package/dist/external/ihe/shared.d.ts.map +1 -0
  71. package/dist/external/ihe/shared.js +25 -0
  72. package/dist/external/ihe/shared.js.map +1 -0
  73. package/dist/external/index.d.ts +1 -0
  74. package/dist/external/index.d.ts.map +1 -1
  75. package/dist/external/index.js +1 -0
  76. package/dist/external/index.js.map +1 -1
  77. package/dist/index.d.ts +3 -3
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +3 -3
  80. package/dist/index.js.map +1 -1
  81. package/dist/interface/external/ehr/athenahealth/cx-mapping.d.ts +5 -1
  82. package/dist/interface/external/ehr/athenahealth/cx-mapping.d.ts.map +1 -1
  83. package/dist/interface/external/ehr/athenahealth/cx-mapping.js +2 -1
  84. package/dist/interface/external/ehr/athenahealth/cx-mapping.js.map +1 -1
  85. package/dist/interface/external/ehr/canvas/cx-mapping.d.ts +6 -2
  86. package/dist/interface/external/ehr/canvas/cx-mapping.d.ts.map +1 -1
  87. package/dist/interface/external/ehr/canvas/cx-mapping.js +2 -1
  88. package/dist/interface/external/ehr/canvas/cx-mapping.js.map +1 -1
  89. package/dist/interface/external/ehr/eclinicalworks/cx-mapping.d.ts +465 -0
  90. package/dist/interface/external/ehr/eclinicalworks/cx-mapping.d.ts.map +1 -0
  91. package/dist/interface/external/ehr/eclinicalworks/cx-mapping.js +10 -0
  92. package/dist/interface/external/ehr/eclinicalworks/cx-mapping.js.map +1 -0
  93. package/dist/interface/external/ehr/elation/cx-mapping.d.ts +5 -1
  94. package/dist/interface/external/ehr/elation/cx-mapping.d.ts.map +1 -1
  95. package/dist/interface/external/ehr/elation/cx-mapping.js +2 -1
  96. package/dist/interface/external/ehr/elation/cx-mapping.js.map +1 -1
  97. package/dist/interface/external/ehr/embed/jwt-token.d.ts +2 -2
  98. package/dist/interface/external/ehr/healthie/cx-mapping.d.ts +5 -1
  99. package/dist/interface/external/ehr/healthie/cx-mapping.d.ts.map +1 -1
  100. package/dist/interface/external/ehr/healthie/cx-mapping.js +2 -1
  101. package/dist/interface/external/ehr/healthie/cx-mapping.js.map +1 -1
  102. package/dist/interface/external/ehr/healthie/medication.d.ts +8 -8
  103. package/dist/interface/external/ehr/practicefusion/allergy.d.ts +16 -0
  104. package/dist/interface/external/ehr/practicefusion/allergy.d.ts.map +1 -0
  105. package/dist/interface/external/ehr/practicefusion/allergy.js +39 -0
  106. package/dist/interface/external/ehr/practicefusion/allergy.js.map +1 -0
  107. package/dist/interface/external/ehr/practicefusion/appointment.d.ts +137 -0
  108. package/dist/interface/external/ehr/practicefusion/appointment.d.ts.map +1 -0
  109. package/dist/interface/external/ehr/practicefusion/appointment.js +29 -0
  110. package/dist/interface/external/ehr/practicefusion/appointment.js.map +1 -0
  111. package/dist/interface/external/ehr/practicefusion/condition.d.ts +17 -0
  112. package/dist/interface/external/ehr/practicefusion/condition.d.ts.map +1 -0
  113. package/dist/interface/external/ehr/practicefusion/condition.js +13 -0
  114. package/dist/interface/external/ehr/practicefusion/condition.js.map +1 -0
  115. package/dist/interface/external/ehr/practicefusion/cx-mapping.d.ts +472 -0
  116. package/dist/interface/external/ehr/practicefusion/cx-mapping.d.ts.map +1 -0
  117. package/dist/interface/external/ehr/practicefusion/cx-mapping.js +13 -0
  118. package/dist/interface/external/ehr/practicefusion/cx-mapping.js.map +1 -0
  119. package/dist/interface/external/ehr/practicefusion/fhir-resources.d.ts +8 -0
  120. package/dist/interface/external/ehr/practicefusion/fhir-resources.d.ts.map +1 -0
  121. package/dist/interface/external/ehr/practicefusion/fhir-resources.js +3 -0
  122. package/dist/interface/external/ehr/practicefusion/fhir-resources.js.map +1 -0
  123. package/dist/interface/external/ehr/practicefusion/index.d.ts +2 -0
  124. package/dist/interface/external/ehr/practicefusion/index.d.ts.map +1 -1
  125. package/dist/interface/external/ehr/practicefusion/index.js +2 -0
  126. package/dist/interface/external/ehr/practicefusion/index.js.map +1 -1
  127. package/dist/interface/external/ehr/practicefusion/jwt-token.d.ts +15 -3
  128. package/dist/interface/external/ehr/practicefusion/jwt-token.d.ts.map +1 -1
  129. package/dist/interface/external/ehr/practicefusion/jwt-token.js +8 -2
  130. package/dist/interface/external/ehr/practicefusion/jwt-token.js.map +1 -1
  131. package/dist/interface/external/ehr/practicefusion/medication.d.ts +17 -0
  132. package/dist/interface/external/ehr/practicefusion/medication.d.ts.map +1 -0
  133. package/dist/interface/external/ehr/practicefusion/medication.js +13 -0
  134. package/dist/interface/external/ehr/practicefusion/medication.js.map +1 -0
  135. package/dist/interface/external/ehr/practicefusion/refresh-token.d.ts +19 -0
  136. package/dist/interface/external/ehr/practicefusion/refresh-token.d.ts.map +1 -0
  137. package/dist/interface/external/ehr/practicefusion/refresh-token.js +11 -0
  138. package/dist/interface/external/ehr/practicefusion/refresh-token.js.map +1 -0
  139. package/dist/interface/external/ehr/practicefusion/write-back.d.ts +47 -0
  140. package/dist/interface/external/ehr/practicefusion/write-back.d.ts.map +1 -0
  141. package/dist/interface/external/ehr/practicefusion/write-back.js +29 -0
  142. package/dist/interface/external/ehr/practicefusion/write-back.js.map +1 -0
  143. package/dist/interface/external/ehr/salesforce/cx-mapping.d.ts +465 -0
  144. package/dist/interface/external/ehr/salesforce/cx-mapping.d.ts.map +1 -0
  145. package/dist/interface/external/ehr/salesforce/cx-mapping.js +10 -0
  146. package/dist/interface/external/ehr/salesforce/cx-mapping.js.map +1 -0
  147. package/dist/interface/external/ehr/shared.d.ts +8 -0
  148. package/dist/interface/external/ehr/shared.d.ts.map +1 -1
  149. package/dist/interface/external/ehr/shared.js +4 -1
  150. package/dist/interface/external/ehr/shared.js.map +1 -1
  151. package/dist/interface/external/ehr/source.d.ts +2 -0
  152. package/dist/interface/external/ehr/source.d.ts.map +1 -1
  153. package/dist/interface/external/ehr/source.js +6 -1
  154. package/dist/interface/external/ehr/source.js.map +1 -1
  155. package/dist/interface/external/index.d.ts +1 -0
  156. package/dist/interface/external/index.d.ts.map +1 -1
  157. package/dist/interface/external/index.js +1 -0
  158. package/dist/interface/external/index.js.map +1 -1
  159. package/dist/interface/external/surescripts/index.d.ts +2 -0
  160. package/dist/interface/external/surescripts/index.d.ts.map +1 -1
  161. package/dist/interface/external/surescripts/index.js +2 -0
  162. package/dist/interface/external/surescripts/index.js.map +1 -1
  163. package/dist/interface/internal/cohort.d.ts +1000 -0
  164. package/dist/interface/internal/cohort.d.ts.map +1 -0
  165. package/dist/interface/internal/cohort.js +62 -0
  166. package/dist/interface/internal/cohort.js.map +1 -0
  167. package/dist/interface/internal/document-query.d.ts +31 -0
  168. package/dist/interface/internal/document-query.d.ts.map +1 -0
  169. package/dist/interface/internal/document-query.js +21 -0
  170. package/dist/interface/internal/document-query.js.map +1 -0
  171. package/dist/interface/internal/index.d.ts +2 -0
  172. package/dist/interface/internal/index.d.ts.map +1 -1
  173. package/dist/interface/internal/index.js +2 -0
  174. package/dist/interface/internal/index.js.map +1 -1
  175. package/dist/medical/fhir/constants.d.ts +1 -0
  176. package/dist/medical/fhir/constants.d.ts.map +1 -1
  177. package/dist/medical/fhir/constants.js +2 -1
  178. package/dist/medical/fhir/constants.js.map +1 -1
  179. package/dist/medical/webhook/webhook-request.d.ts +683 -2
  180. package/dist/medical/webhook/webhook-request.d.ts.map +1 -1
  181. package/dist/medical/webhook/webhook-request.js +57 -2
  182. package/dist/medical/webhook/webhook-request.js.map +1 -1
  183. package/dist/net/axios.d.ts +3 -0
  184. package/dist/net/axios.d.ts.map +1 -0
  185. package/dist/net/axios.js +21 -0
  186. package/dist/net/axios.js.map +1 -0
  187. package/dist/net/http.d.ts +25 -0
  188. package/dist/net/http.d.ts.map +1 -0
  189. package/dist/net/http.js +76 -0
  190. package/dist/net/http.js.map +1 -0
  191. package/dist/net/index.d.ts +6 -0
  192. package/dist/net/index.d.ts.map +1 -0
  193. package/dist/net/index.js +22 -0
  194. package/dist/net/index.js.map +1 -0
  195. package/dist/net/retry.d.ts +1 -0
  196. package/dist/net/retry.d.ts.map +1 -1
  197. package/dist/net/retry.js +8 -1
  198. package/dist/net/retry.js.map +1 -1
  199. package/dist/util/duration.d.ts +1 -0
  200. package/dist/util/duration.d.ts.map +1 -1
  201. package/dist/util/duration.js +15 -1
  202. package/dist/util/duration.js.map +1 -1
  203. package/dist/util/zod.d.ts +2 -0
  204. package/dist/util/zod.d.ts.map +1 -1
  205. package/dist/util/zod.js +10 -1
  206. package/dist/util/zod.js.map +1 -1
  207. package/package.json +6 -2
@@ -1,35 +1,325 @@
1
1
  import { z } from "zod";
2
- import { NetworkQueryCmd, NetworkQueryStatusCmd } from "./query";
2
+ import { NetworkQueryCmd } from "./query";
3
3
  export declare const hieSource = "hie";
4
4
  export declare const pharmacySource = "pharmacy";
5
- export declare const laboratorySource = "laboratory";
6
- export declare const networkSources: readonly ["hie", "pharmacy", "laboratory"];
7
- export declare const networkSourceSchema: z.ZodEnum<["hie", "pharmacy", "laboratory"]>;
5
+ export declare const labSource = "lab";
6
+ export declare const networkSources: readonly ["hie", "pharmacy", "lab"];
7
+ export declare const networkSourceSchema: z.ZodEnum<["hie", "pharmacy", "lab"]>;
8
8
  export type NetworkSource = (typeof networkSources)[number];
9
9
  export declare function isNetworkSource(source: string): source is NetworkSource;
10
+ export declare const hieSpecificSource = "national-hie";
11
+ export declare const surescriptsSpecificSource = "surescripts";
12
+ export declare const questSpecificSource = "quest";
13
+ export declare const specificSources: readonly ["national-hie", "surescripts", "quest"];
14
+ export declare const specificSourceSchema: z.ZodEnum<["national-hie", "surescripts", "quest"]>;
15
+ export type SpecificSource = (typeof specificSources)[number];
16
+ /**
17
+ * Returns the specific source identifier for a given network source.
18
+ * - HIE sources (Commonwell, Carequality, eHex) are aggregated as "national-hie"
19
+ * - Pharmacy sources use "surescripts"
20
+ * - Lab sources use "quest"
21
+ */
22
+ export declare function getSpecificSource(source: NetworkSource): string;
23
+ export declare const statusProcessing = "processing";
24
+ export declare const statusCompleted = "completed";
25
+ export declare const statusFailed = "failed";
10
26
  export declare const sourceQueryStatus: readonly ["processing", "completed", "failed"];
11
27
  export type SourceQueryStatus = (typeof sourceQueryStatus)[number];
12
- export type SourceQueryCmd = Omit<NetworkQueryCmd, "sources"> & {
13
- source: NetworkSource;
28
+ export declare const statusInitialized = "initialized";
29
+ export declare const statusRequested = "requested";
30
+ export declare const statusOnRoster = "on-roster";
31
+ export declare const statusConverted = "converted";
32
+ /**
33
+ * All non-terminal statuses that represent "in-progress" work.
34
+ * Use as `fromStatuses` when you want to update regardless of current processing state.
35
+ */
36
+ export declare const processingStatuses: readonly ["initialized", "requested", "on-roster", "converted"];
37
+ export type ProcessingStatus = (typeof processingStatuses)[number];
38
+ /**
39
+ * All terminal statuses that represent "processing" work is complete.
40
+ *
41
+ * IMPORTANT: If these values are modified (added, removed, or renamed), you must create a new
42
+ * database migration to update the `network_query_request` view which hardcodes these statuses.
43
+ * See: packages/api/src/sequelize/migrations/2026-01-05_00_create-datasource-query-and-nq-view.ts
44
+ */
45
+ export declare const terminalStatuses: readonly ["completed", "failed"];
46
+ export type TerminalStatus = (typeof terminalStatuses)[number];
47
+ export declare const datasourceQueryStatus: readonly ["initialized", "requested", "on-roster", "converted", "completed", "failed"];
48
+ export type DatasourceQueryStatus = (typeof datasourceQueryStatus)[number];
49
+ /** Enum-like object for DatasourceQueryStatus values */
50
+ export declare const DatasourceQueryStatus: {
51
+ readonly Initialized: "initialized";
52
+ readonly Requested: "requested";
53
+ readonly OnRoster: "on-roster";
54
+ readonly Converted: "converted";
55
+ readonly Completed: "completed";
56
+ readonly Failed: "failed";
14
57
  };
15
- export type SourceQueryStatusCmd = NetworkQueryStatusCmd & {
58
+ /**
59
+ * Alias for DatasourceQueryStatus used by core package for network query status updates.
60
+ */
61
+ export declare const networkQueryTrackingStatus: readonly ["initialized", "requested", "on-roster", "converted", "completed", "failed"];
62
+ export type NetworkQueryTrackingStatus = DatasourceQueryStatus;
63
+ /**
64
+ * Top-level network query status (derived from per-source statuses).
65
+ * This is a computed/dynamic column, not stored directly.
66
+ *
67
+ * - `processing`: At least one source is still processing (initialized, requested, on-roster, converted)
68
+ * - `completed`: All sources completed successfully
69
+ * - `partial`: No sources processing, at least one failed and at least one completed
70
+ * - `failed`: No sources processing, all sources failed
71
+ */
72
+ export declare const networkQueryStatus: readonly ["processing", "completed", "partial", "failed"];
73
+ export type NetworkQueryStatus = (typeof networkQueryStatus)[number];
74
+ /**
75
+ * Checks if a per-source status is considered "processing" (not terminal).
76
+ */
77
+ export declare function isSourceProcessing(status: DatasourceQueryStatus): status is ProcessingStatus;
78
+ /**
79
+ * Derives the top-level network query status from per-source statuses.
80
+ *
81
+ * Rules:
82
+ * - If any source is processing → "processing"
83
+ * - If all sources completed → "completed"
84
+ * - If none processing + at least 1 failed + at least 1 completed → "partial"
85
+ * - If none processing + all failed → "failed"
86
+ */
87
+ export declare function deriveNetworkQueryStatus(sourceStatuses: DatasourceQueryStatus[]): NetworkQueryStatus;
88
+ /**
89
+ * Maps per-source datasource query status to DTO status.
90
+ * All non-terminal statuses are shown as "processing".
91
+ */
92
+ export declare function toSourceStatusDto(status: DatasourceQueryStatus): "processing" | "completed" | "failed";
93
+ export type BaseSourceQueryCmd = Pick<NetworkQueryCmd, "cxId" | "patientId" | "facilityId" | "requestId">;
94
+ /**
95
+ * Error information stored when a source query fails.
96
+ */
97
+ export interface SourceQueryErrorData {
98
+ /** HTTP status code (e.g., 400 for access not enabled, 500 for internal error) */
99
+ httpStatus: number;
100
+ /** ISO 8601 timestamp of when the error occurred */
101
+ timestamp: string;
102
+ /** Human-readable error message */
103
+ message: string;
104
+ }
105
+ /**
106
+ * Data stored in the `data` JSONB column for each datasource query.
107
+ * Contains error information or success metadata depending on the outcome.
108
+ */
109
+ export interface SourceQueryData {
110
+ /** Error information. Present when status is "failed". */
111
+ error?: SourceQueryErrorData;
112
+ /** Customer-provided metadata from the network query request. Returned in webhooks. */
113
+ metadata?: Record<string, string>;
114
+ /** Any additional metadata (e.g., rosterId, documentCount). */
115
+ [key: string]: unknown;
116
+ }
117
+ /**
118
+ * Represents an error that occurred when attempting to query a data source.
119
+ * Used when a source fails to start (e.g., feature flag not enabled, unexpected error).
120
+ */
121
+ export interface SourceQueryError {
122
+ /** The network source type that failed (hie, pharmacy, lab) */
16
123
  source: NetworkSource;
17
- };
124
+ /** HTTP status code representing the error (e.g., 400 for access not enabled, 500 for internal error) */
125
+ httpStatus: number;
126
+ /** Human-readable description of the error */
127
+ message: string;
128
+ /** ISO 8601 timestamp of when the error occurred */
129
+ timestamp: string;
130
+ }
131
+ /**
132
+ * Zod schema for SourceQueryError.
133
+ * Used for parsing/validating API responses.
134
+ */
135
+ export declare const sourceQueryErrorSchema: z.ZodObject<{
136
+ source: z.ZodEnum<["hie", "pharmacy", "lab"]>;
137
+ httpStatus: z.ZodNumber;
138
+ message: z.ZodString;
139
+ timestamp: z.ZodString;
140
+ }, "strip", z.ZodTypeAny, {
141
+ message: string;
142
+ source: "pharmacy" | "hie" | "lab";
143
+ timestamp: string;
144
+ httpStatus: number;
145
+ }, {
146
+ message: string;
147
+ source: "pharmacy" | "hie" | "lab";
148
+ timestamp: string;
149
+ httpStatus: number;
150
+ }>;
151
+ /**
152
+ * Result of querying a data source, containing both successful progresses and errors.
153
+ */
154
+ export interface SourceQueryResult {
155
+ progresses: SourceQueryProgress[];
156
+ errors: SourceQueryError[];
157
+ }
158
+ /**
159
+ * Internal representation of source query progress.
160
+ * Uses DatasourceQueryStatus for actual internal states.
161
+ * Map to SourceQueryStatusDto at system boundaries (HTTP responses, webhooks).
162
+ */
18
163
  export interface SourceQueryProgress {
164
+ /** The network source type (hie, pharmacy, lab) */
19
165
  type: NetworkSource;
20
- source?: string;
21
- status: SourceQueryStatus;
22
- startedAt?: Date;
23
- requestId?: string;
24
- documents?: {
25
- downloadInProgress: number;
26
- downloaded: number;
27
- converted: number;
28
- failed: number;
29
- total: number;
30
- };
166
+ /** Specific source provider (e.g., "national-hie", "surescripts", "quest") */
167
+ specificSource: string;
168
+ status: DatasourceQueryStatus;
169
+ startedAt: Date;
170
+ completedAt?: Date;
171
+ requestId: string;
31
172
  }
173
+ /**
174
+ * Per-datasource query entry from the database.
175
+ * Used for aggregated NetworkQuery interface.
176
+ * Note: Uses createdAt internally, mapped to startedAt at the DTO layer.
177
+ */
178
+ export interface DatasourceQueryEntry {
179
+ source: NetworkSource;
180
+ /** Specific source provider (e.g., "national-hie", "surescripts", "quest") */
181
+ specificSource: string;
182
+ status: DatasourceQueryStatus;
183
+ createdAt: Date;
184
+ completedAt?: Date;
185
+ data?: SourceQueryData;
186
+ }
187
+ /**
188
+ * Converts a DatasourceQueryEntry from the database to a SourceQueryProgress.
189
+ * Maps createdAt (DB column) to startedAt (DTO field).
190
+ */
191
+ export declare function datasourceEntryToProgress(entry: DatasourceQueryEntry, requestId: string): SourceQueryProgress;
192
+ /**
193
+ * Extracts error information from a DatasourceQueryEntry's data field.
194
+ * Returns undefined if the entry doesn't have error data.
195
+ */
196
+ export declare function datasourceEntryToError(entry: DatasourceQueryEntry): SourceQueryError | undefined;
32
197
  export interface NetworkQueryProgress {
33
198
  sources: SourceQueryProgress[];
34
199
  }
200
+ /**
201
+ * DTO representation of aggregated source query status by type.
202
+ * Used at system boundaries (HTTP responses, webhooks).
203
+ * Aggregates all sources of the same type into a single status.
204
+ */
205
+ export interface SourceQueryStatusDto {
206
+ /** The network source type (hie, pharmacy, lab) */
207
+ type: NetworkSource;
208
+ status: SourceQueryStatus;
209
+ startedAt: Date;
210
+ completedAt?: Date;
211
+ }
212
+ /**
213
+ * Zod schema for SourceQueryStatusDto.
214
+ * Parses startedAt from ISO string to Date.
215
+ */
216
+ export declare const sourceQueryStatusDtoSchema: z.ZodObject<{
217
+ type: z.ZodEnum<["hie", "pharmacy", "lab"]>;
218
+ status: z.ZodEnum<["processing", "completed", "failed"]>;
219
+ startedAt: z.ZodDate;
220
+ completedAt: z.ZodOptional<z.ZodDate>;
221
+ }, "strip", z.ZodTypeAny, {
222
+ type: "pharmacy" | "hie" | "lab";
223
+ status: "processing" | "completed" | "failed";
224
+ startedAt: Date;
225
+ completedAt?: Date | undefined;
226
+ }, {
227
+ type: "pharmacy" | "hie" | "lab";
228
+ status: "processing" | "completed" | "failed";
229
+ startedAt: Date;
230
+ completedAt?: Date | undefined;
231
+ }>;
232
+ /**
233
+ * DTO representation of network query status.
234
+ * Used at system boundaries (HTTP responses, webhooks).
235
+ */
236
+ export interface NetworkQueryStatusDto {
237
+ requestId: string;
238
+ status: NetworkQueryStatus;
239
+ sources: SourceQueryStatusDto[];
240
+ /** Errors for sources that failed to start (e.g., feature flag not enabled) */
241
+ errors?: SourceQueryError[];
242
+ }
243
+ /**
244
+ * Zod schema for NetworkQueryStatusDto.
245
+ * Used for parsing/validating API responses.
246
+ */
247
+ export declare const networkQueryStatusDtoSchema: z.ZodObject<{
248
+ requestId: z.ZodString;
249
+ status: z.ZodEnum<["processing", "completed", "partial", "failed"]>;
250
+ sources: z.ZodArray<z.ZodObject<{
251
+ type: z.ZodEnum<["hie", "pharmacy", "lab"]>;
252
+ status: z.ZodEnum<["processing", "completed", "failed"]>;
253
+ startedAt: z.ZodDate;
254
+ completedAt: z.ZodOptional<z.ZodDate>;
255
+ }, "strip", z.ZodTypeAny, {
256
+ type: "pharmacy" | "hie" | "lab";
257
+ status: "processing" | "completed" | "failed";
258
+ startedAt: Date;
259
+ completedAt?: Date | undefined;
260
+ }, {
261
+ type: "pharmacy" | "hie" | "lab";
262
+ status: "processing" | "completed" | "failed";
263
+ startedAt: Date;
264
+ completedAt?: Date | undefined;
265
+ }>, "many">;
266
+ errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
267
+ source: z.ZodEnum<["hie", "pharmacy", "lab"]>;
268
+ httpStatus: z.ZodNumber;
269
+ message: z.ZodString;
270
+ timestamp: z.ZodString;
271
+ }, "strip", z.ZodTypeAny, {
272
+ message: string;
273
+ source: "pharmacy" | "hie" | "lab";
274
+ timestamp: string;
275
+ httpStatus: number;
276
+ }, {
277
+ message: string;
278
+ source: "pharmacy" | "hie" | "lab";
279
+ timestamp: string;
280
+ httpStatus: number;
281
+ }>, "many">>;
282
+ }, "strip", z.ZodTypeAny, {
283
+ status: "processing" | "completed" | "failed" | "partial";
284
+ requestId: string;
285
+ sources: {
286
+ type: "pharmacy" | "hie" | "lab";
287
+ status: "processing" | "completed" | "failed";
288
+ startedAt: Date;
289
+ completedAt?: Date | undefined;
290
+ }[];
291
+ errors?: {
292
+ message: string;
293
+ source: "pharmacy" | "hie" | "lab";
294
+ timestamp: string;
295
+ httpStatus: number;
296
+ }[] | undefined;
297
+ }, {
298
+ status: "processing" | "completed" | "failed" | "partial";
299
+ requestId: string;
300
+ sources: {
301
+ type: "pharmacy" | "hie" | "lab";
302
+ status: "processing" | "completed" | "failed";
303
+ startedAt: Date;
304
+ completedAt?: Date | undefined;
305
+ }[];
306
+ errors?: {
307
+ message: string;
308
+ source: "pharmacy" | "hie" | "lab";
309
+ timestamp: string;
310
+ httpStatus: number;
311
+ }[] | undefined;
312
+ }>;
313
+ /** Type derived from the schema's output - use this when parsing API responses. */
314
+ export type NetworkQueryStatusDtoParsed = z.output<typeof networkQueryStatusDtoSchema>;
315
+ /**
316
+ * Maps internal NetworkQueryProgress to DTO representation.
317
+ * Aggregates sources by type.
318
+ * Use at system boundaries (HTTP responses, webhooks).
319
+ */
320
+ export declare function toNetworkQueryStatusDto(progress: NetworkQueryProgress & {
321
+ requestId: string;
322
+ status: NetworkQueryStatus;
323
+ errors?: SourceQueryError[];
324
+ }): NetworkQueryStatusDto;
35
325
  //# sourceMappingURL=source.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../src/domain/network-query/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,SAAS,QAAQ,CAAC;AAC/B,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,M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AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,GAAG,gBAAgB,GAAG,SAAS,CAShG;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;EAKrC,CAAC;AA8DH;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKtC,CAAC;AAEH,mFAAmF;AACnF,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEvF;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,oBAAoB,GAAG;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC7B,GACA,qBAAqB,CAUvB"}
@@ -1,15 +1,268 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sourceQueryStatus = exports.isNetworkSource = exports.networkSourceSchema = exports.networkSources = exports.laboratorySource = exports.pharmacySource = exports.hieSource = void 0;
3
+ exports.toNetworkQueryStatusDto = exports.networkQueryStatusDtoSchema = exports.sourceQueryStatusDtoSchema = exports.datasourceEntryToError = exports.datasourceEntryToProgress = exports.sourceQueryErrorSchema = exports.toSourceStatusDto = exports.deriveNetworkQueryStatus = exports.isSourceProcessing = exports.networkQueryStatus = exports.networkQueryTrackingStatus = exports.DatasourceQueryStatus = exports.datasourceQueryStatus = exports.terminalStatuses = exports.processingStatuses = exports.statusConverted = exports.statusOnRoster = exports.statusRequested = exports.statusInitialized = exports.sourceQueryStatus = exports.statusFailed = exports.statusCompleted = exports.statusProcessing = exports.getSpecificSource = exports.specificSourceSchema = exports.specificSources = exports.questSpecificSource = exports.surescriptsSpecificSource = exports.hieSpecificSource = exports.isNetworkSource = exports.networkSourceSchema = exports.networkSources = exports.labSource = exports.pharmacySource = exports.hieSource = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.hieSource = "hie";
6
6
  exports.pharmacySource = "pharmacy";
7
- exports.laboratorySource = "laboratory";
8
- exports.networkSources = [exports.hieSource, exports.pharmacySource, exports.laboratorySource];
7
+ exports.labSource = "lab";
8
+ exports.networkSources = [exports.hieSource, exports.pharmacySource, exports.labSource];
9
9
  exports.networkSourceSchema = zod_1.z.enum(exports.networkSources);
10
10
  function isNetworkSource(source) {
11
11
  return exports.networkSourceSchema.safeParse(source).success;
12
12
  }
13
13
  exports.isNetworkSource = isNetworkSource;
14
- exports.sourceQueryStatus = ["processing", "completed", "failed"];
14
+ exports.hieSpecificSource = "national-hie";
15
+ exports.surescriptsSpecificSource = "surescripts";
16
+ exports.questSpecificSource = "quest";
17
+ exports.specificSources = [
18
+ exports.hieSpecificSource,
19
+ exports.surescriptsSpecificSource,
20
+ exports.questSpecificSource,
21
+ ];
22
+ exports.specificSourceSchema = zod_1.z.enum(exports.specificSources);
23
+ /**
24
+ * Returns the specific source identifier for a given network source.
25
+ * - HIE sources (Commonwell, Carequality, eHex) are aggregated as "national-hie"
26
+ * - Pharmacy sources use "surescripts"
27
+ * - Lab sources use "quest"
28
+ */
29
+ function getSpecificSource(source) {
30
+ switch (source) {
31
+ case exports.hieSource:
32
+ return exports.hieSpecificSource;
33
+ case exports.pharmacySource:
34
+ return exports.surescriptsSpecificSource;
35
+ case exports.labSource:
36
+ return exports.questSpecificSource;
37
+ }
38
+ }
39
+ exports.getSpecificSource = getSpecificSource;
40
+ exports.statusProcessing = "processing";
41
+ exports.statusCompleted = "completed";
42
+ exports.statusFailed = "failed";
43
+ exports.sourceQueryStatus = [exports.statusProcessing, exports.statusCompleted, exports.statusFailed];
44
+ exports.statusInitialized = "initialized";
45
+ exports.statusRequested = "requested";
46
+ exports.statusOnRoster = "on-roster";
47
+ exports.statusConverted = "converted";
48
+ /**
49
+ * All non-terminal statuses that represent "in-progress" work.
50
+ * Use as `fromStatuses` when you want to update regardless of current processing state.
51
+ */
52
+ exports.processingStatuses = [
53
+ exports.statusInitialized,
54
+ exports.statusRequested,
55
+ exports.statusOnRoster,
56
+ exports.statusConverted,
57
+ ];
58
+ /**
59
+ * All terminal statuses that represent "processing" work is complete.
60
+ *
61
+ * IMPORTANT: If these values are modified (added, removed, or renamed), you must create a new
62
+ * database migration to update the `network_query_request` view which hardcodes these statuses.
63
+ * See: packages/api/src/sequelize/migrations/2026-01-05_00_create-datasource-query-and-nq-view.ts
64
+ */
65
+ exports.terminalStatuses = [exports.statusCompleted, exports.statusFailed];
66
+ exports.datasourceQueryStatus = [...exports.processingStatuses, ...exports.terminalStatuses];
67
+ /** Enum-like object for DatasourceQueryStatus values */
68
+ exports.DatasourceQueryStatus = {
69
+ Initialized: exports.statusInitialized,
70
+ Requested: exports.statusRequested,
71
+ OnRoster: exports.statusOnRoster,
72
+ Converted: exports.statusConverted,
73
+ Completed: exports.statusCompleted,
74
+ Failed: exports.statusFailed,
75
+ };
76
+ /**
77
+ * Alias for DatasourceQueryStatus used by core package for network query status updates.
78
+ */
79
+ exports.networkQueryTrackingStatus = exports.datasourceQueryStatus;
80
+ /**
81
+ * Top-level network query status (derived from per-source statuses).
82
+ * This is a computed/dynamic column, not stored directly.
83
+ *
84
+ * - `processing`: At least one source is still processing (initialized, requested, on-roster, converted)
85
+ * - `completed`: All sources completed successfully
86
+ * - `partial`: No sources processing, at least one failed and at least one completed
87
+ * - `failed`: No sources processing, all sources failed
88
+ */
89
+ exports.networkQueryStatus = ["processing", "completed", "partial", "failed"];
90
+ /**
91
+ * Checks if a per-source status is considered "processing" (not terminal).
92
+ */
93
+ function isSourceProcessing(status) {
94
+ return exports.processingStatuses.includes(status);
95
+ }
96
+ exports.isSourceProcessing = isSourceProcessing;
97
+ /**
98
+ * Derives the top-level network query status from per-source statuses.
99
+ *
100
+ * Rules:
101
+ * - If any source is processing → "processing"
102
+ * - If all sources completed → "completed"
103
+ * - If none processing + at least 1 failed + at least 1 completed → "partial"
104
+ * - If none processing + all failed → "failed"
105
+ */
106
+ function deriveNetworkQueryStatus(sourceStatuses) {
107
+ if (sourceStatuses.length === 0)
108
+ return "processing";
109
+ const hasProcessing = sourceStatuses.some(isSourceProcessing);
110
+ if (hasProcessing)
111
+ return "processing";
112
+ const completedCount = sourceStatuses.filter(s => s === "completed").length;
113
+ const failedCount = sourceStatuses.filter(s => s === "failed").length;
114
+ if (completedCount === sourceStatuses.length)
115
+ return "completed";
116
+ if (failedCount === sourceStatuses.length)
117
+ return "failed";
118
+ if (failedCount > 0 && completedCount > 0)
119
+ return "partial";
120
+ // Fallback (shouldn't happen if all statuses are terminal)
121
+ return "processing";
122
+ }
123
+ exports.deriveNetworkQueryStatus = deriveNetworkQueryStatus;
124
+ /**
125
+ * Maps per-source datasource query status to DTO status.
126
+ * All non-terminal statuses are shown as "processing".
127
+ */
128
+ function toSourceStatusDto(status) {
129
+ if (isSourceProcessing(status))
130
+ return "processing";
131
+ return status;
132
+ }
133
+ exports.toSourceStatusDto = toSourceStatusDto;
134
+ /**
135
+ * Zod schema for SourceQueryError.
136
+ * Used for parsing/validating API responses.
137
+ */
138
+ exports.sourceQueryErrorSchema = zod_1.z.object({
139
+ source: exports.networkSourceSchema,
140
+ httpStatus: zod_1.z.number(),
141
+ message: zod_1.z.string(),
142
+ timestamp: zod_1.z.string(),
143
+ });
144
+ /**
145
+ * Converts a DatasourceQueryEntry from the database to a SourceQueryProgress.
146
+ * Maps createdAt (DB column) to startedAt (DTO field).
147
+ */
148
+ function datasourceEntryToProgress(entry, requestId) {
149
+ return {
150
+ type: entry.source,
151
+ specificSource: entry.specificSource,
152
+ status: entry.status,
153
+ startedAt: entry.createdAt,
154
+ ...(entry.completedAt ? { completedAt: entry.completedAt } : {}),
155
+ requestId,
156
+ };
157
+ }
158
+ exports.datasourceEntryToProgress = datasourceEntryToProgress;
159
+ /**
160
+ * Extracts error information from a DatasourceQueryEntry's data field.
161
+ * Returns undefined if the entry doesn't have error data.
162
+ */
163
+ function datasourceEntryToError(entry) {
164
+ if (!entry.data?.error)
165
+ return undefined;
166
+ const { httpStatus, timestamp, message } = entry.data.error;
167
+ return {
168
+ source: entry.source,
169
+ httpStatus,
170
+ message,
171
+ timestamp,
172
+ };
173
+ }
174
+ exports.datasourceEntryToError = datasourceEntryToError;
175
+ /**
176
+ * Zod schema for SourceQueryStatusDto.
177
+ * Parses startedAt from ISO string to Date.
178
+ */
179
+ exports.sourceQueryStatusDtoSchema = zod_1.z.object({
180
+ type: exports.networkSourceSchema,
181
+ status: zod_1.z.enum(exports.sourceQueryStatus),
182
+ startedAt: zod_1.z.coerce.date(),
183
+ completedAt: zod_1.z.coerce.date().optional(),
184
+ });
185
+ /**
186
+ * Derives aggregated status from multiple source statuses.
187
+ * - If any is "processing" → "processing"
188
+ * - If all are "completed" → "completed"
189
+ * - If all are "failed" → "failed"
190
+ * - Mixed completed/failed → "completed" (processing is done)
191
+ */
192
+ function deriveAggregatedSourceStatus(statuses) {
193
+ if (statuses.length === 0)
194
+ return "processing";
195
+ if (statuses.some(s => s === "processing"))
196
+ return "processing";
197
+ if (statuses.every(s => s === "completed"))
198
+ return "completed";
199
+ if (statuses.every(s => s === "failed"))
200
+ return "failed";
201
+ return "completed";
202
+ }
203
+ /**
204
+ * Aggregates source query progresses by type into DTOs.
205
+ * Groups all sources of the same type and derives a single status.
206
+ */
207
+ function aggregateSourcesByType(sources) {
208
+ const grouped = new Map();
209
+ for (const source of sources) {
210
+ const existing = grouped.get(source.type) ?? [];
211
+ existing.push(source);
212
+ grouped.set(source.type, existing);
213
+ }
214
+ const result = [];
215
+ for (const [type, groupedSources] of grouped) {
216
+ const firstSource = groupedSources[0];
217
+ if (!firstSource)
218
+ continue;
219
+ const statuses = groupedSources.map(s => toSourceStatusDto(s.status));
220
+ const earliestStartedAt = groupedSources.reduce((earliest, s) => (s.startedAt < earliest ? s.startedAt : earliest), firstSource.startedAt);
221
+ // Only include completedAt if ALL sources of this type have completedAt
222
+ const allHaveCompletedAt = groupedSources.every(s => s.completedAt !== undefined);
223
+ const latestCompletedAt = allHaveCompletedAt
224
+ ? groupedSources.reduce((latest, s) => {
225
+ if (!s.completedAt)
226
+ return latest;
227
+ if (!latest)
228
+ return s.completedAt;
229
+ return s.completedAt > latest ? s.completedAt : latest;
230
+ }, undefined)
231
+ : undefined;
232
+ result.push({
233
+ type,
234
+ status: deriveAggregatedSourceStatus(statuses),
235
+ startedAt: earliestStartedAt,
236
+ ...(latestCompletedAt ? { completedAt: latestCompletedAt } : {}),
237
+ });
238
+ }
239
+ return result;
240
+ }
241
+ /**
242
+ * Zod schema for NetworkQueryStatusDto.
243
+ * Used for parsing/validating API responses.
244
+ */
245
+ exports.networkQueryStatusDtoSchema = zod_1.z.object({
246
+ requestId: zod_1.z.string(),
247
+ status: zod_1.z.enum(exports.networkQueryStatus),
248
+ sources: zod_1.z.array(exports.sourceQueryStatusDtoSchema),
249
+ errors: zod_1.z.array(exports.sourceQueryErrorSchema).optional(),
250
+ });
251
+ /**
252
+ * Maps internal NetworkQueryProgress to DTO representation.
253
+ * Aggregates sources by type.
254
+ * Use at system boundaries (HTTP responses, webhooks).
255
+ */
256
+ function toNetworkQueryStatusDto(progress) {
257
+ const result = {
258
+ requestId: progress.requestId,
259
+ status: progress.status,
260
+ sources: aggregateSourcesByType(progress.sources),
261
+ };
262
+ if (progress.errors && progress.errors.length > 0) {
263
+ result.errors = progress.errors;
264
+ }
265
+ return result;
266
+ }
267
+ exports.toNetworkQueryStatusDto = toNetworkQueryStatusDto;
15
268
  //# sourceMappingURL=source.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/domain/network-query/source.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGX,QAAA,SAAS,GAAG,KAAK,CAAC;AAClB,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAChC,QAAA,cAAc,GAAG,CAAC,iBAAS,EAAE,sBAAc,EAAE,wBAAgB,CAAU,CAAC;AACxE,QAAA,mBAAmB,GAAG,OAAC,CAAC,IAAI,CAAC,sBAAc,CAAC,CAAC;AAG1D,SAAgB,eAAe,CAAC,MAAc;IAC5C,OAAO,2BAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AACvD,CAAC;AAFD,0CAEC;AAEY,QAAA,iBAAiB,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC"}
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/domain/network-query/source.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGX,QAAA,SAAS,GAAG,KAAK,CAAC;AAClB,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,SAAS,GAAG,KAAK,CAAC;AAClB,QAAA,cAAc,GAAG,CAAC,iBAAS,EAAE,sBAAc,EAAE,iBAAS,CAAU,CAAC;AACjE,QAAA,mBAAmB,GAAG,OAAC,CAAC,IAAI,CAAC,sBAAc,CAAC,CAAC;AAG1D,SAAgB,eAAe,CAAC,MAAc;IAC5C,OAAO,2BAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,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