Search in sources :

Example 36 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class EventPredictionServiceTest method setUpTest.

@Override
public void setUpTest() {
    final String DATA_ELEMENT_A_UID = "DataElemenA";
    final String DATA_ELEMENT_D_UID = "DataElemenD";
    final String DATA_ELEMENT_I_UID = "DataElemenI";
    final String DATA_ELEMENT_E_UID = "DataElemenE";
    final String DATA_ELEMENT_T_UID = "DataElemenT";
    final String DATA_ELEMENT_X_UID = "DataElemenX";
    final String TRACKED_ENTITY_ATTRIBUTE_UID = "TEAttribute";
    final String PROGRAM_UID = "ProgramUidA";
    final String PROGRAM_INDICATOR_A_UID = "ProgramIndA";
    final String PROGRAM_INDICATOR_B_UID = "ProgramIndB";
    final String PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM = PROGRAM_UID + SEPARATOR + TRACKED_ENTITY_ATTRIBUTE_UID;
    final String PROGRAM_DATA_ELEMENT_DIMENSION_ITEM = PROGRAM_UID + SEPARATOR + DATA_ELEMENT_X_UID;
    // A
    final String EXPRESSION_A = "sum( A{" + PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM + "} )";
    // -
    // ProgramTrackedEntityAttribute
    // D
    final String EXPRESSION_D = "sum( D{" + PROGRAM_DATA_ELEMENT_DIMENSION_ITEM + "} )";
    // -
    // ProgramDataElement
    // I
    final String EXPRESSION_I = "sum( I{" + PROGRAM_INDICATOR_A_UID + "} + I{" + PROGRAM_INDICATOR_B_UID + "} )";
    // -
    // ProgramIndicators
    // E
    final String EXPRESSION_E = "sum( #{" + DATA_ELEMENT_E_UID + "} )";
    // -
    // Data
    // element
    // T -
    final String EXPRESSION_T = EXPRESSION_A + " + " + EXPRESSION_E;
    // Two
    // things,
    // event
    // and
    // data
    // elemeent
    // Program
    final String EX_INDICATOR_A = "#{" + PROGRAM_DATA_ELEMENT_DIMENSION_ITEM + "} + 4";
    // Indicator
    // A
    // expression
    // Program
    final String EX_INDICATOR_B = "V{enrollment_count}";
    // Indicator B
    // expression
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
    orgUnitA = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(orgUnitA);
    Set<OrganisationUnit> orgUnitASet = Sets.newHashSet(orgUnitA);
    PeriodType periodTypeMonthly = new MonthlyPeriodType();
    testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    periodMar = createPeriod(periodTypeMonthly, getDate(testYear, 3, 1), getDate(testYear, 3, 31));
    periodApr = createPeriod(periodTypeMonthly, getDate(testYear, 4, 1), getDate(testYear, 4, 30));
    periodMay = createPeriod(periodTypeMonthly, getDate(testYear, 5, 1), getDate(testYear, 5, 31));
    periodService.addPeriod(periodMar);
    periodService.addPeriod(periodApr);
    periodService.addPeriod(periodMay);
    Date dateMar20 = getDate(testYear, 3, 20);
    Date dateApr10 = getDate(testYear, 4, 10);
    predictorOutputA = createDataElement('A');
    predictorOutputD = createDataElement('D');
    predictorOutputI = createDataElement('I');
    predictorOutputT = createDataElement('T');
    DataElement dataElementE = createDataElement('E');
    DataElement dataElementX = createDataElement('P', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
    predictorOutputA.setUid(DATA_ELEMENT_A_UID);
    predictorOutputD.setUid(DATA_ELEMENT_D_UID);
    predictorOutputI.setUid(DATA_ELEMENT_I_UID);
    predictorOutputT.setUid(DATA_ELEMENT_T_UID);
    dataElementE.setUid(DATA_ELEMENT_E_UID);
    dataElementX.setUid(DATA_ELEMENT_X_UID);
    dataElementService.addDataElement(predictorOutputA);
    dataElementService.addDataElement(predictorOutputD);
    dataElementService.addDataElement(predictorOutputI);
    dataElementService.addDataElement(predictorOutputT);
    dataElementService.addDataElement(dataElementE);
    dataElementService.addDataElement(dataElementX);
    TrackedEntityAttribute entityAttribute = createTrackedEntityAttribute('A');
    entityAttribute.setAggregationType(AggregationType.COUNT);
    entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID);
    entityAttributeService.addTrackedEntityAttribute(entityAttribute);
    TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', orgUnitA, entityAttribute);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    TrackedEntityAttributeValue trackedEntityAttributeValue = new TrackedEntityAttributeValue(entityAttribute, entityInstance);
    trackedEntityAttributeValue.setValue("123");
    entityAttributeValueService.addTrackedEntityAttributeValue(trackedEntityAttributeValue);
    entityInstance.setTrackedEntityAttributeValues(Sets.newHashSet(trackedEntityAttributeValue));
    entityInstanceService.updateTrackedEntityInstance(entityInstance);
    Program program = createProgram('A', null, Sets.newHashSet(entityAttribute), orgUnitASet, null);
    program.setUid(PROGRAM_UID);
    programService.addProgram(program);
    ProgramStage stageA = createProgramStage('A', 0);
    stageA.setProgram(program);
    stageA.addDataElement(dataElementX, 1);
    programStageService.saveProgramStage(stageA);
    ProgramIndicator programIndicatorA = createProgramIndicator('A', program, EX_INDICATOR_A, null);
    programIndicatorA.setAggregationType(AggregationType.SUM);
    programIndicatorA.setUid(PROGRAM_INDICATOR_A_UID);
    programIndicatorService.addProgramIndicator(programIndicatorA);
    ProgramIndicator programIndicatorB = createProgramIndicator('B', program, EX_INDICATOR_B, null);
    programIndicatorB.setAnalyticsType(AnalyticsType.ENROLLMENT);
    programIndicatorB.setAggregationType(AggregationType.COUNT);
    programIndicatorB.setUid(PROGRAM_INDICATOR_B_UID);
    programIndicatorService.addProgramIndicator(programIndicatorB);
    program.setProgramStages(Sets.newHashSet(stageA));
    program.getProgramIndicators().add(programIndicatorA);
    program.getProgramIndicators().add(programIndicatorB);
    programService.updateProgram(program);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, dateMar20, dateMar20, orgUnitA);
    programInstanceService.addProgramInstance(programInstance);
    ProgramStageInstance stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, stageA, dateMar20, dateMar20, orgUnitA);
    ProgramStageInstance stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, stageA, dateApr10, dateApr10, orgUnitA);
    stageInstanceA.setExecutionDate(dateMar20);
    stageInstanceB.setExecutionDate(dateApr10);
    stageInstanceA.setAttributeOptionCombo(defaultCombo);
    stageInstanceB.setAttributeOptionCombo(defaultCombo);
    programStageInstanceService.addProgramStageInstance(stageInstanceA);
    programStageInstanceService.addProgramStageInstance(stageInstanceB);
    categoryManager.addAndPruneAllOptionCombos();
    Expression expressionA = new Expression(EXPRESSION_A, "ProgramTrackedEntityAttribute");
    Expression expressionD = new Expression(EXPRESSION_D, "ProgramDataElement");
    Expression expressionI = new Expression(EXPRESSION_I, "ProgramIndicators");
    Expression expressionT = new Expression(EXPRESSION_T, "Two things");
    OrganisationUnitLevel orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
    predictorA = createPredictor(predictorOutputA, defaultCombo, "A", expressionA, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorD = createPredictor(predictorOutputD, defaultCombo, "D", expressionD, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorI = createPredictor(predictorOutputI, defaultCombo, "I", expressionI, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorT = createPredictor(predictorOutputT, defaultCombo, "T", expressionT, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorService.addPredictor(predictorA);
    predictorService.addPredictor(predictorD);
    predictorService.addPredictor(predictorI);
    Map<String, Grid> itemGridMap = new HashMap<>();
    itemGridMap.put(PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM, newGrid(PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM, 1.0, 1.0));
    itemGridMap.put(PROGRAM_DATA_ELEMENT_DIMENSION_ITEM, newGrid(PROGRAM_DATA_ELEMENT_DIMENSION_ITEM, 4.0, 5.0));
    itemGridMap.put(PROGRAM_INDICATOR_A_UID, newGrid(PROGRAM_INDICATOR_A_UID, 8.0, 9.0));
    itemGridMap.put(PROGRAM_INDICATOR_B_UID, newGrid(PROGRAM_INDICATOR_B_UID, 10.0, 11.0));
    MockAnalyticsService mockAnalyticsSerivce = new MockAnalyticsService();
    mockAnalyticsSerivce.setItemGridMap(itemGridMap);
    setDependency(AnalyticsServiceTarget.class, AnalyticsServiceTarget::setAnalyticsService, mockAnalyticsSerivce, predictionService);
    CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, orgUnitASet, orgUnitASet);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, predictionService);
    dataValueService.addDataValue(createDataValue(dataElementE, periodMar, orgUnitA, defaultCombo, defaultCombo, "100"));
    dataValueService.addDataValue(createDataValue(dataElementE, periodApr, orgUnitA, defaultCombo, defaultCombo, "200"));
    dataValueService.addDataValue(createDataValue(dataElementE, periodMay, orgUnitA, defaultCombo, defaultCombo, "300"));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) HashMap(java.util.HashMap) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) AnalyticsServiceTarget(org.hisp.dhis.analytics.AnalyticsServiceTarget) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) MockAnalyticsService(org.hisp.dhis.mock.MockAnalyticsService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 37 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class ConfigurationController method setOfflineOrganisationUnitLevel.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/offlineOrganisationUnitLevel")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setOfflineOrganisationUnitLevel(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    OrganisationUnitLevel organisationUnitLevel = identifiableObjectManager.get(OrganisationUnitLevel.class, uid);
    if (organisationUnitLevel == null) {
        throw new NotFoundException("Organisation unit level", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setOfflineOrganisationUnitLevel(organisationUnitLevel);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 38 with OrganisationUnitLevel

use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.

the class ConfigurationController method setFacilityOrgUnitLevel.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/facilityOrgUnitLevel")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setFacilityOrgUnitLevel(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    OrganisationUnitLevel level = identifiableObjectManager.get(OrganisationUnitLevel.class, uid);
    if (level == null) {
        throw new NotFoundException("Organisation unit level", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setFacilityOrgUnitLevel(level);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)38 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)11 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)11 DataElement (org.hisp.dhis.dataelement.DataElement)9 Expression (org.hisp.dhis.expression.Expression)9 PeriodType (org.hisp.dhis.period.PeriodType)9 ArrayList (java.util.ArrayList)8 Category (org.hisp.dhis.category.Category)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 Test (org.junit.jupiter.api.Test)6 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 DateUtils.getLongDateString (org.hisp.dhis.util.DateUtils.getLongDateString)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)3