use of org.hisp.dhis.period.PeriodType 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.period.PeriodType in project dhis2-core by dhis2.
the class DataValueSMSListener method getPeriod.
private Period getPeriod(SMSCommand command, Date date) {
Period period = null;
period = command.getDataset().getPeriodType().createPeriod();
PeriodType periodType = period.getPeriodType();
if (command.isCurrentPeriodUsedForReporting()) {
period = periodType.createPeriod(new Date());
} else {
period = periodType.getPreviousPeriod(period);
}
if (date != null) {
period = periodType.createPeriod(date);
}
return period;
}
use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validateHasMatchingPeriodTypes.
private static void validateHasMatchingPeriodTypes(MetaDataProperties props) throws ImportConflictException {
// TODO MdCache?
PeriodType dsPeType = props.dataSet.getPeriodType();
PeriodType peType = props.period.getPeriodType();
if (!dsPeType.equals(peType)) {
throw new ImportConflictException(new ImportConflict(props.period.getUid(), String.format("Period type of period: %s is not equal to the period type of data set: %s", props.period.getIsoDate(), props.dataSet.getPeriodType())));
}
}
use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.
the class DefaultValidationService method extractNotificationPeriods.
/**
* Get the current and most recent periods to use when performing validation
* for generating notifications (previously 'alerts'). The periods are
* filtered against existing (persisted) periods.
* <p>
* TODO Consider:
* This method assumes that the last successful validation run was one day ago.
* If this is not the case (more than one day ago) adding additional (daily)
* periods to 'fill the gap' could be considered.
*/
private Set<Period> extractNotificationPeriods(Set<ValidationRule> rules) {
return rules.stream().map(rule -> periodService.getPeriodTypeByName(rule.getPeriodType().getName())).map(periodType -> {
Period current = periodType.createPeriod(), previous = periodType.getPreviousPeriod(current);
Date start = previous.getStartDate(), end = current.getEndDate();
return periodService.getIntersectingPeriodsByPeriodType(periodType, start, end);
}).flatMap(Collection::stream).collect(Collectors.toSet());
}
use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.
the class DefaultValidationService method getValidationContext.
/**
* Returns a new Builder with basic configuration based on the input parameters.
*
* @param orgUnits organisation units to include in analysis.
* @param periods periods to include in analysis.
* @param validationRules rules to include in analysis.
* @return Builder with basic configuration based on input.
*/
private ValidationRunContext.Builder getValidationContext(List<OrganisationUnit> orgUnits, Collection<Period> periods, Collection<ValidationRule> validationRules) {
User currentUser = currentUserService.getCurrentUser();
Map<PeriodType, PeriodTypeExtended> periodTypeExtendedMap = new HashMap<>();
addPeriodsToContext(periodTypeExtendedMap, periods);
Map<String, DimensionalItemObject> dimensionItemMap = addRulesToContext(periodTypeExtendedMap, validationRules);
removeAnyUnneededPeriodTypes(periodTypeExtendedMap);
addOrgUnitsToContext(periodTypeExtendedMap, orgUnits);
ValidationRunContext.Builder builder = ValidationRunContext.newBuilder().withPeriodTypeExtendedMap(periodTypeExtendedMap).withOrgUnits(orgUnits).withEventItems(getEventItems(dimensionItemMap)).withConstantMap(constantService.getConstantMap());
if (currentUser != null) {
builder.withCoDimensionConstraints(categoryService.getCoDimensionConstraints(currentUser.getUserCredentials())).withCogDimensionConstraints(categoryService.getCogDimensionConstraints(currentUser.getUserCredentials()));
}
return builder;
}
Aggregations