Search in sources :

Example 16 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class DataSetCompletenessServiceTest method testGetDataSetCompletenessByDataSetD.

@Test
public void testGetDataSetCompletenessByDataSetD() {
    dataSetA.getSources().add(unitA);
    dataSetA.getSources().add(unitB);
    dataSetB.getSources().add(unitA);
    dataSetB.getSources().add(unitB);
    dataSetC.getSources().add(unitA);
    dataSetC.getSources().add(unitB);
    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);
    dataSetService.addDataSet(dataSetC);
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitA, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitB, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitA, null, tooLateB, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitD, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetB, periodA, unitA, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetB, periodA, unitC, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetB, periodB, unitB, null, onTimeB, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetC, periodA, unitC, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetC, periodB, unitA, null, tooLateB, ""));
    groupIds.clear();
    groupIds.add(groupA.getId());
    List<DataSetCompletenessResult> results = registrationCompletenessService.getDataSetCompleteness(periodIdC, unitIdA, groupIds);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetA.getName(), 3, 2, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetB.getName(), 3, 1, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetC.getName(), 3, 1, 0)));
    groupIds.clear();
    groupIds.add(groupA.getId());
    groupIds.add(groupB.getId());
    results = registrationCompletenessService.getDataSetCompleteness(periodIdC, unitIdA, groupIds);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetA.getName(), 3, 2, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetB.getName(), 3, 1, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(dataSetC.getName(), 3, 1, 0)));
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class HibernateCompleteDataSetRegistrationStore method getCompleteDataSetRegistration.

@Override
public CompleteDataSetRegistration getCompleteDataSetRegistration(DataSet dataSet, Period period, OrganisationUnit source, DataElementCategoryOptionCombo attributeOptionCombo) {
    Period storedPeriod = periodStore.reloadPeriod(period);
    if (storedPeriod == null) {
        return null;
    }
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(CompleteDataSetRegistration.class);
    criteria.add(Restrictions.eq("dataSet", dataSet));
    criteria.add(Restrictions.eq("period", storedPeriod));
    criteria.add(Restrictions.eq("source", source));
    criteria.add(Restrictions.eq("attributeOptionCombo", attributeOptionCombo));
    return (CompleteDataSetRegistration) criteria.uniqueResult();
}
Also used : Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) Criteria(org.hibernate.Criteria)

Example 18 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class GetDataValuesForDataSetAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Validation
    // ---------------------------------------------------------------------
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    Period period = PeriodType.getPeriodFromIsoString(periodId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    if (organisationUnit == null || period == null || dataSet == null) {
        log.warn("Illegal input, org unit: " + organisationUnit + ", period: " + period + ", data set: " + dataSet);
        return SUCCESS;
    }
    Set<OrganisationUnit> children = organisationUnit.getChildren();
    // ---------------------------------------------------------------------
    // Attributes
    // ---------------------------------------------------------------------
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    // ---------------------------------------------------------------------
    // Data values & Min-max data elements
    // ---------------------------------------------------------------------
    minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(organisationUnit, dataSet.getDataElements()));
    if (!multiOrganisationUnit) {
        dataValues.addAll(dataValueService.getDataValues(organisationUnit, period, dataSet.getDataElements(), attributeOptionCombo));
    } else {
        for (OrganisationUnit ou : children) {
            if (ou.getDataSets().contains(dataSet)) {
                dataValues.addAll(dataValueService.getDataValues(ou, period, dataSet.getDataElements(), attributeOptionCombo));
                minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(ou, dataSet.getDataElements()));
            }
        }
    }
    // ---------------------------------------------------------------------
    // File resource meta-data
    // ---------------------------------------------------------------------
    List<String> fileResourceUids = dataValues.stream().filter(dv -> dv.getDataElement().isFileType()).map(DataValue::getValue).collect(Collectors.toList());
    dataValueFileResourceMap.putAll(fileResourceService.getFileResources(fileResourceUids).stream().collect(Collectors.toMap(BaseIdentifiableObject::getUid, f -> f)));
    if (!multiOrganisationUnit) {
        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, attributeOptionCombo);
        if (registration != null) {
            complete = true;
            date = registration.getDate();
            storedBy = registration.getStoredBy();
        }
        locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
    } else {
        complete = true;
        for (OrganisationUnit ou : children) {
            if (ou.getDataSets().contains(dataSet)) {
                locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
                if (locked) {
                    break;
                }
                CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, ou, attributeOptionCombo);
                if (complete && registration == null) {
                    complete = false;
                }
            }
        }
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 19 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class MarkComplete method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Validate.notNull(organisationUnitId);
    Validate.notNull(isoPeriod);
    Validate.notNull(dataSetId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    Period period = periodService.getPeriod(isoPeriod);
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    //TODO
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
    if (registration == null) {
        registration = new CompleteDataSetRegistration();
        registration.setDataSet(dataSet);
        registration.setPeriod(period);
        registration.setSource(organisationUnit);
        registration.setDate(new Date());
        registration.setStoredBy(currentUserService.getCurrentUsername());
        registrationService.saveCompleteDataSetRegistration(registration);
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

Example 20 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class DefaultDataValueSetService method getCompleteDate.

private Date getCompleteDate(DataExportParams params) {
    if (params.isSingleDataValueSet()) {
        //TODO
        DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(params.getFirstDataSet(), params.getFirstPeriod(), params.getFirstOrganisationUnit(), optionCombo);
        return registration != null ? registration.getDate() : null;
    }
    return null;
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)31 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)12 Test (org.junit.Test)12 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 Period (org.hisp.dhis.period.Period)10 Date (java.util.Date)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 DataSet (org.hisp.dhis.dataset.DataSet)6 DataValue (org.hisp.dhis.datavalue.DataValue)4 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)3 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)2 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Criteria (org.hibernate.Criteria)1