@bahmni/reports-app 0.0.1-dev.456 → 0.0.1-dev.458

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,387 @@
1
+ import { jsx as n, jsxs as h, Fragment as _e } from "react/jsx-runtime";
2
+ import { u as pe, a as Ee, z as ge, i as Ne, Q as Ce, w as Ie, T as v, b as Ae, c as be, K as Le, h as fe, O as ye, d as De, U as j, J as ve, L as we, I as Oe, e as Se, N as Ue, X as J, G as ee } from "./index-CTY4F0kA.js";
3
+ import { useQuery as Me } from "@tanstack/react-query";
4
+ import { useState as T, useRef as Re, useEffect as E, useMemo as g, useCallback as _ } from "react";
5
+ const ke = "DocumentsTable-module_documentsTableBody__6iR3w", $e = "DocumentsTable-module_viewAttachmentsLink__aQ1on", He = "DocumentsTable-module_documentViewerContainer__F5m8D", Be = "DocumentsTable-module_printContainer__rtarJ", Ge = "DocumentsTable-module_attachmentItem__17KA7", ze = "DocumentsTable-module_attachmentCounter__WFiI3", Ve = "DocumentsTable-module_attachmentError__RI4U2", We = "DocumentsTable-module_documentIframe__ptq5I", Fe = "DocumentsTable-module_attachmentContent__IaCEe", xe = "DocumentsTable-module_attachmentLoading__FAR6p", qe = "DocumentsTable-module_hiddenWhileLoading__IxocW", Ke = "DocumentsTable-module_documentImage__KQVgS", Pe = "DocumentsTable-module_header__345GY", Qe = "DocumentsTable-module_documentTypeCell__uWGM8", je = "DocumentsTable-module_printAllButton__IVYUW", Je = "DocumentsTable-module_attachmentHeader__yI2xn", o = {
6
+ documentsTableBody: ke,
7
+ viewAttachmentsLink: $e,
8
+ documentViewerContainer: He,
9
+ printContainer: Be,
10
+ attachmentItem: Ge,
11
+ attachmentCounter: ze,
12
+ attachmentError: Ve,
13
+ documentIframe: We,
14
+ attachmentContent: Fe,
15
+ attachmentLoading: xe,
16
+ hiddenWhileLoading: qe,
17
+ documentImage: Ke,
18
+ header: Pe,
19
+ documentTypeCell: Qe,
20
+ printAllButton: je,
21
+ attachmentHeader: Je
22
+ }, Xe = "startConsultation", Ye = "add", Ze = "documents", X = "document-print-container", Y = () => /* @__PURE__ */ n(ee, {}), et = /* @__PURE__ */ new Set([
23
+ "ArrowUp",
24
+ "ArrowDown",
25
+ "PageUp",
26
+ "PageDown",
27
+ "Home",
28
+ "End",
29
+ " "
30
+ ]), tt = 15e3, nt = [
31
+ "documentType",
32
+ "documentIdentifier",
33
+ "attachments",
34
+ "uploadedOn",
35
+ "uploadedBy"
36
+ ], at = /\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i, Z = (l) => l.attachments.length > 0 ? l.attachments : l.documentUrl ? [{ url: l.documentUrl, contentType: l.contentType }] : [], lt = ({ config: l, encounterUuids: H }) => {
37
+ const [m, B] = T(!1), [r, G] = T(
38
+ null
39
+ ), [b, w] = T(
40
+ /* @__PURE__ */ new Set()
41
+ ), [L, O] = T(
42
+ /* @__PURE__ */ new Set()
43
+ ), C = Re(null), [S, z] = T(
44
+ null
45
+ ), V = S !== null;
46
+ E(() => () => C.current?.abort(), []);
47
+ const N = pe(), { t: a } = Ee(), { addNotification: f } = ge(), c = g(
48
+ () => l?.actions?.find(
49
+ (e) => e.type === Ye
50
+ ),
51
+ [l?.actions]
52
+ ), te = Ne(c?.requiredPrivilege), ne = !!c && te, ae = Number(l?.pageSize) || 5, [U, M] = T(1), [I, oe] = T(ae), [re, R] = T(void 0), W = _((e) => {
53
+ G(e), B(!0);
54
+ }, []), de = _(() => {
55
+ C.current?.abort(), O(/* @__PURE__ */ new Set()), B(!1), G(null), w(/* @__PURE__ */ new Set());
56
+ }, []), F = _((e) => {
57
+ O((t) => new Set(t).add(e));
58
+ }, []), x = _((e) => {
59
+ w((t) => new Set(t).add(e));
60
+ }, []), se = _(() => {
61
+ c && globalThis.dispatchEvent(
62
+ new CustomEvent(Xe, {
63
+ detail: {
64
+ encounterType: c.encounterType,
65
+ editOnly: c.editOnly ?? Ze,
66
+ ...c.editTitle ? { editTitle: c.editTitle } : {}
67
+ }
68
+ })
69
+ );
70
+ }, [c]), { data: A, isLoading: le, isError: k, error: $, refetch: q } = Me({
71
+ queryKey: [
72
+ "documents",
73
+ N,
74
+ H,
75
+ U,
76
+ I
77
+ ],
78
+ enabled: !!N,
79
+ queryFn: () => Ce(
80
+ N,
81
+ H,
82
+ I,
83
+ U
84
+ )
85
+ });
86
+ Ie(
87
+ (e) => {
88
+ e.patientUUID === N && e.updatedResources.documents && q();
89
+ },
90
+ [N, q]
91
+ ), E(() => {
92
+ A && R(A.total);
93
+ }, [A]), E(() => {
94
+ M(1), R(void 0);
95
+ }, [N]), E(() => {
96
+ k && f({
97
+ title: a("ERROR_DEFAULT_TITLE"),
98
+ message: $?.message ?? "",
99
+ type: "error"
100
+ });
101
+ }, [k, $, f, a]), E(() => {
102
+ const e = new AbortController();
103
+ return (async () => {
104
+ if (!m || !r) return;
105
+ const t = /* @__PURE__ */ new Set(), d = Z(r);
106
+ for (let s = 0; s < d.length; s++) {
107
+ const u = v(d[s].url);
108
+ try {
109
+ (await fetch(u, {
110
+ method: "HEAD",
111
+ signal: e.signal
112
+ })).ok || t.add(s);
113
+ } catch (p) {
114
+ p instanceof Error && p.name !== "AbortError" && t.add(s);
115
+ }
116
+ }
117
+ e.signal.aborted || w(t);
118
+ })(), () => e.abort();
119
+ }, [m, r]), E(() => {
120
+ if (!m || !r) return;
121
+ const e = document.querySelector(
122
+ '[data-testid="document-view-modal"] .cds--modal-content'
123
+ );
124
+ if (!e) return;
125
+ let t = !1;
126
+ const d = () => {
127
+ t = !0;
128
+ }, s = (D) => {
129
+ D.target === e && d();
130
+ }, u = (D) => {
131
+ const Te = D.target;
132
+ et.has(D.key) && !Te?.closest("button, input, textarea, select, a") && d();
133
+ }, p = () => {
134
+ !t && e.scrollTop !== 0 && (e.scrollTop = 0);
135
+ };
136
+ return e.addEventListener("wheel", d, { passive: !0 }), e.addEventListener("touchmove", d, { passive: !0 }), e.addEventListener("mousedown", s), e.addEventListener("keydown", u), e.addEventListener("scroll", p), () => {
137
+ e.removeEventListener("wheel", d), e.removeEventListener("touchmove", d), e.removeEventListener("mousedown", s), e.removeEventListener("keydown", u), e.removeEventListener("scroll", p);
138
+ };
139
+ }, [m, r]);
140
+ const ie = _(
141
+ (e, t) => {
142
+ t !== I ? (oe(t), M(1), R(void 0)) : M(e);
143
+ },
144
+ [I]
145
+ ), y = g(
146
+ () => l?.fields ?? nt,
147
+ [l?.fields]
148
+ ), ce = g(() => [...A?.documents ?? []].sort((e, t) => !e.uploadedOn && !t.uploadedOn ? 0 : e.uploadedOn ? t.uploadedOn ? new Date(t.uploadedOn).getTime() - new Date(e.uploadedOn).getTime() : -1 : 1), [A]), me = g(() => Ae(y, a), [y, a]), ue = g(
149
+ () => y.map((e) => ({
150
+ key: e,
151
+ sortable: e !== "attachments"
152
+ })),
153
+ [y]
154
+ ), i = g(
155
+ () => r ? Z(r) : [],
156
+ [r]
157
+ ), K = i.every(
158
+ (e, t) => L.has(t) || b.has(t) || v(e.url) === "#"
159
+ );
160
+ E(() => {
161
+ if (!m || i.length === 0) return;
162
+ const e = setTimeout(
163
+ () => O(new Set(i.keys())),
164
+ tt
165
+ );
166
+ return () => clearTimeout(e);
167
+ }, [m, i]);
168
+ const P = _(
169
+ async (e, t) => {
170
+ if (!r || C.current) return;
171
+ const d = new AbortController(), { signal: s } = d;
172
+ C.current = d, z(t);
173
+ const u = document.getElementById(X);
174
+ try {
175
+ await be(
176
+ e,
177
+ r.documentIdentifier,
178
+ { container: u, signal: s }
179
+ );
180
+ } catch {
181
+ s.aborted || f({
182
+ title: a("ERROR_DEFAULT_TITLE"),
183
+ message: a("DOCUMENTS_ERROR_LOADING_ATTACHMENT"),
184
+ type: "error"
185
+ });
186
+ } finally {
187
+ C.current = null, z(null);
188
+ }
189
+ },
190
+ [r, f, a]
191
+ ), Q = g(
192
+ () => i.filter(
193
+ (e, t) => v(e.url) !== "#" && !b.has(t)
194
+ ),
195
+ [i, b]
196
+ ), he = _(
197
+ (e, t) => {
198
+ switch (t) {
199
+ case "documentIdentifier":
200
+ return /* @__PURE__ */ n("span", { children: e.documentIdentifier?.trim() || "-" });
201
+ case "documentType":
202
+ return /* @__PURE__ */ h("div", { className: o.documentTypeCell, children: [
203
+ /* @__PURE__ */ n("span", { children: e.documentType ?? a("DOCUMENTS_NOT_AVAILABLE") }),
204
+ e.description && /* @__PURE__ */ n(
205
+ ye,
206
+ {
207
+ iconName: "fa-file-lines",
208
+ content: e.description,
209
+ ariaLabel: e.description,
210
+ testId: `document-notes-${e.id}`
211
+ }
212
+ )
213
+ ] });
214
+ case "uploadedOn":
215
+ return fe(
216
+ e.uploadedOn,
217
+ a,
218
+ !0
219
+ ).formattedResult || a("DOCUMENTS_NOT_AVAILABLE");
220
+ case "uploadedBy":
221
+ return e.uploadedBy ?? a("DOCUMENTS_NOT_AVAILABLE");
222
+ case "attachments":
223
+ return e.attachments.length > 0 || e.documentUrl ? /* @__PURE__ */ n(
224
+ Le,
225
+ {
226
+ onClick: () => W(e),
227
+ className: o.viewAttachmentsLink,
228
+ "data-testid": `view-attachments-${e.id}`,
229
+ children: a("DOCUMENTS_VIEW_ATTACHMENTS")
230
+ }
231
+ ) : "--";
232
+ default:
233
+ return null;
234
+ }
235
+ },
236
+ [W, a]
237
+ );
238
+ return /* @__PURE__ */ h(_e, { children: [
239
+ ne && /* @__PURE__ */ h(De, { className: o.header, testId: "documents-header", children: [
240
+ /* @__PURE__ */ n("p", { children: a("DOCUMENTS_TABLE_HEADING") }),
241
+ /* @__PURE__ */ n(
242
+ j,
243
+ {
244
+ autoAlign: !0,
245
+ size: "lg",
246
+ kind: "ghost",
247
+ label: a(c.label),
248
+ testId: "documents-add-button",
249
+ onClick: se,
250
+ children: /* @__PURE__ */ n(ve, { id: "documents-add-icon", name: "fa-plus", size: we.LG })
251
+ }
252
+ )
253
+ ] }),
254
+ /* @__PURE__ */ n("div", { "data-testid": "documents-table", children: /* @__PURE__ */ n(
255
+ Oe,
256
+ {
257
+ headers: me,
258
+ ariaLabel: a("DOCUMENTS_TABLE_HEADING"),
259
+ rows: ce,
260
+ loading: le,
261
+ errorStateMessage: k ? $?.message : null,
262
+ sortable: ue,
263
+ emptyStateMessage: a("DOCUMENTS_NO_RECORDS"),
264
+ renderCell: he,
265
+ className: o.documentsTableBody,
266
+ dataTestId: "documents-table",
267
+ pageSize: I,
268
+ totalItems: re,
269
+ page: U,
270
+ onPageChange: ie
271
+ }
272
+ ) }),
273
+ m && r && /* @__PURE__ */ n(
274
+ Se,
275
+ {
276
+ id: "modalIdForActionAreaLayout",
277
+ portalId: "main-display-area",
278
+ open: m,
279
+ onRequestClose: de,
280
+ modalHeading: r.documentIdentifier,
281
+ passiveModal: !0,
282
+ size: "lg",
283
+ testId: "document-view-modal",
284
+ children: /* @__PURE__ */ h("div", { className: o.documentViewerContainer, children: [
285
+ Q.length > 1 && /* @__PURE__ */ n(
286
+ Ue,
287
+ {
288
+ kind: "tertiary",
289
+ size: "sm",
290
+ className: o.printAllButton,
291
+ renderIcon: S === "all" ? Y : J,
292
+ disabled: V || !K,
293
+ testId: "print-all-attachments",
294
+ onClick: () => P(Q, "all"),
295
+ children: a("DOCUMENTS_PRINT_ALL")
296
+ }
297
+ ),
298
+ i.map((e, t) => {
299
+ const d = v(e.url), s = e.contentType?.toLowerCase().includes("pdf"), u = (e.contentType?.toLowerCase().includes("image") ?? !1) || at.test(e.url ?? ""), p = b.has(t);
300
+ return d === "#" || p ? /* @__PURE__ */ h(
301
+ "div",
302
+ {
303
+ className: o.attachmentError,
304
+ "data-testid": `attachment-error-${t}`,
305
+ children: [
306
+ i.length > 1 && /* @__PURE__ */ n("p", { className: o.attachmentCounter, children: a("DOCUMENTS_ATTACHMENT_COUNTER", {
307
+ current: t + 1,
308
+ total: i.length
309
+ }) }),
310
+ /* @__PURE__ */ n("p", { children: a("DOCUMENTS_ERROR_LOADING_ATTACHMENT") })
311
+ ]
312
+ },
313
+ `${r.id}-${e.url}`
314
+ ) : /* @__PURE__ */ h(
315
+ "div",
316
+ {
317
+ className: o.attachmentItem,
318
+ "data-testid": `attachment-item-${t}`,
319
+ children: [
320
+ /* @__PURE__ */ h("div", { className: o.attachmentHeader, children: [
321
+ i.length > 1 ? /* @__PURE__ */ n("p", { className: o.attachmentCounter, children: a("DOCUMENTS_ATTACHMENT_COUNTER", {
322
+ current: t + 1,
323
+ total: i.length
324
+ }) }) : /* @__PURE__ */ n("span", {}),
325
+ /* @__PURE__ */ n(
326
+ j,
327
+ {
328
+ kind: "ghost",
329
+ size: "sm",
330
+ label: a("DOCUMENTS_PRINT_ATTACHMENT", {
331
+ index: t + 1
332
+ }),
333
+ disabled: V || !K,
334
+ testId: `print-attachment-${t}`,
335
+ onClick: () => P([e], t),
336
+ children: S === t ? /* @__PURE__ */ n(Y, {}) : /* @__PURE__ */ n(J, {})
337
+ }
338
+ )
339
+ ] }),
340
+ /* @__PURE__ */ h("div", { className: o.attachmentContent, children: [
341
+ !L.has(t) && /* @__PURE__ */ n(
342
+ "div",
343
+ {
344
+ className: o.attachmentLoading,
345
+ "data-testid": `attachment-loading-${t}`,
346
+ children: /* @__PURE__ */ n(
347
+ ee,
348
+ {
349
+ description: a("DOCUMENTS_LOADING_ATTACHMENT")
350
+ }
351
+ )
352
+ }
353
+ ),
354
+ u ? /* @__PURE__ */ n(
355
+ "img",
356
+ {
357
+ src: d,
358
+ alt: r.documentIdentifier,
359
+ className: `${o.documentImage} ${L.has(t) ? "" : o.hiddenWhileLoading}`,
360
+ onLoad: () => F(t),
361
+ onError: () => x(t)
362
+ }
363
+ ) : /* @__PURE__ */ n(
364
+ "iframe",
365
+ {
366
+ src: s ? `${d}#toolbar=0` : d,
367
+ className: `${o.documentIframe} ${L.has(t) ? "" : o.hiddenWhileLoading}`,
368
+ title: r.documentIdentifier,
369
+ onLoad: () => F(t),
370
+ onError: () => x(t)
371
+ }
372
+ )
373
+ ] })
374
+ ]
375
+ },
376
+ `${r.id}-${e.url}`
377
+ );
378
+ }),
379
+ /* @__PURE__ */ n("div", { id: X, className: o.printContainer })
380
+ ] })
381
+ }
382
+ )
383
+ ] });
384
+ };
385
+ export {
386
+ lt as default
387
+ };