Search in sources :

Example 6 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class AddProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    // ---------------------------------------------------------------------
    // Section
    // ---------------------------------------------------------------------
    List<DataElement> dataElements = new ArrayList<>();
    for (Integer id : dataElementIds) {
        dataElements.add(dataElementService.getDataElement(id));
    }
    ProgramStageSection programStageSection = new ProgramStageSection(StringUtils.trimToNull(name), dataElements, programStage.getProgramStageSections().size());
    programStageSection.setAutoFields();
    // ---------------------------------------------------------------------
    // Program indicators
    // ---------------------------------------------------------------------
    List<ProgramIndicator> programIndicators = new ArrayList<>();
    for (Integer id : selectedIndicators) {
        ProgramIndicator indicator = programIndicatorService.getProgramIndicator(id);
        programIndicators.add(indicator);
    }
    programStageSection.setProgramIndicators(programIndicators);
    programStageSection.setProgramStage(programStage);
    // ---------------------------------------------------------------------
    // Update program stage
    // ---------------------------------------------------------------------
    Set<ProgramStageSection> sections = programStage.getProgramStageSections();
    sections.add(programStageSection);
    programStage.setProgramStageSections(sections);
    programStageService.updateProgramStage(programStage);
    return SUCCESS;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 7 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class UpdateProgramStageAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    minDaysFromStart = (minDaysFromStart == null) ? 0 : minDaysFromStart;
    repeatable = (repeatable == null) ? false : repeatable;
    autoGenerateEvent = (autoGenerateEvent == null) ? false : autoGenerateEvent;
    validCompleteOnly = (validCompleteOnly == null) ? false : validCompleteOnly;
    displayGenerateEventBox = (displayGenerateEventBox == null) ? false : displayGenerateEventBox;
    captureCoordinates = (captureCoordinates == null) ? false : captureCoordinates;
    relatedEntityInstance = (relatedEntityInstance == null) ? false : relatedEntityInstance;
    generatedByEnrollmentDate = (generatedByEnrollmentDate == null) ? false : generatedByEnrollmentDate;
    blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
    remindCompleted = (remindCompleted == null) ? false : remindCompleted;
    allowGenerateNextVisit = (allowGenerateNextVisit == null) ? false : allowGenerateNextVisit;
    openAfterEnrollment = (openAfterEnrollment == null) ? false : openAfterEnrollment;
    preGenerateUID = (preGenerateUID == null) ? false : preGenerateUID;
    hideDueDate = (hideDueDate == null) ? false : hideDueDate;
    ProgramStage programStage = programStageService.getProgramStage(id);
    programStage.setName(StringUtils.trimToNull(name));
    programStage.setDescription(StringUtils.trimToNull(description));
    programStage.setStandardInterval(standardInterval);
    programStage.setExecutionDateLabel(StringUtils.trimToNull(excecutionDateLabel));
    programStage.setMinDaysFromStart(minDaysFromStart);
    programStage.setRepeatable(repeatable);
    programStage.setMinDaysFromStart(minDaysFromStart);
    programStage.setDisplayGenerateEventBox(displayGenerateEventBox);
    programStage.setBlockEntryForm(blockEntryForm);
    programStage.setRemindCompleted(remindCompleted);
    programStage.setGeneratedByEnrollmentDate(generatedByEnrollmentDate);
    programStage.setAllowGenerateNextVisit(allowGenerateNextVisit);
    programStage.setOpenAfterEnrollment(openAfterEnrollment);
    programStage.setReportDateToUse(reportDateToUse);
    programStage.setPreGenerateUID(preGenerateUID);
    programStage.setHideDueDate(hideDueDate);
    if (!hideDueDate) {
        programStage.setDueDateLabel(StringUtils.trimToNull(dueDateLabel));
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        programStage.setPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        programStage.setPeriodType(null);
    }
    if (programStage.getProgram().isWithoutRegistration()) {
        programStage.setAutoGenerateEvent(true);
    } else {
        programStage.setAutoGenerateEvent(autoGenerateEvent);
    }
    programStage.setValidCompleteOnly(validCompleteOnly);
    programStage.setCaptureCoordinates(captureCoordinates);
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(programStage, jsonAttributeValues);
    }
    Set<ProgramStageDataElement> programStageDataElements = new HashSet<>(programStage.getProgramStageDataElements());
    for (int i = 0; i < this.selectedDataElementsValidator.size(); i++) {
        DataElement dataElement = dataElementService.getDataElement(selectedDataElementsValidator.get(i));
        Boolean allowed = allowProvidedElsewhere.get(i) == null ? false : allowProvidedElsewhere.get(i);
        Boolean displayInReport = displayInReports.get(i) == null ? false : displayInReports.get(i);
        Boolean allowDate = allowFutureDates.get(i) == null ? false : allowFutureDates.get(i);
        Boolean renderAsRadio = renderOptionsAsRadios.get(i) == null ? false : renderOptionsAsRadios.get(i);
        ProgramStageDataElement programStageDataElement = programStageDataElementService.get(programStage, dataElement);
        if (programStageDataElement == null) {
            programStageDataElement = new ProgramStageDataElement(programStage, dataElement, this.compulsories.get(i), i);
            programStageDataElement.setAllowProvidedElsewhere(allowed);
            programStageDataElement.setDisplayInReports(displayInReport);
            programStageDataElement.setAllowFutureDate(allowDate);
            programStageDataElementService.addProgramStageDataElement(programStageDataElement);
            programStageDataElement.setRenderOptionsAsRadio(renderAsRadio);
        } else {
            programStageDataElement.setCompulsory(this.compulsories.get(i));
            programStageDataElement.setSortOrder(i);
            programStageDataElement.setAllowProvidedElsewhere(allowed);
            programStageDataElement.setDisplayInReports(displayInReport);
            programStageDataElement.setAllowFutureDate(allowDate);
            programStageDataElementService.updateProgramStageDataElement(programStageDataElement);
            programStageDataElements.remove(programStageDataElement);
            programStageDataElement.setRenderOptionsAsRadio(renderAsRadio);
        }
    }
    for (ProgramStageSection section : programStage.getProgramStageSections()) {
        for (ProgramStageDataElement element : programStageDataElements) {
            section.getDataElements().remove(element.getDataElement());
        }
        programStageSectionService.updateProgramStageSection(section);
    }
    for (ProgramStageDataElement psdeDelete : programStageDataElements) {
        programStage.getProgramStageDataElements().remove(psdeDelete);
        programStageDataElementService.deleteProgramStageDataElement(psdeDelete);
    }
    programStageService.updateProgramStage(programStage);
    programId = programStage.getProgram().getId();
    return SUCCESS;
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) PeriodType(org.hisp.dhis.period.PeriodType) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ProgramStage(org.hisp.dhis.program.ProgramStage) HashSet(java.util.HashSet)

Example 8 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class RemoveProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStageSection section = programStageSectionService.getProgramStageSection(id);
    programStageSectionService.deleteProgramStageSection(section);
    return SUCCESS;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Example 9 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class UpdateProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Section
    // ---------------------------------------------------------------------
    ProgramStageSection section = programStageSectionService.getProgramStageSection(id);
    section.setName(StringUtils.trimToNull(name));
    List<DataElement> dataElements = new ArrayList<>();
    for (Integer id : dataElementIds) {
        dataElements.add(dataElementService.getDataElement(id));
    }
    section.setDataElements(dataElements);
    // ---------------------------------------------------------------------
    // Program indicators
    // ---------------------------------------------------------------------
    List<ProgramIndicator> programIndicators = new ArrayList<>();
    for (Integer id : selectedIndicators) {
        ProgramIndicator indicator = programIndicatorService.getProgramIndicator(id);
        programIndicators.add(indicator);
    }
    section.setProgramIndicators(programIndicators);
    programStageSectionService.updateProgramStageSection(section);
    return SUCCESS;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 10 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection 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)

Aggregations

ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)13 DataElement (org.hisp.dhis.dataelement.DataElement)6 ArrayList (java.util.ArrayList)5 ProgramStage (org.hisp.dhis.program.ProgramStage)5 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)5 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DataValue (org.hisp.dhis.api.mobile.model.DataValue)1 Program (org.hisp.dhis.api.mobile.model.Program)1 ProgramStage (org.hisp.dhis.api.mobile.model.ProgramStage)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataSet (org.hisp.dhis.dataset.DataSet)1 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 PeriodType (org.hisp.dhis.period.PeriodType)1 Program (org.hisp.dhis.program.Program)1