use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method saveActivityReport.
// -------------------------------------------------------------------------
// DataValueService
// -------------------------------------------------------------------------
@Override
public void saveActivityReport(OrganisationUnit unit, ActivityValue activityValue, Integer programStageSectionId) throws NotAllowedException {
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(activityValue.getProgramInstanceId());
if (programStageInstance == null) {
throw NotAllowedException.INVALID_PROGRAM_STAGE;
}
programStageInstance.getProgramStage();
List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<>();
ProgramStageSection programStageSection = programStageSectionService.getProgramStageSection(programStageSectionId);
if (programStageSectionId != 0) {
dataElements.addAll(programStageSection.getDataElements());
} else {
for (ProgramStageDataElement de : programStageInstance.getProgramStage().getProgramStageDataElements()) {
dataElements.add(de.getDataElement());
}
}
programStageInstance.getProgramStage().getProgramStageDataElements();
Collection<Integer> dataElementIds = new ArrayList<>(activityValue.getDataValues().size());
for (DataValue dv : activityValue.getDataValues()) {
dataElementIds.add(dv.getId());
}
if (dataElements.size() != dataElementIds.size()) {
throw NotAllowedException.INVALID_PROGRAM_STAGE;
}
Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<>();
for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) {
if (!dataElementIds.contains(dataElement.getId())) {
throw NotAllowedException.INVALID_PROGRAM_STAGE;
}
dataElementMap.put(dataElement.getId(), dataElement);
}
// Set ProgramStageInstance to completed
if (programStageSectionId == 0) {
programStageInstance.setStatus(EventStatus.COMPLETED);
programStageInstanceService.updateProgramStageInstance(programStageInstance);
}
// Everything is fine, hence save
saveDataValues(activityValue, programStageInstance, dataElementMap);
}
use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.
the class GetProgramStageSectionAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
section = programStageSectionService.getProgramStageSection(id);
programStage = programStageService.getProgramStage(programStageId);
if (programStage != null && programStage.getProgram() != null) {
availableDataElements = new ArrayList<>(programStage.getAllDataElements());
availableProgramIndicators = new ArrayList<>(programStage.getProgram().getProgramIndicators());
availableProgramIndicators.removeAll(section.getProgramIndicators());
for (ProgramStageSection section : programStage.getProgramStageSections()) {
availableDataElements.removeAll(section.getDataElements());
}
Collections.sort(availableDataElements);
Collections.sort(availableProgramIndicators);
}
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.
the class ShowAddProgramStageSectionAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
programStage = programStageService.getProgramStage(programStageId);
if (programStage != null && programStage.getProgram() != null) {
availableDataElements = new ArrayList<>(programStage.getAllDataElements());
availableProgramIndicators = new ArrayList<>(programStage.getProgram().getProgramIndicators());
for (ProgramStageSection section : programStage.getProgramStageSections()) {
availableDataElements.removeAll(section.getDataElements());
}
Collections.sort(availableDataElements);
Collections.sort(availableProgramIndicators);
}
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.
the class SaveProgramStageSectionSortOrderAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
int index = 0;
for (Integer sectionId : sectionIds) {
ProgramStageSection section = programStageSectionService.getProgramStageSection(sectionId);
section.setSortOrder(index++);
programStageSectionService.updateProgramStageSection(section);
}
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.
the class ProgramRuleActionValidationContextLoader method load.
@Transactional(readOnly = true)
public ProgramRuleActionValidationContext load(Preheat preheat, PreheatIdentifier preheatIdentifier, ProgramRuleAction ruleAction) {
ProgramRule rule = preheat.get(preheatIdentifier, ProgramRule.class, ruleAction.getProgramRule());
Program program = preheat.get(preheatIdentifier, Program.class, rule.getProgram());
List<ProgramStage> stages = preheat.getAll(preheatIdentifier, new ArrayList<>(program.getProgramStages()));
return ProgramRuleActionValidationContext.builder().programRule(rule).program(program).programStages(stages).dataElement(ruleAction.hasDataElement() ? preheat.get(preheatIdentifier, DataElement.class, ruleAction.getDataElement()) : null).trackedEntityAttribute(ruleAction.hasTrackedEntityAttribute() ? preheat.get(preheatIdentifier, TrackedEntityAttribute.class, ruleAction.getAttribute()) : null).notificationTemplate(ruleAction.hasNotification() ? preheat.get(preheatIdentifier, ProgramNotificationTemplate.class, ruleAction.getTemplateUid()) : null).programStageSection(ruleAction.hasProgramStageSection() ? preheat.get(preheatIdentifier, ProgramStageSection.class, ruleAction.getProgramStageSection()) : null).programStage(ruleAction.hasProgramStage() ? preheat.get(preheatIdentifier, ProgramStage.class, ruleAction.getProgramStage()) : null).option(ruleAction.hasOption() ? preheat.get(preheatIdentifier, Option.class, ruleAction.getOption()) : null).optionGroup(ruleAction.hasOptionGroup() ? preheat.get(preheatIdentifier, OptionGroup.class, ruleAction.getOptionGroup()) : null).programRuleActionValidationService(validationService).build();
}
Aggregations