@pih/esm-commons-app 2.1.1-pre.12 → 2.1.1-pre.126

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.
Files changed (122) hide show
  1. package/.turbo/turbo-build.log +5 -33
  2. package/dist/117.js +1 -0
  3. package/dist/117.js.map +1 -0
  4. package/dist/125.js +1 -0
  5. package/dist/125.js.map +1 -0
  6. package/dist/163.js +1 -0
  7. package/dist/163.js.map +1 -0
  8. package/dist/240.js +1 -0
  9. package/dist/240.js.map +1 -0
  10. package/dist/294.js +1 -0
  11. package/dist/294.js.map +1 -0
  12. package/dist/324.js +1 -0
  13. package/dist/324.js.map +1 -0
  14. package/dist/349.js +1 -0
  15. package/dist/349.js.map +1 -0
  16. package/dist/378.js +1 -0
  17. package/dist/378.js.map +1 -0
  18. package/dist/466.js +1 -0
  19. package/dist/466.js.map +1 -0
  20. package/dist/508.js +1 -0
  21. package/dist/508.js.map +1 -0
  22. package/dist/61.js +1 -0
  23. package/dist/61.js.map +1 -0
  24. package/dist/614.js +33 -0
  25. package/dist/614.js.map +1 -0
  26. package/dist/689.js +1 -0
  27. package/dist/689.js.map +1 -0
  28. package/dist/701.js +1 -0
  29. package/dist/701.js.map +1 -0
  30. package/dist/712.js +1 -0
  31. package/dist/712.js.map +1 -0
  32. package/dist/72.js +1 -0
  33. package/dist/72.js.map +1 -0
  34. package/dist/757.js +17 -0
  35. package/dist/757.js.map +1 -0
  36. package/dist/771.js +1 -0
  37. package/dist/771.js.map +1 -0
  38. package/dist/82.js +11 -0
  39. package/dist/82.js.map +1 -0
  40. package/dist/830.js +1 -0
  41. package/dist/830.js.map +1 -0
  42. package/dist/852.js +1 -0
  43. package/dist/852.js.map +1 -0
  44. package/dist/855.js +1 -0
  45. package/dist/855.js.map +1 -0
  46. package/dist/859.js +1 -0
  47. package/dist/859.js.map +1 -0
  48. package/dist/867.js +1 -0
  49. package/dist/867.js.map +1 -0
  50. package/dist/88.js +1 -0
  51. package/dist/88.js.map +1 -0
  52. package/dist/912.js +1 -0
  53. package/dist/912.js.map +1 -0
  54. package/dist/913.js +1 -0
  55. package/dist/913.js.map +1 -0
  56. package/dist/985.js +1 -0
  57. package/dist/985.js.map +1 -0
  58. package/dist/989.js +1 -0
  59. package/dist/989.js.map +1 -0
  60. package/dist/main.js +6 -1
  61. package/dist/main.js.map +1 -1
  62. package/dist/pih-esm-commons-app.js +6 -1
  63. package/dist/pih-esm-commons-app.js.buildmanifest.json +628 -93
  64. package/dist/pih-esm-commons-app.js.map +1 -1
  65. package/dist/routes.json +1 -1
  66. package/package.json +8 -11
  67. package/rspack.config.js +1 -0
  68. package/src/config-schema.ts +85 -0
  69. package/src/declarations.d.ts +2 -0
  70. package/src/dispensing/zebra-label-print-action.extension.tsx +66 -0
  71. package/src/dispensing/zebra-label-print.resource.ts +49 -0
  72. package/src/dispensing/zebra-pdf-print.ts +108 -0
  73. package/src/hooks/useConceptReferenceRanges.ts +128 -0
  74. package/src/hooks/useEncounters.ts +22 -0
  75. package/src/hooks/useProgramEnrollment.ts +19 -0
  76. package/src/hooks/useVisitAttribute.ts +37 -0
  77. package/src/index.ts +39 -12
  78. package/src/routes.json +65 -11
  79. package/src/service-queues-app/maternal-triage-form.workspace.tsx +111 -0
  80. package/src/service-queues-app/maternal-triage-queue-actions.extension.tsx +132 -0
  81. package/src/service-queues-app/maternal-triage-queue-actions.resource.ts +84 -0
  82. package/src/service-queues-app/maternal-trial-queue-actions.scss +14 -0
  83. package/src/service-queues-app/types.ts +58 -0
  84. package/src/ward-app/VitalsTable.tsx +361 -0
  85. package/src/ward-app/inborn-outborn-tag-row.extension.tsx +79 -0
  86. package/src/ward-app/inborn-outborn-tag-row.scss +58 -0
  87. package/src/ward-app/o2-iframe.component.tsx +86 -0
  88. package/src/ward-app/o2-iframe.scss +20 -0
  89. package/src/ward-app/o2-pregnancy-infant-dashboard.extension.tsx +69 -38
  90. package/src/ward-app/o2-pregnancy-infant-dashboard.scss +3 -11
  91. package/src/ward-app/o2-visit-summary-action-button.component.tsx +17 -0
  92. package/src/ward-app/o2-visit-summary-workspace.component.tsx +72 -26
  93. package/src/ward-app/o2-vital-signs-action-button.component.tsx +17 -0
  94. package/src/ward-app/o2-vital-signs-workspace.component.tsx +65 -0
  95. package/src/ward-app/types.ts +7 -4
  96. package/translations/en.json +26 -2
  97. package/translations/es.json +7 -1
  98. package/translations/fr.json +7 -1
  99. package/dist/138.js +0 -1
  100. package/dist/138.js.map +0 -1
  101. package/dist/291.js +0 -1
  102. package/dist/291.js.map +0 -1
  103. package/dist/300.js +0 -1
  104. package/dist/39.js +0 -1
  105. package/dist/39.js.map +0 -1
  106. package/dist/41.js +0 -2
  107. package/dist/41.js.LICENSE.txt +0 -9
  108. package/dist/41.js.map +0 -1
  109. package/dist/55.js +0 -1
  110. package/dist/641.js +0 -1
  111. package/dist/641.js.map +0 -1
  112. package/dist/710.js +0 -1
  113. package/dist/710.js.map +0 -1
  114. package/dist/831.js +0 -2
  115. package/dist/831.js.LICENSE.txt +0 -5
  116. package/dist/831.js.map +0 -1
  117. package/dist/90.js +0 -1
  118. package/dist/90.js.map +0 -1
  119. package/dist/99.js +0 -1
  120. package/src/ward-app/o2-visit-summary-action-button.extension.tsx +0 -18
  121. package/src/ward-app/o2-visit-summary-workspace.scss +0 -9
  122. package/webpack.config.js +0 -1
@@ -0,0 +1,132 @@
1
+ import { Button, OverflowMenu, OverflowMenuItem } from '@carbon/react';
2
+ import { isDesktop, launchWorkspace2, showModal, useConfig, useLayoutType } from '@openmrs/esm-framework';
3
+ import React from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import styles from './maternal-trial-queue-actions.scss';
6
+ import { type QueueEntry } from './types';
7
+ import { transitionQueueEntry, useMutateQueueEntries } from './maternal-triage-queue-actions.resource';
8
+
9
+ // types taken from esm-service-queues-app
10
+ interface QueueTableCellComponentProps {
11
+ queueEntry: QueueEntry;
12
+ }
13
+
14
+ interface ConfigObject {
15
+ concepts: {
16
+ defaultTransitionStatus: string;
17
+ };
18
+ // other fields not shown
19
+ }
20
+
21
+ /**
22
+ * This extension provides an extra "Triage" action, along with the other standard actions for
23
+ * queue entries in the queues table. The Triage action opens the maternal triage form, and also
24
+ * has the side effect of putting the patient's queue entry into the "in service" status, if they have
25
+ * not yet already
26
+ * @param param0
27
+ * @returns
28
+ */
29
+ const MaternalTriageQueueActions: React.FC<QueueTableCellComponentProps> = ({ queueEntry }) => {
30
+ const { t } = useTranslation();
31
+ const layout = useLayoutType();
32
+
33
+ const { mutateQueueEntries } = useMutateQueueEntries();
34
+ const { concepts } = useConfig<ConfigObject>({ externalModuleName: '@openmrs/esm-service-queues-app' });
35
+ const inServiceStatus = concepts.defaultTransitionStatus;
36
+
37
+ const { patient } = queueEntry;
38
+
39
+ return (
40
+ <div className={styles.actionsCell}>
41
+ <Button
42
+ kind="ghost"
43
+ aria-label={t('triage', 'Triage')}
44
+ onClick={async () => {
45
+ if (queueEntry.status.uuid !== inServiceStatus) {
46
+ const res = await transitionQueueEntry({
47
+ queueEntryToTransition: queueEntry.uuid,
48
+ newStatus: inServiceStatus,
49
+ });
50
+ mutateQueueEntries();
51
+ const updatedQueueEntry = { ...res.data, visit: queueEntry.visit };
52
+ launchWorkspace2('maternal-triage-form-workspace', { queueEntry: updatedQueueEntry, patient });
53
+ } else {
54
+ launchWorkspace2('maternal-triage-form-workspace', { queueEntry, patient });
55
+ }
56
+ }}
57
+ size={isDesktop(layout) ? 'sm' : 'lg'}>
58
+ {t('triage', 'Triage')}
59
+ </Button>
60
+
61
+ <OverflowMenu aria-label="Actions menu" size={isDesktop(layout) ? 'sm' : 'lg'} align="left" flipped>
62
+ <OverflowMenuItem
63
+ className={styles.menuItem}
64
+ aria-label={t('transition', 'Transition')}
65
+ hasDivider
66
+ onClick={() => {
67
+ const dispose = showModal('transition-queue-entry-modal', {
68
+ closeModal: () => dispose(),
69
+ queueEntry,
70
+ });
71
+ }}
72
+ itemText={t('transition', 'Transition')}
73
+ />
74
+ <OverflowMenuItem
75
+ className={styles.menuItem}
76
+ aria-label={t('edit', 'Edit')}
77
+ hasDivider
78
+ onClick={() => {
79
+ const dispose = showModal('edit-queue-entry-modal', {
80
+ closeModal: () => dispose(),
81
+ queueEntry,
82
+ });
83
+ }}
84
+ itemText={t('edit', 'Edit')}
85
+ />
86
+ <OverflowMenuItem
87
+ className={styles.menuItem}
88
+ aria-label={t('removePatient', 'Remove patient')}
89
+ hasDivider
90
+ onClick={() => {
91
+ const dispose = showModal('remove-queue-entry-modal', {
92
+ closeModal: () => dispose(),
93
+ queueEntry,
94
+ });
95
+ }}
96
+ itemText={t('removePatient', 'Remove patient')}
97
+ />
98
+ {queueEntry.previousQueueEntry == null ? (
99
+ <OverflowMenuItem
100
+ className={styles.menuItem}
101
+ aria-label={t('delete', 'Delete')}
102
+ hasDivider
103
+ isDelete
104
+ onClick={() => {
105
+ const dispose = showModal('delete-queue-entry-modal', {
106
+ closeModal: () => dispose(),
107
+ queueEntry,
108
+ });
109
+ }}
110
+ itemText={t('delete', 'Delete')}
111
+ />
112
+ ) : (
113
+ <OverflowMenuItem
114
+ className={styles.menuItem}
115
+ aria-label={t('undoTransition', 'Undo transition')}
116
+ hasDivider
117
+ isDelete
118
+ onClick={() => {
119
+ const dispose = showModal('undo-transition-queue-entry-modal', {
120
+ closeModal: () => dispose(),
121
+ queueEntry,
122
+ });
123
+ }}
124
+ itemText={t('undoTransition', 'Undo transition')}
125
+ />
126
+ )}
127
+ </OverflowMenu>
128
+ </div>
129
+ );
130
+ };
131
+
132
+ export default MaternalTriageQueueActions;
@@ -0,0 +1,84 @@
1
+ import { type Concept, type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
2
+ import { useSWRConfig } from 'swr';
3
+ import { type QueueEntry } from './types';
4
+ import { useCallback, useMemo } from 'react';
5
+
6
+ // Hooks here copied from esm-service-queues-app
7
+
8
+ export function useMutateQueueEntries() {
9
+ const { mutate, cache } = useSWRConfig();
10
+ const mutateQueueEntries = useCallback(() => {
11
+ const promises: Promise<unknown>[] = [];
12
+ for (const key of cache.keys()) {
13
+ if (key.includes(`${restBaseUrl}/queue-entry`) || key.includes(`${restBaseUrl}/visit-queue-entry`)) {
14
+ promises.push(mutate(key));
15
+ }
16
+ }
17
+ return Promise.all(promises);
18
+ }, [mutate, cache]);
19
+
20
+ return useMemo(
21
+ () => ({
22
+ mutateQueueEntries,
23
+ }),
24
+ [mutateQueueEntries],
25
+ );
26
+ }
27
+
28
+ interface TransitionQueueEntryParams {
29
+ queueEntryToTransition: string;
30
+ transitionDate?: string;
31
+ newQueue?: string;
32
+ newStatus?: string;
33
+ newPriority?: string;
34
+ newPriorityComment?: string;
35
+ }
36
+
37
+ /**
38
+ * A transition is defined as an action that ends a current queue entry and immediately starts a new one
39
+ * with (slightly) different values. For now, this could be used to transition the queue entry's status,
40
+ * priority or queue. This allows us to keep a history of queue entries through a patient's visit.
41
+ * Note that there are some use cases (like RDE or data correction) where a transition is NOT appropriate.
42
+ * @param params
43
+ * @param abortController
44
+ * @returns
45
+ */
46
+ export function transitionQueueEntry(
47
+ params: TransitionQueueEntryParams,
48
+ abortController?: AbortController,
49
+ ): Promise<FetchResponse<QueueEntry>> {
50
+ return openmrsFetch(`${restBaseUrl}/queue-entry/transition`, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ },
55
+ signal: abortController?.signal,
56
+ body: params,
57
+ });
58
+ }
59
+
60
+ interface UpdateQueueEntryParams {
61
+ status?: Concept;
62
+ priority?: Concept;
63
+ priorityComment?: string;
64
+ sortWeight?: number;
65
+ startedAt?: string;
66
+ endedAt?: string;
67
+ loationWaitingFor?: Location;
68
+ providerWaitingFor?: Location;
69
+ }
70
+
71
+ export function updateQueueEntry(
72
+ queueEntryUuid: string,
73
+ params: UpdateQueueEntryParams,
74
+ abortController?: AbortController,
75
+ ) {
76
+ return openmrsFetch(`${restBaseUrl}/queue-entry/${queueEntryUuid}`, {
77
+ method: 'POST',
78
+ headers: {
79
+ 'Content-Type': 'application/json',
80
+ },
81
+ signal: abortController?.signal,
82
+ body: params,
83
+ });
84
+ }
@@ -0,0 +1,14 @@
1
+ .actionCellContainer {
2
+ white-space: nowrap;
3
+ }
4
+
5
+ .menuItem {
6
+ max-width: none;
7
+ }
8
+
9
+ .actionsCell {
10
+ display: flex;
11
+ justify-content: flex-end;
12
+ height: 100%;
13
+ align-items: center;
14
+ }
@@ -0,0 +1,58 @@
1
+ import { type Concept, type OpenmrsResource, type Patient, type Visit } from '@openmrs/esm-framework';
2
+
3
+ export interface Queue {
4
+ uuid: string;
5
+ display: string;
6
+ name: string;
7
+ description: string;
8
+ location: Location;
9
+ service: Concept;
10
+ allowedPriorities: Array<Concept>;
11
+ allowedStatuses: Array<Concept>;
12
+ }
13
+
14
+ export interface QueueEntry {
15
+ uuid: string;
16
+ display: string;
17
+ endedAt: string;
18
+ locationWaitingFor: Location;
19
+ patient: Patient;
20
+ priority: Concept;
21
+ priorityComment: string | null;
22
+ providerWaitingFor: Provider;
23
+ queue: Queue;
24
+ startedAt: string;
25
+ status: Concept;
26
+ visit: Visit;
27
+ sortWeight: number;
28
+ queueComingFrom: Queue;
29
+ previousQueueEntry: QueueEntry;
30
+ }
31
+
32
+ export interface Provider extends OpenmrsResource {}
33
+
34
+ export interface Encounter {
35
+ uuid: string;
36
+ encounterDateTime: string;
37
+ encounterProviders: Array<{
38
+ uuid: string;
39
+ display: string;
40
+ encounterRole: {
41
+ uuid: string;
42
+ display: string;
43
+ };
44
+ provider: {
45
+ uuid: string;
46
+ person: {
47
+ uuid: string;
48
+ display: string;
49
+ };
50
+ };
51
+ }>;
52
+ encounterType: {
53
+ uuid: string;
54
+ display: string;
55
+ };
56
+ obs: Array<OpenmrsResource>;
57
+ orders: Array<OpenmrsResource>;
58
+ }
@@ -0,0 +1,361 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import {
4
+ DataTable,
5
+ Table,
6
+ TableBody,
7
+ TableCell,
8
+ TableContainer,
9
+ TableHead,
10
+ TableHeader,
11
+ TableRow,
12
+ Button,
13
+ } from '@carbon/react';
14
+ import { restBaseUrl, useConfig, useOpenmrsFetchAll, usePagination, usePatient } from '@openmrs/esm-framework';
15
+ import { Pagination, NumericObservation } from '@openmrs/esm-styleguide';
16
+ import {
17
+ useConceptReferenceRanges,
18
+ calculateInterpretation,
19
+ type ObservationInterpretation,
20
+ } from '../hooks/useConceptReferenceRanges';
21
+ import dayjs from 'dayjs';
22
+
23
+ interface VitalsTableProps {
24
+ patientUuid: string;
25
+ visitUuid: string;
26
+ }
27
+
28
+ interface Observation {
29
+ uuid: string;
30
+ concept: {
31
+ uuid: string;
32
+ name: {
33
+ display: string;
34
+ };
35
+ };
36
+ value: number | string | object | null;
37
+ }
38
+
39
+ interface EncounterProvider {
40
+ provider: {
41
+ person: {
42
+ display: string;
43
+ };
44
+ };
45
+ }
46
+
47
+ interface Encounter {
48
+ uuid: string;
49
+ display: string;
50
+ encounterDatetime: string;
51
+ encounterProviders?: EncounterProvider[];
52
+ obs: Observation[];
53
+ }
54
+
55
+ interface EncounterResponse {
56
+ results: Encounter[];
57
+ }
58
+
59
+ const customRepresentation =
60
+ 'custom:(uuid,display,encounterDatetime,encounterProviders:(provider:(person:(display))),obs:(uuid,concept:(uuid,name:(display)),value))';
61
+
62
+ const VitalsTable: React.FC<VitalsTableProps> = ({ patientUuid, visitUuid }) => {
63
+ const { concepts: externalConcepts } = useConfig<{ concepts: Record<string, string> }>({
64
+ externalModuleName: '@openmrs/esm-patient-vitals-app',
65
+ });
66
+ const { concepts: localConcepts } = useConfig<{
67
+ concepts: { hemoglobinUuid: string; glucoseUuid: string; fhrUuid: string; secondFhrUuid: string };
68
+ }>();
69
+ const vitalsConcepts = {
70
+ systolic: externalConcepts.systolicBloodPressureUuid,
71
+ diastolic: externalConcepts.diastolicBloodPressureUuid,
72
+ pulse: externalConcepts.pulseUuid,
73
+ temperature: externalConcepts.temperatureUuid,
74
+ oxygenSaturation: externalConcepts.oxygenSaturationUuid,
75
+ respiratoryRate: externalConcepts.respiratoryRateUuid,
76
+ hemoglobin: localConcepts.hemoglobinUuid,
77
+ glucose: localConcepts.glucoseUuid,
78
+ fhr: localConcepts.fhrUuid,
79
+ secondFhr: localConcepts.secondFhrUuid,
80
+ };
81
+ const { referenceRangeMap } = useConceptReferenceRanges(patientUuid, Object.values(vitalsConcepts));
82
+ const { t } = useTranslation();
83
+ const [showAll, setShowAll] = useState(false);
84
+ const { patient } = usePatient(patientUuid);
85
+
86
+ // Check if patient is less than 30 days old
87
+ const isNewborn = useMemo(() => {
88
+ if (!patient?.birthDate) return false;
89
+ const birthDate = dayjs(patient.birthDate);
90
+ const ageInDays = dayjs().diff(birthDate, 'day');
91
+ return ageInDays < 30;
92
+ }, [patient?.birthDate]);
93
+
94
+ const interpretationLabels: Record<ObservationInterpretation, string> = {
95
+ normal: t('normal', 'Normal'),
96
+ high: t('high', 'High'),
97
+ critically_high: t('criticallyHigh', 'Critically high'),
98
+ off_scale_high: t('offScaleHigh', 'Off scale high'),
99
+ low: t('low', 'Low'),
100
+ critically_low: t('criticallyLow', 'Critically low'),
101
+ off_scale_low: t('offScaleLow', 'Off scale low'),
102
+ };
103
+
104
+ interface VitalCellData {
105
+ value: number | string | object | null;
106
+ interpretation?: ObservationInterpretation;
107
+ conceptUuid?: string;
108
+ }
109
+
110
+ interface VitalRowData {
111
+ id: string;
112
+ date: string;
113
+ bp: { systolic?: VitalCellData; diastolic?: VitalCellData };
114
+ pulse?: VitalCellData;
115
+ temperature?: VitalCellData;
116
+ oxygenSaturation?: VitalCellData;
117
+ respiratoryRate?: VitalCellData;
118
+ hemoglobin?: VitalCellData;
119
+ glucose?: VitalCellData;
120
+ fhr?: VitalCellData;
121
+ secondFhr?: VitalCellData;
122
+ provider?: string;
123
+ }
124
+
125
+ type VitalColumnKey = Exclude<keyof VitalRowData, 'id' | 'date' | 'provider'>;
126
+
127
+ const createVitalCellData = (value: number | string | object | null, conceptUuid?: string): VitalCellData => {
128
+ if (value === null || value === undefined) {
129
+ return { value: null };
130
+ }
131
+
132
+ const numericValue = typeof value === 'object' ? undefined : value;
133
+ const interpretation = conceptUuid
134
+ ? calculateInterpretation(numericValue, referenceRangeMap[conceptUuid])
135
+ : undefined;
136
+
137
+ return {
138
+ value,
139
+ interpretation,
140
+ conceptUuid,
141
+ };
142
+ };
143
+
144
+ const vitalColumns: Array<{ key: VitalColumnKey; label: string; conceptUuid?: string }> = useMemo(() => {
145
+ let columns = [
146
+ { key: 'bp', label: t('bloodPressure', 'BP') },
147
+ { key: 'pulse', label: t('pulse', 'HR'), conceptUuid: vitalsConcepts.pulse },
148
+ { key: 'temperature', label: t('temperature', 'Temp'), conceptUuid: vitalsConcepts.temperature },
149
+ { key: 'respiratoryRate', label: t('respiratoryRate', 'RR'), conceptUuid: vitalsConcepts.respiratoryRate },
150
+ { key: 'oxygenSaturation', label: t('oxygenSaturation', 'O2 Sat'), conceptUuid: vitalsConcepts.oxygenSaturation },
151
+ { key: 'glucose', label: t('glucose', 'Glucose'), conceptUuid: vitalsConcepts.glucose },
152
+ ] as Array<{ key: VitalColumnKey; label: string; conceptUuid?: string }>;
153
+
154
+ // Only include hemoglobin, fhr, and secondFhr for patients 30 days or older
155
+ if (!isNewborn) {
156
+ columns.push(
157
+ { key: 'hemoglobin', label: t('hemoglobin', 'Hb'), conceptUuid: vitalsConcepts.hemoglobin },
158
+ { key: 'fhr', label: t('fetalHeartRate', 'FHR'), conceptUuid: vitalsConcepts.fhr },
159
+ { key: 'secondFhr', label: t('secondFetalHeartRate', '2nd FHR'), conceptUuid: vitalsConcepts.secondFhr },
160
+ );
161
+ }
162
+
163
+ return columns;
164
+ }, [isNewborn, vitalsConcepts, t]);
165
+
166
+ const renderVitalCell = (
167
+ cellData: VitalCellData | { systolic?: VitalCellData; diastolic?: VitalCellData } | undefined,
168
+ ) => {
169
+ if (!cellData) {
170
+ return <span>—</span>;
171
+ }
172
+
173
+ // Handle BP which is an object with systolic and diastolic
174
+ if ('systolic' in cellData) {
175
+ const bpData = cellData as { systolic?: VitalCellData; diastolic?: VitalCellData };
176
+ return (
177
+ <div style={{ display: 'flex', gap: '0', alignItems: 'center' }}>
178
+ {bpData.systolic && (
179
+ <NumericObservation
180
+ value={
181
+ bpData.systolic.value !== null && bpData.systolic.value !== undefined
182
+ ? String(bpData.systolic.value)
183
+ : ''
184
+ }
185
+ interpretation={bpData.systolic.interpretation}
186
+ conceptUuid={bpData.systolic.conceptUuid}
187
+ variant="cell"
188
+ patientUuid={patientUuid}
189
+ />
190
+ )}
191
+ <span style={{ margin: '0 -0.25rem' }}>/</span>
192
+ {bpData.diastolic && (
193
+ <NumericObservation
194
+ value={
195
+ bpData.diastolic.value !== null && bpData.diastolic.value !== undefined
196
+ ? String(bpData.diastolic.value)
197
+ : ''
198
+ }
199
+ interpretation={bpData.diastolic.interpretation}
200
+ conceptUuid={bpData.diastolic.conceptUuid}
201
+ variant="cell"
202
+ patientUuid={patientUuid}
203
+ />
204
+ )}
205
+ </div>
206
+ );
207
+ }
208
+
209
+ // Handle regular vitals
210
+ const vitalData = cellData as VitalCellData;
211
+ if (vitalData.value === null || vitalData.value === undefined) {
212
+ return <span>—</span>;
213
+ }
214
+
215
+ return (
216
+ <NumericObservation
217
+ value={String(vitalData.value)}
218
+ interpretation={vitalData.interpretation}
219
+ conceptUuid={vitalData.conceptUuid}
220
+ variant="cell"
221
+ patientUuid={patientUuid}
222
+ />
223
+ );
224
+ };
225
+
226
+ const createRowData = (encounter: Encounter): VitalRowData => {
227
+ const vitalsMap = encounter.obs.reduce(
228
+ (acc, obs) => {
229
+ acc[obs.concept.uuid] = obs.value;
230
+ return acc;
231
+ },
232
+ {} as Record<string, number | string | object | null>,
233
+ );
234
+
235
+ const providerName = encounter.encounterProviders?.[0]?.provider?.person?.display || '—';
236
+
237
+ return {
238
+ id: encounter.uuid,
239
+ date: dayjs(encounter.encounterDatetime).format('DD/MM/YYYY HH:mm'),
240
+ bp: {
241
+ systolic: createVitalCellData(vitalsMap[vitalsConcepts.systolic]),
242
+ diastolic: createVitalCellData(vitalsMap[vitalsConcepts.diastolic]),
243
+ },
244
+ pulse: createVitalCellData(vitalsMap[vitalsConcepts.pulse]),
245
+ temperature: createVitalCellData(vitalsMap[vitalsConcepts.temperature]),
246
+ oxygenSaturation: createVitalCellData(
247
+ vitalsMap[vitalsConcepts.oxygenSaturation],
248
+ vitalsConcepts.oxygenSaturation,
249
+ ),
250
+ respiratoryRate: createVitalCellData(vitalsMap[vitalsConcepts.respiratoryRate]),
251
+ hemoglobin: createVitalCellData(vitalsMap[vitalsConcepts.hemoglobin]),
252
+ glucose: createVitalCellData(vitalsMap[vitalsConcepts.glucose]),
253
+ fhr: createVitalCellData(vitalsMap[vitalsConcepts.fhr]),
254
+ secondFhr: createVitalCellData(vitalsMap[vitalsConcepts.secondFhr]),
255
+ provider: providerName,
256
+ };
257
+ };
258
+
259
+ const { data: vitalsData, error } = useOpenmrsFetchAll<Encounter>(
260
+ `${restBaseUrl}/encounter?patient=${patientUuid}&visit=${visitUuid}&order=desc&v=${customRepresentation}`,
261
+ );
262
+
263
+ const encounters: Encounter[] = vitalsData || [];
264
+
265
+ // Filter encounters to only include those with vitals observations
266
+ const encountersWithVitals = encounters.filter((encounter) => {
267
+ return encounter.obs.some((obs) => Object.values(vitalsConcepts).includes(obs.concept.uuid));
268
+ });
269
+
270
+ // Process each encounter to extract vital signs
271
+ const tableRows = useMemo(
272
+ () => encountersWithVitals.map(createRowData),
273
+ [encountersWithVitals, vitalsConcepts, referenceRangeMap],
274
+ );
275
+
276
+ const pageSize = 5;
277
+ const { results: paginatedVitals, currentPage, goTo } = usePagination(tableRows, pageSize);
278
+
279
+ const displayedRows = showAll ? tableRows : paginatedVitals;
280
+
281
+ if (error) {
282
+ return <div>{t('errorLoadingVitals', 'Error loading vitals')}</div>;
283
+ }
284
+
285
+ if (!vitalsData) {
286
+ return <div>{t('loadingVitals', 'Loading vitals...')}</div>;
287
+ }
288
+
289
+ const tableHeaders = [
290
+ { key: 'date', header: t('date', 'Date') },
291
+ ...vitalColumns.map((col) => ({ key: col.key, header: col.label })),
292
+ { key: 'provider', header: t('provider', 'Provider') },
293
+ ];
294
+
295
+ return (
296
+ <>
297
+ <DataTable headers={tableHeaders} rows={displayedRows} size="sm" useZebraStyles>
298
+ {({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => (
299
+ <TableContainer>
300
+ <Table {...getTableProps()}>
301
+ <TableHead>
302
+ <TableRow>
303
+ {headers.map((header) => (
304
+ <TableHeader {...getHeaderProps({ header })} key={header.key}>
305
+ {header.header}
306
+ </TableHeader>
307
+ ))}
308
+ </TableRow>
309
+ </TableHead>
310
+ <TableBody>
311
+ {rows.map((row) => {
312
+ const rowData = displayedRows.find((r) => r.id === row.id) as VitalRowData | undefined;
313
+
314
+ return (
315
+ <TableRow {...getRowProps({ row })} key={row.id}>
316
+ {row.cells.map((cell) => {
317
+ if (cell.info.header === 'date' || cell.info.header === 'provider') {
318
+ return <TableCell key={cell.id}>{cell.value}</TableCell>;
319
+ }
320
+
321
+ const columnKey = cell.info.header as VitalColumnKey;
322
+ const cellValue = rowData?.[columnKey];
323
+
324
+ return (
325
+ <TableCell key={cell.id} style={{ padding: 0 }}>
326
+ {renderVitalCell(cellValue)}
327
+ </TableCell>
328
+ );
329
+ })}
330
+ </TableRow>
331
+ );
332
+ })}
333
+ </TableBody>
334
+ </Table>
335
+ </TableContainer>
336
+ )}
337
+ </DataTable>
338
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: '1rem' }}>
339
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', marginLeft: '1rem' }}>
340
+ <span style={{ fontSize: '0.875rem', color: '#6f6f6f' }}>
341
+ {displayedRows.length} / {tableRows.length} {t('items', 'items')}
342
+ </span>
343
+ <Button kind="ghost" size="sm" onClick={() => setShowAll(!showAll)}>
344
+ {showAll ? t('showPaginated', 'Show Paginated') : t('showAll', 'Show All')}
345
+ </Button>
346
+ </div>
347
+ {!showAll && (
348
+ <Pagination
349
+ pageNumber={currentPage}
350
+ totalItems={tableRows.length}
351
+ currentItems={paginatedVitals.length}
352
+ pageSize={pageSize}
353
+ onPageNumberChange={({ page }) => goTo(page)}
354
+ />
355
+ )}
356
+ </div>
357
+ </>
358
+ );
359
+ };
360
+
361
+ export default VitalsTable;