Search in sources :

Example 1 with Model

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

the class DefaultProgramService method updateProgram.

@Override
public List<Program> updateProgram(ModelList programsFromClient, String localeString, OrganisationUnit unit) {
    List<Program> programs = new ArrayList<>();
    boolean isExisted = false;
    // Get all Program belong to this OrgUnit
    List<Program> serverPrograms = this.getPrograms(unit, localeString);
    for (Program program : serverPrograms) {
        // Loop thought the list of program from client
        for (int j = 0; j < programsFromClient.getModels().size(); j++) {
            Model model = programsFromClient.getModels().get(j);
            if (program.getId() == model.getId()) {
                // Version is different
                if (program.getVersion() != Integer.parseInt(model.getName())) {
                    programs.add(program);
                    isExisted = true;
                }
            }
        }
        // Server has more program than client
        if (!isExisted) {
            programs.add(program);
        }
    }
    return programs;
}
Also used : Program(org.hisp.dhis.api.mobile.model.Program) ArrayList(java.util.ArrayList) Model(org.hisp.dhis.api.mobile.model.Model)

Example 2 with Model

use of org.hisp.dhis.api.mobile.model.Model 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 3 with Model

use of org.hisp.dhis.api.mobile.model.Model 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;
}
Also used : ModelList(org.hisp.dhis.api.mobile.model.ModelList) ArrayList(java.util.ArrayList) Model(org.hisp.dhis.api.mobile.model.Model) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 4 with Model

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

the class ProgramStageDataElement method serialize.

@Override
public void serialize(DataOutputStream dout) throws IOException {
    super.serialize(dout);
    dout.writeUTF(this.getType());
    if (this.getNumberType() != null) {
        dout.writeBoolean(true);
        dout.writeUTF(this.getNumberType());
    } else {
        dout.writeBoolean(false);
    }
    dout.writeBoolean(this.isCompulsory());
    List<Model> cateOptCombos = this.getCategoryOptionCombos().getModels();
    if (cateOptCombos == null || cateOptCombos.size() <= 0) {
        dout.writeInt(0);
    } else {
        dout.writeInt(cateOptCombos.size());
        for (Model each : cateOptCombos) {
            each.setClientVersion(TWO_POINT_TEN);
            each.serialize(dout);
        }
    }
    if (optionSet == null || optionSet.getOptions().size() <= 0) {
        dout.writeBoolean(false);
    } else {
        dout.writeBoolean(true);
        optionSet.setClientVersion(TWO_POINT_TEN);
        optionSet.serialize(dout);
    }
    if (this.getValue() == null) {
        dout.writeBoolean(false);
    } else {
        dout.writeBoolean(true);
        dout.writeUTF(this.getValue());
    }
}
Also used : Model(org.hisp.dhis.api.mobile.model.Model)

Aggregations

Model (org.hisp.dhis.api.mobile.model.Model)4 ArrayList (java.util.ArrayList)3 DataElement (org.hisp.dhis.api.mobile.model.DataElement)1 DataSet (org.hisp.dhis.api.mobile.model.DataSet)1 ModelList (org.hisp.dhis.api.mobile.model.ModelList)1 Program (org.hisp.dhis.api.mobile.model.Program)1 Section (org.hisp.dhis.api.mobile.model.Section)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1