use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.
the class FormUtils method fillWithDataValues.
public static void fillWithDataValues(Form form, Collection<DataValue> dataValues) {
Map<String, Field> operandFieldMap = buildCacheMap(form);
for (DataValue dataValue : dataValues) {
DataElement dataElement = dataValue.getDataElement();
DataElementCategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
Field field = operandFieldMap.get(dataElement.getUid() + SEP + categoryOptionCombo.getUid());
if (field != null) {
field.setValue(dataValue.getValue());
field.setComment(dataValue.getComment());
}
}
}
use of org.hisp.dhis.datavalue.DataValue 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.datavalue.DataValue 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.");
}
}
use of org.hisp.dhis.datavalue.DataValue 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);
}
}
}
Aggregations