Search in sources :

Example 16 with PeriodType

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;
}
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 17 with PeriodType

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;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Period(org.hisp.dhis.period.Period) Date(java.util.Date)

Example 18 with PeriodType

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())));
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 19 with PeriodType

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());
}
Also used : java.util(java.util) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataSet(org.hisp.dhis.dataset.DataSet) PeriodService(org.hisp.dhis.period.PeriodService) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) StringUtils(org.apache.commons.lang3.StringUtils) Program(org.hisp.dhis.program.Program) DataElement(org.hisp.dhis.dataelement.DataElement) ExpressionService(org.hisp.dhis.expression.ExpressionService) Lists(com.google.common.collect.Lists) DataValueService(org.hisp.dhis.datavalue.DataValueService) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) I18nFormat(org.hisp.dhis.i18n.I18nFormat) COMPOSITE_DIM_OBJECT_ESCAPED_SEP(org.hisp.dhis.common.DimensionalObjectUtils.COMPOSITE_DIM_OBJECT_ESCAPED_SEP) User(org.hisp.dhis.user.User) DataElementCategoryService(org.hisp.dhis.dataelement.DataElementCategoryService) TextUtils.splitSafe(org.hisp.dhis.commons.util.TextUtils.splitSafe) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) Period(org.hisp.dhis.period.Period) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ImmutableSet(com.google.common.collect.ImmutableSet) ValidationNotificationService(org.hisp.dhis.validation.notification.ValidationNotificationService) DimensionItemType(org.hisp.dhis.common.DimensionItemType) ConstantService(org.hisp.dhis.constant.ConstantService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SetMap(org.hisp.dhis.common.SetMap) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Clock(org.hisp.dhis.system.util.Clock) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) CurrentUserService(org.hisp.dhis.user.CurrentUserService) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) SettingKey(org.hisp.dhis.setting.SettingKey) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) MapMap(org.hisp.dhis.common.MapMap) Transactional(org.springframework.transaction.annotation.Transactional) Period(org.hisp.dhis.period.Period)

Example 20 with PeriodType

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;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) User(org.hisp.dhis.user.User) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)67 Period (org.hisp.dhis.period.Period)21 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)13 ArrayList (java.util.ArrayList)12 DataSet (org.hisp.dhis.dataset.DataSet)12 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)6 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)6 ProgramStage (org.hisp.dhis.program.ProgramStage)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4