Search in sources :

Example 41 with DataSet

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

the class DataDimensionExtractor method getReportingRate.

/**
 * Returns a {@link ReportingRate}.
 *
 * @param idScheme the identifier scheme.
 * @param dataSetId the data set identifier.
 * @param metric the reporting rate metric.
 */
ReportingRate getReportingRate(final IdScheme idScheme, final String dataSetId, final String metric) {
    final DataSet dataSet = idObjectManager.getObject(DataSet.class, idScheme, dataSetId);
    final boolean metricValid = isValidEnum(ReportingRateMetric.class, metric);
    if (dataSet == null || !metricValid) {
        return null;
    }
    return new ReportingRate(dataSet, ReportingRateMetric.valueOf(metric));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate)

Example 42 with DataSet

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

the class HibernateDataSetStore method getDataSetsByPeriodType.

@Override
public List<DataSet> getDataSetsByPeriodType(PeriodType periodType) {
    PeriodType refreshedPeriodType = periodService.reloadPeriodType(periodType);
    CriteriaBuilder builder = getCriteriaBuilder();
    JpaQueryParameters<DataSet> parameters = newJpaParameters().addPredicate(root -> builder.equal(root.get("periodType"), refreshedPeriodType));
    return getList(builder, parameters);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet)

Example 43 with DataSet

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

the class DefaultDataSetNotificationService method createBatchForSummaryNotifications.

private MessageBatch createBatchForSummaryNotifications(Set<DataSetNotificationTemplate> templates) {
    MessageBatch batch = new MessageBatch();
    String messageText = "";
    boolean summaryCreated = false;
    Long pendingOus;
    for (DataSetNotificationTemplate template : templates) {
        DhisMessage dhisMessage = new DhisMessage();
        for (DataSet dataSet : template.getDataSets()) {
            if (isValidForSending(getDataSetPeriod(dataSet), template)) {
                summaryCreated = true;
                pendingOus = dataSet.getSources().stream().filter(ou -> !isCompleted(createRespectiveRegistrationObject(dataSet, ou))).count();
                messageText += String.format(SUMMARY_TEXT, pendingOus, getPeriodString(dataSet.getPeriodType().createPeriod()), dataSet.getName()) + TEXT_SEPARATOR;
            }
        }
        if (summaryCreated) {
            dhisMessage.message = new NotificationMessage(createSubjectString(template), messageText);
            dhisMessage.recipients = resolveInternalRecipients(template);
            batch.dhisMessages.add(dhisMessage);
            messageText = "";
        }
    }
    log.info(String.format("%d summary dataset notifications created.", batch.dhisMessages.size()));
    return batch;
}
Also used : NotificationMessage(org.hisp.dhis.notification.NotificationMessage) DataSet(org.hisp.dhis.dataset.DataSet)

Example 44 with DataSet

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

the class HibernateCompleteDataSetRegistrationStore method getCompleteDataSetRegistration.

@Override
public CompleteDataSetRegistration getCompleteDataSetRegistration(DataSet dataSet, Period period, OrganisationUnit source, CategoryOptionCombo attributeOptionCombo) {
    Period storedPeriod = periodStore.reloadPeriod(period);
    if (storedPeriod == null) {
        return null;
    }
    CriteriaBuilder builder = getCriteriaBuilder();
    return getSingleResult(builder, newJpaParameters().addPredicate(root -> builder.equal(root, new CompleteDataSetRegistration(dataSet, storedPeriod, source, attributeOptionCombo))));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) Criteria(org.hibernate.Criteria) Restrictions(org.hibernate.criterion.Restrictions) Date(java.util.Date) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataSet(org.hisp.dhis.dataset.DataSet) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) Projections(org.hibernate.criterion.Projections) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CompleteDataSetRegistrationStore(org.hisp.dhis.dataset.CompleteDataSetRegistrationStore) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PeriodStore(org.hisp.dhis.period.PeriodStore) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Repository(org.springframework.stereotype.Repository) Period(org.hisp.dhis.period.Period) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration)

Example 45 with DataSet

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

the class ExpressionService2Test method setUp.

@BeforeEach
public void setUp() {
    target = new DefaultExpressionService(hibernateGenericStore, constantService, dimensionService, idObjectManager, statementBuilder, i18nManager, cacheProvider);
    categoryOptionA = new CategoryOption("Under 5");
    categoryOptionB = new CategoryOption("Over 5");
    categoryOptionC = new CategoryOption("Male");
    categoryOptionD = new CategoryOption("Female");
    categoryA = new Category("Age", DataDimensionType.DISAGGREGATION);
    categoryB = new Category("Gender", DataDimensionType.DISAGGREGATION);
    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);
    categoryCombo = new CategoryCombo("Age and gender", DataDimensionType.DISAGGREGATION);
    categoryCombo.getCategories().add(categoryA);
    categoryCombo.getCategories().add(categoryB);
    categoryCombo.generateOptionCombos();
    List<CategoryOptionCombo> optionCombos = Lists.newArrayList(categoryCombo.getOptionCombos());
    cocA = optionCombos.get(0);
    cocA.setUid(CodeGenerator.generateUid());
    cocB = optionCombos.get(1);
    cocB.setUid(CodeGenerator.generateUid());
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deD = createDataElement('D');
    deE = createDataElement('E', categoryCombo);
    coc = rnd.nextObject(CategoryOptionCombo.class);
    coc.setName(DEFAULT_CATEGORY_COMBO_NAME);
    optionCombos.add(coc);
    opA = new DataElementOperand(deA, coc);
    opB = new DataElementOperand(deB, coc);
    opC = new DataElementOperand(deC, coc);
    opD = new DataElementOperand(deD, coc);
    opE = new DataElementOperand(deB, cocA);
    opF = new DataElementOperand(deA, cocA, cocB);
    period = createPeriod(getDate(2000, 1, 1), getDate(2000, 1, 31));
    pteaA = rnd.nextObject(ProgramTrackedEntityAttributeDimensionItem.class);
    pdeA = rnd.nextObject(ProgramDataElementDimensionItem.class);
    piA = rnd.nextObject(ProgramIndicator.class);
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    unitC = createOrganisationUnit('C');
    constantA = rnd.nextObject(Constant.class);
    constantA.setName("ConstantA");
    constantA.setValue(2.0);
    constantB = rnd.nextObject(Constant.class);
    constantB.setName("ConstantB");
    constantB.setValue(5.0);
    groupA = createOrganisationUnitGroup('A');
    groupA.addOrganisationUnit(unitA);
    groupA.addOrganisationUnit(unitB);
    groupA.addOrganisationUnit(unitC);
    groupB = createOrganisationUnitGroup('B');
    groupB.addOrganisationUnit(unitB);
    DataSet dataSetA = createDataSet('A');
    dataSetA.setUid("a23dataSetA");
    dataSetA.addOrganisationUnit(unitA);
    reportingRate = new ReportingRate(dataSetA);
    expressionA = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
    expressionB = "#{" + deC.getUid() + SEPARATOR + coc.getUid() + "}-#{" + deD.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionC = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+#{" + deE.getUid() + "}-10";
    expressionD = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+" + SYMBOL_DAYS;
    expressionE = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*C{" + constantA.getUid() + "}";
    expressionF = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionG = expressionF + "+#{" + deB.getUid() + "}-#{" + deC.getUid() + "}";
    expressionH = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*OUG{" + groupA.getUid() + "}";
    expressionI = "#{" + opA.getDimensionItem() + "}*" + "#{" + deB.getDimensionItem() + "}+" + "C{" + constantA.getUid() + "}+5-" + "D{" + pdeA.getDimensionItem() + "}+" + "A{" + pteaA.getDimensionItem() + "}-10+" + "I{" + piA.getDimensionItem() + "}";
    expressionJ = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
    expressionK = "1.5*avg(" + expressionJ + ")";
    expressionL = expressionA + "+avg(" + expressionJ + ")+1.5*stddev(" + expressionJ + ")+" + expressionB;
    expressionM = "#{" + deA.getUid() + SEPARATOR + SYMBOL_WILDCARD + "}-#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionN = "#{" + deA.getUid() + SEPARATOR + cocA.getUid() + SEPARATOR + cocB.getUid() + "}-#{" + deB.getUid() + SEPARATOR + cocA.getUid() + "}";
    expressionO = "#{" + opA.getDimensionItem() + "}+sum(#{" + opB.getDimensionItem() + "})";
    expressionP = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
    expressionR = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}" + " + R{" + reportingRate.getUid() + ".REPORTING_RATE}";
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) Constant(org.hisp.dhis.constant.Constant) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)199 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)82 Test (org.junit.jupiter.api.Test)69 DataElement (org.hisp.dhis.dataelement.DataElement)58 Period (org.hisp.dhis.period.Period)56 ArrayList (java.util.ArrayList)41 List (java.util.List)40 User (org.hisp.dhis.user.User)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)32 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)28 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)22 HashSet (java.util.HashSet)20 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)20 CategoryCombo (org.hisp.dhis.category.CategoryCombo)19 HashMap (java.util.HashMap)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)17 ReportingRate (org.hisp.dhis.common.ReportingRate)16 Section (org.hisp.dhis.dataset.Section)16