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