Search in sources :

Example 26 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method findPatientInAdvanced.

/**
     * keyword is on format of
     * {attribute-id1}:{operator1}:{filter-value1};{attribute
     * -id2}:{operator2}:{filter-value2}
     */
@Override
public String findPatientInAdvanced(String keyword, int orgUnitId, int programId) throws NotAllowedException {
    TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
    List<TrackedEntityAttribute> displayAttributes = new ArrayList<>(attributeService.getTrackedEntityAttributesDisplayInList());
    for (TrackedEntityAttribute trackedEntityAttribute : displayAttributes) {
        QueryItem queryItem = new QueryItem(trackedEntityAttribute);
        param.addAttribute(queryItem);
    }
    if (programId != 0) {
        param.setProgram(programService.getProgram(programId));
    }
    if (orgUnitId != 0) {
        param.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
        param.setOrganisationUnitMode(OrganisationUnitSelectionMode.SELECTED);
    } else {
        param.setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL);
    }
    String[] items = keyword.split(";");
    if (items == null) {
        items = new String[1];
        items[0] = keyword;
    }
    for (int i = 0; i < items.length; i++) {
        String[] split = keyword.split(":");
        if (split == null || (split.length != 3 && split.length != 2)) {
            throw NotAllowedException.INVALID_FILTER;
        }
        if (split.length == 2) {
            QueryOperator operator = QueryOperator.fromString(split[0]);
            param.setQuery(new QueryFilter(operator, split[1]));
        } else {
            TrackedEntityAttribute at = attributeService.getTrackedEntityAttributeByName(split[0]);
            QueryItem queryItem = new QueryItem(at, at.getLegendSets().get(0), at.getValueType(), at.getAggregationType(), at.getOptionSet());
            QueryOperator operator = QueryOperator.fromString(split[1]);
            queryItem.getFilters().add(new QueryFilter(operator, split[2]));
            param.getFilters().add(queryItem);
        }
    }
    Grid trackedEntityInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
    List<List<Object>> listOfTrackedEntityInstance = trackedEntityInstanceGrid.getRows();
    if (listOfTrackedEntityInstance.size() == 0) {
        throw NotAllowedException.NO_BENEFICIARY_FOUND;
    }
    /**
         * Grid columns: 0 = instance 1 = created 2 = lastupdated 3 = ou 4 = te
         * 5 onwards = attributes
         */
    int instanceIndex = 0;
    int teIndex = 4;
    List<Integer> attributesIndex = new ArrayList<>();
    List<GridHeader> headers = trackedEntityInstanceGrid.getHeaders();
    int index = 0;
    for (GridHeader header : headers) {
        if (header.getName().equals("instance")) {
            instanceIndex = index;
        } else if (header.getName().equals("te")) {
            teIndex = index;
        } else if (!header.getName().equals("created") && !header.getName().equals("lastupdated") && !header.getName().equals("ou")) {
            attributesIndex.add(new Integer(index));
        }
        index++;
    }
    String instanceInfo = "";
    String trackedEntityName = "";
    for (List<Object> row : listOfTrackedEntityInstance) {
        TrackedEntity te = trackedEntityService.getTrackedEntity((String) row.get(teIndex));
        if (!trackedEntityName.equals(te.getDisplayName())) {
            trackedEntityName = te.getDisplayName();
            instanceInfo += te.getDisplayName() + "$";
        }
        // NOTE: this line should be here but because the mobile client uses
        // the int TEI id, we will temprarily get the int id for now.
        // instanceInfo += (String) row.get( instanceIndex ) + "/";
        TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance((String) row.get(instanceIndex));
        instanceInfo += tei.getId() + "/";
        // end of temproary fix
        String attText = "";
        for (Integer attIndex : attributesIndex) {
            if (row.get(attIndex.intValue()) != null) {
                attText += (String) row.get(attIndex.intValue()) + " ";
            }
        }
        instanceInfo += attText.trim() + "$";
    }
    return instanceInfo;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) GridHeader(org.hisp.dhis.common.GridHeader) QueryFilter(org.hisp.dhis.common.QueryFilter) List(java.util.List) PatientList(org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList) ArrayList(java.util.ArrayList) QueryOperator(org.hisp.dhis.common.QueryOperator) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)

Example 27 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class ExportAnalysisResultAction method generateGrid.

@SuppressWarnings("unchecked")
private Grid generateGrid() {
    List<DeflatedDataValue> results = (List<DeflatedDataValue>) SessionUtils.getSessionVar(GetAnalysisAction.KEY_ANALYSIS_DATA_VALUES);
    Grid grid = new ListGrid();
    grid.setTitle(i18n.getString("data_analysis_report"));
    grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
    grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
    grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
    grid.addHeader(new GridHeader(i18n.getString("min"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("max"), false, false));
    for (DeflatedDataValue dataValue : results) {
        Period period = dataValue.getPeriod();
        grid.addRow();
        grid.addValue(dataValue.getDataElementName());
        grid.addValue(dataValue.getSourceName());
        grid.addValue(format.formatPeriod(period));
        grid.addValue(dataValue.getMin());
        grid.addValue(dataValue.getValue());
        grid.addValue(dataValue.getMax());
    }
    return grid;
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) List(java.util.List) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)27 Grid (org.hisp.dhis.common.Grid)14 ArrayList (java.util.ArrayList)9 ListGrid (org.hisp.dhis.system.grid.ListGrid)9 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 QueryItem (org.hisp.dhis.common.QueryItem)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)2 MetadataObject (org.hisp.dhis.common.MetadataObject)2 Pager (org.hisp.dhis.common.Pager)2 Period (org.hisp.dhis.period.Period)2 CsvWriter (com.csvreader.CsvWriter)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1