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