@bahmni/widgets 0.0.1-dev.348 → 0.0.1-dev.350

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.
@@ -1,233 +0,0 @@
1
- import { jsx as i, jsxs as oe, Fragment as te } from "react/jsx-runtime";
2
- import { u as se, $ as ae, H as ne, j as de, V as ie, w as ce, n as le, e as me, b as U, R as ue, B as fe, q as k, T as ye, c as be, F as pe, O as ge } from "./index-BbuEus1P.js";
3
- import { useQueryClient as he, useQuery as b } from "@tanstack/react-query";
4
- import { useState as H, useMemo as d, useCallback as p } from "react";
5
- import { useTranslation as Fe } from "react-i18next";
6
- const Ne = "FormsTable-module_formsTableBody__SvGha", Oe = "FormsTable-module_customAccordianItem__isszs", O = {
7
- formsTableBody: Ne,
8
- customAccordianItem: Oe
9
- }, Ae = ({
10
- episodeOfCareUuids: v,
11
- encounterUuids: l,
12
- config: j
13
- }) => {
14
- const { t: n } = Fe(), m = se(), [f, E] = H(!1), [a, M] = H(null), {
15
- numberOfVisits: w,
16
- hideThumbnail: V = !1,
17
- forms: y
18
- } = j ?? {}, B = ae(
19
- v,
20
- l
21
- ), $ = he(), {
22
- data: I = [],
23
- isLoading: A,
24
- isError: D,
25
- error: x,
26
- refetch: K
27
- } = b({
28
- queryKey: ["forms", m, v],
29
- queryFn: () => ne(m, void 0, w),
30
- enabled: !!m && !B
31
- }), T = d(() => {
32
- let e = I;
33
- return l && l.length > 0 && (e = e.filter(
34
- (o) => l.includes(o.encounterUuid)
35
- )), Array.isArray(y) && y.length > 0 && (e = e.filter(
36
- (o) => y.some((r) => r.toLowerCase() === o.formName.toLowerCase())
37
- )), e;
38
- }, [I, l, y]), { data: R = [] } = b({
39
- queryKey: ["observationForms"],
40
- queryFn: () => de()
41
- }), _ = p(
42
- (e) => R.find((r) => r.name === e)?.uuid,
43
- [R]
44
- ), g = d(() => {
45
- if (a)
46
- return _(a.formName);
47
- }, [a, _]), {
48
- data: c,
49
- isLoading: P,
50
- isError: z,
51
- error: h
52
- } = b({
53
- queryKey: ["formMetadata", g],
54
- queryFn: () => ie(g),
55
- enabled: !!g && f
56
- }), {
57
- data: F,
58
- isLoading: G,
59
- isError: Q,
60
- error: N
61
- } = b({
62
- queryKey: ["formsEncounterFHIR", a?.encounterUuid],
63
- queryFn: () => ce(a.encounterUuid),
64
- enabled: !!a?.encounterUuid && f
65
- });
66
- le(
67
- (e) => {
68
- e.patientUUID === m && e.updatedConcepts.size > 0 && (K(), $.invalidateQueries({ queryKey: ["formsEncounterFHIR"] }));
69
- },
70
- [m]
71
- );
72
- const Y = d(() => !F?.entry || !a?.formName ? [] : F.entry.filter((o) => o.resource?.resourceType === "Observation").map((o) => o.resource).filter((o) => {
73
- const r = me(o);
74
- return !r || r.includes(a.formName);
75
- }), [F, a?.formName]), J = d(() => {
76
- if (!c?.schema) return;
77
- const e = [], o = (r) => {
78
- (r ?? []).forEach((t) => {
79
- const s = t;
80
- s.id != null && e.push(String(s.id)), s.controls && o(s.controls);
81
- });
82
- };
83
- return o(
84
- c.schema.controls ?? []
85
- ), e.length > 0 ? e : void 0;
86
- }, [c]), W = d(() => {
87
- if (!c?.schema) return;
88
- const e = {}, o = (r, t) => {
89
- for (const s of r)
90
- if (s.type === "section") {
91
- const u = s.label?.value ?? "Section";
92
- o(s.controls ?? [], u);
93
- } else
94
- s.id != null && t && (e[String(s.id)] = t), s.controls && o(s.controls, t);
95
- };
96
- return o(
97
- c.schema.controls ?? [],
98
- null
99
- ), Object.keys(e).length > 0 ? e : void 0;
100
- }, [c]), X = d(() => {
101
- if (h)
102
- return U(h).message;
103
- if (N)
104
- return U(N).message;
105
- }, [h, N]), L = d(
106
- () => [
107
- { key: "recordedOn", header: n("RECORDED_ON") },
108
- { key: "recordedBy", header: n("RECORDED_BY") }
109
- ],
110
- [n]
111
- ), Z = d(
112
- () => [
113
- { key: "recordedOn", sortable: !0 },
114
- { key: "recordedBy", sortable: !0 }
115
- ],
116
- []
117
- ), C = d(() => {
118
- const e = T.reduce(
119
- (r, t) => {
120
- const s = t.formName;
121
- r[s] ??= [];
122
- const u = t.providers.map((re) => re.providerName).filter(Boolean).join(", ");
123
- return r[s].push({
124
- id: t.encounterUuid,
125
- formName: t.formName,
126
- recordedOn: ue(t.encounterDateTime, n, !0).formattedResult,
127
- recordedBy: u ?? "--",
128
- encounterDateTime: t.encounterDateTime,
129
- encounterUuid: t.encounterUuid
130
- }), r;
131
- },
132
- {}
133
- );
134
- return Object.entries(e).map(
135
- ([r, t]) => ({
136
- formName: r,
137
- records: t.sort(
138
- (s, u) => u.encounterDateTime - s.encounterDateTime
139
- )
140
- })
141
- ).sort((r, t) => r.formName.localeCompare(t.formName));
142
- }, [T, n]), q = p((e) => {
143
- M(e), E(!0);
144
- }, []), ee = p(() => {
145
- E(!1), M(null);
146
- }, []), S = p(
147
- (e, o) => {
148
- switch (o) {
149
- case "recordedOn":
150
- return /* @__PURE__ */ i(fe, { onClick: () => q(e), children: e.recordedOn });
151
- case "recordedBy":
152
- return e.recordedBy;
153
- default:
154
- return null;
155
- }
156
- },
157
- [q]
158
- );
159
- return /* @__PURE__ */ oe(te, { children: [
160
- /* @__PURE__ */ i("div", { id: "forms-table", "data-testid": "forms-table", children: A || D || C.length === 0 || B ? /* @__PURE__ */ i(
161
- k,
162
- {
163
- headers: L,
164
- ariaLabel: n("FORMS_HEADING"),
165
- rows: [],
166
- loading: A,
167
- errorStateMessage: D ? x?.message : void 0,
168
- emptyStateMessage: n("FORMS_UNAVAILABLE"),
169
- renderCell: S,
170
- className: O.formsTableBody,
171
- dataTestId: "forms-table"
172
- }
173
- ) : /* @__PURE__ */ i(ye, { align: "start", children: C.map((e, o) => {
174
- const { formName: r, records: t } = e;
175
- return /* @__PURE__ */ i(
176
- be,
177
- {
178
- title: r,
179
- className: O.customAccordianItem,
180
- testId: `accordian-title-${r}`,
181
- open: o === 0,
182
- children: /* @__PURE__ */ i(
183
- k,
184
- {
185
- headers: L,
186
- ariaLabel: n("FORMS_HEADING"),
187
- rows: t,
188
- loading: !1,
189
- errorStateMessage: "",
190
- sortable: Z,
191
- emptyStateMessage: n("FORMS_UNAVAILABLE"),
192
- renderCell: S,
193
- className: O.formsTableBody,
194
- dataTestId: `forms-table-${r}`
195
- }
196
- )
197
- },
198
- r
199
- );
200
- }) }) }),
201
- f && a && /* @__PURE__ */ i(
202
- pe,
203
- {
204
- id: "modalIdForActionAreaLayout",
205
- portalId: "main-display-area",
206
- open: f,
207
- onRequestClose: ee,
208
- modalHeading: a.formName,
209
- modalLabel: `${a.recordedOn} | ${a.recordedBy}`,
210
- passiveModal: !0,
211
- size: "md",
212
- testId: "form-details-modal",
213
- children: /* @__PURE__ */ i(
214
- ge,
215
- {
216
- observations: Y,
217
- isLoading: P || G,
218
- isError: z || Q,
219
- errorMessage: X,
220
- emptyStateMessage: n("NO_FORM_DATA_AVAILABLE"),
221
- testIdPrefix: a.formName,
222
- hideThumbnail: V,
223
- controlOrder: J,
224
- sectionMap: W
225
- }
226
- )
227
- }
228
- )
229
- ] });
230
- };
231
- export {
232
- Ae as default
233
- };