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());
}
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);
}
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));
}
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());
}
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());
}
Aggregations