Search in sources :

Example 1 with ProgramStageSection

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);
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) DataValue(org.hisp.dhis.api.mobile.model.DataValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 2 with ProgramStageSection

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;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Example 3 with ProgramStageSection

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;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Example 4 with ProgramStageSection

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;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Example 5 with ProgramStageSection

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();
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Option(org.hisp.dhis.option.Option) ProgramStage(org.hisp.dhis.program.ProgramStage) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)17 ProgramStage (org.hisp.dhis.program.ProgramStage)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 ArrayList (java.util.ArrayList)5 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)5 Program (org.hisp.dhis.program.Program)3 Test (org.junit.jupiter.api.Test)3 HashSet (java.util.HashSet)2 List (java.util.List)2 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 ProgramRule (org.hisp.dhis.programrule.ProgramRule)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 HashMap (java.util.HashMap)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