Search in sources :

Example 31 with DataElementCategoryOptionCombo

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);
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 32 with DataElementCategoryOptionCombo

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);
    }
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

Example 33 with DataElementCategoryOptionCombo

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())));
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DateRange(org.hisp.dhis.common.DateRange) Period(org.hisp.dhis.period.Period) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 34 with DataElementCategoryOptionCombo

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);
}
Also used : HashMap(java.util.HashMap) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 35 with DataElementCategoryOptionCombo

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;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4