Search in sources :

Example 86 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo 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 87 with CategoryOptionCombo

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

the class DataAnalysisController method getValidationRuleExpressionDetials.

@GetMapping("validationRulesExpression")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ValidationRuleExpressionDetails getValidationRuleExpressionDetials(@RequestParam String validationRuleId, @RequestParam String periodId, @RequestParam String organisationUnitId, @RequestParam(required = false) String attributeOptionComboId) throws WebMessageException {
    ValidationRule validationRule = validationRuleService.getValidationRule(validationRuleId);
    if (validationRule == null) {
        throw new WebMessageException(notFound("Can't find ValidationRule with id =" + validationRuleId));
    }
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    if (organisationUnit == null) {
        throw new WebMessageException(notFound("Can't find OrganisationUnit with id =" + organisationUnitId));
    }
    Period period = periodService.getPeriod(periodId);
    if (period == null) {
        throw new WebMessageException(notFound("Can't find Period with id =" + periodId));
    }
    CategoryOptionCombo attributeOptionCombo;
    if (attributeOptionComboId == null) {
        attributeOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    } else {
        attributeOptionCombo = categoryService.getCategoryOptionCombo(attributeOptionComboId);
        if (attributeOptionCombo == null) {
            throw new WebMessageException(notFound("Can't find AttributeOptionCombo with id = " + attributeOptionComboId));
        }
    }
    ValidationAnalysisParams params = validationService.newParamsBuilder(Lists.newArrayList(validationRule), organisationUnit, Lists.newArrayList(period)).withAttributeOptionCombo(attributeOptionCombo).build();
    return validationService.getValidationRuleExpressionDetails(params);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ValidationRule(org.hisp.dhis.validation.ValidationRule) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 88 with CategoryOptionCombo

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

the class DataAnalysisController method validationResultsListToResponse.

private List<ValidationResultView> validationResultsListToResponse(List<ValidationResult> validationResults) {
    I18nFormat format = i18nManager.getI18nFormat();
    if (validationResults == null) {
        return Collections.emptyList();
    }
    List<ValidationResultView> validationResultViews = new ArrayList<>(validationResults.size());
    for (ValidationResult validationResult : validationResults) {
        ValidationResultView validationResultView = new ValidationResultView();
        ValidationRule validationRule = validationResult.getValidationRule();
        if (validationRule != null) {
            validationResultView.setValidationRuleId(validationRule.getUid());
            validationResultView.setValidationRuleDescription(validationRule.getDescription());
            validationResultView.setImportance(validationRule.getImportance().toString());
            validationResultView.setOperator(validationRule.getOperator().getMathematicalOperator());
        }
        OrganisationUnit organisationUnit = validationResult.getOrganisationUnit();
        if (organisationUnit != null) {
            validationResultView.setOrganisationUnitId(organisationUnit.getUid());
            validationResultView.setOrganisationUnitDisplayName(organisationUnit.getDisplayName());
            validationResultView.setOrganisationUnitPath(organisationUnit.getPath());
            validationResultView.setOrganisationUnitAncestorNames(organisationUnit.getAncestorNames());
        }
        Period period = validationResult.getPeriod();
        if (period != null) {
            validationResultView.setPeriodId(period.getIsoDate());
            validationResultView.setPeriodDisplayName(format.formatPeriod(period));
        }
        CategoryOptionCombo attributeOptionCombo = validationResult.getAttributeOptionCombo();
        if (attributeOptionCombo != null) {
            validationResultView.setAttributeOptionComboId(attributeOptionCombo.getUid());
            validationResultView.setAttributeOptionComboDisplayName(attributeOptionCombo.getDisplayName());
        }
        validationResultView.setLeftSideValue(validationResult.getLeftsideValue());
        validationResultView.setRightSideValue(validationResult.getRightsideValue());
        validationResultViews.add(validationResultView);
    }
    return validationResultViews;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ValidationResultView(org.hisp.dhis.webapi.webdomain.ValidationResultView) ValidationResult(org.hisp.dhis.validation.ValidationResult) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Example 89 with CategoryOptionCombo

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

the class DataAnalysisController method markDataValues.

@PostMapping(value = "/followup/mark", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public void markDataValues(@RequestBody UpdateFollowUpForDataValuesRequest params) {
    log.info("markDataValues from DataAnalysisController input " + params);
    List<DataValue> dataValues = new ArrayList<>();
    for (FollowupParams followup : params.getFollowups()) {
        DataElement dataElement = dataElementService.getDataElement(followup.getDataElementId());
        Period period = periodService.getPeriod(followup.getPeriodId());
        OrganisationUnit source = organisationUnitService.getOrganisationUnit(followup.getOrganisationUnitId());
        CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(followup.getCategoryOptionComboId());
        CategoryOptionCombo attributeOptionCombo = categoryService.getCategoryOptionCombo(followup.getAttributeOptionComboId());
        DataValue dataValue = dataValueService.getDataValue(dataElement, period, source, categoryOptionCombo, attributeOptionCombo);
        if (dataValue != null) {
            dataValue.setFollowup(followup.isFollowup());
            dataValues.add(dataValue);
        }
    }
    if (dataValues.size() > 0) {
        dataValueService.updateDataValues(dataValues);
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) FollowupParams(org.hisp.dhis.dataanalysis.FollowupParams) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 90 with CategoryOptionCombo

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

the class DataApprovalController method getApprovalPermissions.

// -------------------------------------------------------------------------
// Get
// -------------------------------------------------------------------------
@GetMapping(value = APPROVALS_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public DataApprovalPermissions getApprovalPermissions(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
    DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
    DataApprovalStatus status = dataApprovalService.getDataApprovalStatus(workflow, period, organisationUnit, optionCombo);
    DataApprovalPermissions permissions = status.getPermissions();
    permissions.setState(status.getState().toString());
    return status.getPermissions();
}
Also used : DataApprovalPermissions(org.hisp.dhis.dataapproval.DataApprovalPermissions) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16