@bahmni/appointments-app 0.0.1-dev.182 → 0.0.1-dev.185

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.
@@ -0,0 +1,369 @@
1
+ import { jsxs as D, jsx as v } from "react/jsx-runtime";
2
+ import { o as U, r as _, s as P, Q as L, c as V, t as K, v as G, w as j, x as W, z as J, A as X, B as T, D as N, E as Y, H as Z, M as ee, p as se, u as M, I as te, a as re, S as ie, e as ne, J as oe, L as ae, R as ue, b as ce, N as le, W as k, X as he, h as de, Z as pe, y as be, k as fe, l as ye, _ as ve } from "./index-Dxc52lRE.js";
3
+ import * as E from "react";
4
+ import { useRef as me, useEffect as I, useMemo as C } from "react";
5
+ function $(e, s) {
6
+ const t = new Set(s);
7
+ return e.filter((i) => !t.has(i));
8
+ }
9
+ function Re(e, s, t) {
10
+ const i = e.slice(0);
11
+ return i[s] = t, i;
12
+ }
13
+ var Oe = class extends U {
14
+ #r;
15
+ #e;
16
+ #i;
17
+ #n;
18
+ #s;
19
+ #t;
20
+ #o;
21
+ #a;
22
+ #u = [];
23
+ constructor(e, s, t) {
24
+ super(), this.#r = e, this.#n = t, this.#i = [], this.#s = [], this.#e = [], this.setQueries(s);
25
+ }
26
+ onSubscribe() {
27
+ this.listeners.size === 1 && this.#s.forEach((e) => {
28
+ e.subscribe((s) => {
29
+ this.#d(e, s);
30
+ });
31
+ });
32
+ }
33
+ onUnsubscribe() {
34
+ this.listeners.size || this.destroy();
35
+ }
36
+ destroy() {
37
+ this.listeners = /* @__PURE__ */ new Set(), this.#s.forEach((e) => {
38
+ e.destroy();
39
+ });
40
+ }
41
+ setQueries(e, s) {
42
+ if (this.#i = e, this.#n = s, process.env.NODE_ENV !== "production") {
43
+ const t = e.map(
44
+ (i) => this.#r.defaultQueryOptions(i).queryHash
45
+ );
46
+ new Set(t).size !== t.length && console.warn(
47
+ "[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
48
+ );
49
+ }
50
+ _.batch(() => {
51
+ const t = this.#s, i = this.#h(this.#i);
52
+ this.#u = i, i.forEach(
53
+ (n) => n.observer.setOptions(n.defaultedQueryOptions)
54
+ );
55
+ const r = i.map((n) => n.observer), o = r.map(
56
+ (n) => n.getCurrentResult()
57
+ ), a = r.some(
58
+ (n, u) => n !== t[u]
59
+ );
60
+ t.length === r.length && !a || (this.#s = r, this.#e = o, this.hasListeners() && ($(t, r).forEach((n) => {
61
+ n.destroy();
62
+ }), $(r, t).forEach((n) => {
63
+ n.subscribe((u) => {
64
+ this.#d(n, u);
65
+ });
66
+ }), this.#p()));
67
+ });
68
+ }
69
+ getCurrentResult() {
70
+ return this.#e;
71
+ }
72
+ getQueries() {
73
+ return this.#s.map((e) => e.getCurrentQuery());
74
+ }
75
+ getObservers() {
76
+ return this.#s;
77
+ }
78
+ getOptimisticResult(e, s) {
79
+ const t = this.#h(e), i = t.map(
80
+ (r) => r.observer.getOptimisticResult(r.defaultedQueryOptions)
81
+ );
82
+ return [
83
+ i,
84
+ (r) => this.#l(r ?? i, s),
85
+ () => this.#c(i, t)
86
+ ];
87
+ }
88
+ #c(e, s) {
89
+ return s.map((t, i) => {
90
+ const r = e[i];
91
+ return t.defaultedQueryOptions.notifyOnChangeProps ? r : t.observer.trackResult(r, (o) => {
92
+ s.forEach((a) => {
93
+ a.observer.trackProp(o);
94
+ });
95
+ });
96
+ });
97
+ }
98
+ #l(e, s) {
99
+ return s ? ((!this.#t || this.#e !== this.#a || s !== this.#o) && (this.#o = s, this.#a = this.#e, this.#t = P(
100
+ this.#t,
101
+ s(e)
102
+ )), this.#t) : e;
103
+ }
104
+ #h(e) {
105
+ const s = new Map(
106
+ this.#s.map((i) => [i.options.queryHash, i])
107
+ ), t = [];
108
+ return e.forEach((i) => {
109
+ const r = this.#r.defaultQueryOptions(i), o = s.get(r.queryHash);
110
+ o ? t.push({
111
+ defaultedQueryOptions: r,
112
+ observer: o
113
+ }) : t.push({
114
+ defaultedQueryOptions: r,
115
+ observer: new L(this.#r, r)
116
+ });
117
+ }), t;
118
+ }
119
+ #d(e, s) {
120
+ const t = this.#s.indexOf(e);
121
+ t !== -1 && (this.#e = Re(this.#e, t, s), this.#p());
122
+ }
123
+ #p() {
124
+ if (this.hasListeners()) {
125
+ const e = this.#t, s = this.#c(this.#e, this.#u), t = this.#l(s, this.#n?.combine);
126
+ e !== t && _.batch(() => {
127
+ this.listeners.forEach((i) => {
128
+ i(this.#e);
129
+ });
130
+ });
131
+ }
132
+ }
133
+ };
134
+ function ge({
135
+ queries: e,
136
+ ...s
137
+ }, t) {
138
+ const i = V(t), r = K(), o = G(), a = E.useMemo(
139
+ () => e.map((l) => {
140
+ const d = i.defaultQueryOptions(
141
+ l
142
+ );
143
+ return d._optimisticResults = r ? "isRestoring" : "optimistic", d;
144
+ }),
145
+ [e, i, r]
146
+ );
147
+ a.forEach((l) => {
148
+ j(l), W(l, o);
149
+ }), J(o);
150
+ const [n] = E.useState(
151
+ () => new Oe(
152
+ i,
153
+ a,
154
+ s
155
+ )
156
+ ), [u, p, b] = n.getOptimisticResult(
157
+ a,
158
+ s.combine
159
+ ), f = !r && s.subscribed !== !1;
160
+ E.useSyncExternalStore(
161
+ E.useCallback(
162
+ (l) => f ? n.subscribe(_.batchCalls(l)) : X,
163
+ [n, f]
164
+ ),
165
+ () => n.getCurrentResult(),
166
+ () => n.getCurrentResult()
167
+ ), E.useEffect(() => {
168
+ n.setQueries(
169
+ a,
170
+ s
171
+ );
172
+ }, [a, s, n]);
173
+ const S = u.some(
174
+ (l, d) => T(a[d], l)
175
+ ) ? u.flatMap((l, d) => {
176
+ const h = a[d];
177
+ if (h) {
178
+ const O = new L(i, h);
179
+ if (T(h, l))
180
+ return N(h, O, o);
181
+ Y(l, r) && N(h, O, o);
182
+ }
183
+ return [];
184
+ }) : [];
185
+ if (S.length > 0)
186
+ throw Promise.all(S);
187
+ const R = u.find(
188
+ (l, d) => {
189
+ const h = a[d];
190
+ return h && Z({
191
+ result: l,
192
+ errorResetBoundary: o,
193
+ throwOnError: h.throwOnError,
194
+ query: i.getQueryCache().get(h.queryHash),
195
+ suspense: h.suspense
196
+ });
197
+ }
198
+ );
199
+ if (R?.error)
200
+ throw R.error;
201
+ return p(b());
202
+ }
203
+ const z = (e, s, t, i, r) => {
204
+ const o = he(e, s), a = o.value, n = de(a);
205
+ let u = a;
206
+ n === "Image" && (u = /* @__PURE__ */ v(be, { imageSrc: a, alt: a, id: `${a}-img` })), n === "Video" && (u = /* @__PURE__ */ v(fe, { id: `${a}-video`, videoSrc: a })), n === "PDF" && (u = /* @__PURE__ */ v(ye, { id: `${a}-pdf`, src: a }));
207
+ const p = r("OBSERVATIONS_RECORDED_BY", {
208
+ provider: o.provider
209
+ }), b = e.display, f = e.observationValue?.isAbnormal ? "abnormal-obs" : "obs", y = i ? `${i}-${f}-${b}-${t}-${s}` : `${f}-${b}-${t}-${s}`;
210
+ return /* @__PURE__ */ v(
211
+ pe,
212
+ {
213
+ header: o.header,
214
+ value: u,
215
+ info: p,
216
+ id: y,
217
+ testId: y,
218
+ ariaLabel: y
219
+ },
220
+ `obs-${e.id}`
221
+ );
222
+ }, Ee = (e, s, t, i, r, o) => /* @__PURE__ */ v(
223
+ k,
224
+ {
225
+ title: e.display,
226
+ id: `grouped-obs-${e.display}-${i}`,
227
+ open: t,
228
+ children: e.members?.map(
229
+ (a, n) => z(a, n, r, o, s)
230
+ )
231
+ },
232
+ `grouped-obs-${e.id}`
233
+ ), Se = ({
234
+ groupedData: e,
235
+ title: s = ""
236
+ }) => {
237
+ const { t } = M(), i = (r, o, a) => {
238
+ const n = le(r.encounterDetails, t);
239
+ return /* @__PURE__ */ D(
240
+ k,
241
+ {
242
+ title: n,
243
+ id: `encounter-${r.encounterId}`,
244
+ open: o,
245
+ children: [
246
+ r.observations.map(
247
+ (u, p) => z(u, p, a, s, t)
248
+ ),
249
+ r.groupedObservations.map(
250
+ (u, p) => Ee(
251
+ u,
252
+ t,
253
+ o,
254
+ p,
255
+ a,
256
+ s
257
+ )
258
+ )
259
+ ]
260
+ },
261
+ `encounter-${r.encounterId}`
262
+ );
263
+ };
264
+ return /* @__PURE__ */ v(
265
+ "div",
266
+ {
267
+ id: "obs-by-encounter",
268
+ "data-testid": "obs-by-encounter-test-id",
269
+ "aria-label": "obs-by-encounter-aria-label",
270
+ children: e.map(
271
+ (r, o) => i(r, o === 0, o)
272
+ )
273
+ }
274
+ );
275
+ }, Qe = "_observations_kfbhq_1", Ce = "_title_kfbhq_12", q = {
276
+ observations: Qe,
277
+ title: Ce
278
+ }, _e = (e) => ["conceptUuid", e], we = (e, s) => ["observations", e, ...s], $e = ({ config: e }) => {
279
+ const s = e, { conceptNames: t = [], conceptUuid: i = [] } = s, r = me(/* @__PURE__ */ new Set()), o = ee(), { addNotification: a } = se(), { t: n } = M(), u = ge({
280
+ queries: t.map((c) => ({
281
+ queryKey: _e(c),
282
+ queryFn: () => te(c),
283
+ enabled: !!c
284
+ }))
285
+ });
286
+ I(() => {
287
+ u.forEach((c, m) => {
288
+ if (c.isError && !r.current.has(m)) {
289
+ const H = t[m];
290
+ a({
291
+ title: n("ERROR_DEFAULT_TITLE"),
292
+ message: n("ERROR_FETCHING_CONCEPT", { conceptName: H }),
293
+ type: "error"
294
+ }), r.current.add(m);
295
+ } else c.isError || r.current.delete(m);
296
+ });
297
+ }, [u, t]);
298
+ const p = C(() => u.map((c) => c.data?.uuid).filter((c) => !!c), [u]), b = C(() => [.../* @__PURE__ */ new Set([...p, ...i])], [p, i]), f = C(() => t.length === 0 ? !0 : u.every((c) => !c.isLoading), [u, t.length]), {
299
+ data: y,
300
+ isLoading: S,
301
+ isError: R,
302
+ refetch: l
303
+ } = re({
304
+ queryKey: we(o, b),
305
+ queryFn: () => ve(o, b),
306
+ enabled: !!o && b.length > 0 && f
307
+ });
308
+ ie(
309
+ (c) => {
310
+ c.patientUUID === o && c.updatedConcepts.size > 0 && [...c.updatedConcepts.keys()].some(
311
+ (m) => b.includes(m)
312
+ ) && l();
313
+ },
314
+ [o, l]
315
+ ), I(() => {
316
+ R && a({
317
+ title: n("ERROR_DEFAULT_TITLE"),
318
+ message: n("ERROR_FETCHING_OBSERVATIONS"),
319
+ type: "error"
320
+ });
321
+ }, [R]);
322
+ const d = C(() => {
323
+ if (!y) return [];
324
+ const c = ne(y), m = oe(c);
325
+ return ae(m);
326
+ }, [y]), h = [
327
+ { key: "name", header: "name" },
328
+ { key: "value", header: "value" },
329
+ { key: "form", header: "form" }
330
+ ], O = S || !f, w = R && f, A = (!y || y.entry?.length === 0 || b.length === 0) && f, B = w ? n("ERROR_FETCHING_OBSERVATIONS") : null, x = A ? n("NO_OBSERVATIONS_FOUND") : void 0, F = d.length > 0 && !O && !w, Q = s.titleTranslationKey, g = Q ? n(Q) : "";
331
+ return /* @__PURE__ */ D(
332
+ "div",
333
+ {
334
+ id: "observations",
335
+ "data-testid": Q ? `observations-${g}` : "observations",
336
+ "aria-label": "observations-aria-label",
337
+ className: q.observations,
338
+ children: [
339
+ /* @__PURE__ */ v(
340
+ ue,
341
+ {
342
+ id: "observations-title",
343
+ testId: Q ? `observations-title-${g}` : "observations-title",
344
+ title: g,
345
+ className: q.title,
346
+ children: /* @__PURE__ */ v("p", { children: g })
347
+ }
348
+ ),
349
+ F ? /* @__PURE__ */ v(Se, { groupedData: d, title: g }) : /* @__PURE__ */ v(
350
+ ce,
351
+ {
352
+ headers: h,
353
+ rows: [],
354
+ ariaLabel: n("OBSERVATIONS"),
355
+ loading: O,
356
+ errorStateMessage: B,
357
+ emptyStateMessage: x,
358
+ dataTestId: "observations-table"
359
+ }
360
+ )
361
+ ]
362
+ }
363
+ );
364
+ };
365
+ export {
366
+ _e as conceptUuidQueryKeys,
367
+ $e as default,
368
+ we as observationsQueryKeys
369
+ };