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;
}
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;
}
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;
}
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;
}
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>();
}
Aggregations