Search in sources :

Example 1 with DataSetColumn

use of org.openmrs.module.reporting.dataset.DataSetColumn in project openmrs-module-pihcore by PIH.

the class InpatientStatsDailyDataSetManagerTest method testRunningReport.

@Test
public void testRunningReport() throws Exception {
    EvaluationContext context = new EvaluationContext();
    context.addParameterValue("day", DateUtil.parseDate("2013-10-03", "yyyy-MM-dd"));
    DataSetDescriptor descriptor = new DataSetDescriptor();
    DataSetDefinition dsd = manager.constructDataSetDefinition(descriptor, null);
    MapDataSet mds = (MapDataSet) dataSetDefinitionService.evaluate(dsd, context);
    Map<String, Integer> results = new HashMap<>();
    for (DataSetColumn column : mds.getMetaData().getColumns()) {
        CohortIndicatorAndDimensionResult val = (CohortIndicatorAndDimensionResult) mds.getData(column);
        results.put(column.getName(), val.getValue().intValue());
    }
    // Men's Internal Medicine
    assertAndRemove(results, "censusAtStart:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "admissions:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "discharged:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    assertAndRemove(results, "censusAtEnd:e5db0599-89e8-44fa-bfa2-07e47d63546f", 1);
    // Surgical Ward
    assertAndRemove(results, "transfersIn:7d6cc39d-a600-496f-a320-fd4985f07f0b", 1);
    assertAndRemove(results, "censusAtEnd:7d6cc39d-a600-496f-a320-fd4985f07f0b", 1);
    // Women's Internal Medicine
    assertAndRemove(results, "censusAtStart:2c93919d-7fc6-406d-a057-c0b640104790", 2);
    assertAndRemove(results, "transfersOut:2c93919d-7fc6-406d-a057-c0b640104790", 1);
    assertAndRemove(results, "censusAtEnd:2c93919d-7fc6-406d-a057-c0b640104790", 1);
    assertAndRemove(results, "edcheckin", 1);
    assertAndRemove(results, "orvolume", 1);
    assertAndRemove(results, "possiblereadmission", 1);
    // everything else should be 0
    for (Integer actual : results.values()) {
        assertThat(actual, is(0));
    }
}
Also used : DataSetColumn(org.openmrs.module.reporting.dataset.DataSetColumn) DataSetDescriptor(org.openmrs.module.reporting.config.DataSetDescriptor) HashMap(java.util.HashMap) MapDataSet(org.openmrs.module.reporting.dataset.MapDataSet) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DataSetDefinition(org.openmrs.module.reporting.dataset.definition.DataSetDefinition) CohortIndicatorAndDimensionResult(org.openmrs.module.reporting.indicator.dimension.CohortIndicatorAndDimensionResult) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 2 with DataSetColumn

use of org.openmrs.module.reporting.dataset.DataSetColumn in project openmrs-module-pihcore by PIH.

the class NonCodedDiagnosisDataSetEvaluator method evaluate.

@Override
public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context) throws EvaluationException {
    Long startTime = new Date().getTime();
    NonCodedDiagnosisDataSetDefinition dsd = (NonCodedDiagnosisDataSetDefinition) dataSetDefinition;
    Date fromDate = ObjectUtil.nvl(dsd.getFromDate(), DateUtils.addDays(new Date(), -7));
    Date toDate = ObjectUtil.nvl(dsd.getToDate(), new Date());
    fromDate = DateUtil.getStartOfDay(fromDate);
    toDate = DateUtil.getEndOfDay(toDate);
    String nonCoded = ObjectUtil.nvl(dsd.getNonCoded(), null);
    Provider provider = ObjectUtil.nvl(dsd.getProvider(), null);
    Integer userId = null;
    if (provider != null) {
        List<User> users = userService.getUsersByPerson(provider.getPerson(), true);
        if (users != null && users.size() > 0) {
            userId = users.get(0).getId();
        }
    }
    PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
    Concept nonCodedConcept = emrApiProperties.getDiagnosisMetadata().getNonCodedDiagnosisConcept();
    StringBuilder sqlQuery = new StringBuilder("select " + "    o.value_text as 'nonCodedDiagnosis', " + "    o.creator as 'creatorId', " + "    n.given_name as 'creatorFirstName', " + "    n.family_name as 'creatorLastName', " + "    o.date_created as 'dateCreated', " + "    o.person_id as 'patientId', " + "    id1.identifier as 'patientIdentifier', " + "    o.obs_id as 'obsId', " + "    e.visit_id as 'visitId', " + "    e.encounter_datetime as 'encounterDateTime', " + "    n1.given_name as 'patientFirstName', " + "    n1.family_name as 'patientLastName'");
    sqlQuery.append(" from obs o ");
    sqlQuery.append(" inner join patient_identifier as id1 on (o.person_id = id1.patient_id and id1.identifier_type = :primaryIdentifierType ) ");
    sqlQuery.append(" inner join encounter as e on (o.encounter_id = e.encounter_id) ");
    sqlQuery.append(" inner join users as u on (o.creator = u.user_id) ");
    sqlQuery.append(" inner join person_name as n on (u.person_id = n.person_id and n.voided=0) ");
    sqlQuery.append(" inner join person_name as n1 on (o.person_id = n1.person_id and n1.voided=0) ");
    sqlQuery.append(" ");
    sqlQuery.append(" where o.voided = 0  ");
    sqlQuery.append(" and o.concept_id = :nonCodedConcept ");
    if (fromDate != null) {
        sqlQuery.append(" and o.date_created > :startDate ");
    }
    if (toDate != null) {
        sqlQuery.append(" and o.date_created < :endDate ");
    }
    if (userId != null) {
        sqlQuery.append(" and o.creator = :userId ");
    }
    if (StringUtils.isNotBlank(nonCoded)) {
        sqlQuery.append(" and o.value_text like '%").append(nonCoded).append("%'");
    }
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery.toString());
    query.setInteger("primaryIdentifierType", primaryIdentifierType.getId());
    query.setInteger("nonCodedConcept", nonCodedConcept.getId());
    if (fromDate != null) {
        query.setTimestamp("startDate", fromDate);
    }
    if (toDate != null) {
        query.setTimestamp("endDate", toDate);
    }
    if (userId != null) {
        query.setInteger("userId", userId);
    }
    List<Object[]> list = query.list();
    SimpleDataSet dataSet = new SimpleDataSet(dataSetDefinition, context);
    for (Object[] o : list) {
        DataSetRow row = new DataSetRow();
        row.addColumnValue(new DataSetColumn("nonCodedDiagnosis", "nonCodedDiagnosis", String.class), o[0]);
        row.addColumnValue(new DataSetColumn("creatorId", "creatorId", String.class), o[1]);
        row.addColumnValue(new DataSetColumn("creatorFirstName", "creatorFirstName", String.class), o[2]);
        row.addColumnValue(new DataSetColumn("creatorLastName", "creatorLastName", String.class), o[3]);
        row.addColumnValue(new DataSetColumn("dateCreated", "dateCreated", String.class), o[4]);
        row.addColumnValue(new DataSetColumn("patientId", "patientId", String.class), o[5]);
        row.addColumnValue(new DataSetColumn("patientIdentifier", "patientIdentifier", String.class), o[6]);
        row.addColumnValue(new DataSetColumn("obsId", "obsId", String.class), o[7]);
        row.addColumnValue(new DataSetColumn("visitId", "visitId", String.class), o[8]);
        row.addColumnValue(new DataSetColumn("encounterDateTime", "encounterDateTime", String.class), o[9]);
        row.addColumnValue(new DataSetColumn("patientFirstName", "patientFirstName", String.class), o[10]);
        row.addColumnValue(new DataSetColumn("patientLastName", "patientLastName", String.class), o[11]);
        dataSet.addRow(row);
    }
    return dataSet;
}
Also used : Concept(org.openmrs.Concept) DataSetColumn(org.openmrs.module.reporting.dataset.DataSetColumn) User(org.openmrs.User) SimpleDataSet(org.openmrs.module.reporting.dataset.SimpleDataSet) SQLQuery(org.hibernate.SQLQuery) Date(java.util.Date) Provider(org.openmrs.Provider) NonCodedDiagnosisDataSetDefinition(org.openmrs.module.pihcore.reporting.dataset.definition.NonCodedDiagnosisDataSetDefinition) PatientIdentifierType(org.openmrs.PatientIdentifierType) DataSetRow(org.openmrs.module.reporting.dataset.DataSetRow)

Aggregations

DataSetColumn (org.openmrs.module.reporting.dataset.DataSetColumn)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SQLQuery (org.hibernate.SQLQuery)1 Test (org.junit.Test)1 Concept (org.openmrs.Concept)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Provider (org.openmrs.Provider)1 User (org.openmrs.User)1 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)1 NonCodedDiagnosisDataSetDefinition (org.openmrs.module.pihcore.reporting.dataset.definition.NonCodedDiagnosisDataSetDefinition)1 DataSetDescriptor (org.openmrs.module.reporting.config.DataSetDescriptor)1 DataSetRow (org.openmrs.module.reporting.dataset.DataSetRow)1 MapDataSet (org.openmrs.module.reporting.dataset.MapDataSet)1 SimpleDataSet (org.openmrs.module.reporting.dataset.SimpleDataSet)1 DataSetDefinition (org.openmrs.module.reporting.dataset.definition.DataSetDefinition)1 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)1 CohortIndicatorAndDimensionResult (org.openmrs.module.reporting.indicator.dimension.CohortIndicatorAndDimensionResult)1