use of org.hisp.dhis.event.EventStatus 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.event.EventStatus in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findLostToFollowUp.
@Override
public String findLostToFollowUp(int orgUnitId, String searchEventInfos) throws NotAllowedException {
String[] searchEventInfosArray = searchEventInfos.split("-");
EventStatus eventStatus = EventStatus.ACTIVE;
if (searchEventInfosArray[1].equalsIgnoreCase("Scheduled in future")) {
eventStatus = EventStatus.SCHEDULE;
} else if (searchEventInfosArray[1].equalsIgnoreCase("Overdue")) {
eventStatus = EventStatus.OVERDUE;
}
String eventsInfo = "";
Calendar toCalendar = new GregorianCalendar();
toCalendar.add(Calendar.DATE, -1);
toCalendar.add(Calendar.YEAR, 100);
Date toDate = toCalendar.getTime();
Calendar fromCalendar = new GregorianCalendar();
fromCalendar.add(Calendar.DATE, -1);
fromCalendar.add(Calendar.YEAR, -100);
Date fromDate = fromCalendar.getTime();
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.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
param.setEventStatus(eventStatus);
param.setEventStartDate(fromDate);
param.setEventEndDate(toDate);
Grid programStageInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> rows = programStageInstanceGrid.getRows();
if (rows.size() == 0) {
throw NotAllowedException.NO_EVENT_FOUND;
} else if (rows.size() > 0) {
for (List<Object> row : rows) {
for (int i = 5; i < row.size(); i++) {
eventsInfo += row.get(i) + "/";
if (i == row.size() - 1) {
eventsInfo += "$";
}
}
}
throw new NotAllowedException(eventsInfo);
} else {
return "";
}
}
use of org.hisp.dhis.event.EventStatus in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method getTrackedEntityInstances.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityInstances(@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) String trackedEntityInstance, @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) throws Exception {
programEnrollmentStartDate = ObjectUtils.firstNonNull(programEnrollmentStartDate, programStartDate);
programEnrollmentEndDate = ObjectUtils.firstNonNull(programEnrollmentEndDate, programEndDate);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
RootNode rootNode = NodeUtils.createMetadata();
List<TrackedEntityInstance> trackedEntityInstances;
TrackedEntityInstanceQueryParams queryParams = 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));
if (trackedEntityInstance == null) {
trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, getTrackedEntityInstanceParams(fields));
} else {
Set<String> trackedEntityInstanceIds = TextUtils.splitToArray(trackedEntityInstance, TextUtils.SEMICOLON);
trackedEntityInstances = trackedEntityInstanceIds != null ? trackedEntityInstanceIds.stream().map(id -> trackedEntityInstanceService.getTrackedEntityInstance(id, getTrackedEntityInstanceParams(fields))).collect(Collectors.toList()) : null;
}
if (queryParams.isPaging() && queryParams.isTotalPages()) {
int count = trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams);
Pager pager = new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault());
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(TrackedEntityInstance.class, trackedEntityInstances, fields));
return rootNode;
}
Aggregations