use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class TrackerTest method createProgramStage.
protected ProgramStage createProgramStage(Program program, boolean publicAccess) {
ProgramStage programStage = createProgramStage('1', program);
programStage.setUid(CodeGenerator.generateUid());
programStage.setRepeatable(true);
if (publicAccess) {
programStage.setPublicAccess(AccessStringHelper.FULL);
}
doInTransaction(() -> manager.save(programStage));
return programStage;
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class TrackerTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
// Tracker graph creation
trackedEntityTypeA = createTrackedEntityType('A');
trackedEntityTypeA.setUid(CodeGenerator.generateUid());
trackedEntityTypeA.setName("TrackedEntityTypeA" + trackedEntityTypeA.getUid());
organisationUnitA = createOrganisationUnit('A');
organisationUnitA.setUid(CodeGenerator.generateUid());
organisationUnitA.setCode(RandomStringUtils.randomAlphanumeric(10));
organisationUnitB = createOrganisationUnit('B');
organisationUnitB.setUid(CodeGenerator.generateUid());
organisationUnitB.setCode(RandomStringUtils.randomAlphanumeric(10));
categoryComboA = manager.getByName(CategoryCombo.class, "default");
categoryComboA.setUid(CodeGenerator.generateUid());
manager.update(categoryComboA);
ProgramStage programStageA2;
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programA.setCategoryCombo(categoryComboA);
programA.setUid(CodeGenerator.generateUid());
programA.setCode(RandomStringUtils.randomAlphanumeric(10));
CategoryOptionCombo defaultCategoryOptionCombo = createCategoryOptionCombo('A');
defaultCategoryOptionCombo.setCategoryCombo(categoryComboA);
defaultCategoryOptionCombo.setUid(DEF_COC_UID);
defaultCategoryOptionCombo.setName("default1");
relationshipType = new RelationshipType();
relationshipType.setFromToName(RandomStringUtils.randomAlphanumeric(5));
relationshipType.setToFromName(RandomStringUtils.randomAlphanumeric(5));
relationshipType.setName(RandomStringUtils.randomAlphanumeric(10));
// Tracker graph persistence
doInTransaction(() -> {
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeA);
manager.save(organisationUnitA);
manager.save(organisationUnitB);
manager.save(categoryComboA);
manager.save(programA);
manager.save(relationshipType);
});
programStageA1 = createProgramStage(programA, true);
programStageA2 = createProgramStage(programA, true);
programA.setProgramStages(Stream.of(programStageA1, programStageA2).collect(Collectors.toCollection(HashSet::new)));
manager.update(programA);
super.userService = this.userService;
mockCurrentUserService();
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class AnalyticsValidationServiceTest method setUpTest.
@Override
public void setUpTest() {
final String DATA_ELEMENT_A_UID = "DataElement";
final String TRACKED_ENTITY_ATTRIBUTE_UID = "TEAttribute";
final String PROGRAM_UID = "ProgramABCD";
final String PROGRAM_INDICATOR_UID = "ProgramIndA";
// A - ProgramTrackedEntityAttribute
final String EXPRESSION_A = "A{" + PROGRAM_UID + SEPARATOR + TRACKED_ENTITY_ATTRIBUTE_UID + "}";
// D - ProgramDataElement
final String EXPRESSION_D = "D{" + PROGRAM_UID + SEPARATOR + DATA_ELEMENT_A_UID + "}";
// I - ProgramIndicator
final String EXPRESSION_I = "I{" + PROGRAM_INDICATOR_UID + "}";
// Program Indicator expression
final String EX_INDICATOR = "#{" + PROGRAM_UID + SEPARATOR + DATA_ELEMENT_A_UID + "} + 4";
final String EXPRESSION_AI = EXPRESSION_A + " + " + EXPRESSION_I;
final String EXPRESSION_DI = EXPRESSION_D + " + " + EXPRESSION_I;
defaultCombo = categoryService.getDefaultCategoryOptionCombo();
orgUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(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));
periodService.addPeriod(periodMar);
periodService.addPeriod(periodApr);
dayInPeriod = 15;
Date dateMar20 = getDate(testYear, 3, 20);
Date dateApr10 = getDate(testYear, 4, 10);
DataElement dataElementA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
dataElementA.setUid(DATA_ELEMENT_A_UID);
dataElementService.addDataElement(dataElementA);
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), Sets.newHashSet(orgUnitA, orgUnitA), null);
program.setUid(PROGRAM_UID);
programService.addProgram(program);
ProgramStage stageA = createProgramStage('A', 0);
stageA.setProgram(program);
stageA.addDataElement(dataElementA, 1);
programStageService.saveProgramStage(stageA);
ProgramIndicator programIndicator = createProgramIndicator('A', program, EX_INDICATOR, null);
programIndicator.setAggregationType(AggregationType.SUM);
programIndicator.setUid(PROGRAM_INDICATOR_UID);
programIndicatorService.addProgramIndicator(programIndicator);
program.setProgramStages(Sets.newHashSet(stageA));
program.getProgramIndicators().add(programIndicator);
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, "ProgramIndicator");
Expression expressionAI = new Expression(EXPRESSION_AI, "ProgramTrackedEntityAttribute + ProgramIndicator");
Expression expressionASlide = new Expression(EXPRESSION_A, "ProgramTrackedEntityAttribute Slide");
Expression expressionDSlide = new Expression(EXPRESSION_D, "ProgramDataElement Slide");
Expression expressionISlide = new Expression(EXPRESSION_I, "ProgramIndicator Slide");
Expression expressionDISlide = new Expression(EXPRESSION_DI, "ProgramDataElement + ProgramIndicator Slide");
expressionASlide.setSlidingWindow(true);
expressionDSlide.setSlidingWindow(true);
expressionISlide.setSlidingWindow(true);
ruleA = createValidationRule("A", not_equal_to, expressionA, expressionA, periodTypeMonthly);
ruleD = createValidationRule("D", not_equal_to, expressionD, expressionD, periodTypeMonthly);
ruleI = createValidationRule("I", not_equal_to, expressionI, expressionI, periodTypeMonthly);
ruleASlide = createValidationRule("T", not_equal_to, expressionASlide, expressionASlide, periodTypeMonthly);
ruleDSlide = createValidationRule("U", not_equal_to, expressionDSlide, expressionDSlide, periodTypeMonthly);
ruleISlide = createValidationRule("V", not_equal_to, expressionISlide, expressionISlide, periodTypeMonthly);
ruleX = createValidationRule("X", equal_to, expressionAI, expressionDISlide, periodTypeMonthly);
validationRuleService.saveValidationRule(ruleA);
validationRuleService.saveValidationRule(ruleD);
validationRuleService.saveValidationRule(ruleI);
validationRuleService.saveValidationRule(ruleASlide);
validationRuleService.saveValidationRule(ruleDSlide);
validationRuleService.saveValidationRule(ruleISlide);
validationRuleService.saveValidationRule(ruleX);
Map<Date, Grid> dateGridMap = new HashMap<>();
dateGridMap.put(periodMar.getStartDate(), newGrid(4, 1, 8, 3));
dateGridMap.put(periodApr.getStartDate(), newGrid(5, 1, 9, 2));
MockAnalyticsService mockAnalyticsSerivce = new MockAnalyticsService();
mockAnalyticsSerivce.setDateGridMap(dateGridMap);
setDependency(AnalyticsServiceTarget.class, AnalyticsServiceTarget::setAnalyticsService, mockAnalyticsSerivce, validationService);
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testCascadeShareEventReport.
@Test
void testCascadeShareEventReport() {
DataElement deA = createDataElement('A');
deA.setSharing(defaultSharing());
objectManager.save(deA, false);
LegendSet lsA = createLegendSet('A');
lsA.setSharing(defaultSharing());
objectManager.save(lsA, false);
ProgramStage psA = createProgramStage('A', 1);
psA.setSharing(defaultSharing());
objectManager.save(psA, false);
TrackedEntityDataElementDimension teDeDim = new TrackedEntityDataElementDimension(deA, lsA, psA, "EQ:1");
EventReport eventReport = createEventReport("A", programA);
eventReport.addTrackedEntityDataElementDimension(teDeDim);
eventReport.setSharing(defaultSharing());
eventReport.setType(EventVisualizationType.LINE_LIST);
objectManager.save(eventReport, false);
// Add eventReport to dashboard
Dashboard dashboard = createDashboardWithItem("dashboardA", sharingReadForUserA);
dashboard.getItems().get(0).setEventReport(eventReport);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().build());
assertEquals(0, report.getErrorReports().size());
assertEquals(4, report.getUpdateObjects().size());
assertEquals(1, report.getUpdateObjects().get(DataElementSchemaDescriptor.PLURAL).size());
assertEquals(1, report.getUpdateObjects().get(LegendSetSchemaDescriptor.PLURAL).size());
assertEquals(1, report.getUpdateObjects().get(ProgramStageSchemaDescriptor.PLURAL).size());
assertEquals(1, report.getUpdateObjects().get(EventReportSchemaDescriptor.PLURAL).size());
assertTrue(aclService.canRead(userA, eventReport));
assertTrue(aclService.canRead(userA, deA));
assertTrue(aclService.canRead(userA, lsA));
assertTrue(aclService.canRead(userA, psA));
assertFalse(aclService.canRead(userB, eventReport));
assertFalse(aclService.canRead(userB, deA));
assertFalse(aclService.canRead(userB, lsA));
assertFalse(aclService.canRead(userB, psA));
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class RepeatedEventsValidationHookTest method repeatebleProgramStageWithoutRegistration.
private ProgramStage repeatebleProgramStageWithoutRegistration() {
ProgramStage programStage = createProgramStage('A', 1, true);
programStage.setUid(REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION);
programStage.setProgram(programWithoutRegistration());
return programStage;
}
Aggregations