Skip to content

Commit

Permalink
Creation of 407A and 407B nutrition report
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel090 committed Nov 18, 2024
1 parent 0e01dfb commit 3ebab9f
Show file tree
Hide file tree
Showing 68 changed files with 3,350 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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.
* <p>
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* NutritionRegister cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.NutritionRegisterCohortDefinition")
public class NutritionRegisterCohortDefinition extends BaseQuery<Encounter> implements EncounterQuery {
@Localized("reporting.MOH407ARegisterCohortDefinition")
public class MOH407ARegisterCohortDefinition extends BaseQuery<Encounter> implements EncounterQuery {
@ConfigurationProperty
private Date asOfDate;

public NutritionRegisterCohortDefinition() {
public MOH407ARegisterCohortDefinition() {
}

public Date getAsOfDate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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.cohort.definition;

import org.openmrs.Encounter;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;
import org.openmrs.module.reporting.query.BaseQuery;
import org.openmrs.module.reporting.query.encounter.definition.EncounterQuery;

import java.util.Date;

/**
* NutritionRegister cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.MOH407BRegisterCohortDefinition")
public class MOH407BRegisterCohortDefinition extends BaseQuery<Encounter> implements EncounterQuery {
@ConfigurationProperty
private Date asOfDate;

public MOH407BRegisterCohortDefinition() {
}

public Date getAsOfDate() {
return asOfDate;
}

public void setAsOfDate(Date asOfDate) {
this.asOfDate = asOfDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.NutritionRegisterCohortDefinition;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.MOH407ARegisterCohortDefinition;
import org.openmrs.module.reporting.common.ObjectUtil;
import org.openmrs.module.reporting.evaluation.EvaluationContext;
import org.openmrs.module.reporting.evaluation.EvaluationException;
Expand All @@ -30,8 +30,8 @@
* Evaluator for patients for Nutrition Register
*
*/
@Handler(supports = {NutritionRegisterCohortDefinition.class})
public class NutritionRegisterCohortDefinitionEvaluator implements EncounterQueryEvaluator {
@Handler(supports = {MOH407ARegisterCohortDefinition.class})
public class MOH407ACohortDefinitionEvaluator implements EncounterQueryEvaluator {

private final Log log = LogFactory.getLog(this.getClass());
@Autowired
Expand All @@ -41,18 +41,11 @@ public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContex
context = ObjectUtil.nvl(context, new EvaluationContext());
EncounterQueryResult queryResult = new EncounterQueryResult(definition, context);

String qry = "SELECT nt.encounter_id \n" +
"FROM kenyaemr_etl.etl_nutrition nt\n" +
"INNER JOIN kenyaemr_etl.etl_patient_demographics p \n" +
" ON p.patient_id = nt.patient_id \n" +
" AND p.voided = 0\n" +
"WHERE timestampdiff(YEAR, date(p.DOB), (\n" +
" SELECT MAX(nt2.visit_date) \n" +
" FROM kenyaemr_etl.etl_nutrition nt2 \n" +
" WHERE nt2.patient_id = nt.patient_id\n" +
")) <= 15 \n" +
"AND date(nt.visit_date) BETWEEN date(:startDate) AND date(:endDate) \n" +
"AND nt.voided = 0;";
String qry = "SELECT nt.encounter_id FROM kenyaemr_etl.etl_nutrition nt INNER JOIN kenyaemr_etl.etl_patient_demographics p \n" +
"ON p.patient_id = nt.patient_id AND p.voided = 0\n" +
"WHERE timestampdiff(YEAR, date(p.DOB), (SELECT MAX(nt2.visit_date) FROM kenyaemr_etl.etl_nutrition nt2 \n" +
"WHERE nt2.patient_id = nt.patient_id)) >= 15 \n" +
"AND date(nt.visit_date) BETWEEN date(:startDate) AND date(:endDate) AND nt.voided = 0;";

SqlQueryBuilder builder = new SqlQueryBuilder();
builder.append(qry);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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.cohort.definition.evaluator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.MOH407BRegisterCohortDefinition;
import org.openmrs.module.reporting.common.ObjectUtil;
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.openmrs.module.reporting.query.encounter.EncounterQueryResult;
import org.openmrs.module.reporting.query.encounter.definition.EncounterQuery;
import org.openmrs.module.reporting.query.encounter.evaluator.EncounterQueryEvaluator;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
* Evaluator for patients for Nutrition Register
*
*/
@Handler(supports = {MOH407BRegisterCohortDefinition.class})
public class MOH407BRegisterCohortDefinitionEvaluator implements EncounterQueryEvaluator {

private final Log log = LogFactory.getLog(this.getClass());
@Autowired
EvaluationService evaluationService;

public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContext context) throws EvaluationException {
context = ObjectUtil.nvl(context, new EvaluationContext());
EncounterQueryResult queryResult = new EncounterQueryResult(definition, context);

String qry = "SELECT nt.encounter_id FROM kenyaemr_etl.etl_nutrition nt INNER JOIN kenyaemr_etl.etl_patient_demographics p \n" +
"ON p.patient_id = nt.patient_id AND p.voided = 0\n" +
"WHERE timestampdiff(YEAR, date(p.DOB), (SELECT MAX(nt2.visit_date) FROM kenyaemr_etl.etl_nutrition nt2 \n" +
"WHERE nt2.patient_id = nt.patient_id)) <= 15 \n" +
"AND date(nt.visit_date) BETWEEN date(:startDate) AND date(:endDate) AND nt.voided = 0;";

SqlQueryBuilder builder = new SqlQueryBuilder();
builder.append(qry);
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
builder.addParameter("endDate", endDate);
builder.addParameter("startDate", startDate);

List<Integer> results = evaluationService.evaluateToList(builder, Integer.class, context);
queryResult.getMemberIds().addAll(results);
return queryResult;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.data.converter.definition.evaluator.nutrition;

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nutrition.NutritionAnaemiaLevelDataDefinition;
import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData;
import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition;
import org.openmrs.module.reporting.data.encounter.evaluator.EncounterDataEvaluator;
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;

/**
*
*/
@Handler(supports= NutritionAnaemiaLevelDataDefinition.class, order=50)
public class NutritionAnaemiaLevelDataEvaluator implements EncounterDataEvaluator {

@Autowired
private EvaluationService evaluationService;

public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context);

String qry = "SELECT encounter_id,\n" +
"(case anaemia_level when 1118 then 'Not Done' when 1115 then 'Normal' when 1498 then 'Mild' when 1499 then 'Moderate' when 1500 then 'Severe' else '' end) as anaemia_level\n" +
"FROM kenyaemr_etl.etl_nutrition\n" +
"WHERE DATE(visit_date) between date(:startDate) and date(:endDate)\n" +
"GROUP BY encounter_id;";
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
queryBuilder.addParameter("endDate", endDate);
queryBuilder.addParameter("startDate", startDate);
Map<Integer, Object> data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context);
c.setData(data);
return c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.data.converter.definition.evaluator.nutrition;

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nutrition.NutritionCadreDataDefinition;
import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData;
import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition;
import org.openmrs.module.reporting.data.encounter.evaluator.EncounterDataEvaluator;
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;

/**
*
*/
@Handler(supports= NutritionCadreDataDefinition.class, order=50)
public class NutritionCadreDataEvaluator implements EncounterDataEvaluator {

@Autowired
private EvaluationService evaluationService;

public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context);

String qry = "SELECT encounter_id,\n" +
"(case cadre when 900009 then 'Nutritionist' when 1577 then 'Nurse' when 162591 then 'Doctor' when 1574 then 'Clinical Officer' when 5622 then 'Others' else '' end) as cadre\n" +
"FROM kenyaemr_etl.etl_nutrition\n" +
"WHERE DATE(visit_date) between date(:startDate) and date(:endDate)\n" +
"GROUP BY encounter_id;";
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
queryBuilder.addParameter("endDate", endDate);
queryBuilder.addParameter("startDate", startDate);
Map<Integer, Object> data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context);
c.setData(data);
return c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.data.converter.definition.evaluator.nutrition;

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nutrition.NutritionCoexialMedicalConditionDataDefinition;
import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData;
import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition;
import org.openmrs.module.reporting.data.encounter.evaluator.EncounterDataEvaluator;
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;

/**
* Nutrition Coexial Medical Condition
*/
@Handler(supports= NutritionCoexialMedicalConditionDataDefinition.class, order=50)
public class NutritionCoexialMedicalConditionDataEvaluator implements EncounterDataEvaluator {

@Autowired
private EvaluationService evaluationService;

public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context);

String qry = "SELECT encounter_id,\n" +
"(case medication_condition when 112141 then 'TB' when 119481 then 'Diabetes' when 117399 then 'Hypertension' when 5622 then 'Other' else '' end) as medication_condition\n" +
"FROM kenyaemr_etl.etl_nutrition\n" +
"WHERE DATE(visit_date) between date(:startDate) and date(:endDate)\n" +
"GROUP BY encounter_id;";
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
queryBuilder.addParameter("endDate", endDate);
queryBuilder.addParameter("startDate", startDate);
Map<Integer, Object> data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context);
c.setData(data);
return c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.data.converter.definition.evaluator.nutrition;

import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.data.converter.definition.nutrition.NutritionCriteriaForAdmissionDataDefinition;
import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData;
import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition;
import org.openmrs.module.reporting.data.encounter.evaluator.EncounterDataEvaluator;
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;

/**
*
*/
@Handler(supports= NutritionCriteriaForAdmissionDataDefinition.class, order=50)
public class NutritionCriteriaForAdmissionDataEvaluator implements EncounterDataEvaluator {

@Autowired
private EvaluationService evaluationService;

public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException {
EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context);

String qry = "SELECT encounter_id,\n" +
"(case criteria_for_admission when 1362 then 'Edema +' when 1363 then 'Edema ++' when 1364 then 'Edema +++' when 1343 then 'MUAC' when 162584 then 'WHZ' when 1342 then 'BMI for Age' else '' end) as criteria_for_admission\n" +
"FROM kenyaemr_etl.etl_nutrition\n" +
"WHERE DATE(visit_date) between date(:startDate) and date(:endDate)\n" +
"GROUP BY encounter_id;";
SqlQueryBuilder queryBuilder = new SqlQueryBuilder();
queryBuilder.append(qry);
Date startDate = (Date)context.getParameterValue("startDate");
Date endDate = (Date)context.getParameterValue("endDate");
queryBuilder.addParameter("endDate", endDate);
queryBuilder.addParameter("startDate", startDate);
Map<Integer, Object> data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context);
c.setData(data);
return c;
}
}
Loading

0 comments on commit 3ebab9f

Please sign in to comment.