@bahmni/registration-app 0.0.1-dev.191 → 0.0.1-dev.193

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,171 @@
1
+ import { jsxs as N, jsx as l } from "react/jsx-runtime";
2
+ import { d as k, t as B, u as I, y as Q, H, E as K, V as j, h as w, i as x, j as G, N as M, k as z, Q as S, T as P, c as Y, $ as J, e as W, r as X, f as Z } from "./index-ZU51OKCH.js";
3
+ import { useQueries as ee, useQuery as te } from "@tanstack/react-query";
4
+ import { useRef as ae, useEffect as T, useMemo as f } from "react";
5
+ const D = (t, d, n, u, r) => {
6
+ const a = P(t, d, r), s = a.value, o = Y(s);
7
+ let i = s;
8
+ o === "Image" && (i = /* @__PURE__ */ l(W, { imageSrc: s, alt: s, id: `${s}-img` })), o === "Video" && (i = /* @__PURE__ */ l(X, { id: `${s}-video`, videoSrc: s })), o === "PDF" && (i = /* @__PURE__ */ l(Z, { id: `${s}-pdf`, src: s }));
9
+ const b = r("OBSERVATIONS_RECORDED_BY", {
10
+ provider: a.provider
11
+ }), p = t.display, y = t.observationValue?.isAbnormal ? "abnormal-obs" : "obs", c = u ? `${u}-${y}-${p}-${n}-${d}` : `${y}-${p}-${n}-${d}`;
12
+ return /* @__PURE__ */ l(
13
+ J,
14
+ {
15
+ header: a.header,
16
+ value: i,
17
+ info: b,
18
+ id: c,
19
+ testId: c,
20
+ ariaLabel: c
21
+ },
22
+ `obs-${t.id}`
23
+ );
24
+ }, se = (t, d, n, u, r, a) => /* @__PURE__ */ l(
25
+ S,
26
+ {
27
+ title: t.display,
28
+ id: `grouped-obs-${t.display}-${u}`,
29
+ open: n,
30
+ children: t.members?.map(
31
+ (s, o) => D(s, o, r, a, d)
32
+ )
33
+ },
34
+ `grouped-obs-${t.id}`
35
+ ), re = ({
36
+ groupedData: t,
37
+ title: d = ""
38
+ }) => {
39
+ const { t: n } = I(), u = (r, a, s) => {
40
+ const o = z(r.encounterDetails, n);
41
+ return /* @__PURE__ */ N(
42
+ S,
43
+ {
44
+ title: o,
45
+ id: `encounter-${r.encounterId}`,
46
+ open: a,
47
+ children: [
48
+ r.observations.map(
49
+ (i, b) => D(i, b, s, d, n)
50
+ ),
51
+ r.groupedObservations.map(
52
+ (i, b) => se(
53
+ i,
54
+ n,
55
+ a,
56
+ b,
57
+ s,
58
+ d
59
+ )
60
+ )
61
+ ]
62
+ },
63
+ `encounter-${r.encounterId}`
64
+ );
65
+ };
66
+ return /* @__PURE__ */ l(
67
+ "div",
68
+ {
69
+ id: "obs-by-encounter",
70
+ "data-testid": "obs-by-encounter-test-id",
71
+ "aria-label": "obs-by-encounter-aria-label",
72
+ children: t.map(
73
+ (r, a) => u(r, a === 0, a)
74
+ )
75
+ }
76
+ );
77
+ }, oe = "_observations_kfbhq_1", ie = "_title_kfbhq_12", _ = {
78
+ observations: oe,
79
+ title: ie
80
+ }, ne = (t) => ["conceptUuid", t], de = (t, d) => ["observations", t, ...d], pe = ({ config: t }) => {
81
+ const d = t, { conceptNames: n = [], conceptUuid: u = [] } = d, r = ae(/* @__PURE__ */ new Set()), a = k(), { addNotification: s } = B(), { t: o } = I(), i = ee({
82
+ queries: n.map((e) => ({
83
+ queryKey: ne(e),
84
+ queryFn: () => Q(e),
85
+ enabled: !!e
86
+ }))
87
+ });
88
+ T(() => {
89
+ i.forEach((e, m) => {
90
+ if (e.isError && !r.current.has(m)) {
91
+ const q = n[m];
92
+ s({
93
+ title: o("ERROR_DEFAULT_TITLE"),
94
+ message: o("ERROR_FETCHING_CONCEPT", { conceptName: q }),
95
+ type: "error"
96
+ }), r.current.add(m);
97
+ } else e.isError || r.current.delete(m);
98
+ });
99
+ }, [i, n]);
100
+ const b = f(() => i.map((e) => e.data?.uuid).filter((e) => !!e), [i]), p = f(() => [.../* @__PURE__ */ new Set([...b, ...u])], [b, u]), y = f(() => n.length === 0 ? !0 : i.every((e) => !e.isLoading), [i, n.length]), {
101
+ data: c,
102
+ isLoading: F,
103
+ isError: h,
104
+ refetch: R
105
+ } = te({
106
+ queryKey: de(a, p),
107
+ queryFn: () => H(a, p),
108
+ enabled: !!a && p.length > 0 && y
109
+ });
110
+ K(
111
+ (e) => {
112
+ e.patientUUID === a && e.updatedConcepts.size > 0 && [...e.updatedConcepts.keys()].some(
113
+ (m) => p.includes(m)
114
+ ) && R();
115
+ },
116
+ [a, R]
117
+ ), T(() => {
118
+ h && s({
119
+ title: o("ERROR_DEFAULT_TITLE"),
120
+ message: o("ERROR_FETCHING_OBSERVATIONS"),
121
+ type: "error"
122
+ });
123
+ }, [h]);
124
+ const g = f(() => {
125
+ if (!c) return [];
126
+ const e = j(c), m = w(e);
127
+ return x(m);
128
+ }, [c]), L = [
129
+ { key: "name", header: "name" },
130
+ { key: "value", header: "value" },
131
+ { key: "form", header: "form" }
132
+ ], O = F || !y, $ = h && y, A = (!c || c.entry?.length === 0 || p.length === 0) && y, C = $ ? o("ERROR_FETCHING_OBSERVATIONS") : null, U = A ? o("NO_OBSERVATIONS_FOUND") : void 0, V = g.length > 0 && !O && !$, E = d.titleTranslationKey, v = E ? o(E) : "";
133
+ return /* @__PURE__ */ N(
134
+ "div",
135
+ {
136
+ id: "observations",
137
+ "data-testid": E ? `observations-${v}` : "observations",
138
+ "aria-label": "observations-aria-label",
139
+ className: _.observations,
140
+ children: [
141
+ /* @__PURE__ */ l(
142
+ G,
143
+ {
144
+ id: "observations-title",
145
+ testId: E ? `observations-title-${v}` : "observations-title",
146
+ title: v,
147
+ className: _.title,
148
+ children: /* @__PURE__ */ l("p", { children: v })
149
+ }
150
+ ),
151
+ V ? /* @__PURE__ */ l(re, { groupedData: g, title: v }) : /* @__PURE__ */ l(
152
+ M,
153
+ {
154
+ headers: L,
155
+ rows: [],
156
+ ariaLabel: o("OBSERVATIONS"),
157
+ loading: O,
158
+ errorStateMessage: C,
159
+ emptyStateMessage: U,
160
+ dataTestId: "observations-table"
161
+ }
162
+ )
163
+ ]
164
+ }
165
+ );
166
+ };
167
+ export {
168
+ ne as conceptUuidQueryKeys,
169
+ pe as default,
170
+ de as observationsQueryKeys
171
+ };