Search in sources :

Example 1 with DataElement

use of org.hisp.dhis.api.mobile.model.DataElement in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getDataSetForLocale.

@Override
public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
    org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet(dataSetId);
    if (dataSet == null) {
        return null;
    }
    DataSet ds = new DataSet();
    ds.setId(dataSet.getId());
    String name = StringUtils.defaultIfEmpty(dataSet.getName(), dataSet.getShortName());
    ds.setName(name);
    ds.setVersion(1);
    Integer version = dataSet.getVersion();
    if (version != null) {
        ds.setVersion(version);
    }
    ds.setPeriodType(dataSet.getPeriodType().getName());
    List<Section> sectionList = new ArrayList<>();
    ds.setSections(sectionList);
    Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
    if (sections == null || sections.size() == 0) {
        List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
        // Fake section to store data elements
        Section section = new Section();
        section.setId(0);
        section.setName("");
        section.setDataElements(getDataElements(locale, dataElements));
        sectionList.add(section);
    } else {
        for (org.hisp.dhis.dataset.Section sec : sections) {
            Section section = new Section();
            section.setId(sec.getId());
            section.setName(sec.getName());
            List<org.hisp.dhis.dataelement.DataElement> des = new ArrayList<>(sec.getDataElements());
            // Remove grey fields in order to not display them on mobile
            List<DataElement> dataElementList = getDataElements(locale, des);
            List<DataElement> dataElementListFinal = new ArrayList<>(dataElementList);
            int tempI = 0;
            for (int i = 0; i < dataElementList.size(); i++) {
                List<Model> categoryOptionCombos = dataElementList.get(i).getCategoryOptionCombos().getModels();
                List<Model> newCategoryOptionCombos = new ArrayList<>();
                for (int j = 0; j < categoryOptionCombos.size(); j++) {
                    if (!isGreyField(sec, dataElementList.get(i).getId(), categoryOptionCombos.get(j).getId())) {
                        newCategoryOptionCombos.add(categoryOptionCombos.get(j));
                    }
                }
                if (newCategoryOptionCombos.isEmpty()) {
                    dataElementListFinal.remove(i - tempI);
                    tempI++;
                } else {
                    dataElementListFinal.get(i - tempI).getCategoryOptionCombos().setModels(newCategoryOptionCombos);
                }
            }
            section.setDataElements(dataElementListFinal);
            sectionList.add(section);
        }
    }
    return ds;
}
Also used : DataSet(org.hisp.dhis.api.mobile.model.DataSet) ArrayList(java.util.ArrayList) Section(org.hisp.dhis.api.mobile.model.Section) DataElement(org.hisp.dhis.api.mobile.model.DataElement) Model(org.hisp.dhis.api.mobile.model.Model)

Example 2 with DataElement

use of org.hisp.dhis.api.mobile.model.DataElement in project dhis2-core by dhis2.

the class ModelMapping method getDataElement.

public static DataElement getDataElement(org.hisp.dhis.dataelement.DataElement dataElement) {
    DataElement de = new DataElement();
    de.setId(dataElement.getId());
    de.setName(dataElement.getFormNameFallback());
    de.setType(dataElement.getValueType());
    de.setCategoryOptionCombos(getCategoryOptionCombos(dataElement));
    // Limit the optionset transfer to the client
    if (dataElement.getOptionSet() != null && dataElement.getOptionSet().getOptions().size() <= 50) {
        de.setOptionSet(getOptionSet(dataElement));
    }
    return de;
}
Also used : ProgramStageDataElement(org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement) DataElement(org.hisp.dhis.api.mobile.model.DataElement)

Example 3 with DataElement

use of org.hisp.dhis.api.mobile.model.DataElement 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());
}
Also used : DataValue(org.hisp.dhis.api.mobile.model.DataValue) Period(org.hisp.dhis.period.Period) Date(java.util.Date) DataElement(org.hisp.dhis.api.mobile.model.DataElement) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 4 with DataElement

use of org.hisp.dhis.api.mobile.model.DataElement in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getDataElements.

private List<DataElement> getDataElements(Locale locale, List<org.hisp.dhis.dataelement.DataElement> dataElements) {
    List<DataElement> dataElementList = new ArrayList<>();
    for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) {
        DataElement de = ModelMapping.getDataElement(dataElement);
        // For facility Reporting, no data elements are mandatory
        de.setCompulsory(false);
        dataElementList.add(de);
    }
    return dataElementList;
}
Also used : DataElement(org.hisp.dhis.api.mobile.model.DataElement) ArrayList(java.util.ArrayList)

Example 5 with DataElement

use of org.hisp.dhis.api.mobile.model.DataElement in project dhis2-core by dhis2.

the class DefaultProgramService method getProgram.

@Override
public Program getProgram(int programId, String localeString) {
    org.hisp.dhis.program.Program program = programService.getProgram(programId);
    Program pr = new Program();
    pr.setId(program.getId());
    pr.setName(program.getName());
    pr.setVersion(program.getVersion());
    List<ProgramStage> prStgs = new ArrayList<>();
    for (org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages()) {
        ProgramStage prStg = new ProgramStage();
        prStg.setId(programStage.getId());
        prStg.setName(programStage.getName());
        List<DataElement> des = new ArrayList<>();
        Set<ProgramStageDataElement> programStageDataElements = programStage.getProgramStageDataElements();
        for (ProgramStageDataElement programStagedataElement : programStageDataElements) {
            org.hisp.dhis.dataelement.DataElement dataElement = programStagedataElement.getDataElement();
            DataElement de = ModelMapping.getDataElement(dataElement);
            de.setCompulsory(programStagedataElement.isCompulsory());
            des.add(de);
        }
        prStg.setDataElements(des);
        prStgs.add(prStg);
    }
    pr.setProgramStages(prStgs);
    return pr;
}
Also used : Program(org.hisp.dhis.api.mobile.model.Program) ArrayList(java.util.ArrayList) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.api.mobile.model.DataElement) ProgramStage(org.hisp.dhis.api.mobile.model.ProgramStage)

Aggregations

DataElement (org.hisp.dhis.api.mobile.model.DataElement)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)1 DataSet (org.hisp.dhis.api.mobile.model.DataSet)1 DataValue (org.hisp.dhis.api.mobile.model.DataValue)1 ProgramStageDataElement (org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement)1 Model (org.hisp.dhis.api.mobile.model.Model)1 Program (org.hisp.dhis.api.mobile.model.Program)1 ProgramStage (org.hisp.dhis.api.mobile.model.ProgramStage)1 Section (org.hisp.dhis.api.mobile.model.Section)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 Period (org.hisp.dhis.period.Period)1 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)1