@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,5 +1,5 @@
1
1
  import { jsx as r, jsxs as T, Fragment as Y } from "react/jsx-runtime";
2
- import { u as W, a as X, d as J, B as Z, R as x, q as ee, F as te } from "./index-BbuEus1P.js";
2
+ import { u as W, a as X, g as J, B as Z, P as x, q as ee, F as te } from "./index-C1f36q-O.js";
3
3
  import { useQuery as ne } from "@tanstack/react-query";
4
4
  import { useState as l, useCallback as _, useEffect as I, useMemo as p } from "react";
5
5
  import { useTranslation as ae } from "react-i18next";
@@ -19,7 +19,7 @@ const oe = "DocumentsTable-module_documentsTableBody__6iR3w", se = "DocumentsTab
19
19
  uploadedBy: "DOCUMENTS_UPLOADED_BY",
20
20
  attachments: "DOCUMENTS_ATTACHMENTS"
21
21
  };
22
- function B(n) {
22
+ function F(n) {
23
23
  return !n || n.includes(":") ? "#" : `/openmrs/auth?requested_document=/document_images/${n}`;
24
24
  }
25
25
  function he(n, f) {
@@ -34,7 +34,7 @@ const Te = [
34
34
  "attachments",
35
35
  "uploadedOn",
36
36
  "uploadedBy"
37
- ], _e = /\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i, F = (n) => n.attachments.length > 0 ? n.attachments : n.documentUrl ? [{ url: n.documentUrl, contentType: n.contentType }] : [], Ie = ({ config: n, encounterUuids: f }) => {
37
+ ], _e = /\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i, R = (n) => n.attachments.length > 0 ? n.attachments : n.documentUrl ? [{ url: n.documentUrl, contentType: n.contentType }] : [], Ie = ({ config: n, encounterUuids: f }) => {
38
38
  const [d, L] = l(!1), [s, U] = l(
39
39
  null
40
40
  ), [P, A] = l(
@@ -43,7 +43,7 @@ const Te = [
43
43
  U(e), L(!0);
44
44
  }, []), H = _(() => {
45
45
  L(!1), U(null), A(/* @__PURE__ */ new Set());
46
- }, []), R = _((e) => {
46
+ }, []), B = _((e) => {
47
47
  A((t) => new Set(t).add(e));
48
48
  }, []), { data: i, isLoading: q, isError: S, error: y } = ne({
49
49
  queryKey: [
@@ -75,9 +75,9 @@ const Te = [
75
75
  const e = new AbortController();
76
76
  return (async () => {
77
77
  if (!d || !s) return;
78
- const a = /* @__PURE__ */ new Set(), g = F(s);
79
- for (let m = 0; m < g.length; m++) {
80
- const b = B(g[m].url);
78
+ const a = /* @__PURE__ */ new Set(), D = R(s);
79
+ for (let m = 0; m < D.length; m++) {
80
+ const b = F(D[m].url);
81
81
  try {
82
82
  (await fetch(b, {
83
83
  method: "HEAD",
@@ -95,17 +95,17 @@ const Te = [
95
95
  t !== u ? ($(t), C(1), O(void 0)) : C(e);
96
96
  },
97
97
  [u]
98
- ), D = p(
98
+ ), g = p(
99
99
  () => n?.fields ?? Te,
100
100
  [n?.fields]
101
- ), j = p(() => [...i?.documents ?? []].sort((t, a) => !t.uploadedOn && !a.uploadedOn ? 0 : t.uploadedOn ? a.uploadedOn ? new Date(a.uploadedOn).getTime() - new Date(t.uploadedOn).getTime() : -1 : 1), [i]), K = p(() => he(D, o), [D, o]), G = p(
102
- () => D.map((e) => ({
101
+ ), j = p(() => [...i?.documents ?? []].sort((t, a) => !t.uploadedOn && !a.uploadedOn ? 0 : t.uploadedOn ? a.uploadedOn ? new Date(a.uploadedOn).getTime() - new Date(t.uploadedOn).getTime() : -1 : 1), [i]), K = p(() => he(g, o), [g, o]), G = p(
102
+ () => g.map((e) => ({
103
103
  key: e,
104
104
  sortable: e !== "attachments"
105
105
  })),
106
- [D]
106
+ [g]
107
107
  ), h = p(
108
- () => s ? F(s) : [],
108
+ () => s ? R(s) : [],
109
109
  [s]
110
110
  ), Q = _(
111
111
  (e, t) => {
@@ -170,7 +170,7 @@ const Te = [
170
170
  size: "lg",
171
171
  testId: "document-view-modal",
172
172
  children: /* @__PURE__ */ r("div", { className: c.documentViewerContainer, children: h.map((e, t) => {
173
- const a = B(e.url), g = e.contentType?.toLowerCase().includes("pdf"), m = (e.contentType?.toLowerCase().includes("image") ?? !1) || _e.test(e.url ?? ""), b = P.has(t);
173
+ const a = F(e.url), D = e.contentType?.toLowerCase().includes("pdf"), m = (e.contentType?.toLowerCase().includes("image") ?? !1) || _e.test(e.url ?? ""), b = P.has(t);
174
174
  return a === "#" || b ? /* @__PURE__ */ T(
175
175
  "div",
176
176
  {
@@ -203,15 +203,15 @@ const Te = [
203
203
  src: a,
204
204
  alt: s.documentIdentifier,
205
205
  className: c.documentImage,
206
- onError: () => R(t)
206
+ onError: () => B(t)
207
207
  }
208
208
  ) : /* @__PURE__ */ r(
209
209
  "iframe",
210
210
  {
211
- src: g ? `${a}#toolbar=0` : a,
211
+ src: D ? `${a}#toolbar=0` : a,
212
212
  className: c.documentIframe,
213
213
  title: s.documentIdentifier,
214
- onError: () => R(t)
214
+ onError: () => B(t)
215
215
  }
216
216
  )
217
217
  ]
@@ -0,0 +1,294 @@
1
+ import { jsx as i, jsxs as K, Fragment as ye } from "react/jsx-runtime";
2
+ import { u as be, b as pe, c as Oe, D as Ne, K as Te, z as Ee, Y as Fe, v as Ie, d as ve, e as _e, f as Ae, h as x, P as Re, l as j, $ as G, B as De, q as Q, T as Me, R as Be, F as Ce, O as Le, C as Se } from "./index-C1f36q-O.js";
3
+ import { useQueryClient as Ue, useQuery as T } from "@tanstack/react-query";
4
+ import { useState as Y, useMemo as d, useCallback as l } from "react";
5
+ import { useTranslation as we } from "react-i18next";
6
+ const He = "FormsTable-module_formsTableBody__SvGha", ke = "FormsTable-module_modalHeading__wnTmA", qe = "FormsTable-module_customAccordianItem__isszs", E = {
7
+ formsTableBody: He,
8
+ modalHeading: ke,
9
+ customAccordianItem: qe
10
+ }, Pe = "startConsultation", je = ({
11
+ episodeOfCareUuids: D,
12
+ encounterUuids: m,
13
+ config: W,
14
+ disableActions: J = !1,
15
+ activeEncounterUuid: y = null
16
+ }) => {
17
+ const { t: n } = we(), u = be(), [b, M] = Y(!1), [a, B] = Y(null), {
18
+ numberOfVisits: X,
19
+ hideThumbnail: Z = !1,
20
+ forms: p
21
+ } = W ?? {}, ee = pe(
22
+ Se.EDIT_OBSERVATIONS
23
+ ), { userPrivileges: O } = Oe(), F = ee && !J && !!y, C = Ne(
24
+ D,
25
+ m
26
+ ), re = Ue(), {
27
+ data: L = [],
28
+ isLoading: S,
29
+ isError: U,
30
+ error: te,
31
+ refetch: oe
32
+ } = T({
33
+ queryKey: ["forms", u, D],
34
+ queryFn: () => Te(u, void 0, X),
35
+ enabled: !!u && !C
36
+ }), w = d(() => {
37
+ let e = L;
38
+ return m && m.length > 0 && (e = e.filter(
39
+ (r) => m.includes(r.encounterUuid)
40
+ )), Array.isArray(p) && p.length > 0 && (e = e.filter(
41
+ (r) => p.some((o) => o.toLowerCase() === r.formName.toLowerCase())
42
+ )), e;
43
+ }, [L, m, p]), { data: N = [] } = T({
44
+ queryKey: ["observationForms"],
45
+ queryFn: () => Ee()
46
+ }), H = l(
47
+ (e) => {
48
+ const r = N.find((t) => t.name === e);
49
+ if (!r?.privileges || r.privileges.length === 0) return !0;
50
+ if (!O || O.length === 0) return !1;
51
+ const o = new Set(O.map((t) => t.name));
52
+ return r.privileges.some(
53
+ (t) => o.has(t.privilegeName) && t.editable
54
+ );
55
+ },
56
+ [N, O]
57
+ ), f = l(
58
+ (e) => !y || e.encounterUuid !== y ? !1 : H(e.formName),
59
+ [y, H]
60
+ ), k = l(
61
+ (e) => N.find((o) => o.name === e)?.uuid,
62
+ [N]
63
+ ), I = d(() => {
64
+ if (a)
65
+ return k(a.formName);
66
+ }, [a, k]), {
67
+ data: c,
68
+ isLoading: se,
69
+ isError: ae,
70
+ error: v
71
+ } = T({
72
+ queryKey: ["formMetadata", I],
73
+ queryFn: () => Fe(I),
74
+ enabled: !!I && b
75
+ }), {
76
+ data: _,
77
+ isLoading: ne,
78
+ isError: ie,
79
+ error: A
80
+ } = T({
81
+ queryKey: ["formsEncounterFHIR", a?.encounterUuid],
82
+ queryFn: () => Ie(a.encounterUuid),
83
+ enabled: !!a?.encounterUuid && b
84
+ });
85
+ ve(
86
+ (e) => {
87
+ e.patientUUID === u && e.updatedConcepts.size > 0 && (oe(), re.invalidateQueries({ queryKey: ["formsEncounterFHIR"] }));
88
+ },
89
+ [u]
90
+ );
91
+ const de = d(() => !_?.entry || !a?.formName ? [] : _.entry.filter((r) => r.resource?.resourceType === "Observation").map((r) => r.resource).filter((r) => _e(r) ? Ae(r)?.toLowerCase() === a.formName.toLowerCase() : !0), [_, a?.formName]), le = d(() => {
92
+ if (!c?.schema) return;
93
+ const e = [], r = (o) => {
94
+ (o ?? []).forEach((t) => {
95
+ const s = t;
96
+ s.id != null && e.push(String(s.id)), s.controls && r(s.controls);
97
+ });
98
+ };
99
+ return r(
100
+ c.schema.controls ?? []
101
+ ), e.length > 0 ? e : void 0;
102
+ }, [c]), ce = d(() => {
103
+ if (!c?.schema) return;
104
+ const e = {}, r = (o, t) => {
105
+ for (const s of o)
106
+ if (s.type === "section") {
107
+ const g = s.label?.value ?? "Section";
108
+ r(s.controls ?? [], g);
109
+ } else
110
+ s.id != null && t && (e[String(s.id)] = t), s.controls && r(s.controls, t);
111
+ };
112
+ return r(
113
+ c.schema.controls ?? [],
114
+ null
115
+ ), Object.keys(e).length > 0 ? e : void 0;
116
+ }, [c]), me = d(() => {
117
+ if (v)
118
+ return x(v).message;
119
+ if (A)
120
+ return x(A).message;
121
+ }, [v, A]), h = d(
122
+ () => [
123
+ { key: "recordedOn", header: n("RECORDED_ON") },
124
+ { key: "recordedBy", header: n("RECORDED_BY") }
125
+ ],
126
+ [n]
127
+ ), q = d(
128
+ () => [...h, { key: "actions", header: n("ACTIONS") }],
129
+ [h, n]
130
+ ), ue = l(
131
+ (e) => F && e.some((o) => f(o)) ? q : h,
132
+ [F, f, q, h]
133
+ ), fe = h, he = d(
134
+ () => [
135
+ { key: "recordedOn", sortable: !0 },
136
+ { key: "recordedBy", sortable: !0 }
137
+ ],
138
+ []
139
+ ), P = d(() => {
140
+ const e = w.reduce(
141
+ (o, t) => {
142
+ const s = t.formName;
143
+ o[s] ??= [];
144
+ const g = t.providers.map((ge) => ge.providerName).filter(Boolean).join(", ");
145
+ return o[s].push({
146
+ id: t.encounterUuid,
147
+ formName: t.formName,
148
+ recordedOn: Re(t.encounterDateTime, n, !0).formattedResult,
149
+ recordedBy: g ?? "--",
150
+ encounterDateTime: t.encounterDateTime,
151
+ encounterUuid: t.encounterUuid
152
+ }), o;
153
+ },
154
+ {}
155
+ );
156
+ return Object.entries(e).map(
157
+ ([o, t]) => ({
158
+ formName: o,
159
+ records: t.sort(
160
+ (s, g) => g.encounterDateTime - s.encounterDateTime
161
+ )
162
+ })
163
+ ).sort((o, t) => o.formName.localeCompare(t.formName));
164
+ }, [w, n]), V = l((e) => {
165
+ B(e), M(!0);
166
+ }, []), z = l(() => {
167
+ M(!1), B(null);
168
+ }, []), R = l((e) => {
169
+ globalThis.dispatchEvent(
170
+ new CustomEvent(Pe, {
171
+ detail: {
172
+ editOnly: "observationForms",
173
+ editTitle: "EDIT_OBSERVATION_FORM_TITLE",
174
+ editEncounterUuid: e.encounterUuid,
175
+ editFormName: e.formName,
176
+ directFormMode: !0
177
+ }
178
+ })
179
+ );
180
+ }, []), $ = l(
181
+ (e, r) => {
182
+ switch (r) {
183
+ case "recordedOn":
184
+ return /* @__PURE__ */ i(De, { onClick: () => V(e), children: e.recordedOn });
185
+ case "recordedBy":
186
+ return e.recordedBy;
187
+ case "actions":
188
+ return f(e) ? /* @__PURE__ */ i(
189
+ j,
190
+ {
191
+ label: n("EDIT_OBSERVATION_FORM"),
192
+ kind: "ghost",
193
+ size: "sm",
194
+ testId: `edit-form-${e.encounterUuid}`,
195
+ onClick: () => R(e),
196
+ children: /* @__PURE__ */ i(G, {})
197
+ }
198
+ ) : null;
199
+ default:
200
+ return null;
201
+ }
202
+ },
203
+ [V, R, f, n]
204
+ );
205
+ return /* @__PURE__ */ K(ye, { children: [
206
+ /* @__PURE__ */ i("div", { id: "forms-table", "data-testid": "forms-table", children: S || U || P.length === 0 || C ? /* @__PURE__ */ i(
207
+ Q,
208
+ {
209
+ headers: fe,
210
+ ariaLabel: n("FORMS_HEADING"),
211
+ rows: [],
212
+ loading: S,
213
+ errorStateMessage: U ? te?.message : void 0,
214
+ emptyStateMessage: n("FORMS_UNAVAILABLE"),
215
+ renderCell: $,
216
+ className: E.formsTableBody,
217
+ dataTestId: "forms-table"
218
+ }
219
+ ) : /* @__PURE__ */ i(Me, { align: "start", children: P.map((e, r) => {
220
+ const { formName: o, records: t } = e, s = ue(t);
221
+ return /* @__PURE__ */ i(
222
+ Be,
223
+ {
224
+ title: o,
225
+ className: E.customAccordianItem,
226
+ testId: `accordian-title-${o}`,
227
+ open: r === 0,
228
+ children: /* @__PURE__ */ i(
229
+ Q,
230
+ {
231
+ headers: s,
232
+ ariaLabel: n("FORMS_HEADING"),
233
+ rows: t,
234
+ loading: !1,
235
+ errorStateMessage: "",
236
+ sortable: he,
237
+ emptyStateMessage: n("FORMS_UNAVAILABLE"),
238
+ renderCell: $,
239
+ className: E.formsTableBody,
240
+ dataTestId: `forms-table-${o}`
241
+ }
242
+ )
243
+ },
244
+ o
245
+ );
246
+ }) }) }),
247
+ b && a && /* @__PURE__ */ i(
248
+ Ce,
249
+ {
250
+ id: "modalIdForActionAreaLayout",
251
+ portalId: "main-display-area",
252
+ open: b,
253
+ onRequestClose: z,
254
+ modalHeading: /* @__PURE__ */ K("div", { className: E.modalHeading, children: [
255
+ /* @__PURE__ */ i("span", { children: a.formName }),
256
+ F && f(a) && /* @__PURE__ */ i(
257
+ j,
258
+ {
259
+ label: n("EDIT_OBSERVATION_FORM"),
260
+ kind: "ghost",
261
+ size: "sm",
262
+ testId: `edit-form-modal-${a.encounterUuid}`,
263
+ onClick: () => {
264
+ z(), R(a);
265
+ },
266
+ children: /* @__PURE__ */ i(G, {})
267
+ }
268
+ )
269
+ ] }),
270
+ modalLabel: `${a.recordedOn} | ${a.recordedBy}`,
271
+ passiveModal: !0,
272
+ size: "md",
273
+ testId: "form-details-modal",
274
+ children: /* @__PURE__ */ i(
275
+ Le,
276
+ {
277
+ observations: de,
278
+ isLoading: se || ne,
279
+ isError: ae || ie,
280
+ errorMessage: me,
281
+ emptyStateMessage: n("NO_FORM_DATA_AVAILABLE"),
282
+ testIdPrefix: a.formName,
283
+ hideThumbnail: Z,
284
+ controlOrder: le,
285
+ sectionMap: ce
286
+ }
287
+ )
288
+ }
289
+ )
290
+ ] });
291
+ };
292
+ export {
293
+ je as default
294
+ };
@@ -1,5 +1,5 @@
1
1
  import { jsx as d, jsxs as N } from "react/jsx-runtime";
2
- import { f as K, Q as D, t as V, g as q, W as k, h as w, i as H, k as G, u as P, a as j, l as z, m as W, n as J, o as Y, p as X, s as Z, r as x, q as ee } from "./index-BbuEus1P.js";
2
+ import { i as K, Q as D, t as V, j as q, W as w, k, n as H, m as G, u as P, a as j, o as z, p as W, d as J, r as Y, s as X, w as Z, x, q as ee } from "./index-C1f36q-O.js";
3
3
  import { useQueries as te, useQuery as se } from "@tanstack/react-query";
4
4
  import { useRef as oe, useEffect as C, useMemo as g } from "react";
5
5
  import { useTranslation as U } from "react-i18next";
@@ -7,7 +7,7 @@ const B = (t, i, c, l, u, r) => {
7
7
  const s = V(t, i, u), o = s.value, a = q(o);
8
8
  let n = o;
9
9
  a === "Image" && (n = /* @__PURE__ */ d(
10
- w,
10
+ k,
11
11
  {
12
12
  imageSrc: o,
13
13
  alt: o,
@@ -26,7 +26,7 @@ const B = (t, i, c, l, u, r) => {
26
26
  provider: s.provider
27
27
  }), m = t.display, p = t.observationValue?.isAbnormal ? "abnormal-obs" : "obs", y = l ? `${l}-${p}-${m}-${c}-${i}` : `${p}-${m}-${c}-${i}`;
28
28
  return /* @__PURE__ */ d(
29
- k,
29
+ w,
30
30
  {
31
31
  header: s.header,
32
32
  value: n,
@@ -1 +1 @@
1
- {"version":3,"file":"FormsTable.d.ts","sourceRoot":"","sources":["../../src/forms/FormsTable.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAUhD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CA+VrC,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;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAehD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAycrC,CAAC;AAEF,eAAe,UAAU,CAAC"}