Search in sources :

Example 71 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventImportTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    CategoryOption categoryOption1 = new CategoryOption("male");
    categoryOption1.setAutoFields();
    CategoryOption categoryOption2 = new CategoryOption("female");
    categoryOption2.setAutoFields();
    manager.save(Lists.newArrayList(categoryOption1, categoryOption2));
    Category cat1 = new Category("cat1", DataDimensionType.DISAGGREGATION);
    cat1.setShortName(cat1.getName());
    cat1.setCategoryOptions(Lists.newArrayList(categoryOption1, categoryOption2));
    manager.save(Lists.newArrayList(cat1));
    CategoryCombo categoryCombo = manager.getByName(CategoryCombo.class, "default");
    categoryCombo.setCategories(Lists.newArrayList(cat1));
    dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.setCategoryCombo(categoryCombo);
    manager.save(dataElementA);
    dataElementA2 = createDataElement('a');
    dataElementA2.setValueType(ValueType.INTEGER);
    dataElementA2.setCategoryCombo(categoryCombo);
    manager.save(dataElementA2);
    dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.INTEGER);
    dataElementB.setCategoryCombo(categoryCombo);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageA.setFeatureType(FeatureType.POINT);
    manager.save(programStageA);
    programStageA2 = createProgramStage('a', 0);
    programStageA2.setFeatureType(FeatureType.POINT);
    programStageA2.setRepeatable(true);
    manager.save(programStageA2);
    programStageB = createProgramStage('B', 0);
    programStageB.setFeatureType(FeatureType.POINT);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setCategoryCombo(categoryCombo);
    manager.save(programA);
    programB = createProgram('B', new HashSet<>(), organisationUnitB);
    programB.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    programB.setCategoryCombo(categoryCombo);
    manager.save(programB);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    ProgramStageDataElement programStageDataElementA2 = new ProgramStageDataElement();
    programStageDataElementA2.setDataElement(dataElementA2);
    programStageDataElementA2.setProgramStage(programStageA2);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementA2);
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA2.getProgramStageDataElements().add(programStageDataElementA2);
    programStageA.setProgram(programA);
    programStageA2.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageA2);
    programStageB.getProgramStageDataElements().add(programStageDataElementB);
    programStageB.setProgram(programB);
    programB.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageA2);
    manager.update(programA);
    manager.update(programStageB);
    manager.update(programB);
    pi = new ProgramInstance();
    pi.setEnrollmentDate(new Date());
    pi.setIncidentDate(new Date());
    pi.setProgram(programB);
    pi.setStatus(ProgramStatus.ACTIVE);
    pi.setStoredBy("test");
    pi.setName("EventImportTestPI");
    pi.setUid(CodeGenerator.generateUid());
    manager.save(pi);
    event = createEvent("eventUid001");
    createUserAndInjectSecurityContext(true);
    // Flush all data to disk
    manager.flush();
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramInstance(org.hisp.dhis.program.ProgramInstance) CategoryOption(org.hisp.dhis.category.CategoryOption) Date(java.util.Date) HashSet(java.util.HashSet)

Example 72 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class AttributeOptionComboLoaderTest method verifyGetAttributeOptionComboWithNonExistingCategoryOption.

@Test
void verifyGetAttributeOptionComboWithNonExistingCategoryOption() {
    CategoryCombo cc = new CategoryCombo();
    assertThrows(IllegalQueryException.class, () -> subject.getAttributeOptionCombo(cc, "abcdef", "", IdScheme.UID), "Illegal category option identifier: abcdef");
}
Also used : DhisConvenienceTest.createCategoryCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryCombo) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Test(org.junit.jupiter.api.Test)

Example 73 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class AttributeOptionComboLoaderTest method verifyGetAttributeOptionCombo.

@Test
void verifyGetAttributeOptionCombo() {
    // prepare data
    CategoryCombo cc = createCategoryCombo('B');
    CategoryOption categoryOption = createCategoryOption('A');
    categoryOption.setId(100L);
    when(jdbcTemplate.queryForObject(eq("select categoryoptionid, uid, code, name, startdate, enddate, sharing from dataelementcategoryoption where uid = 'abcdef'"), any(RowMapper.class))).thenReturn(categoryOption);
    when(jdbcTemplate.query(anyString(), any(RowMapper.class))).thenReturn(singletonList(createCategoryOptionCombo(cc, categoryOption)));
    // method under test
    CategoryOptionCombo categoryOptionCombo = subject.getAttributeOptionCombo(cc, "abcdef", "", IdScheme.UID);
    // assertions
    assertThat(categoryOptionCombo, is(notNullValue()));
    verify(jdbcTemplate).query(sqlCaptor.capture(), any(RowMapper.class));
    final String sql = sqlCaptor.getValue();
    assertThat(sql, is(replace(SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS, "resolvedScheme", "uid = '" + cc.getUid() + "'", "option_ids", "'100'")));
}
Also used : DhisConvenienceTest.createCategoryCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryCombo) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) DhisConvenienceTest.createCategoryOption(org.hisp.dhis.DhisConvenienceTest.createCategoryOption) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DhisConvenienceTest.createCategoryOptionCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryOptionCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Example 74 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class CategoryOptionComboSupplierTest method case3.

private void case3(ImportOptions importOptions) {
    when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
    CategoryCombo catCombo = new CategoryCombo();
    catCombo.setUid(CodeGenerator.generateUid());
    program.setCategoryCombo(catCombo);
    // create event to import
    Event event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setAttributeCategoryOptions("abcded;fghilm");
    event.setProgram(program.getUid());
    CategoryOptionCombo coc = new CategoryOptionCombo();
    coc.setUid(CodeGenerator.generateUid());
    when(attributeOptionComboLoader.getAttributeOptionCombo(catCombo, event.getAttributeCategoryOptions(), event.getAttributeOptionCombo(), importOptions.getIdSchemes().getCategoryOptionComboIdScheme())).thenReturn(coc);
    Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(event));
    CategoryOptionCombo categoryOptionCombo = map.get(event.getUid());
    assertThat(categoryOptionCombo, is(notNullValue()));
    assertThat(categoryOptionCombo.getUid(), is(coc.getUid()));
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) Event(org.hisp.dhis.dxf2.events.event.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 75 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class ProgramStageValidationStrategyTest method setUpTest.

@Override
protected void setUpTest() {
    final int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    userService = _userService;
    createUserAndInjectSecurityContext(false, "F_TRACKED_ENTITY_DATAVALUE_ADD", "F_TRACKED_ENTITY_DATAVALUE_DELETE", "F_UNCOMPLETE_EVENT", "F_PROGRAMSTAGE_ADD", "F_PROGRAMSTAGE_DELETE", "F_PROGRAM_PUBLIC_ADD", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAM_DELETE", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_TRACKED_ENTITY_DELETE", "F_DATAELEMENT_PUBLIC_ADD", "F_DATAELEMENT_PRIVATE_ADD", "F_DATAELEMENT_DELETE", "F_CATEGORY_COMBO_PUBLIC_ADD", "F_CATEGORY_COMBO_PRIVATE_ADD", "F_CATEGORY_COMBO_DELETE");
    User currentUser = currentUserService.getCurrentUser();
    UserAccess userAccess1 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess2 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess3 = new UserAccess(currentUser, "rwrw----");
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitA.addUser(currentUser);
    organisationUnitA.getSharing().addUserAccess(userAccess1);
    currentUser.getTeiSearchOrganisationUnits().add(organisationUnitA);
    manager.save(organisationUnitA, false);
    userService.updateUser(currentUser);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityType.getSharing().addUserAccess(userAccess1);
    manager.save(trackedEntityType, false);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    maleA.getSharing().addUserAccess(userAccess1);
    maleA.setCreatedBy(currentUser);
    manager.save(maleA, false);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    DataElement dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(dataElementA, false);
    DataElement dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.TEXT);
    dataElementB.getSharing().addUserAccess(userAccess2);
    manager.save(dataElementB, false);
    DataElement dataElementC = createDataElement('C');
    dataElementC.setValueType(ValueType.INTEGER);
    dataElementC.getSharing().addUserAccess(userAccess3);
    manager.save(dataElementC, false);
    programStageA = createProgramStage('A', 0);
    programStageA.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    programStageA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageA, false);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.getSharing().addUserAccess(userAccess1);
    manager.save(programA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementA = new ProgramStageDataElement();
    programStageDataElementA.setDataElement(dataElementA);
    programStageDataElementA.setProgramStage(programStageA);
    programStageDataElementA.setCompulsory(true);
    programStageDataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageA);
    programStageDataElementB.setCompulsory(true);
    programStageDataElementB.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementB, false);
    // Create a NON-compulsory PSDE
    ProgramStageDataElement programStageDataElementC = new ProgramStageDataElement();
    programStageDataElementC.setDataElement(dataElementC);
    programStageDataElementC.setProgramStage(programStageA);
    programStageDataElementC.setCompulsory(false);
    programStageDataElementC.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementC, false);
    // Assign all 3 created PSDEs to created ProgramStage programStageA and
    // to
    // created Program programA
    programStageA.getProgramStageDataElements().add(programStageDataElementA);
    programStageA.getProgramStageDataElements().add(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElementC);
    programStageA.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    manager.update(programStageA);
    manager.update(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setIncidentDate(new Date());
    programInstance.setEnrollmentDate(new Date());
    programInstance.setEntityInstance(maleA);
    programInstance.getSharing().addUserAccess(userAccess1);
    maleA.getProgramInstances().add(programInstance);
    manager.save(programInstance, false);
    manager.update(maleA);
    Period periodA = createPeriod(testYear + "03");
    periodA.getSharing().addUserAccess(userAccess1);
    manager.save(periodA, false);
    CategoryCombo categoryComboA = createCategoryCombo('A');
    CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryComboA.getSharing().addUserAccess(userAccess1);
    categoryOptionComboA.getSharing().addUserAccess(userAccess1);
    manager.save(categoryComboA, false);
    manager.save(categoryOptionComboA, false);
    dataValueAMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "");
    dataValueBMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "");
    dataValueCMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "");
    dataValueA = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "42");
    dataValueB = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "Ford Prefect");
    dataValueC = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "84");
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Period(org.hisp.dhis.period.Period) Date(java.util.Date) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19