Skip to content

Commit

Permalink
Merge pull request #213 from njorocs/dqa-2023
Browse files Browse the repository at this point in the history
Removed ccc 10 digit and format validation.Revised Current on ART reg…
  • Loading branch information
patryllus authored Jan 11, 2024
2 parents b02d222 + 7ede41b commit 176275f
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ protected PatientDataSetDefinition dqaActiveDataSetVariablesDefinition(String da
dsd.addColumn("id", new PersonIdDataDefinition(), "");
dsd.addColumn("Name", nameDef, "");
dsd.addColumn("CCC No", cccIdentifierDef, "");
dsd.addColumn("CCC No 10 Digits", identifierDef, "");
dsd.addColumn("CCC No Format", identifierDef, "");
//dsd.addColumn("CCC No 10 Digits", identifierDef, "");
//dsd.addColumn("CCC No Format", identifierDef, "");
dsd.addColumn("Sex", new GenderDataDefinition(), "", new DQADefaultYesDataConverter());
dsd.addColumn("Date of Birth", new BirthdateDataDefinition(), "", new DQADefaultYesDataConverter());
dsd.addSortCriteria("Category", SortCriteria.SortDirection.ASC);
Expand Down Expand Up @@ -308,8 +308,7 @@ protected PatientDataSetDefinition dqaActiveDataSetVariablesDefinition(String da
currentRegimenDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
currentRegimenDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("Current ART Regimen", currentRegimenDataDefinition, indParams,
new DQADefaultDataCompletenessDataConverter());
dsd.addColumn("Current ART Regimen", currentRegimenDataDefinition, indParams, null);

LastAppointmentPeriodDataDefinition lastAppointmentPeriodDataDefinition = new LastAppointmentPeriodDataDefinition();
lastAppointmentPeriodDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
Expand All @@ -322,19 +321,37 @@ protected PatientDataSetDefinition dqaActiveDataSetVariablesDefinition(String da
muacDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
muacDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("MUAC", muacDataDefinition, indParams, null);
dsd.addColumn("MUAC_BMI", muacDataDefinition, indParams, null);

DQATBScreeningLastVisitDataDefinition tbScreeningDataDefinition = new DQATBScreeningLastVisitDataDefinition();
tbScreeningDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
tbScreeningDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("TB Screening", tbScreeningDataDefinition, indParams, null);

EverOnIPTDataDefinition everOnIPTDataDefinition = new EverOnIPTDataDefinition();
everOnIPTDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
everOnIPTDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));
DQATBScreeningLastVisitOutcomeDataDefinition tbScreeningOutcomeDataDefinition = new DQATBScreeningLastVisitOutcomeDataDefinition();
tbScreeningOutcomeDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
tbScreeningOutcomeDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("TB Screening Outcome", tbScreeningOutcomeDataDefinition, indParams, null);

DQATPTStartDateDataDefinition dqatptStartDateDataDefinition = new DQATPTStartDateDataDefinition();
dqatptStartDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
dqatptStartDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("TPT Start date", dqatptStartDateDataDefinition, indParams, null);

DQATPTStatusDataDefinition tptStatusDataDefinition = new DQATPTStatusDataDefinition();
tptStatusDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
tptStatusDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("TPT Status", tptStatusDataDefinition, indParams, null);

DQATPTOutcomeDateDataDefinition dqatptOutcomeDateDataDefinition = new DQATPTOutcomeDateDataDefinition();
dqatptOutcomeDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
dqatptOutcomeDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));

dsd.addColumn("TPT Status", everOnIPTDataDefinition, indParams, new DQADefaultDataCompletenessDataConverter());
dsd.addColumn("TPT Outcome date", dqatptOutcomeDateDataDefinition, indParams, null);

LastNutritionAssessmentDataDefinition lastNutritionAssessmentDataDefinition = new LastNutritionAssessmentDataDefinition();
lastNutritionAssessmentDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationCon
+ " max(d.visit_date) as date_discontinued,\n"
+ " d.effective_disc_date as effective_disc_date,\n"
+ " de.patient_id as started_on_drugs,\n"
+ " e.patient_type as patient_type,\n"
+ " e.patient_type as patient_type,\n"
+ " mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " left join (select c.id, c.patient_related_to\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.kenyaemrextras.reporting.data.definition;

import org.openmrs.module.reporting.data.BaseDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* DQA TB screening Outcome Data Definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
public class DQATBScreeningLastVisitOutcomeDataDefinition extends BaseDataDefinition implements PersonDataDefinition {

public static final long serialVersionUID = 1L;

/**
* Default Constructor
*/
public DQATBScreeningLastVisitOutcomeDataDefinition() {
super();
}

/**
* Constructor to populate name only
*/
public DQATBScreeningLastVisitOutcomeDataDefinition(String name) {
super(name);
}

//***** INSTANCE METHODS *****

/**
* @see org.openmrs.module.reporting.data.DataDefinition#getDataType()
*/
public Class<?> getDataType() {
return Integer.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.kenyaemrextras.reporting.data.definition;

import org.openmrs.module.reporting.data.BaseDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

import java.util.Date;

/**
* DQA TPT outcome Date Data Definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
public class DQATPTOutcomeDateDataDefinition extends BaseDataDefinition implements PersonDataDefinition {

public static final long serialVersionUID = 1L;

/**
* Default Constructor
*/
public DQATPTOutcomeDateDataDefinition() {
super();
}

/**
* Constructor to populate name only
*/
public DQATPTOutcomeDateDataDefinition(String name) {
super(name);
}

//***** INSTANCE METHODS *****

/**
* @see org.openmrs.module.reporting.data.DataDefinition#getDataType()
*/
public Class<?> getDataType() {
return Date.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.kenyaemrextras.reporting.data.definition;

import org.openmrs.module.reporting.data.BaseDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

import java.util.Date;

/**
* DQA TPT start Date Data Definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
public class DQATPTStartDateDataDefinition extends BaseDataDefinition implements PersonDataDefinition {

public static final long serialVersionUID = 1L;

/**
* Default Constructor
*/
public DQATPTStartDateDataDefinition() {
super();
}

/**
* Constructor to populate name only
*/
public DQATPTStartDateDataDefinition(String name) {
super(name);
}

//***** INSTANCE METHODS *****

/**
* @see org.openmrs.module.reporting.data.DataDefinition#getDataType()
*/
public Class<?> getDataType() {
return Date.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.kenyaemrextras.reporting.data.definition;

import org.openmrs.module.reporting.data.BaseDataDefinition;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* DQA TPT status Data Definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
public class DQATPTStatusDataDefinition extends BaseDataDefinition implements PersonDataDefinition {

public static final long serialVersionUID = 1L;

/**
* Default Constructor
*/
public DQATPTStatusDataDefinition() {
super();
}

/**
* Constructor to populate name only
*/
public DQATPTStatusDataDefinition(String name) {
super(name);
}

//***** INSTANCE METHODS *****

/**
* @see org.openmrs.module.reporting.data.DataDefinition#getDataType()
*/
public Class<?> getDataType() {
return Integer.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC
throws EvaluationException {
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select d.patient_id, mid(max(concat(d.date_started, d.regimen)), 11) as regimenName\n"
String qry = "select d.patient_id, if (mid(max(concat(d.date_started, d.regimen)), 11) like '%DTG%','DTG-based regimen','Non-DTG-based regimen') as is_DTG_based\n"
+ "\t from kenyaemr_etl.etl_drug_event d\n"
+ "\t where d.program='HIV' and date(d.date_started) <= date(:endDate)\n" + "\t group by d.patient_id ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC
throws EvaluationException {
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select t.patient_id, mid(max(concat(date(t.visit_date), t.height)), 11) as height\n"
+ "from kenyaemr_etl.etl_patient_triage t\n" + "where date(t.visit_date) <= date(:endDate)\n"
+ "GROUP BY t.patient_id;";
String qry = " select t.patient_id, if (mid(max(concat(date (t.visit_date), t.height)), 11) is null,'Missing',mid(max(concat(date (t.visit_date), t.height)), 11)) as height\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup t where date (t.visit_date) <= date (:endDate)\n"
+ " GROUP BY t.patient_id;";

SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
Date startDate = (Date) context.getParameterValue("startDate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select a.patient_id,\n"
+ " if((a.pregnancy_status is null or a.pregnancy_status = 1066) and (age > 5), 'NA',\n"
+ " if((a.pregnancy_status = 1065 or age <= 5) and (muac is not null or muac <> '') , 'Yes', 'No')) as muac\n"
+ "from (select fup.patient_id,\n"
+ " mid(max(concat(date(fup.visit_date), fup.pregnancy_status)), 11) as pregnancy_status,\n"
+ " mid(max(concat(date(fup.visit_date), fup.muac)), 11) as muac,\n"
+ " timestampdiff(YEAR, d.DOB, date(:endDate)) as age\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " inner join kenyaemr_etl.etl_patient_demographics d on fup.patient_id = d.patient_id\n"
+ " where fup.visit_date <= date(:endDate)\n" + " group by fup.patient_id)a;";
+ " if ((muac is null or muac ='') and (weight is null or height is null),'Missing',if((a.pregnancy_status = 1065 or age <= 5) and (muac is not null or muac <> ''), muac, if((a.pregnancy_status is null or a.pregnancy_status = 1066) and (age > 5), ROUND(weight/(height * height),2),\n"
+ " 'Missing'))) as muac_bmi\n" + " from (select fup.patient_id,\n"
+ " mid(max(concat(date (fup.visit_date), fup.pregnancy_status)), 11) as pregnancy_status,\n"
+ " mid(max(concat(date (fup.visit_date), fup.muac)), 11) as muac,\n"
+ " mid(max(concat(date (fup.visit_date), fup.weight)), 11) as weight,\n"
+ " mid(max(concat(date (fup.visit_date), fup.height)), 11)/100 as height,\n"
+ " timestampdiff(YEAR, d.DOB, date (:endDate)) as age\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup fup\n"
+ " inner join kenyaemr_etl.etl_patient_demographics d on fup.patient_id = d.patient_id\n"
+ " where fup.visit_date <= date (:endDate) group by fup.patient_id) a;";

SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
Date startDate = (Date) context.getParameterValue("startDate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationC
throws EvaluationException {
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select a.patient_id,\n"
+ " if(a.person_present = 161642, 'NA',\n"
+ " if( a.tb_screened in (1660, 1662, 142177), 'Yes', 'No')) as tb_screened\n"
+ "from (select tb.patient_id,\n"
+ " mid(max(concat(date(tb.visit_date), ifnull(tb.resulting_tb_status, 0))), 11) as tb_screened,\n"
+ " mid(max(concat(date(tb.visit_date), ifnull(tb.person_present, 0))), 11) as person_present\n"
+ " from kenyaemr_etl.etl_tb_screening tb\n" + " where tb.visit_date <= date(:endDate)\n"
+ " group by tb.patient_id) a;";
String qry = " select tb.patient_id,\n"
+ " if (mid(max(concat(date (tb.visit_date),tb.person_present)),11) = 161642, 'NA',mid(max(concat(date (tb.visit_date), tb.screened_for_tb)), 11)) as screened_for_tb\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup tb where tb.visit_date <= date (:endDate) group by tb.patient_id;";

SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
Date startDate = (Date) context.getParameterValue("startDate");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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.kenyaemrextras.reporting.data.definition.evaluator;

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemrextras.reporting.data.definition.DQATBScreeningLastVisitDataDefinition;
import org.openmrs.module.kenyaemrextras.reporting.data.definition.DQATBScreeningLastVisitOutcomeDataDefinition;
import org.openmrs.module.reporting.data.person.EvaluatedPersonData;
import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition;
import org.openmrs.module.reporting.data.person.evaluator.PersonDataEvaluator;
import org.openmrs.module.reporting.evaluation.EvaluationContext;
import org.openmrs.module.reporting.evaluation.EvaluationException;
import org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder;
import org.openmrs.module.reporting.evaluation.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.Map;

/**
* Evaluates TB screening outcome on last visit Data Definition
*/
@Handler(supports = DQATBScreeningLastVisitOutcomeDataDefinition.class, order = 50)
public class DQATBScreeningLastVisitOutcomeDataEvaluator implements PersonDataEvaluator {

@Autowired
private EvaluationService evaluationService;

public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context)
throws EvaluationException {
EvaluatedPersonData c = new EvaluatedPersonData(definition, context);

String qry = "select a.patient_id,\n"
+ " if(person_present = 978 and screened_for_tb = 'Yes',case a.tb_status when 1660 then 'No TB' when 1662 then 'TB Confirmed' when 142177 then 'Pr TB' end,null) as tb_status\n"
+ " from (select tb.patient_id,\n"
+ " mid(max(concat(date (tb.visit_date), ifnull(tb.tb_status, 0))), 11) as tb_status,\n"
+ " mid(max(concat(date (tb.visit_date),tb.person_present)),11) as person_present,\n"
+ " mid(max(concat(date (tb.visit_date), tb.screened_for_tb)), 11) as screened_for_tb\n"
+ " from kenyaemr_etl.etl_patient_hiv_followup tb where tb.visit_date <= date (:endDate)\n"
+ " group by tb.patient_id) a;";

SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
Date startDate = (Date) context.getParameterValue("startDate");
Date endDate = (Date) context.getParameterValue("endDate");
queryBuilder.addParameter("endDate", endDate);
queryBuilder.addParameter("startDate", startDate);
queryBuilder.append(qry);
Map<Integer, Object> data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context);
c.setData(data);
return c;
}
}
Loading

0 comments on commit 176275f

Please sign in to comment.