@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
@@ -220,7 +220,7 @@ export const reportCategories: ReportCategory[] = [
220
220
 
221
221
  /**
222
222
  * The Reports tab's groups, each with its own categories. The Ministry of
223
- * Health summary forms above make up the first; program and action summary
223
+ * Health summary forms above make up the first; program and quality improvement
224
224
  * reports go in theirs as they are built.
225
225
  */
226
226
  export interface ReportGroup {
@@ -308,157 +308,51 @@ export const reportGroups: ReportGroup[] = [
308
308
  ],
309
309
  },
310
310
  {
311
- id: 'action-summary',
312
- title: 'Action summary reports',
313
- shortTitle: 'Action summary',
311
+ id: 'quality-improvement',
312
+ title: 'Quality Improvement Reports',
313
+ shortTitle: 'Quality improvement',
314
314
  description: 'Clients due for follow-up or action',
315
- /* each opens on the shared report template page (src/reports/program)
316
- until its own template is built */
317
315
  categories: [
318
316
  {
319
- id: 'testing-and-linkage',
320
- title: 'Testing & linkage',
321
- description: 'Clients to link to care or prevention',
317
+ id: 'gap-reviews',
318
+ title: 'Gap reviews',
319
+ description: 'Clients due for follow-up or action',
322
320
  tone: 'teal',
323
321
  reports: [
324
322
  {
325
- code: 'LINKAGE',
326
- name: 'HIV positive not linked',
323
+ code: 'QI',
324
+ name: 'Quality Improvement Report',
327
325
  description:
328
- 'Individuals diagnosed with HIV who have not been successfully enrolled or linked to care and treatment services.',
329
- path: '/action-summary/hiv-positive-not-linked',
330
- icon: UserMultiple,
331
- keywords: ['linkage', 'linked', 'positive', 'enrolment', 'hts'],
332
- },
333
- {
334
- code: 'PBF PrEP',
335
- name: 'High risk -ve PBFs not on PrEP',
336
- description:
337
- 'High-risk HIV-negative individuals (such as partners in serodiscordant relationships or key populations) identified through Partner/Client Index Testing (PBF) who are not on Pre-Exposure Prophylaxis (PrEP).',
338
- path: '/action-summary/high-risk-pbf-not-on-prep',
339
- icon: HealthCross,
340
- keywords: ['prep', 'pbf', 'pbfw', 'negative', 'high risk', 'serodiscordant', 'index'],
341
- },
342
- {
343
- code: 'PNS',
344
- name: 'PNS contacts with undocumented HIV status',
345
- description:
346
- 'Partner Notification Services (PNS) contacts whose HIV test status has not yet been documented.',
347
- path: '/action-summary/pns-undocumented-status',
348
- icon: UserMultiple,
349
- keywords: ['pns', 'contacts', 'partner', 'notification', 'index', 'undocumented', 'status'],
350
- },
351
- {
352
- code: 'SNS',
353
- name: 'SNS contacts with undocumented HIV status',
354
- description: 'Social Network Strategy (SNS) contacts whose HIV test status has not yet been documented.',
355
- path: '/action-summary/sns-undocumented-status',
356
- icon: UserMultiple,
357
- keywords: ['sns', 'contacts', 'social network', 'strategy', 'undocumented', 'status'],
358
- },
359
- ],
360
- },
361
- {
362
- id: 'viral-load',
363
- title: 'Viral load',
364
- description: 'Clients to test or support to suppression',
365
- tone: 'violet',
366
- reports: [
367
- {
368
- code: 'VL TEST',
369
- name: 'Missed opportunity in VL testing',
370
- description:
371
- 'Clients who are due for a routine or targeted viral load test but did not have the sample collected.',
372
- path: '/action-summary/missed-vl-testing',
373
- icon: Microscope,
374
- keywords: ['vl', 'viral load', 'missed', 'due', 'sample'],
375
- },
376
- {
377
- code: 'VL ≥200',
378
- name: 'Current on ART with VL ≥ 200',
379
- description:
380
- 'Patients actively on antiretroviral therapy whose viral load result is 200 copies/mL or more (unsuppressed, needing EAC). Includes those of 1000 or more.',
381
- path: '/action-summary/viral-load-200-plus',
382
- icon: Microscope,
383
- keywords: ['vl', 'viral load', 'unsuppressed', '200', 'eac', 'art', 'high vl'],
384
- },
385
- {
386
- code: 'VL ≥1000',
387
- name: 'Current on ART with VL ≥ 1000',
388
- description:
389
- 'Patients actively on antiretroviral therapy whose viral load result is 1000 copies/mL or more (indicating virological failure).',
390
- path: '/action-summary/viral-load-1000-plus',
391
- icon: Microscope,
392
- keywords: ['vl', 'viral load', 'unsuppressed', '1000', 'failure', 'art', 'high vl'],
393
- },
394
- {
395
- code: 'EAC',
396
- name: 'Delayed enhanced adherence counselling (EAC)',
397
- description:
398
- 'Patients with elevated viral loads who experience delays in receiving intensive adherence support sessions.',
399
- path: '/action-summary/delayed-eac',
400
- icon: Warning,
401
- keywords: ['eac', 'adherence', 'counselling', 'delayed', 'viral load'],
402
- },
403
- ],
404
- },
405
- {
406
- id: 'retention',
407
- title: 'Retention',
408
- description: 'Clients to trace or enrol in support',
409
- tone: 'blue',
410
- reports: [
411
- {
412
- code: 'DEFAULTERS',
413
- name: 'Recent defaulters (missed app < 30 days)',
414
- description:
415
- 'Patients who missed their scheduled clinic appointment by less than 30 days and require tracing.',
416
- path: '/action-summary/recent-defaulters',
417
- icon: Warning,
418
- keywords: ['defaulters', 'missed', 'appointment', 'tracing', 'iit'],
419
- },
420
- {
421
- code: 'OTZ',
422
- name: 'Adolescent not enrolled in OTZ',
423
- description:
424
- 'Adolescents living with HIV who are not enrolled in the Operation-to-Zero (OTZ) or Adolescent Package of Care program.',
425
- path: '/action-summary/adolescent-not-in-otz',
426
- icon: UserMultiple,
427
- keywords: ['otz', 'adolescent', 'youth', 'enrol', 'package of care'],
428
- },
429
- ],
430
- },
431
- {
432
- id: 'hei',
433
- title: 'HIV-exposed infants',
434
- description: 'Infants due for a test, linkage or outcome',
435
- tone: 'magenta',
436
- reports: [
437
- {
438
- code: 'HEI PCR',
439
- name: 'HEI (6–8 wk) without DNA PCR',
440
- description: 'HIV-Exposed Infants at 6 to 8 weeks of age missing their virological DNA PCR test.',
441
- path: '/action-summary/hei-without-dna-pcr',
442
- icon: Growth,
443
- keywords: ['hei', 'infant', 'pcr', 'dna', '6 weeks', 'eid'],
444
- },
445
- {
446
- code: 'HEI LINK',
447
- name: 'HEI not linked to the mother',
448
- description:
449
- "Infant-mother pairs where the child's file is not cross-referenced or linked with the mother's ART file.",
450
- path: '/action-summary/hei-not-linked-to-mother',
451
- icon: Growth,
452
- keywords: ['hei', 'infant', 'mother', 'linked', 'pair'],
326
+ 'Clients needing action this month, with counts that open their lists: linkage, PrEP for PBFs, PNS/SNS contacts, viral load testing and suppression, EAC, recent defaulters, OTZ and HEI follow-up.',
327
+ path: '/quality-improvement/report',
328
+ icon: DocumentTasks,
329
+ keywords: [
330
+ 'quality improvement',
331
+ 'qi',
332
+ 'action',
333
+ 'linkage',
334
+ 'prep',
335
+ 'pbf',
336
+ 'pns',
337
+ 'sns',
338
+ 'contacts',
339
+ 'viral load',
340
+ 'vl',
341
+ 'eac',
342
+ 'defaulters',
343
+ 'otz',
344
+ 'hei',
345
+ 'pcr',
346
+ 'outcome',
347
+ ],
453
348
  },
454
349
  {
455
- code: 'HEI OUTCOME',
456
- name: 'HEI above 2 years without documented outcome',
457
- description:
458
- 'HIV-Exposed Infants above 2 years of age whose final outcome (e.g. discharged negative, transferred out, lost to follow-up or dead) has not been documented.',
459
- path: '/action-summary/hei-without-outcome',
460
- icon: Growth,
461
- keywords: ['hei', 'infant', 'outcome', 'final', '2 years', 'undocumented', 'discharge'],
350
+ code: 'CS',
351
+ name: 'Case Surveillance Report',
352
+ description: 'Realtime gap review and progress tracking of the case surveillance indicators.',
353
+ path: '/quality-improvement/case-surveillance',
354
+ icon: ChartColumn,
355
+ keywords: ['case surveillance', 'gap review', 'progress tracker', 'linkage', 'prep', 'hei', 'viral load'],
462
356
  },
463
357
  ],
464
358
  },
@@ -497,5 +391,5 @@ const reportsOf = (groupId: string): ReportDefinition[] =>
497
391
  /** Every program report, each routed to the shared report template page */
498
392
  export const programReports = reportsOf('program');
499
393
 
500
- /** Every action summary report, each routed to the shared report template page */
501
- export const actionSummaryReports = reportsOf('action-summary');
394
+ /** Every quality improvement report */
395
+ export const qualityImprovementReports = reportsOf('quality-improvement');
@@ -13,7 +13,7 @@ import {
13
13
  type ReportCategory,
14
14
  type ReportDefinition,
15
15
  } from './report-catalog';
16
- import { useFacilityName } from '../common/report-header';
16
+ import { FacilityClinics, useFacility } from '../common/report-header';
17
17
  import styles from './reports-dashboard.module.scss';
18
18
 
19
19
  interface ReportsDashboardProps {}
@@ -38,7 +38,7 @@ const ReportsDashboard: React.FC<ReportsDashboardProps> = () => {
38
38
  setSearchParams(next, { replace: true });
39
39
  };
40
40
 
41
- /* The Reports tab's group (MOH, Program, Action summary), also kept in the URL */
41
+ /* The Reports tab's group (MOH, Program, Quality improvement), also kept in the URL */
42
42
  const selectedGroup = reportGroups.find((group) => group.id === searchParams.get('group')) ?? reportGroups[0];
43
43
  const selectGroup = (groupId: string) => {
44
44
  const next = new URLSearchParams(searchParams);
@@ -65,7 +65,8 @@ const ReportsDashboard: React.FC<ReportsDashboardProps> = () => {
65
65
 
66
66
  /* the facility the reports cover (the session location's parent, e.g. MTRH
67
67
  for MTRH Module 1), as the reports themselves name it */
68
- const facilityName = useFacilityName(session?.sessionLocation?.uuid, session?.sessionLocation?.display ?? '');
68
+ const facility = useFacility(session?.sessionLocation?.uuid, session?.sessionLocation?.display ?? '');
69
+ const facilityName = facility.name;
69
70
  const today = formatDate(new Date(), { mode: 'standard', time: false, noToday: true });
70
71
 
71
72
  /* One report or register: its code and name, opening its page */
@@ -188,7 +189,7 @@ const ReportsDashboard: React.FC<ReportsDashboardProps> = () => {
188
189
  {facilityName && (
189
190
  <span className={styles.metaItem}>
190
191
  <Location size={16} />
191
- {facilityName}
192
+ <FacilityClinics name={facilityName} clinics={facility.clinics} />
192
193
  </span>
193
194
  )}
194
195
  <span className={styles.metaItem}>
@@ -44,6 +44,22 @@ const columnsFor = (shown: string[]): LinelistColumn[] =>
44
44
  { header: 'Started TPT', field: 'started_tpt' },
45
45
  { header: 'Viral Load', field: 'vl_1' },
46
46
  date('VL Date', 'vl_1_date'),
47
+ { header: 'Status Now', field: 'status' },
48
+ { header: 'Status Last Month', field: 'previous_status' },
49
+ { header: 'Clinic Last Month', field: 'previous_location' },
50
+ date('Transfer In Date', 'transfer_in_date'),
51
+ date('Transfer Out Date', 'transfer_out_date'),
52
+ date('Missed Appointment', 'missed_appointment'),
53
+ { header: 'Days Interrupted', field: 'interruption_days' },
54
+ { header: 'Months on ART', field: 'months_on_art' },
55
+ { header: 'Latest CD4', field: 'latest_cd4' },
56
+ date('Latest CD4 Date', 'latest_cd4_date'),
57
+ date('Death Date', 'death_date'),
58
+ { header: 'Cause of Death', field: 'cause_of_death', wrap: true },
59
+ date('EDD', 'edd'),
60
+ date('Child Birth Date', 'child_birthdate'),
61
+ date('HIV Diagnosis Date', 'hiv_diagnosis_date'),
62
+ { header: 'Known/New Positive', field: 'pmtct_status' },
47
63
  ].map((column) => ({ ...column, hidden: !shown.includes(column.header) }));
48
64
 
49
65
  const COMMON = ['Name', 'CCC Number', 'AMRS Number', 'NUPI', 'Sex', 'Age', 'Clinic'];
@@ -85,6 +101,77 @@ const SECTIONS = [
85
101
  title: 'Current on ART',
86
102
  columns: columnsFor([...COMMON, 'ART Start Date', 'Regimen', 'Last Visit', 'RTC Date', 'WHO Stage', 'Stability']),
87
103
  },
104
+ {
105
+ prefix: 'ti',
106
+ layoutKey: 'care-and-treatment:ti',
107
+ title: 'Transfer in',
108
+ columns: columnsFor([
109
+ ...COMMON,
110
+ 'ART Start Date',
111
+ 'Regimen',
112
+ 'Transfer In Date',
113
+ 'Status Last Month',
114
+ 'Clinic Last Month',
115
+ 'Last Visit',
116
+ 'RTC Date',
117
+ ]),
118
+ },
119
+ {
120
+ prefix: 'rtt',
121
+ layoutKey: 'care-and-treatment:tx-rtt',
122
+ title: 'TX_RTT',
123
+ columns: columnsFor([
124
+ ...COMMON,
125
+ 'ART Start Date',
126
+ 'Regimen',
127
+ 'Status Last Month',
128
+ 'Missed Appointment',
129
+ 'Last Visit',
130
+ 'Days Interrupted',
131
+ 'Latest CD4',
132
+ 'Latest CD4 Date',
133
+ ]),
134
+ },
135
+ {
136
+ prefix: 'ml_',
137
+ layoutKey: 'care-and-treatment:tx-ml',
138
+ title: 'TX_ML',
139
+ /* for a loss, the RTC date is the appointment missed */
140
+ columns: columnsFor([
141
+ ...COMMON,
142
+ 'ART Start Date',
143
+ 'Months on ART',
144
+ 'Last Visit',
145
+ 'RTC Date',
146
+ 'Status Now',
147
+ 'Transfer Out Date',
148
+ 'Death Date',
149
+ ]),
150
+ },
151
+ {
152
+ prefix: 'cod_',
153
+ layoutKey: 'care-and-treatment:cod',
154
+ title: 'Cause of death',
155
+ columns: columnsFor([...COMMON, 'ART Start Date', 'Last Visit', 'Death Date', 'Cause of Death']),
156
+ },
157
+ {
158
+ prefix: 'pmtct',
159
+ layoutKey: 'care-and-treatment:pmtct-vl',
160
+ title: 'PMTCT VL tracking',
161
+ columns: columnsFor([
162
+ ...COMMON,
163
+ 'HIV Diagnosis Date',
164
+ 'ART Start Date',
165
+ 'Regimen',
166
+ 'Pregnant',
167
+ 'EDD',
168
+ 'Breastfeeding',
169
+ 'Child Birth Date',
170
+ 'Known/New Positive',
171
+ 'Viral Load',
172
+ 'VL Date',
173
+ ]),
174
+ },
88
175
  ];
89
176
 
90
177
  /**
@@ -111,7 +111,7 @@ const CareAndTreatmentTable: React.FC<CareAndTreatmentTableProps> = ({ count, op
111
111
  >
112
112
  {groupIndex === 0 && rowIndex === 0 && (
113
113
  <th scope="rowgroup" rowSpan={sectionRows(section)} className={styles.sectionCell}>
114
- <span className={styles.sectionNumber}>{section.number}</span>
114
+ {section.number && <span className={styles.sectionNumber}>{section.number}</span>}
115
115
  <span className={styles.sectionName}>{section.title}</span>
116
116
  </th>
117
117
  )}
@@ -8,10 +8,10 @@ import { useSession } from '@openmrs/esm-framework';
8
8
  import { ReportFiltersComponent, type ReportPeriod, useRestorePeriod } from '../../../common/report-filters';
9
9
  import { downloadSheetsPdf } from '../../../common/report-page';
10
10
  import { showReportError } from '../../../common/report-error';
11
- import { columnsToCsv, downloadCsv, type RegisterColumn } from '../../../common/report-register';
11
+ import { buildXlsx, downloadBlob, rangeOf, type XlsxCell } from '../../../common/report-register';
12
12
  import { ReportPlaceholder, useGeneratedLocation } from '../../../common/report-placeholder';
13
13
  import { ReportSkeleton } from '../../../common/report-skeleton';
14
- import { useFacilityName } from '../../../common/report-header';
14
+ import { FacilityClinics, useFacility } from '../../../common/report-header';
15
15
  import { type ReportDefinition } from '../../../dashboard/report-catalog';
16
16
  import { getCareAndTreatment, type CareAndTreatmentGroup } from '../../../resources/care-and-treatment.resource';
17
17
  import { AGE_BANDS, CARE_AND_TREATMENT_SECTIONS, isMchRow, rowTitle, SEXES } from './care-and-treatment.config';
@@ -36,8 +36,9 @@ export function cellParams({ section, row, band, sex }: CellQuery) {
36
36
 
37
37
  /**
38
38
  * Care & Treatment and ARV Management (Program reports → HIV), sections 1.1
39
- * to 1.4: Starting on ART, Current on ART, months of ARVs dispensed and
40
- * TX_PVLS, by age band and sex, for the session location's whole facility in
39
+ * to 1.7: Starting on ART, Current on ART, months of ARVs dispensed, TX_PVLS,
40
+ * the inflows (transfers in, TX_RTT), TX_ML and the causes of death, by age
41
+ * band and sex, for the session location's whole facility in
41
42
  * the month chosen -- one table, laid out as the reporting form.
42
43
  *
43
44
  * The ETL adds the figures up by age band, sex and MCH/PMTCT (a few dozen rows
@@ -55,7 +56,8 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
55
56
  const session = useSession();
56
57
  const locationUuids = session?.sessionLocation?.uuid ?? '';
57
58
  /* the figures cover the session location's whole facility, so it is named by its parent location (MTRH) */
58
- const facility = useFacilityName(locationUuids, session?.sessionLocation?.display ?? '');
59
+ const facilityDetails = useFacility(locationUuids, session?.sessionLocation?.display ?? '');
60
+ const facility = facilityDetails.name;
59
61
  const { isForCurrentLocation, hasLocationChanged, markGenerated } = useGeneratedLocation('careAndTreatmentLocation');
60
62
  const isReportGenerated = groups !== null && isForCurrentLocation;
61
63
 
@@ -144,58 +146,116 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
144
146
  .join('_')
145
147
  .replace(/[^a-z0-9_-]+/gi, '-');
146
148
 
147
- /* Download CSV: the table as it is laid out -- the age bands across the top
148
- with F and M under each, then the Total; each section's and group's name
149
- once, at its first row, as the merged cells read -- under the report's
150
- title, facility and period, with its notes after. Cells that do not apply
151
- are left empty. */
152
- const exportCsv = () => {
153
- const lines = CARE_AND_TREATMENT_SECTIONS.flatMap((section) =>
154
- section.groups.flatMap((group, groupIndex) =>
155
- group.rows.map((row, rowIndex) => ({
156
- section,
157
- group,
158
- row,
159
- firstInSection: groupIndex === 0 && rowIndex === 0,
160
- firstInGroup: rowIndex === 0,
161
- })),
162
- ),
163
- );
164
- const columns: RegisterColumn[] = [
165
- {
166
- header: 'Section',
167
- value: (line) => (line.firstInSection ? `${line.section.number} ${line.section.title}` : ''),
168
- },
169
- { header: 'Group', value: (line) => (line.firstInGroup ? (line.group.title ?? '') : '') },
170
- { header: 'Indicator', value: (line) => line.row.label },
149
+ /* Download Excel: the table as it is laid out, merged cells and all -- the
150
+ report's title, facility and period; the age bands across the top over
151
+ their F and M, then the Total; each section's and group's name merged down
152
+ beside its rows -- with its notes under it. Cells that do not apply are
153
+ shaded and left empty. */
154
+ const exportExcel = () => {
155
+ const bandColumns = AGE_BANDS.length * SEXES.length;
156
+ const totalColumn = 3 + bandColumns;
157
+ const width = totalColumn + 1;
158
+ const blank = (count: number): XlsxCell[] => Array.from({ length: count }, () => ({}));
159
+ const rows: XlsxCell[][] = [];
160
+ const merges: string[] = [];
161
+ const wholeRow = (value: string, style: XlsxCell['style']) => {
162
+ merges.push(rangeOf(rows.length, 0, rows.length, width - 1));
163
+ rows.push([{ value, style }, ...blank(width - 1)]);
164
+ };
165
+
166
+ wholeRow('Monthly Reporting Summary - 1.0 Care & Treatment and ARV Management', 'title');
167
+ wholeRow(`Facility: ${facility}`, 'meta');
168
+ wholeRow(`Period: ${periodLabel}`, 'meta');
169
+ rows.push(blank(width));
170
+
171
+ /* the heading: Indicator and Total down both rows, each band over its F and M */
172
+ const head = rows.length;
173
+ merges.push(rangeOf(head, 0, head + 1, 2), rangeOf(head, totalColumn, head + 1, totalColumn));
174
+ AGE_BANDS.forEach((_, index) => {
175
+ const column = 3 + index * SEXES.length;
176
+ merges.push(rangeOf(head, column, head, column + SEXES.length - 1));
177
+ });
178
+ rows.push([
179
+ { value: 'Indicator', style: 'header' },
180
+ { style: 'header' },
181
+ { style: 'header' },
171
182
  ...AGE_BANDS.flatMap((band) =>
172
- SEXES.map(
173
- (sex, index): RegisterColumn => ({
174
- /* the band over its F and M, as the table's heading */
175
- header: index === 0 ? band.label : '',
176
- value: (line) =>
177
- isMchRow(line.section, line.row) && (sex === 'M' || band.child)
178
- ? ''
179
- : count({ ...(line as CellQuery), band, sex }),
180
- }),
181
- ),
183
+ SEXES.map((_, index) => ({ value: index === 0 ? band.label : '', style: 'header' as const })),
182
184
  ),
183
- { header: 'Total', value: (line) => count(line as CellQuery) },
184
- ];
185
- const subHeaderRow = ['', '', '', ...AGE_BANDS.flatMap(() => SEXES), ''];
186
- const quoted = (text: string) => `"${text.replace(/"/g, '""')}"`;
187
- const title = [
188
- 'Monthly Reporting Summary - 1.0 Care & Treatment and ARV Management',
189
- `Facility: ${facility}`,
190
- `Period: ${periodLabel}`,
191
- ].map(quoted);
192
- const notes = [
185
+ { value: 'Total', style: 'header' },
186
+ ]);
187
+ rows.push([
188
+ { style: 'header' },
189
+ { style: 'header' },
190
+ { style: 'header' },
191
+ ...AGE_BANDS.flatMap(() => SEXES.map((sex) => ({ value: sex, style: 'header' as const }))),
192
+ { style: 'header' },
193
+ ]);
194
+
195
+ CARE_AND_TREATMENT_SECTIONS.forEach((section) => {
196
+ const sectionStart = rows.length;
197
+ section.groups.forEach((group) => {
198
+ const groupStart = rows.length;
199
+ group.rows.forEach((row) => {
200
+ const cell = { section, group, row };
201
+ const mchOnly = isMchRow(section, row);
202
+ const labelStyle = row.strong
203
+ ? 'labelStrong'
204
+ : row.reference
205
+ ? 'labelMuted'
206
+ : row.notRecorded
207
+ ? 'labelItalic'
208
+ : 'label';
209
+ const numberStyle = row.strong ? 'numberStrong' : row.reference ? 'numberMuted' : 'number';
210
+ if (!group.title) {
211
+ /* a row without a group spans the group's column too */
212
+ merges.push(rangeOf(rows.length, 1, rows.length, 2));
213
+ }
214
+ rows.push([
215
+ {
216
+ value: rows.length === sectionStart ? `${section.number} ${section.title}`.trim() : '',
217
+ style: 'section',
218
+ },
219
+ group.title
220
+ ? { value: rows.length === groupStart ? group.title : '', style: 'group' }
221
+ : { value: row.label, style: labelStyle },
222
+ group.title ? { value: row.label, style: labelStyle } : { style: labelStyle },
223
+ ...AGE_BANDS.flatMap((band) =>
224
+ SEXES.map(
225
+ (sex): XlsxCell =>
226
+ mchOnly && (sex === 'M' || band.child)
227
+ ? { style: 'notApplicable' }
228
+ : { value: count({ ...cell, band, sex }), style: numberStyle },
229
+ ),
230
+ ),
231
+ { value: count(cell), style: numberStyle },
232
+ ]);
233
+ });
234
+ if (group.title && group.rows.length > 1) {
235
+ merges.push(rangeOf(groupStart, 1, rows.length - 1, 1));
236
+ }
237
+ });
238
+ if (rows.length - sectionStart > 1) {
239
+ merges.push(rangeOf(sectionStart, 0, rows.length - 1, 0));
240
+ }
241
+ });
242
+
243
+ rows.push(blank(width));
244
+ wholeRow('Notes', 'meta');
245
+ [
193
246
  ...CARE_AND_TREATMENT_SECTIONS.filter((section) => section.note).map((section) => section.note ?? ''),
194
- 'Not categorized rows are clients whose detail is not recorded, shown so each part adds up to its total (for data cleanup); empty cells do not apply.',
195
- ].map(quoted);
196
- downloadCsv(
197
- [...title, '', columnsToCsv(lines, columns, { subHeaderRow }), '', 'Notes', ...notes].join('\n'),
198
- `${fileName}.csv`,
247
+ 'Not categorized rows (in italics) are clients whose detail is not recorded, shown so each part adds up to its total (for data cleanup); shaded cells do not apply.',
248
+ ].forEach((note) => wholeRow(note, 'note'));
249
+
250
+ downloadBlob(
251
+ buildXlsx({
252
+ sheetName: 'Care & Treatment',
253
+ rows,
254
+ merges,
255
+ columnWidths: [22, 20, 42, ...Array.from({ length: bandColumns }, () => 6), 8],
256
+ freeze: { rows: head + 2, columns: 3 },
257
+ }),
258
+ `${fileName}.xlsx`,
199
259
  );
200
260
  };
201
261
 
@@ -203,6 +263,7 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
203
263
  <>
204
264
  <ReportFiltersComponent
205
265
  reportName={`${report.name} (${report.code})`}
266
+ /* monthly only: its figures are each client's status at the month's end (the HIV monthly dataset) */
206
267
  mode="monthly"
207
268
  onGenerate={generate}
208
269
  isLoading={isLoading}
@@ -218,7 +279,7 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
218
279
  {!isLoading && isReportGenerated && (
219
280
  <div className={styles.report}>
220
281
  <Layer as="section" className={styles.sheet} ref={sheetRef}>
221
- {/* the title, facility and period, with the section links and the CSV
282
+ {/* the title, facility and period, with the section links and the Excel
222
283
  download under them, stay in view as the report scrolls */}
223
284
  <div className={styles.stickyHead} ref={headRef}>
224
285
  <header className={styles.masthead}>
@@ -229,7 +290,9 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
229
290
  <dl className={styles.meta}>
230
291
  <div>
231
292
  <dt>Facility</dt>
232
- <dd>{facility}</dd>
293
+ <dd>
294
+ <FacilityClinics name={facility} clinics={facilityDetails.clinics} />
295
+ </dd>
233
296
  </div>
234
297
  <div>
235
298
  <dt>Period</dt>
@@ -246,13 +309,13 @@ const CareAndTreatmentReport: React.FC<CareAndTreatmentReportProps> = ({ report
246
309
  className={styles.sectionLink}
247
310
  onClick={() => scrollTo(section.id)}
248
311
  >
249
- <span className={styles.sectionNumber}>{section.number}</span>
312
+ {section.number && <span className={styles.sectionNumber}>{section.number}</span>}
250
313
  {section.shortTitle}
251
314
  </button>
252
315
  ))}
253
316
  </nav>
254
- <Button kind="tertiary" size="sm" renderIcon={Download} onClick={exportCsv}>
255
- Download CSV
317
+ <Button kind="tertiary" size="sm" renderIcon={Download} onClick={exportExcel}>
318
+ Download Excel
256
319
  </Button>
257
320
  </div>
258
321
  </div>