Search in sources :

Example 51 with CategoryCombo

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

the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound.

@Test
void eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound() {
    OrganisationUnit orgUnit = setupOrgUnit();
    Program program = setupProgram(orgUnit);
    CategoryCombo cc = categoryCombo();
    program.setCategoryCombo(cc);
    CategoryOption co = cc.getCategoryOptions().get(0);
    when(preheat.getCategoryOption(co.getUid())).thenReturn(co);
    CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
    when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
    Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(co.getUid()).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
    assertEquals(aoc, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) Event(org.hisp.dhis.tracker.domain.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 52 with CategoryCombo

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

the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndAOCIsSetToDefault.

@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndAOCIsSetToDefault() {
    OrganisationUnit orgUnit = setupOrgUnit();
    Program program = setupProgram(orgUnit);
    CategoryCombo cc = categoryCombo();
    program.setCategoryCombo(cc);
    CategoryOption co = cc.getCategoryOptions().get(0);
    when(preheat.getCategoryOption(co.getUid())).thenReturn(co);
    CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCategoryCombo());
    when(preheat.getCategoryOptionCombo(defaultAOC.getUid())).thenReturn(defaultAOC);
    Event event = eventBuilder().attributeOptionCombo(defaultAOC.getUid()).attributeCategoryOptions(co.getUid()).build();
    hook.validateEvent(reporter, event);
    assertEquals(1, reporter.getReportList().size());
    assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1055));
    assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Category(org.hisp.dhis.category.Category) RelationshipItem(org.hisp.dhis.tracker.domain.RelationshipItem) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DataDimensionType(org.hisp.dhis.common.DataDimensionType) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TRACKED_ENTITY_INSTANCE(org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE) RelationshipEntity(org.hisp.dhis.relationship.RelationshipEntity) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) Event(org.hisp.dhis.tracker.domain.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 53 with CategoryCombo

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

the class DataApprovalController method getApprovalByCategoryOptionCombos.

@GetMapping(value = APPROVALS_PATH + "/categoryOptionCombos", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public List<Map<String, Object>> getApprovalByCategoryOptionCombos(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam(required = false) String ou) throws WebMessageException {
    Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
    if (orgUnit != null && orgUnit.isRoot()) {
        // Look for all org units.
        orgUnit = null;
    }
    List<DataApprovalStatus> statusList = new ArrayList<>();
    for (DataApprovalWorkflow workflow : workflows) {
        Set<CategoryCombo> attributeCombos = new HashSet<>();
        for (DataSet dataSet : workflow.getDataSets()) {
            attributeCombos.add(dataSet.getCategoryCombo());
        }
        for (CategoryCombo attributeCombo : attributeCombos) {
            statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
        }
    }
    List<Map<String, Object>> list = new ArrayList<>();
    for (DataApprovalStatus status : statusList) {
        Map<String, Object> item = new HashMap<>();
        Map<String, String> approvalLevel = new HashMap<>();
        if (status.getApprovedLevel() != null) {
            approvalLevel.put("id", status.getApprovedLevel().getUid());
            approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
        }
        item.put("id", status.getAttributeOptionComboUid());
        item.put("level", approvalLevel);
        item.put("ou", status.getOrganisationUnitUid());
        item.put("ouName", status.getOrganisationUnitName());
        item.put("accepted", status.isAccepted());
        item.put("permissions", status.getPermissions());
        list.add(item);
    }
    return list;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 54 with CategoryCombo

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

the class GetDataElementsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    canReadType(DataElement.class);
    if (id != null && id != ALL) {
        DataElementGroup dataElementGroup = dataElementService.getDataElementGroup(id);
        if (dataElementGroup != null) {
            dataElements = new ArrayList<>(dataElementGroup.getMembers());
        }
    } else if (categoryComboId != null && categoryComboId != ALL) {
        CategoryCombo categoryCombo = categoryService.getCategoryCombo(categoryComboId);
        if (categoryCombo != null) {
            dataElements = new ArrayList<>(dataElementService.getDataElementByCategoryCombo(categoryCombo));
        }
    } else if (dataSetId != null) {
        DataSet dataset = dataSetService.getDataSet(dataSetId);
        if (dataset != null) {
            dataElements = new ArrayList<>(dataset.getDataElements());
        }
    } else if (periodTypeName != null) {
        PeriodType periodType = periodService.getPeriodTypeByName(periodTypeName);
        if (periodType != null) {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByPeriodType(periodType));
        }
    } else if (domain != null) {
        if (domain.equals(DataElementDomain.AGGREGATE.getValue())) {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.AGGREGATE));
        } else {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.TRACKER));
        }
    } else {
        dataElements = new ArrayList<>(dataElementService.getAllDataElements());
        ContextUtils.clearIfNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataElements);
    }
    if (key != null) {
        dataElements = IdentifiableObjectUtils.filterNameByKey(dataElements, key, true);
    }
    if (dataElements == null) {
        dataElements = new ArrayList<>();
    }
    Collections.sort(dataElements);
    if (aggregate) {
        FilterUtils.filter(dataElements, new AggregatableDataElementFilter());
    }
    User currentUser = currentUserService.getCurrentUser();
    dataElements.forEach(instance -> canReadInstance(instance, currentUser));
    if (usePaging) {
        this.paging = createPaging(dataElements.size());
        dataElements = dataElements.subList(paging.getStartPos(), paging.getEndPos());
    }
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) User(org.hisp.dhis.user.User) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) AggregatableDataElementFilter(org.hisp.dhis.system.filter.AggregatableDataElementFilter)

Example 55 with CategoryCombo

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

the class HandleRelationshipsTrackedEntityInstanceServiceTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    organisationUnitA = createOrganisationUnit('A');
    trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    trackedEntityInstanceA = createTrackedEntityInstance(organisationUnitA);
    trackedEntityInstanceA.setTrackedEntityType(trackedEntityType);
    trackedEntityInstanceB = createTrackedEntityInstance(organisationUnitA);
    trackedEntityInstanceB.setTrackedEntityType(trackedEntityType);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programStageA1 = createProgramStage('1', programA);
    programStageA2 = createProgramStage('2', programA);
    programA.setProgramStages(Stream.of(programStageA1, programStageA2).collect(Collectors.toCollection(HashSet::new)));
    manager.save(organisationUnitA);
    manager.save(trackedEntityInstanceA);
    manager.save(trackedEntityInstanceB);
    manager.save(programA);
    manager.save(programStageA1);
    manager.save(programStageA2);
    ProgramInstance programInstanceA = programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceA, programA, null, null, organisationUnitA);
    programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA1);
    programStageInstanceA.setDueDate(null);
    programStageInstanceA.setUid("UID-A");
    CategoryCombo categoryComboA = createCategoryCombo('A');
    CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    manager.save(categoryComboA);
    manager.save(categoryOptionComboA);
    programStageInstanceA.setAttributeOptionCombo(categoryOptionComboA);
    programStageInstanceService.addProgramStageInstance(programStageInstanceA);
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

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