Search in sources :

Example 76 with OrganisationUnit

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OrganisationUnitQueryParams(org.hisp.dhis.organisationunit.OrganisationUnitQueryParams)

Example 77 with OrganisationUnit

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateTime(org.joda.time.DateTime) ProgramMessageQueryParams(org.hisp.dhis.program.message.ProgramMessageQueryParams) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) HashSet(java.util.HashSet)

Example 78 with OrganisationUnit

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");
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HashSet(java.util.HashSet)

Example 79 with OrganisationUnit

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");
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HashSet(java.util.HashSet)

Example 80 with OrganisationUnit

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)321 Period (org.hisp.dhis.period.Period)74 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)62 User (org.hisp.dhis.user.User)57 Date (java.util.Date)53 HashSet (java.util.HashSet)53 DataSet (org.hisp.dhis.dataset.DataSet)53 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 DataElement (org.hisp.dhis.dataelement.DataElement)50 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)37 List (java.util.List)36 CurrentUserService (org.hisp.dhis.user.CurrentUserService)29 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)23 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)23 Program (org.hisp.dhis.program.Program)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20