Search in sources :

Example 6 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DefaultPredictorService method getSamplePeriodsMap.

/**
     * Creates a map relating each output period to a list of sample periods
     * from which the sample data is to be drawn.
     *
     * @param outputPeriods the output periods
     * @param predictor the predictor
     * @return map from output periods to sample periods
     */
private ListMap<Period, Period> getSamplePeriodsMap(List<Period> outputPeriods, Predictor predictor) {
    int sequentialCount = predictor.getSequentialSampleCount();
    int annualCount = predictor.getAnnualSampleCount();
    int skipCount = firstNonNull(predictor.getSequentialSkipCount(), 0);
    PeriodType periodType = predictor.getPeriodType();
    ListMap<Period, Period> samplePeriodsMap = new ListMap<Period, Period>();
    for (Period outputPeriod : outputPeriods) {
        samplePeriodsMap.put(outputPeriod, new ArrayList<Period>());
        Period p = periodType.getPreviousPeriod(outputPeriod, skipCount);
        for (int i = skipCount; i < sequentialCount; i++) {
            p = periodType.getPreviousPeriod(p);
            addPeriod(samplePeriodsMap, outputPeriod, p);
        }
        for (int year = 1; year <= annualCount; year++) {
            Period pPrev = periodType.getPreviousYearsPeriod(outputPeriod, year);
            Period pNext = pPrev;
            addPeriod(samplePeriodsMap, outputPeriod, pPrev);
            for (int i = 0; i < sequentialCount; i++) {
                pPrev = periodType.getPreviousPeriod(pPrev);
                pNext = periodType.getNextPeriod(pNext);
                addPeriod(samplePeriodsMap, outputPeriod, pPrev);
                addPeriod(samplePeriodsMap, outputPeriod, pNext);
            }
        }
    }
    return samplePeriodsMap;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Period(org.hisp.dhis.period.Period) ListMap(org.hisp.dhis.common.ListMap)

Example 7 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 8 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DefaultFieldFilterService method buildNode.

private AbstractNode buildNode(FieldMap fieldMap, Class<?> klass, Object object, String nodeName) {
    Schema schema = schemaService.getDynamicSchema(klass);
    ComplexNode complexNode = new ComplexNode(nodeName);
    complexNode.setNamespace(schema.getNamespace());
    if (object == null) {
        return new SimpleNode(schema.getName(), null);
    }
    updateFields(fieldMap, schema.getKlass());
    for (String fieldKey : fieldMap.keySet()) {
        AbstractNode child;
        Property property = schema.getProperty(fieldKey);
        if (property == null || !property.isReadable()) {
            // throw new FieldFilterException( fieldKey, schema );
            log.debug("Unknown field property `" + fieldKey + "`, available fields are " + schema.getPropertyMap().keySet());
            continue;
        }
        Object returnValue = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
        Schema propertySchema = schemaService.getDynamicSchema(property.getKlass());
        FieldMap fieldValue = fieldMap.get(fieldKey);
        if (returnValue == null && property.isCollection()) {
            continue;
        }
        if (property.isCollection()) {
            updateFields(fieldValue, property.getItemKlass());
        } else {
            updateFields(fieldValue, property.getKlass());
        }
        if (fieldValue.isEmpty()) {
            List<String> fields = Preset.defaultAssociationPreset().getFields();
            if (property.isCollection()) {
                Collection<?> collection = (Collection<?>) returnValue;
                child = new CollectionNode(property.getCollectionName());
                child.setNamespace(property.getNamespace());
                if (property.isIdentifiableObject() && isProperIdObject(property.getItemKlass())) {
                    for (Object collectionObject : collection) {
                        child.addChild(getProperties(property, collectionObject, fields));
                    }
                } else if (!property.isSimple()) {
                    FieldMap map = getFullFieldMap(schemaService.getDynamicSchema(property.getItemKlass()));
                    for (Object collectionObject : collection) {
                        Node node = buildNode(map, property.getItemKlass(), collectionObject);
                        if (!node.getChildren().isEmpty()) {
                            child.addChild(node);
                        }
                    }
                } else {
                    if (collection != null) {
                        for (Object collectionObject : collection) {
                            SimpleNode simpleNode = child.addChild(new SimpleNode(property.getName(), collectionObject));
                            simpleNode.setProperty(property);
                        }
                    }
                }
            } else if (property.isIdentifiableObject() && isProperIdObject(property.getKlass())) {
                child = getProperties(property, returnValue, fields);
            } else {
                if (propertySchema.getProperties().isEmpty()) {
                    SimpleNode simpleNode = new SimpleNode(fieldKey, returnValue);
                    simpleNode.setAttribute(property.isAttribute());
                    simpleNode.setNamespace(property.getNamespace());
                    child = simpleNode;
                } else {
                    child = buildNode(getFullFieldMap(propertySchema), property.getKlass(), returnValue);
                }
            }
        } else {
            if (property.isCollection()) {
                child = new CollectionNode(property.getCollectionName());
                child.setNamespace(property.getNamespace());
                for (Object collectionObject : (Collection<?>) returnValue) {
                    Node node = buildNode(fieldValue, property.getItemKlass(), collectionObject, property.getName());
                    if (!node.getChildren().isEmpty()) {
                        child.addChild(node);
                    }
                }
            } else {
                child = buildNode(fieldValue, property.getKlass(), returnValue);
            }
        }
        if (child != null) {
            child.setName(fieldKey);
            child.setProperty(property);
            // TODO fix ugly hack, will be replaced by custom field serializer/deserializer
            if (child.isSimple() && PeriodType.class.isInstance((((SimpleNode) child).getValue()))) {
                child = new SimpleNode(child.getName(), ((PeriodType) ((SimpleNode) child).getValue()).getName());
            }
            complexNode.addChild(fieldValue.getPipeline().process(child));
        }
    }
    return complexNode;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) AbstractNode(org.hisp.dhis.node.AbstractNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) Schema(org.hisp.dhis.schema.Schema) CollectionNode(org.hisp.dhis.node.types.CollectionNode) AbstractNode(org.hisp.dhis.node.AbstractNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Collection(java.util.Collection) EmbeddedObject(org.hisp.dhis.common.EmbeddedObject) Property(org.hisp.dhis.schema.Property)

Example 9 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalAuditStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    level1 = new DataApprovalLevel("01", 1, null);
    level2 = new DataApprovalLevel("02", 2, null);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
    workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2));
    dataApprovalService.addWorkflow(workflowA);
    dataApprovalService.addWorkflow(workflowB);
    periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
    periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    userA = createUser('A');
    userService.addUser(userA);
    optionA = new DataElementCategoryOption("CategoryOptionA");
    optionB = new DataElementCategoryOption("CategoryOptionB");
    categoryService.addDataElementCategoryOption(optionA);
    categoryService.addDataElementCategoryOption(optionB);
    categoryA = createDataElementCategory('A', optionA, optionB);
    categoryService.addDataElementCategory(categoryA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addDataElementCategoryCombo(categoryComboA);
    optionComboA = createCategoryOptionCombo('A', categoryComboA, optionA);
    optionComboB = createCategoryOptionCombo('B', categoryComboA, optionA, optionB);
    categoryService.addDataElementCategoryOptionCombo(optionComboA);
    categoryService.addDataElementCategoryOptionCombo(optionComboB);
    dateA = getDate(2017, 1, 1);
    dateB = getDate(2018, 1, 1);
    DataApproval approvalA = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userA);
    DataApproval approvalB = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userA);
    auditA = new DataApprovalAudit(approvalA, APPROVE);
    auditB = new DataApprovalAudit(approvalB, UNAPPROVE);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption)

Example 10 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getMobileDataSetsForUnit.

// -------------------------------------------------------------------------
// Service methods
// -------------------------------------------------------------------------
@Override
public List<DataSet> getMobileDataSetsForUnit(OrganisationUnit unit, String localeString) {
    List<DataSet> datasets = new ArrayList<>();
    Locale locale = LocaleUtil.getLocale(localeString);
    if (DEBUG)
        log.debug("Getting data sets for unit " + unit.getName());
    for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile(unit)) {
        PeriodType periodType = dataSet.getPeriodType();
        if (periodType instanceof DailyPeriodType || periodType instanceof WeeklyPeriodType || periodType instanceof MonthlyPeriodType || periodType instanceof YearlyPeriodType || periodType instanceof QuarterlyPeriodType) {
            if (DEBUG)
                log.debug("Found data set " + dataSet.getName());
            datasets.add(getDataSetForLocale(dataSet.getId(), locale));
        } else {
            log.warn("Dataset '" + dataSet.getName() + "' set to be reported from mobile, but not of a supported period type: " + periodType.getName());
        }
    }
    return datasets;
}
Also used : Locale(java.util.Locale) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.api.mobile.model.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) ArrayList(java.util.ArrayList) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType)

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