use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DataValueDimensionTest method setUpTest.
@Override
public void setUpTest() {
male = new DataElementCategoryOption("Male");
female = new DataElementCategoryOption("Female");
under15 = new DataElementCategoryOption("<15");
over15 = new DataElementCategoryOption(">15");
categoryService.addDataElementCategoryOption(male);
categoryService.addDataElementCategoryOption(female);
categoryService.addDataElementCategoryOption(under15);
categoryService.addDataElementCategoryOption(over15);
gender = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
gender.getCategoryOptions().add(male);
gender.getCategoryOptions().add(female);
ageGroup = new DataElementCategory("Agegroup", DataDimensionType.DISAGGREGATION);
ageGroup.getCategoryOptions().add(under15);
ageGroup.getCategoryOptions().add(over15);
categoryService.addDataElementCategory(gender);
categoryService.addDataElementCategory(ageGroup);
genderAndAgeGroup = new DataElementCategoryCombo("Gender and Agegroup", DataDimensionType.DISAGGREGATION);
genderAndAgeGroup.getCategories().add(gender);
genderAndAgeGroup.getCategories().add(ageGroup);
categoryService.addDataElementCategoryCombo(genderAndAgeGroup);
categoryService.generateOptionCombos(genderAndAgeGroup);
dataElementA = createDataElement('A', genderAndAgeGroup);
dataElementService.addDataElement(dataElementA);
periodA = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
periodService.addPeriod(periodA);
sourceA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(sourceA);
defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
for (DataElementCategoryOptionCombo categoryOptionCombo : genderAndAgeGroup.getOptionCombos()) {
dataValueService.addDataValue(createDataValue(dataElementA, periodA, sourceA, "10", categoryOptionCombo, defaultOptionCombo));
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class AbstractWebApiTest method createTestObject.
@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
if (DataElementGroup.class.isAssignableFrom(clazz)) {
return (T) createDataElementGroup(uniqueName);
} else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
} else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
return (T) createCategoryOption(uniqueName);
} else if (DataElement.class.isAssignableFrom(clazz)) {
return (T) createDataElement(uniqueName);
} else if (DataElementCategory.class.isAssignableFrom(clazz)) {
return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
} else if (Program.class.isAssignableFrom(clazz)) {
OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
manager.save(organisationUnitA);
return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
} else if (DataElementOperand.class.isAssignableFrom(clazz)) {
DataElement deA = createDataElement(uniqueName);
manager.save(deA);
DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
DataElementCategoryOption co = createCategoryOption(uniqueName);
manager.save(cc);
manager.save(co);
DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
manager.save(coc);
return (T) new DataElementOperand(deA, coc);
} else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
return (T) createDataElementGroupSet(uniqueName);
} else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
DataElementCategoryOption co = createCategoryOption(uniqueName);
manager.save(cc);
manager.save(co);
return (T) createCategoryOptionCombo(cc, co);
} else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
DataElementCategoryOption co = createCategoryOption(uniqueName);
manager.save(co);
return (T) createCategoryOptionGroup(uniqueName, co);
} else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
return (T) createCategoryOptionGroupSet(uniqueName);
} else if (EventChart.class.isAssignableFrom(clazz)) {
Program prA = createProgram(uniqueName);
manager.save(prA);
EventChart ecA = new EventChart("evc" + uniqueName);
ecA.setProgram(prA);
ecA.setType(ChartType.COLUMN);
return (T) ecA;
} else if (EventReport.class.isAssignableFrom(clazz)) {
Program prA = createProgram(uniqueName);
manager.save(prA);
EventReport erA = new EventReport("er" + uniqueName);
erA.setProgram(prA);
return (T) erA;
} else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
Program prA = createProgram(uniqueName);
manager.save(prA);
DataElement deA = createDataElement(uniqueName);
manager.save(deA);
return (T) new ProgramDataElementDimensionItem(prA, deA);
} else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
Program program = (Program) createTestObject(Program.class, uniqueName);
manager.save(program);
Constant constantA = createConstant(uniqueName, 7.0);
manager.save(constantA);
String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} ) / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
return (T) createProgramIndicator(uniqueName, program, expressionA, null);
} else if (Indicator.class.isAssignableFrom(clazz)) {
IndicatorType indicatorType = createIndicatorType(uniqueName);
manager.save(indicatorType);
return (T) createIndicator(uniqueName, indicatorType);
} else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
return (T) createIndicatorGroup(uniqueName);
} else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
return (T) createIndicatorGroupSet(uniqueName);
} else if (IndicatorType.class.isAssignableFrom(clazz)) {
return (T) createIndicatorType(uniqueName);
} else if (Legend.class.isAssignableFrom(clazz)) {
return (T) createLegend(uniqueName, 0d, 10d);
} else if (LegendSet.class.isAssignableFrom(clazz)) {
return (T) createLegendSet(uniqueName);
} else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
return (T) createOrganisationUnit(uniqueName);
} else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
return (T) createOrganisationUnitGroup(uniqueName);
} else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
return (T) createOrganisationUnitGroupSet(uniqueName);
} else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
} else if (Color.class.isAssignableFrom(clazz)) {
Color color = new Color("#ff3200");
color.setName("Color" + uniqueName);
return (T) color;
} else if (ColorSet.class.isAssignableFrom(clazz)) {
ColorSet colorSet = new ColorSet();
colorSet.setName("ColorSet" + uniqueName);
return (T) colorSet;
} else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
map.setName("Map" + uniqueName);
map.setDisplayName("DisplayName" + uniqueName);
map.setLatitude(952175.62553525);
map.setLongitude(-1378543.6774686);
return (T) map;
} else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
externalMapLayer.setMapService(MapService.WMS);
externalMapLayer.setUrl("testUrl");
externalMapLayer.setImageFormat(ImageFormat.JPG);
externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
return (T) externalMapLayer;
} else if (OptionGroup.class.isAssignableFrom(clazz)) {
OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
optionGroup.setShortName("Group" + uniqueName);
return (T) optionGroup;
} else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
} else if (Option.class.isAssignableFrom(clazz)) {
return (T) new Option("Option" + uniqueName, "code" + uniqueName);
} else if (OptionSet.class.isAssignableFrom(clazz)) {
return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
} else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
group.addAttribute(attr);
return (T) group;
} else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
return (T) createProgramTrackedEntityAttribute(uniqueName);
} else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
return (T) createProgramDataElement(uniqueName);
}
return null;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryOptionGroup.
/**
* @param uniqueIdentifier A unique character to identify the
* category option group.
* @param categoryOptions the category options.
* @return CategoryOptionGroup
*/
public static CategoryOptionGroup createCategoryOptionGroup(char uniqueIdentifier, DataElementCategoryOption... categoryOptions) {
CategoryOptionGroup categoryOptionGroup = new CategoryOptionGroup("CategoryOptionGroup" + uniqueIdentifier);
categoryOptionGroup.setShortName("ShortName" + uniqueIdentifier);
categoryOptionGroup.setAutoFields();
categoryOptionGroup.setMembers(new HashSet<>());
for (DataElementCategoryOption categoryOption : categoryOptions) {
categoryOptionGroup.addCategoryOption(categoryOption);
}
return categoryOptionGroup;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryOptionCombo.
/**
* @param categoryCombo the category combo.
* @param categoryOptions the category options.
* @return DataElementCategoryOptionCombo
*/
public static DataElementCategoryOptionCombo createCategoryOptionCombo(DataElementCategoryCombo categoryCombo, DataElementCategoryOption... categoryOptions) {
DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
categoryOptionCombo.setAutoFields();
categoryOptionCombo.setCategoryCombo(categoryCombo);
for (DataElementCategoryOption categoryOption : categoryOptions) {
categoryOptionCombo.getCategoryOptions().add(categoryOption);
categoryOption.getCategoryOptionCombos().add(categoryOptionCombo);
}
return categoryOptionCombo;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOption in project dhis2-core by dhis2.
the class HibernateCategoryOptionComboStore method getCategoryOptionCombo.
@Override
public DataElementCategoryOptionCombo getCategoryOptionCombo(DataElementCategoryCombo categoryCombo, Set<DataElementCategoryOption> categoryOptions) {
String hql = "from DataElementCategoryOptionCombo co where co.categoryCombo = :categoryCombo";
for (DataElementCategoryOption option : categoryOptions) {
hql += " and :option" + option.getId() + " in elements (co.categoryOptions)";
}
Query query = getQuery(hql);
query.setEntity("categoryCombo", categoryCombo);
for (DataElementCategoryOption option : categoryOptions) {
query.setEntity("option" + option.getId(), option);
}
return (DataElementCategoryOptionCombo) query.uniqueResult();
}
Aggregations