Search in sources :

Example 16 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DataAnalysisController method performFollowupAnalysis.

@PostMapping(value = "/followup", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<DeflatedDataValue> performFollowupAnalysis(@RequestBody DataAnalysisParams params, HttpSession session) throws WebMessageException {
    I18nFormat format = i18nManager.getI18nFormat();
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(params.getOu());
    if (organisationUnit == null) {
        throw new WebMessageException(badRequest("No organisation unit defined"));
    }
    Collection<Period> periods = periodService.getPeriodsBetweenDates(format.parseDate(params.getStartDate()), format.parseDate(params.getEndDate()));
    Set<DataElement> dataElements = new HashSet<>();
    if (params.getDs() != null) {
        for (String uid : params.getDs()) {
            dataElements.addAll(dataSetService.getDataSet(uid).getDataElements());
        }
    }
    List<DeflatedDataValue> dataValues = new ArrayList<>(followupAnalysisService.getFollowupDataValues(Sets.newHashSet(organisationUnit), dataElements, periods, DataAnalysisService.MAX_OUTLIERS + 1));
    // +1 to detect overflow
    session.setAttribute(KEY_ANALYSIS_DATA_VALUES, dataValues);
    session.setAttribute(KEY_ORG_UNIT, organisationUnit);
    return deflatedValuesListToResponse(dataValues);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) HashSet(java.util.HashSet) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class EventCategoryOptValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    Program program = context.getProgram(event.getProgram());
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    checkNotNull(context.getBundle().getUser(), TrackerImporterAssertErrors.USER_CANT_BE_NULL);
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    checkNotNull(event, TrackerImporterAssertErrors.EVENT_CANT_BE_NULL);
    CategoryOptionCombo categoryOptionCombo = reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getUid());
    checkNotNull(categoryOptionCombo, TrackerImporterAssertErrors.CATEGORY_OPTION_COMBO_CANT_BE_NULL);
    Date eventDate;
    try {
        eventDate = DateUtils.fromInstant(ObjectUtils.firstNonNull(event.getOccurredAt(), event.getScheduledAt(), Instant.now()));
    } catch (IllegalArgumentException e) {
        log.debug("Failed to parse dates, an error should already be reported.");
        return;
    }
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    for (CategoryOption option : categoryOptionCombo.getCategoryOptions()) {
        if (option.getStartDate() != null && eventDate.compareTo(option.getStartDate()) < 0) {
            reporter.addError(event, E1056, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getStartDate()), option.getName());
        }
        if (option.getEndDate() != null && eventDate.compareTo(option.getAdjustedEndDate(program)) > 0) {
            reporter.addError(event, E1057, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getAdjustedEndDate(program)), option.getName(), program.getName());
        }
    }
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) CategoryOption(org.hisp.dhis.category.CategoryOption) I18nFormat(org.hisp.dhis.i18n.I18nFormat) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Example 18 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class MapController method postProcessResponseEntity.

// --------------------------------------------------------------------------
// Hooks
// --------------------------------------------------------------------------
@Override
public void postProcessResponseEntity(Map map, WebOptions options, java.util.Map<String, String> parameters) throws Exception {
    I18nFormat format = i18nManager.getI18nFormat();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (MapView view : map.getMapViews()) {
        view.populateAnalyticalProperties();
        for (OrganisationUnit organisationUnit : view.getOrganisationUnits()) {
            view.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
        }
        if (view.getPeriods() != null && !view.getPeriods().isEmpty()) {
            for (Period period : view.getPeriods()) {
                period.setName(format.formatPeriod(period));
            }
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MapView(org.hisp.dhis.mapping.MapView) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 19 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DefaultFollowupAnalysisService method getFollowupDataValues.

@Override
@Transactional(readOnly = true)
public FollowupAnalysisResponse getFollowupDataValues(FollowupAnalysisRequest request) {
    validate(request);
    List<FollowupValue> followupValues = followupValueManager.getFollowupDataValues(currentUserService.getCurrentUser(), request);
    I18nFormat format = i18nManager.getI18nFormat();
    followupValues.forEach(value -> value.setPeName(format.formatPeriod(value.getPeAsPeriod())));
    return new FollowupAnalysisResponse(new FollowupAnalysisMetadata(request), followupValues);
}
Also used : I18nFormat(org.hisp.dhis.i18n.I18nFormat) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class ReportTableController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
protected void postProcessEntity(ReportTable reportTable) throws Exception {
    reportTable.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : reportTable.getOrganisationUnits()) {
        reportTable.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    I18nFormat format = i18nManager.getI18nFormat();
    if (reportTable.getPeriods() != null && !reportTable.getPeriods().isEmpty()) {
        for (Period period : reportTable.getPeriods()) {
            period.setName(format.formatPeriod(period));
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Aggregations

I18nFormat (org.hisp.dhis.i18n.I18nFormat)37 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)24 Period (org.hisp.dhis.period.Period)19 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Grid (org.hisp.dhis.common.Grid)5 IdScheme (org.hisp.dhis.common.IdScheme)5 I18n (org.hisp.dhis.i18n.I18n)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)4 User (org.hisp.dhis.user.User)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 HashMap (java.util.HashMap)3