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