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;
}
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;
}
Aggregations