Search in sources :

Example 1 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement 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 ProgramStageDataElement

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

the class AddProgramStageAction 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 = new ProgramStage();
    Program program = programService.getProgram(id);
    programStage.setName(StringUtils.trimToNull(name));
    programStage.setDescription(StringUtils.trimToNull(description));
    programStage.setProgram(program);
    programStage.setStandardInterval(standardInterval);
    programStage.setExecutionDateLabel(StringUtils.trimToNull(excecutionDateLabel));
    programStage.setRepeatable(repeatable);
    programStage.setMinDaysFromStart(minDaysFromStart);
    programStage.setDisplayGenerateEventBox(displayGenerateEventBox);
    programStage.setValidCompleteOnly(validCompleteOnly);
    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 (program.isWithoutRegistration()) {
        programStage.setAutoGenerateEvent(true);
    } else {
        programStage.setAutoGenerateEvent(autoGenerateEvent);
    }
    programStage.setCaptureCoordinates(captureCoordinates);
    programStage.setBlockEntryForm(blockEntryForm);
    programStage.setRemindCompleted(remindCompleted);
    programStage.setGeneratedByEnrollmentDate(generatedByEnrollmentDate);
    programStage.setAllowGenerateNextVisit(allowGenerateNextVisit);
    programStage.setOpenAfterEnrollment(openAfterEnrollment);
    programStage.setReportDateToUse(reportDateToUse);
    programStage.setPreGenerateUID(preGenerateUID);
    programStage.setSortOrder(program.getProgramStages().size() + 1);
    programStage.setHideDueDate(hideDueDate);
    program.getProgramStages().add(programStage);
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(programStage, jsonAttributeValues);
    }
    programStageService.saveProgramStage(programStage);
    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);
        ProgramStageDataElement programStageDataElement = new ProgramStageDataElement(programStage, dataElement, this.compulsories.get(i), new Integer(i));
        programStageDataElement.setAllowProvidedElsewhere(allowed);
        programStageDataElement.setDisplayInReports(displayInReport);
        programStageDataElement.setAllowFutureDate(allowDate);
        programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    }
    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) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 3 with ProgramStageDataElement

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

the class ProgramSupplier method loadProgramStageDataElementSets.

/**
 * Loads all data elements for each program stage, partitioned into
 * compulsory and non-compulsory.
 */
private Map<Long, DataElementSets> loadProgramStageDataElementSets() {
    final String sql = "select psde.programstageid, de.dataelementid, de.uid as de_uid, de.code as de_code, psde.compulsory " + "from programstagedataelement psde " + "join dataelement de on psde.dataelementid = de.dataelementid " + "order by psde.programstageid";
    return jdbcTemplate.query(sql, (ResultSet rs) -> {
        Map<Long, DataElementSets> results = new HashMap<>();
        long programStageId = 0;
        while (rs.next()) {
            if (programStageId != rs.getLong(PROGRAM_STAGE_ID)) {
                DataElementSets dataElementSets = new DataElementSets();
                DataElement dataElement = toDataElement(rs);
                if (rs.getBoolean(COMPULSORY)) {
                    dataElementSets.getCompulsoryDataElements().add(dataElement);
                } else {
                    dataElementSets.getNonCompulsoryDataElements().add(dataElement);
                }
                results.put(rs.getLong(PROGRAM_STAGE_ID), dataElementSets);
                programStageId = rs.getLong(PROGRAM_STAGE_ID);
            } else {
                DataElementSets dataElementSets = results.get(rs.getLong(PROGRAM_STAGE_ID));
                DataElement dataElement = toDataElement(rs);
                if (rs.getBoolean(COMPULSORY)) {
                    dataElementSets.getCompulsoryDataElements().add(dataElement);
                } else {
                    dataElementSets.getNonCompulsoryDataElements().add(dataElement);
                }
            }
        }
        return results;
    });
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet)

Example 4 with ProgramStageDataElement

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

the class EnrollmentSecurityImportValidationTest method setupMetadata.

private void setupMetadata() {
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementB.setValueType(ValueType.INTEGER);
    manager.save(dataElementA);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageB = createProgramStage('B', 0);
    programStageB.setRepeatable(true);
    manager.save(programStageA);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    TrackedEntityType trackedEntityTypeFromProgram = createTrackedEntityType('C');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeFromProgram);
    manager.save(programA);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA.setProgram(programA);
    programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementB);
    programStageDataElement.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageB.getProgramStageDataElements().add(programStageDataElement);
    programStageB.setProgram(programA);
    programStageB.setMinDaysFromStart(2);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageB);
    manager.update(programA);
    maleA = createTrackedEntityInstance('A', organisationUnitA);
    maleB = createTrackedEntityInstance(organisationUnitB);
    femaleA = createTrackedEntityInstance(organisationUnitA);
    femaleB = createTrackedEntityInstance(organisationUnitB);
    maleA.setTrackedEntityType(trackedEntityType);
    maleB.setTrackedEntityType(trackedEntityType);
    femaleA.setTrackedEntityType(trackedEntityType);
    femaleB.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    manager.save(maleB);
    manager.save(femaleA);
    manager.save(femaleB);
    manager.flush();
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) HashSet(java.util.HashSet)

Example 5 with ProgramStageDataElement

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

the class ShowErrorWarningImplementerTest method setUpTest.

@BeforeEach
void setUpTest() {
    bundle = TrackerBundle.builder().build();
    bundle.setEvents(getEvents());
    bundle.setEnrollments(getEnrollments());
    bundle.setRuleEffects(getRuleEventAndEnrollmentEffects());
    bundle.setPreheat(preheat);
    programStage = createProgramStage('A', 0);
    programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    DataElement dataElementA = createDataElement('A');
    dataElementA.setUid(DATA_ELEMENT_ID);
    ProgramStageDataElement programStageDataElementA = createProgramStageDataElement(programStage, dataElementA, 0);
    programStage.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA));
    anotherProgramStage = createProgramStage('B', 0);
    anotherProgramStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    DataElement dataElementB = createDataElement('B');
    dataElementB.setUid(ANOTHER_DATA_ELEMENT_ID);
    ProgramStageDataElement programStageDataElementB = createProgramStageDataElement(anotherProgramStage, dataElementB, 0);
    anotherProgramStage.setProgramStageDataElements(Sets.newHashSet(programStageDataElementB));
    when(preheat.get(ProgramStage.class, PROGRAM_STAGE_ID)).thenReturn(programStage);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)43 DataElement (org.hisp.dhis.dataelement.DataElement)21 ProgramStage (org.hisp.dhis.program.ProgramStage)15 HashSet (java.util.HashSet)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)7 User (org.hisp.dhis.user.User)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Program (org.hisp.dhis.program.Program)6 Test (org.junit.jupiter.api.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 List (java.util.List)4 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)4 Event (org.hisp.dhis.tracker.domain.Event)4 HashMap (java.util.HashMap)3 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 PeriodType (org.hisp.dhis.period.PeriodType)3