use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method sendSuccessFeedback.
private void sendSuccessFeedback(String sender, SMSCommand command, Map<String, String> parsedMessage, Period period, OrganisationUnit orgunit) {
String reportBack = "Thank you! Values entered: ";
String notInReport = "Missing values for: ";
boolean missingElements = false;
for (SMSCode code : command.getCodes()) {
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo(code.getOptionId());
DataValue dv = dataValueService.getDataValue(code.getDataElement(), period, orgunit, optionCombo);
if (dv == null && !StringUtils.isEmpty(code.getCode())) {
notInReport += code.getCode() + ",";
missingElements = true;
} else if (dv != null) {
String value = dv.getValue();
if (ValueType.BOOLEAN == dv.getDataElement().getValueType()) {
if ("true".equals(value)) {
value = "Yes";
} else if ("false".equals(value)) {
value = "No";
}
}
reportBack += code.getCode() + "=" + value + " ";
}
}
notInReport = notInReport.substring(0, notInReport.length() - 1);
if (missingElements) {
reportBack += notInReport;
}
if (command.getSuccessMessage() != null && !StringUtils.isEmpty(command.getSuccessMessage())) {
reportBack = command.getSuccessMessage();
}
smsSender.sendMessage(null, reportBack, sender);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method registerCompleteDataSet.
private void registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit organisationUnit, String storedBy) {
CompleteDataSetRegistration registration = new CompleteDataSetRegistration();
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
if (registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo) == null) {
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(organisationUnit);
registration.setDate(new Date());
registration.setStoredBy(storedBy);
registration.setPeriodName(registration.getPeriod().toString());
registrationService.saveCompleteDataSetRegistration(registration, false);
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validateAttrOptCombo.
private void validateAttrOptCombo(MetaDataProperties mdProps, MetaDataCaches mdCaches, ImportConfig config) throws ImportConflictException {
final Period pe = mdProps.period;
if (mdProps.attrOptCombo == null) {
if (config.requireAttrOptionCombos) {
throw new ImportConflictException(new ImportConflict("Attribute option combo", "Attribute option combo is required but is not specified"));
} else {
mdProps.attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
}
final DataElementCategoryOptionCombo aoc = mdProps.attrOptCombo;
DateRange range = aoc.getDateRange();
if ((range.getStartDate() != null && range.getStartDate().compareTo(pe.getStartDate()) > 0) || (range.getEndDate() != null && range.getEndDate().compareTo(pe.getEndDate()) < 0)) {
throw new ImportConflictException(new ImportConflict(mdProps.orgUnit.getUid(), String.format("Period: %s is not within range of attribute option combo: %s", pe.getIsoDate(), aoc.getUid())));
}
final String aocOrgUnitKey = aoc.getUid() + mdProps.orgUnit.getUid();
boolean isOrgUnitValidForAoc = mdCaches.attrOptComboOrgUnitMap.get(aocOrgUnitKey, () -> {
Set<OrganisationUnit> aocOrgUnits = aoc.getOrganisationUnits();
return aocOrgUnits == null || mdProps.orgUnit.isDescendant(aocOrgUnits);
});
if (!isOrgUnitValidForAoc) {
throw new ImportConflictException(new ImportConflict(mdProps.orgUnit.getUid(), String.format("Organisation unit: %s is not valid for attribute option combo %s", mdProps.orgUnit.getUid(), aoc.getUid())));
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultAdxDataService method convertAttributesToDxf.
private void convertAttributesToDxf(Map<String, String> attributes, String optionComboName, DataElementCategoryCombo catCombo, IdentifiableProperty scheme) throws AdxException {
log.debug("ADX attributes: " + attributes);
if (catCombo.isDefault()) {
return;
}
Map<String, DataElementCategory> categoryMap = getCodeCategoryMap(catCombo);
Map<String, String> attributeOptions = new HashMap<>();
for (String category : categoryMap.keySet()) {
if (attributes.containsKey(category)) {
attributeOptions.put(category, attributes.get(category));
attributes.remove(category);
} else {
throw new AdxException("Category combo " + catCombo.getName() + " must have " + categoryMap.get(category).getName());
}
}
DataElementCategoryOptionCombo catOptCombo = getCatOptComboFromAttributes(attributeOptions, catCombo, scheme);
attributes.put(optionComboName, catOptCombo.getUid());
log.debug("DXF attributes: " + attributes);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DefaultDataValueSetService method getDataValueTemplate.
private CollectionNode getDataValueTemplate(DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, Period period, boolean comment) {
CollectionNode collectionNode = new CollectionNode("dataValues");
collectionNode.setWrapping(false);
for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
ComplexNode complexNode = collectionNode.addChild(new ComplexNode("dataValue"));
String label = dataElement.getDisplayName();
if (!categoryOptionCombo.isDefault()) {
label += " " + categoryOptionCombo.getDisplayName();
}
if (comment) {
complexNode.setComment("Data element: " + label);
}
if (IdentifiableProperty.CODE.toString().toLowerCase().equals(deScheme.toLowerCase())) {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getCode()));
simpleNode.setAttribute(true);
} else {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getUid()));
simpleNode.setAttribute(true);
}
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("categoryOptionCombo", categoryOptionCombo.getUid()));
simpleNode.setAttribute(true);
simpleNode = complexNode.addChild(new SimpleNode("period", period != null ? period.getIsoDate() : ""));
simpleNode.setAttribute(true);
if (organisationUnit != null) {
if (IdentifiableProperty.CODE.toString().toLowerCase().equals(ouScheme.toLowerCase())) {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode()));
simpleNode.setAttribute(true);
} else {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid()));
simpleNode.setAttribute(true);
}
}
simpleNode = complexNode.addChild(new SimpleNode("value", ""));
simpleNode.setAttribute(true);
}
return collectionNode;
}
Aggregations