@bahmni/clinical-app 0.0.1-dev.119 → 0.0.1-dev.121

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