Search in sources :

Example 26 with CompleteDataSetRegistration

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

the class DataSetCompletenessServiceTest method testGetDataSetCompletenessByOrganisationUnitD.

@Test
public void testGetDataSetCompletenessByOrganisationUnitD() {
    dataSetA.getSources().add(unitE);
    dataSetA.getSources().add(unitF);
    dataSetA.getSources().add(unitG);
    dataSetA.getSources().add(unitH);
    dataSetIdA = dataSetService.addDataSet(dataSetA);
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitE, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitF, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitG, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitE, null, onTimeA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitF, null, onTimeA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitG, null, onTimeA, ""));
    groupIds.clear();
    groupIds.add(groupC.getId());
    Collection<DataSetCompletenessResult> results = registrationCompletenessService.getDataSetCompleteness(periodIdA, unitIdsA, dataSetIdA, groupIds);
    assertNotNull(results);
    assertEquals(2, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(unitB.getName(), 2, 2, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitA.getName(), 2, 2, 0)));
    results = registrationCompletenessService.getDataSetCompleteness(periodIdC, unitIdsA, dataSetIdA, groupIds);
    assertNotNull(results);
    assertEquals(2, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(unitB.getName(), 6, 4, 2)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitA.getName(), 6, 4, 2)));
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 27 with CompleteDataSetRegistration

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

the class DataSetCompletenessServiceTest method testGetDataSetCompletenessByOrganisationUnitB.

@Test
public void testGetDataSetCompletenessByOrganisationUnitB() {
    dataSetA.getSources().add(unitE);
    dataSetA.getSources().add(unitF);
    dataSetA.getSources().add(unitG);
    dataSetIdA = dataSetService.addDataSet(dataSetA);
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitE, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitG, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodA, unitH, null, tooLateA, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitE, null, onTimeB, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitG, null, onTimeB, ""));
    registrationService.saveCompleteDataSetRegistration(new CompleteDataSetRegistration(dataSetA, periodB, unitH, null, onTimeB, ""));
    Collection<DataSetCompletenessResult> results = registrationCompletenessService.getDataSetCompleteness(periodIdA, unitIdsA, dataSetIdA, null);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(unitB.getName(), 2, 1, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitC.getName(), 1, 1, 0)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitA.getName(), 3, 2, 0)));
    results = registrationCompletenessService.getDataSetCompleteness(periodIdC, unitIdsA, dataSetIdA, null);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains(new DataSetCompletenessResult(unitB.getName(), 6, 2, 1)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitC.getName(), 3, 2, 1)));
    assertTrue(results.contains(new DataSetCompletenessResult(unitA.getName(), 9, 4, 2)));
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 28 with CompleteDataSetRegistration

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

the class FacilityReportingServiceImpl method saveDataSetValues.

@Override
public void saveDataSetValues(OrganisationUnit unit, DataSetValue dataSetValue) throws NotAllowedException {
    org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet(dataSetValue.getId());
    if (!dataSetAssociatedWithOrgUnit(unit, dataSet)) {
        log.info("Failed to save data value set for: " + unit.getName() + ", " + dataSet.getName() + " - Org unit and data set not associated.");
        throw NotAllowedException.INVALID_DATASET_ASSOCIATION;
    }
    Period period = getPeriod(dataSetValue.getPeriodName(), dataSet.getPeriodType());
    if (period == null) {
        log.info("Failed to save data value set for: " + unit.getName() + ", " + dataSet.getName() + " - Period not found.");
        throw NotAllowedException.INVALID_PERIOD;
    }
    log.info("Recieved data value set for: " + unit.getName() + ", " + dataSet.getName() + ", " + period.getIsoDate());
    Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = getDataElementIdMapping(dataSet);
    for (DataValue dataValue : dataSetValue.getDataValues()) {
        org.hisp.dhis.dataelement.DataElement dataElement = dataElementMap.get(dataValue.getId());
        if (dataElement == null) {
            log.info("Data value submitted for data element " + dataValue.getId() + ", that is not in data set '" + dataSet.getName() + "'");
            continue;
        }
        if (StringUtils.isEmpty(dataValue.getValue())) {
            log.debug("Empty data value for data element " + dataValue.getId() + " not saved");
            continue;
        }
        saveValue(unit, period, dataElement, dataValue);
    }
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, unit, optionCombo);
    if (registration != null) {
        registrationService.deleteCompleteDataSetRegistration(registration);
    }
    registration = new CompleteDataSetRegistration();
    registration.setDataSet(dataSet);
    registration.setPeriod(period);
    registration.setSource(unit);
    registration.setDate(new Date());
    registration.setStoredBy(currentUserService.getCurrentUser().getUsername());
    registrationService.saveCompleteDataSetRegistration(registration);
    log.info("Saved and registered data value set as complete: " + unit.getName() + ", " + dataSet.getName() + ", " + period.getIsoDate());
}
Also used : DataValue(org.hisp.dhis.api.mobile.model.DataValue) Period(org.hisp.dhis.period.Period) Date(java.util.Date) DataElement(org.hisp.dhis.api.mobile.model.DataElement) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 29 with CompleteDataSetRegistration

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

the class DataValueSMSListener method deregisterCompleteDataSet.

private void deregisterCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit organisationUnit) {
    DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
    if (registration != null) {
        registrationService.deleteCompleteDataSetRegistration(registration);
    }
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 30 with CompleteDataSetRegistration

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

the class DataValueSMSListener method registerCompleteDataSet.

private void registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit organisationUnit, String storedBy) {
    CompleteDataSetRegistration registration = new CompleteDataSetRegistration();
    DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
    if (registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo) == null) {
        registration.setDataSet(dataSet);
        registration.setPeriod(period);
        registration.setSource(organisationUnit);
        registration.setDate(new Date());
        registration.setStoredBy(storedBy);
        registration.setPeriodName(registration.getPeriod().toString());
        registrationService.saveCompleteDataSetRegistration(registration, false);
    }
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

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