Search in sources :

Example 76 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrations.

private CompleteDataSetRegistrations getCompleteDataSetRegistrations(Set<String> dataSet, String period, Date startDate, Date endDate, Set<String> orgUnit, boolean children) {
    Set<Period> periods = new HashSet<>();
    Set<DataSet> dataSets = new HashSet<>();
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(period);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    if (periods.isEmpty()) {
        return new CompleteDataSetRegistrations();
    }
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(orgUnit));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(orgUnit));
    }
    dataSets.addAll(manager.getByUid(DataSet.class, dataSet));
    CompleteDataSetRegistrations completeDataSetRegistrations = new CompleteDataSetRegistrations();
    completeDataSetRegistrations.setCompleteDataSetRegistrations(new ArrayList<>(registrationService.getCompleteDataSetRegistrations(dataSets, organisationUnits, periods)));
    return completeDataSetRegistrations;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) HashSet(java.util.HashSet)

Example 77 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalAuditServiceTest method setUpTest.

@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
    periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    superUserService = getMockCurrentUserService("SuperUser", true, sourceA, UserAuthorityGroup.AUTHORITY_ALL);
    userAService = getMockCurrentUserService("UserA", false, sourceA);
    userBService = getMockCurrentUserService("UserB", false, sourceB);
    userCService = getMockCurrentUserService("UserC", false, sourceB);
    userDService = getMockCurrentUserService("UserD", false, sourceB);
    userZ = createUser('Z');
    userService.addUser(userZ);
    UserGroup userGroupC = getUserGroup("UserGroupA", Sets.newHashSet(userCService.getCurrentUser()));
    UserGroup userGroupD = getUserGroup("UserGroupB", Sets.newHashSet(userDService.getCurrentUser()));
    userCService.getCurrentUser().getGroups().add(userGroupC);
    userDService.getCurrentUser().getGroups().add(userGroupD);
    optionA = new CategoryOption("CategoryOptionA");
    optionB = new CategoryOption("CategoryOptionB");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    categoryA = createCategory('A', optionA, optionB);
    categoryService.addCategory(categoryA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addCategoryCombo(categoryComboA);
    optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
    optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
    optionComboC = createCategoryOptionCombo(categoryComboA, optionA, optionB);
    categoryService.addCategoryOptionCombo(optionComboA);
    categoryService.addCategoryOptionCombo(optionComboB);
    categoryService.addCategoryOptionCombo(optionComboC);
    optionGroupA = createCategoryOptionGroup('A', optionA);
    optionGroupB = createCategoryOptionGroup('B', optionB);
    categoryService.saveCategoryOptionGroup(optionGroupA);
    categoryService.saveCategoryOptionGroup(optionGroupB);
    optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
    categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
    optionGroupSetB.addCategoryOptionGroup(optionGroupA);
    optionGroupSetB.addCategoryOptionGroup(optionGroupB);
    optionGroupA.getGroupSets().add(optionGroupSetB);
    optionGroupB.getGroupSets().add(optionGroupSetB);
    setPrivateAccess(optionA, userGroupC);
    setPrivateAccess(optionB);
    setPrivateAccess(optionGroupA);
    setPrivateAccess(optionGroupB, userGroupD);
    categoryService.updateCategoryOptionGroupSet(optionGroupSetB);
    categoryService.updateCategoryOptionGroup(optionGroupA);
    categoryService.updateCategoryOptionGroup(optionGroupB);
    userCService.getCurrentUser().getCatDimensionConstraints().add(categoryA);
    userDService.getCurrentUser().getCogsDimensionConstraints().add(optionGroupSetB);
    dateA = getDate(2017, 1, 1);
    dateB = getDate(2018, 1, 1);
    level1 = new DataApprovalLevel("01", 1, null);
    level2 = new DataApprovalLevel("02", 2, null);
    level3 = new DataApprovalLevel("03", 2, optionGroupSetB);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
    workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2, level3));
    dataApprovalService.addWorkflow(workflowA);
    dataApprovalService.addWorkflow(workflowB);
    DataApproval approvalAA1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userZ);
    DataApproval approvalAB1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboB, false, dateA, userZ);
    DataApproval approvalAC1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboC, false, dateA, userZ);
    DataApproval approvalBA2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
    DataApproval approvalBB2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
    DataApproval approvalBC2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
    DataApproval approvalBA3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
    DataApproval approvalBB3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
    DataApproval approvalBC3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
    auditAA1 = new DataApprovalAudit(approvalAA1, APPROVE);
    auditAB1 = new DataApprovalAudit(approvalAB1, UNAPPROVE);
    auditAC1 = new DataApprovalAudit(approvalAC1, ACCEPT);
    auditBA2 = new DataApprovalAudit(approvalBA2, UNACCEPT);
    auditBB2 = new DataApprovalAudit(approvalBB2, APPROVE);
    auditBC2 = new DataApprovalAudit(approvalBC2, UNAPPROVE);
    auditBA3 = new DataApprovalAudit(approvalBA3, ACCEPT);
    auditBB3 = new DataApprovalAudit(approvalBB3, UNACCEPT);
    auditBC3 = new DataApprovalAudit(approvalBC3, APPROVE);
    dataApprovalAuditStore.save(auditAA1);
    dataApprovalAuditStore.save(auditAB1);
    dataApprovalAuditStore.save(auditAC1);
    dataApprovalAuditStore.save(auditBA2);
    dataApprovalAuditStore.save(auditBB2);
    dataApprovalAuditStore.save(auditBC2);
    dataApprovalAuditStore.save(auditBA3);
    dataApprovalAuditStore.save(auditBB3);
    dataApprovalAuditStore.save(auditBC3);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) UserGroup(org.hisp.dhis.user.UserGroup)

Example 78 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataSetStoreTest method testGetDataSetByPeriodType.

@Test
void testGetDataSetByPeriodType() {
    List<PeriodType> types = PeriodType.getAvailablePeriodTypes();
    PeriodType periodType1 = types.get(0);
    PeriodType periodType2 = types.get(1);
    DataSet dataSetA = addDataSet('A', periodType1);
    DataSet dataSetB = addDataSet('B', periodType2);
    assertContainsOnly(dataSetStore.getDataSetsByPeriodType(periodType1), dataSetA);
    assertContainsOnly(dataSetStore.getDataSetsByPeriodType(periodType2), dataSetB);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 79 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    level1 = new DataApprovalLevel("01", 1, null);
    level2 = new DataApprovalLevel("02", 2, null);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    workflowA1 = new DataApprovalWorkflow("workflowA1", periodType, newHashSet(level1));
    workflowA12 = new DataApprovalWorkflow("workflowA12", periodType, newHashSet(level1, level2));
    workflowB12 = new DataApprovalWorkflow("workflowB12", periodType, newHashSet(level1, level2));
    dataApprovalService.addWorkflow(workflowA1);
    dataApprovalService.addWorkflow(workflowA12);
    dataApprovalService.addWorkflow(workflowB12);
    periodA = createPeriod(getDay(5), getDay(6));
    periodB = createPeriod(getDay(6), getDay(7));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    sourceC = createOrganisationUnit('C', sourceB);
    sourceD = createOrganisationUnit('D', sourceC);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    userA = createUser('A');
    userB = createUser('B');
    userService.addUser(userA);
    userService.addUser(userB);
    categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType)

Example 80 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class BulkPatchManagerTest method setUpTest.

@Override
public void setUpTest() {
    userService = _userService;
    userA = createUserWithId("A", "NOOF56dveaZ");
    userB = createUserWithId("B", "Kh68cDMwZsg");
    userC = createUser("C");
    userD = createUser("D");
    dataElementA = createDataElement('A');
    dataElementA.setSharing(Sharing.builder().owner(userD.getUid()).publicAccess(AccessStringHelper.DEFAULT).build());
    dataElementA.setUid("fbfJHSPpUQD");
    manager.save(dataElementA, false);
    dataElementB = createDataElement('B');
    dataElementB.setUid("cYeuwXTCPkU");
    dataElementB.setSharing(Sharing.builder().owner(userD.getUid()).publicAccess(AccessStringHelper.DEFAULT).build());
    manager.save(dataElementB, false);
    PeriodType periodType = periodService.getPeriodTypeByClass(MonthlyPeriodType.class);
    dataSetA = createDataSet('A', periodType);
    dataSetA.setUid("em8Bg4LCr5k");
    dataSetA.setSharing(Sharing.builder().owner(userD.getUid()).publicAccess(AccessStringHelper.DEFAULT).build());
    manager.save(dataSetA, false);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)104 Period (org.hisp.dhis.period.Period)27 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)24 DataElement (org.hisp.dhis.dataelement.DataElement)17 DataSet (org.hisp.dhis.dataset.DataSet)17 ArrayList (java.util.ArrayList)15 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)13 Test (org.junit.jupiter.api.Test)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 Date (java.util.Date)10 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)8 ProgramStage (org.hisp.dhis.program.ProgramStage)8 HashMap (java.util.HashMap)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)7 Expression (org.hisp.dhis.expression.Expression)7 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)7 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Program (org.hisp.dhis.program.Program)6 Property (org.hisp.dhis.schema.Property)6 Schema (org.hisp.dhis.schema.Schema)6