@ampath/esm-reports-app 1.0.0-next.97 → 1.0.0-next.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useSearchParams } from 'react-router-dom';
3
+
4
+ import { LinelistTable, type LinelistColumn, useAllRows } from '../../../common/linelist-table';
5
+ import { RegisterLayout, useLocationName } from '../../../common/report-register';
6
+ import { getMoh407PatientList } from '../../../resources/moh-711.resource';
7
+
8
+ const formatDate = (value: unknown) => (value ? new Date(String(value)).toLocaleDateString('en-GB') : '');
9
+
10
+ const MOH_733_LINELIST_COLUMNS: LinelistColumn[] = [
11
+ {
12
+ header: 'Date of Visit',
13
+ value: (row) => formatDate(row.date_of_visit ?? row.date),
14
+ sortValue: (row) => row.date_of_visit ?? row.date,
15
+ },
16
+ { header: 'CR Number', value: (row) => row.cr_id ?? row.national_identification_number ?? '', text: true },
17
+ { header: 'Full Name', value: (row) => row.full_names ?? row.patient_names ?? '' },
18
+ {
19
+ header: 'Date of Birth',
20
+ value: (row) => formatDate(row.date_of_birth),
21
+ sortValue: (row) => row.date_of_birth,
22
+ },
23
+ { header: 'Age (Months)', field: 'age_in_months' },
24
+ { header: 'Sex (Male/Female)', field: 'sex' },
25
+ { header: 'Weight (kg)', field: 'weight' },
26
+ { header: 'Height (cm)', field: 'height' },
27
+ { header: 'Visit Type (New/Revisit)', value: (row) => row.visit_type ?? row.patient_visit ?? '' },
28
+ { header: 'Age (Years)', field: 'age' },
29
+ { header: 'Nutrition Assessment Score', value: (row) => row.nutrition_assessment_score ?? row.z_score ?? '' },
30
+ { header: 'Nutrition Status', field: 'nutrition_status' },
31
+ ];
32
+
33
+ const Moh733Linelist: React.FC = () => {
34
+ const [searchParams] = useSearchParams();
35
+ const startDate = searchParams.get('startDate');
36
+ const endDate = searchParams.get('endDate');
37
+ const locationUuids = searchParams.get('locationUuids');
38
+ const indicator = searchParams.get('indicator') ?? '';
39
+ const locationName = useLocationName(locationUuids);
40
+
41
+ const fetchPatientList = useCallback(
42
+ ({ startIndex, limit }: { startIndex: number; limit: number }) =>
43
+ getMoh407PatientList({
44
+ startDate: startDate ?? undefined,
45
+ endDate: endDate ?? undefined,
46
+ locationUuids: locationUuids ?? '',
47
+ indicator,
48
+ reportName: 'moh733Report',
49
+ startIndex,
50
+ limit,
51
+ }),
52
+ [startDate, endDate, locationUuids, indicator],
53
+ );
54
+ const { rows, isLoading } = useAllRows(fetchPatientList, [startDate, endDate, locationUuids, indicator]);
55
+
56
+ return (
57
+ <RegisterLayout
58
+ parentLabel="MOH-733 Report"
59
+ parentPath="/moh-733"
60
+ title="MOH-733 Linelist"
61
+ location={locationName}
62
+ isLoading={isLoading}
63
+ isEmpty={!isLoading && rows.length === 0}
64
+ >
65
+ <LinelistTable
66
+ rows={rows}
67
+ columns={MOH_733_LINELIST_COLUMNS}
68
+ layoutKey={`moh-733:${indicator}`}
69
+ exportName={`MOH-733 ${indicator} ${startDate ?? ''} ${endDate ?? ''}`}
70
+ />
71
+ </RegisterLayout>
72
+ );
73
+ };
74
+
75
+ export default Moh733Linelist;
@@ -0,0 +1,19 @@
1
+ import { useCallback } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+
4
+ export function useOpenMoh733Linelist(startDate: string, endDate: string, locationUuids: string) {
5
+ const navigate = useNavigate();
6
+
7
+ return useCallback(
8
+ (indicator: string) => {
9
+ const params = new URLSearchParams({
10
+ startDate,
11
+ endDate,
12
+ locationUuids,
13
+ indicator,
14
+ });
15
+ navigate(`/moh-733-linelist?${params}`);
16
+ },
17
+ [navigate, startDate, endDate, locationUuids],
18
+ );
19
+ }
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import ClientCategoryComponent from './sections/client-category.component';
3
3
 
4
4
  import styles from './moh-733.scss';
@@ -6,22 +6,172 @@ import NutritionStatusComponent from './sections/nutrition-status.component';
6
6
  import NutritionStatusWeightComponent from './sections/nutrition-status-weight.component';
7
7
  import NutritionInterventionComponent from './sections/nutrition-intervention.component';
8
8
  import NutritionInterventionPregnantBrestfeedingComponent from './sections/nutrition-intervention-pregnant-breastfeeding.component';
9
+ import { showReportError } from '../../common/report-error';
10
+ import dayjs from 'dayjs';
11
+ import { ReportFiltersComponent, type ReportPeriod } from '../../common/report-filters';
12
+ import { formatDate, useSession } from '@openmrs/esm-framework';
13
+ import { hasReportData, ReportPlaceholder, useGeneratedLocation } from '../../common/report-placeholder';
14
+ import { getMoh733 } from '../../resources/moh-733.resource';
15
+ import { ReportSkeleton } from '../../common/report-skeleton';
16
+ import { ReportPage } from '../../common/report-page';
9
17
 
10
18
  const Moh733Component: React.FC = () => {
19
+ const [moh733Data, setMoh733Data] = useState<any>(() => {
20
+ const saved = sessionStorage.getItem('moh733Data');
21
+ return saved ? JSON.parse(saved) : [];
22
+ });
23
+ /* Only a report for the current location counts: after switching location the
24
+ old figures would otherwise be shown, and labelled, as the new location's. */
25
+ const { isForCurrentLocation, hasLocationChanged, markGenerated } = useGeneratedLocation('moh733Location');
26
+ const isReportGenerated = hasReportData(moh733Data) && isForCurrentLocation;
27
+ const [isLoading, setIsLoading] = useState<boolean>(false);
28
+ const [startDate, setStartDate] = useState<string>(() => {
29
+ return sessionStorage.getItem('moh733StartDate') || '';
30
+ });
31
+
32
+ const [endDate, setEndDate] = useState<string>(() => {
33
+ return sessionStorage.getItem('moh733EndDate') || '';
34
+ });
35
+ useEffect(() => {
36
+ sessionStorage.setItem('moh733Data', JSON.stringify(moh733Data));
37
+ }, [moh733Data]);
38
+
39
+ useEffect(() => {
40
+ sessionStorage.setItem('moh733StartDate', startDate);
41
+ }, [startDate]);
42
+
43
+ useEffect(() => {
44
+ sessionStorage.setItem('moh733EndDate', endDate);
45
+ }, [endDate]);
46
+
47
+ const session = useSession();
48
+ const locationUuid = session?.sessionLocation?.uuid;
49
+
50
+ /* The masthead names the location the report was generated from; county and
51
+ sub-county come from the response where the ETL supplies them. Month and
52
+ year follow the period generated, not today. */
53
+ const facility = session?.sessionLocation?.display ?? moh733Data?.facility ?? '';
54
+ const county = moh733Data?.county ?? '';
55
+ const subCounty = moh733Data?.sub_county ?? '';
56
+ const reportMonth = startDate ? dayjs(startDate).format('MMMM') : '';
57
+ const reportYear = startDate ? dayjs(startDate).format('YYYY') : '';
58
+ const compiledBy = session?.user?.person?.display ?? session?.user?.display ?? '';
59
+ const compiledOn = formatDate(new Date(), { mode: 'standard', time: false, noToday: true });
60
+
61
+ const fetchMoh733ReportData = async ({ startDate, endDate }: ReportPeriod) => {
62
+ setIsLoading(true);
63
+ setStartDate(startDate);
64
+ setEndDate(endDate);
65
+
66
+ const params = {
67
+ locationUuids: locationUuid || '',
68
+ startDate,
69
+ endDate,
70
+ };
71
+ try {
72
+ const data = await getMoh733(params);
73
+ const flatData = Object.assign({}, ...data.result);
74
+ setMoh733Data(flatData);
75
+ markGenerated(params.locationUuids);
76
+ setIsLoading(false);
77
+ } catch (error) {
78
+ setIsLoading(false);
79
+ setIsLoading(false);
80
+ showReportError('the MOH-733 report', error);
81
+ }
82
+ };
11
83
  return (
12
84
  <>
13
- <div className={styles.parentBorder}>
14
- <p>CLIENT CATEGORY</p>
15
- <ClientCategoryComponent moh733Data={[]} startDate="" endDate="" locationUuids="" />
16
- <p>NUTRITION STATUS</p>
17
- <NutritionStatusComponent moh733Data={[]} startDate="" endDate="" locationUuids="" />
18
- <p>NUTRITION STATUS</p>
19
- <NutritionStatusWeightComponent moh733Data={[]} startDate="" endDate="" locationUuids="" />
20
- <p>NUTRITION INTERVENTION</p>
21
- <NutritionInterventionComponent moh733Data={[]} startDate="" endDate="" locationUuids="" />
22
- <p>NUTRITION INTERVENTION</p>
23
- <NutritionInterventionPregnantBrestfeedingComponent moh733Data={[]} startDate="" endDate="" locationUuids="" />
24
- </div>
85
+ <ReportFiltersComponent
86
+ reportName="MOH-733 Report"
87
+ mode="both"
88
+ onGenerate={fetchMoh733ReportData}
89
+ isLoading={isLoading}
90
+ isReportGenerated={isReportGenerated}
91
+ generatedPeriod={{ startDate, endDate }}
92
+ />
93
+ {isLoading && <ReportSkeleton />}
94
+ {!isLoading && !isReportGenerated && (
95
+ <ReportPlaceholder reportName="MOH-733" isLocationChanged={hasReportData(moh733Data) && hasLocationChanged} />
96
+ )}
97
+ {!isLoading && isReportGenerated && (
98
+ <ReportPage>
99
+ <div className={styles.headerContainer}>
100
+ <div className={styles.mainTitleBox}>
101
+ <h5>
102
+ INTEGRATED PROGRAM SUMMARY REPORT FORM: REPRODUCTIVE AND CHILD HEALTH, MEDICAL AND REHABILITATION
103
+ SERVICES
104
+ </h5>
105
+ <div className={styles.locationContainer}>
106
+ <span>
107
+ Facility Name: <span className={styles.line}>{facility}</span>
108
+ </span>
109
+ <span>
110
+ County: <span className={styles.line}>{county}</span>
111
+ </span>
112
+ <span>
113
+ Sub County: <span className={styles.line}>{subCounty}</span>
114
+ </span>
115
+ <span>
116
+ Month: <span className={styles.shortLine}>{reportMonth}</span>
117
+ </span>
118
+ <span>
119
+ Year: <span className={styles.shortLine}>{reportYear}</span>
120
+ </span>
121
+ </div>
122
+ </div>
123
+ </div>
124
+ <div>
125
+ <p>CLIENT CATEGORY</p>
126
+ <ClientCategoryComponent
127
+ moh733Data={moh733Data}
128
+ startDate={startDate}
129
+ endDate={endDate}
130
+ locationUuids={locationUuid || ''}
131
+ />
132
+ <p>NUTRITION STATUS</p>
133
+ <NutritionStatusComponent
134
+ moh733Data={moh733Data}
135
+ startDate={startDate}
136
+ endDate={endDate}
137
+ locationUuids={locationUuid || ''}
138
+ />
139
+ <p>NUTRITION STATUS</p>
140
+ <NutritionStatusWeightComponent
141
+ moh733Data={moh733Data}
142
+ startDate={startDate}
143
+ endDate={endDate}
144
+ locationUuids={locationUuid || ''}
145
+ />
146
+ <p>NUTRITION INTERVENTION</p>
147
+ <NutritionInterventionComponent
148
+ moh733Data={moh733Data}
149
+ startDate={startDate}
150
+ endDate={endDate}
151
+ locationUuids={locationUuid || ''}
152
+ />
153
+ <p>NUTRITION INTERVENTION</p>
154
+ <NutritionInterventionPregnantBrestfeedingComponent
155
+ moh733Data={moh733Data}
156
+ startDate={startDate}
157
+ endDate={endDate}
158
+ locationUuids={locationUuid || ''}
159
+ />
160
+ </div>
161
+ <div className={styles.signOff}>
162
+ <span>
163
+ Compiled by:<span className={styles.line}>{compiledBy}</span>
164
+ </span>
165
+ <span>
166
+ Signature:
167
+ <span className={styles.line} />
168
+ </span>
169
+ <span>
170
+ Date:<span className={styles.shortLine}>{compiledOn}</span>
171
+ </span>
172
+ </div>
173
+ </ReportPage>
174
+ )}
25
175
  </>
26
176
  );
27
177
  };
@@ -2,6 +2,16 @@
2
2
  /* Smaller than the section headings beneath it: at 9pt the form title was
3
3
  heavier than the lettered sections it introduces. */
4
4
 
5
+ $ink: #000;
6
+ $bar: #d9d9d9;
7
+ $rule: 1px solid $ink;
8
+
9
+ $text: 7pt;
10
+ $title: 7.5pt;
11
+ $meta: 6.5pt;
12
+
13
+ $pad: 3mm;
14
+
5
15
  .mainTitleBox h5 {
6
16
  font-size: 7.5pt;
7
17
  font-weight: 700;
@@ -188,4 +198,25 @@
188
198
  margin: 2rem;
189
199
  justify-content: space-between;
190
200
  padding: 2rem;
201
+ }
202
+
203
+ .signOff {
204
+ display: flex;
205
+ flex-wrap: nowrap;
206
+ align-items: baseline;
207
+ justify-content: space-between;
208
+ gap: 2.5mm;
209
+ padding: $pad;
210
+ font-size: $meta;
211
+ white-space: nowrap;
212
+ border: $rule;
213
+ border-top: none;
214
+
215
+ .line {
216
+ width: 45mm;
217
+ }
218
+
219
+ .shortLine {
220
+ width: 25mm;
221
+ }
191
222
  }