Search in sources :

Example 56 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DataApprovalController method getApprovalPermissions.

// -------------------------------------------------------------------------
// Get
// -------------------------------------------------------------------------
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalPermissions(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws IOException, WebMessageException {
    DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    DataApprovalStatus status = dataApprovalService.getDataApprovalStatusAndPermissions(workflow, period, organisationUnit, optionCombo);
    DataApprovalPermissions permissions = status.getPermissions();
    permissions.setState(status.getState().toString());
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), 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) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DataApprovalController method getApprovalsAsList.

private List<DataApproval> getApprovalsAsList(DataApprovalLevel dataApprovalLevel, DataApprovalWorkflow workflow, Period period, OrganisationUnit organisationUnit, boolean accepted, Date created, User creator) {
    List<DataApproval> approvals = new ArrayList<>();
    DataElementCategoryOptionCombo combo = categoryService.getDefaultDataElementCategoryOptionCombo();
    period = periodService.reloadPeriod(period);
    approvals.add(new DataApproval(dataApprovalLevel, workflow, period, organisationUnit, combo, accepted, created, creator));
    return approvals;
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 58 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.

@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
    List<CompleteDataSetRegistration> registrations = new ArrayList<>();
    for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
        String ds = completeDataSetRegistrationRequest.getDs();
        DataSet dataSet = dataSetService.getDataSet(ds);
        if (dataSet == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
        }
        String pe = completeDataSetRegistrationRequest.getPe();
        Period period = PeriodType.getPeriodFromIsoString(pe);
        if (period == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
        }
        String ou = completeDataSetRegistrationRequest.getOu();
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
        }
        String cc = completeDataSetRegistrationRequest.getCc();
        String cp = completeDataSetRegistrationRequest.getCp();
        DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
        if (attributeOptionCombo == null) {
            return;
        }
        // ---------------------------------------------------------------------
        // Check locked status
        // ---------------------------------------------------------------------
        boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
        if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
            throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
        }
        // ---------------------------------------------------------------------
        // Register as completed data set
        // ---------------------------------------------------------------------
        String sb = completeDataSetRegistrationRequest.getSb();
        String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
        Date cd = completeDataSetRegistrationRequest.getCd();
        Date completionDate = (cd == null) ? new Date() : cd;
        Set<OrganisationUnit> orgUnits = new HashSet<>();
        orgUnits.add(organisationUnit);
        if (multiOu) {
            orgUnits.addAll(organisationUnit.getChildren());
        }
        addRegistrationsForOrgUnits(registrations, orgUnits, dataSet, period, attributeOptionCombo, storedBy, completionDate);
    }
    registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistrationRequest(org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest) Date(java.util.Date) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 59 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class RunValidationAction method execute.

// -------------------------------------------------------------------------
// Execute
// -------------------------------------------------------------------------
@Override
public String execute() {
    organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitWithChildren(organisationUnit.getId());
    ValidationRuleGroup group = validationRuleGroupId == -1 ? null : validationRuleService.getValidationRuleGroup(validationRuleGroupId);
    DataElementCategoryOptionCombo attributeOptionCombo = attributeOptionComboId == null || attributeOptionComboId == -1 ? null : dataElementCategoryService.getDataElementCategoryOptionCombo(attributeOptionComboId);
    log.info("Validating data for " + (group == null ? "all rules" : "group: " + group.getName()));
    validationResults = new ArrayList<>(validationService.startInteractiveValidationAnalysis(format.parseDate(startDate), format.parseDate(endDate), organisationUnits, attributeOptionCombo, group, sendNotifications, format));
    maxExceeded = validationResults.size() > ValidationService.MAX_INTERACTIVE_ALERTS;
    Collections.sort(validationResults, new ValidationResultComparator());
    SessionUtils.setSessionVar(KEY_VALIDATIONRESULT, validationResults);
    computeShowAttributeCombos();
    log.info("Validation done");
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationRuleGroup(org.hisp.dhis.validation.ValidationRuleGroup) ValidationResultComparator(org.hisp.dhis.validation.comparator.ValidationResultComparator) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)59 DataElement (org.hisp.dhis.dataelement.DataElement)26 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Period (org.hisp.dhis.period.Period)22 Date (java.util.Date)13 DataValue (org.hisp.dhis.datavalue.DataValue)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)11 ArrayList (java.util.ArrayList)10 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)9 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)6 DataSet (org.hisp.dhis.dataset.DataSet)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 HashSet (java.util.HashSet)5 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)4 Test (org.junit.Test)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Matcher (java.util.regex.Matcher)3 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)3