Search in sources :

Example 41 with DataElementCategoryOptionCombo

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

the class EventController method getCsvEvents.

@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/csv", "application/csv+gzip", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
public void getCsvEvents(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false, defaultValue = "false") boolean skipHeader, IdSchemes idSchemes, HttpServletResponse response, HttpServletRequest request) throws IOException, WebMessageException {
    boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
    if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, null, null, null, includeDeleted);
    Events events = eventService.getEvents(params);
    OutputStream outputStream = response.getOutputStream();
    response.setContentType("application/csv");
    if (ContextUtils.isAcceptCsvGzip(request)) {
        response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
        outputStream = new GZIPOutputStream(outputStream);
        response.setContentType("application/csv+gzip");
    }
    if (!StringUtils.isEmpty(attachment)) {
        response.addHeader("Content-Disposition", "attachment; filename=" + attachment);
    }
    csvEventService.writeEvents(outputStream, events, !skipHeader);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Events(org.hisp.dhis.dxf2.events.event.Events) GZIPOutputStream(java.util.zip.GZIPOutputStream) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with DataElementCategoryOptionCombo

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

the class FacilityReportingServiceImpl method saveValue.

private void saveValue(OrganisationUnit unit, Period period, org.hisp.dhis.dataelement.DataElement dataElement, DataValue dv) {
    String value = dv.getValue().trim();
    DataElementCategoryOptionCombo catOptCombo = categoryService.getDataElementCategoryOptionCombo(dv.getCategoryOptComboID());
    org.hisp.dhis.datavalue.DataValue dataValue = dataValueService.getDataValue(dataElement, period, unit, catOptCombo);
    if (dataValue == null) {
        dataValue = new org.hisp.dhis.datavalue.DataValue(dataElement, period, unit, catOptCombo, categoryService.getDefaultDataElementCategoryOptionCombo(), value, "", new Date(), "");
        dataValueService.addDataValue(dataValue);
    } else {
        dataValue.setValue(value);
        dataValue.setLastUpdated(new Date());
        dataValueService.updateDataValue(dataValue);
    }
}
Also used : DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

Example 43 with DataElementCategoryOptionCombo

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

the class FacilityReportingServiceImpl method saveDataSetValues.

@Override
public void saveDataSetValues(OrganisationUnit unit, DataSetValue dataSetValue) throws NotAllowedException {
    org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet(dataSetValue.getId());
    if (!dataSetAssociatedWithOrgUnit(unit, dataSet)) {
        log.info("Failed to save data value set for: " + unit.getName() + ", " + dataSet.getName() + " - Org unit and data set not associated.");
        throw NotAllowedException.INVALID_DATASET_ASSOCIATION;
    }
    Period period = getPeriod(dataSetValue.getPeriodName(), dataSet.getPeriodType());
    if (period == null) {
        log.info("Failed to save data value set for: " + unit.getName() + ", " + dataSet.getName() + " - Period not found.");
        throw NotAllowedException.INVALID_PERIOD;
    }
    log.info("Recieved data value set for: " + unit.getName() + ", " + dataSet.getName() + ", " + period.getIsoDate());
    Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = getDataElementIdMapping(dataSet);
    for (DataValue dataValue : dataSetValue.getDataValues()) {
        org.hisp.dhis.dataelement.DataElement dataElement = dataElementMap.get(dataValue.getId());
        if (dataElement == null) {
            log.info("Data value submitted for data element " + dataValue.getId() + ", that is not in data set '" + dataSet.getName() + "'");
            continue;
        }
        if (StringUtils.isEmpty(dataValue.getValue())) {
            log.debug("Empty data value for data element " + dataValue.getId() + " not saved");
            continue;
        }
        saveValue(unit, period, dataElement, dataValue);
    }
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, unit, optionCombo);
    if (registration != null) {
        registrationService.deleteCompleteDataSetRegistration(registration);
    }
    registration = new CompleteDataSetRegistration();
    registration.setDataSet(dataSet);
    registration.setPeriod(period);
    registration.setSource(unit);
    registration.setDate(new Date());
    registration.setStoredBy(currentUserService.getCurrentUser().getUsername());
    registrationService.saveCompleteDataSetRegistration(registration);
    log.info("Saved and registered data value set as complete: " + unit.getName() + ", " + dataSet.getName() + ", " + period.getIsoDate());
}
Also used : DataValue(org.hisp.dhis.api.mobile.model.DataValue) Period(org.hisp.dhis.period.Period) Date(java.util.Date) DataElement(org.hisp.dhis.api.mobile.model.DataElement) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 44 with DataElementCategoryOptionCombo

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

the class FormUtilsImpl method getDataValueMap.

@Override
public Map<String, String> getDataValueMap(OrganisationUnit organisationUnit, DataSet dataSet, Period period) {
    Map<String, String> dataValueMap = new HashMap<>();
    List<DataValue> values = dataValueService.getDataValues(new DataExportParams().setDataElements(dataSet.getDataElements()).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(organisationUnit)));
    for (DataValue dataValue : values) {
        DataElement dataElement = dataValue.getDataElement();
        DataElementCategoryOptionCombo optionCombo = dataValue.getCategoryOptionCombo();
        String key = String.format("DE%dOC%d", dataElement.getId(), optionCombo.getId());
        String value = dataValue.getValue();
        dataValueMap.put(key, value);
    }
    return dataValueMap;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 45 with DataElementCategoryOptionCombo

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

the class DataValueSMSListener method sendSuccessFeedback.

protected void sendSuccessFeedback(String sender, SMSCommand command, Map<String, String> parsedMessage, Date date, OrganisationUnit orgunit) {
    String reportBack = "Thank you! Values entered: ";
    String notInReport = "Missing values for: ";
    Period period = null;
    Map<String, DataValue> codesWithDataValues = new TreeMap<>();
    List<String> codesWithoutDataValues = new ArrayList<>();
    for (SMSCode code : command.getCodes()) {
        DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo(code.getOptionId());
        period = getPeriod(command, date);
        DataValue dv = dataValueService.getDataValue(code.getDataElement(), period, orgunit, optionCombo);
        if (dv == null && !StringUtils.isEmpty(code.getCode())) {
            codesWithoutDataValues.add(code.getCode());
        } else if (dv != null) {
            codesWithDataValues.put(code.getCode(), dv);
        }
    }
    for (String key : codesWithDataValues.keySet()) {
        DataValue dv = codesWithDataValues.get(key);
        String value = dv.getValue();
        if (ValueType.BOOLEAN == dv.getDataElement().getValueType()) {
            if ("true".equals(value)) {
                value = "Yes";
            } else if ("false".equals(value)) {
                value = "No";
            }
        }
        reportBack += key + "=" + value + " ";
    }
    Collections.sort(codesWithoutDataValues);
    for (String key : codesWithoutDataValues) {
        notInReport += key + ",";
    }
    notInReport = notInReport.substring(0, notInReport.length() - 1);
    if (smsSender.isConfigured()) {
        if (command.getSuccessMessage() != null && !StringUtils.isEmpty(command.getSuccessMessage())) {
            smsSender.sendMessage(null, command.getSuccessMessage(), sender);
        } else {
            smsSender.sendMessage(null, reportBack, sender);
        }
    } else {
        Log.info("No sms configuration found.");
    }
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) TreeMap(java.util.TreeMap) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4