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");
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithChartsWithPeriods1.
@Test
public void testCreateMetadataWithChartsWithPeriods1() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_chart_periods1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<Chart> charts = manager.getAll(Chart.class);
assertEquals(1, dataSets.size());
assertEquals(1, organisationUnits.size());
assertEquals(4, dataElements.size());
assertEquals(4, charts.size());
Chart chart = manager.get(Chart.class, "ziCoxdcXRQz");
assertNotNull(chart);
assertEquals(5, chart.getPeriods().size());
}
Aggregations