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);
}
}
}
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);
}
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);
}
}
}
}
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;
}
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());
}
Aggregations