use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.
the class DefaultTrackedEntityInstanceService method getQueryItem.
/**
* Creates a QueryItem from the given item string. Item is on format
* {attribute-id}:{operator}:{filter-value}[:{operator}:{filter-value}].
* Only the attribute-id is mandatory.
*/
private QueryItem getQueryItem(String item) {
String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || (split.length % 2 != 1)) {
throw new IllegalQueryException("Query item or filter is invalid: " + item);
}
QueryItem queryItem = getItem(split[0]);
if (// Filters specified
split.length > 1) {
for (int i = 1; i < split.length; i += 2) {
QueryOperator operator = QueryOperator.fromString(split[i]);
queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
}
}
return queryItem;
}
use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.
the class DefaultTrackedEntityInstanceService method getQueryFilter.
/**
* Creates a QueryFilter from the given query string. Query is on format
* {operator}:{filter-value}. Only the filter-value is mandatory. The EQ
* QueryOperator is used as operator if not specified.
*/
private QueryFilter getQueryFilter(String query) {
if (query == null || query.isEmpty()) {
return null;
}
if (!query.contains(DimensionalObject.DIMENSION_NAME_SEP)) {
return new QueryFilter(QueryOperator.EQ, query);
} else {
String[] split = query.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || split.length != 2) {
throw new IllegalQueryException("Query has invalid format: " + query);
}
QueryOperator op = QueryOperator.fromString(split[0]);
return new QueryFilter(op, split[1]);
}
}
use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.
the class RequestToSearchParamsMapper method getQueryItem.
private QueryItem getQueryItem(String item) {
String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || split.length % 2 != 1) {
throw new IllegalQueryException("Query item or filter is invalid: " + item);
}
QueryItem queryItem = getItem(split[0]);
if (split.length > 1) {
for (int i = 1; i < split.length; i += 2) {
QueryOperator operator = QueryOperator.fromString(split[i]);
queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
}
}
return queryItem;
}
use of org.hisp.dhis.common.QueryOperator in project dhis2-core by dhis2.
the class AbstractEventService method getQueryItem.
private QueryItem getQueryItem(String item) {
String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || split.length % 2 != 1) {
throw new IllegalQueryException("Query item or filter is invalid: " + item);
}
QueryItem queryItem = getItem(split[0]);
if (split.length > 1) {
for (int i = 1; i < split.length; i += 2) {
QueryOperator operator = QueryOperator.fromString(split[i]);
queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
}
}
return queryItem;
}
use of org.hisp.dhis.common.QueryOperator 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;
}
Aggregations