use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method countProgramInstances.
@Override
public int countProgramInstances(ProgramInstanceQueryParams params) {
decideAccess(params);
validate(params);
User user = currentUserService.getCurrentUser();
if (user != null && params.isOrganisationUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE)) {
params.setOrganisationUnits(user.getDataViewOrganisationUnitsWithFallback());
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.DESCENDANTS);
} else if (params.isOrganisationUnitMode(CHILDREN)) {
Set<OrganisationUnit> organisationUnits = new HashSet<>();
organisationUnits.addAll(params.getOrganisationUnits());
for (OrganisationUnit organisationUnit : params.getOrganisationUnits()) {
organisationUnits.addAll(organisationUnit.getChildren());
}
params.setOrganisationUnits(organisationUnits);
}
params.setSkipPaging(true);
return programInstanceStore.countProgramInstances(params);
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultProgramService method mergeWithCurrentUserOrganisationUnits.
@Override
public void mergeWithCurrentUserOrganisationUnits(Program program, Collection<OrganisationUnit> mergeOrganisationUnits) {
Set<OrganisationUnit> selectedOrgUnits = Sets.newHashSet(program.getOrganisationUnits());
OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
params.setParents(currentUserService.getCurrentUser().getOrganisationUnits());
Set<OrganisationUnit> userOrganisationUnits = Sets.newHashSet(organisationUnitService.getOrganisationUnitsByQuery(params));
selectedOrgUnits.removeAll(userOrganisationUnits);
selectedOrgUnits.addAll(mergeOrganisationUnits);
program.updateOrganisationUnits(selectedOrgUnits);
updateProgram(program);
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ProgramMessageStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Prerequisite
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
orgUnitService.addOrganisationUnit(ouA);
orgUnitService.addOrganisationUnit(ouB);
programA = createProgram('A', new HashSet<>(), ouA);
programService.addProgram(programA);
ProgramStage stageA = new ProgramStage("StageA", programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
entityInstanceA = createTrackedEntityInstance('A', ouA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
TrackedEntityInstance entityInstanceB = createTrackedEntityInstance('B', ouA);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceA, programA);
programInstanceA.setUid("UID-A");
programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setUid("UID-A");
Set<OrganisationUnit> ouSet = new HashSet<>();
ouSet.add(ouA);
Set<String> ouUids = new HashSet<>();
ouUids.add(ouA.getUid());
// ouSet.add( ouB );
teiA = createTrackedEntityInstance('Z', ouA);
teiService.addTrackedEntityInstance(teiA);
recipientsA = new ProgramMessageRecipients();
recipientsA.setOrganisationUnit(ouA);
recipientsA.setTrackedEntityInstance(teiA);
recipientsB = new ProgramMessageRecipients();
recipientsB.setOrganisationUnit(ouA);
recipientsB.setTrackedEntityInstance(teiA);
recipientsC = new ProgramMessageRecipients();
recipientsC.setOrganisationUnit(ouA);
recipientsC.setTrackedEntityInstance(teiA);
Set<String> phoneNumberListA = new HashSet<>();
phoneNumberListA.add(msisdn);
recipientsA.setPhoneNumbers(phoneNumberListA);
Set<String> phoneNumberListB = new HashSet<>();
phoneNumberListB.add(msisdn);
recipientsB.setPhoneNumbers(phoneNumberListB);
Set<String> phoneNumberListC = new HashSet<>();
phoneNumberListC.add(msisdn);
recipientsC.setPhoneNumbers(phoneNumberListC);
channels.add(DeliveryChannel.SMS);
pmsgA = new ProgramMessage();
pmsgA.setText(text);
pmsgA.setSubject(subject);
pmsgA.setRecipients(recipientsA);
pmsgA.setMessageStatus(messageStatus);
pmsgA.setDeliveryChannels(channels);
pmsgB = new ProgramMessage();
pmsgB.setText(text);
pmsgB.setSubject(subject);
pmsgB.setRecipients(recipientsB);
pmsgB.setMessageStatus(messageStatus);
pmsgB.setDeliveryChannels(channels);
pmsgC = new ProgramMessage();
pmsgC.setText(text);
pmsgC.setSubject(subject);
pmsgC.setRecipients(recipientsC);
pmsgC.setMessageStatus(messageStatus);
pmsgC.setDeliveryChannels(channels);
uidA = CodeGenerator.generateCode(10);
uidB = CodeGenerator.generateCode(10);
uidC = CodeGenerator.generateCode(10);
pmsgA.setUid(uidA);
pmsgB.setUid(uidB);
pmsgC.setUid(uidC);
params = new ProgramMessageQueryParams();
params.setOrganisationUnit(ouUids);
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ProgramStageServiceTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
stageA = new ProgramStage("A", program);
stageA.setUid("UID-A");
stageB = new ProgramStage("B", program);
stageB.setUid("UID-B");
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ProgramStageStoreTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
stageA = new ProgramStage("A", program);
stageA.setProgram(program);
stageA.setUid("UID-A");
stageB = new ProgramStage("B", program);
stageB.setProgram(program);
stageB.setUid("UID-B");
stageC = new ProgramStage("C", program);
stageB.setProgram(program);
stageC.setUid("UID-C");
}
Aggregations