@bahmni/clinical-app 0.0.1-dev.109 → 0.0.1-dev.110

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,503 @@
1
+ import { jsxs as I, jsx as p } from "react/jsx-runtime";
2
+ import { S as U, n as w, h as F, i as D, j as J, k as P, l as K, m as z, o as G, p as j, q as W, s as T, t as Q, w as X, v as Y, T as Z, x as ee, u as N, y as te, a as se, z as re, Q as ne, A as ie, B as q, _ as oe, H as ae, E as ue, G as ce, I as le } from "./index-BzD6Dx9A.js";
3
+ import * as R from "react";
4
+ import { useRef as de, useEffect as C, useMemo as S } from "react";
5
+ function _(e, t) {
6
+ const s = new Set(t);
7
+ return e.filter((r) => !s.has(r));
8
+ }
9
+ function he(e, t, s) {
10
+ const r = e.slice(0);
11
+ return r[t] = s, r;
12
+ }
13
+ var pe = class extends U {
14
+ #r;
15
+ #e;
16
+ #n;
17
+ #i;
18
+ #t;
19
+ #s;
20
+ #o;
21
+ #a;
22
+ #u = [];
23
+ constructor(e, t, s) {
24
+ super(), this.#r = e, this.#i = s, this.#n = [], this.#t = [], this.#e = [], this.setQueries(t);
25
+ }
26
+ onSubscribe() {
27
+ this.listeners.size === 1 && this.#t.forEach((e) => {
28
+ e.subscribe((t) => {
29
+ this.#h(e, t);
30
+ });
31
+ });
32
+ }
33
+ onUnsubscribe() {
34
+ this.listeners.size || this.destroy();
35
+ }
36
+ destroy() {
37
+ this.listeners = /* @__PURE__ */ new Set(), this.#t.forEach((e) => {
38
+ e.destroy();
39
+ });
40
+ }
41
+ setQueries(e, t) {
42
+ if (this.#n = e, this.#i = t, process.env.NODE_ENV !== "production") {
43
+ const s = e.map(
44
+ (r) => this.#r.defaultQueryOptions(r).queryHash
45
+ );
46
+ new Set(s).size !== s.length && console.warn(
47
+ "[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
48
+ );
49
+ }
50
+ w.batch(() => {
51
+ const s = this.#t, r = this.#d(this.#n);
52
+ this.#u = r, r.forEach(
53
+ (i) => i.observer.setOptions(i.defaultedQueryOptions)
54
+ );
55
+ const n = r.map((i) => i.observer), o = n.map(
56
+ (i) => i.getCurrentResult()
57
+ ), a = n.some(
58
+ (i, u) => i !== s[u]
59
+ );
60
+ s.length === n.length && !a || (this.#t = n, this.#e = o, this.hasListeners() && (_(s, n).forEach((i) => {
61
+ i.destroy();
62
+ }), _(n, s).forEach((i) => {
63
+ i.subscribe((u) => {
64
+ this.#h(i, u);
65
+ });
66
+ }), this.#p()));
67
+ });
68
+ }
69
+ getCurrentResult() {
70
+ return this.#e;
71
+ }
72
+ getQueries() {
73
+ return this.#t.map((e) => e.getCurrentQuery());
74
+ }
75
+ getObservers() {
76
+ return this.#t;
77
+ }
78
+ getOptimisticResult(e, t) {
79
+ const s = this.#d(e), r = s.map(
80
+ (n) => n.observer.getOptimisticResult(n.defaultedQueryOptions)
81
+ );
82
+ return [
83
+ r,
84
+ (n) => this.#l(n ?? r, t),
85
+ () => this.#c(r, s)
86
+ ];
87
+ }
88
+ #c(e, t) {
89
+ return t.map((s, r) => {
90
+ const n = e[r];
91
+ return s.defaultedQueryOptions.notifyOnChangeProps ? n : s.observer.trackResult(n, (o) => {
92
+ t.forEach((a) => {
93
+ a.observer.trackProp(o);
94
+ });
95
+ });
96
+ });
97
+ }
98
+ #l(e, t) {
99
+ return t ? ((!this.#s || this.#e !== this.#a || t !== this.#o) && (this.#o = t, this.#a = this.#e, this.#s = F(
100
+ this.#s,
101
+ t(e)
102
+ )), this.#s) : e;
103
+ }
104
+ #d(e) {
105
+ const t = new Map(
106
+ this.#t.map((r) => [r.options.queryHash, r])
107
+ ), s = [];
108
+ return e.forEach((r) => {
109
+ const n = this.#r.defaultQueryOptions(r), o = t.get(n.queryHash);
110
+ o ? s.push({
111
+ defaultedQueryOptions: n,
112
+ observer: o
113
+ }) : s.push({
114
+ defaultedQueryOptions: n,
115
+ observer: new D(this.#r, n)
116
+ });
117
+ }), s;
118
+ }
119
+ #h(e, t) {
120
+ const s = this.#t.indexOf(e);
121
+ s !== -1 && (this.#e = he(this.#e, s, t), this.#p());
122
+ }
123
+ #p() {
124
+ if (this.hasListeners()) {
125
+ const e = this.#s, t = this.#c(this.#e, this.#u), s = this.#l(t, this.#i?.combine);
126
+ e !== s && w.batch(() => {
127
+ this.listeners.forEach((r) => {
128
+ r(this.#e);
129
+ });
130
+ });
131
+ }
132
+ }
133
+ };
134
+ function fe({
135
+ queries: e,
136
+ ...t
137
+ }, s) {
138
+ const r = J(s), n = P(), o = K(), a = R.useMemo(
139
+ () => e.map((c) => {
140
+ const h = r.defaultQueryOptions(
141
+ c
142
+ );
143
+ return h._optimisticResults = n ? "isRestoring" : "optimistic", h;
144
+ }),
145
+ [e, r, n]
146
+ );
147
+ a.forEach((c) => {
148
+ z(c), G(c, o);
149
+ }), j(o);
150
+ const [i] = R.useState(
151
+ () => new pe(
152
+ r,
153
+ a,
154
+ t
155
+ )
156
+ ), [u, f, v] = i.getOptimisticResult(
157
+ a,
158
+ t.combine
159
+ ), b = !n && t.subscribed !== !1;
160
+ R.useSyncExternalStore(
161
+ R.useCallback(
162
+ (c) => b ? i.subscribe(w.batchCalls(c)) : W,
163
+ [i, b]
164
+ ),
165
+ () => i.getCurrentResult(),
166
+ () => i.getCurrentResult()
167
+ ), R.useEffect(() => {
168
+ i.setQueries(
169
+ a,
170
+ t
171
+ );
172
+ }, [a, t, i]);
173
+ const E = u.some(
174
+ (c, h) => T(a[h], c)
175
+ ) ? u.flatMap((c, h) => {
176
+ const d = a[h];
177
+ if (d) {
178
+ const O = new D(r, d);
179
+ if (T(d, c))
180
+ return Q(d, O, o);
181
+ X(c, n) && Q(d, O, o);
182
+ }
183
+ return [];
184
+ }) : [];
185
+ if (E.length > 0)
186
+ throw Promise.all(E);
187
+ const m = u.find(
188
+ (c, h) => {
189
+ const d = a[h];
190
+ return d && Y({
191
+ result: c,
192
+ errorResetBoundary: o,
193
+ throwOnError: d.throwOnError,
194
+ query: r.getQueryCache().get(d.queryHash),
195
+ suspense: d.suspense
196
+ });
197
+ }
198
+ );
199
+ if (m?.error)
200
+ throw m.error;
201
+ return f(v());
202
+ }
203
+ const be = "normal", ve = "http://terminology.hl7.org/CodeSystem/referencerange-meaning", ge = "A", me = "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation", ye = (e, t) => e?.date ? ie(e.date, t).formattedResult : t("DATE_ERROR_PARSE"), Oe = (e) => {
204
+ const { value: t, unit: s } = e.observationValue;
205
+ return s ? `${t} ${s}` : String(t);
206
+ }, Re = (e) => {
207
+ const { unit: t, referenceRange: s } = e.observationValue, r = e.display;
208
+ if (!s)
209
+ return String(r);
210
+ const { low: n, high: o } = s;
211
+ if (n && o) {
212
+ const a = n.unit ? `${n.value} ${n.unit}` : t ? `${n.value} ${t}` : String(n.value), i = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value);
213
+ return `${r} (${a} - ${i})`;
214
+ }
215
+ if (n) {
216
+ const a = n.unit ? `${n.value} ${n.unit}` : t ? `${n.value} ${t}` : String(n.value);
217
+ return `${r} (>${a})`;
218
+ }
219
+ if (o) {
220
+ const a = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value);
221
+ return `${r} (<${a})`;
222
+ }
223
+ return r;
224
+ }, Ee = (e, t) => ({
225
+ index: t,
226
+ header: Re(e),
227
+ value: Oe(e),
228
+ provider: e.encounter?.provider
229
+ }), $ = (e) => (typeof e == "string" ? e : e?.reference)?.split("/")?.pop();
230
+ function Se(e) {
231
+ return !e.interpretation || e.interpretation.length === 0 ? !1 : e.interpretation.some(
232
+ (t) => t.coding?.some(
233
+ (s) => s.system === me && s.code === ge
234
+ )
235
+ );
236
+ }
237
+ function we(e) {
238
+ const { valueQuantity: t, valueCodeableConcept: s, valueString: r, referenceRange: n } = e, o = Se(e);
239
+ if (t) {
240
+ const a = {
241
+ value: t.value ?? "",
242
+ unit: t.unit,
243
+ type: "quantity",
244
+ isAbnormal: o
245
+ };
246
+ if (n && n.length > 0) {
247
+ const i = n.find(
248
+ (u) => u.type?.coding?.some(
249
+ (f) => f.system === ve && f.code === be
250
+ )
251
+ );
252
+ i && (i.low || i.high) && (a.referenceRange = {
253
+ low: i.low ? {
254
+ value: i.low.value,
255
+ unit: i.low.unit
256
+ } : void 0,
257
+ high: i.high ? {
258
+ value: i.high.value,
259
+ unit: i.high.unit
260
+ } : void 0
261
+ });
262
+ }
263
+ return a;
264
+ }
265
+ if (s)
266
+ return {
267
+ value: s.text ?? s.coding[0].display,
268
+ type: "codeable",
269
+ isAbnormal: o
270
+ };
271
+ if (r)
272
+ return {
273
+ value: r,
274
+ type: "string",
275
+ isAbnormal: o
276
+ };
277
+ }
278
+ function $e(e, t) {
279
+ const s = t.get(e);
280
+ if (s)
281
+ return {
282
+ id: s.id ?? e,
283
+ type: s.type?.[0]?.coding?.[0]?.display ?? "Unknown",
284
+ date: s.period?.start ?? "",
285
+ provider: s.participant?.[0]?.individual?.display,
286
+ location: s.location?.[0]?.location?.display
287
+ };
288
+ }
289
+ function M(e, t, s) {
290
+ const r = $(e.encounter), n = (e.hasMember ?? []).map((o) => $(o)).map((o) => o ? s.get(o) : void 0).filter((o) => !!o).map(
291
+ (o) => M(o, t, s)
292
+ );
293
+ return {
294
+ id: e.id,
295
+ display: e.code?.text ?? e.code?.coding?.[0]?.display ?? "",
296
+ observationValue: we(e),
297
+ effectiveDateTime: e.effectiveDateTime,
298
+ issued: e.issued,
299
+ encounter: r ? $e(r, t) : void 0,
300
+ members: n.length > 0 ? n : void 0
301
+ };
302
+ }
303
+ function Te(e) {
304
+ const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
305
+ e.entry?.forEach(({ resource: a }) => {
306
+ a?.id && (a.resourceType === "Encounter" ? t.set(a.id, a) : a.resourceType === "Observation" && (s.set(a.id, a), a.hasMember?.forEach((i) => {
307
+ const u = $(i);
308
+ u && r.add(u);
309
+ })));
310
+ });
311
+ const n = [], o = [];
312
+ return s.forEach((a, i) => {
313
+ if (r.has(i)) return;
314
+ const u = M(
315
+ a,
316
+ t,
317
+ s
318
+ );
319
+ u.members?.length ? o.push({ ...u, children: u.members }) : n.push(u);
320
+ }), { observations: n, groupedObservations: o };
321
+ }
322
+ function Qe(e) {
323
+ const t = /* @__PURE__ */ new Map();
324
+ return e.observations.forEach((s) => {
325
+ if (!s.encounter?.id) return;
326
+ const r = s.encounter.id;
327
+ t.has(r) || t.set(r, {
328
+ observations: [],
329
+ groupedObservations: []
330
+ }), t.get(r).observations.push(s);
331
+ }), e.groupedObservations.forEach((s) => {
332
+ if (!s.encounter?.id) return;
333
+ const r = s.encounter.id;
334
+ t.has(r) || t.set(r, {
335
+ observations: [],
336
+ groupedObservations: []
337
+ }), t.get(r).groupedObservations.push(s);
338
+ }), Array.from(t.entries()).map(([s, r]) => {
339
+ const n = r.observations[0]?.encounter ?? r.groupedObservations[0]?.encounter;
340
+ return {
341
+ encounterId: s,
342
+ encounterDetails: n,
343
+ observations: r.observations,
344
+ groupedObservations: r.groupedObservations
345
+ };
346
+ });
347
+ }
348
+ function Ce(e) {
349
+ return [...e].sort((t, s) => {
350
+ const r = t.encounterDetails?.date, n = s.encounterDetails?.date;
351
+ return !r && !n ? 0 : r ? n ? new Date(n).getTime() - new Date(r).getTime() : -1 : 1;
352
+ });
353
+ }
354
+ const k = (e, t, s) => {
355
+ const r = Ee(e, t), n = r.value, o = oe(n);
356
+ let a = n;
357
+ o === "Image" && (a = /* @__PURE__ */ p(ue, { imageSrc: n, alt: n, id: `${n}-img` })), o === "Video" && (a = /* @__PURE__ */ p(ce, { id: `${n}-video`, videoSrc: n }));
358
+ const i = s("OBSERVATIONS_RECORDED_BY", {
359
+ provider: r.provider
360
+ }), u = e.observationValue?.isAbnormal ? `abnormal-obs-${e.id}` : `obs-${e.id}`;
361
+ return /* @__PURE__ */ p(
362
+ ae,
363
+ {
364
+ header: r.header,
365
+ value: a,
366
+ info: i,
367
+ id: u,
368
+ testId: `${u}-test-id`,
369
+ ariaLabel: `${u}-aria-label`
370
+ },
371
+ `obs-${e.id}`
372
+ );
373
+ }, _e = (e, t, s) => /* @__PURE__ */ p(
374
+ q,
375
+ {
376
+ title: e.display,
377
+ id: `grouped-obs-${e.id}`,
378
+ open: s,
379
+ children: e.children.map(
380
+ (r, n) => k(r, n, t)
381
+ )
382
+ },
383
+ `grouped-obs-${e.id}`
384
+ ), Ae = ({
385
+ groupedData: e
386
+ }) => {
387
+ const { t } = N(), s = (r, n) => {
388
+ const o = ye(r.encounterDetails, t);
389
+ return /* @__PURE__ */ I(
390
+ q,
391
+ {
392
+ title: o,
393
+ id: `encounter-${r.encounterId}`,
394
+ open: n,
395
+ children: [
396
+ r.observations.map(
397
+ (a, i) => k(a, i, t)
398
+ ),
399
+ r.groupedObservations.map(
400
+ (a) => _e(a, t, n)
401
+ )
402
+ ]
403
+ },
404
+ `encounter-${r.encounterId}`
405
+ );
406
+ };
407
+ return /* @__PURE__ */ p(
408
+ "div",
409
+ {
410
+ id: "obs-by-encounter",
411
+ "data-testid": "obs-by-encounter-test-id",
412
+ "aria-label": "obs-by-encounter-aria-label",
413
+ children: e.map(
414
+ (r, n) => s(r, n === 0)
415
+ )
416
+ }
417
+ );
418
+ }, Ie = "_observations_kfbhq_1", De = "_title_kfbhq_12", A = {
419
+ observations: Ie,
420
+ title: De
421
+ }, Ne = (e) => ["conceptUuid", e], qe = (e, t) => ["observations", e, ...t], Le = ({ config: e }) => {
422
+ const t = e, { conceptNames: s = [], conceptUuid: r = [] } = t, n = de(/* @__PURE__ */ new Set()), o = Z(), { addNotification: a } = ee(), { t: i } = N(), u = fe({
423
+ queries: s.map((l) => ({
424
+ queryKey: Ne(l),
425
+ queryFn: () => te(l),
426
+ enabled: !!l
427
+ }))
428
+ });
429
+ C(() => {
430
+ u.forEach((l, y) => {
431
+ if (l.isError && !n.current.has(y)) {
432
+ const H = s[y];
433
+ a({
434
+ title: i("ERROR_DEFAULT_TITLE"),
435
+ message: i("ERROR_FETCHING_CONCEPT", { conceptName: H }),
436
+ type: "error"
437
+ }), n.current.add(y);
438
+ } else l.isError || n.current.delete(y);
439
+ });
440
+ }, [u, s]);
441
+ const f = S(() => u.map((l) => l.data?.uuid).filter((l) => !!l), [u]), v = S(() => [.../* @__PURE__ */ new Set([...f, ...r])], [f, r]), b = S(() => s.length === 0 ? !0 : u.every((l) => !l.isLoading), [u, s.length]), {
442
+ data: g,
443
+ isLoading: E,
444
+ isError: m
445
+ } = se({
446
+ queryKey: qe(o, v),
447
+ queryFn: () => le(o, v),
448
+ enabled: !!o && v.length > 0 && b
449
+ });
450
+ C(() => {
451
+ m && a({
452
+ title: i("ERROR_DEFAULT_TITLE"),
453
+ message: i("ERROR_FETCHING_OBSERVATIONS"),
454
+ type: "error"
455
+ });
456
+ }, [m]);
457
+ const c = S(() => {
458
+ if (!g) return [];
459
+ const l = Te(g), y = Qe(l);
460
+ return Ce(y);
461
+ }, [g]), h = [
462
+ { key: "name", header: "name" },
463
+ { key: "value", header: "value" },
464
+ { key: "form", header: "form" }
465
+ ], d = E || !b, O = m && b, x = (!g || g.entry?.length === 0 || v.length === 0) && b, L = O ? i("ERROR_FETCHING_OBSERVATIONS") : null, V = x ? i("NO_OBSERVATIONS_FOUND") : void 0, B = c.length > 0 && !d && !O;
466
+ return /* @__PURE__ */ I(
467
+ "div",
468
+ {
469
+ id: "observations",
470
+ "data-testid": "observations-test-id",
471
+ "aria-label": "observations-aria-label",
472
+ className: A.observations,
473
+ children: [
474
+ /* @__PURE__ */ p(
475
+ re,
476
+ {
477
+ id: "observations-title",
478
+ testId: "observations-title-test-id",
479
+ title: i(t.titleTranslationKey),
480
+ className: A.title,
481
+ children: /* @__PURE__ */ p("p", { children: i(t.titleTranslationKey) })
482
+ }
483
+ ),
484
+ B ? /* @__PURE__ */ p(Ae, { groupedData: c }) : /* @__PURE__ */ p(
485
+ ne,
486
+ {
487
+ headers: h,
488
+ rows: [],
489
+ ariaLabel: i("OBSERVATIONS"),
490
+ loading: d,
491
+ errorStateMessage: L,
492
+ emptyStateMessage: V
493
+ }
494
+ )
495
+ ]
496
+ }
497
+ );
498
+ };
499
+ export {
500
+ Ne as conceptUuidQueryKeys,
501
+ Le as default,
502
+ qe as observationsQueryKeys
503
+ };
@@ -1,4 +1,4 @@
1
- import { k as we, l as z, o as xt, m as B, i as q, j as y, P as Ro, n as ye, S as R, p as _, q as k, s as N, v as A, w as bs, x as ir, y as $e, z as U, A as Hn, B as Vn, D as dt, G as D, H as xs, I as cn, J as Be, K as ws, L as qt, M as zt, O as $s, R as Cs, T as $n, U as Ss, W as Nr, Y as Bt, $ as zo, Z as ks, a0 as Es, a1 as j, a2 as Ur, a3 as Ms, a4 as Ds, a5 as sr, a6 as As, a7 as Ts, a8 as zn, a9 as Fs, aa as Is, ab as Z, ac as Ps, ad as Ls } from "./index-BK9tPWzE.js";
1
+ import { P as we, U as z, V as xt, W as B, M as q, N as y, X as Ro, Y as ye, Z as R, $ as _, a0 as k, a1 as N, a2 as A, a3 as bs, a4 as ir, a5 as $e, a6 as U, a7 as Hn, a8 as Vn, a9 as dt, aa as D, ab as xs, ac as cn, ad as Be, ae as ws, af as qt, ag as zt, ah as $s, ai as Cs, aj as $n, ak as Ss, al as Nr, am as Bt, an as zo, ao as ks, ap as Es, aq as j, ar as Ur, as as Ms, at as Ds, au as sr, av as As, aw as Ts, ax as zn, ay as Fs, az as Is, aA as Z, aB as Ps, aC as Ls } from "./index-BzD6Dx9A.js";
2
2
  var Os = (e) => e != null, qs = (e) => e.filter(Os);
3
3
  function _s(e) {
4
4
  return (...t) => {