@bahmni/widgets 0.0.1-dev.118 → 0.0.1-dev.119

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 { jsxs as _, jsx as t, Fragment as J } from "react/jsx-runtime";
2
- import { c as h, u as W, C as X, F as Z, q as ee, U as re, I as oe, l as te, e as ae, P as $, i as ne, f as se, p as ce, a as de, b as U, d as le } from "./index-Ciduksrd.js";
2
+ import { c as h, u as W, C as X, F as Z, q as ee, U as re, I as oe, l as te, e as ae, P as $, i as ne, f as se, p as ce, a as de, b as U, d as le } from "./index-BSGBBl-w.js";
3
3
  import { useQuery as g } from "@tanstack/react-query";
4
4
  import { useState as q, useMemo as b, useCallback as N } from "react";
5
5
  import { createPortal as me } from "react-dom";
@@ -0,0 +1,330 @@
1
+ import { jsx as d, jsxs as T } from "react/jsx-runtime";
2
+ import { g as U, h as $, j as F, v as L, m as x, k as G, u as k, n as q, G as P, O as Q, y as K, P as H } from "./index-BSGBBl-w.js";
3
+ import { useQueries as j, useQuery as Y } 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 ? U(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
+ }), b = (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 = b(e.encounter), o = (e.hasMember ?? []).map((i) => b(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 = b(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 = F(o);
183
+ let s = o;
184
+ i === "Image" && (s = /* @__PURE__ */ d(x, { imageSrc: o, alt: o, id: `${o}-img` })), i === "Video" && (s = /* @__PURE__ */ d(G, { 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
+ L,
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 = k(), { addNotification: s } = q(), { t: a } = _(), u = j({
250
+ queries: t.map((c) => ({
251
+ queryKey: fe(c),
252
+ queryFn: () => P(c),
253
+ enabled: !!c
254
+ }))
255
+ });
256
+ R(() => {
257
+ u.forEach((c, f) => {
258
+ if (c.isError && !o.current.has(f)) {
259
+ const B = t[f];
260
+ s({
261
+ title: a("ERROR_DEFAULT_TITLE"),
262
+ message: a("ERROR_FETCHING_CONCEPT", { conceptName: B }),
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: D,
271
+ isError: h
272
+ } = Y({
273
+ queryKey: ge(i, p),
274
+ queryFn: () => Q(i, p),
275
+ enabled: !!i && p.length > 0 && v
276
+ });
277
+ R(() => {
278
+ h && s({
279
+ title: a("ERROR_DEFAULT_TITLE"),
280
+ message: a("ERROR_FETCHING_OBSERVATIONS"),
281
+ type: "error"
282
+ });
283
+ }, [h]);
284
+ const y = m(() => {
285
+ if (!g) return [];
286
+ const c = ae(g), f = ue(c);
287
+ return ce(f);
288
+ }, [g]), A = [
289
+ { key: "name", header: "name" },
290
+ { key: "value", header: "value" },
291
+ { key: "form", header: "form" }
292
+ ], E = D || !v, O = h && 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, M = 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
+ K,
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
+ M ? /* @__PURE__ */ d(de, { groupedData: y }) : /* @__PURE__ */ d(
312
+ H,
313
+ {
314
+ headers: A,
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
+ };
@@ -75658,11 +75658,11 @@ const BGe = () => {
75658
75658
  },
75659
75659
  {
75660
75660
  type: "forms",
75661
- component: o1(() => import("./FormsTable-DKfPe7sR.js"))
75661
+ component: o1(() => import("./FormsTable-Dr1mQ8jd.js"))
75662
75662
  },
75663
75663
  {
75664
75664
  type: "observations",
75665
- component: o1(() => import("./Observations-CDcoFLGt.js"))
75665
+ component: o1(() => import("./Observations-Bv0p8jrw.js"))
75666
75666
  }
75667
75667
  ];
75668
75668
  class Qr {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { H as t, B as s, A as o, r, D as n, s as g, L as l, M as c, N as d, w as P, o as v, t as T, R as b, S as W, z as A, V as f, X as u, W as C, K as S, Q as m, T as p, J as D, Y as N, E as R, n as U, u as h, x } from "./index-Ciduksrd.js";
1
+ import { H as t, B as s, A as o, r, D as n, s as g, L as l, M as c, N as d, w as P, o as v, t as T, R as b, S as W, z as A, V as f, X as u, W as C, K as S, Q as m, T as p, J as D, Y as N, E as R, n as U, u as h, x } from "./index-BSGBBl-w.js";
2
2
  import "react";
3
3
  export {
4
4
  t as ActivePractitionerContext,
@@ -161,4 +161,9 @@ export declare const mockObservationWithNoUnits: {
161
161
  };
162
162
  };
163
163
  };
164
+ export declare const mockObservationWithoutObservationValue: {
165
+ id: string;
166
+ display: string;
167
+ observationValue: undefined;
168
+ };
164
169
  //# sourceMappingURL=observationTestData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observationTestData.d.ts","sourceRoot":"","sources":["../../../src/observations/__mocks__/observationTestData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,WAAW,CA0D3D,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,CAI/C,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,WAAW,CAGvD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,WAAW,GAAG,SAAS,CA2B1E,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,WAAW,CAuBvD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B,KACrD,MAIF,CAAC;AAiDF,eAAO,MAAM,6BAA6B,GACxC,aAAa,oBAAoB,EACjC,OAAO,MAAM;;;;;CAQd,CAAC;AAmIF,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,GACtC,2BAA2B,CAuC7B;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,2BAA2B,GAClC,uBAAuB,EAAE,CA8C3B;AAED,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE,uBAAuB,EAAE,GACtC,uBAAuB,EAAE,CAW3B"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/observations/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAa,MAAM,SAAS,CAAC;AACpE,OAAO,EACL,gBAAgB,EAEhB,oBAAoB,EACpB,kBAAkB,EAClB,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,UAAU,CAAC;AASlB,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,gBAAgB,GAAG,SAAS,EAC9C,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,KACzB,MAMF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,aAAa,oBAAoB,GAAG,kBAAkB,KACrD,MAOF,CAAC;AAsDF,eAAO,MAAM,6BAA6B,GACxC,aAAa,oBAAoB,EACjC,OAAO,MAAM;;;;;CAQd,CAAC;AAyJF,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,GACtC,2BAA2B,CAuC7B;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,2BAA2B,GAClC,uBAAuB,EAAE,CA8C3B;AAED,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE,uBAAuB,EAAE,GACtC,uBAAuB,EAAE,CAW3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bahmni/widgets",
3
- "version": "0.0.1-dev.118",
3
+ "version": "0.0.1-dev.119",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,306 +0,0 @@
1
- import { jsx as l, jsxs as T } from "react/jsx-runtime";
2
- import { g as B, h as $, j as F, v as L, m as x, k as G, u as k, n as q, G as P, O as Q, y as K, P as H } from "./index-Ciduksrd.js";
3
- import { useQueries as j, useQuery as Y } from "@tanstack/react-query";
4
- import { useRef as z, useEffect as R, useMemo as g } 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, t) => e?.date ? B(e.date, t).formattedResult : t("DATE_ERROR_PARSE"), te = (e) => {
7
- const { value: t, unit: n } = e.observationValue;
8
- return n ? `${t} ${n}` : String(t);
9
- }, ne = (e) => {
10
- const { unit: t, referenceRange: n } = e.observationValue, r = e.display;
11
- if (!n)
12
- return String(r);
13
- const { low: o, high: s } = n;
14
- if (o && s) {
15
- const i = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value), a = s.unit ? `${s.value} ${s.unit}` : t ? `${s.value} ${t}` : String(s.value);
16
- return `${r} (${i} - ${a})`;
17
- }
18
- if (o) {
19
- const i = o.unit ? `${o.value} ${o.unit}` : t ? `${o.value} ${t}` : String(o.value);
20
- return `${r} (>${i})`;
21
- }
22
- if (s) {
23
- const i = s.unit ? `${s.value} ${s.unit}` : t ? `${s.value} ${t}` : String(s.value);
24
- return `${r} (<${i})`;
25
- }
26
- return r;
27
- }, re = (e, t) => ({
28
- index: t,
29
- header: ne(e),
30
- value: te(e),
31
- provider: e.encounter?.provider
32
- }), b = (e) => (typeof e == "string" ? e : e?.reference)?.split("/")?.pop();
33
- function oe(e) {
34
- return !e.interpretation || e.interpretation.length === 0 ? !1 : e.interpretation.some(
35
- (t) => t.coding?.some(
36
- (n) => n.system === Z && n.code === X
37
- )
38
- );
39
- }
40
- function se(e) {
41
- const { valueQuantity: t, valueCodeableConcept: n, valueString: r, referenceRange: o } = e, s = oe(e);
42
- if (t) {
43
- const i = {
44
- value: t.value ?? "",
45
- unit: t.unit,
46
- type: "quantity",
47
- isAbnormal: s
48
- };
49
- if (o && o.length > 0) {
50
- const a = o.find(
51
- (u) => u.type?.coding?.some(
52
- (v) => v.system === W && v.code === J
53
- )
54
- );
55
- a && (a.low || a.high) && (i.referenceRange = {
56
- low: a.low ? {
57
- value: a.low.value,
58
- unit: a.low.unit
59
- } : void 0,
60
- high: a.high ? {
61
- value: a.high.value,
62
- unit: a.high.unit
63
- } : void 0
64
- });
65
- }
66
- return i;
67
- }
68
- if (n)
69
- return {
70
- value: n.text ?? n.coding[0].display,
71
- type: "codeable",
72
- isAbnormal: s
73
- };
74
- if (r)
75
- return {
76
- value: r,
77
- type: "string",
78
- isAbnormal: s
79
- };
80
- }
81
- function ie(e, t) {
82
- const n = t.get(e);
83
- if (n)
84
- return {
85
- id: n.id ?? e,
86
- type: n.type?.[0]?.coding?.[0]?.display ?? "Unknown",
87
- date: n.period?.start ?? "",
88
- provider: n.participant?.[0]?.individual?.display,
89
- location: n.location?.[0]?.location?.display
90
- };
91
- }
92
- function I(e, t, n) {
93
- const r = b(e.encounter), o = (e.hasMember ?? []).map((s) => b(s)).map((s) => s ? n.get(s) : void 0).filter((s) => !!s).map(
94
- (s) => I(s, t, n)
95
- );
96
- return {
97
- id: e.id,
98
- display: e.code?.text ?? e.code?.coding?.[0]?.display ?? "",
99
- observationValue: se(e),
100
- effectiveDateTime: e.effectiveDateTime,
101
- issued: e.issued,
102
- encounter: r ? ie(r, t) : void 0,
103
- members: o.length > 0 ? o : void 0
104
- };
105
- }
106
- function ae(e) {
107
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
108
- e.entry?.forEach(({ resource: i }) => {
109
- i?.id && (i.resourceType === "Encounter" ? t.set(i.id, i) : i.resourceType === "Observation" && (n.set(i.id, i), i.hasMember?.forEach((a) => {
110
- const u = b(a);
111
- u && r.add(u);
112
- })));
113
- });
114
- const o = [], s = [];
115
- return n.forEach((i, a) => {
116
- if (r.has(a)) return;
117
- const u = I(
118
- i,
119
- t,
120
- n
121
- );
122
- u.members?.length ? s.push({ ...u, children: u.members }) : o.push(u);
123
- }), { observations: o, groupedObservations: s };
124
- }
125
- function ue(e) {
126
- const t = /* @__PURE__ */ new Map();
127
- return e.observations.forEach((n) => {
128
- if (!n.encounter?.id) return;
129
- const r = n.encounter.id;
130
- t.has(r) || t.set(r, {
131
- observations: [],
132
- groupedObservations: []
133
- }), t.get(r).observations.push(n);
134
- }), e.groupedObservations.forEach((n) => {
135
- if (!n.encounter?.id) return;
136
- const r = n.encounter.id;
137
- t.has(r) || t.set(r, {
138
- observations: [],
139
- groupedObservations: []
140
- }), t.get(r).groupedObservations.push(n);
141
- }), Array.from(t.entries()).map(([n, r]) => {
142
- const o = r.observations[0]?.encounter ?? r.groupedObservations[0]?.encounter;
143
- return {
144
- encounterId: n,
145
- encounterDetails: o,
146
- observations: r.observations,
147
- groupedObservations: r.groupedObservations
148
- };
149
- });
150
- }
151
- function ce(e) {
152
- return [...e].sort((t, n) => {
153
- const r = t.encounterDetails?.date, o = n.encounterDetails?.date;
154
- return !r && !o ? 0 : r ? o ? new Date(o).getTime() - new Date(r).getTime() : -1 : 1;
155
- });
156
- }
157
- const N = (e, t, n) => {
158
- const r = re(e, t), o = r.value, s = F(o);
159
- let i = o;
160
- s === "Image" && (i = /* @__PURE__ */ l(x, { imageSrc: o, alt: o, id: `${o}-img` })), s === "Video" && (i = /* @__PURE__ */ l(G, { id: `${o}-video`, videoSrc: o }));
161
- const a = n("OBSERVATIONS_RECORDED_BY", {
162
- provider: r.provider
163
- }), u = e.observationValue?.isAbnormal ? `abnormal-obs-${e.id}` : `obs-${e.id}`;
164
- return /* @__PURE__ */ l(
165
- L,
166
- {
167
- header: r.header,
168
- value: i,
169
- info: a,
170
- id: u,
171
- testId: `${u}-test-id`,
172
- ariaLabel: `${u}-aria-label`
173
- },
174
- `obs-${e.id}`
175
- );
176
- }, le = (e, t, n) => /* @__PURE__ */ l(
177
- $,
178
- {
179
- title: e.display,
180
- id: `grouped-obs-${e.id}`,
181
- open: n,
182
- children: e.children.map(
183
- (r, o) => N(r, o, t)
184
- )
185
- },
186
- `grouped-obs-${e.id}`
187
- ), de = ({
188
- groupedData: e
189
- }) => {
190
- const { t } = _(), n = (r, o) => {
191
- const s = ee(r.encounterDetails, t);
192
- return /* @__PURE__ */ T(
193
- $,
194
- {
195
- title: s,
196
- id: `encounter-${r.encounterId}`,
197
- open: o,
198
- children: [
199
- r.observations.map(
200
- (i, a) => N(i, a, t)
201
- ),
202
- r.groupedObservations.map(
203
- (i) => le(i, t, o)
204
- )
205
- ]
206
- },
207
- `encounter-${r.encounterId}`
208
- );
209
- };
210
- return /* @__PURE__ */ l(
211
- "div",
212
- {
213
- id: "obs-by-encounter",
214
- "data-testid": "obs-by-encounter-test-id",
215
- "aria-label": "obs-by-encounter-aria-label",
216
- children: e.map(
217
- (r, o) => n(r, o === 0)
218
- )
219
- }
220
- );
221
- }, ve = "_observations_kfbhq_1", pe = "_title_kfbhq_12", S = {
222
- observations: ve,
223
- title: pe
224
- }, fe = (e) => ["conceptUuid", e], me = (e, t) => ["observations", e, ...t], Oe = ({ config: e }) => {
225
- const t = e, { conceptNames: n = [], conceptUuid: r = [] } = t, o = z(/* @__PURE__ */ new Set()), s = k(), { addNotification: i } = q(), { t: a } = _(), u = j({
226
- queries: n.map((c) => ({
227
- queryKey: fe(c),
228
- queryFn: () => P(c),
229
- enabled: !!c
230
- }))
231
- });
232
- R(() => {
233
- u.forEach((c, d) => {
234
- if (c.isError && !o.current.has(d)) {
235
- const U = n[d];
236
- i({
237
- title: a("ERROR_DEFAULT_TITLE"),
238
- message: a("ERROR_FETCHING_CONCEPT", { conceptName: U }),
239
- type: "error"
240
- }), o.current.add(d);
241
- } else c.isError || o.current.delete(d);
242
- });
243
- }, [u, n]);
244
- const v = g(() => u.map((c) => c.data?.uuid).filter((c) => !!c), [u]), f = g(() => [.../* @__PURE__ */ new Set([...v, ...r])], [v, r]), m = g(() => n.length === 0 ? !0 : u.every((c) => !c.isLoading), [u, n.length]), {
245
- data: p,
246
- isLoading: D,
247
- isError: h
248
- } = Y({
249
- queryKey: me(s, f),
250
- queryFn: () => Q(s, f),
251
- enabled: !!s && f.length > 0 && m
252
- });
253
- R(() => {
254
- h && i({
255
- title: a("ERROR_DEFAULT_TITLE"),
256
- message: a("ERROR_FETCHING_OBSERVATIONS"),
257
- type: "error"
258
- });
259
- }, [h]);
260
- const y = g(() => {
261
- if (!p) return [];
262
- const c = ae(p), d = ue(c);
263
- return ce(d);
264
- }, [p]), A = [
265
- { key: "name", header: "name" },
266
- { key: "value", header: "value" },
267
- { key: "form", header: "form" }
268
- ], E = D || !m, O = h && m, w = (!p || p.entry?.length === 0 || f.length === 0) && m, C = O ? a("ERROR_FETCHING_OBSERVATIONS") : null, V = w ? a("NO_OBSERVATIONS_FOUND") : void 0, M = y.length > 0 && !E && !O;
269
- return /* @__PURE__ */ T(
270
- "div",
271
- {
272
- id: "observations",
273
- "data-testid": "observations-test-id",
274
- "aria-label": "observations-aria-label",
275
- className: S.observations,
276
- children: [
277
- /* @__PURE__ */ l(
278
- K,
279
- {
280
- id: "observations-title",
281
- testId: "observations-title-test-id",
282
- title: a(t.titleTranslationKey),
283
- className: S.title,
284
- children: /* @__PURE__ */ l("p", { children: a(t.titleTranslationKey) })
285
- }
286
- ),
287
- M ? /* @__PURE__ */ l(de, { groupedData: y }) : /* @__PURE__ */ l(
288
- H,
289
- {
290
- headers: A,
291
- rows: [],
292
- ariaLabel: a("OBSERVATIONS"),
293
- loading: E,
294
- errorStateMessage: C,
295
- emptyStateMessage: V
296
- }
297
- )
298
- ]
299
- }
300
- );
301
- };
302
- export {
303
- fe as conceptUuidQueryKeys,
304
- Oe as default,
305
- me as observationsQueryKeys
306
- };