@ampath/esm-reports-app 1.0.0-next.112 → 1.0.0-next.113

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 (37) hide show
  1. package/dist/248.css +1 -0
  2. package/dist/248.css.map +1 -0
  3. package/dist/248.js +1 -0
  4. package/dist/248.js.map +1 -0
  5. package/dist/410.js +1 -1
  6. package/dist/ampath-esm-reports-app.js +1 -1
  7. package/dist/routes.json +1 -1
  8. package/package.json +1 -1
  9. package/src/common/report-header/facility-clinics.component.tsx +42 -0
  10. package/src/common/report-header/facility-clinics.scss +61 -0
  11. package/src/common/report-header/index.ts +1 -0
  12. package/src/common/report-page/download-sheet-pdf.ts +2 -0
  13. package/src/common/report-register/index.ts +1 -0
  14. package/src/common/report-register/register-layout.component.tsx +3 -26
  15. package/src/common/report-register/register-layout.scss +0 -58
  16. package/src/common/report-register/xlsx.ts +263 -0
  17. package/src/dashboard/report-catalog.ts +39 -145
  18. package/src/dashboard/reports-dasboard.tsx +5 -4
  19. package/src/reports/program/care-and-treatment/care-and-treatment-linelist.component.tsx +87 -0
  20. package/src/reports/program/care-and-treatment/care-and-treatment-table.component.tsx +1 -1
  21. package/src/reports/program/care-and-treatment/care-and-treatment.component.tsx +122 -59
  22. package/src/reports/program/care-and-treatment/care-and-treatment.config.ts +120 -2
  23. package/src/reports/program/program-report.component.tsx +11 -5
  24. package/src/reports/quality-improvement/case-surveillance.component.tsx +258 -0
  25. package/src/reports/quality-improvement/case-surveillance.config.ts +57 -0
  26. package/src/reports/quality-improvement/case-surveillance.scss +305 -0
  27. package/src/reports/quality-improvement/quality-improvement-linelist.component.tsx +137 -0
  28. package/src/reports/quality-improvement/quality-improvement.component.tsx +217 -0
  29. package/src/reports/quality-improvement/quality-improvement.config.ts +144 -0
  30. package/src/reports/quality-improvement/quality-improvement.scss +227 -0
  31. package/src/resources/care-and-treatment.resource.ts +1 -1
  32. package/src/resources/quality-improvement.resource.ts +91 -0
  33. package/src/root.component.tsx +27 -14
  34. package/dist/955.css +0 -1
  35. package/dist/955.css.map +0 -1
  36. package/dist/955.js +0 -1
  37. package/dist/955.js.map +0 -1
@@ -0,0 +1,305 @@
1
+ @use '@carbon/layout';
2
+ @use '@carbon/type';
3
+ @use '@openmrs/esm-styleguide/src/vars' as *;
4
+
5
+ /* a card's status colour, and an ink dark enough for text on its tint */
6
+ $good: #24a148;
7
+ $good-ink: #0e6027;
8
+ $alert: #da1e28;
9
+ $alert-ink: #a2191f;
10
+ $figure: #0f62fe;
11
+
12
+ .sheet {
13
+ margin: layout.$spacing-05 0;
14
+ padding: layout.$spacing-06;
15
+ background-color: $ui-02;
16
+ border: 1px solid $ui-03;
17
+ }
18
+
19
+ /* the title, facility and period, as on the Quality Improvement Report */
20
+ .masthead {
21
+ display: flex;
22
+ flex-wrap: wrap;
23
+ align-items: center;
24
+ justify-content: space-between;
25
+ gap: layout.$spacing-03 layout.$spacing-07;
26
+ padding-bottom: layout.$spacing-04;
27
+ margin-bottom: layout.$spacing-04;
28
+ border-bottom: 1px solid $ui-03;
29
+ }
30
+
31
+ .title {
32
+ @include type.type-style('productive-heading-02');
33
+ color: $color-gray-100;
34
+ }
35
+
36
+ .subtitle {
37
+ @include type.type-style('label-01');
38
+ margin-top: layout.$spacing-01;
39
+ color: $text-02;
40
+ }
41
+
42
+ .meta {
43
+ @include type.type-style('label-01');
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: layout.$spacing-03;
47
+ }
48
+
49
+ .metaItem {
50
+ display: inline-flex;
51
+ align-items: center;
52
+ gap: layout.$spacing-02;
53
+ padding: layout.$spacing-01 layout.$spacing-03;
54
+ font-weight: 600;
55
+ color: $color-gray-100;
56
+ background-color: $ui-01;
57
+ border-radius: 1rem;
58
+
59
+ svg {
60
+ fill: $text-02;
61
+ }
62
+ }
63
+
64
+ /* Realtime gap review / Progress tracker: the selected one underlined in the brand colour */
65
+ .tabs {
66
+ :global(.cds--tabs__nav-item) {
67
+ padding: 0 layout.$spacing-05;
68
+ border-bottom: 2px solid $ui-03;
69
+ }
70
+
71
+ :global(.cds--tabs__nav-item--selected) {
72
+ font-weight: 600;
73
+ border-bottom-color: var(--brand-01);
74
+ }
75
+
76
+ :global(.cds--tabs__nav-item:focus) {
77
+ outline: none;
78
+ }
79
+
80
+ :global(.cds--tabs__nav-item:focus-visible) {
81
+ outline: 2px solid var(--brand-01);
82
+ outline-offset: -2px;
83
+ }
84
+ }
85
+
86
+ .panel {
87
+ padding: layout.$spacing-05 0 0;
88
+ }
89
+
90
+ /* each card and progress row takes its status colour */
91
+ .good {
92
+ --status: #{$good};
93
+ --status-ink: #{$good-ink};
94
+ }
95
+
96
+ .alert {
97
+ --status: #{$alert};
98
+ --status-ink: #{$alert-ink};
99
+ }
100
+
101
+ /* the gap review: three cards to a row, fewer on narrower screens */
102
+ .cardGrid {
103
+ display: grid;
104
+ grid-template-columns: repeat(3, minmax(0, 1fr));
105
+ gap: layout.$spacing-04;
106
+ }
107
+
108
+ /* a card: its status as a pill, and the gap's share */
109
+ .card {
110
+ display: flex;
111
+ flex-direction: column;
112
+ gap: layout.$spacing-03;
113
+ padding: layout.$spacing-04 layout.$spacing-05;
114
+ background-color: $ui-02;
115
+ border: 1px solid $ui-03;
116
+ border-radius: 0.375rem;
117
+ transition: box-shadow 110ms;
118
+
119
+ &:hover {
120
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
121
+ }
122
+ }
123
+
124
+ .cardHeader {
125
+ display: flex;
126
+ align-items: flex-start;
127
+ justify-content: space-between;
128
+ gap: layout.$spacing-03;
129
+ }
130
+
131
+ .cardTitle {
132
+ @include type.type-style('body-compact-01');
133
+ font-weight: 600;
134
+ color: $color-gray-100;
135
+ }
136
+
137
+ .status {
138
+ @include type.type-style('label-01');
139
+ flex: none;
140
+ padding: 0 layout.$spacing-03;
141
+ font-weight: 600;
142
+ line-height: 1.25rem;
143
+ white-space: nowrap;
144
+ color: var(--status-ink);
145
+ background-color: color-mix(in srgb, var(--status) 12%, #{$ui-02});
146
+ border-radius: 1rem;
147
+ }
148
+
149
+ .cardValue {
150
+ display: flex;
151
+ align-items: baseline;
152
+ justify-content: space-between;
153
+ gap: layout.$spacing-03;
154
+ }
155
+
156
+ .figures {
157
+ display: inline-flex;
158
+ align-items: baseline;
159
+ gap: layout.$spacing-02;
160
+ }
161
+
162
+ .figure {
163
+ @include type.type-style('heading-compact-02');
164
+ padding: 0;
165
+ font-variant-numeric: tabular-nums;
166
+ background: none;
167
+ border: 0;
168
+ }
169
+
170
+ .numerator {
171
+ color: $figure;
172
+ }
173
+
174
+ .denominator {
175
+ color: $text-02;
176
+ }
177
+
178
+ button.figure {
179
+ cursor: pointer;
180
+
181
+ &:hover {
182
+ text-decoration: underline;
183
+ }
184
+ }
185
+
186
+ .slash {
187
+ @include type.type-style('body-compact-01');
188
+ color: $ui-04;
189
+ }
190
+
191
+ .percent {
192
+ @include type.type-style('heading-compact-01');
193
+ font-variant-numeric: tabular-nums;
194
+ color: var(--status-ink);
195
+ }
196
+
197
+ .gapTrack {
198
+ height: 0.25rem;
199
+ overflow: hidden;
200
+ background-color: $ui-01;
201
+ border-radius: 0.125rem;
202
+ }
203
+
204
+ .gapBar {
205
+ height: 100%;
206
+ background-color: var(--status);
207
+ border-radius: 0.125rem;
208
+ }
209
+
210
+ .cardDescription {
211
+ @include type.type-style('helper-text-01');
212
+ color: $text-02;
213
+ }
214
+
215
+ /* the progress tracker: what has been done, out of the clients each card applies to */
216
+ .progressList {
217
+ border: 1px solid $ui-03;
218
+ border-radius: 0.375rem;
219
+ }
220
+
221
+ .progressRow {
222
+ display: grid;
223
+ grid-template-columns: minmax(12rem, 20rem) 1fr 3.5rem;
224
+ align-items: center;
225
+ gap: layout.$spacing-05;
226
+ padding: layout.$spacing-04 layout.$spacing-05;
227
+
228
+ & + & {
229
+ border-top: 1px solid $ui-03;
230
+ }
231
+ }
232
+
233
+ .progressLabel {
234
+ display: flex;
235
+ flex-direction: column;
236
+ gap: layout.$spacing-01;
237
+ }
238
+
239
+ .progressTitle {
240
+ @include type.type-style('body-compact-01');
241
+ font-weight: 600;
242
+ color: $color-gray-100;
243
+ }
244
+
245
+ .progressCount {
246
+ @include type.type-style('helper-text-01');
247
+ color: $text-02;
248
+
249
+ strong {
250
+ font-weight: 600;
251
+ color: $color-gray-100;
252
+ }
253
+ }
254
+
255
+ .track {
256
+ height: 0.25rem;
257
+ overflow: hidden;
258
+ background-color: $ui-01;
259
+ border-radius: 0.125rem;
260
+ }
261
+
262
+ .bar {
263
+ height: 100%;
264
+ background-color: var(--status);
265
+ border-radius: 0.125rem;
266
+ }
267
+
268
+ .progressPercent {
269
+ @include type.type-style('heading-compact-01');
270
+ text-align: right;
271
+ font-variant-numeric: tabular-nums;
272
+ color: var(--status-ink);
273
+ }
274
+
275
+ .note {
276
+ @include type.type-style('label-01');
277
+ padding-top: layout.$spacing-04;
278
+ margin-top: layout.$spacing-05;
279
+ color: $text-02;
280
+ border-top: 1px solid $ui-03;
281
+ }
282
+
283
+ @media (max-width: 66rem) {
284
+ .cardGrid {
285
+ grid-template-columns: repeat(2, minmax(0, 1fr));
286
+ }
287
+ }
288
+
289
+ @media (max-width: 42rem) {
290
+ .sheet {
291
+ padding: layout.$spacing-05 layout.$spacing-04;
292
+ }
293
+
294
+ .cardGrid {
295
+ grid-template-columns: minmax(0, 1fr);
296
+ }
297
+
298
+ .progressRow {
299
+ grid-template-columns: 1fr 3.5rem;
300
+ }
301
+
302
+ .progressLabel {
303
+ grid-column: 1 / -1;
304
+ }
305
+ }
@@ -0,0 +1,137 @@
1
+ import React from 'react';
2
+ import { useSearchParams } from 'react-router-dom';
3
+
4
+ import { type LinelistColumn, LinelistTable, useAllRows } from '../../common/linelist-table';
5
+ import { RegisterLayout, useLocationName } from '../../common/report-register';
6
+ import { useFacility } from '../../common/report-header';
7
+ import { getQualityImprovementPatientList } from '../../resources/quality-improvement.resource';
8
+ import { QUALITY_IMPROVEMENT_PATH } from './quality-improvement.config';
9
+ import { CASE_SURVEILLANCE_PATH } from './case-surveillance.config';
10
+
11
+ const formatDate = (value: unknown) => (value ? new Date(String(value)).toLocaleDateString('en-GB') : '');
12
+
13
+ const date = (header: string, field: string): LinelistColumn => ({
14
+ header,
15
+ value: (row) => formatDate(row[field]),
16
+ sortValue: (row) => row[field],
17
+ });
18
+
19
+ const COMMON: LinelistColumn[] = [
20
+ { header: 'Name', field: 'full_name' },
21
+ { header: 'CCC Number', field: 'ccc_number', text: true },
22
+ { header: 'AMRS Number', field: 'amrs_number', text: true },
23
+ { header: 'Sex', field: 'gender' },
24
+ { header: 'Age', field: 'age' },
25
+ { header: 'Clinic', field: 'location' },
26
+ ];
27
+
28
+ const VIRAL_LOAD = [{ header: 'Last Viral Load', field: 'last_vl' }, date('Last VL Date', 'last_vl_date')];
29
+
30
+ const HEI = [
31
+ { header: 'Name', field: 'full_name' },
32
+ { header: 'HEI Number', field: 'hei_number', text: true },
33
+ { header: 'AMRS Number', field: 'amrs_number', text: true },
34
+ { header: 'Sex', field: 'gender' },
35
+ date('Birth Date', 'birth_date'),
36
+ { header: 'Clinic', field: 'location' },
37
+ date('Last Visit', 'last_visit_date'),
38
+ ];
39
+
40
+ /** Each indicator's columns: who the clients are, and what needs doing */
41
+ const COLUMNS: Record<string, LinelistColumn[]> = {
42
+ 'hiv-positive-not-linked': [...COMMON, date('HIV Test Date', 'test_date')],
43
+ 'high-risk-pbf-not-on-prep': [
44
+ ...COMMON,
45
+ { header: 'PrEP Number', field: 'prep_number', text: true },
46
+ date('Screening Date', 'screening_date'),
47
+ ],
48
+ 'pns-undocumented-status': [
49
+ { header: 'Index Client', field: 'full_name' },
50
+ { header: 'CCC Number', field: 'ccc_number', text: true },
51
+ { header: 'Clinic', field: 'location' },
52
+ { header: 'Contact', field: 'contact_name' },
53
+ { header: 'Relationship', field: 'relationship' },
54
+ { header: 'Contact Age', field: 'contact_age' },
55
+ { header: 'Contact Sex', field: 'contact_sex' },
56
+ { header: 'Contact Phone', field: 'contact_phone', text: true },
57
+ date('Date Elicited', 'date_elicited'),
58
+ ],
59
+ 'missed-vl-testing': [...COMMON, date('Last Visit', 'last_visit_date'), ...VIRAL_LOAD],
60
+ 'viral-load-200-plus': [...COMMON, ...VIRAL_LOAD],
61
+ 'viral-load-1000-plus': [...COMMON, ...VIRAL_LOAD],
62
+ 'delayed-eac': [...COMMON, ...VIRAL_LOAD, { header: 'Days Since VL', field: 'days_since_vl' }],
63
+ 'recent-defaulters': [
64
+ ...COMMON,
65
+ date('Last Visit', 'last_visit_date'),
66
+ date('Missed Appointment', 'rtc_date'),
67
+ { header: 'Days Missed', field: 'days_missed' },
68
+ ],
69
+ 'adolescent-not-in-otz': [...COMMON, date('Last Visit', 'last_visit_date')],
70
+ 'hei-without-dna-pcr': HEI,
71
+ 'hei-not-linked-to-mother': HEI,
72
+ 'hei-without-outcome': HEI,
73
+ /* the Case Surveillance cards' other figures */
74
+ 'cs-new-positives': [...COMMON, date('HIV Test Date', 'test_date')],
75
+ 'cs-high-risk-pbfw': [
76
+ ...COMMON,
77
+ { header: 'PrEP Number', field: 'prep_number', text: true },
78
+ date('Screening Date', 'screening_date'),
79
+ ],
80
+ 'cs-unsuppressed': [...COMMON, ...VIRAL_LOAD, { header: 'Days Since VL', field: 'days_since_vl' }],
81
+ 'cs-visited-due-for-vl': [...COMMON, date('Last Visit', 'last_visit_date'), ...VIRAL_LOAD],
82
+ 'cs-hei-6-8-weeks': HEI,
83
+ 'cs-hei-24-months': HEI,
84
+ 'cs-hei-24-months-without-outcome': HEI,
85
+ };
86
+
87
+ /* the report a list was opened from, which its breadcrumb leads back to */
88
+ const PARENTS = {
89
+ 'case-surveillance': { label: 'Case Surveillance Report', path: CASE_SURVEILLANCE_PATH, title: 'Case Surveillance' },
90
+ 'quality-improvement': {
91
+ label: 'Quality Improvement Report',
92
+ path: QUALITY_IMPROVEMENT_PATH,
93
+ title: 'Quality Improvement',
94
+ },
95
+ };
96
+
97
+ /** The clients of one Quality Improvement or Case Surveillance figure (`i`) for the period */
98
+ const QualityImprovementLinelist: React.FC = () => {
99
+ const [searchParams] = useSearchParams();
100
+ const startDate = searchParams.get('startDate') ?? '';
101
+ const endDate = searchParams.get('endDate') ?? '';
102
+ const locationUuids = searchParams.get('locationUuids') ?? '';
103
+ const indicator = searchParams.get('i') ?? '';
104
+ const heading = `${searchParams.get('label') ?? 'Clients'} linelist`;
105
+ const parent =
106
+ searchParams.get('from') === 'case-surveillance' ? PARENTS['case-surveillance'] : PARENTS['quality-improvement'];
107
+
108
+ /* the clients come from the whole facility, so it is named by its parent location, with its clinics */
109
+ const facility = useFacility(locationUuids, useLocationName(locationUuids));
110
+ const { rows, isLoading } = useAllRows(
111
+ ({ startIndex, limit }) =>
112
+ getQualityImprovementPatientList({ locationUuids, startDate, endDate, indicator, startIndex, limit }),
113
+ [searchParams.toString()],
114
+ );
115
+
116
+ return (
117
+ <RegisterLayout
118
+ parentLabel={parent.label}
119
+ parentPath={parent.path}
120
+ title={parent.title}
121
+ heading={heading}
122
+ location={facility.name}
123
+ locationClinics={facility.clinics}
124
+ isLoading={isLoading}
125
+ isEmpty={rows.length === 0}
126
+ >
127
+ <LinelistTable
128
+ rows={rows}
129
+ columns={COLUMNS[indicator] ?? COMMON}
130
+ layoutKey={`quality-improvement:${indicator}`}
131
+ exportName={`${parent.title} ${heading} ${endDate}`}
132
+ />
133
+ </RegisterLayout>
134
+ );
135
+ };
136
+
137
+ export default QualityImprovementLinelist;
@@ -0,0 +1,217 @@
1
+ import React, { useCallback, useRef, useState } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+ import dayjs from 'dayjs';
4
+ import { Layer } from '@carbon/react';
5
+ import { Calendar, Location } from '@carbon/react/icons';
6
+ import { useSession } from '@openmrs/esm-framework';
7
+
8
+ import { ReportFiltersComponent, type ReportPeriod, useRestorePeriod } from '../../common/report-filters';
9
+ import { downloadSheetsPdf } from '../../common/report-page';
10
+ import { showReportError } from '../../common/report-error';
11
+ import { ReportPlaceholder, useGeneratedLocation } from '../../common/report-placeholder';
12
+ import { ReportSkeleton } from '../../common/report-skeleton';
13
+ import { FacilityClinics, useFacility } from '../../common/report-header';
14
+ import { type ReportDefinition } from '../../dashboard/report-catalog';
15
+ import { getQualityImprovement, type QualityImprovementCounts } from '../../resources/quality-improvement.resource';
16
+ import {
17
+ QUALITY_AREAS,
18
+ QUALITY_IMPROVEMENT_LINELIST_PATH,
19
+ type QualityArea,
20
+ type QualityIndicator,
21
+ } from './quality-improvement.config';
22
+ import styles from './quality-improvement.scss';
23
+
24
+ interface QualityImprovementReportProps {
25
+ report: ReportDefinition;
26
+ }
27
+
28
+ /**
29
+ * Quality Improvement Report (Reports tab → Quality Improvement Reports): for
30
+ * the month chosen, at the session location's whole facility, how many
31
+ * clients need each action -- linking, PrEP, partner testing, viral load,
32
+ * adherence, tracing, OTZ and the HEI follow-ups -- by area. Each count opens
33
+ * the list of its clients.
34
+ */
35
+ const QualityImprovementReport: React.FC<QualityImprovementReportProps> = ({ report }) => {
36
+ const [result, setResult] = useState<QualityImprovementCounts | null>(null);
37
+ const counts = result?.counts ?? null;
38
+ const [isLoading, setIsLoading] = useState(false);
39
+ const [period, setPeriod] = useState<{ startDate: string; endDate: string }>({ startDate: '', endDate: '' });
40
+ const sheetRef = useRef<HTMLElement>(null);
41
+ const navigate = useNavigate();
42
+
43
+ const session = useSession();
44
+ const locationUuids = session?.sessionLocation?.uuid ?? '';
45
+ /* the counts cover the session location's whole facility, so it is named by its parent location (MTRH) */
46
+ const facilityDetails = useFacility(locationUuids, session?.sessionLocation?.display ?? '');
47
+ const facility = facilityDetails.name;
48
+ const { isForCurrentLocation, hasLocationChanged, markGenerated } =
49
+ useGeneratedLocation('qualityImprovementLocation');
50
+ const isReportGenerated = counts !== null && isForCurrentLocation;
51
+
52
+ const generate = useCallback(
53
+ async ({ startDate, endDate }: ReportPeriod) => {
54
+ setIsLoading(true);
55
+ setPeriod({ startDate, endDate });
56
+ try {
57
+ setResult(await getQualityImprovement({ locationUuids, startDate, endDate }));
58
+ markGenerated(locationUuids);
59
+ } catch (error) {
60
+ showReportError('the Quality Improvement report', error);
61
+ } finally {
62
+ setIsLoading(false);
63
+ }
64
+ },
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ [locationUuids],
67
+ );
68
+
69
+ useRestorePeriod(generate);
70
+
71
+ const open = (indicator: QualityIndicator) => {
72
+ const params = new URLSearchParams({
73
+ i: indicator.id,
74
+ label: indicator.name,
75
+ startDate: period.startDate,
76
+ endDate: period.endDate,
77
+ locationUuids,
78
+ });
79
+ navigate(`${QUALITY_IMPROVEMENT_LINELIST_PATH}?${params}`);
80
+ };
81
+
82
+ /* the period, as the filter bar names it: `October 2026`, or its dates */
83
+ const isWholeMonth =
84
+ Boolean(period.startDate) &&
85
+ dayjs(period.startDate).isSame(dayjs(period.startDate).startOf('month'), 'day') &&
86
+ dayjs(period.endDate).isSame(dayjs(period.startDate).endOf('month'), 'day');
87
+ const periodLabel = !period.endDate
88
+ ? ''
89
+ : isWholeMonth
90
+ ? dayjs(period.endDate).format('MMMM YYYY')
91
+ : `${dayjs(period.startDate).format('DD-MMM-YYYY')} to ${dayjs(period.endDate).format('DD-MMM-YYYY')}`;
92
+ /* the month's end the status counts are for, when it is not the period's own */
93
+ const statusMonth = result?.statusMonth ? dayjs(result.statusMonth).format('DD-MMM-YYYY') : '';
94
+ const statusIsPeriodEnd = Boolean(result?.statusMonth) && result?.statusMonth === period.endDate;
95
+ const fileName = [
96
+ 'Quality-Improvement',
97
+ facility,
98
+ isWholeMonth ? period.endDate.slice(0, 7) : `${period.startDate}_${period.endDate}`,
99
+ ]
100
+ .filter(Boolean)
101
+ .join('_')
102
+ .replace(/[^a-z0-9_-]+/gi, '-');
103
+
104
+ const countOf = (indicator: QualityIndicator) => (indicator.pending ? null : Number(counts?.[indicator.id] ?? 0));
105
+
106
+ /* Download PDF saves the sheet as one A4 page */
107
+ const downloadPdf = async () => {
108
+ if (sheetRef.current) {
109
+ await downloadSheetsPdf([sheetRef.current], `${fileName}.pdf`);
110
+ }
111
+ };
112
+
113
+ const renderCount = (indicator: QualityIndicator) => {
114
+ const amount = countOf(indicator);
115
+ if (amount === null) {
116
+ return <span className={styles.pending}>Not available</span>;
117
+ }
118
+ if (amount === 0) {
119
+ return <span className={styles.none}>0</span>;
120
+ }
121
+ return (
122
+ <button
123
+ type="button"
124
+ className={styles.count}
125
+ onClick={() => open(indicator)}
126
+ title={`List the ${amount.toLocaleString()} clients`}
127
+ >
128
+ {amount.toLocaleString()}
129
+ </button>
130
+ );
131
+ };
132
+
133
+ const renderArea = (area: QualityArea) => (
134
+ <tbody key={area.id} data-tone={area.tone}>
135
+ {area.indicators.map((indicator, index) => (
136
+ <tr key={indicator.id}>
137
+ {index === 0 && (
138
+ <th scope="rowgroup" rowSpan={area.indicators.length} className={styles.areaCell}>
139
+ <span className={styles.areaName}>{area.title}</span>
140
+ <span className={styles.areaDescription}>{area.description}</span>
141
+ </th>
142
+ )}
143
+ <td className={styles.codeCell}>
144
+ <span className={styles.code}>{indicator.code}</span>
145
+ </td>
146
+ <th scope="row" className={styles.indicatorCell}>
147
+ <span className={styles.indicatorName}>{indicator.name}</span>
148
+ <span className={styles.indicatorDescription}>{indicator.description}</span>
149
+ </th>
150
+ <td className={styles.countCell}>{renderCount(indicator)}</td>
151
+ </tr>
152
+ ))}
153
+ </tbody>
154
+ );
155
+
156
+ return (
157
+ <>
158
+ <ReportFiltersComponent
159
+ reportName={report.name}
160
+ /* a month, or any dates: the indicators of a client's status on ART
161
+ read the end of the month the period ends in */
162
+ mode="both"
163
+ defaultTab="monthly"
164
+ onGenerate={generate}
165
+ isLoading={isLoading}
166
+ isReportGenerated={isReportGenerated}
167
+ generatedPeriod={period}
168
+ onDownloadPdf={downloadPdf}
169
+ backLink={{ label: 'Quality Improvement Reports', to: '/?group=quality-improvement' }}
170
+ />
171
+ {isLoading && <ReportSkeleton blocks={2} />}
172
+ {!isLoading && !isReportGenerated && (
173
+ <ReportPlaceholder reportName={report.name} isLocationChanged={counts !== null && hasLocationChanged} />
174
+ )}
175
+ {!isLoading && isReportGenerated && (
176
+ <Layer as="section" className={styles.sheet} ref={sheetRef}>
177
+ <header className={styles.masthead}>
178
+ <div>
179
+ <h4 className={styles.title}>Quality Improvement Report</h4>
180
+ <p className={styles.subtitle}>Clients needing action, by area. Select a count to list its clients.</p>
181
+ </div>
182
+ <p className={styles.meta}>
183
+ <span className={styles.metaItem}>
184
+ <Location size={14} />
185
+ <FacilityClinics name={facility} clinics={facilityDetails.clinics} />
186
+ </span>
187
+ <span className={styles.metaItem}>
188
+ <Calendar size={14} />
189
+ {periodLabel}
190
+ </span>
191
+ </p>
192
+ </header>
193
+ <table className={styles.table} aria-label="Quality improvement indicators">
194
+ <thead>
195
+ <tr>
196
+ <th scope="col">Area</th>
197
+ <th scope="col">Code</th>
198
+ <th scope="col">Indicator</th>
199
+ <th scope="col" className={styles.countHead}>
200
+ Clients
201
+ </th>
202
+ </tr>
203
+ </thead>
204
+ {QUALITY_AREAS.map(renderArea)}
205
+ </table>
206
+ <p className={styles.note}>
207
+ Counts are for the whole facility. Viral load, EAC, defaulter and OTZ counts are each client&rsquo;s status
208
+ on ART at the month&rsquo;s end{statusIsPeriodEnd ? '' : ` (${statusMonth})`}; the rest are for the period.
209
+ The VL ≥200 count includes those of 1000 and over.
210
+ </p>
211
+ </Layer>
212
+ )}
213
+ </>
214
+ );
215
+ };
216
+
217
+ export default QualityImprovementReport;