@ampath/esm-reports-app 1.0.0-next.41 → 1.0.0-next.42

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 (147) hide show
  1. package/dist/110.js +2 -1
  2. package/dist/110.js.LICENSE.txt +35 -0
  3. package/dist/110.js.map +1 -1
  4. package/dist/205.js +1 -1
  5. package/dist/441.js +1 -0
  6. package/dist/441.js.map +1 -0
  7. package/dist/738.js +1 -0
  8. package/dist/738.js.map +1 -0
  9. package/dist/812.js +1 -1
  10. package/dist/812.js.map +1 -1
  11. package/dist/ampath-esm-reports-app.js +1 -1
  12. package/dist/ampath-esm-reports-app.js.buildmanifest.json +66 -39
  13. package/dist/main.js +1 -1
  14. package/dist/main.js.map +1 -1
  15. package/dist/routes.json +1 -1
  16. package/package.json +1 -1
  17. package/src/common/report-error/index.ts +1 -0
  18. package/src/common/report-error/show-report-error.ts +25 -0
  19. package/src/common/report-filters/date-range.ts +137 -0
  20. package/src/common/report-filters/index.ts +4 -0
  21. package/src/common/report-filters/report-filters.component.tsx +281 -151
  22. package/src/common/report-filters/report-filters.scss +180 -55
  23. package/src/common/report-filters/types.ts +66 -0
  24. package/src/common/report-filters/use-restore-period.ts +43 -0
  25. package/src/common/report-page/index.ts +2 -0
  26. package/src/common/report-page/report-page.component.tsx +32 -0
  27. package/src/common/report-page/report-page.scss +45 -0
  28. package/src/common/report-page/use-page-scale.ts +50 -0
  29. package/src/common/report-placeholder/has-report-data.ts +15 -0
  30. package/src/common/report-placeholder/index.ts +2 -0
  31. package/src/common/report-placeholder/report-placeholder.component.tsx +56 -0
  32. package/src/common/report-placeholder/report-placeholder.scss +46 -0
  33. package/src/common/report-register/index.ts +5 -0
  34. package/src/common/report-register/register-columns.ts +34 -0
  35. package/src/common/report-register/register-layout.component.tsx +237 -0
  36. package/src/common/report-register/register-layout.scss +140 -0
  37. package/src/common/report-register/register-table.scss +62 -0
  38. package/src/common/report-register/report-parents.ts +27 -0
  39. package/src/common/report-register/rows-to-csv.ts +59 -0
  40. package/src/common/report-register/use-patient-list.ts +92 -0
  41. package/src/common/report-skeleton/index.ts +1 -0
  42. package/src/common/report-skeleton/report-skeleton.component.tsx +46 -0
  43. package/src/common/report-skeleton/report-skeleton.scss +29 -0
  44. package/src/config-schema.ts +9 -1
  45. package/src/dashboard/report-catalog.ts +173 -0
  46. package/src/dashboard/reports-dasboard.tsx +101 -35
  47. package/src/dashboard/reports-dashboard.module.scss +269 -11
  48. package/src/index.ts +13 -1
  49. package/src/reports/datatable-wrapper/datatable-wrapper.component.tsx +50 -48
  50. package/src/reports/moh-240/moh-240-header.component.tsx +54 -56
  51. package/src/reports/moh-240/moh-240.columns.ts +64 -0
  52. package/src/reports/moh-240/moh-240.component.tsx +65 -84
  53. package/src/reports/moh-240/moh-240.scss +36 -7
  54. package/src/reports/moh-240/sub-reports/moh-240-register.component.tsx +27 -65
  55. package/src/reports/moh-240/sub-reports/page-summary.component.tsx +2 -2
  56. package/src/reports/moh-505/moh-505-header.component.tsx +59 -57
  57. package/src/reports/moh-505/moh-505.component.tsx +51 -56
  58. package/src/reports/moh-505/moh-505.scss +116 -2
  59. package/src/reports/moh-705B/moh-204b-register.component.tsx +41 -42
  60. package/src/reports/moh-705B/moh-204b.columns.ts +39 -0
  61. package/src/reports/moh-705B/moh-705b.component.tsx +492 -473
  62. package/src/reports/moh-705B/moh-705b.scss +110 -24
  63. package/src/reports/moh-705a/moh-705a.component.tsx +496 -476
  64. package/src/reports/moh-705a/moh-705a.scss +109 -24
  65. package/src/reports/moh-705a/registers/moh-204a-register.component.tsx +41 -42
  66. package/src/reports/moh-705a/registers/moh-204a.columns.ts +57 -0
  67. package/src/reports/moh-706/moh-706-header.component.tsx +58 -56
  68. package/src/reports/moh-706/moh-706.component.tsx +84 -55
  69. package/src/reports/moh-706/moh-706.scss +115 -19
  70. package/src/reports/moh-710/moh-710.component.tsx +743 -727
  71. package/src/reports/moh-710/moh-710.scss +140 -23
  72. package/src/reports/moh-710/registers/moh-511-710-register.component.tsx +48 -43
  73. package/src/reports/moh-710/registers/moh-511-710.columns.ts +52 -0
  74. package/src/reports/moh-711/moh-711.component.tsx +94 -106
  75. package/src/reports/moh-711/moh711.scss +95 -64
  76. package/src/reports/moh-711/registers/moh-333-register.component.tsx +92 -94
  77. package/src/reports/moh-711/registers/moh-333.columns.ts +119 -0
  78. package/src/reports/moh-711/registers/moh-405-register.component.tsx +88 -89
  79. package/src/reports/moh-711/registers/moh-405.columns.ts +120 -0
  80. package/src/reports/moh-711/registers/moh-406-register.component.tsx +85 -88
  81. package/src/reports/moh-711/registers/moh-406.columns.ts +133 -0
  82. package/src/reports/moh-711/registers/moh-510-register.component.tsx +38 -44
  83. package/src/reports/moh-711/registers/moh-511-register.component.tsx +42 -43
  84. package/src/reports/moh-711/registers/moh-511.columns.ts +59 -0
  85. package/src/reports/moh-711/sections/anc.component.tsx +3 -3
  86. package/src/reports/moh-711/sections/cervical-cancer.component.tsx +3 -3
  87. package/src/reports/moh-711/sections/chanis.component.tsx +2 -3
  88. package/src/reports/moh-711/sections/family-planning.component.tsx +2 -2
  89. package/src/reports/moh-711/sections/gbv.component.tsx +2 -2
  90. package/src/reports/moh-711/sections/maternity.component.tsx +3 -8
  91. package/src/reports/moh-711/sections/medical-social-work.component.tsx +2 -12
  92. package/src/reports/moh-711/sections/other.component.tsx +2 -2
  93. package/src/reports/moh-711/sections/physiotherapy.component.tsx +2 -2
  94. package/src/reports/moh-711/sections/pnc.component.tsx +7 -5
  95. package/src/reports/moh-711/sections/post-abortion.component.tsx +2 -2
  96. package/src/reports/moh-711/sections/rehabilitation.component.tsx +2 -2
  97. package/src/reports/moh-711/sections/report-compiled-by.component.tsx +12 -4
  98. package/src/reports/moh-711/sections/tb-screening.component.tsx +2 -2
  99. package/src/reports/moh-717/moh-717.component.tsx +100 -121
  100. package/src/reports/moh-717/moh717.scss +163 -102
  101. package/src/reports/moh-717/sections/maternity.component.tsx +1 -1
  102. package/src/reports/moh-717/sections/orthopaedic-trauma.component.tsx +1 -1
  103. package/src/reports/moh-717/sections/outpatient.component.tsx +23 -23
  104. package/src/reports/moh-717/sections/preparedby.component.tsx +7 -2
  105. package/src/reports/moh-717/sections/special-services.component.tsx +1 -1
  106. package/src/reports/moh-731/moh-731.component.tsx +127 -110
  107. package/src/reports/moh-731/moh-731.scss +396 -68
  108. package/src/reports/moh-731/registers/moh-366.columns.ts +38 -0
  109. package/src/reports/moh-731/registers/moh-366.component.tsx +76 -83
  110. package/src/reports/moh-731/registers/prep-register.component.tsx +70 -78
  111. package/src/reports/moh-731/registers/prep.columns.ts +34 -0
  112. package/src/reports/moh-731/sections/hiv-and-tb-treatment.component.tsx +1031 -751
  113. package/src/reports/moh-731/sections/hiv-testing-and-pre-exposure.component.tsx +230 -86
  114. package/src/reports/moh-731/sections/pmtct.component.tsx +185 -64
  115. package/src/reports/moh-740/moh-740.component.scss +159 -79
  116. package/src/reports/moh-740/moh-740.component.tsx +258 -227
  117. package/src/reports/moh-740/moh-740.resource.ts +17 -10
  118. package/src/reports/moh-740/registers/moh-222-daily-register/moh-222-daily-register.tsx +77 -96
  119. package/src/reports/moh-740/registers/moh-270-permanent-register/moh-270-permanent-register.tsx +50 -70
  120. package/src/reports/moh-740/registers/moh-740-patient-list.tsx +61 -32
  121. package/src/reports/moh-740/registers/moh-740.columns.ts +52 -0
  122. package/src/reports/moh-745/moh-745.component.tsx +897 -877
  123. package/src/reports/moh-745/moh-745.scss +104 -46
  124. package/src/reports/moh-745/registers/moh-412-register.component.tsx +42 -43
  125. package/src/reports/moh-745/registers/moh-412.columns.ts +52 -0
  126. package/src/reports/table-wrapper/table-wrapper.component.tsx +23 -14
  127. package/src/reports/table-wrapper/table-wrapper.scss +1 -16
  128. package/src/resources/moh-505.resource.ts +18 -35
  129. package/src/resources/moh-705.resource.ts +28 -39
  130. package/src/resources/moh-706.resource.ts +17 -30
  131. package/src/resources/moh-710.resource.ts +7 -17
  132. package/src/resources/moh-711.resource.ts +46 -64
  133. package/src/resources/moh-717.resource.ts +7 -17
  134. package/src/resources/moh-731.resource.ts +26 -32
  135. package/src/resources/moh-745.resource.ts +18 -20
  136. package/src/resources/patient-list-page.ts +66 -0
  137. package/src/root.component.tsx +28 -26
  138. package/src/root.scss +39 -0
  139. package/src/utils/get-base-url.ts +39 -7
  140. package/dist/822.js +0 -2
  141. package/dist/822.js.LICENSE.txt +0 -20
  142. package/dist/822.js.map +0 -1
  143. package/src/reports/moh-731/registers/moh-366.scss +0 -45
  144. package/src/reports/moh-731/registers/prep-registers.scss +0 -45
  145. package/src/reports/moh-740/registers/moh-222-daily-register/moh-222-daily-register.scss +0 -18
  146. package/src/reports/moh-740/registers/moh-270-permanent-register/moh-270-permanent-register.scss +0 -18
  147. /package/src/{reports/moh-740/shared/utils → utils}/format-indicator.ts +0 -0
@@ -1,5 +1,12 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
+ import {
4
+ PAGE_SIZE,
5
+ pageParams,
6
+ toPatientListPage,
7
+ type PatientListPage,
8
+ type PatientListParams,
9
+ } from './patient-list-page';
3
10
 
4
11
  interface Moh706Params {
5
12
  locationUuids: string;
@@ -11,30 +18,18 @@ interface Moh706Response {
11
18
  result: Array<Record<string, unknown>>;
12
19
  }
13
20
 
14
- interface Moh706PatientListParams {
15
- locationUuids: string;
16
- startDate?: string;
17
- endDate?: string;
18
- indicators: string;
19
- }
20
-
21
21
  interface Moh706PatientListResponse {
22
22
  result: Array<Record<string, unknown>>;
23
23
  }
24
24
 
25
25
  export async function getMoh706(params: Moh706Params): Promise<Array<Record<string, unknown>>> {
26
- const etlBaseUrl = await getEtlBaseUrl();
27
- const url = `${etlBaseUrl}/lab-706`;
28
- const queryparams = {
26
+ const url = await buildEtlUrl('lab-706', {
29
27
  locationUuids: params.locationUuids || '',
30
28
  startDate: params.startDate || '',
31
29
  endDate: params.endDate || '',
32
- };
33
- const queryString = new URLSearchParams(
34
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
35
- ).toString();
30
+ });
36
31
  try {
37
- const response = await openmrsFetch(`${url}?${queryString}`);
32
+ const response = await openmrsFetch(url);
38
33
 
39
34
  if (!response.ok) {
40
35
  const errorText = await response.text();
@@ -53,20 +48,16 @@ export async function getMoh706(params: Moh706Params): Promise<Array<Record<stri
53
48
  }
54
49
  }
55
50
 
56
- export async function getMoh706PatientList(params: Moh706PatientListParams): Promise<Array<Record<string, unknown>>> {
57
- const etlBaseUrl = await getEtlBaseUrl();
58
- const url = `${etlBaseUrl}/lab-706/patient-list`;
59
- const queryparams = {
51
+ export async function getMoh706PatientList(params: PatientListParams): Promise<PatientListPage> {
52
+ const url = await buildEtlUrl('lab-706/patient-list', {
60
53
  locationUuids: params.locationUuids || '',
61
54
  startDate: params.startDate || '',
62
55
  endDate: params.endDate || '',
63
56
  indicators: params.indicators || '',
64
- };
65
- const queryString = new URLSearchParams(
66
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
67
- ).toString();
57
+ ...pageParams(params),
58
+ });
68
59
  try {
69
- const response = await openmrsFetch(`${url}?${queryString}`);
60
+ const response = await openmrsFetch(url);
70
61
 
71
62
  if (!response.ok) {
72
63
  const errorText = await response.text();
@@ -75,11 +66,7 @@ export async function getMoh706PatientList(params: Moh706PatientListParams): Pro
75
66
 
76
67
  const data = await response.json();
77
68
 
78
- if (!Array.isArray(data.result)) {
79
- throw new Error('Invalid MOH-706 patient list response format: missing result array.');
80
- }
81
-
82
- return data.result;
69
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
83
70
  } catch (error: any) {
84
71
  throw new Error(`An error occurred while fetching the MOH-706 patient list: ${error.message}`);
85
72
  }
@@ -1,5 +1,5 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
3
 
4
4
  interface Moh710Params {
5
5
  locationUuids: string;
@@ -9,18 +9,13 @@ interface Moh710Params {
9
9
  }
10
10
 
11
11
  export async function getMoh710(params: Moh710Params): Promise<any> {
12
- const etlBaseUrl = await getEtlBaseUrl();
13
- const url = `${etlBaseUrl}/moh-710`;
14
- const queryparams = {
12
+ const url = await buildEtlUrl('moh-710', {
15
13
  locationUuids: params.locationUuids || '',
16
14
  startDate: params.startDate || '',
17
15
  endDate: params.endDate || '',
18
- };
19
- const queryString = new URLSearchParams(
20
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
21
- ).toString();
16
+ });
22
17
  try {
23
- const response = await openmrsFetch(`${url}?${queryString}`);
18
+ const response = await openmrsFetch(url);
24
19
 
25
20
  if (!response.ok) {
26
21
  const errorText = await response.text();
@@ -35,19 +30,14 @@ export async function getMoh710(params: Moh710Params): Promise<any> {
35
30
  }
36
31
 
37
32
  export async function getMoh710PatientList(params: Moh710Params): Promise<any> {
38
- const etlBaseUrl = await getEtlBaseUrl();
39
- const url = `${etlBaseUrl}/moh-710-patient-list`;
40
- const queryparams = {
33
+ const url = await buildEtlUrl('moh-710-patient-list', {
41
34
  locationUuids: params.locationUuids || '',
42
35
  startDate: params.startDate || '',
43
36
  endDate: params.endDate || '',
44
37
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
45
- };
46
- const queryString = new URLSearchParams(
47
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
48
- ).toString();
38
+ });
49
39
  try {
50
- const response = await openmrsFetch(`${url}?${queryString}`);
40
+ const response = await openmrsFetch(url);
51
41
 
52
42
  if (!response.ok) {
53
43
  const errorText = await response.text();
@@ -1,5 +1,12 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
+ import {
4
+ PAGE_SIZE,
5
+ pageParams,
6
+ toPatientListPage,
7
+ type PatientListPage,
8
+ type PatientListParams,
9
+ } from './patient-list-page';
3
10
 
4
11
  interface Moh711Params {
5
12
  locationUuids: string;
@@ -10,18 +17,13 @@ interface Moh711Params {
10
17
  }
11
18
 
12
19
  export async function getMoh711(params: Moh711Params): Promise<any> {
13
- const etlBaseUrl = await getEtlBaseUrl();
14
- const url = `${etlBaseUrl}/moh-711`;
15
- const queryparams = {
20
+ const url = await buildEtlUrl('moh-711', {
16
21
  locationUuids: params.locationUuids || '',
17
22
  startDate: params.startDate || '',
18
23
  endDate: params.endDate || '',
19
- };
20
- const queryString = new URLSearchParams(
21
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
22
- ).toString();
24
+ });
23
25
  try {
24
- const response = await openmrsFetch(`${url}?${queryString}`);
26
+ const response = await openmrsFetch(url);
25
27
 
26
28
  if (!response.ok) {
27
29
  const errorText = await response.text();
@@ -35,22 +37,17 @@ export async function getMoh711(params: Moh711Params): Promise<any> {
35
37
  }
36
38
  }
37
39
 
38
- export async function getMoh406PatientList(params: Moh711Params): Promise<any> {
39
- const etlBaseUrl = await getEtlBaseUrl();
40
- const url = `${etlBaseUrl}/moh-406-patient-list`;
41
- const queryparams = {
40
+ export async function getMoh406PatientList(params: PatientListParams): Promise<PatientListPage> {
41
+ const url = await buildEtlUrl('moh-406-patient-list', {
42
42
  locationUuids: params.locationUuids || '',
43
43
  startDate: params.startDate || '',
44
44
  endDate: params.endDate || '',
45
45
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
46
46
  reportName: params.reportName || '',
47
- limit: '300',
48
- };
49
- const queryString = new URLSearchParams(
50
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
51
- ).toString();
47
+ ...pageParams(params),
48
+ });
52
49
  try {
53
- const response = await openmrsFetch(`${url}?${queryString}`);
50
+ const response = await openmrsFetch(url);
54
51
 
55
52
  if (!response.ok) {
56
53
  const errorText = await response.text();
@@ -58,28 +55,24 @@ export async function getMoh406PatientList(params: Moh711Params): Promise<any> {
58
55
  }
59
56
 
60
57
  const data = await response.json();
61
- return data;
58
+
59
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
62
60
  } catch (error: any) {
63
61
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
64
62
  }
65
63
  }
66
64
 
67
- export async function getMoh405PatientList(params: Moh711Params): Promise<any> {
68
- const etlBaseUrl = await getEtlBaseUrl();
69
- const url = `${etlBaseUrl}/moh-405-patient-list`;
70
- const queryparams = {
65
+ export async function getMoh405PatientList(params: PatientListParams): Promise<PatientListPage> {
66
+ const url = await buildEtlUrl('moh-405-patient-list', {
71
67
  locationUuids: params.locationUuids || '',
72
68
  startDate: params.startDate || '',
73
69
  endDate: params.endDate || '',
74
70
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
75
71
  reportName: params.reportName || '',
76
- limit: '300',
77
- };
78
- const queryString = new URLSearchParams(
79
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
80
- ).toString();
72
+ ...pageParams(params),
73
+ });
81
74
  try {
82
- const response = await openmrsFetch(`${url}?${queryString}`);
75
+ const response = await openmrsFetch(url);
83
76
 
84
77
  if (!response.ok) {
85
78
  const errorText = await response.text();
@@ -87,28 +80,24 @@ export async function getMoh405PatientList(params: Moh711Params): Promise<any> {
87
80
  }
88
81
 
89
82
  const data = await response.json();
90
- return data;
83
+
84
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
91
85
  } catch (error: any) {
92
86
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
93
87
  }
94
88
  }
95
89
 
96
- export async function getMoh333PatientList(params: Moh711Params): Promise<any> {
97
- const etlBaseUrl = await getEtlBaseUrl();
98
- const url = `${etlBaseUrl}/moh-333-patient-list`;
99
- const queryparams = {
90
+ export async function getMoh333PatientList(params: PatientListParams): Promise<PatientListPage> {
91
+ const url = await buildEtlUrl('moh-333-patient-list', {
100
92
  locationUuids: params.locationUuids || '',
101
93
  startDate: params.startDate || '',
102
94
  endDate: params.endDate || '',
103
95
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
104
96
  reportName: params.reportName || '',
105
- limit: '300',
106
- };
107
- const queryString = new URLSearchParams(
108
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
109
- ).toString();
97
+ ...pageParams(params),
98
+ });
110
99
  try {
111
- const response = await openmrsFetch(`${url}?${queryString}`);
100
+ const response = await openmrsFetch(url);
112
101
 
113
102
  if (!response.ok) {
114
103
  const errorText = await response.text();
@@ -116,27 +105,23 @@ export async function getMoh333PatientList(params: Moh711Params): Promise<any> {
116
105
  }
117
106
 
118
107
  const data = await response.json();
119
- return data;
108
+
109
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
120
110
  } catch (error: any) {
121
111
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
122
112
  }
123
113
  }
124
114
 
125
- export async function getMoh510PatientList(params: Moh711Params): Promise<any> {
126
- const etlBaseUrl = await getEtlBaseUrl();
127
- const url = `${etlBaseUrl}/moh-510-patient-list`;
128
- const queryparams = {
115
+ export async function getMoh510PatientList(params: PatientListParams): Promise<PatientListPage> {
116
+ const url = await buildEtlUrl('moh-510-patient-list', {
129
117
  locationUuids: params.locationUuids || '',
130
118
  startDate: params.startDate || '',
131
119
  endDate: params.endDate || '',
132
120
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
133
- limit: '300',
134
- };
135
- const queryString = new URLSearchParams(
136
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
137
- ).toString();
121
+ ...pageParams(params),
122
+ });
138
123
  try {
139
- const response = await openmrsFetch(`${url}?${queryString}`);
124
+ const response = await openmrsFetch(url);
140
125
 
141
126
  if (!response.ok) {
142
127
  const errorText = await response.text();
@@ -144,28 +129,24 @@ export async function getMoh510PatientList(params: Moh711Params): Promise<any> {
144
129
  }
145
130
 
146
131
  const data = await response.json();
147
- return data;
132
+
133
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
148
134
  } catch (error: any) {
149
135
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
150
136
  }
151
137
  }
152
138
 
153
- export async function getMoh511PatientList(params: Moh711Params): Promise<any> {
154
- const etlBaseUrl = await getEtlBaseUrl();
155
- const url = `${etlBaseUrl}/moh-511-patient-list`;
156
- const queryparams = {
139
+ export async function getMoh511PatientList(params: PatientListParams): Promise<PatientListPage> {
140
+ const url = await buildEtlUrl('moh-511-patient-list', {
157
141
  locationUuids: params.locationUuids || '',
158
142
  startDate: params.startDate || '',
159
143
  endDate: params.endDate || '',
160
144
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
161
145
  reportName: params.reportName || '',
162
- limit: '300',
163
- };
164
- const queryString = new URLSearchParams(
165
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
166
- ).toString();
146
+ ...pageParams(params),
147
+ });
167
148
  try {
168
- const response = await openmrsFetch(`${url}?${queryString}`);
149
+ const response = await openmrsFetch(url);
169
150
 
170
151
  if (!response.ok) {
171
152
  const errorText = await response.text();
@@ -173,7 +154,8 @@ export async function getMoh511PatientList(params: Moh711Params): Promise<any> {
173
154
  }
174
155
 
175
156
  const data = await response.json();
176
- return data;
157
+
158
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
177
159
  } catch (error: any) {
178
160
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
179
161
  }
@@ -1,5 +1,5 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
3
 
4
4
  interface Moh717Params {
5
5
  locationUuids: string;
@@ -8,19 +8,14 @@ interface Moh717Params {
8
8
  }
9
9
 
10
10
  export async function getMoh717(params: Moh717Params): Promise<any> {
11
- const etlBaseUrl = await getEtlBaseUrl();
12
- const url = `${etlBaseUrl}/moh-717`;
13
- const queryparams = {
11
+ const url = await buildEtlUrl('moh-717', {
14
12
  locationUuids: params.locationUuids || '',
15
13
  startDate: params.startDate || '',
16
14
  endDate: params.endDate || '',
17
- };
18
- const queryString = new URLSearchParams(
19
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
20
- ).toString();
15
+ });
21
16
 
22
17
  try {
23
- const response = await openmrsFetch(`${url}?${queryString}`);
18
+ const response = await openmrsFetch(url);
24
19
 
25
20
  if (!response.ok) {
26
21
  const errorText = await response.text();
@@ -35,19 +30,14 @@ export async function getMoh717(params: Moh717Params): Promise<any> {
35
30
  }
36
31
 
37
32
  export async function getNutritionRegister(params: Moh717Params): Promise<any> {
38
- const etlBaseUrl = await getEtlBaseUrl();
39
- const url = `${etlBaseUrl}/moh-717`;
40
- const queryparams = {
33
+ const url = await buildEtlUrl('moh-717', {
41
34
  locationUuids: params.locationUuids || '',
42
35
  startDate: params.startDate || '',
43
36
  endDate: params.endDate || '',
44
- };
45
- const queryString = new URLSearchParams(
46
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
47
- ).toString();
37
+ });
48
38
 
49
39
  try {
50
- const response = await openmrsFetch(`${url}?${queryString}`);
40
+ const response = await openmrsFetch(url);
51
41
 
52
42
  if (!response.ok) {
53
43
  const errorText = await response.text();
@@ -1,5 +1,12 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
+ import {
4
+ PAGE_SIZE,
5
+ pageParams,
6
+ toPatientListPage,
7
+ type PatientListPage,
8
+ type PatientListParams,
9
+ } from './patient-list-page';
3
10
 
4
11
  interface Moh745Params {
5
12
  locationUuids: string;
@@ -10,18 +17,13 @@ interface Moh745Params {
10
17
  }
11
18
 
12
19
  export async function getMoh731(params: Moh745Params): Promise<any> {
13
- const etlBaseUrl = await getEtlBaseUrl();
14
- const url = `${etlBaseUrl}/moh-731-monthly-summary`;
15
- const queryparams = {
20
+ const url = await buildEtlUrl('moh-731-monthly-summary', {
16
21
  locationUuids: params.locationUuids || '',
17
22
  startDate: params.startDate || '',
18
23
  endDate: params.endDate || '',
19
- };
20
- const queryString = new URLSearchParams(
21
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
22
- ).toString();
24
+ });
23
25
  try {
24
- const response = await openmrsFetch(`${url}?${queryString}`);
26
+ const response = await openmrsFetch(url);
25
27
 
26
28
  if (!response.ok) {
27
29
  const errorText = await response.text();
@@ -31,26 +33,21 @@ export async function getMoh731(params: Moh745Params): Promise<any> {
31
33
  const data = await response.json();
32
34
  return data;
33
35
  } catch (error: any) {
34
- throw new Error(`An error occurred while fetching the MOH-710 report: ${error.message}`);
36
+ throw new Error(`An error occurred while fetching the MOH-731 report: ${error.message}`);
35
37
  }
36
38
  }
37
39
 
38
- export async function getMoh366PatientList(params: Moh745Params): Promise<any> {
39
- const etlBaseUrl = await getEtlBaseUrl();
40
- const url = `${etlBaseUrl}/moh-731-monthly-summary-patient-list`;
41
- const queryparams = {
40
+ export async function getMoh366PatientList(params: PatientListParams): Promise<PatientListPage> {
41
+ const url = await buildEtlUrl('moh-731-monthly-summary-patient-list', {
42
42
  locationUuids: params.locationUuids || '',
43
43
  startDate: params.startDate || '',
44
44
  endDate: params.endDate || '',
45
45
  indicator: params.indicator || '',
46
46
  gender: params.gender || '',
47
- limit: '300',
48
- };
49
- const queryString = new URLSearchParams(
50
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
51
- ).toString();
47
+ ...pageParams(params),
48
+ });
52
49
  try {
53
- const response = await openmrsFetch(`${url}?${queryString}`);
50
+ const response = await openmrsFetch(url);
54
51
 
55
52
  if (!response.ok) {
56
53
  const errorText = await response.text();
@@ -58,29 +55,25 @@ export async function getMoh366PatientList(params: Moh745Params): Promise<any> {
58
55
  }
59
56
 
60
57
  const data = await response.json();
61
- return data;
58
+
59
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
62
60
  } catch (error: any) {
63
61
  console.error('Failed to fetch MOH 412 PATIENT LIST data', error);
64
62
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
65
63
  }
66
64
  }
67
65
 
68
- export async function getPrepPatientList(params: Moh745Params): Promise<any> {
69
- const etlBaseUrl = await getEtlBaseUrl();
70
- const url = `${etlBaseUrl}/prep-patient-list`;
71
- const queryparams = {
66
+ export async function getPrepPatientList(params: PatientListParams): Promise<PatientListPage> {
67
+ const url = await buildEtlUrl('prep-patient-list', {
72
68
  locationUuids: params.locationUuids || '',
73
69
  startDate: params.startDate || '',
74
70
  endDate: params.endDate || '',
75
71
  indicator: params.indicator || '',
76
72
  gender: params.gender || '',
77
- limit: '300',
78
- };
79
- const queryString = new URLSearchParams(
80
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
81
- ).toString();
73
+ ...pageParams(params),
74
+ });
82
75
  try {
83
- const response = await openmrsFetch(`${url}?${queryString}`);
76
+ const response = await openmrsFetch(url);
84
77
 
85
78
  if (!response.ok) {
86
79
  const errorText = await response.text();
@@ -88,7 +81,8 @@ export async function getPrepPatientList(params: Moh745Params): Promise<any> {
88
81
  }
89
82
 
90
83
  const data = await response.json();
91
- return data;
84
+
85
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
92
86
  } catch (error: any) {
93
87
  console.error('Failed to fetch MOH 412 PATIENT LIST data', error);
94
88
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
@@ -1,5 +1,12 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl } from '../utils/get-base-url';
2
+ import { buildEtlUrl } from '../utils/get-base-url';
3
+ import {
4
+ PAGE_SIZE,
5
+ pageParams,
6
+ toPatientListPage,
7
+ type PatientListPage,
8
+ type PatientListParams,
9
+ } from './patient-list-page';
3
10
 
4
11
  interface Moh745Params {
5
12
  locationUuids: string;
@@ -9,18 +16,13 @@ interface Moh745Params {
9
16
  }
10
17
 
11
18
  export async function getMoh745(params: Moh745Params): Promise<any> {
12
- const etlBaseUrl = await getEtlBaseUrl();
13
- const url = `${etlBaseUrl}/moh-745`;
14
- const queryparams = {
19
+ const url = await buildEtlUrl('moh-745', {
15
20
  locationUuids: params.locationUuids || '',
16
21
  startDate: params.startDate || '',
17
22
  endDate: params.endDate || '',
18
- };
19
- const queryString = new URLSearchParams(
20
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
21
- ).toString();
23
+ });
22
24
  try {
23
- const response = await openmrsFetch(`${url}?${queryString}`);
25
+ const response = await openmrsFetch(url);
24
26
 
25
27
  if (!response.ok) {
26
28
  const errorText = await response.text();
@@ -34,21 +36,16 @@ export async function getMoh745(params: Moh745Params): Promise<any> {
34
36
  }
35
37
  }
36
38
 
37
- export async function getMoh412PatientList(params: Moh745Params): Promise<any> {
38
- const etlBaseUrl = await getEtlBaseUrl();
39
- const url = `${etlBaseUrl}/moh-412-patient-list`;
40
- const queryparams = {
39
+ export async function getMoh412PatientList(params: PatientListParams): Promise<PatientListPage> {
40
+ const url = await buildEtlUrl('moh-412-patient-list', {
41
41
  locationUuids: params.locationUuids || '',
42
42
  startDate: params.startDate || '',
43
43
  endDate: params.endDate || '',
44
44
  indicator: Array.isArray(params.indicator) ? params.indicator.join(',') : params.indicator || '',
45
- limit: '300',
46
- };
47
- const queryString = new URLSearchParams(
48
- Object.fromEntries(Object.entries(queryparams).filter(([_, v]) => v !== undefined && v !== null)),
49
- ).toString();
45
+ ...pageParams(params),
46
+ });
50
47
  try {
51
- const response = await openmrsFetch(`${url}?${queryString}`);
48
+ const response = await openmrsFetch(url);
52
49
 
53
50
  if (!response.ok) {
54
51
  const errorText = await response.text();
@@ -56,7 +53,8 @@ export async function getMoh412PatientList(params: Moh745Params): Promise<any> {
56
53
  }
57
54
 
58
55
  const data = await response.json();
59
- return data;
56
+
57
+ return toPatientListPage(data, params.startIndex ?? 0, params.limit ?? PAGE_SIZE);
60
58
  } catch (error: any) {
61
59
  console.error('Failed to fetch MOH 412 PATIENT LIST data', error);
62
60
  throw new Error(`An error occurred while fetching the MOH-705 patient list: ${error.message}`);
@@ -0,0 +1,66 @@
1
+ /** How many rows a register asks for at a time */
2
+ export const PAGE_SIZE = 50;
3
+
4
+ export interface PatientListParams {
5
+ locationUuids: string;
6
+ startDate?: string;
7
+ endDate?: string;
8
+ indicator?: string;
9
+ indicators?: string;
10
+ gender?: string;
11
+ /** MOH-711 endpoints scope the list by report */
12
+ reportName?: string;
13
+ /** Row to start at, 0-based, as the ETL expects */
14
+ startIndex?: number;
15
+ limit?: number;
16
+ }
17
+
18
+ export interface PatientListPage {
19
+ results: Array<Record<string, any>>;
20
+ /** Rows across every page */
21
+ total: number;
22
+ /** `false` when the total had to be inferred rather than read from the response */
23
+ isTotalExact: boolean;
24
+ }
25
+
26
+ /** The paging arguments every patient-list endpoint takes */
27
+ export function pageParams(params: PatientListParams) {
28
+ return {
29
+ startIndex: String(params.startIndex ?? 0),
30
+ limit: String(params.limit ?? PAGE_SIZE),
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Normalises a patient-list response into a page of rows plus a total.
36
+ *
37
+ * The endpoints nest their payload differently and do not all report a count,
38
+ * so the total is read from whichever field carries it and inferred otherwise:
39
+ * a short page means we are on the last one, a full page means there is at
40
+ * least one more. Inferring keeps the pager usable without ever overstating
41
+ * what we know -- `isTotalExact` says which it is.
42
+ */
43
+ export function toPatientListPage(data: any, startIndex: number, limit: number): PatientListPage {
44
+ const container = data?.results ?? data ?? {};
45
+ const results: Array<Record<string, any>> = Array.isArray(container?.results)
46
+ ? container.results
47
+ : Array.isArray(container)
48
+ ? container
49
+ : [];
50
+
51
+ const reported = [container?.total, container?.totalCount, container?.count, data?.total, data?.totalCount].find(
52
+ (value) => typeof value === 'number',
53
+ );
54
+
55
+ if (typeof reported === 'number') {
56
+ return { results, total: reported, isTotalExact: true };
57
+ }
58
+
59
+ const isLastPage = results.length < limit;
60
+
61
+ return {
62
+ results,
63
+ total: isLastPage ? startIndex + results.length : startIndex + results.length + 1,
64
+ isTotalExact: isLastPage,
65
+ };
66
+ }