Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clients transfers #1497

Open
wants to merge 3 commits into
base: multitenancy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@
@Builds({"kenyaemr.common.report.clients.transferred.in"})
public class ETLTransferInPatientsReportBuilder extends AbstractHybridReportBuilder {
public static final String DATE_FORMAT = "dd/MM/yyyy";
String paramMapping = "startDate=${startDate},endDate=${endDate}";
String paramMapping = "startDate=${startDate},endDate=${endDate},defaultLocation=${defaultLocation}";

@Override
protected List<Parameter> getParameters(ReportDescriptor reportDescriptor) {
return Arrays.asList(
new Parameter("startDate", "Start Date", Date.class),
new Parameter("endDate", "End Date", Date.class),
new Parameter("defaultLocation", "Selected Facility", String.class),
new Parameter("dateBasedReporting", "", String.class)
);
}
Expand All @@ -70,7 +71,6 @@ protected List<Parameter> getParameters(ReportDescriptor reportDescriptor) {
*/
@Override
protected void addColumns(HybridReportDescriptor report, PatientDataSetDefinition dsd) {

PatientIdentifierType upn = MetadataUtils.existing(PatientIdentifierType.class, HivMetadata._PatientIdentifierType.UNIQUE_PATIENT_NUMBER);
DataConverter identifierFormatter = new ObjectFormatter("{identifier}");
DataDefinition identifierDef = new ConvertedPatientDataDefinition("identifier", new PatientIdentifierDataDefinition(upn.getName(), upn), identifierFormatter);
Expand Down Expand Up @@ -106,6 +106,7 @@ protected Mapped<CohortDefinition> buildCohort(HybridReportDescriptor descriptor
cd.setName("Transfer in patients");
cd.addParameter(new Parameter("startDate", "Start Date", Date.class));
cd.addParameter(new Parameter("endDate", "End Date", Date.class));
cd.addParameter(new Parameter("defaultLocation", "Selected Facility", String.class));
return ReportUtils.map(cd, paramMapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@
@Builds({"kenyaemr.common.report.clients.transferred.out"})
public class ETLTransferOutPatientsReportBuilder extends AbstractHybridReportBuilder {
public static final String DATE_FORMAT = "dd/MM/yyyy";
String paramMapping = "startDate=${startDate},endDate=${endDate}";
String paramMapping = "startDate=${startDate},endDate=${endDate},defaultLocation=${defaultLocation}";

@Override
protected List<Parameter> getParameters(ReportDescriptor reportDescriptor) {
return Arrays.asList(
new Parameter("startDate", "Start Date", Date.class),
new Parameter("endDate", "End Date", Date.class),
new Parameter("defaultLocation", "Selected Facility", String.class),
new Parameter("dateBasedReporting", "", String.class)
);
}
Expand Down Expand Up @@ -112,6 +113,7 @@ protected Mapped<CohortDefinition> buildCohort(HybridReportDescriptor descriptor
cd.setName("Transfer out patients");
cd.addParameter(new Parameter("startDate", "Start Date", Date.class));
cd.addParameter(new Parameter("endDate", "End Date", Date.class));
cd.addParameter(new Parameter("defaultLocation", "Selected Facility", String.class));
return ReportUtils.map(cd, paramMapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.AllKenyaEmrPatientsCohortDefinition;
import org.openmrs.module.kenyaemr.reporting.library.shared.queries.SharedQueries;
import org.openmrs.module.reporting.cohort.EvaluatedCohort;
import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
import org.openmrs.module.reporting.cohort.definition.evaluator.CohortDefinitionEvaluator;
Expand Down Expand Up @@ -44,18 +45,11 @@ public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationCon
if (context.getBaseCohort() != null && context.getBaseCohort().isEmpty()) {
return cohort;
}
SqlQueryBuilder query = new SqlQueryBuilder(getQuery(def.getDefaultLocation()));
SqlQueryBuilder query = new SqlQueryBuilder(SharedQueries.getBaseCohortQuery(def.getDefaultLocation()));

List<Integer> ptIds = evaluationService.evaluateToList(query, Integer.class, context);
cohort.setMemberIds(new HashSet<Integer>(ptIds));

return cohort;
}


private String getQuery(Integer loc){
String query = "SELECT patient_id FROM kenyaemr_etl.etl_last_month_newly_enrolled_in_care where location_id ="+loc;

return query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationCon
return null;

Cohort newCohort = new Cohort();
String locationId = (String)context.getParameterValue("defaultLocation");
String qry=" select patient_id\n" +
"from kenyaemr_etl.etl_hiv_enrollment\n" +
"where patient_type=160563\n" +
" and (date(transfer_in_date) between date(:startDate) and date(:endDate) or date(visit_date) between date(:startDate) and date(:endDate));\n";
" and (date(transfer_in_date) between date(:startDate) and date(:endDate) or date(visit_date) between date(:startDate) and date(:endDate)) AND location_id="+locationId;

SqlQueryBuilder builder = new SqlQueryBuilder();
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
builder.addParameter("endDate", endDate);
builder.addParameter("startDate", startDate);
builder.addParameter("defaultLocation", locationId);
builder.append(qry);
List<Integer> ptIds = evaluationService.evaluateToList(builder, Integer.class, context);
newCohort.setMemberIds(new HashSet<Integer>(ptIds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationCon
return null;

Cohort newCohort = new Cohort();
String locationId = (String)context.getParameterValue("defaultLocation");
String qry=" select patient_id\n" +
"from kenyaemr_etl.etl_patient_program_discontinuation\n" +
"where program_name='HIV' and discontinuation_reason = 159492\n" +
"and (date(transfer_date) between date(:startDate) and date(:endDate) or date(visit_date) between date(:startDate) and date(:endDate));";
"and (date(transfer_date) between date(:startDate) and date(:endDate) or date(visit_date) between date(:startDate) and date(:endDate)) AND location_id="+locationId;

SqlQueryBuilder builder = new SqlQueryBuilder();
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
builder.addParameter("endDate", endDate);
builder.addParameter("startDate", startDate);
builder.addParameter("defaultLocation", locationId);
builder.append(qry);
List<Integer> ptIds = evaluationService.evaluateToList(builder, Integer.class, context);
newCohort.setMemberIds(new HashSet<Integer>(ptIds));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.kenyaemr.reporting.library.shared.queries;

public class SharedQueries {

public static String getBaseCohortQuery(int locationId) {
String query = "SELECT patient_id FROM patient p INNER JOIN encounter e ON p.patient_id=e.patient_id "
+" WHERE e.location_id ="+locationId
+" AND p.voided=0 AND e.voided=0";

return query;
}
}