Search in sources :

Example 1 with Field

use of org.hisp.dhis.webapi.webdomain.form.Field 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_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(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
        group.setDescription(DataElementCategoryCombo.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)

Example 2 with Field

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

the class FormUtils method inputFromDataElements.

private static List<Field> inputFromDataElements(List<DataElement> dataElements, final List<DataElementOperand> greyedFields) {
    List<Field> fields = new ArrayList<>();
    for (DataElement dataElement : dataElements) {
        for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
            if (!isDisabled(dataElement, categoryOptionCombo, greyedFields)) {
                Field field = new Field();
                if (categoryOptionCombo.isDefault()) {
                    field.setLabel(dataElement.getDisplayFormName());
                } else {
                    field.setLabel(dataElement.getDisplayFormName() + " " + categoryOptionCombo.getDisplayName());
                }
                field.setDataElement(dataElement.getUid());
                field.setCategoryOptionCombo(categoryOptionCombo.getUid());
                field.setType(inputTypeFromDataElement(dataElement));
                if (dataElement.getOptionSet() != null) {
                    field.setOptionSet(dataElement.getOptionSet().getUid());
                }
                fields.add(field);
            }
        }
    }
    return fields;
}
Also used : Field(org.hisp.dhis.webapi.webdomain.form.Field) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 3 with Field

use of org.hisp.dhis.webapi.webdomain.form.Field 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("captureCoordinates", programStage.getCaptureCoordinates());
    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 4 with Field

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

the class FormUtils method fillWithDataValues.

public static void fillWithDataValues(Form form, Collection<DataValue> dataValues) {
    Map<String, Field> operandFieldMap = buildCacheMap(form);
    for (DataValue dataValue : dataValues) {
        DataElement dataElement = dataValue.getDataElement();
        DataElementCategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
        Field field = operandFieldMap.get(dataElement.getUid() + SEP + categoryOptionCombo.getUid());
        if (field != null) {
            field.setValue(dataValue.getValue());
            field.setComment(dataValue.getComment());
        }
    }
}
Also used : Field(org.hisp.dhis.webapi.webdomain.form.Field) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.datavalue.DataValue) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

Field (org.hisp.dhis.webapi.webdomain.form.Field)4 ArrayList (java.util.ArrayList)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)2 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 Form (org.hisp.dhis.webapi.webdomain.form.Form)2 Group (org.hisp.dhis.webapi.webdomain.form.Group)2 Section (org.hisp.dhis.dataset.Section)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1