Skip to content

Commit

Permalink
Lost Clients Report (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
solemabrothers authored and ssmusoke committed Nov 22, 2018
1 parent be0dd7a commit 0ea218f
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,14 @@ public CohortDefinition getPatientsWhoseMostRecentObsDateIsBetweenValuesByEndDat
return convert(cd, params);
}

public CohortDefinition getLostClients() {
LostPatientsCohortDefinition cd = new LostPatientsCohortDefinition();
cd.setMinimumDays(30);
cd.setMaximumDays(89);
cd.addParameter(new Parameter("startDate", "startDate", Date.class));
cd.addParameter(new Parameter("endDate", "Ending", Date.class));
return convert(cd, ObjectUtil.toMap("startDate=startDate,endDate=endDate"));
}
public CohortDefinition getLastVisitInTheQuarter(Concept question, TimeModifier timeModifier) {
HavingVisitCohortDefinition cd = new HavingVisitCohortDefinition();
cd.setTimeModifier(timeModifier);
Expand All @@ -990,8 +998,6 @@ public CohortDefinition getLostToFollowUp() {
return convert(cd, ObjectUtil.toMap("startDate=startDate,endDate=endDate"));

}


public CohortDefinition getEverLost() {
LostPatientsCohortDefinition cd = new LostPatientsCohortDefinition();
cd.setMinimumDays(90);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package org.openmrs.module.ugandaemrreports.reports;

import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
import org.openmrs.module.reporting.data.patient.library.BuiltInPatientDataLibrary;
import org.openmrs.module.reporting.data.person.definition.BirthdateDataDefinition;
import org.openmrs.module.reporting.data.person.definition.GenderDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PreferredNameDataDefinition;
import org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition;
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.ugandaemrreports.library.*;
import org.openmrs.module.ugandaemrreports.metadata.HIVMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
* Daily Appointments List report
*/
@Component
public class SetUpLostReport extends UgandaEMRDataExportManager {

@Autowired
private DataFactory df;

@Autowired
ARTClinicCohortDefinitionLibrary hivCohorts;

@Autowired
private BuiltInPatientDataLibrary builtInPatientData;

@Autowired
private HIVPatientDataLibrary hivPatientData;

@Autowired
private BasePatientDataLibrary basePatientData;

@Autowired
private HIVMetadata hivMetadata;

@Autowired
private HIVCohortDefinitionLibrary hivCohortDefinitionLibrary;


/**
* @return the uuid for the report design for exporting to Excel
*/
@Override
public String getExcelDesignUuid() {
return "34213c70-36bd-4e7a-8e76-9ded9e8c8397";
}

@Override
public String getUuid() {
return "6325ccbd-2d98-4e8c-bc1c-befc2eb0dfa5";
}

@Override
public String getName() {
return "LOST CLIENTS";
}

@Override
public String getDescription() {
return "LOST CLIENTS";
}

@Override
public List<Parameter> getParameters() {
List<Parameter> l = new ArrayList<Parameter>();
l.add(df.getStartDateParameter());
l.add(df.getEndDateParameter());
return l;
}

@Override
public List<ReportDesign> constructReportDesigns(ReportDefinition reportDefinition) {
List<ReportDesign> l = new ArrayList<ReportDesign>();
l.add(buildReportDesign(reportDefinition));
return l;
}

/**
* Build the report design for the specified report, this allows a user to override the report design by adding
* properties and other metadata to the report design
*
* @param reportDefinition
* @return The report design
*/
@Override

public ReportDesign buildReportDesign(ReportDefinition reportDefinition) {
ReportDesign rd = createExcelTemplateDesign(getExcelDesignUuid(), reportDefinition, "Lost.xls");
Properties props = new Properties();
props.put("repeatingSections", "sheet:1,row:7,dataset:LOST_CLIENTS");
props.put("sortWeight", "5000");
rd.setProperties(props);
return rd;
}

@Override
public ReportDefinition constructReportDefinition() {

ReportDefinition rd = new ReportDefinition();

rd.setUuid(getUuid());
rd.setName(getName());
rd.setDescription(getDescription());
rd.setParameters(getParameters());


CohortDefinition deadPatients = df.getDeadPatientsDuringPeriod();
CohortDefinition transferedOut = hivCohortDefinitionLibrary.getPatientsTransferredOutDuringPeriod();
CohortDefinition patientsDeadAndtransferedOut =df.getPatientsInAny(deadPatients,transferedOut);
CohortDefinition allLostClients = df.getLostClients();

PatientDataSetDefinition dsd = new PatientDataSetDefinition();

CohortDefinition definition = df.getPatientsNotIn(allLostClients,patientsDeadAndtransferedOut);

dsd.setName(getName());
dsd.setParameters(getParameters());
dsd.addRowFilter(Mapped.mapStraightThrough(definition));
dsd.addColumn("Patient Name", new PreferredNameDataDefinition(), (String) null);
dsd.addColumn("Sex", new GenderDataDefinition(), (String) null);
dsd.addColumn("Birth Date", new BirthdateDataDefinition(), (String) null);
addColumn(dsd, "Age", builtInPatientData.getAgeAtStart());
addColumn(dsd, "Telephone", basePatientData.getTelephone());
addColumn(dsd, "HIV Enrolled Date", hivPatientData.getEnrollmentDate());
addColumn(dsd, "ART Start Date", hivPatientData.getArtStartDate());
addColumn(dsd, "Current Regimen",hivPatientData.getCurrentRegimen());
addColumn(dsd, "Last Visit Date",hivPatientData.getLastVisitDate());
addColumn(dsd, "Last Appointment",hivPatientData.getExpectedReturnDate());

rd.addDataSetDefinition("LOST_CLIENTS", Mapped.mapStraightThrough(dsd));
rd.setBaseCohortDefinition(Mapped.mapStraightThrough(definition));

return rd;
}

@Override
public String getVersion() {
return "0.4";
}
}
Binary file not shown.
9 changes: 9 additions & 0 deletions omod/src/main/resources/apps/ugandaemr_reports_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@
"url": "reportingui/runReport.page?reportDefinition=795050b6-3804-46d7-b49f-cb146a6cbf74",
"order": 65
},

{
"id": "Lost Clients",
"extensionPointId": "org.openmrs.module.ugandaemr.reports.overview",
"type": "link",
"label": "Lost Clients",
"url": "reportingui/runReport.page?reportDefinition=6325ccbd-2d98-4e8c-bc1c-befc2eb0dfa5",
"order": 100
},
{
"id": "Lost To Follow Up",
"extensionPointId": "org.openmrs.module.ugandaemr.reports.overview",
Expand Down

0 comments on commit 0ea218f

Please sign in to comment.