Search in sources :

Example 16 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataSetDeletionHandler method deleteDataElement.

@Override
public void deleteDataElement(DataElement dataElement) {
    Iterator<DataSetElement> elements = dataElement.getDataSetElements().iterator();
    while (elements.hasNext()) {
        DataSetElement element = elements.next();
        elements.remove();
        dataElement.removeDataSetElement(element);
        idObjectManager.updateNoAcl(element.getDataSet());
    }
    List<DataSet> dataSets = idObjectManager.getAllNoAcl(DataSet.class);
    for (DataSet dataSet : dataSets) {
        boolean update = false;
        Iterator<DataElementOperand> operands = dataSet.getCompulsoryDataElementOperands().iterator();
        while (operands.hasNext()) {
            DataElementOperand operand = operands.next();
            if (operand.getDataElement().equals(dataElement)) {
                operands.remove();
                update = true;
            }
        }
        if (update) {
            idObjectManager.updateNoAcl(dataSet);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand)

Example 17 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testCreateDataSetWithSectionsAndGreyedFields.

@Test
public void testCreateDataSetWithSectionsAndGreyedFields() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertTrue(validate.getErrorReports().isEmpty());
    objectBundleService.commit(bundle);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<Section> sections = manager.getAll(Section.class);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
    List<TrackedEntity> trackedEntities = manager.getAll(TrackedEntity.class);
    List<OrganisationUnitLevel> organisationUnitLevels = manager.getAll(OrganisationUnitLevel.class);
    assertFalse(organisationUnits.isEmpty());
    assertEquals(1, organisationUnitLevels.size());
    assertEquals(1, trackedEntities.size());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, dataSets.size());
    assertEquals(2, sections.size());
    assertEquals(1, dataElementOperands.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals(2, dataSet.getSections().size());
    Section section1 = sections.get(0);
    Section section2 = sections.get(1);
    assertEquals(1, section1.getDataElements().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section1.getDataSet());
    assertNotNull(section2.getDataSet());
    Section section = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section.getDataSet());
    assertEquals(1, section.getCategoryCombos().size());
    assertEquals(1, section.getGreyedFields().size());
    DataElementCategoryCombo categoryCombo = manager.get(DataElementCategoryCombo.class, "faV8QvLgIwB");
    assertNotNull(categoryCombo);
    DataElementCategory category = manager.get(DataElementCategory.class, "XJGLlMAMCcn");
    assertNotNull(category);
    DataElementCategoryOption categoryOption1 = manager.get(DataElementCategoryOption.class, "JYiFOMKa25J");
    DataElementCategoryOption categoryOption2 = manager.get(DataElementCategoryOption.class, "tdaMRD34m8o");
    assertNotNull(categoryOption1);
    assertNotNull(categoryOption2);
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) Section(org.hisp.dhis.dataset.Section) ClassPathResource(org.springframework.core.io.ClassPathResource) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class LoadFormAction method getSectionForm.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getSectionForm(Collection<DataElement> dataElements, DataSet dataSet) {
    sections = new ArrayList<>(dataSet.getSections());
    Collections.sort(sections, new SectionOrderComparator());
    for (Section section : sections) {
        Set<Integer> categoryComboIds = new HashSet<>();
        for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
            categoryComboIds.add(categoryCombo.getId());
            sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
        }
        if (!categoryComboIds.isEmpty()) {
            sectionCombos.put(section.getId(), categoryComboIds);
        }
        for (DataElementOperand operand : section.getGreyedFields()) {
            if (operand != null && operand.getDataElement() != null && operand.getCategoryOptionCombo() != null) {
                greyedFields.put(operand.getDataElement().getUid() + ":" + operand.getCategoryOptionCombo().getUid(), true);
            }
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet)

Example 19 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class ValidationAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
    DataSet dataSet = dataSetService.getDataSet(ds);
    Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    if (attributeOptionCombo == null) {
        attributeOptionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
    }
    if (selectedPeriod == null || orgUnit == null || (multiOu && !orgUnit.hasChild())) {
        return SUCCESS;
    }
    Period period = periodService.getPeriod(selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedPeriod.getPeriodType());
    List<OrganisationUnit> organisationUnits = new ArrayList<>();
    if (!multiOu) {
        organisationUnits.add(orgUnit);
    } else {
        organisationUnits.addAll(orgUnit.getChildren());
    }
    Collections.sort(organisationUnits);
    Date from = new DateTime(period.getStartDate()).minusYears(2).toDate();
    for (OrganisationUnit organisationUnit : organisationUnits) {
        List<DeflatedDataValue> values = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataSet.getDataElements(), Sets.newHashSet(period), null, from));
        if (!values.isEmpty()) {
            dataValues.put(organisationUnit.getUid(), values);
        }
        List<ValidationResult> results = new ArrayList<>(validationService.startInteractiveValidationAnalysis(dataSet, period, organisationUnit, attributeOptionCombo));
        if (!results.isEmpty()) {
            validationResults.put(organisationUnit.getUid(), results);
        }
        List<DataElementOperand> violations = validationService.validateRequiredComments(dataSet, period, organisationUnit, attributeOptionCombo);
        if (!violations.isEmpty()) {
            commentViolations.put(organisationUnit.getUid(), violations);
        }
    }
    return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) ValidationResult(org.hisp.dhis.validation.ValidationResult) Date(java.util.Date) DateTime(org.joda.time.DateTime) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 20 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataElementGroupController method getOperandsByQuery.

@RequestMapping(value = "/{uid}/operands/query/{q}", method = RequestMethod.GET)
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    WebOptions options = new WebOptions(parameters);
    setUserContext(translateParams);
    List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
    if (dataElementGroups.isEmpty()) {
        throw new WebMessageException(WebMessageUtils.notFound("DataElementGroup not found for uid: " + uid));
    }
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands = Lists.newArrayList();
    for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
        if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
            dataElementOperands.add(dataElementOperand);
        }
    }
    metadata.setDataElementOperands(dataElementOperands);
    if (options.hasPaging()) {
        Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        metadata.setPager(pager);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    metadata.setDataElementOperands(dataElementOperands);
    linkService.generateLinks(metadata, false);
    model.addAttribute("model", metadata);
    model.addAttribute("viewClass", options.getViewClass("basic"));
    return StringUtils.uncapitalize(getEntitySimpleName());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)28 DataElement (org.hisp.dhis.dataelement.DataElement)12 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 Period (org.hisp.dhis.period.Period)6 Test (org.junit.Test)6 DataSet (org.hisp.dhis.dataset.DataSet)5 List (java.util.List)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)3 Section (org.hisp.dhis.dataset.Section)3 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)3 User (org.hisp.dhis.user.User)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2