Search in sources :

Example 46 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeIsSetToCodeForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputDataElementIdSchemeIsSetToCodeForDataValueSet() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
    theDataQueryParams.setOutputDataElementIdScheme(CODE);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getUid())));
    assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getUid())));
    assertThat(responseMap.get(dataElementA.getUid()), is(equalTo(dataElementA.getCode())));
    assertThat(responseMap.get(dataElementB.getUid()), is(equalTo(dataElementB.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(equalTo(categoryOptionComboC.getCode())));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 47 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method stubDataElementOperands.

private List<DataElementOperand> stubDataElementOperands() {
    final DataElement dataElementA = new DataElement("NameA");
    dataElementA.setUid("uid1234567A");
    dataElementA.setCode("CodeA");
    final DataElement dataElementB = new DataElement("NameB");
    dataElementB.setUid("uid1234567B");
    dataElementB.setCode("CodeB");
    final CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    categoryOptionCombo.setName("NameC");
    categoryOptionCombo.setUid("uid1234567C");
    categoryOptionCombo.setCode("CodeC");
    final DataElementOperand dataElementOperandA = new DataElementOperand(dataElementA, categoryOptionCombo);
    final DataElementOperand dataElementOperandB = new DataElementOperand(dataElementB, categoryOptionCombo);
    return newArrayList(dataElementOperandA, dataElementOperandB);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 48 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToUid.

@Test
void testGetSchemeIdResponseMapWhenOutputIdSchemeIsSetToUid() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub);
    theDataQueryParams.setOutputIdScheme(UUID);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(emptyOrNullString()));
    assertThat(responseMap.get(periodIsoDate), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 49 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class SchemaIdResponseMapperTest method testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToCodeForDataValueSet.

@Test
void testGetSchemeIdResponseMapWhenOutputOrgUnitIdSchemeIsSetToCodeForDataValueSet() {
    // Given
    final List<DataElementOperand> dataElementOperandsStub = stubDataElementOperands();
    final OrganisationUnit orUnitStub = stubOrgUnit();
    final Period periodStub = stubPeriod();
    final DataQueryParams theDataQueryParams = stubQueryParams(dataElementOperandsStub, orUnitStub, periodStub, DATA_VALUE_SET);
    theDataQueryParams.setOutputOrgUnitIdScheme(CODE);
    // When
    final Map<String, String> responseMap = schemaIdResponseMapper.getSchemeIdResponseMap(theDataQueryParams);
    // Then
    final String orgUnitUid = orUnitStub.getUid();
    final String periodIsoDate = periodStub.getIsoDate();
    final DataElement dataElementA = dataElementOperandsStub.get(0).getDataElement();
    final DataElement dataElementB = dataElementOperandsStub.get(1).getDataElement();
    final CategoryOptionCombo categoryOptionComboC = dataElementOperandsStub.get(0).getCategoryOptionCombo();
    assertThat(responseMap.get(orgUnitUid), is(equalTo(orUnitStub.getCode())));
    assertThat(responseMap.get(periodIsoDate), is(equalTo(periodStub.getUid())));
    assertThat(responseMap.get(dataElementA.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(dataElementB.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
    assertThat(responseMap.get(categoryOptionComboC.getUid()), is(emptyOrNullString()));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Period(org.hisp.dhis.period.Period) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) PeriodType.getPeriodFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodFromIsoString) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 50 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultPdfDataEntryFormService method insertTable_DataSetSections.

private void insertTable_DataSetSections(PdfPTable mainTable, PdfWriter writer, Rectangle rectangle, Collection<DataElement> dataElements, String sectionName) throws IOException, DocumentException {
    boolean hasBorder = true;
    // Add Section Name and Section Spacing
    insertTable_TextRow(writer, mainTable, TEXT_BLANK);
    if (sectionName != null && !sectionName.isEmpty()) {
        insertTable_TextRow(writer, mainTable, sectionName, pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_SECTIONHEADER));
    }
    // Create A Table To Add For Each Section
    PdfPTable table = new PdfPTable(2);
    table.setWidths(new int[] { 2, 1 });
    table.setWidthPercentage(100.0f);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    // row.
    for (DataElement dataElement : dataElements) {
        for (CategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
            String categoryOptionComboDisplayName = "";
            // Hide Default category option combo name
            if (!categoryOptionCombo.isDefault()) {
                categoryOptionComboDisplayName = categoryOptionCombo.getDisplayName();
            }
            addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback() + " " + categoryOptionComboDisplayName, Element.ALIGN_RIGHT);
            String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + dataElement.getUid() + "_" + categoryOptionCombo.getUid();
            ValueType valueType = dataElement.getValueType();
            // Yes Only case - render as check-box
            if (ValueType.TRUE_ONLY == valueType) {
                addCell_WithCheckBox(table, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            } else if (ValueType.BOOLEAN == valueType) {
                // Create Yes - true, No - false, Select..
                String[] optionList = new String[] { "[No Value]", "Yes", "No" };
                String[] valueList = new String[] { "", "true", "false" };
                // addCell_WithRadioButton(table, writer, strFieldLabel);
                addCell_WithDropDownListField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, optionList, valueList);
            } else if (valueType.isNumeric()) {
                Rectangle rectNum = new Rectangle(TEXTBOXWIDTH_NUMBERTYPE, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
                addCell_WithTextField(table, rectNum, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER);
            } else {
                addCell_WithTextField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            }
        }
    }
    PdfPCell cell_withInnerTable = new PdfPCell(table);
    cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
    mainTable.addCell(cell_withInnerTable);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) PdfPCell(com.lowagie.text.pdf.PdfPCell) PdfPTable(com.lowagie.text.pdf.PdfPTable) ValueType(org.hisp.dhis.common.ValueType) Rectangle(com.lowagie.text.Rectangle) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16