use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method getAttributeOptionCombo.
private CategoryOptionCombo getAttributeOptionCombo(CategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
if (categoryCombo == null) {
throw new IllegalQueryException("Illegal category combo");
}
// ---------------------------------------------------------------------
// Attribute category options validation
// ---------------------------------------------------------------------
CategoryOptionCombo attrOptCombo = null;
if (opts != null) {
Set<CategoryOption> categoryOptions = new HashSet<>();
for (String uid : opts) {
CategoryOption categoryOption = getCategoryOption(idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
final String id = resolveCategoryComboId(categoryCombo, idScheme);
attrOptCombo = getAttributeOptionCombo(idScheme, id, categoryOptions);
if (attrOptCombo == null) {
throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
}
} else if (attributeOptionCombo != null) {
attrOptCombo = getCategoryOptionCombo(idScheme, attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = getDefault();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionComboSupplier method get.
@Override
public Map<String, CategoryOptionCombo> get(ImportOptions importOptions, List<Event> events) {
if (events == null) {
return emptyMap();
}
// TODO this should be optimized to execute less SQL queries
IdScheme idScheme = importOptions.getIdSchemes().getCategoryOptionIdScheme();
Map<String, CategoryOptionCombo> eventToCocMap = new HashMap<>();
Map<String, Program> programMap = programSupplier.get(importOptions, events);
Map<String, ProgramStageInstance> programStageInstanceMap = programStageInstanceSupplier.get(importOptions, events);
for (Event event : events) {
Program program = programMap.get(event.getProgram());
ProgramStageInstance psi = programStageInstanceMap.get(event.getUid());
// validation stage
if (program == null) {
return emptyMap();
}
CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(program, event, psi, idScheme);
if (categoryOptionCombo != null) {
eventToCocMap.put(event.getUid(), categoryOptionCombo);
}
}
return eventToCocMap;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class ExpressionService2Test method setUp.
@BeforeEach
public void setUp() {
target = new DefaultExpressionService(hibernateGenericStore, constantService, dimensionService, idObjectManager, statementBuilder, i18nManager, cacheProvider);
categoryOptionA = new CategoryOption("Under 5");
categoryOptionB = new CategoryOption("Over 5");
categoryOptionC = new CategoryOption("Male");
categoryOptionD = new CategoryOption("Female");
categoryA = new Category("Age", DataDimensionType.DISAGGREGATION);
categoryB = new Category("Gender", DataDimensionType.DISAGGREGATION);
categoryA.getCategoryOptions().add(categoryOptionA);
categoryA.getCategoryOptions().add(categoryOptionB);
categoryB.getCategoryOptions().add(categoryOptionC);
categoryB.getCategoryOptions().add(categoryOptionD);
categoryCombo = new CategoryCombo("Age and gender", DataDimensionType.DISAGGREGATION);
categoryCombo.getCategories().add(categoryA);
categoryCombo.getCategories().add(categoryB);
categoryCombo.generateOptionCombos();
List<CategoryOptionCombo> optionCombos = Lists.newArrayList(categoryCombo.getOptionCombos());
cocA = optionCombos.get(0);
cocA.setUid(CodeGenerator.generateUid());
cocB = optionCombos.get(1);
cocB.setUid(CodeGenerator.generateUid());
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deD = createDataElement('D');
deE = createDataElement('E', categoryCombo);
coc = rnd.nextObject(CategoryOptionCombo.class);
coc.setName(DEFAULT_CATEGORY_COMBO_NAME);
optionCombos.add(coc);
opA = new DataElementOperand(deA, coc);
opB = new DataElementOperand(deB, coc);
opC = new DataElementOperand(deC, coc);
opD = new DataElementOperand(deD, coc);
opE = new DataElementOperand(deB, cocA);
opF = new DataElementOperand(deA, cocA, cocB);
period = createPeriod(getDate(2000, 1, 1), getDate(2000, 1, 31));
pteaA = rnd.nextObject(ProgramTrackedEntityAttributeDimensionItem.class);
pdeA = rnd.nextObject(ProgramDataElementDimensionItem.class);
piA = rnd.nextObject(ProgramIndicator.class);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
constantA = rnd.nextObject(Constant.class);
constantA.setName("ConstantA");
constantA.setValue(2.0);
constantB = rnd.nextObject(Constant.class);
constantB.setName("ConstantB");
constantB.setValue(5.0);
groupA = createOrganisationUnitGroup('A');
groupA.addOrganisationUnit(unitA);
groupA.addOrganisationUnit(unitB);
groupA.addOrganisationUnit(unitC);
groupB = createOrganisationUnitGroup('B');
groupB.addOrganisationUnit(unitB);
DataSet dataSetA = createDataSet('A');
dataSetA.setUid("a23dataSetA");
dataSetA.addOrganisationUnit(unitA);
reportingRate = new ReportingRate(dataSetA);
expressionA = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionB = "#{" + deC.getUid() + SEPARATOR + coc.getUid() + "}-#{" + deD.getUid() + SEPARATOR + coc.getUid() + "}";
expressionC = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+#{" + deE.getUid() + "}-10";
expressionD = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+" + SYMBOL_DAYS;
expressionE = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*C{" + constantA.getUid() + "}";
expressionF = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}";
expressionG = expressionF + "+#{" + deB.getUid() + "}-#{" + deC.getUid() + "}";
expressionH = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*OUG{" + groupA.getUid() + "}";
expressionI = "#{" + opA.getDimensionItem() + "}*" + "#{" + deB.getDimensionItem() + "}+" + "C{" + constantA.getUid() + "}+5-" + "D{" + pdeA.getDimensionItem() + "}+" + "A{" + pteaA.getDimensionItem() + "}-10+" + "I{" + piA.getDimensionItem() + "}";
expressionJ = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionK = "1.5*avg(" + expressionJ + ")";
expressionL = expressionA + "+avg(" + expressionJ + ")+1.5*stddev(" + expressionJ + ")+" + expressionB;
expressionM = "#{" + deA.getUid() + SEPARATOR + SYMBOL_WILDCARD + "}-#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
expressionN = "#{" + deA.getUid() + SEPARATOR + cocA.getUid() + SEPARATOR + cocB.getUid() + "}-#{" + deB.getUid() + SEPARATOR + cocA.getUid() + "}";
expressionO = "#{" + opA.getDimensionItem() + "}+sum(#{" + opB.getDimensionItem() + "})";
expressionP = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
expressionR = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}" + " + R{" + reportingRate.getUid() + ".REPORTING_RATE}";
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DataApprovalStoreUserTest method testGetDataApprovalStatuses.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testGetDataApprovalStatuses() {
CategoryOption catOptionA = new CategoryOption("CategoryOptionA");
catOptionA.addOrganisationUnit(orgUnitB);
categoryService.addCategoryOption(catOptionA);
org.hisp.dhis.category.Category catA = createCategory('A', catOptionA);
categoryService.addCategory(catA);
CategoryCombo catComboA = createCategoryCombo('A', catA);
categoryService.addCategoryCombo(catComboA);
CategoryOptionCombo catOptionComboA = createCategoryOptionCombo(catComboA, catOptionA);
categoryService.addCategoryOptionCombo(catOptionComboA);
List<DataApprovalStatus> statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitA), orgUnitA.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
DataApprovalStatus status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
assertEquals(orgUnitA.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitA.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitB), orgUnitB.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
assertEquals(orgUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitB.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitC), orgUnitC.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_READY, status.getState());
assertEquals(orgUnitC.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitC.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitD), orgUnitD.getHierarchyLevel(), catComboA, null, null, null);
assertEquals(0, statuses.size());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DataSetNotificationServiceTest method setUpConfigurations.
private void setUpConfigurations() {
categoryOptionCombo = new CategoryOptionCombo();
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
organisationUnitA.setPhoneNumber(PHONE_NUMBER);
organisationUnitB.setPhoneNumber(PHONE_NUMBER);
periodA = createPeriod(new MonthlyPeriodType(), getDate(2000, 1, 1), getDate(2000, 1, 31));
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementA.setUid(DATA_ELEMENT_A_UID);
dataElementB.setUid(DATA_ELEMENT_B_UID);
dataSetA = createDataSet('A', new MonthlyPeriodType());
dataSetA.addDataSetElement(dataElementA);
dataSetA.addDataSetElement(dataElementB);
dataSetA.getSources().add(organisationUnitA);
dataSetA.getSources().add(organisationUnitB);
smsTemplateA = new DataSetNotificationTemplate();
smsTemplateA.setUid(TEMPALTE_A_UID);
smsTemplateA.setDataSetNotificationTrigger(DataSetNotificationTrigger.DATA_SET_COMPLETION);
smsTemplateA.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
smsTemplateA.setNotificationRecipient(DataSetNotificationRecipient.ORGANISATION_UNIT_CONTACT);
smsTemplateA.getDataSets().add(dataSetA);
emailTemplateB = new DataSetNotificationTemplate();
emailTemplateB.setUid(TEMPALTE_B_UID);
emailTemplateB.setDataSetNotificationTrigger(DataSetNotificationTrigger.DATA_SET_COMPLETION);
emailTemplateB.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL));
emailTemplateB.setNotificationRecipient(DataSetNotificationRecipient.ORGANISATION_UNIT_CONTACT);
emailTemplateB.getDataSets().add(dataSetA);
templates.add(smsTemplateA);
registrationA = new CompleteDataSetRegistration(dataSetA, periodA, organisationUnitA, categoryOptionCombo, new Date(), "", new Date(), "", true);
notificationMessage = new NotificationMessage("subject", "message");
summary = new OutboundMessageResponseSummary();
summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
summary.setChannel(DeliveryChannel.SMS);
successStatus = new BatchResponseStatus(Arrays.asList(summary));
}
Aggregations