Search in sources :

Example 1 with DataEntryForm

use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.

the class ExpressionUpgrader method upgradeDataEntryForms.

private void upgradeDataEntryForms() {
    Collection<DataEntryForm> forms = dataEntryFormService.getAllDataEntryForms();
    for (DataEntryForm form : forms) {
        if (DataEntryForm.CURRENT_FORMAT > form.getFormat() && form.getHtmlCode() != null && !form.getHtmlCode().trim().isEmpty()) {
            try {
                // ---------------------------------------------------------
                // Identifiers
                // ---------------------------------------------------------
                Matcher matcher = IDENTIFIER_PATTERN.matcher(form.getHtmlCode());
                StringBuffer sb = new StringBuffer();
                while (matcher.find()) {
                    DataElement de = dataElementService.getDataElement(Integer.parseInt(matcher.group(1)));
                    DataElementCategoryOptionCombo coc = categoryService.getDataElementCategoryOptionCombo(Integer.parseInt(matcher.group(2)));
                    String replacement = "id=\"" + de.getUid() + "-" + coc.getUid() + "-val\"";
                    matcher.appendReplacement(sb, replacement);
                }
                matcher.appendTail(sb);
                form.setHtmlCode(sb.toString());
                // ---------------------------------------------------------
                // Data element totals
                // ---------------------------------------------------------
                matcher = DATAELEMENT_TOTAL_PATTERN.matcher(form.getHtmlCode());
                sb = new StringBuffer();
                while (matcher.find()) {
                    DataElement de = dataElementService.getDataElement(Integer.parseInt(matcher.group(1)));
                    String replacement = "dataelementid=\"" + de.getUid() + "\"";
                    matcher.appendReplacement(sb, replacement);
                }
                matcher.appendTail(sb);
                form.setHtmlCode(sb.toString());
                // ---------------------------------------------------------
                // Indicators
                // ---------------------------------------------------------
                matcher = INDICATOR_PATTERN.matcher(form.getHtmlCode());
                sb = new StringBuffer();
                while (matcher.find()) {
                    Indicator in = indicatorService.getIndicator(Integer.parseInt(matcher.group(1)));
                    String replacement = "indicatorid=\"" + in.getUid() + "\"";
                    matcher.appendReplacement(sb, replacement);
                }
                matcher.appendTail(sb);
                form.setHtmlCode(sb.toString());
                // ---------------------------------------------------------
                // Update format and save
                // ---------------------------------------------------------
                form.setFormat(DataEntryForm.CURRENT_FORMAT);
                dataEntryFormService.updateDataEntryForm(form);
                log.info("Upgraded custom data entry form: " + form.getName());
            } catch (Exception ex) {
                log.error("Upgrading custom data entry form failed: " + form.getName());
                // Log and continue
                log.error(ex);
            }
        }
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Matcher(java.util.regex.Matcher) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator)

Example 2 with DataEntryForm

use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.

the class ValidateDataEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    name = name.trim();
    DataEntryForm match = dataEntryFormService.getDataEntryFormByName(name);
    if (match != null && (dataEntryFormId == null || match.getId() != dataEntryFormId)) {
        message = i18n.getString("duplicate_names");
        return ERROR;
    }
    message = i18n.getString("everything_is_ok");
    return SUCCESS;
}
Also used : DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm)

Example 3 with DataEntryForm

use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.

the class RemoveDataEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryForm(id);
    Program program = programStageService.getProgramStage(programStageId).getProgram();
    programId = program.getId();
    Set<ProgramStage> programStages = program.getProgramStages();
    for (ProgramStage programStage : programStages) {
        DataEntryForm programEntryForm = programStage.getDataEntryForm();
        if (programEntryForm != null && programEntryForm.equals(dataEntryForm)) {
            programStage.setDataEntryForm(null);
            programStageService.updateProgramStage(programStage);
        }
    }
    program.increaseVersion();
    dataEntryFormService.deleteDataEntryForm(dataEntryForm);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 4 with DataEntryForm

use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.

the class RemoveProgramEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Program program = programService.getProgram(programId);
    program.setDataEntryForm(null);
    programService.updateProgram(program);
    DataEntryForm dataEntryForm = program.getDataEntryForm();
    dataEntryFormService.deleteDataEntryForm(dataEntryForm);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm)

Example 5 with DataEntryForm

use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.

the class SaveDataEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    Program program = programStage.getProgram();
    programId = program.getId();
    DataEntryForm dataEntryForm = null;
    if (dataEntryFormId == null) {
        dataEntryForm = programStage.getDataEntryForm();
    } else {
        dataEntryForm = dataEntryFormService.getDataEntryForm(dataEntryFormId);
    }
    if (dataEntryForm == null || !dataEntryForm.getHtmlCode().equals(designTextarea)) {
        program.increaseVersion();
    }
    designTextarea = dataEntryFormService.prepareDataEntryFormForSave(designTextarea);
    if (dataEntryForm == null) {
        program.increaseVersion();
        dataEntryForm = new DataEntryForm(StringUtils.trimToNull(name), designTextarea);
        dataEntryFormService.addDataEntryForm(dataEntryForm);
    } else {
        dataEntryForm.setName(StringUtils.trimToNull(name));
        dataEntryForm.setHtmlCode(designTextarea);
        dataEntryFormService.updateDataEntryForm(dataEntryForm);
    }
    programStage.setDataEntryForm(dataEntryForm);
    programStageService.updateProgramStage(programStage);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

DataEntryForm (org.hisp.dhis.dataentryform.DataEntryForm)16 Program (org.hisp.dhis.program.Program)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Test (org.junit.jupiter.api.Test)3 HashSet (java.util.HashSet)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 ProgramStage (org.hisp.dhis.program.ProgramStage)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 Action (com.opensymphony.xwork2.Action)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1