Search in sources :

Example 1 with Group

use of org.hisp.dhis.webapi.webdomain.form.Group in project dhis2-core by dhis2.

the class FormUtils method fromProgram.

public static Form fromProgram(Program program) {
    Assert.notNull(program, "Program cannot be null");
    Form form = new Form();
    form.setLabel(program.getDisplayName());
    if (!StringUtils.isEmpty(program.getDescription())) {
        form.getOptions().put("description", program.getDescription());
    }
    if (!StringUtils.isEmpty(program.getEnrollmentDateLabel())) {
        form.getOptions().put("dateOfEnrollmentDescription", program.getEnrollmentDateLabel());
    }
    if (!StringUtils.isEmpty(program.getIncidentDateLabel())) {
        form.getOptions().put("dateOfIncidentDescription", program.getIncidentDateLabel());
    }
    form.getOptions().put("type", program.getProgramType().getValue());
    ProgramStage programStage = program.getProgramStageByStage(1);
    if (programStage == null) {
        if (program.isWithoutRegistration()) {
            throw new IllegalStateException("Program is without registration");
        } else {
            return form;
        }
    }
    form.getOptions().put("featureType", programStage.getFeatureType());
    if (programStage.getProgramStageSections().size() > 0) {
        for (ProgramStageSection section : programStage.getProgramStageSections()) {
            List<Field> fields = inputFromDataElements(section.getDataElements());
            Group group = new Group();
            group.setLabel(section.getDisplayName());
            group.setDataElementCount(section.getDataElements().size());
            group.setFields(fields);
            form.getGroups().add(group);
        }
    } else {
        List<Field> fields = inputFromProgramStageDataElements(new ArrayList<>(programStage.getProgramStageDataElements()));
        Group group = new Group();
        group.setLabel("default");
        group.setFields(fields);
        group.setDataElementCount(programStage.getProgramStageDataElements().size());
        form.getGroups().add(group);
    }
    return form;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Field(org.hisp.dhis.webapi.webdomain.form.Field) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 2 with Group

use of org.hisp.dhis.webapi.webdomain.form.Group in project dhis2-core by dhis2.

the class FormUtils method fromDataSet.

public static Form fromDataSet(DataSet dataSet, boolean metaData, Set<OrganisationUnit> userOrganisationUnits) {
    Form form = new Form();
    form.setLabel(dataSet.getDisplayName());
    form.setSubtitle(dataSet.getDisplayShortName());
    form.getOptions().put(KEY_PERIOD_TYPE, dataSet.getPeriodType().getName());
    form.getOptions().put(KEY_OPEN_FUTURE_PERIODS, dataSet.getOpenFuturePeriods());
    form.getOptions().put(KEY_OPEN_PERIODS_AFTER_CO_END_DATE, dataSet.getOpenPeriodsAfterCoEndDate());
    form.getOptions().put(KEY_EXPIRY_DAYS, dataSet.getExpiryDays());
    form.setCategoryCombo(getCategoryCombo(dataSet, userOrganisationUnits));
    if (dataSet.hasSections()) {
        List<Section> sections = new ArrayList<>(dataSet.getSections());
        Collections.sort(sections, SectionOrderComparator.INSTANCE);
        for (Section section : sections) {
            List<Field> fields = inputFromDataElements(new ArrayList<>(section.getDataElements()), new ArrayList<>(section.getGreyedFields()));
            Group group = new Group();
            group.setLabel(section.getDisplayName());
            group.setDescription(section.getDescription());
            group.setDataElementCount(section.getDataElements().size());
            group.setFields(fields);
            if (metaData) {
                group.getMetaData().put(KEY_DATA_ELEMENTS, NameableObjectUtils.getAsNameableObjects(section.getDataElements()));
                group.getMetaData().put(KEY_INDICATORS, NameableObjectUtils.getAsNameableObjects(section.getIndicators()));
            }
            form.getGroups().add(group);
        }
    } else {
        List<Field> fields = inputFromDataElements(new ArrayList<>(dataSet.getDataElements()));
        Group group = new Group();
        group.setLabel(org.hisp.dhis.category.CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
        group.setDescription(org.hisp.dhis.category.CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
        group.setDataElementCount(dataSet.getDataElements().size());
        group.setFields(fields);
        if (metaData) {
            group.getMetaData().put(KEY_DATA_ELEMENTS, NameableObjectUtils.getAsNameableObjects(new ArrayList<>(dataSet.getDataElements())));
        }
        form.getGroups().add(group);
    }
    return form;
}
Also used : Field(org.hisp.dhis.webapi.webdomain.form.Field) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) ArrayList(java.util.ArrayList) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Aggregations

ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 Field (org.hisp.dhis.webapi.webdomain.form.Field)2 Form (org.hisp.dhis.webapi.webdomain.form.Form)2 Group (org.hisp.dhis.webapi.webdomain.form.Group)2 ArrayList (java.util.ArrayList)1 Section (org.hisp.dhis.dataset.Section)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1