@bahmni/widgets 0.0.1-dev.122 → 0.0.1-dev.124

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,330 +0,0 @@
1
- import { jsx as d, jsxs as T } from "react/jsx-runtime";
2
- import { Y as B, H as $, d as U, L as F, e as x, V as K, u as q, f as H, g as Q, A as k, S as G, K as P } from "./index-CQcHNtl1.js";
3
- import { useQueries as Y, useQuery as j } from "@tanstack/react-query";
4
- import { useRef as z, useEffect as R, useMemo as m } from "react";
5
- import { useTranslation as _ } from "react-i18next";
6
- const J = "normal", W = "http://terminology.hl7.org/CodeSystem/referencerange-meaning", X = "A", Z = "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation", ee = (e, n) => e?.date ? B(e.date, n).formattedResult : n("DATE_ERROR_PARSE"), te = (e) => {
7
- if (!e.observationValue?.value)
8
- return "";
9
- const { value: n, unit: t } = e.observationValue;
10
- return t ? `${n} ${t}` : String(n);
11
- }, ne = (e) => {
12
- const n = e.display;
13
- if (!e.observationValue)
14
- return String(n);
15
- const { unit: t, referenceRange: r } = e.observationValue;
16
- if (!r)
17
- return String(n);
18
- const { low: o, high: i } = r;
19
- if (o && i) {
20
- const s = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value), a = i.unit ? `${i.value} ${i.unit}` : t ? `${i.value} ${t}` : String(i.value);
21
- return `${n} (${s} - ${a})`;
22
- }
23
- if (o) {
24
- const s = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value);
25
- return `${n} (>${s})`;
26
- }
27
- if (i) {
28
- const s = i.unit ? `${i.value} ${i.unit}` : t ? `${i.value} ${t}` : String(i.value);
29
- return `${n} (<${s})`;
30
- }
31
- return n;
32
- }, re = (e, n) => ({
33
- index: n,
34
- header: ne(e),
35
- value: te(e),
36
- provider: e.encounter?.provider
37
- }), h = (e) => (typeof e == "string" ? e : e?.reference)?.split("/")?.pop();
38
- function oe(e) {
39
- return !e.interpretation || e.interpretation.length === 0 ? !1 : e.interpretation.some(
40
- (n) => n.coding?.some(
41
- (t) => t.system === Z && t.code === X
42
- )
43
- );
44
- }
45
- function ie(e) {
46
- const {
47
- valueQuantity: n,
48
- valueCodeableConcept: t,
49
- valueString: r,
50
- valueBoolean: o,
51
- valueInteger: i,
52
- referenceRange: s
53
- } = e, a = oe(e);
54
- if (n) {
55
- const u = {
56
- value: n.value ?? "",
57
- unit: n.unit,
58
- type: "quantity",
59
- isAbnormal: a
60
- };
61
- if (s && s.length > 0) {
62
- const l = s.find(
63
- (p) => p.type?.coding?.some(
64
- (v) => v.system === W && v.code === J
65
- )
66
- );
67
- l && (l.low || l.high) && (u.referenceRange = {
68
- low: l.low ? {
69
- value: l.low.value,
70
- unit: l.low.unit
71
- } : void 0,
72
- high: l.high ? {
73
- value: l.high.value,
74
- unit: l.high.unit
75
- } : void 0
76
- });
77
- }
78
- return u;
79
- }
80
- if (t)
81
- return {
82
- value: t.text ?? t.coding[0].display,
83
- type: "codeable",
84
- isAbnormal: a
85
- };
86
- if (r)
87
- return {
88
- value: r,
89
- type: "string",
90
- isAbnormal: a
91
- };
92
- if (o !== void 0)
93
- return {
94
- value: o,
95
- type: "boolean",
96
- isAbnormal: a
97
- };
98
- if (i !== void 0)
99
- return {
100
- value: i,
101
- type: "integer",
102
- isAbnormal: a
103
- };
104
- }
105
- function se(e, n) {
106
- const t = n.get(e);
107
- if (t)
108
- return {
109
- id: t.id ?? e,
110
- type: t.type?.[0]?.coding?.[0]?.display ?? "Unknown",
111
- date: t.period?.start ?? "",
112
- provider: t.participant?.[0]?.individual?.display,
113
- location: t.location?.[0]?.location?.display
114
- };
115
- }
116
- function I(e, n, t) {
117
- const r = h(e.encounter), o = (e.hasMember ?? []).map((i) => h(i)).map((i) => i ? t.get(i) : void 0).filter((i) => !!i).map(
118
- (i) => I(i, n, t)
119
- );
120
- return {
121
- id: e.id,
122
- display: e.code?.text ?? e.code?.coding?.[0]?.display ?? "",
123
- observationValue: ie(e),
124
- effectiveDateTime: e.effectiveDateTime,
125
- issued: e.issued,
126
- encounter: r ? se(r, n) : void 0,
127
- members: o.length > 0 ? o : void 0
128
- };
129
- }
130
- function ae(e) {
131
- const n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
132
- e.entry?.forEach(({ resource: s }) => {
133
- s?.id && (s.resourceType === "Encounter" ? n.set(s.id, s) : s.resourceType === "Observation" && (t.set(s.id, s), s.hasMember?.forEach((a) => {
134
- const u = h(a);
135
- u && r.add(u);
136
- })));
137
- });
138
- const o = [], i = [];
139
- return t.forEach((s, a) => {
140
- if (r.has(a)) return;
141
- const u = I(
142
- s,
143
- n,
144
- t
145
- );
146
- u.members?.length ? i.push({ ...u, children: u.members }) : o.push(u);
147
- }), { observations: o, groupedObservations: i };
148
- }
149
- function ue(e) {
150
- const n = /* @__PURE__ */ new Map();
151
- return e.observations.forEach((t) => {
152
- if (!t.encounter?.id) return;
153
- const r = t.encounter.id;
154
- n.has(r) || n.set(r, {
155
- observations: [],
156
- groupedObservations: []
157
- }), n.get(r).observations.push(t);
158
- }), e.groupedObservations.forEach((t) => {
159
- if (!t.encounter?.id) return;
160
- const r = t.encounter.id;
161
- n.has(r) || n.set(r, {
162
- observations: [],
163
- groupedObservations: []
164
- }), n.get(r).groupedObservations.push(t);
165
- }), Array.from(n.entries()).map(([t, r]) => {
166
- const o = r.observations[0]?.encounter ?? r.groupedObservations[0]?.encounter;
167
- return {
168
- encounterId: t,
169
- encounterDetails: o,
170
- observations: r.observations,
171
- groupedObservations: r.groupedObservations
172
- };
173
- });
174
- }
175
- function ce(e) {
176
- return [...e].sort((n, t) => {
177
- const r = n.encounterDetails?.date, o = t.encounterDetails?.date;
178
- return !r && !o ? 0 : r ? o ? new Date(o).getTime() - new Date(r).getTime() : -1 : 1;
179
- });
180
- }
181
- const N = (e, n, t) => {
182
- const r = re(e, n), o = r.value, i = U(o);
183
- let s = o;
184
- i === "Image" && (s = /* @__PURE__ */ d(x, { imageSrc: o, alt: o, id: `${o}-img` })), i === "Video" && (s = /* @__PURE__ */ d(K, { id: `${o}-video`, videoSrc: o }));
185
- const a = t("OBSERVATIONS_RECORDED_BY", {
186
- provider: r.provider
187
- }), u = e.observationValue?.isAbnormal ? `abnormal-obs-${e.id}` : `obs-${e.id}`;
188
- return /* @__PURE__ */ d(
189
- F,
190
- {
191
- header: r.header,
192
- value: s,
193
- info: a,
194
- id: u,
195
- testId: `${u}-test-id`,
196
- ariaLabel: `${u}-aria-label`
197
- },
198
- `obs-${e.id}`
199
- );
200
- }, le = (e, n, t) => /* @__PURE__ */ d(
201
- $,
202
- {
203
- title: e.display,
204
- id: `grouped-obs-${e.id}`,
205
- open: t,
206
- children: e.children.map(
207
- (r, o) => N(r, o, n)
208
- )
209
- },
210
- `grouped-obs-${e.id}`
211
- ), de = ({
212
- groupedData: e
213
- }) => {
214
- const { t: n } = _(), t = (r, o) => {
215
- const i = ee(r.encounterDetails, n);
216
- return /* @__PURE__ */ T(
217
- $,
218
- {
219
- title: i,
220
- id: `encounter-${r.encounterId}`,
221
- open: o,
222
- children: [
223
- r.observations.map(
224
- (s, a) => N(s, a, n)
225
- ),
226
- r.groupedObservations.map(
227
- (s) => le(s, n, o)
228
- )
229
- ]
230
- },
231
- `encounter-${r.encounterId}`
232
- );
233
- };
234
- return /* @__PURE__ */ d(
235
- "div",
236
- {
237
- id: "obs-by-encounter",
238
- "data-testid": "obs-by-encounter-test-id",
239
- "aria-label": "obs-by-encounter-aria-label",
240
- children: e.map(
241
- (r, o) => t(r, o === 0)
242
- )
243
- }
244
- );
245
- }, ve = "_observations_kfbhq_1", pe = "_title_kfbhq_12", S = {
246
- observations: ve,
247
- title: pe
248
- }, fe = (e) => ["conceptUuid", e], ge = (e, n) => ["observations", e, ...n], Oe = ({ config: e }) => {
249
- const n = e, { conceptNames: t = [], conceptUuid: r = [] } = n, o = z(/* @__PURE__ */ new Set()), i = q(), { addNotification: s } = H(), { t: a } = _(), u = Y({
250
- queries: t.map((c) => ({
251
- queryKey: fe(c),
252
- queryFn: () => Q(c),
253
- enabled: !!c
254
- }))
255
- });
256
- R(() => {
257
- u.forEach((c, f) => {
258
- if (c.isError && !o.current.has(f)) {
259
- const M = t[f];
260
- s({
261
- title: a("ERROR_DEFAULT_TITLE"),
262
- message: a("ERROR_FETCHING_CONCEPT", { conceptName: M }),
263
- type: "error"
264
- }), o.current.add(f);
265
- } else c.isError || o.current.delete(f);
266
- });
267
- }, [u, t]);
268
- const l = m(() => u.map((c) => c.data?.uuid).filter((c) => !!c), [u]), p = m(() => [.../* @__PURE__ */ new Set([...l, ...r])], [l, r]), v = m(() => t.length === 0 ? !0 : u.every((c) => !c.isLoading), [u, t.length]), {
269
- data: g,
270
- isLoading: A,
271
- isError: b
272
- } = j({
273
- queryKey: ge(i, p),
274
- queryFn: () => k(i, p),
275
- enabled: !!i && p.length > 0 && v
276
- });
277
- R(() => {
278
- b && s({
279
- title: a("ERROR_DEFAULT_TITLE"),
280
- message: a("ERROR_FETCHING_OBSERVATIONS"),
281
- type: "error"
282
- });
283
- }, [b]);
284
- const y = m(() => {
285
- if (!g) return [];
286
- const c = ae(g), f = ue(c);
287
- return ce(f);
288
- }, [g]), D = [
289
- { key: "name", header: "name" },
290
- { key: "value", header: "value" },
291
- { key: "form", header: "form" }
292
- ], E = A || !v, O = b && v, w = (!g || g.entry?.length === 0 || p.length === 0) && v, C = O ? a("ERROR_FETCHING_OBSERVATIONS") : null, V = w ? a("NO_OBSERVATIONS_FOUND") : void 0, L = y.length > 0 && !E && !O;
293
- return /* @__PURE__ */ T(
294
- "div",
295
- {
296
- id: "observations",
297
- "data-testid": "observations-test-id",
298
- "aria-label": "observations-aria-label",
299
- className: S.observations,
300
- children: [
301
- /* @__PURE__ */ d(
302
- G,
303
- {
304
- id: "observations-title",
305
- testId: "observations-title-test-id",
306
- title: a(n.titleTranslationKey),
307
- className: S.title,
308
- children: /* @__PURE__ */ d("p", { children: a(n.titleTranslationKey) })
309
- }
310
- ),
311
- L ? /* @__PURE__ */ d(de, { groupedData: y }) : /* @__PURE__ */ d(
312
- P,
313
- {
314
- headers: D,
315
- rows: [],
316
- ariaLabel: a("OBSERVATIONS"),
317
- loading: E,
318
- errorStateMessage: C,
319
- emptyStateMessage: V
320
- }
321
- )
322
- ]
323
- }
324
- );
325
- };
326
- export {
327
- fe as conceptUuidQueryKeys,
328
- Oe as default,
329
- ge as observationsQueryKeys
330
- };