use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class EventAnalyticsServiceMetadataTest method testGetQueryItemMetadata.
@Test
@SuppressWarnings("unchecked")
void testGetQueryItemMetadata() {
DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA));
QueryItem qiA = new QueryItem(deA, deA.getLegendSet(), deA.getValueType(), deA.getAggregationType(), null);
QueryItem qiB = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), deE.getOptionSet());
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(qiA).addItemFilter(qiB).withSkipData(true).withSkipMeta(false).withApiVersion(DhisApiVersion.V29).build();
Grid grid = eventAnalyticsService.getAggregatedEventData(params);
Map<String, Object> metadata = grid.getMetaData();
Map<String, MetadataItem> itemMap = (Map<String, MetadataItem>) metadata.get(AnalyticsMetaDataKey.ITEMS.getKey());
assertNotNull(itemMap.get(DimensionalObject.PERIOD_DIM_ID));
assertNotNull(itemMap.get(DimensionalObject.ORGUNIT_DIM_ID));
for (Legend legend : deA.getLegendSet().getLegends()) {
assertNotNull(itemMap.get(legend.getUid()));
}
for (Option option : deE.getOptionSet().getOptions()) {
assertNotNull(itemMap.get(option.getUid()));
}
assertNotNull(itemMap.get(deA.getUid()));
assertNotNull(itemMap.get(deE.getUid()));
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class EventAnalyticsUtilsTest method testGenerateEventDataPermutations.
@Test
void testGenerateEventDataPermutations() {
Map<String, List<EventAnalyticsDimensionalItem>> tableRows = new LinkedHashMap<>();
Grid grid = new ListGrid();
DataElement deA = createDataElement('A');
deA.setValueType(ValueType.BOOLEAN);
grid.addMetaData(deA.getUid(), deA);
TrackedEntityAttribute trackedEntityAttribute = createTrackedEntityAttribute('B');
OptionSet optionSet = new OptionSet();
optionSet.addOption(new Option("name", "code"));
trackedEntityAttribute.setOptionSet(optionSet);
grid.addMetaData(trackedEntityAttribute.getUid(), trackedEntityAttribute);
List<EventAnalyticsDimensionalItem> objects = new ArrayList<>();
Option t = new Option();
t.setCode("1");
t.setName("Yes");
Option f = new Option();
f.setCode("0");
f.setName("No");
objects.add(new EventAnalyticsDimensionalItem(t, deA.getUid()));
objects.add(new EventAnalyticsDimensionalItem(f, deA.getUid()));
objects.add(new EventAnalyticsDimensionalItem(new Option("name", "code"), trackedEntityAttribute.getUid()));
tableRows.put(deA.getUid(), objects);
tableRows.put(trackedEntityAttribute.getDimensionItem(), objects);
List<Map<String, EventAnalyticsDimensionalItem>> rowPermutations = EventAnalyticsUtils.generateEventDataPermutations(tableRows);
assertEquals(9, rowPermutations.size());
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DefaultPdfDataEntryFormService method insertTable_ProgramStageSections.
private void insertTable_ProgramStageSections(PdfPTable mainTable, Rectangle rectangle, PdfWriter writer, Collection<DataElement> dataElements) throws IOException, DocumentException {
boolean hasBorder = false;
// Add one to column count due to date entry + one hidden height set
// field.
int colCount = dataElements.size() + 1 + 1;
// Code 1
PdfPTable table = new PdfPTable(colCount);
float totalWidth = 800f;
float firstCellWidth_dateEntry = PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 3;
float lastCellWidth_hidden = PdfDataEntryFormUtil.UNITSIZE_DEFAULT;
float dataElementCellWidth = (totalWidth - firstCellWidth_dateEntry - lastCellWidth_hidden) / dataElements.size();
// Create 2 types of Rectangles, one for Date field, one for data
// elements - to be used when rendering them.
Rectangle rectangleDate = new Rectangle(0, 0, PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 2, PdfDataEntryFormUtil.UNITSIZE_DEFAULT);
Rectangle rectangleDataElement = new Rectangle(0, 0, dataElementCellWidth, PdfDataEntryFormUtil.UNITSIZE_DEFAULT);
// Cell Width Set
float[] cellWidths = new float[colCount];
// Date Field Settings
cellWidths[0] = firstCellWidth_dateEntry;
for (int i = 1; i < colCount - 1; i++) {
cellWidths[i] = dataElementCellWidth;
}
cellWidths[colCount - 1] = lastCellWidth_hidden;
table.setWidths(cellWidths);
// Create Header
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), "Date", Element.ALIGN_CENTER);
// Add Program Data Elements Columns
for (DataElement dataElement : dataElements) {
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback(), Element.ALIGN_CENTER);
}
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), TEXT_BLANK, Element.ALIGN_CENTER);
for (int rowNo = 1; rowNo <= PROGRAM_FORM_ROW_NUMBER; rowNo++) {
// Add Date Column
String strFieldDateLabel = PdfDataEntryFormUtil.LABELCODE_DATADATETEXTFIELD + Integer.toString(rowNo);
addCell_WithTextField(table, rectangleDate, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldDateLabel);
// Add Program Data Elements Columns
for (DataElement dataElement : dataElements) {
OptionSet optionSet = dataElement.getOptionSet();
String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + Long.toString(dataElement.getId()) + // Integer.toString(rowNo);
"_" + Integer.toString(rowNo);
if (optionSet != null) {
// Get All Option
String query = "";
// TODO: This gets repeated <- Create an array of the
// options. and apply only once.
List<Option> options = optionService.getOptions(optionSet.getId(), query, MAX_OPTIONS_DISPLAYED);
addCell_WithDropDownListField(table, rectangleDataElement, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, options.toArray(new String[0]), options.toArray(new String[0]));
} else {
// NOTE: When Rendering for DataSet, DataElement's OptionSet
// does not get rendered.
// Only for events, it gets rendered as dropdown list.
addCell_WithTextField(table, rectangleDataElement, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
}
}
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), TEXT_BLANK, Element.ALIGN_LEFT);
}
PdfPCell cell_withInnerTable = new PdfPCell(table);
cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
mainTable.addCell(cell_withInnerTable);
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOption.
public static Option createOption(char uniqueCharacter) {
Option option = new Option();
option.setAutoFields();
option.setName("Option" + uniqueCharacter);
option.setCode("OptionCode" + uniqueCharacter);
return option;
}
use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.
the class ProgramRuleActionValidationContextLoader method load.
@Transactional(readOnly = true)
public ProgramRuleActionValidationContext load(Preheat preheat, PreheatIdentifier preheatIdentifier, ProgramRuleAction ruleAction) {
ProgramRule rule = preheat.get(preheatIdentifier, ProgramRule.class, ruleAction.getProgramRule());
Program program = preheat.get(preheatIdentifier, Program.class, rule.getProgram());
List<ProgramStage> stages = preheat.getAll(preheatIdentifier, new ArrayList<>(program.getProgramStages()));
return ProgramRuleActionValidationContext.builder().programRule(rule).program(program).programStages(stages).dataElement(ruleAction.hasDataElement() ? preheat.get(preheatIdentifier, DataElement.class, ruleAction.getDataElement()) : null).trackedEntityAttribute(ruleAction.hasTrackedEntityAttribute() ? preheat.get(preheatIdentifier, TrackedEntityAttribute.class, ruleAction.getAttribute()) : null).notificationTemplate(ruleAction.hasNotification() ? preheat.get(preheatIdentifier, ProgramNotificationTemplate.class, ruleAction.getTemplateUid()) : null).programStageSection(ruleAction.hasProgramStageSection() ? preheat.get(preheatIdentifier, ProgramStageSection.class, ruleAction.getProgramStageSection()) : null).programStage(ruleAction.hasProgramStage() ? preheat.get(preheatIdentifier, ProgramStage.class, ruleAction.getProgramStage()) : null).option(ruleAction.hasOption() ? preheat.get(preheatIdentifier, Option.class, ruleAction.getOption()) : null).optionGroup(ruleAction.hasOptionGroup() ? preheat.get(preheatIdentifier, OptionGroup.class, ruleAction.getOptionGroup()) : null).programRuleActionValidationService(validationService).build();
}
Aggregations