Skip to content

Commit 095e781

Browse files
committed
Adding the VL Exchange transaction report
1 parent d4f8f76 commit 095e781

File tree

7 files changed

+344
-0
lines changed

7 files changed

+344
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.openmrs.module.ugandaemrreports.definition.dataset.definition;
2+
3+
import org.openmrs.Encounter;
4+
import org.openmrs.module.reporting.dataset.definition.BaseDataSetDefinition;
5+
import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty;
6+
7+
import java.util.Date;
8+
9+
/**
10+
*/
11+
public class VLExchangeDatasetDefinition extends BaseDataSetDefinition {
12+
13+
private static final long serialVersionUID = 6405583324151111487L;
14+
@ConfigurationProperty
15+
private Date startDate;
16+
17+
@ConfigurationProperty
18+
private Date endDate;
19+
20+
@ConfigurationProperty
21+
private Encounter encounter;
22+
23+
public VLExchangeDatasetDefinition() {
24+
super();
25+
}
26+
27+
public VLExchangeDatasetDefinition(String name, String description) {
28+
super(name, description);
29+
}
30+
31+
public Date getStartDate() {
32+
return startDate;
33+
}
34+
35+
public void setStartDate(Date startDate) {
36+
this.startDate = startDate;
37+
}
38+
39+
public static long getSerialVersionUID() {
40+
return serialVersionUID;
41+
}
42+
43+
public Date getEndDate() {
44+
return endDate;
45+
}
46+
47+
public void setEndDate(Date endDate) {
48+
this.endDate = endDate;
49+
}
50+
51+
public Encounter getEncounter() {
52+
return encounter;
53+
}
54+
55+
public void setEncounter(Encounter encounter) {
56+
this.encounter = encounter;
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package org.openmrs.module.ugandaemrreports.definition.dataset.evaluator;
2+
3+
import com.google.common.base.Joiner;
4+
import org.openmrs.annotation.Handler;
5+
import org.openmrs.module.reporting.common.DateUtil;
6+
import org.openmrs.module.reporting.common.ObjectUtil;
7+
import org.openmrs.module.reporting.dataset.DataSet;
8+
import org.openmrs.module.reporting.dataset.DataSetRow;
9+
import org.openmrs.module.reporting.dataset.SimpleDataSet;
10+
import org.openmrs.module.reporting.dataset.definition.DataSetDefinition;
11+
import org.openmrs.module.reporting.dataset.definition.evaluator.DataSetEvaluator;
12+
import org.openmrs.module.reporting.evaluation.EvaluationContext;
13+
import org.openmrs.module.reporting.evaluation.EvaluationException;
14+
import org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder;
15+
import org.openmrs.module.reporting.evaluation.service.EvaluationService;
16+
import org.openmrs.module.ugandaemrreports.common.PatientDataHelper;
17+
import org.openmrs.module.ugandaemrreports.common.PersonDemographics;
18+
import org.openmrs.module.ugandaemrreports.definition.dataset.definition.VLExchangeDatasetDefinition;
19+
import org.springframework.beans.factory.annotation.Autowired;
20+
21+
import java.sql.Connection;
22+
import java.sql.SQLException;
23+
import java.util.*;
24+
import java.util.stream.Collectors;
25+
import java.util.stream.Stream;
26+
27+
import static org.openmrs.module.ugandaemrreports.reports.Helper.*;
28+
29+
30+
/**
31+
*/
32+
@Handler(supports = {VLExchangeDatasetDefinition.class})
33+
public class VLExchangeDatasetDefinitionEvaluator implements DataSetEvaluator {
34+
35+
@Autowired
36+
EvaluationService evaluationService;
37+
38+
39+
Map<Integer,String> drugNames = new HashMap<>();
40+
@Override
41+
public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context) throws EvaluationException {
42+
43+
VLExchangeDatasetDefinition definition = (VLExchangeDatasetDefinition) dataSetDefinition;
44+
45+
46+
SimpleDataSet dataSet = new SimpleDataSet(dataSetDefinition, context);
47+
PatientDataHelper pdh = new PatientDataHelper();
48+
49+
String startDate = DateUtil.formatDate(definition.getStartDate(), "yyyy-MM-dd");
50+
String endDate = DateUtil.formatDate(definition.getEndDate(), "yyyy-MM-dd");
51+
52+
startDate = startDate+" 00:00:00";
53+
endDate = endDate+" 23:59:59";
54+
context = ObjectUtil.nvl(context, new EvaluationContext());
55+
56+
String dataQuery = String.format("SELECT pi.identifier as HIV_clinic_no,\n" +
57+
" p.birthdate,\n" +
58+
" TIMESTAMPDIFF(YEAR,p.birthdate,CURRENT_DATE) AS age,\n" +
59+
" p.gender,\n" +
60+
" accession_number AS specimen_id,\n" +
61+
" specimen_source,\n" +
62+
" DATE(date_activated),\n" +
63+
" DATE(send_request_sync_task.date_sent) AS send_request_date_sent,\n" +
64+
" send_request_sync_task.status AS send_request_status,\n" +
65+
" send_request_sync_task.status_code AS send_request_status_code,\n" +
66+
" program_data_task.status as program_data_status,\n" +
67+
" program_data_task.status_code as program_data_status_code,\n" +
68+
" DATE(program_data_task.date_created) as program_data_date,\n" +
69+
" DATE(request_result_task.date_created) as request_results_date,\n" +
70+
" request_result_task.status as request_results,\n" +
71+
" request_result_task.status_code as request_status_code\n" +
72+
"\n" +
73+
"FROM (SELECT orders.patient_id,orders.date_activated,orders.accession_number, test_order.specimen_source\n" +
74+
" FROM orders\n" +
75+
" INNER JOIN test_order ON (test_order.order_id = orders.order_id)\n" +
76+
"WHERE accession_number IS NOT NULL\n" +
77+
" AND specimen_source IS NOT NULL\n" +
78+
" AND orders.instructions = 'REFER TO cphl'\n" +
79+
" AND orders.concept_id = 165412\n" +
80+
" AND orders.voided = 0\n" +
81+
" AND orders.date_activated >= '%s'\n" +
82+
" AND orders.date_activated <= '%s')cohort\n" +
83+
"LEFT JOIN person p on p.person_id = cohort.patient_id\n" +
84+
"LEFT JOIN sync_task send_request_sync_task on send_request_sync_task.sync_task = accession_number and send_request_sync_task.sync_task_type = (SELECT sync_task_type_id from sync_task_type where uuid='3551ca84-06c0-432b-9064-fcfeefd6f4ec')\n" +
85+
"LEFT JOIN sync_task request_result_task on request_result_task.sync_task = accession_number and request_result_task.sync_task_type = (SELECT sync_task_type_id from sync_task_type where uuid='3396dcf0-2106-4e73-9b90-c63978c3a8b4')\n" +
86+
"LEFT JOIN sync_task program_data_task on program_data_task.sync_task = accession_number and program_data_task.sync_task_type = (SELECT sync_task_type_id from sync_task_type where uuid='f9b2fa5d-5d37-4fd9-b20a-a0cab664f520')\n" +
87+
"LEFT JOIN patient_identifier pi ON pi.patient_id = cohort.patient_id and pi.identifier_type = (SELECT patient_identifier_type_id from patient_identifier_type where uuid = 'e1731641-30ab-102d-86b0-7a5022ba4115');",startDate,endDate);
88+
89+
SqlQueryBuilder q = new SqlQueryBuilder();
90+
q.append(dataQuery);
91+
92+
List<Object[]> results = evaluationService.evaluateToList(q, context);
93+
94+
if(!results.isEmpty()) {
95+
for (Object[] e : results) {
96+
DataSetRow row = new DataSetRow();
97+
pdh.addCol(row, "HIV Clinic No", e[0]);
98+
pdh.addCol(row, "Birthdate", e[1]);
99+
pdh.addCol(row, "Age", e[2]);
100+
pdh.addCol(row, "Sex", e[3]);
101+
pdh.addCol(row, "Specimen ID", e[4]);
102+
pdh.addCol(row, "Specimen source", e[5]);
103+
pdh.addCol(row, "Date Ordered", e[6]);
104+
pdh.addCol(row, "send_request_date_sent", e[7]);
105+
pdh.addCol(row, "send_request_status", e[8]);
106+
pdh.addCol(row, "send_request_status_code", e[9]);
107+
pdh.addCol(row, "program_data_status", e[10]);
108+
pdh.addCol(row, "program_data_status_code", e[11]);
109+
pdh.addCol(row, "program_data_date", e[12]);
110+
pdh.addCol(row, "request_results_date", e[13]);
111+
pdh.addCol(row, "request_results", e[14]);
112+
pdh.addCol(row, "request_status_code", e[15]);
113+
114+
dataSet.addRow(row);
115+
}
116+
117+
}
118+
return dataSet;
119+
}
120+
121+
}

api/src/main/java/org/openmrs/module/ugandaemrreports/library/HIVCohortDefinitionLibrary.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,4 +772,22 @@ public CohortDefinition getTX_ML(){
772772
return cohortDefinition;
773773
}
774774

775+
public CohortDefinition getPatientsWithVLOrdersInReportingPeriod() {
776+
String query = "SELECT orders.patient_id\n" +
777+
"FROM orders\n" +
778+
" INNER JOIN test_order ON (test_order.order_id = orders.order_id)\n" +
779+
"WHERE accession_number IS NOT NULL\n" +
780+
" AND specimen_source IS NOT NULL\n" +
781+
" AND orders.instructions = 'REFER TO cphl'\n" +
782+
" AND orders.concept_id = 165412\n" +
783+
" AND orders.voided = 0\n" +
784+
" AND orders.date_activated >= ':startDate'\n" +
785+
" AND orders.date_activated <= ':endDate';";
786+
SqlCohortDefinition cohort = new SqlCohortDefinition(query);
787+
cohort.addParameter(new Parameter("startDate", "startDate", Date.class));
788+
cohort.addParameter(new Parameter("endDate", "endDate", Date.class));
789+
790+
return cohort;
791+
}
792+
775793
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package org.openmrs.module.ugandaemrreports.reports2019;
2+
3+
4+
import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
5+
import org.openmrs.module.reporting.data.converter.BirthdateConverter;
6+
import org.openmrs.module.reporting.data.patient.library.BuiltInPatientDataLibrary;
7+
import org.openmrs.module.reporting.data.person.definition.BirthdateDataDefinition;
8+
import org.openmrs.module.reporting.data.person.definition.GenderDataDefinition;
9+
import org.openmrs.module.reporting.data.person.definition.PreferredNameDataDefinition;
10+
import org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition;
11+
import org.openmrs.module.reporting.evaluation.parameter.Mapped;
12+
import org.openmrs.module.reporting.evaluation.parameter.Parameter;
13+
import org.openmrs.module.reporting.report.ReportDesign;
14+
import org.openmrs.module.reporting.report.definition.ReportDefinition;
15+
import org.openmrs.module.ugandaemrreports.definition.dataset.definition.VLExchangeDatasetDefinition;
16+
import org.openmrs.module.ugandaemrreports.library.*;
17+
import org.openmrs.module.ugandaemrreports.reports.UgandaEMRDataExportManager;
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.stereotype.Component;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.Properties;
24+
25+
/**
26+
* TX ML Patient Listing Report
27+
*/
28+
@Component
29+
public class SetupVLExchangeTransactionReport extends UgandaEMRDataExportManager {
30+
31+
@Autowired
32+
private DataFactory df;
33+
34+
@Autowired
35+
ARTClinicCohortDefinitionLibrary hivCohorts;
36+
@Autowired
37+
private HIVCohortDefinitionLibrary hivCohortDefinitionLibrary;
38+
39+
@Autowired
40+
private BuiltInPatientDataLibrary builtInPatientData;
41+
42+
@Autowired
43+
private HIVPatientDataLibrary hivPatientData;
44+
45+
@Autowired
46+
private BasePatientDataLibrary basePatientData;
47+
48+
/**
49+
* @return the uuid for the report design for exporting to Excel
50+
*/
51+
@Override
52+
public String getExcelDesignUuid() {return "3d7b99b4-51a6-498a-b2cb-99000ff82375";}
53+
54+
public String getCSVDesignUuid() {
55+
return "175762b6-b8a6-4f80-bb66-52f538928a87";
56+
}
57+
58+
@Override
59+
public String getUuid() {
60+
return "1759f19f-a7a7-44c7-b584-b5bafe4c36e8";
61+
}
62+
63+
@Override
64+
public String getName() {
65+
return "Patient List for VL Exchange Transaction Report";
66+
}
67+
68+
@Override
69+
public String getDescription() {
70+
return "VL Exchange Transactions Report";
71+
}
72+
73+
@Override
74+
public List<Parameter> getParameters() {
75+
List<Parameter> l = new ArrayList<Parameter>();
76+
l.add(df.getStartDateParameter());
77+
l.add(df.getEndDateParameter());
78+
return l;
79+
}
80+
81+
82+
@Override
83+
public List<ReportDesign> constructReportDesigns(ReportDefinition reportDefinition) {
84+
List<ReportDesign> l = new ArrayList<ReportDesign>();
85+
l.add(buildReportDesign(reportDefinition));
86+
l.add(buildCSVReportDesign(reportDefinition));
87+
return l;
88+
}
89+
90+
/**
91+
* Build the report design for the specified report, this allows a user to override the report design by adding
92+
* properties and other metadata to the report design
93+
*
94+
* @param reportDefinition
95+
* @return The report design
96+
*/
97+
@Override
98+
public ReportDesign buildReportDesign(ReportDefinition reportDefinition) {
99+
ReportDesign rd = createExcelTemplateDesign(getExcelDesignUuid(), reportDefinition, "VL_Exchange_PatientList.xls");
100+
Properties props = new Properties();
101+
props.put("repeatingSections", "sheet:1,row:7,dataset:VL_EX");
102+
props.put("sortWeight", "5000");
103+
rd.setProperties(props);
104+
return rd;
105+
}
106+
107+
public ReportDesign buildCSVReportDesign(ReportDefinition reportDefinition) {
108+
return createCSVDesign(getCSVDesignUuid(), reportDefinition);
109+
}
110+
111+
@Override
112+
public ReportDefinition constructReportDefinition() {
113+
114+
ReportDefinition rd = new ReportDefinition();
115+
116+
rd.setUuid(getUuid());
117+
rd.setName(getName());
118+
rd.setDescription(getDescription());
119+
rd.setParameters(getParameters());
120+
121+
VLExchangeDatasetDefinition dsd = new VLExchangeDatasetDefinition();
122+
dsd.setName(getName());
123+
dsd.setParameters(getParameters());
124+
125+
rd.addDataSetDefinition("VL_EX", Mapped.mapStraightThrough(dsd));
126+
127+
return rd;
128+
}
129+
130+
@Override
131+
public String getVersion() {
132+
return "0.1.3";
133+
}
134+
}

api/src/main/resources/moduleApplicationContext.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
</property>
2525
<property name="renderers">
2626
<map>
27+
<entry>
28+
<key><value>org.openmrs.web.report.CohortReportWebRenderer</value></key>
29+
<bean class="org.openmrs.web.report.CohortReportWebRenderer"/>
30+
</entry>
2731
<entry>
2832
<key><value>org.openmrs.report.impl.TsvReportRenderer</value></key>
2933
<bean class="org.openmrs.report.impl.TsvReportRenderer"/>

omod/src/main/resources/apps/ugandaemr_reports_app.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,15 @@
666666
"order":15,
667667
"requiredPrivilege": "App: ugandaemrreports.recencyHTSClientCardDataExport"
668668
},
669+
{
670+
"id": "VL Exchange Transaction Report",
671+
"extensionPointId": "org.openmrs.module.ugandaemr.integrationdataexports",
672+
"type": "link",
673+
"label": "VL Exchange Transaction Report",
674+
"url": "reportingui/runReport.page?reportDefinition=1759f19f-a7a7-44c7-b584-b5bafe4c36e8",
675+
"order":20,
676+
"requiredPrivilege": "App: ugandaemrreports.recencyHTSClientCardDataExport"
677+
},
669678
{
670679
"id": "HMIS 105 Section 2",
671680
"extensionPointId": "org.openmrs.module.ugandaemr.reports.monthly",

0 commit comments

Comments
 (0)