forked from mekomsolutions/openmrs-module-commonreports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutpatientConsultationReportManager.java
343 lines (281 loc) · 15.3 KB
/
OutpatientConsultationReportManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package org.openmrs.module.mksreports.reports;
import java.util.*;
import org.openmrs.Concept;
import org.openmrs.Location;
import org.openmrs.module.initializer.api.InitializerService;
import org.openmrs.module.mksreports.MKSReportManager;
import org.openmrs.module.mksreports.MKSReportsConstants;
import org.openmrs.module.mksreports.dataset.definition.ObsSummaryRowDataSetDefinition;
import org.openmrs.module.reporting.cohort.definition.AgeCohortDefinition;
import org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition;
import org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition;
import org.openmrs.module.reporting.cohort.definition.GenderCohortDefinition;
import org.openmrs.module.reporting.cohort.definition.evaluator.CodedObsCohortDefinitionEvaluator;
import org.openmrs.module.reporting.common.BooleanOperator;
import org.openmrs.module.reporting.common.DurationUnit;
import org.openmrs.module.reporting.common.MessageUtil;
import org.openmrs.module.reporting.common.SetComparator;
import org.openmrs.module.reporting.dataset.definition.CohortCrossTabDataSetDefinition;
import org.openmrs.module.reporting.evaluation.parameter.Mapped;
import org.openmrs.module.reporting.evaluation.parameter.Parameter;
import org.openmrs.module.reporting.report.ReportDesign;
import org.openmrs.module.reporting.report.definition.ReportDefinition;
import org.openmrs.module.reporting.report.manager.ReportManagerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component(MKSReportsConstants.COMPONENT_REPORTMANAGER_OPDCONSULT)
public class OutpatientConsultationReportManager extends MKSReportManager {
@Autowired
private InitializerService inizService;
@Override
public boolean isActive() {
return inizService.getBooleanFromKey("report.opdconsult.active", true);
}
@Override
public String getVersion() {
return "1.0.0-SNAPSHOT";
}
@Override
public String getUuid() {
return "58d7a2ba-5b62-4e21-ac21-090e3758cce7";
}
@Override
public String getName() {
return "HC1 Outpatient Consultation";
}
@Override
public String getDescription() {
return "";
}
private Parameter getStartDateParameter() {
return new Parameter("startDate", "Start Date", Date.class);
}
private Parameter getEndDateParameter() {
return new Parameter("endDate", "End Date", Date.class);
}
private Parameter getLocationParameter() {
return new Parameter("locationList", "Visit Location", Location.class, List.class, null);
}
public static String col1 = "";
public static String col2 = "";
public static String col3 = "";
public static String col4 = "";
public static String col5 = "";
public static String col6 = "";
public static String col7 = "";
public static String col8 = "";
public static String col9 = "";
public static String col10 = "";
public static String col11 = "";
public static String col12 = "";
public static String col13 = "";
public static String col14 = "";
public static String col15 = "";
public static String col16 = "";
public static String col17 = "";
public static String col18 = "";
public static String col19 = "";
public static String col20 = "";
public static String col21 = "";
public static String col22 = "";
public static String col23 = "";
@Override
public List<Parameter> getParameters() {
List<Parameter> params = new ArrayList<Parameter>();
params.add(getStartDateParameter());
params.add(getEndDateParameter());
params.add(getLocationParameter());
return params;
}
@Override
public ReportDefinition constructReportDefinition() {
ReportDefinition rd = new ReportDefinition();
rd.setUuid(getUuid());
rd.setName(getName());
rd.setDescription(getDescription());
rd.setParameters(getParameters());
CohortCrossTabDataSetDefinition opdConsult = new CohortCrossTabDataSetDefinition();
opdConsult.addParameters(getParameters());
rd.addDataSetDefinition(getName(), Mapped.mapStraightThrough(opdConsult));
Concept allDiags = inizService.getConceptFromKey("report.opdconsult.diagnoses.conceptSet");
List<Concept> questionConcepts = inizService.getConceptsFromKey("report.opdconsult.diagnosisQuestion.concepts");
ObsSummaryRowDataSetDefinition obsSummaryDS = new ObsSummaryRowDataSetDefinition();
obsSummaryDS.addParameters(getParameters());
obsSummaryDS.setConceptList(allDiags.getSetMembers());
obsSummaryDS.setQuestions(questionConcepts);
rd.addDataSetDefinition("Obs Summary", Mapped.mapStraightThrough(obsSummaryDS));
Map<String, Object> parameterMappings = new HashMap<String, Object>();
parameterMappings.put("onOrAfter", "${startDate}");
parameterMappings.put("onOrBefore", "${endDate}");
parameterMappings.put("locationList", "${locationList}");
for (Concept member : allDiags.getSetMembers()) {
List<CodedObsCohortDefinition> codedObsList = new ArrayList<>();
for (Concept question : questionConcepts) {
CodedObsCohortDefinition diag = new CodedObsCohortDefinition();
diag.addParameter(new Parameter("onOrAfter", "On Or After", Date.class));
diag.addParameter(new Parameter("onOrBefore", "On Or Before", Date.class));
diag.addParameter(new Parameter("locationList", "Visit Location", Location.class, List.class, null));
diag.setOperator(SetComparator.IN);
diag.setQuestion(question);
diag.setValueList(Arrays.asList(member));
codedObsList.add(diag);
}
CompositionCohortDefinition compCD = new CompositionCohortDefinition();
compCD.initializeFromQueries(BooleanOperator.OR,
codedObsList.toArray(new CodedObsCohortDefinition[codedObsList.size()]));
opdConsult.addRow(member.getDisplayString(), compCD, parameterMappings);
}
setColumnNames();
GenderCohortDefinition males = new GenderCohortDefinition();
males.setMaleIncluded(true);
GenderCohortDefinition females = new GenderCohortDefinition();
females.setFemaleIncluded(true);
AgeCohortDefinition _0To1m = new AgeCohortDefinition();
_0To1m.setMinAge(0);
_0To1m.setMinAgeUnit(DurationUnit.DAYS);
_0To1m.setMaxAge(1);
_0To1m.setMaxAgeUnit(DurationUnit.MONTHS);
opdConsult.addColumn(col1, createCohortComposition(_0To1m, males), null);
opdConsult.addColumn(col2, createCohortComposition(_0To1m, females), null);
obsSummaryDS.addColumn(col1, createCohortComposition(_0To1m, males));
obsSummaryDS.addColumn(col2, createCohortComposition(_0To1m, females));
AgeCohortDefinition _1mTo1y = new AgeCohortDefinition();
_1mTo1y.setMinAge(1);
_1mTo1y.setMinAgeUnit(DurationUnit.MONTHS);
_1mTo1y.setMaxAge(11);
_1mTo1y.setMaxAgeUnit(DurationUnit.MONTHS);
opdConsult.addColumn(col3, createCohortComposition(_1mTo1y, males), null);
opdConsult.addColumn(col4, createCohortComposition(_1mTo1y, females), null);
obsSummaryDS.addColumn(col3, createCohortComposition(_1mTo1y, males));
obsSummaryDS.addColumn(col4, createCohortComposition(_1mTo1y, females));
AgeCohortDefinition _1To5y = new AgeCohortDefinition();
_1To5y.setMinAge(1);
_1To5y.setMinAgeUnit(DurationUnit.YEARS);
_1To5y.setMaxAge(4);
_1To5y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col5, createCohortComposition(_1To5y, males), null);
opdConsult.addColumn(col6, createCohortComposition(_1To5y, females), null);
obsSummaryDS.addColumn(col5, createCohortComposition(_1To5y, males));
obsSummaryDS.addColumn(col6, createCohortComposition(_1To5y, females));
AgeCohortDefinition _5To15y = new AgeCohortDefinition();
_5To15y.setMinAge(5);
_5To15y.setMinAgeUnit(DurationUnit.YEARS);
_5To15y.setMaxAge(14);
_5To15y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col7, createCohortComposition(_5To15y, males), null);
opdConsult.addColumn(col8, createCohortComposition(_5To15y, females), null);
obsSummaryDS.addColumn(col7, createCohortComposition(_5To15y, males));
obsSummaryDS.addColumn(col8, createCohortComposition(_5To15y, females));
AgeCohortDefinition _15To25y = new AgeCohortDefinition();
_15To25y.setMinAge(15);
_15To25y.setMinAgeUnit(DurationUnit.YEARS);
_15To25y.setMaxAge(24);
_15To25y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col9, createCohortComposition(_15To25y, males), null);
opdConsult.addColumn(col10, createCohortComposition(_15To25y, females), null);
obsSummaryDS.addColumn(col9, createCohortComposition(_15To25y, males));
obsSummaryDS.addColumn(col10, createCohortComposition(_15To25y, females));
AgeCohortDefinition _25To50y = new AgeCohortDefinition();
_25To50y.setMinAge(25);
_25To50y.setMinAgeUnit(DurationUnit.YEARS);
_25To50y.setMaxAge(49);
_25To50y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col11, createCohortComposition(_25To50y, males), null);
opdConsult.addColumn(col12, createCohortComposition(_25To50y, females), null);
obsSummaryDS.addColumn(col11, createCohortComposition(_25To50y, males));
obsSummaryDS.addColumn(col12, createCohortComposition(_25To50y, females));
AgeCohortDefinition _50To65y = new AgeCohortDefinition();
_50To65y.setMinAge(50);
_50To65y.setMinAgeUnit(DurationUnit.YEARS);
_50To65y.setMaxAge(64);
_50To65y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col13, createCohortComposition(_50To65y, males), null);
opdConsult.addColumn(col14, createCohortComposition(_50To65y, females), null);
obsSummaryDS.addColumn(col13, createCohortComposition(_50To65y, males));
obsSummaryDS.addColumn(col14, createCohortComposition(_50To65y, females));
AgeCohortDefinition moreThan65y = new AgeCohortDefinition();
moreThan65y.setMinAge(65);
moreThan65y.setMinAgeUnit(DurationUnit.YEARS);
moreThan65y.setMaxAge(200);
moreThan65y.setMaxAgeUnit(DurationUnit.YEARS);
opdConsult.addColumn(col15, createCohortComposition(moreThan65y, males), null);
opdConsult.addColumn(col16, createCohortComposition(moreThan65y, females), null);
obsSummaryDS.addColumn(col15, createCohortComposition(moreThan65y, males));
obsSummaryDS.addColumn(col16, createCohortComposition(moreThan65y, females));
// Total column
GenderCohortDefinition total = new GenderCohortDefinition();
total.setFemaleIncluded(true);
total.setMaleIncluded(true);
total.setUnknownGenderIncluded(true);
opdConsult.addColumn(col17, createCohortComposition(total, males), null);
opdConsult.addColumn(col18, createCohortComposition(total, females), null);
opdConsult.addColumn(col23, createCohortComposition(total), null);
obsSummaryDS.addColumn(col23, createCohortComposition(total));
// Referred To column
CodedObsCohortDefinition referredTo = new CodedObsCohortDefinition();
referredTo.addParameter(new Parameter("onOrAfter", "On Or After", Date.class));
referredTo.addParameter(new Parameter("onOrBefore", "On Or Before", Date.class));
referredTo.setOperator(SetComparator.IN);
referredTo.setQuestion(inizService.getConceptFromKey("report.opdconsult.referredTo.concept"));
opdConsult.addColumn(col19, createCohortComposition(referredTo, males), null);
opdConsult.addColumn(col20, createCohortComposition(referredTo, females), null);
return rd;
}
private void setColumnNames() {
col1 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory1.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col2 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory1.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col3 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory2.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col4 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory2.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col5 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory3.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col6 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory3.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col7 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory4.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col8 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory4.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col9 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory5.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col10 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory5.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col11 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory6.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col12 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory6.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col13 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory7.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col14 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory7.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col15 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory8.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col16 = MessageUtil.translate("mksreports.report.outpatientRecordBook.ageCategory8.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col17 = MessageUtil.translate("mksreports.report.opdconsult.total.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col18 = MessageUtil.translate("mksreports.report.opdconsult.total.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col19 = MessageUtil.translate("mksreports.report.opdconsult.referredTo.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col20 = MessageUtil.translate("mksreports.report.opdconsult.referredTo.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col21 = MessageUtil.translate("mksreports.report.opdconsult.hefId.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.males.label");
col22 = MessageUtil.translate("mksreports.report.opdconsult.hefId.label") + " - "
+ MessageUtil.translate("mksreports.report.opdconsult.females.label");
col23 = MessageUtil.translate("mksreports.report.opdconsult.total.label");
}
private CompositionCohortDefinition createCohortComposition(Object... elements) {
CompositionCohortDefinition compCD = new CompositionCohortDefinition();
compCD.initializeFromElements(elements);
return compCD;
}
@Override
public List<ReportDesign> constructReportDesigns(ReportDefinition reportDefinition) {
return Arrays
.asList(ReportManagerUtil.createCsvReportDesign("42b32ac1-fcd0-473d-8fdb-71fd6fc2e26d", reportDefinition));
}
}