use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ProgramExpressionServiceTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
Program program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
stageA = new ProgramStage("StageA", program);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
stageB = new ProgramStage("StageB", program);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
program.setProgramStages(programStages);
programService.updateProgram(program);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', organisationUnit);
entityInstanceService.addTrackedEntityInstance(entityInstance);
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, new Date(), new Date(), organisationUnit);
ProgramStageInstance stageInstance = programStageInstanceService.createProgramStageInstance(programInstance, stageA, new Date(), new Date(), organisationUnit);
TrackedEntityDataValue dataValueA = new TrackedEntityDataValue(stageInstance, dataElementA, "1");
TrackedEntityDataValue dataValueB = new TrackedEntityDataValue(stageInstance, dataElementB, "2");
dataValueService.saveTrackedEntityDataValue(dataValueA);
dataValueService.saveTrackedEntityDataValue(dataValueB);
programExpressionA = new ProgramExpression("[" + ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT + ProgramExpression.SEPARATOR_OBJECT + stageA.getUid() + "." + dataElementA.getUid() + "]", "A");
programExpressionB = new ProgramExpression("[" + ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT + ProgramExpression.SEPARATOR_OBJECT + stageA.getUid() + "." + dataElementB.getUid() + "]", "B");
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class MinMaxDataElementStoreTest method testBasic.
@Test
public void testBasic() {
OrganisationUnit source1 = createOrganisationUnit('A');
OrganisationUnit source2 = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(source1);
organisationUnitService.addOrganisationUnit(source2);
DataElement dataElement1 = createDataElement('A');
DataElement dataElement2 = createDataElement('B');
DataElement dataElement3 = createDataElement('C');
DataElement dataElement4 = createDataElement('D');
dataElementService.addDataElement(dataElement1);
dataElementService.addDataElement(dataElement2);
dataElementService.addDataElement(dataElement3);
dataElementService.addDataElement(dataElement4);
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(source1, dataElement1, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(source2, dataElement2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(source2, dataElement3, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(source2, dataElement4, optionCombo, 0, 100, false);
minMaxDataElementStore.save(minMaxDataElement1);
int mmdeid1 = minMaxDataElement1.getId();
minMaxDataElementStore.save(minMaxDataElement2);
minMaxDataElementStore.save(minMaxDataElement3);
minMaxDataElementStore.save(minMaxDataElement4);
// ----------------------------------------------------------------------
// Assertions
// ----------------------------------------------------------------------
assertNotNull(minMaxDataElementStore.get(mmdeid1));
assertTrue(minMaxDataElementStore.get(mmdeid1).getMax() == 100);
List<DataElement> dataElements1 = new ArrayList<>();
dataElements1.add(dataElement1);
List<DataElement> dataElements2 = new ArrayList<>();
dataElements2.add(dataElement2);
dataElements2.add(dataElement3);
dataElements2.add(dataElement4);
assertNotNull(minMaxDataElementStore.get(source1, dataElement1, optionCombo));
assertNull(minMaxDataElementStore.get(source2, dataElement1, optionCombo));
assertEquals(1, minMaxDataElementStore.get(source1, dataElements1).size());
assertEquals(3, minMaxDataElementStore.get(source2, dataElements2).size());
minMaxDataElementStore.delete(minMaxDataElement1);
assertNull(minMaxDataElementStore.get(mmdeid1));
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ProgramIndicatorServiceTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
// ---------------------------------------------------------------------
// Program
// ---------------------------------------------------------------------
programA = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(programA);
psA = new ProgramStage("StageA", programA);
psA.setSortOrder(1);
programStageService.saveProgramStage(psA);
psB = new ProgramStage("StageB", programA);
psB.setSortOrder(2);
programStageService.saveProgramStage(psB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(psA);
programStages.add(psB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
programB = createProgram('B', new HashSet<>(), organisationUnit);
programService.addProgram(programB);
// ---------------------------------------------------------------------
// Program Stage DE
// ---------------------------------------------------------------------
deA = createDataElement('A');
deA.setDomainType(DataElementDomain.TRACKER);
deB = createDataElement('B');
deB.setDomainType(DataElementDomain.TRACKER);
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
ProgramStageDataElement stageDataElementA = new ProgramStageDataElement(psA, deA, false, 1);
ProgramStageDataElement stageDataElementB = new ProgramStageDataElement(psA, deB, false, 2);
ProgramStageDataElement stageDataElementC = new ProgramStageDataElement(psB, deA, false, 1);
ProgramStageDataElement stageDataElementD = new ProgramStageDataElement(psB, deB, false, 2);
programStageDataElementService.addProgramStageDataElement(stageDataElementA);
programStageDataElementService.addProgramStageDataElement(stageDataElementB);
programStageDataElementService.addProgramStageDataElement(stageDataElementC);
programStageDataElementService.addProgramStageDataElement(stageDataElementD);
// ---------------------------------------------------------------------
// TrackedEntityInstance & Enrollment
// ---------------------------------------------------------------------
TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', organisationUnit);
entityInstanceService.addTrackedEntityInstance(entityInstance);
incidentDate = DateUtils.getMediumDate("2014-10-22");
enrollmentDate = DateUtils.getMediumDate("2014-12-31");
programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
incidentDate = DateUtils.getMediumDate("2014-10-22");
enrollmentDate = DateUtils.getMediumDate("2014-12-31");
programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
// TODO enroll twice?
// ---------------------------------------------------------------------
// TrackedEntityAttribute
// ---------------------------------------------------------------------
atA = createTrackedEntityAttribute('A', ValueType.NUMBER);
atB = createTrackedEntityAttribute('B', ValueType.NUMBER);
attributeService.addTrackedEntityAttribute(atA);
attributeService.addTrackedEntityAttribute(atB);
TrackedEntityAttributeValue attributeValueA = new TrackedEntityAttributeValue(atA, entityInstance, "1");
TrackedEntityAttributeValue attributeValueB = new TrackedEntityAttributeValue(atB, entityInstance, "2");
attributeValueService.addTrackedEntityAttributeValue(attributeValueA);
attributeValueService.addTrackedEntityAttributeValue(attributeValueB);
// ---------------------------------------------------------------------
// TrackedEntityDataValue
// ---------------------------------------------------------------------
ProgramStageInstance stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, psA, enrollmentDate, incidentDate, organisationUnit);
ProgramStageInstance stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, psB, enrollmentDate, incidentDate, organisationUnit);
Set<ProgramStageInstance> programStageInstances = new HashSet<>();
programStageInstances.add(stageInstanceA);
programStageInstances.add(stageInstanceB);
programInstance.setProgramStageInstances(programStageInstances);
programInstance.setProgram(programA);
TrackedEntityDataValue dataValueA = new TrackedEntityDataValue(stageInstanceA, deA, "3");
TrackedEntityDataValue dataValueB = new TrackedEntityDataValue(stageInstanceA, deB, "1");
TrackedEntityDataValue dataValueC = new TrackedEntityDataValue(stageInstanceB, deA, "5");
TrackedEntityDataValue dataValueD = new TrackedEntityDataValue(stageInstanceB, deB, "7");
dataValueService.saveTrackedEntityDataValue(dataValueA);
dataValueService.saveTrackedEntityDataValue(dataValueB);
dataValueService.saveTrackedEntityDataValue(dataValueC);
dataValueService.saveTrackedEntityDataValue(dataValueD);
// ---------------------------------------------------------------------
// Constant
// ---------------------------------------------------------------------
Constant constantA = createConstant('A', 7.0);
constantService.saveConstant(constantA);
// ---------------------------------------------------------------------
// ProgramIndicator
// ---------------------------------------------------------------------
String expressionA = "( d2:daysBetween(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "}, " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}) ) / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
indicatorA = createProgramIndicator('A', programA, expressionA, null);
programA.getProgramIndicators().add(indicatorA);
indicatorB = createProgramIndicator('B', programA, "70", null);
programA.getProgramIndicators().add(indicatorB);
indicatorC = createProgramIndicator('C', programA, "0", null);
programA.getProgramIndicators().add(indicatorC);
String expressionD = "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}";
indicatorD = createProgramIndicator('D', programB, expressionD, null);
String expressionE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deA.getUid() + "} - " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atB.getUid() + "}";
String filterE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} > 10";
indicatorE = createProgramIndicator('E', programB, expressionE, filterE);
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DhisConvenienceTest method createUserAndInjectSecurityContext.
/**
* Creates a user and injects into the security context with username
* "username". Requires <code>identifiableObjectManager</code> and
* <code>userService</code> to be injected into the test.
*
* @param organisationUnits the organisation units of the user.
* @param dataViewOrganisationUnits user's data view organisation units.
* @param allAuth whether to grant the ALL authority.
* @param auths authorities to grant to user.
* @return the user.
*/
protected User createUserAndInjectSecurityContext(Set<OrganisationUnit> organisationUnits, Set<OrganisationUnit> dataViewOrganisationUnits, boolean allAuth, String... auths) {
Assert.notNull(userService, "UserService must be injected in test");
Set<String> authorities = new HashSet<>();
if (allAuth) {
authorities.add(UserAuthorityGroup.AUTHORITY_ALL);
}
if (auths != null) {
authorities.addAll(Lists.newArrayList(auths));
}
UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
userAuthorityGroup.setName("Superuser");
userAuthorityGroup.getAuthorities().addAll(authorities);
userService.addUserAuthorityGroup(userAuthorityGroup);
User user = createUser('A');
if (organisationUnits != null) {
user.setOrganisationUnits(organisationUnits);
}
if (dataViewOrganisationUnits != null) {
user.setDataViewOrganisationUnits(dataViewOrganisationUnits);
}
user.getUserCredentials().getUserAuthorityGroups().add(userAuthorityGroup);
userService.addUser(user);
user.getUserCredentials().setUserInfo(user);
userService.addUserCredentials(user.getUserCredentials());
Set<GrantedAuthority> grantedAuths = authorities.stream().map(a -> new SimpleGrantedAuthority(a)).collect(Collectors.toSet());
UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getUserCredentials().getUsername(), user.getUserCredentials().getPassword(), grantedAuths);
Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, "", grantedAuths);
SecurityContextHolder.getContext().setAuthentication(authentication);
return user;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOrganisationUnit.
/**
* @param name The name, short name and code of the organisation unit.
*/
public static OrganisationUnit createOrganisationUnit(String name) {
OrganisationUnit unit = new OrganisationUnit();
unit.setAutoFields();
unit.setUid(CodeGenerator.generateUid());
unit.setName(name);
unit.setShortName(name);
unit.setCode(name);
unit.setOpeningDate(date);
unit.setComment("Comment " + name);
return unit;
}
Aggregations