@bahmni/widgets 0.0.1-dev.151 → 0.0.1-dev.152

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,368 @@
1
+ import { jsxs as b, jsx as a, Fragment as X } from "react/jsx-runtime";
2
+ import { c as M, u as Z, o as ee, h as te, f as re, p as oe, a as ae, A as se, g as ne, b as ce, J as q, L as de, H as le, d as me, t as ie, e as H, l as ue } from "./index-CImzN7Zl.js";
3
+ import { useQueryClient as pe, useQuery as h } from "@tanstack/react-query";
4
+ import { useState as k, useMemo as g, useCallback as y } from "react";
5
+ import { useTranslation as be } from "react-i18next";
6
+ const _e = "_formsTableBody_1pd36_1", fe = "_customAccordianItem_1pd36_6", ge = "_formContent_1pd36_18", Ne = "_formDetailsContainer_1pd36_25", $e = "_observation_1pd36_30", he = "_groupContainer_1pd36_39", ye = "_rowContainer_1pd36_43", Me = "_groupLabel_1pd36_48", Le = "_rowLabel_1pd36_58", Ae = "_rowValue_1pd36_67", De = "_groupMembers_1pd36_75", Te = "_memberRow_1pd36_81", Oe = "_memberLabel_1pd36_86", Re = "_memberValue_1pd36_94", Ce = "_abnormalValue_1pd36_102", we = "_commentSection_1pd36_110", Fe = "_commentText_1pd36_116", ve = "_nestedGroup_1pd36_125", Ee = "_nestedGroupLabel_1pd36_132", Ie = "_nestedGroupMembers_1pd36_141", o = {
7
+ formsTableBody: _e,
8
+ customAccordianItem: fe,
9
+ formContent: ge,
10
+ formDetailsContainer: Ne,
11
+ observation: $e,
12
+ groupContainer: he,
13
+ rowContainer: ye,
14
+ groupLabel: Me,
15
+ rowLabel: Le,
16
+ rowValue: Ae,
17
+ groupMembers: De,
18
+ memberRow: Te,
19
+ memberLabel: Oe,
20
+ memberValue: Re,
21
+ abnormalValue: Ce,
22
+ commentSection: we,
23
+ commentText: Fe,
24
+ nestedGroup: ve,
25
+ nestedGroupLabel: Ee,
26
+ nestedGroupMembers: Ie
27
+ }, Be = "ABNORMAL", P = (e) => {
28
+ const n = e.concept?.units, d = e.concept?.lowNormal, t = e.concept?.hiNormal, i = d != null, c = t != null, l = i && c ? ` (${d} - ${t})` : i ? ` (>${d})` : c ? ` (<${t})` : "", r = e.interpretation && e.interpretation.toUpperCase() === Be;
29
+ return { units: n, rangeString: l, isAbnormal: r };
30
+ }, K = ({
31
+ member: e,
32
+ depth: n = 0,
33
+ memberIndex: d = 0,
34
+ formName: t = ""
35
+ }) => {
36
+ const i = e.groupMembers && e.groupMembers.length > 0, c = e.conceptNameToDisplay ?? e.concept?.shortName ?? e.concept?.name, l = t ? `${t}-` : "";
37
+ if (i)
38
+ return /* @__PURE__ */ b(
39
+ "div",
40
+ {
41
+ className: o.nestedGroup,
42
+ "data-testid": `${l}obs-nested-group-${c}-${d}`,
43
+ children: [
44
+ /* @__PURE__ */ a(
45
+ "div",
46
+ {
47
+ className: o.nestedGroupLabel,
48
+ "data-testid": `${l}obs-nested-group-label-${c}-${d}`,
49
+ style: { paddingLeft: `${n * 16}px` },
50
+ children: c
51
+ }
52
+ ),
53
+ /* @__PURE__ */ a(
54
+ "div",
55
+ {
56
+ className: o.nestedGroupMembers,
57
+ "data-testid": `${l}obs-nested-group-members-${c}-${d}`,
58
+ children: e.groupMembers?.map((N, L) => /* @__PURE__ */ a(
59
+ K,
60
+ {
61
+ member: N,
62
+ depth: n + 1,
63
+ memberIndex: L,
64
+ formName: t
65
+ },
66
+ `${N.concept.uuid}`
67
+ ))
68
+ }
69
+ )
70
+ ]
71
+ }
72
+ );
73
+ const { units: r, rangeString: _, isAbnormal: f } = P(e);
74
+ return /* @__PURE__ */ b(
75
+ "div",
76
+ {
77
+ className: o.memberRow,
78
+ "data-testid": `${l}obs-member-row-${c}-${d}`,
79
+ style: { paddingLeft: `${n * 16}px` },
80
+ children: [
81
+ /* @__PURE__ */ b(
82
+ "p",
83
+ {
84
+ className: M(
85
+ o.memberLabel,
86
+ f ? o.abnormalValue : ""
87
+ ),
88
+ "data-testid": `${l}obs-member-label-${c}-${d}`,
89
+ children: [
90
+ c,
91
+ _
92
+ ]
93
+ }
94
+ ),
95
+ /* @__PURE__ */ b(
96
+ "p",
97
+ {
98
+ className: M(
99
+ o.memberValue,
100
+ f ? o.abnormalValue : ""
101
+ ),
102
+ "data-testid": `${l}obs-member-value-${c}-${d}`,
103
+ children: [
104
+ e.valueAsString,
105
+ r && ` ${r}`
106
+ ]
107
+ }
108
+ )
109
+ ]
110
+ }
111
+ );
112
+ }, Ve = ({
113
+ observation: e,
114
+ index: n,
115
+ formName: d = ""
116
+ }) => {
117
+ const t = e.groupMembers && e.groupMembers.length > 0, { units: i, rangeString: c, isAbnormal: l } = P(e), r = d ? `${d}-` : "";
118
+ return /* @__PURE__ */ b(
119
+ "div",
120
+ {
121
+ className: o.observation,
122
+ "data-testid": `${r}observation-item-${e.conceptNameToDisplay}-${n}`,
123
+ children: [
124
+ /* @__PURE__ */ b(
125
+ "div",
126
+ {
127
+ className: t ? o.groupContainer : o.rowContainer,
128
+ "data-testid": `${r}observation-container-${e.conceptNameToDisplay}-${n}`,
129
+ children: [
130
+ /* @__PURE__ */ b(
131
+ "p",
132
+ {
133
+ className: M(
134
+ t ? o.groupLabel : o.rowLabel,
135
+ !t && l ? o.abnormalValue : ""
136
+ ),
137
+ "data-testid": `${r}observation-label-${e.conceptNameToDisplay}-${n}`,
138
+ children: [
139
+ e.conceptNameToDisplay,
140
+ !t && c && /* @__PURE__ */ a("span", { className: o.rangeInfo, children: c })
141
+ ]
142
+ }
143
+ ),
144
+ t ? /* @__PURE__ */ a(
145
+ "div",
146
+ {
147
+ className: o.groupMembers,
148
+ "data-testid": `${r}observation-group-members-${e.conceptNameToDisplay}-${n}`,
149
+ children: e.groupMembers?.map((_, f) => /* @__PURE__ */ a(
150
+ K,
151
+ {
152
+ member: _,
153
+ depth: 0,
154
+ memberIndex: f,
155
+ formName: d
156
+ },
157
+ `${_.concept.uuid}`
158
+ ))
159
+ }
160
+ ) : /* @__PURE__ */ b(
161
+ "p",
162
+ {
163
+ className: M(
164
+ o.rowValue,
165
+ l ? o.abnormalValue : ""
166
+ ),
167
+ "data-testid": `${r}observation-value-${e.conceptNameToDisplay}-${n}`,
168
+ children: [
169
+ e.valueAsString,
170
+ i && ` ${i}`
171
+ ]
172
+ }
173
+ )
174
+ ]
175
+ }
176
+ ),
177
+ e.comment && /* @__PURE__ */ a(
178
+ "div",
179
+ {
180
+ className: o.commentSection,
181
+ "data-testid": `${r}observation-comment-${e.conceptNameToDisplay}-${n}`,
182
+ children: /* @__PURE__ */ b("span", { className: o.commentText, children: [
183
+ e.comment,
184
+ e.providers?.[0]?.name && ` - by ${e.providers[0].name}`
185
+ ] })
186
+ }
187
+ )
188
+ ]
189
+ },
190
+ `${e.concept.uuid}-${n}`
191
+ );
192
+ }, Pe = ({
193
+ episodeOfCareUuids: e,
194
+ encounterUuids: n,
195
+ config: d
196
+ }) => {
197
+ const { t } = be(), i = Z(), [c, l] = k(!1), [r, _] = k(null), f = d?.numberOfVisits, N = ee(
198
+ e,
199
+ n
200
+ ), L = pe(), {
201
+ data: A = [],
202
+ isLoading: R,
203
+ isError: C,
204
+ error: j,
205
+ refetch: Q
206
+ } = h({
207
+ queryKey: ["forms", i, e],
208
+ queryFn: () => te(i, void 0, f),
209
+ enabled: !!i && !N
210
+ }), w = g(() => !n || n.length === 0 ? A : A.filter(
211
+ (s) => n.includes(s.encounterUuid)
212
+ ), [A, n]), { data: F = [] } = h({
213
+ queryKey: ["observationForms"],
214
+ queryFn: () => re()
215
+ }), v = y(
216
+ (s) => F.find((m) => m.name === s)?.uuid,
217
+ [F]
218
+ ), D = g(() => {
219
+ if (r)
220
+ return v(r.formName);
221
+ }, [r, v]), {
222
+ data: Se,
223
+ isLoading: z,
224
+ error: E
225
+ } = h({
226
+ queryKey: ["formMetadata", D],
227
+ queryFn: () => oe(D),
228
+ enabled: !!D && c
229
+ }), {
230
+ data: T,
231
+ isLoading: J,
232
+ error: I
233
+ } = h({
234
+ queryKey: ["formsEncounter", r?.encounterUuid],
235
+ queryFn: () => ae(r.encounterUuid, !0),
236
+ enabled: !!r?.encounterUuid && c
237
+ });
238
+ se(
239
+ (s) => {
240
+ s.patientUUID === i && s.updatedConcepts.size > 0 && (Q(), L.invalidateQueries({ queryKey: ["formsEncounter"] }));
241
+ },
242
+ [i]
243
+ );
244
+ const B = g(() => !T?.observations || !r?.formName ? [] : T.observations.filter(
245
+ (p) => "formFieldPath" in p && typeof p.formFieldPath == "string" && p.formFieldPath.includes(r.formName)
246
+ ), [T?.observations, r?.formName]), V = g(
247
+ () => [
248
+ { key: "recordedOn", header: t("FORM_RECORDED_ON") },
249
+ { key: "recordedBy", header: t("FORM_RECORDED_BY") }
250
+ ],
251
+ [t]
252
+ ), x = g(
253
+ () => [
254
+ { key: "recordedOn", sortable: !0 },
255
+ { key: "recordedBy", sortable: !0 }
256
+ ],
257
+ []
258
+ ), S = g(() => {
259
+ const s = w.reduce(
260
+ (m, u) => {
261
+ const $ = u.formName;
262
+ m[$] ??= [];
263
+ const O = u.providers.map((W) => W.providerName).filter(Boolean).join(", ");
264
+ return m[$].push({
265
+ id: u.encounterUuid,
266
+ formName: u.formName,
267
+ recordedOn: ne(u.encounterDateTime, t, ue).formattedResult,
268
+ recordedBy: O ?? "--",
269
+ encounterDateTime: u.encounterDateTime,
270
+ encounterUuid: u.encounterUuid
271
+ }), m;
272
+ },
273
+ {}
274
+ );
275
+ return Object.entries(s).map(
276
+ ([m, u]) => ({
277
+ formName: m,
278
+ records: u.sort(
279
+ ($, O) => O.encounterDateTime - $.encounterDateTime
280
+ )
281
+ })
282
+ ).sort((m, u) => m.formName.localeCompare(u.formName));
283
+ }, [w, t]), G = y((s) => {
284
+ _(s), l(!0);
285
+ }, []), Y = y(() => {
286
+ l(!1), _(null);
287
+ }, []), U = y(
288
+ (s, p) => {
289
+ switch (p) {
290
+ case "recordedOn":
291
+ return /* @__PURE__ */ a(ce, { onClick: () => G(s), children: s.recordedOn });
292
+ case "recordedBy":
293
+ return s.recordedBy;
294
+ default:
295
+ return null;
296
+ }
297
+ },
298
+ [G]
299
+ );
300
+ return /* @__PURE__ */ b(X, { children: [
301
+ /* @__PURE__ */ a("div", { "data-testid": "forms-table", children: R || C || S.length === 0 || N ? /* @__PURE__ */ a(
302
+ q,
303
+ {
304
+ headers: V,
305
+ ariaLabel: t("FORMS_HEADING"),
306
+ rows: [],
307
+ loading: R,
308
+ errorStateMessage: C ? j?.message : void 0,
309
+ emptyStateMessage: t("FORMS_UNAVAILABLE"),
310
+ renderCell: U,
311
+ className: o.formsTableBody,
312
+ dataTestId: "forms-table"
313
+ }
314
+ ) : /* @__PURE__ */ a(de, { align: "start", children: S.map((s, p) => {
315
+ const { formName: m, records: u } = s;
316
+ return /* @__PURE__ */ a(
317
+ le,
318
+ {
319
+ title: m,
320
+ className: o.customAccordianItem,
321
+ testId: `accordian-title-${m}`,
322
+ open: p === 0,
323
+ children: /* @__PURE__ */ a(
324
+ q,
325
+ {
326
+ headers: V,
327
+ ariaLabel: t("FORMS_HEADING"),
328
+ rows: u,
329
+ loading: !1,
330
+ errorStateMessage: "",
331
+ sortable: x,
332
+ emptyStateMessage: t("FORMS_UNAVAILABLE"),
333
+ renderCell: U,
334
+ className: o.formsTableBody,
335
+ dataTestId: `forms-table-${m}`
336
+ }
337
+ )
338
+ },
339
+ m
340
+ );
341
+ }) }) }),
342
+ c && r && /* @__PURE__ */ a(
343
+ me,
344
+ {
345
+ id: "modalIdForActionAreaLayout",
346
+ open: c,
347
+ onRequestClose: Y,
348
+ modalHeading: r.formName,
349
+ modalLabel: `${r.recordedOn} | ${r.recordedBy}`,
350
+ passiveModal: !0,
351
+ size: "md",
352
+ testId: "form-details-modal",
353
+ children: /* @__PURE__ */ a("div", { className: o.formContent, children: z || J ? /* @__PURE__ */ a(ie, { width: "100%", lineCount: 3 }) : E ? /* @__PURE__ */ a("div", { children: H(E).message ?? t("ERROR_FETCHING_FORM_METADATA") }) : I ? /* @__PURE__ */ a("div", { children: H(I).message ?? t("ERROR_FETCHING_FORM_DATA") }) : B.length > 0 ? /* @__PURE__ */ a("div", { className: o.formDetailsContainer, children: B.map((s, p) => /* @__PURE__ */ a(
354
+ Ve,
355
+ {
356
+ observation: s,
357
+ index: p,
358
+ formName: r.formName
359
+ },
360
+ `${s.concept.uuid}`
361
+ )) }) : /* @__PURE__ */ a("div", { children: t("NO_FORM_DATA_AVAILABLE") }) })
362
+ }
363
+ )
364
+ ] });
365
+ };
366
+ export {
367
+ Pe as default
368
+ };
@@ -0,0 +1,172 @@
1
+ import { jsx as d, jsxs as N } from "react/jsx-runtime";
2
+ import { i as k, V as S, j as q, D as w, _ as M, x as K, k as Q, u as G, m as j, n as H, r as P, A as J, q as z, s as Y, v as x, O as W, J as X } from "./index-CImzN7Zl.js";
3
+ import { useQueries as Z, useQuery as ee } from "@tanstack/react-query";
4
+ import { useRef as te, useEffect as $, useMemo as h } from "react";
5
+ import { useTranslation as C } from "react-i18next";
6
+ const U = (t, c, n, l, o) => {
7
+ const s = q(t, c), r = s.value, a = w(r);
8
+ let i = r;
9
+ a === "Image" && (i = /* @__PURE__ */ d(K, { imageSrc: r, alt: r, id: `${r}-img` })), a === "Video" && (i = /* @__PURE__ */ d(Q, { id: `${r}-video`, videoSrc: r }));
10
+ const u = o("OBSERVATIONS_RECORDED_BY", {
11
+ provider: s.provider
12
+ }), b = t.display, m = t.observationValue?.isAbnormal ? "abnormal-obs" : "obs", f = l ? `${l}-${m}-${b}-${n}-${c}` : `${m}-${b}-${n}-${c}`;
13
+ return /* @__PURE__ */ d(
14
+ M,
15
+ {
16
+ header: s.header,
17
+ value: i,
18
+ info: u,
19
+ id: f,
20
+ testId: f,
21
+ ariaLabel: f
22
+ },
23
+ `obs-${t.id}`
24
+ );
25
+ }, se = (t, c, n, l, o, s) => /* @__PURE__ */ d(
26
+ S,
27
+ {
28
+ title: t.display,
29
+ id: `grouped-obs-${t.display}-${l}`,
30
+ open: n,
31
+ children: t.members?.map(
32
+ (r, a) => U(r, a, o, s, c)
33
+ )
34
+ },
35
+ `grouped-obs-${t.id}`
36
+ ), oe = ({
37
+ groupedData: t,
38
+ title: c = ""
39
+ }) => {
40
+ const { t: n } = C(), l = (o, s, r) => {
41
+ const a = k(o.encounterDetails, n);
42
+ return /* @__PURE__ */ N(
43
+ S,
44
+ {
45
+ title: a,
46
+ id: `encounter-${o.encounterId}`,
47
+ open: s,
48
+ children: [
49
+ o.observations.map(
50
+ (i, u) => U(i, u, r, c, n)
51
+ ),
52
+ o.groupedObservations.map(
53
+ (i, u) => se(
54
+ i,
55
+ n,
56
+ s,
57
+ u,
58
+ r,
59
+ c
60
+ )
61
+ )
62
+ ]
63
+ },
64
+ `encounter-${o.encounterId}`
65
+ );
66
+ };
67
+ return /* @__PURE__ */ d(
68
+ "div",
69
+ {
70
+ id: "obs-by-encounter",
71
+ "data-testid": "obs-by-encounter-test-id",
72
+ "aria-label": "obs-by-encounter-aria-label",
73
+ children: t.map(
74
+ (o, s) => l(o, s === 0, s)
75
+ )
76
+ }
77
+ );
78
+ }, re = "_observations_kfbhq_1", ae = "_title_kfbhq_12", D = {
79
+ observations: re,
80
+ title: ae
81
+ }, ne = (t) => ["conceptUuid", t], ie = (t, c) => ["observations", t, ...c], me = ({ config: t }) => {
82
+ const c = t, { conceptNames: n = [], conceptUuid: l = [] } = c, o = te(/* @__PURE__ */ new Set()), s = G(), { addNotification: r } = j(), { t: a } = C(), i = Z({
83
+ queries: n.map((e) => ({
84
+ queryKey: ne(e),
85
+ queryFn: () => H(e),
86
+ enabled: !!e
87
+ }))
88
+ });
89
+ $(() => {
90
+ i.forEach((e, p) => {
91
+ if (e.isError && !o.current.has(p)) {
92
+ const g = n[p];
93
+ r({
94
+ title: a("ERROR_DEFAULT_TITLE"),
95
+ message: a("ERROR_FETCHING_CONCEPT", { conceptName: g }),
96
+ type: "error"
97
+ }), o.current.add(p);
98
+ } else e.isError || o.current.delete(p);
99
+ });
100
+ }, [i, n]);
101
+ const u = h(() => i.map((e) => e.data?.uuid).filter((e) => !!e), [i]), b = h(() => [.../* @__PURE__ */ new Set([...u, ...l])], [u, l]), v = h(() => n.length === 0 ? !0 : i.every((e) => !e.isLoading), [i, n.length]), {
102
+ data: m,
103
+ isLoading: f,
104
+ isError: O,
105
+ refetch: R
106
+ } = ee({
107
+ queryKey: ie(s, b),
108
+ queryFn: () => P(s, b),
109
+ enabled: !!s && b.length > 0 && v
110
+ });
111
+ J(
112
+ (e) => {
113
+ e.patientUUID === s && e.updatedConcepts.size > 0 && [...e.updatedConcepts.keys()].some(
114
+ (g) => b.includes(g)
115
+ ) && R();
116
+ },
117
+ [s, R]
118
+ ), $(() => {
119
+ O && r({
120
+ title: a("ERROR_DEFAULT_TITLE"),
121
+ message: a("ERROR_FETCHING_OBSERVATIONS"),
122
+ type: "error"
123
+ });
124
+ }, [O]);
125
+ const T = h(() => {
126
+ if (!m) return [];
127
+ const e = z(m), p = Y(e);
128
+ return x(p);
129
+ }, [m]), A = [
130
+ { key: "name", header: "name" },
131
+ { key: "value", header: "value" },
132
+ { key: "form", header: "form" }
133
+ ], _ = f || !v, I = O && v, B = (!m || m.entry?.length === 0 || b.length === 0) && v, F = I ? a("ERROR_FETCHING_OBSERVATIONS") : null, L = B ? a("NO_OBSERVATIONS_FOUND") : void 0, V = T.length > 0 && !_ && !I, E = c.titleTranslationKey, y = E ? a(E) : "";
134
+ return /* @__PURE__ */ N(
135
+ "div",
136
+ {
137
+ id: "observations",
138
+ "data-testid": E ? `observations-${y}` : "observations",
139
+ "aria-label": "observations-aria-label",
140
+ className: D.observations,
141
+ children: [
142
+ /* @__PURE__ */ d(
143
+ W,
144
+ {
145
+ id: "observations-title",
146
+ testId: E ? `observations-title-${y}` : "observations-title",
147
+ title: y,
148
+ className: D.title,
149
+ children: /* @__PURE__ */ d("p", { children: y })
150
+ }
151
+ ),
152
+ V ? /* @__PURE__ */ d(oe, { groupedData: T, title: y }) : /* @__PURE__ */ d(
153
+ X,
154
+ {
155
+ headers: A,
156
+ rows: [],
157
+ ariaLabel: a("OBSERVATIONS"),
158
+ loading: _,
159
+ errorStateMessage: F,
160
+ emptyStateMessage: L,
161
+ dataTestId: "observations-table"
162
+ }
163
+ )
164
+ ]
165
+ }
166
+ );
167
+ };
168
+ export {
169
+ ne as conceptUuidQueryKeys,
170
+ me as default,
171
+ ie as observationsQueryKeys
172
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"FormsTable.d.ts","sourceRoot":"","sources":["../../src/forms/FormsTable.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAShD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAoRrC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"FormsTable.d.ts","sourceRoot":"","sources":["../../src/forms/FormsTable.tsx"],"names":[],"mappings":"AA0BA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAShD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAqSrC,CAAC;AAEF,eAAe,UAAU,CAAC"}