Search in sources :

Example 1 with TrackedEntityInstanceQueryParams

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);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Grid(org.hisp.dhis.common.Grid) ActivityPlan(org.hisp.dhis.api.mobile.model.ActivityPlan) ArrayList(java.util.ArrayList) Activity(org.hisp.dhis.api.mobile.model.Activity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) List(java.util.List) PatientList(org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList) ArrayList(java.util.ArrayList) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 2 with TrackedEntityInstanceQueryParams

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;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Grid(org.hisp.dhis.common.Grid) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) EventStatus(org.hisp.dhis.event.EventStatus) ArrayList(java.util.ArrayList) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) List(java.util.List) PatientList(org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList) ArrayList(java.util.ArrayList) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)

Example 3 with TrackedEntityInstanceQueryParams

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;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryFilter(org.hisp.dhis.common.QueryFilter) Program(org.hisp.dhis.program.Program) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)

Example 4 with TrackedEntityInstanceQueryParams

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);
}
Also used : TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 5 with TrackedEntityInstanceQueryParams

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);
}
Also used : TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)12 Grid (org.hisp.dhis.common.Grid)9 List (java.util.List)6 ArrayList (java.util.ArrayList)5 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 QueryItem (org.hisp.dhis.common.QueryItem)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 Date (java.util.Date)3 EventStatus (org.hisp.dhis.event.EventStatus)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Activity (org.hisp.dhis.api.mobile.model.Activity)2 ActivityPlan (org.hisp.dhis.api.mobile.model.ActivityPlan)2 QueryFilter (org.hisp.dhis.common.QueryFilter)2 Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1