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)));
}
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)));
}
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());
}
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);
}
}
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);
}
}
Aggregations