use of org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getCurrentActivityPlan.
@Override
public ActivityPlan getCurrentActivityPlan(OrganisationUnit unit, String localeString) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 30);
long upperBound = cal.getTime().getTime();
cal.add(Calendar.DATE, -60);
long lowerBound = cal.getTime().getTime();
List<Activity> items = new ArrayList<>();
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams().addOrganisationUnit(unit);
Grid trackedEntityDrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> entityInstanceList = trackedEntityDrid.getRows();
for (List<Object> entityInstance : entityInstanceList) {
TrackedEntityInstance trackedEntityInstance = entityInstanceService.getTrackedEntityInstance(entityInstance.get(0).toString());
for (ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(trackedEntityInstance, EventStatus.ACTIVE)) {
if (programStageInstance.getDueDate().getTime() >= lowerBound && programStageInstance.getDueDate().getTime() <= upperBound) {
items.add(getActivity(programStageInstance, false));
}
}
}
if (items.isEmpty()) {
return null;
}
Collections.sort(items, activityComparator);
return new ActivityPlan(items);
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findVisitSchedule.
@Override
public String findVisitSchedule(int orgUnitId, int programId, String info) throws NotAllowedException {
String status = info.substring(0, info.indexOf("$"));
String fromDays = info.substring(info.indexOf("$") + 1, info.indexOf("/"));
String toDays = info.substring(info.indexOf("/") + 1);
// Event Status
EventStatus eventStatus = null;
if (status.equals("Schedule in future")) {
eventStatus = EventStatus.SCHEDULE;
} else if (status.equals("Overdue")) {
eventStatus = EventStatus.OVERDUE;
} else if (status.equals("Incomplete")) {
eventStatus = EventStatus.VISITED;
} else if (status.equals("Completed")) {
eventStatus = EventStatus.COMPLETED;
} else if (status.equals("Skipped")) {
eventStatus = EventStatus.SKIPPED;
}
// From/To Date
Date fromDate = getDate(-1, fromDays);
Date toDate = getDate(1, toDays);
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
List<TrackedEntityAttribute> trackedEntityAttributeList = new ArrayList<>(attributeService.getTrackedEntityAttributesByDisplayOnVisitSchedule(true));
for (TrackedEntityAttribute trackedEntityAttribute : trackedEntityAttributeList) {
QueryItem queryItem = new QueryItem(trackedEntityAttribute);
param.addAttribute(queryItem);
}
param.setProgram(programService.getProgram(programId));
param.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
param.setEventStatus(eventStatus);
param.setEventStartDate(fromDate);
param.setEventEndDate(toDate);
Grid programStageInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> listOfListProgramStageInstance = programStageInstanceGrid.getRows();
if (listOfListProgramStageInstance.size() == 0) {
throw NotAllowedException.NO_EVENT_FOUND;
}
String eventsInfo = "";
for (List<Object> row : listOfListProgramStageInstance) {
TrackedEntityInstance instance = entityInstanceService.getTrackedEntityInstance((String) row.get(0));
Collection<TrackedEntityAttribute> displayAttributes = attributeService.getTrackedEntityAttributesDisplayInList();
eventsInfo += instance.getId() + "/";
String displayName = "";
for (TrackedEntityAttribute displayAttribute : displayAttributes) {
TrackedEntityAttributeValue value = attValueService.getTrackedEntityAttributeValue(instance, displayAttribute);
if (value != null) {
displayName += value.getValue() + " ";
}
}
eventsInfo += displayName.trim() + "$";
}
return eventsInfo;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams in project dhis2-core by dhis2.
the class DefaultTrackedEntityInstanceService method getFromUrl.
@Override
public TrackedEntityInstanceQueryParams getFromUrl(String query, Set<String> attribute, Set<String> filter, Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Boolean followUp, Date lastUpdatedStartDate, Date lastUpdatedEndDate, Date programEnrollmentStartDate, Date programEnrollmentEndDate, Date programIncidentStartDate, Date programIncidentEndDate, String trackedEntity, EventStatus eventStatus, Date eventStartDate, Date eventEndDate, boolean skipMeta, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, boolean includeDeleted, List<String> orders) {
TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
QueryFilter queryFilter = getQueryFilter(query);
if (attribute != null) {
for (String attr : attribute) {
QueryItem it = getQueryItem(attr);
params.getAttributes().add(it);
}
}
if (filter != null) {
for (String filt : filter) {
QueryItem it = getQueryItem(filt);
params.getFilters().add(it);
}
}
if (ou != null) {
for (String orgUnit : ou) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
if (organisationUnit == null) {
throw new IllegalQueryException("Organisation unit does not exist: " + orgUnit);
}
params.getOrganisationUnits().add(organisationUnit);
}
}
Program pr = program != null ? programService.getProgram(program) : null;
if (program != null && pr == null) {
throw new IllegalQueryException("Program does not exist: " + program);
}
TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity(trackedEntity) : null;
if (trackedEntity != null && te == null) {
throw new IllegalQueryException("Tracked entity does not exist: " + program);
}
params.setQuery(queryFilter).setProgram(pr).setProgramStatus(programStatus).setFollowUp(followUp).setLastUpdatedStartDate(lastUpdatedStartDate).setLastUpdatedEndDate(lastUpdatedEndDate).setProgramEnrollmentStartDate(programEnrollmentStartDate).setProgramEnrollmentEndDate(programEnrollmentEndDate).setProgramIncidentStartDate(programIncidentStartDate).setProgramIncidentEndDate(programIncidentEndDate).setTrackedEntity(te).setOrganisationUnitMode(ouMode).setEventStatus(eventStatus).setEventStartDate(eventStartDate).setEventEndDate(eventEndDate).setSkipMeta(skipMeta).setPage(page).setPageSize(pageSize).setTotalPages(totalPages).setSkipPaging(skipPaging).setIncludeDeleted(includeDeleted).setOrders(orders);
return params;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceQueryTest method testValidateNoOrgUnitsModeAll.
@Test
public void testValidateNoOrgUnitsModeAll() {
TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL);
instanceService.validate(params);
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method queryTrackedEntityInstancesJson.
@RequestMapping(value = "/query", method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@ResponseBody
public Grid queryTrackedEntityInstancesJson(@RequestParam(required = false) String query, @RequestParam(required = false) Set<String> attribute, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEnrollmentStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) Date programEnrollmentEndDate, @RequestParam(required = false) Date programIncidentStartDate, @RequestParam(required = false) Date programIncidentEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date eventStartDate, @RequestParam(required = false) Date eventEndDate, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) boolean includeDeleted, @RequestParam(required = false) String order, Model model, HttpServletResponse response) throws Exception {
programEnrollmentStartDate = ObjectUtils.firstNonNull(programEnrollmentStartDate, programStartDate);
programEnrollmentEndDate = ObjectUtils.firstNonNull(programEnrollmentEndDate, programEndDate);
Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
TrackedEntityInstanceQueryParams params = instanceService.getFromUrl(query, attribute, filter, orgUnits, ouMode, program, programStatus, followUp, lastUpdatedStartDate, lastUpdatedEndDate, programEnrollmentStartDate, programEnrollmentEndDate, programIncidentStartDate, programIncidentEndDate, trackedEntity, eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize, totalPages, skipPaging, includeDeleted, getOrderParams(order));
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE);
return instanceService.getTrackedEntityInstancesGrid(params);
}
Aggregations