Search in sources :

Example 1 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class ActiveVisitsListPageController method get.

public void get(PageModel model, @SpringBean CoreAppsProperties coreAppsProperties, @RequestParam(value = "location", required = false) Integer location, @RequestParam(value = "timeQualifier", required = false) String timeQualifier, UiSessionContext uiSessionContext) throws EvaluationException {
    EvaluationContext context = new EvaluationContext();
    SqlQueryBuilder q = new SqlQueryBuilder();
    q.append("(select e.patient_id, e.encounter_datetime as lastSeen");
    q.append(" from encounter e");
    q.append(" inner join (");
    q.append(" select patient_id, max(encounter_datetime) lastSeen ");
    q.append(" from encounter");
    q.append(" where voided = 0 and visit_id in ( select visit_id from visit where date_stopped is null and voided = 0)");
    q.append(" group by patient_id");
    q.append(" ) b on e.patient_id = b.patient_id and  e.encounter_datetime = b.lastSeen");
    q.append(" where e.voided = 0 and e.visit_id in");
    q.append(" ( select visit_id from visit where date_stopped is null and voided = 0)");
    if (location != null) {
        q.append(" and e.location_id = :location").addParameter("location", location);
    }
    q.append(" )");
    q.append(" union");
    q.append(" (select v.patient_id, v.date_started as lastSeen");
    q.append(" from visit v");
    q.append(" where v.date_stopped is null and v.voided = 0 ");
    q.append(" and v.visit_id not in");
    q.append(" (select e.visit_id from encounter e where e.patient_id = v.patient_id and e.visit_id is not null and e.voided = 0))");
    q.append(" order by lastSeen desc");
    DbSessionFactory dbSessionFactory = Context.getRegisteredComponents(DbSessionFactory.class).get(0);
    List<Object[]> resultSet = q.evaluateToList(dbSessionFactory, context);
    List<Integer> activeVisitsCohort = new ArrayList<Integer>();
    if (resultSet != null && resultSet.size() > 0) {
        for (Object[] activeVisit : resultSet) {
            activeVisitsCohort.add((Integer) activeVisit[0]);
        }
    }
    model.addAttribute("locale", uiSessionContext.getLocale());
    model.addAttribute("lastLocation", location);
    model.addAttribute("activeVisitsCohort", activeVisitsCohort);
    model.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
    // used to determine if we display links to patient dashboard)
    model.put("privilegePatientDashboard", CoreAppsConstants.PRIVILEGE_PATIENT_DASHBOARD);
}
Also used : DbSessionFactory(org.openmrs.api.db.hibernate.DbSessionFactory) SqlQueryBuilder(org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder) ArrayList(java.util.ArrayList) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext)

Example 2 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class AdmissionSoonAfterExitCohortDefinitionEvaluatorTest method testEvaluate.

@Test
public void testEvaluate() throws Exception {
    Date startDate = DateUtil.parseDate("2013-10-03 00:00:00", "yyyy-MM-dd HH:mm:ss");
    Date endDate = DateUtil.parseDate("2013-10-03 23:59:59", "yyyy-MM-dd HH:mm:ss");
    AdmissionSoonAfterExitCohortDefinition definition = new AdmissionSoonAfterExitCohortDefinition();
    definition.setOnOrAfter(startDate);
    definition.setOnOrBefore(endDate);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient3.getId()));
}
Also used : AdmissionSoonAfterExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.AdmissionSoonAfterExitCohortDefinition) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 3 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByAnyCoded.

@Test
public void testEvaluateByAnyCoded() throws Exception {
    createDiagnosisObs();
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    cd.setIncludeAllCodedDiagnoses(true);
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(2, 6));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateSimple.

@Test
public void testEvaluateSimple() throws Exception {
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort.size(), is(0));
    assertThat((DiagnosisCohortDefinition) cohort.getDefinition(), is(cd));
    createDiagnosisObs();
    cd = new DiagnosisCohortDefinition();
    cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(2, 6, 7));
    cd.setOnOrAfter(DateUtil.parseDate("2013-01-02", "yyyy-MM-dd"));
    cd.setOnOrBefore(DateUtil.parseDate("2013-01-02", "yyyy-MM-dd"));
    cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(2));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 5 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByCertainty.

@Test
public void testEvaluateByCertainty() throws Exception {
    createDiagnosisObs();
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    cd.setCertainty(Diagnosis.Certainty.CONFIRMED);
    cd.setCodedDiagnoses(Arrays.asList(conceptService.getConcept(9)));
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(6));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)25 Test (org.junit.Test)22 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)18 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Date (java.util.Date)7 DiagnosisCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition)7 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)6 Location (org.openmrs.Location)5 PersonAuditInfoCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition)5 SimpleDataSet (org.openmrs.module.reporting.dataset.SimpleDataSet)4 DataSetDefinition (org.openmrs.module.reporting.dataset.definition.DataSetDefinition)4 DataSetRow (org.openmrs.module.reporting.dataset.DataSetRow)3 InpatientLocationCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientLocationCohortDefinition)2 InpatientTransferCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition)2 PatientDataDefinition (org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition)2 DataSet (org.openmrs.module.reporting.dataset.DataSet)2 Parameter (org.openmrs.module.reporting.evaluation.parameter.Parameter)2 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1