use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class PredictorServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
dataElementA = createDataElement('A');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
DataElement dataElementD = createDataElement('D');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
defaultCombo = categoryService.getDefaultCategoryOptionCombo();
altCategoryOption = new CategoryOption("AltCategoryOption");
categoryService.addCategoryOption(altCategoryOption);
altCategory = createCategory('A', altCategoryOption);
categoryService.addCategory(altCategory);
altCategoryCombo = createCategoryCombo('Y', altCategory);
categoryService.addCategoryCombo(altCategoryCombo);
altCombo = createCategoryOptionCombo(altCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addCategoryOptionCombo(altCombo);
expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("135.79", "descriptionC");
expressionD = new Expression("34.98", "descriptionD");
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultCsvImportService method categoryOptionsFromCsv.
private List<CategoryOption> categoryOptionsFromCsv(CsvReader reader) throws IOException {
List<CategoryOption> list = new ArrayList<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
CategoryOption object = new CategoryOption();
setIdentifiableObject(object, values);
object.setShortName(getSafe(values, 3, object.getName(), 50));
list.add(object);
}
}
return list;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method getAttributeOptionCombo.
private CategoryOptionCombo getAttributeOptionCombo(IdScheme idScheme, String categoryComboId, Set<CategoryOption> categoryOptions) {
final String key = "categorycomboid";
final String categoryComboKey = resolveId(idScheme, key, categoryComboId);
final String optionsId = categoryOptions.stream().map(co -> Long.toString(co.getId())).map(s -> "'" + s + "'").collect(Collectors.joining(","));
StringSubstitutor sub = new StringSubstitutor(ImmutableMap.<String, String>builder().put("resolvedScheme", Objects.requireNonNull(categoryComboKey)).put("option_ids", optionsId).build());
// TODO use cache
List<CategoryOptionCombo> categoryOptionCombos = jdbcTemplate.query(sub.replace(SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS), (rs, i) -> bind("categoryoptioncomboid", rs));
if (categoryOptionCombos.size() == 1) {
return categoryOptionCombos.get(0);
} else {
// TODO throw an error??
return null;
}
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultDataSetMetadataExportService method getDataSetMetadata.
// TODO add lock exceptions
// TODO add validation caching (ETag and If-None-Match).
@Override
public ObjectNode getDataSetMetadata() {
User user = currentUserService.getCurrentUser();
List<DataSet> dataSets = idObjectManager.getDataWriteAll(DataSet.class);
Set<DataElement> dataElements = flatMapToSet(dataSets, DataSet::getDataElements);
Set<Indicator> indicators = flatMapToSet(dataSets, DataSet::getIndicators);
Set<CategoryCombo> dataElementCategoryCombos = flatMapToSet(dataElements, DataElement::getCategoryCombos);
Set<CategoryCombo> dataSetCategoryCombos = mapToSet(dataSets, DataSet::getCategoryCombo);
Set<Category> dataElementCategories = flatMapToSet(dataElementCategoryCombos, CategoryCombo::getCategories);
Set<Category> dataSetCategories = flatMapToSet(dataSetCategoryCombos, CategoryCombo::getCategories);
Set<CategoryOption> categoryOptions = getCategoryOptions(dataElementCategories, dataSetCategories, user);
expressionService.substituteIndicatorExpressions(indicators);
ObjectNode rootNode = fieldFilterService.createObjectNode();
rootNode.putArray(DataSetSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataSets, FIELDS_DATA_SETS, DataSet.class));
rootNode.putArray(DataElementSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElements, FIELDS_DATA_ELEMENTS, DataElement.class));
rootNode.putArray(IndicatorSchemaDescriptor.PLURAL).addAll(asObjectNodes(indicators, FIELDS_INDICATORS, Indicator.class));
rootNode.putArray(CategoryComboSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElementCategoryCombos, FIELDS_DATAELEMENT_CAT_COMBOS, CategoryCombo.class)).addAll(asObjectNodes(dataSetCategoryCombos, FIELDS_DATA_SET_CAT_COMBOS, CategoryCombo.class));
rootNode.putArray(CategorySchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElementCategories, FIELDS_CATEGORIES, Category.class)).addAll(asObjectNodes(dataSetCategories, FIELDS_CATEGORIES, Category.class));
rootNode.putArray(CategoryOptionSchemaDescriptor.PLURAL).addAll(asObjectNodes(categoryOptions, FIELDS_CATEGORIES, CategoryOption.class));
return rootNode;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class AdxDataServiceIntegrationTest method setUpTest.
@Override
public void setUpTest() {
// UserService
userService = _userService;
// Category Option
coUnder5 = new CategoryOption("Under 5");
coOver5 = new CategoryOption("Over 5");
coF = new CategoryOption("Female");
coM = new CategoryOption("Male");
coPepfar = new CategoryOption("PEPFAR mechanism");
coMcDonalds = new CategoryOption("McDonalds mechanism");
coUnder5.setCode("under5");
coOver5.setCode("over5");
coF.setCode("F");
coM.setCode("M");
coPepfar.setCode("PEPFAR");
coMcDonalds.setCode("McDonalds");
coUnder5.setUid("under555555");
coOver5.setUid("over5555555");
coF.setUid("FFFFFFFFFFF");
coM.setUid("MMMMMMMMMMM");
coPepfar.setUid("PEPFARRRRRR");
coMcDonalds.setUid("McDonaldsss");
idObjectManager.save(coUnder5);
idObjectManager.save(coOver5);
idObjectManager.save(coF);
idObjectManager.save(coM);
idObjectManager.save(coPepfar);
idObjectManager.save(coMcDonalds);
// Category
cAge = createCategory('A', coUnder5, coOver5);
cSex = createCategory('B', coF, coM);
cMechanism = createCategory('C', coPepfar, coMcDonalds);
cAge.setName("Age_category");
cSex.setName("Sex_category");
cMechanism.setName("Mechanism_category");
cAge.setCode("age");
cSex.setCode("sex");
cMechanism.setCode("mechanism");
cAge.setUid("ageeeeeeeee");
cSex.setUid("sexxxxxxxxx");
cMechanism.setUid("mechanismmm");
idObjectManager.save(cAge);
idObjectManager.save(cSex);
idObjectManager.save(cMechanism);
// Category Combo
ccAgeAndSex = createCategoryCombo('A', cAge, cSex);
ccMechanism = createCategoryCombo('B', cMechanism);
ccAgeAndSex.setName("Age and Sex Category Combo");
ccMechanism.setName("Mechanism Category Combo");
idObjectManager.save(ccAgeAndSex);
idObjectManager.save(ccMechanism);
cAge.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
cSex.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
cMechanism.setCategoryCombos(Lists.newArrayList(ccMechanism));
idObjectManager.update(cAge);
idObjectManager.update(cSex);
idObjectManager.update(cMechanism);
// Category Option Combo
cocFUnder5 = createCategoryOptionCombo(ccAgeAndSex, coF, coUnder5);
cocMUnder5 = createCategoryOptionCombo(ccAgeAndSex, coM, coUnder5);
cocFOver5 = createCategoryOptionCombo(ccAgeAndSex, coF, coOver5);
cocMOver5 = createCategoryOptionCombo(ccAgeAndSex, coM, coOver5);
cocPepfar = createCategoryOptionCombo(ccMechanism, coPepfar);
cocMcDonalds = createCategoryOptionCombo(ccMechanism, coMcDonalds);
cocFUnder5.setName("Female Under 5");
cocMUnder5.setName("Male Under 5");
cocFOver5.setName("Female Over 5");
cocMOver5.setName("Male Over 5");
cocPepfar.setName("PEPFAR CategoryOptionCombo");
cocMcDonalds.setName("McDonalds CategoryOptionCombo");
cocFUnder5.setCode("F_Under5");
cocMUnder5.setCode("M_Under5");
cocFOver5.setCode("F_Over5");
cocMOver5.setCode("M_Over5");
cocPepfar.setCode("coc_PEPFAR");
cocMcDonalds.setCode("coc_McDonalds");
cocFUnder5.setUid("FUnder55555");
cocMUnder5.setUid("MUnder55555");
cocFOver5.setUid("FOver555555");
cocMOver5.setUid("MOver555555");
cocPepfar.setUid("cocPEPFARRR");
cocMcDonalds.setUid("cocMcDonald");
idObjectManager.save(cocFUnder5);
idObjectManager.save(cocMUnder5);
idObjectManager.save(cocFOver5);
idObjectManager.save(cocMOver5);
idObjectManager.save(cocPepfar);
idObjectManager.save(cocMcDonalds);
ccAgeAndSex.getOptionCombos().add(cocFUnder5);
ccAgeAndSex.getOptionCombos().add(cocMUnder5);
ccAgeAndSex.getOptionCombos().add(cocFOver5);
ccAgeAndSex.getOptionCombos().add(cocMOver5);
ccMechanism.getOptionCombos().add(cocPepfar);
ccMechanism.getOptionCombos().add(cocMcDonalds);
idObjectManager.update(ccAgeAndSex);
idObjectManager.update(ccMechanism);
cocDefault = categoryService.getDefaultCategoryOptionCombo();
// Data Element
deA = createDataElement('A');
deB = createDataElement('B');
deA.setName("Malaria numeric");
deB.setName("Malaria text");
deA.setCode("Mal_num");
deB.setCode("Mal_text");
deA.setUid("MalNummmmmm");
deB.setUid("MalTexttttt");
deA.setCategoryCombo(ccAgeAndSex);
deB.setValueType(ValueType.TEXT);
idObjectManager.save(deA);
idObjectManager.save(deB);
// Period
pe202001 = PeriodType.getPeriodFromIsoString("202001");
pe202002 = PeriodType.getPeriodFromIsoString("202002");
pe2021Q1 = PeriodType.getPeriodFromIsoString("2021Q1");
periodService.addPeriod(pe202001);
periodService.addPeriod(pe202002);
periodService.addPeriod(pe2021Q1);
// Data Set
dsA = createDataSet('A', PeriodType.getPeriodTypeByName("Monthly"));
dsB = createDataSet('B', PeriodType.getPeriodTypeByName("Quarterly"));
dsA.setName("Malaria DS");
dsB.setName("Malaria Mechanism DS");
dsA.setCode("MalariaDS");
dsB.setCode("MalariaMechanismDS");
dsA.setUid("MalariaDSSS");
dsB.setUid("MalariaMech");
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsB.addDataSetElement(deA);
dsB.addDataSetElement(deB);
dsB.setCategoryCombo(ccMechanism);
idObjectManager.save(dsA);
idObjectManager.save(dsB);
// Organisation Unit
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
ouA.setName("Provincial Hospital");
ouB.setName("District Hospital");
ouA.setCode("123");
ouB.setCode("456");
ouA.setUid("P1233333333");
ouB.setUid("D4566666666");
idObjectManager.save(ouA);
idObjectManager.save(ouB);
// Organisation Unit Group
ougA = createOrganisationUnitGroup('A');
ougA.addOrganisationUnit(ouA);
ougA.addOrganisationUnit(ouB);
organisationUnitGroupService.addOrganisationUnitGroup(ougA);
// User & Current User Service
user = createAndInjectAdminUser();
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
userService.addUser(user);
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService, organisationUnitService);
}
Aggregations