Search in sources :

Example 91 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class RelationshipStoreTest method getByProgramStageInstance.

@Test
void getByProgramStageInstance() {
    Program programA = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setAutoFields();
    programInstance.setEnrollmentDate(new Date());
    programInstance.setIncidentDate(new Date());
    programInstance.setStatus(ProgramStatus.ACTIVE);
    programInstanceService.addProgramInstance(programInstance);
    ProgramStage programStageA = createProgramStage('S', programA);
    programStageA.setProgram(programA);
    programStageService.saveProgramStage(programStageA);
    programA.getProgramStages().add(programStageA);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setOrganisationUnit(organisationUnit);
    programStageInstance.setProgramStage(programStageA);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setAutoFields();
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    RelationshipItem relationshipItemFrom = new RelationshipItem();
    relationshipItemFrom.setTrackedEntityInstance(trackedEntityInstanceA);
    RelationshipItem relationshipItemTo = new RelationshipItem();
    relationshipItemTo.setProgramStageInstance(programStageInstance);
    Relationship relationshipA = new Relationship();
    relationshipA.setRelationshipType(relationshipType);
    relationshipA.setFrom(relationshipItemFrom);
    relationshipA.setTo(relationshipItemTo);
    relationshipA.setKey(RelationshipUtils.generateRelationshipKey(relationshipA));
    relationshipA.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(relationshipA));
    relationshipService.addRelationship(relationshipA);
    List<Relationship> relationshipList = relationshipService.getRelationshipsByProgramStageInstance(programStageInstance, true);
    assertEquals(1, relationshipList.size());
    assertTrue(relationshipList.contains(relationshipA));
    assertTrue(relationshipService.getRelationshipByRelationship(relationshipA).isPresent());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Relationship(org.hisp.dhis.relationship.Relationship) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 92 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class AclServiceTest method testUpdatePrivateProgram.

@Test
void testUpdatePrivateProgram() {
    User user = createUser("user1A1", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAMSTAGE_ADD");
    Program program = createProgram('A');
    program.setCreatedBy(user);
    program.getSharing().setOwner(user);
    program.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.save(program);
    Access access = aclService.getAccess(program, user);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertFalse(access.isDelete());
    assertTrue(access.isManage());
    List<ErrorReport> errorReports = aclService.verifySharing(program, user);
    assertTrue(errorReports.isEmpty());
    manager.update(program);
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 93 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DashboardServiceTest method testSearchDashboardWithMaxCount.

@Test
void testSearchDashboardWithMaxCount() {
    Program prA = createProgram('A', null, null);
    objectManager.save(prA);
    IntStream.range(1, 30).forEach(i -> {
        Visualization visualization = createVisualization('A');
        visualization.setName(RandomStringUtils.randomAlphabetic(5));
        visualizationService.save(visualization);
    });
    IntStream.range(1, 30).forEach(i -> {
        EventVisualization eventVisualization = createEventVisualization("A", prA);
        eventVisualization.setName(RandomStringUtils.randomAlphabetic(5));
        eventVisualizationService.save(eventVisualization);
    });
    IntStream.range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA)));
    DashboardSearchResult result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION));
    assertThat(result.getVisualizationCount(), is(25));
    assertThat(result.getEventChartCount(), is(6));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION), 3, null);
    assertThat(result.getVisualizationCount(), is(25));
    assertThat(result.getEventChartCount(), is(3));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION), 3, 29);
    assertThat(result.getVisualizationCount(), is(29));
    assertThat(result.getEventChartCount(), is(3));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.EVENT_VISUALIZATION), 3, 29);
    assertThat(result.getEventVisualizationCount(), is(29));
    assertThat(result.getEventReportCount(), is(0));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.EVENT_VISUALIZATION), 3, 30);
    assertThat(result.getEventVisualizationCount(), is(30));
    assertThat(result.getEventChartCount(), is(3));
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Visualization(org.hisp.dhis.visualization.Visualization) Program(org.hisp.dhis.program.Program) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 94 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class ProgramRuleVariableIntegrationTest method shouldAssignValueTypeFromTrackedEntityAttributeToProgramRuleVariable.

@Test
public void shouldAssignValueTypeFromTrackedEntityAttributeToProgramRuleVariable() {
    Program program = programService.getProgram("BFcipDERJne");
    TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute("sYn3tkL3XKa");
    List<ProgramRuleVariable> ruleVariables = programRuleVariableService.getProgramRuleVariable(program);
    ProgramRuleVariable prv = ruleVariables.stream().filter(r -> ProgramRuleVariableSourceType.TEI_ATTRIBUTE == r.getSourceType()).findFirst().get();
    assertEquals(trackedEntityAttribute.getValueType(), prv.getValueType());
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 95 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class ProgramRuleVariableIntegrationTest method shouldAssignDefaultValueTypeToProgramRuleVariable.

@Test
public void shouldAssignDefaultValueTypeToProgramRuleVariable() {
    Program program = programService.getProgram("BFcipDERJne");
    List<ProgramRuleVariable> ruleVariables = programRuleVariableService.getProgramRuleVariable(program);
    ProgramRuleVariable prv = ruleVariables.stream().filter(r -> ProgramRuleVariableSourceType.CALCULATED_VALUE == r.getSourceType()).findFirst().get();
    assertEquals(ValueType.TEXT, prv.getValueType());
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Program(org.hisp.dhis.program.Program) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37