@bahmni/admin-app 0.0.1-dev.451 → 0.0.1-dev.452

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