Search in sources :

Example 26 with ProgramStage

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

the class SortProgramStagesAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    int index = 1;
    for (Integer id : programStageIds) {
        ProgramStage programStage = programStageService.getProgramStage(id);
        programStage.setSortOrder(index);
        programStageService.updateProgramStage(programStage);
        index++;
    }
    return SUCCESS;
}
Also used : ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 27 with ProgramStage

use of org.hisp.dhis.program.ProgramStage 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 28 with ProgramStage

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

the class RemoveProgramStageAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    try {
        ProgramStage programStage = programStageService.getProgramStage(id);
        Program program = programStage.getProgram();
        program.getProgramStages().remove(programStage);
        programStageService.deleteProgramStage(programStage);
    } catch (DeleteNotAllowedException ex) {
        if (ex.getErrorCode().equals(DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS)) {
            message = i18n.getString("object_not_deleted_associated_by_objects") + " " + ex.getMessage();
            return ERROR;
        }
    }
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DeleteNotAllowedException(org.hisp.dhis.common.DeleteNotAllowedException) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 29 with ProgramStage

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

the class GetSelectedDataElementsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(associationId);
    dataElementList = new ArrayList<>(programStage.getAllDataElements());
    Collections.sort(dataElementList);
    return SUCCESS;
}
Also used : ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 30 with ProgramStage

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

the class SMSCommandAction method getProgramStageDataElementList.

public Collection<ProgramStageDataElement> getProgramStageDataElementList() {
    if (smsCommand != null) {
        Program program = smsCommand.getProgram();
        ProgramStage programStage = program.getProgramStages().iterator().next();
        if (programStage != null) {
            programStageDataElementList = programStage.getProgramStageDataElements();
        }
        return programStageDataElementList;
    }
    return new ArrayList<ProgramStageDataElement>();
}
Also used : Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)40 Program (org.hisp.dhis.program.Program)24 DataElement (org.hisp.dhis.dataelement.DataElement)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)10 ArrayList (java.util.ArrayList)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 PeriodType (org.hisp.dhis.period.PeriodType)6 Date (java.util.Date)5 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)5 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)5 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3