Search in sources :

Example 21 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class AbstractEventService method getEventsGrid.

@Transactional(readOnly = true)
@Override
public Grid getEventsGrid(EventSearchParams params) {
    User user = currentUserService.getCurrentUser();
    if (params.getProgramStage() == null || params.getProgramStage().getProgram() == null) {
        throw new IllegalQueryException("Program stage can not be null");
    }
    if (params.getProgramStage().getProgramStageDataElements() == null) {
        throw new IllegalQueryException("Program stage should have at least one data element");
    }
    List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
    params.handleCurrentUserSelectionMode(user);
    if (params.isIncludeAllDataElements()) {
        for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
            QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
            params.getDataElements().add(qi);
        }
    } else {
        if (params.getDataElements().isEmpty()) {
            for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
                if (pde.getDisplayInReports()) {
                    QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
                    params.getDataElements().add(qi);
                }
            }
        }
    }
    // ---------------------------------------------------------------------
    // Grid headers
    // ---------------------------------------------------------------------
    Grid grid = new ListGrid();
    for (String col : STATIC_EVENT_COLUMNS) {
        grid.addHeader(new GridHeader(col, col));
    }
    for (QueryItem item : params.getDataElements()) {
        grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
    }
    List<Map<String, String>> events = eventStore.getEventsGrid(params, organisationUnits);
    for (Map<String, String> event : events) {
        grid.addRow();
        for (String col : STATIC_EVENT_COLUMNS) {
            grid.addValue(event.get(col));
        }
        for (QueryItem item : params.getDataElements()) {
            grid.addValue(event.get(item.getItemId()));
        }
    }
    Map<String, Object> metaData = new HashMap<>();
    if (params.isPaging()) {
        final Pager pager;
        if (params.isTotalPages()) {
            int count = eventStore.getEventCount(params, organisationUnits);
            pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
        } else {
            pager = handleLastPageFlag(params, grid);
        }
        metaData.put(PAGER_META_KEY, pager);
    }
    grid.setMetaData(metaData);
    return grid;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryItem(org.hisp.dhis.common.QueryItem) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) SlimPager(org.hisp.dhis.common.SlimPager) Pager(org.hisp.dhis.common.Pager) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) CachingMap(org.hisp.dhis.commons.collection.CachingMap) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class DataValueCheck method validateMandatoryAttributes.

public void validateMandatoryAttributes(ImportConflicts importConflicts, WorkContext ctx, ImmutableEvent event) {
    if (StringUtils.isEmpty(event.getProgramStage()))
        return;
    final IdScheme programStageIdScheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
    final IdScheme dataElementIdScheme = ctx.getImportOptions().getIdSchemes().getDataElementIdScheme();
    final Map<String, Set<EventDataValue>> eventDataValueMap = ctx.getEventDataValueMap();
    final boolean allowSingleUpdates = ctx.getImportOptions().isMergeDataValues();
    ProgramStage programStage = ctx.getProgramStage(programStageIdScheme, event.getProgramStage());
    final Set<ProgramStageDataElement> mandatoryDataElements = getMandatoryProgramStageDataElements(programStage);
    // Data Element IDs associated to the current event
    Set<String> dataValues = eventDataValueMap.get(event.getUid()).stream().map(EventDataValue::getDataElement).collect(Collectors.toSet());
    if (allowSingleUpdates) {
        final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getUid());
        dataValues.addAll(programStageInstance.getEventDataValues().stream().filter(dv -> !StringUtils.isEmpty(dv.getValue().trim())).map(EventDataValue::getDataElement).collect(Collectors.toSet()));
    }
    for (ProgramStageDataElement mandatoryDataElement : mandatoryDataElements) {
        String resolvedDataElementId = getIdentifierBasedOnIdScheme(mandatoryDataElement.getDataElement(), dataElementIdScheme);
        if (!dataValues.contains(resolvedDataElementId)) {
            importConflicts.addConflict(resolvedDataElementId, "value_required_but_not_provided");
        }
    }
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) Authorities(org.hisp.dhis.security.Authorities) ValueType(org.hisp.dhis.common.ValueType) ValidationUtils(org.hisp.dhis.system.util.ValidationUtils) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) IdentifiableObjectUtils.getIdentifierBasedOnIdScheme(org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifierBasedOnIdScheme) StringUtils(org.apache.commons.lang3.StringUtils) DataElement(org.hisp.dhis.dataelement.DataElement) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) SQLException(java.sql.SQLException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) Map(java.util.Map) Checker(org.hisp.dhis.dxf2.events.importer.Checker) ImageIO(javax.imageio.ImageIO) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) User(org.hisp.dhis.user.User) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) EventUtils.eventDataValuesToJson(org.hisp.dhis.dxf2.events.event.EventUtils.eventDataValuesToJson) ImmutableSet(com.google.common.collect.ImmutableSet) FileResource(org.hisp.dhis.fileresource.FileResource) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) Component(org.springframework.stereotype.Component) OptionSet(org.hisp.dhis.option.OptionSet) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Optional(java.util.Optional) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) OptionSet(org.hisp.dhis.option.OptionSet) IdentifiableObjectUtils.getIdentifierBasedOnIdScheme(org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifierBasedOnIdScheme) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 23 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ProgramSupplier method aggregateProgramAndAclData.

private void aggregateProgramAndAclData(Map<String, Program> programMap, Map<Long, DataElementSets> dataElementSetsMap) {
    for (Program program : programMap.values()) {
        for (ProgramStage programStage : program.getProgramStages()) {
            DataElementSets dataElementSets = dataElementSetsMap.get(programStage.getId());
            if (dataElementSets != null) {
                Stream<ProgramStageDataElement> compulsoryProgramStageDataElementsStream = getOrEmpty(dataElementSets.getCompulsoryDataElements()).map(de -> new ProgramStageDataElement(programStage, de, true));
                Stream<ProgramStageDataElement> nonCompulsoryProgramStageDataElementsStream = getOrEmpty(dataElementSets.getNonCompulsoryDataElements()).map(de -> new ProgramStageDataElement(programStage, de, false));
                Set<ProgramStageDataElement> allProgramStageDataElements = Stream.concat(compulsoryProgramStageDataElementsStream, nonCompulsoryProgramStageDataElementsStream).collect(Collectors.toSet());
                programStage.setProgramStageDataElements(allProgramStageDataElements);
            }
        }
    }
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 24 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ProgramStageDataElementObjectBundleHook method validate.

/**
 * Validate that the RenderType (if any) conforms to the constraints of
 * ValueType or OptionSet.
 */
@Override
public void validate(ProgramStageDataElement psda, ObjectBundle bundle, Consumer<ErrorReport> addReports) {
    DeviceRenderTypeMap<ValueTypeRenderingObject> map = psda.getRenderType();
    if (map == null) {
        return;
    }
    DataElement de = psda.getDataElement();
    for (ValueTypeRenderingObject renderingObject : map.values()) {
        if (renderingObject.getType() == null) {
            addReports.accept(new ErrorReport(ProgramStageDataElement.class, ErrorCode.E4011, "renderType.type"));
        }
        if (!ValidationUtils.validateRenderingType(ProgramStageDataElement.class, de.getValueType(), de.hasOptionSet(), renderingObject.getType())) {
            addReports.accept(new ErrorReport(ProgramStageDataElement.class, ErrorCode.E4017, renderingObject.getType(), de.getValueType()));
        }
    }
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ValueTypeRenderingObject(org.hisp.dhis.render.type.ValueTypeRenderingObject)

Example 25 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class EventImportTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    CategoryOption categoryOption1 = new CategoryOption("male");
    categoryOption1.setAutoFields();
    CategoryOption categoryOption2 = new CategoryOption("female");
    categoryOption2.setAutoFields();
    manager.save(Lists.newArrayList(categoryOption1, categoryOption2));
    Category cat1 = new Category("cat1", DataDimensionType.DISAGGREGATION);
    cat1.setShortName(cat1.getName());
    cat1.setCategoryOptions(Lists.newArrayList(categoryOption1, categoryOption2));
    manager.save(Lists.newArrayList(cat1));
    CategoryCombo categoryCombo = manager.getByName(CategoryCombo.class, "default");
    categoryCombo.setCategories(Lists.newArrayList(cat1));
    dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.setCategoryCombo(categoryCombo);
    manager.save(dataElementA);
    dataElementA2 = createDataElement('a');
    dataElementA2.setValueType(ValueType.INTEGER);
    dataElementA2.setCategoryCombo(categoryCombo);
    manager.save(dataElementA2);
    dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.INTEGER);
    dataElementB.setCategoryCombo(categoryCombo);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageA.setFeatureType(FeatureType.POINT);
    manager.save(programStageA);
    programStageA2 = createProgramStage('a', 0);
    programStageA2.setFeatureType(FeatureType.POINT);
    programStageA2.setRepeatable(true);
    manager.save(programStageA2);
    programStageB = createProgramStage('B', 0);
    programStageB.setFeatureType(FeatureType.POINT);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setCategoryCombo(categoryCombo);
    manager.save(programA);
    programB = createProgram('B', new HashSet<>(), organisationUnitB);
    programB.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    programB.setCategoryCombo(categoryCombo);
    manager.save(programB);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    ProgramStageDataElement programStageDataElementA2 = new ProgramStageDataElement();
    programStageDataElementA2.setDataElement(dataElementA2);
    programStageDataElementA2.setProgramStage(programStageA2);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementA2);
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA2.getProgramStageDataElements().add(programStageDataElementA2);
    programStageA.setProgram(programA);
    programStageA2.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageA2);
    programStageB.getProgramStageDataElements().add(programStageDataElementB);
    programStageB.setProgram(programB);
    programB.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageA2);
    manager.update(programA);
    manager.update(programStageB);
    manager.update(programB);
    pi = new ProgramInstance();
    pi.setEnrollmentDate(new Date());
    pi.setIncidentDate(new Date());
    pi.setProgram(programB);
    pi.setStatus(ProgramStatus.ACTIVE);
    pi.setStoredBy("test");
    pi.setName("EventImportTestPI");
    pi.setUid(CodeGenerator.generateUid());
    manager.save(pi);
    event = createEvent("eventUid001");
    createUserAndInjectSecurityContext(true);
    // Flush all data to disk
    manager.flush();
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramInstance(org.hisp.dhis.program.ProgramInstance) CategoryOption(org.hisp.dhis.category.CategoryOption) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)43 DataElement (org.hisp.dhis.dataelement.DataElement)21 ProgramStage (org.hisp.dhis.program.ProgramStage)15 HashSet (java.util.HashSet)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)7 User (org.hisp.dhis.user.User)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Program (org.hisp.dhis.program.Program)6 Test (org.junit.jupiter.api.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 List (java.util.List)4 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)4 Event (org.hisp.dhis.tracker.domain.Event)4 HashMap (java.util.HashMap)3 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 PeriodType (org.hisp.dhis.period.PeriodType)3