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 J2MEDataValueSMSListener method storeDataValue.
private void storeDataValue(String sender, OrganisationUnit orgUnit, Map<String, String> parsedMessage, SMSCode code, SMSCommand command, Period period, DataSet dataset) {
String upperCaseCode = code.getCode().toUpperCase();
String storedBy = SmsUtils.getUser(sender, command, userService.getUsersByPhoneNumber(sender)).getUsername();
if (StringUtils.isBlank(storedBy)) {
storedBy = "[unknown] from [" + sender + "]";
}
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo(code.getOptionId());
DataValue dv = dataValueService.getDataValue(code.getDataElement(), period, orgUnit, optionCombo);
String value = parsedMessage.get(upperCaseCode);
if (!StringUtils.isEmpty(value)) {
boolean newDataValue = false;
if (dv == null) {
dv = new DataValue();
dv.setCategoryOptionCombo(optionCombo);
dv.setSource(orgUnit);
dv.setDataElement(code.getDataElement());
dv.setPeriod(period);
dv.setComment("");
newDataValue = true;
}
if (ValueType.BOOLEAN == dv.getDataElement().getValueType()) {
if ("Y".equals(value.toUpperCase()) || "YES".equals(value.toUpperCase())) {
value = "true";
} else if ("N".equals(value.toUpperCase()) || "NO".equals(value.toUpperCase())) {
value = "false";
}
}
dv.setValue(value);
dv.setLastUpdated(new java.util.Date());
dv.setStoredBy(storedBy);
if (ValidationUtils.dataValueIsValid(value, dv.getDataElement()) != null) {
// not a valid value for data element
return;
}
if (newDataValue) {
dataValueService.addDataValue(dv);
} else {
dataValueService.updateDataValue(dv);
}
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class ChartController method getHistoryChart.
@RequestMapping(value = { "/history/data", "/history/data.png" }, method = RequestMethod.GET)
public void getHistoryChart(@RequestParam String de, @RequestParam String co, @RequestParam String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(defaultValue = "525", required = false) int width, @RequestParam(defaultValue = "300", required = false) int height, HttpServletResponse response) throws IOException, WebMessageException {
DataElement dataElement = dataElementService.getDataElement(de);
if (dataElement == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data element does not exist: " + de));
}
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(co);
if (categoryOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + co));
}
DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo(cp);
if (attributeOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("Category option combo does not exist: " + cp));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period does not exist: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist: " + ou));
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", false);
JFreeChart chart = chartService.getJFreeChartHistory(dataElement, categoryOptionCombo, attributeOptionCombo, period, organisationUnit, 13, i18nManager.getI18nFormat());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}
Aggregations