Search in sources :

Example 26 with OrganisationUnit

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

Example 27 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 28 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 29 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 30 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)

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