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");
}
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);
}
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;
}
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);
}
}
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();
}
Aggregations