use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultExpressionService method getOperandsInExpression.
@Override
@Transactional
public Set<DataElementOperand> getOperandsInExpression(String expression) {
Set<DataElementOperand> operandsInExpression = new HashSet<>();
if (expression != null) {
final Matcher matcher = OPERAND_PATTERN.matcher(expression);
while (matcher.find()) {
String dataElementUid = StringUtils.trimToNull(matcher.group(GROUP_DATA_ELEMENT));
String optionComboUid = StringUtils.trimToNull(matcher.group(GROUP_CATEGORORY_OPTION_COMBO));
DataElement dataElement = dataElementService.getDataElement(dataElementUid);
DataElementCategoryOptionCombo optionCombo = optionComboUid == null ? null : categoryService.getDataElementCategoryOptionCombo(optionComboUid);
operandsInExpression.add(new DataElementOperand(dataElement, optionCombo));
}
}
return operandsInExpression;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DataValueDimensionTest method setUpTest.
@Override
public void setUpTest() {
male = new DataElementCategoryOption("Male");
female = new DataElementCategoryOption("Female");
under15 = new DataElementCategoryOption("<15");
over15 = new DataElementCategoryOption(">15");
categoryService.addDataElementCategoryOption(male);
categoryService.addDataElementCategoryOption(female);
categoryService.addDataElementCategoryOption(under15);
categoryService.addDataElementCategoryOption(over15);
gender = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
gender.getCategoryOptions().add(male);
gender.getCategoryOptions().add(female);
ageGroup = new DataElementCategory("Agegroup", DataDimensionType.DISAGGREGATION);
ageGroup.getCategoryOptions().add(under15);
ageGroup.getCategoryOptions().add(over15);
categoryService.addDataElementCategory(gender);
categoryService.addDataElementCategory(ageGroup);
genderAndAgeGroup = new DataElementCategoryCombo("Gender and Agegroup", DataDimensionType.DISAGGREGATION);
genderAndAgeGroup.getCategories().add(gender);
genderAndAgeGroup.getCategories().add(ageGroup);
categoryService.addDataElementCategoryCombo(genderAndAgeGroup);
categoryService.generateOptionCombos(genderAndAgeGroup);
dataElementA = createDataElement('A', genderAndAgeGroup);
dataElementService.addDataElement(dataElementA);
periodA = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
periodService.addPeriod(periodA);
sourceA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(sourceA);
defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
for (DataElementCategoryOptionCombo categoryOptionCombo : genderAndAgeGroup.getOptionCombos()) {
dataValueService.addDataValue(createDataValue(dataElementA, periodA, sourceA, "10", categoryOptionCombo, defaultOptionCombo));
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class ModelMapping method getCategoryOptionCombos.
public static ModelList getCategoryOptionCombos(org.hisp.dhis.dataelement.DataElement dataElement) {
ModelList deCateOptCombo = new ModelList();
List<Model> listCateOptCombo = new ArrayList<>();
deCateOptCombo.setModels(listCateOptCombo);
for (DataElementCategoryOptionCombo oneCatOptCombo : dataElement.getSortedCategoryOptionCombos()) {
Model oneCateOptCombo = new Model();
oneCateOptCombo.setId(oneCatOptCombo.getId());
oneCateOptCombo.setName(oneCatOptCombo.getName());
listCateOptCombo.add(oneCateOptCombo);
}
return deCateOptCombo;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class SaveSectionFormAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
Validate.notNull(organisationUnitId);
Validate.notNull(isoPeriod);
Validate.notNull(dataSetId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Period period = periodService.getPeriod(isoPeriod);
boolean needsValidation = false;
dataSet = dataSetService.getDataSet(dataSetId);
String storedBy = currentUserService.getCurrentUsername();
if (StringUtils.isBlank(storedBy)) {
storedBy = "[unknown]";
}
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
Map<String, String> parameterMap = ContextUtils.getParameterMap(request);
for (String key : parameterMap.keySet()) {
if (key.startsWith("DE") && key.contains("OC")) {
String[] splitKey = key.split("OC");
Integer dataElementId = Integer.parseInt(splitKey[0].substring(2));
Integer optionComboId = Integer.parseInt(splitKey[1]);
String value = parameterMap.get(key);
DataElement dataElement = dataElementService.getDataElement(dataElementId);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(optionComboId);
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo);
value = value.trim();
Boolean valueIsEmpty = value.length() == 0;
// validate types
Boolean correctType = true;
ValueType valueType = dataElement.getValueType();
if (!valueIsEmpty) {
if (valueType.isText()) {
} else if (ValueType.BOOLEAN == valueType) {
if (!ValueUtils.isBoolean(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_boolean"));
}
} else if (ValueType.DATE == valueType) {
if (!ValueUtils.isDate(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_date"));
}
} else if (ValueType.NUMBER == valueType) {
if (!MathUtils.isNumeric(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_number"));
}
} else if (ValueType.INTEGER == valueType) {
if (!MathUtils.isInteger(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_integer"));
}
} else if (ValueType.INTEGER_POSITIVE == valueType) {
if (!MathUtils.isPositiveInteger(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_positive_integer"));
}
} else if (ValueType.INTEGER_NEGATIVE == valueType) {
if (!MathUtils.isNegativeInteger(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_negative_integer"));
}
} else if (ValueType.INTEGER_ZERO_OR_POSITIVE == valueType) {
if (!MathUtils.isZeroOrPositiveInteger(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_zero_or_positive_integer"));
}
} else if (ValueType.COORDINATE == valueType) {
if (!MathUtils.isCoordinate(value)) {
correctType = false;
typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_coordinate"));
}
}
}
// nothing entered
if (valueIsEmpty || !correctType) {
if (dataValue != null) {
dataValueService.deleteDataValue(dataValue);
}
}
if (correctType && !valueIsEmpty) {
if (dataValue == null) {
needsValidation = true;
dataValue = new DataValue(dataElement, period, organisationUnit, categoryOptionCombo, null, value, storedBy, new Date(), null);
dataValueService.addDataValue(dataValue);
} else {
if (!dataValue.getValue().equals(value)) {
needsValidation = true;
dataValue.setValue(value);
dataValue.setLastUpdated(new Date());
dataValue.setStoredBy(storedBy);
dataValueService.updateDataValue(dataValue);
}
}
}
}
}
//TODO
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
if (registration == null && complete) {
registration = new CompleteDataSetRegistration();
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(organisationUnit);
registration.setDate(new Date());
registration.setStoredBy(storedBy);
registrationService.saveCompleteDataSetRegistration(registration);
} else if (registration != null && !complete) {
registrationService.deleteCompleteDataSetRegistration(registration);
}
if (typeViolations.size() > 0) {
needsValidation = true;
}
if (sectionId != null) {
for (Section section : dataSet.getSections()) {
if (section.getId() == sectionId) {
name = section.getName();
dataElements = section.getDataElements();
break;
}
}
} else {
name = "Default";
dataElements = new ArrayList<>(dataSet.getDataElements());
Collections.sort(dataElements);
}
dataValues = formUtils.getDataValueMap(organisationUnit, dataSet, period);
validationViolations = formUtils.getValidationViolations(organisationUnit, dataElements, period);
if (needsValidation && (!validationViolations.isEmpty() || !typeViolations.isEmpty())) {
return ERROR;
}
validated = true;
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class UndoCompleteAction method execute.
@Override
public String execute() throws Exception {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Period period = periodService.getPeriod(isoPeriod);
DataSet dataSet = dataSetService.getDataSet(dataSetId);
//TODO
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
if (registration != null) {
registrationService.deleteCompleteDataSetRegistration(registration);
}
return SUCCESS;
}
Aggregations