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