@ampath/esm-reports-app 1.0.0-next.67 → 1.0.0-next.69

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,14 +1,74 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import { type Moh222Patient } from '../../types';
3
3
  import styles from '../../../../common/report-register/register-table.scss';
4
4
  import classNames from 'classnames';
5
5
  import { Link, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@carbon/react';
6
- interface Moh222DailyRegisterProps {
7
- moh222PatientList: Moh222Patient[];
8
- }
9
- const Moh222DailyRegister: React.FC<Moh222DailyRegisterProps> = ({ moh222PatientList }) => {
6
+ import { useSearchParams } from 'react-router-dom';
7
+ import ReportFiltersComponent from '../../../../common/report-filters/report-filters.component';
8
+ import { type ReportPeriod } from '../../../../common/report-filters/types';
9
+ import { useGeneratedLocation } from '../../../../common/report-placeholder/use-generated-location';
10
+ import { fetchMoh740Register } from '../../moh-740.resource';
11
+ import { useSession } from '@openmrs/esm-framework';
12
+ import { showReportError } from '../../../../common/report-error/show-report-error';
13
+ import dayjs from 'dayjs';
14
+ const Moh222DailyRegister = () => {
15
+ const [rows, setRows] = useState<Moh222Patient[] | any>([]);
16
+ const [searchParams ] = useSearchParams();
17
+ const startDate = searchParams.get('startDate') ?? '';
18
+ const endDate = searchParams.get('endDate') ?? '';
19
+ const locationUuids = searchParams.get('locationUuids') ??'';
20
+ const indicator = searchParams.get('indicator') ?? '';
21
+ const [isLoading,setIsLoading] = useState<boolean>(false);
22
+ const [period, setPeriod] = useState<{ startDate: string; endDate: string }>({ startDate: '', endDate: '' });
23
+ const session = useSession();
24
+ const { isForCurrentLocation, hasLocationChanged, markGenerated } = useGeneratedLocation('moh222Location');
25
+ const isGenerated = rows !== null && isForCurrentLocation;
26
+ useEffect(()=>{
27
+ if(startDate && endDate && locationUuids){
28
+ generate({startDate: startDate,endDate: endDate, label: ''})
29
+ }
30
+ },[startDate,endDate,locationUuids,indicator]);
31
+ const generate = async ({ startDate, endDate }: ReportPeriod) => {
32
+ setIsLoading(true);
33
+ setPeriod({ startDate, endDate });
34
+ let indicators = '';
35
+ let locationUuid = '';
36
+ const selectedDate = dayjs(startDate).endOf('month')
37
+ const registerStartDate = selectedDate.format('YYYY-MM-DD');
38
+ try {
39
+ if(!indicator){
40
+ indicators = 'cumulative_all';
41
+ }else{
42
+ indicators = indicator;
43
+ }
44
+ if(!locationUuids){
45
+ locationUuid = session.sessionLocation?.uuid ?? '';
46
+ }else{
47
+ locationUuid = locationUuids;
48
+ }
49
+ const resp = await fetchMoh740Register({ locationUuid: locationUuid, endDate: registerStartDate,indicators: indicators});
50
+ if(resp){
51
+ setRows(resp);
52
+ }
53
+ markGenerated(locationUuids);
54
+ } catch (error) {
55
+ showReportError('The MOH 222 register', error);
56
+ } finally {
57
+ setIsLoading(false);
58
+ }
59
+ };
10
60
  return (
11
61
  <div className={styles.tableContainer}>
62
+ <ReportFiltersComponent
63
+ reportName="MOH 222 Daily Register"
64
+ mode="both"
65
+ onGenerate={generate}
66
+ isLoading={isLoading}
67
+ isReportGenerated={isGenerated}
68
+ generatedPeriod={period}
69
+ defaultTab="custom"
70
+ backLink={{ label: 'All registers', to: '/?tab=registers' }}
71
+ />
12
72
  <Table className={classNames(styles.table, styles.tableBordered, styles.tableStriped)}>
13
73
  <TableHead>
14
74
  <TableRow>
@@ -45,7 +105,7 @@ const Moh222DailyRegister: React.FC<Moh222DailyRegisterProps> = ({ moh222Patient
45
105
  </TableRow>
46
106
  </TableHead>
47
107
  <TableBody>
48
- {moh222PatientList.map((p, index) => (
108
+ {rows.map((p, index) => (
49
109
  <TableRow key={p.patient_uuid}>
50
110
  <TableCell>{index + 1}</TableCell>
51
111
  <TableCell>{p.encounter_date}</TableCell>
@@ -1,14 +1,74 @@
1
1
  import { Link, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@carbon/react';
2
- import React from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import { type Moh270Patient } from '../../types';
4
4
  import styles from '../../../../common/report-register/register-table.scss';
5
5
  import classNames from 'classnames';
6
- interface Moh270DailyRegisterProps {
7
- moh270PatientList: Moh270Patient[];
8
- }
9
- const Moh270DailyRegister: React.FC<Moh270DailyRegisterProps> = ({ moh270PatientList }) => {
6
+ import { useSearchParams } from 'react-router-dom';
7
+ import { useSession } from '@openmrs/esm-framework';
8
+ import { useGeneratedLocation } from '../../../../common/report-placeholder/use-generated-location';
9
+ import { type ReportPeriod } from '../../../../common/report-filters/types';
10
+ import dayjs from 'dayjs';
11
+ import { fetchMoh740Register } from '../../moh-740.resource';
12
+ import { showReportError } from '../../../../common/report-error/show-report-error';
13
+ import ReportFiltersComponent from '../../../../common/report-filters/report-filters.component';
14
+ const Moh270DailyRegister = () => {
15
+ const [rows, setRows] = useState<Moh270Patient[] | any>([]);
16
+ const [searchParams ] = useSearchParams();
17
+ const startDate = searchParams.get('startDate') ?? '';
18
+ const endDate = searchParams.get('endDate') ?? '';
19
+ const locationUuids = searchParams.get('locationUuids') ??'';
20
+ const indicator = searchParams.get('indicator') ?? '';
21
+ const [isLoading,setIsLoading] = useState<boolean>(false);
22
+ const [period, setPeriod] = useState<{ startDate: string; endDate: string }>({ startDate: '', endDate: '' });
23
+ const session = useSession();
24
+ const { isForCurrentLocation, hasLocationChanged, markGenerated } = useGeneratedLocation('moh270Location');
25
+ const isGenerated = rows !== null && isForCurrentLocation;
26
+ useEffect(()=>{
27
+ if(startDate && endDate && locationUuids){
28
+ generate({startDate: startDate,endDate: endDate, label: ''})
29
+ }
30
+ },[startDate,endDate,locationUuids,indicator]);
31
+ const generate = async ({ startDate, endDate }: ReportPeriod) => {
32
+ setIsLoading(true);
33
+ setPeriod({ startDate, endDate });
34
+ let indicators = '';
35
+ let locationUuid = '';
36
+ const selectedDate = dayjs(startDate).endOf('month')
37
+ const registerStartDate = selectedDate.format('YYYY-MM-DD');
38
+ try {
39
+ if(!indicator){
40
+ indicators = 'cumulative_all';
41
+ }else{
42
+ indicators = indicator;
43
+ }
44
+ if(!locationUuids){
45
+ locationUuid = session.sessionLocation?.uuid ?? '';
46
+ }else{
47
+ locationUuid = locationUuids;
48
+ }
49
+ const resp = await fetchMoh740Register({ locationUuid: locationUuid, endDate: registerStartDate,indicators: indicators});
50
+ if(resp){
51
+ setRows(resp);
52
+ }
53
+ markGenerated(locationUuids);
54
+ } catch (error) {
55
+ showReportError('The MOH 270 register', error);
56
+ } finally {
57
+ setIsLoading(false);
58
+ }
59
+ }
10
60
  return (
11
61
  <div className={styles.tableContainer}>
62
+ <ReportFiltersComponent
63
+ reportName="MOH 270 Permanent Register"
64
+ mode="both"
65
+ onGenerate={generate}
66
+ isLoading={isLoading}
67
+ isReportGenerated={isGenerated}
68
+ generatedPeriod={period}
69
+ defaultTab="custom"
70
+ backLink={{ label: 'All registers', to: '/?tab=registers' }}
71
+ />
12
72
  <Table className={classNames(styles.table, styles.tableBordered, styles.tableStriped)}>
13
73
  <TableHead>
14
74
  <TableRow>
@@ -32,7 +92,7 @@ const Moh270DailyRegister: React.FC<Moh270DailyRegisterProps> = ({ moh270Patient
32
92
  </TableRow>
33
93
  </TableHead>
34
94
  <TableBody>
35
- {moh270PatientList.map((p, index) => (
95
+ {rows.map((p, index) => (
36
96
  <TableRow key={p.patient_uuid}>
37
97
  <TableCell>{index + 1}</TableCell>
38
98
  <TableCell>{p?.enrollment_date ?? ''}</TableCell>
@@ -30,42 +30,7 @@ const Moh740PatientList: React.FC<Moh740PatientListProps> = ({
30
30
 
31
31
  const isDaily = register === Moh740Rgisters.DailyRegister;
32
32
 
33
- useEffect(() => {
34
- if (locationUuid && reportingMonth && indicators) {
35
- fethPatientList();
36
- }
37
- }, [locationUuid, reportingMonth, indicators, register]);
38
33
 
39
- async function fethPatientList() {
40
- setIsLoading(true);
41
-
42
- try {
43
- const resp = await fetchMoh740Register({
44
- locationUuid: locationUuid,
45
- endDate: reportingMonth,
46
- indicators: indicators,
47
- });
48
-
49
- if (resp) {
50
- if (register === Moh740Rgisters.DailyRegister) {
51
- setMoh222PatientList(resp as any);
52
- setMoh270PatientList([]);
53
- }
54
- if (register === Moh740Rgisters.PermanentRegister) {
55
- setMoh270PatientList(resp);
56
- setMoh222PatientList([]);
57
- }
58
- }
59
- } catch (error) {
60
- /* Without this a failed fetch left an empty list, which reads on screen
61
- as "no clients matched" rather than as a request that did not land. */
62
- setMoh222PatientList([]);
63
- setMoh270PatientList([]);
64
- showReportError('the register', error);
65
- } finally {
66
- setIsLoading(false);
67
- }
68
- }
69
34
 
70
35
  if (!locationUuid || !reportingMonth || !indicators) {
71
36
  return <></>;
@@ -84,9 +49,9 @@ const Moh740PatientList: React.FC<Moh740PatientListProps> = ({
84
49
  fetchAll={async () => rows}
85
50
  >
86
51
  {isDaily ? (
87
- <Moh222DailyRegister moh222PatientList={moh222PatientList} />
52
+ <Moh222DailyRegister/>
88
53
  ) : (
89
- <Moh270DailyRegister moh270PatientList={moh270patientList} />
54
+ <Moh270DailyRegister/>
90
55
  )}
91
56
  </RegisterLayout>
92
57
  );
@@ -25,8 +25,11 @@ import Moh366Register from './reports/moh-731/registers/moh-366.component';
25
25
  import PrepRegisterComponent from './reports/moh-731/registers/prep-register.component';
26
26
  import Moh731Linelist from './reports/moh-731/linelist/moh-731-linelist.component';
27
27
  import Moh362Register from './registers/moh-362/moh-362.component';
28
+ import Moh240LabRegister from './registers/moh-240/moh-240.component';
28
29
  import styles from './root.scss';
29
30
  import Moh510RegisterComponent from './reports/moh-710/registers/moh-510/moh-510.component';
31
+ import Moh222DailyRegister from './reports/moh-740/registers/moh-222-daily-register/moh-222-daily-register';
32
+ import Moh270DailyRegister from './reports/moh-740/registers/moh-270-permanent-register/moh-270-permanent-register';
30
33
 
31
34
  const RootComponent: React.FC = () => {
32
35
  const baseName = window.getOpenmrsSpaBase() + 'home/reports';
@@ -61,6 +64,9 @@ const RootComponent: React.FC = () => {
61
64
  <Route path="/prep-register" element={<PrepRegisterComponent />} />
62
65
  <Route path="/moh-510-register" element={<Moh510RegisterComponent />} />
63
66
  <Route path="/moh-362" element={<Moh362Register />} />
67
+ <Route path="/moh-222" element={<Moh222DailyRegister />} />
68
+ <Route path="/moh-270" element={<Moh270DailyRegister />} />
69
+ <Route path="/moh-240-register" element={<Moh240LabRegister />} />
64
70
  </Routes>
65
71
  </div>
66
72
  </BrowserRouter>