Search in sources :

Example 1 with CompleteDataSetRegistrationRequest

use of org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest 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)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 CompleteDataSetRegistrationRequest (org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 DataSet (org.hisp.dhis.dataset.DataSet)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1