Skip to content

Commit

Permalink
Merge pull request #2019 from gabriel090/KHP3-6713
Browse files Browse the repository at this point in the history
Develop a case report for the flagged syndromes
  • Loading branch information
gabriel090 authored Oct 15, 2024
2 parents 287b42c + 668e6a0 commit b6749d2
Show file tree
Hide file tree
Showing 24 changed files with 2,169 additions and 1,001 deletions.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Febrile illness cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.FebrileIllnessCohortDefinition")
public class FebrileIllnessCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Febrile Rash cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.FebrileRashCohortDefinition")
public class FebrileRashCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Jaundice cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.JaundiceCohortDefinition")
public class JaundiceCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Meningitis cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.MeningitisCohortDefinition")
public class MeningitisCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* mpox cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.MpoxCohortDefinition")
public class MpoxCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Neurological Syndrome cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.NeurologicalSyndromeCohortDefinition")
public class NeurologicalSyndromeCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.dmi;

import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition;
import org.openmrs.module.reporting.common.Localized;
import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy;
import org.openmrs.module.reporting.evaluation.caching.Caching;

/**
* Watery Diarrhoea cohort definition
*/
@Caching(strategy = ConfigurationPropertyCachingStrategy.class)
@Localized("reporting.WateryDiarrhoeaCohortDefinition")
public class WateryDiarrhoeaCohortDefinition extends BaseCohortDefinition {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* 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.dmi;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Cohort;
import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.dmi.FebrileIllnessCohortDefinition;
import org.openmrs.module.reporting.cohort.EvaluatedCohort;
import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
import org.openmrs.module.reporting.cohort.definition.evaluator.CohortDefinitionEvaluator;
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.HashSet;
import java.util.List;

/**
* Evaluator for Febrile Illness Cohort
*/
@Handler(supports = { FebrileIllnessCohortDefinition.class })
public class FebrileIllnessCohortDefinitionEvaluator implements CohortDefinitionEvaluator {

private final Log log = LogFactory.getLog(this.getClass());

@Autowired
EvaluationService evaluationService;

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {

FebrileIllnessCohortDefinition definition = (FebrileIllnessCohortDefinition) cohortDefinition;

if (definition == null)
return null;
Cohort newCohort = new Cohort();
String sqlQuery = "select a.patient_id\n" +
" from (select patient_id, c.visit_date,group_concat(c.complaint) as complaint,\n" +
" CASE\n" +
" WHEN group_concat(concat_ws('|',c.complaint,c.complaint_duration)) LIKE '%140238%' THEN\n" +
" SUBSTRING_INDEX(SUBSTRING_INDEX(group_concat(concat_ws('|',c.complaint,c.complaint_duration)) , '|', -1), ',', 1)\n" +
" END AS fever_duration_from_days\n" +
" from kenyaemr_etl.etl_allergy_chronic_illness c\n" +
" where c.complaint = 140238\n" +
" AND c.complaint_duration < 14\n" +
" and date(c.visit_date) between date(:startDate) and date(:endDate)\n" +
" group by patient_id) a\n" +
" join kenyaemr_etl.etl_patient_demographics d on a.patient_id = d.patient_id\n" +
" join kenyaemr_etl.etl_patient_triage t\n" +
" on a.patient_id = t.patient_id and date(t.visit_date) between date(:startDate) and date(:endDate) and\n" +
" t.temperature > 38.5 and date(a.visit_date) between date(:startDate) and date(:endDate)\n" +
" where FIND_IN_SET(140238, a.complaint) > 0;";

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

List<Integer> ptIds = evaluationService.evaluateToList(builder, Integer.class, context);
newCohort.setMemberIds(new HashSet<Integer>(ptIds));
return new EvaluatedCohort(newCohort, definition, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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.dmi;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Cohort;
import org.openmrs.annotation.Handler;
import org.openmrs.module.kenyaemr.reporting.cohort.definition.dmi.FebrileRashCohortDefinition;
import org.openmrs.module.reporting.cohort.EvaluatedCohort;
import org.openmrs.module.reporting.cohort.definition.CohortDefinition;
import org.openmrs.module.reporting.cohort.definition.evaluator.CohortDefinitionEvaluator;
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.HashSet;
import java.util.List;

/**
* Evaluator for FebrileRash Cohort
*/
@Handler(supports = { FebrileRashCohortDefinition.class })
public class FebrileRashCohortDefinitionEvaluator implements CohortDefinitionEvaluator {

private final Log log = LogFactory.getLog(this.getClass());

@Autowired
EvaluationService evaluationService;

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {

FebrileRashCohortDefinition definition = (FebrileRashCohortDefinition) cohortDefinition;

if (definition == null)
return null;

Cohort newCohort = new Cohort();
String sqlQuery = "SELECT a.patient_id\n" +
"FROM (\n" +
" SELECT\n" +
" patient_id,\n" +
" c.visit_date,\n" +
" GROUP_CONCAT(c.complaint) AS complaint,\n" +
" DATE_SUB(c.visit_date, INTERVAL c.complaint_duration DAY) AS complaint_date,\n" +
" c.complaint_duration\n" +
" FROM\n" +
" kenyaemr_etl.etl_allergy_chronic_illness c\n" +
" WHERE\n" +
" c.complaint IN (140238, 512)\n" +
" AND c.complaint_duration < 14\n" +
" AND DATE(c.visit_date) BETWEEN DATE(:startDate) AND DATE(:endDate)\n" +
" GROUP BY patient_id) a\n" +
"WHERE\n" +
" FIND_IN_SET(140238, a.complaint) > 0\n" +
" AND FIND_IN_SET(512, a.complaint) > 0;";

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

List<Integer> ptIds = evaluationService.evaluateToList(builder, Integer.class, context);
newCohort.setMemberIds(new HashSet<Integer>(ptIds));
return new EvaluatedCohort(newCohort, definition, context);
}
}
Loading

0 comments on commit b6749d2

Please sign in to comment.