Search in sources :

Example 1 with FormType

use of org.hisp.dhis.dataset.FormType in project dhis2-core by dhis2.

the class DataSetReportController method getDataSetReport.

@RequestMapping(method = RequestMethod.GET)
public void getDataSetReport(HttpServletResponse response, @RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) Set<String> dimension, @RequestParam(required = false) boolean selectedUnitOnly, @RequestParam(required = false) String type) throws Exception {
    OrganisationUnit selectedOrgunit = idObjectManager.get(OrganisationUnit.class, ou);
    DataSet selectedDataSet = dataSetService.getDataSet(ds);
    Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
    if (selectedOrgunit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
    }
    if (selectedDataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
    }
    if (selectedPeriod == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
    }
    selectedPeriod = periodService.reloadPeriod(selectedPeriod);
    String customDataEntryFormCode = null;
    List<Grid> grids = new ArrayList<>();
    FormType formType = selectedDataSet.getFormType();
    // ---------------------------------------------------------------------
    // Configure response
    // ---------------------------------------------------------------------
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING);
    if (formType.isCustom()) {
        if (type != null) {
            grids = dataSetReportService.getCustomDataSetReportAsGrid(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, i18nManager.getI18nFormat());
        } else {
            customDataEntryFormCode = dataSetReportService.getCustomDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, i18nManager.getI18nFormat());
        }
    } else if (formType.isSection()) {
        grids = dataSetReportService.getSectionDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, i18nManager.getI18nFormat(), i18nManager.getI18n());
    } else {
        grids = dataSetReportService.getDefaultDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, i18nManager.getI18nFormat(), i18nManager.getI18n());
    }
    // ---------------------------------------------------------------------
    // Write response
    // ---------------------------------------------------------------------
    Writer output = response.getWriter();
    if (formType.isCustom() && type == null) {
        IOUtils.write(customDataEntryFormCode, output);
    } else {
        for (Grid grid : grids) {
            GridUtils.toHtmlCss(grid, output);
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) FormType(org.hisp.dhis.dataset.FormType) Period(org.hisp.dhis.period.Period) Writer(java.io.Writer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with FormType

use of org.hisp.dhis.dataset.FormType in project dhis2-core by dhis2.

the class LoadFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    dataSet = dataSetService.getDataSet(dataSetId);
    if (dataSet == null) {
        return INPUT;
    }
    FormType formType = dataSet.getFormType();
    if (formType.isCustom() && dataSet.hasDataEntryForm()) {
        dataEntryForm = dataSet.getDataEntryForm();
        customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
        return formType.toString();
    }
    // ---------------------------------------------------------------------
    // Section / default form
    // ---------------------------------------------------------------------
    List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
    if (dataElements.isEmpty()) {
        return INPUT;
    }
    Collections.sort(dataElements);
    orderedDataElements = ListMap.getListMap(dataElements, de -> de.getCategoryCombo(dataSet));
    orderedCategoryCombos = getDataElementCategoryCombos(dataElements, dataSet);
    for (DataElementCategoryCombo categoryCombo : orderedCategoryCombos) {
        List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
        orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
        // -----------------------------------------------------------------
        // Perform ordering of categories and their options so that they
        // could be displayed as in the paper form. Note that the total
        // number of entry cells to be generated are the multiple of options
        // from each category.
        // -----------------------------------------------------------------
        numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
        orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
        Map<Integer, List<DataElementCategoryOption>> optionsMap = new HashMap<>();
        for (DataElementCategory category : categoryCombo.getCategories()) {
            optionsMap.put(category.getId(), category.getCategoryOptions());
        }
        orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
        // -----------------------------------------------------------------
        // Calculating the number of times each category should be repeated
        // -----------------------------------------------------------------
        Map<Integer, Integer> catRepeat = new HashMap<>();
        Map<Integer, Collection<Integer>> colRepeat = new HashMap<>();
        int catColSpan = optionCombos.size();
        for (DataElementCategory cat : categoryCombo.getCategories()) {
            int categoryOptionSize = cat.getCategoryOptions().size();
            if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
                catColSpan = catColSpan / categoryOptionSize;
                int total = optionCombos.size() / (catColSpan * categoryOptionSize);
                Collection<Integer> cols = new ArrayList<>(total);
                for (int i = 0; i < total; i++) {
                    cols.add(i);
                }
                colRepeat.put(cat.getId(), cols);
                catRepeat.put(cat.getId(), catColSpan);
            }
        }
        catColRepeat.put(categoryCombo.getId(), colRepeat);
    }
    // ---------------------------------------------------------------------
    // Get data entry form
    // ---------------------------------------------------------------------
    DataSet dsOriginal = dataSet;
    if (dataSet.getFormType().isDefault()) {
        DataSet dataSetCopy = new DataSet();
        dataSetCopy.setUid(dataSet.getUid());
        dataSetCopy.setName(dataSet.getName());
        dataSetCopy.setShortName(dataSet.getShortName());
        dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
        dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
        dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
        dataSet = dataSetCopy;
        for (int i = 0; i < orderedCategoryCombos.size(); i++) {
            DataElementCategoryCombo categoryCombo = orderedCategoryCombos.get(i);
            String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
            Section section = new Section();
            section.setUid(CodeGenerator.generateUid());
            section.setId(i);
            section.setName(name);
            section.setSortOrder(i);
            section.setDataSet(dataSetCopy);
            dataSetCopy.getSections().add(section);
            section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
            section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
        }
        formType = FormType.SECTION;
    }
    if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
        List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
        for (OrganisationUnit child : organisationUnit.getChildren()) {
            if (child.getDataSets().contains(dsOriginal)) {
                organisationUnitChildren.add(child);
            }
        }
        Collections.sort(organisationUnitChildren);
        organisationUnits.addAll(organisationUnitChildren);
        getSectionForm(dataElements, dataSet);
        formType = FormType.SECTION_MULTIORG;
    }
    getSectionForm(dataElements, dataSet);
    return formType.toString();
}
Also used : ListMap(org.hisp.dhis.common.ListMap) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) DataSet(org.hisp.dhis.dataset.DataSet) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) I18n(org.hisp.dhis.i18n.I18n) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) HashSet(java.util.HashSet) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Map(java.util.Map) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) FormType(org.hisp.dhis.dataset.FormType) Collection(java.util.Collection) Set(java.util.Set) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategoryComboSizeComparator(org.hisp.dhis.dataelement.comparator.DataElementCategoryComboSizeComparator) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Section(org.hisp.dhis.dataset.Section) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Action(com.opensymphony.xwork2.Action) DataSetService(org.hisp.dhis.dataset.DataSetService) Collections(java.util.Collections) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) HashMap(java.util.HashMap) DataSet(org.hisp.dhis.dataset.DataSet) FormType(org.hisp.dhis.dataset.FormType) ArrayList(java.util.ArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 3 with FormType

use of org.hisp.dhis.dataset.FormType in project dhis2-core by dhis2.

the class GenerateDataSetReportAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Configure response
    // ---------------------------------------------------------------------
    HttpServletResponse response = ServletActionContext.getResponse();
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, null, false);
    // ---------------------------------------------------------------------
    // Assemble report
    // ---------------------------------------------------------------------
    selectedDataSet = dataSetService.getDataSetNoAcl(ds);
    if (pe != null) {
        selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
        selectedPeriod = periodService.reloadPeriod(selectedPeriod);
    }
    selectedOrgunit = organisationUnitService.getOrganisationUnit(ou);
    FormType formType = selectedDataSet.getFormType();
    DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    registration = registrationService.getCompleteDataSetRegistration(selectedDataSet, selectedPeriod, selectedOrgunit, attributeOptionCombo);
    if (formType.isCustom()) {
        if (type != null) {
            grids = dataSetReportService.getCustomDataSetReportAsGrid(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, format);
        } else {
            customDataEntryFormCode = dataSetReportService.getCustomDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, format);
        }
    } else if (formType.isSection()) {
        grids = dataSetReportService.getSectionDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, format, i18n);
    } else {
        grids = dataSetReportService.getDefaultDataSetReport(selectedDataSet, selectedPeriod, selectedOrgunit, dimension, selectedUnitOnly, format, i18n);
    }
    return type != null ? type : formType.toString();
}
Also used : FormType(org.hisp.dhis.dataset.FormType) HttpServletResponse(javax.servlet.http.HttpServletResponse) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

FormType (org.hisp.dhis.dataset.FormType)3 ArrayList (java.util.ArrayList)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DataSet (org.hisp.dhis.dataset.DataSet)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Action (com.opensymphony.xwork2.Action)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CodeGenerator (org.hisp.dhis.common.CodeGenerator)1 Grid (org.hisp.dhis.common.Grid)1 ListMap (org.hisp.dhis.common.ListMap)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)1