Search in sources :

Example 1 with EventStatus

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;
}
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 2 with EventStatus

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 "";
    }
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) NotAllowedException(org.hisp.dhis.api.mobile.NotAllowedException) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Grid(org.hisp.dhis.common.Grid) EventStatus(org.hisp.dhis.event.EventStatus) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) 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 EventStatus

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;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) WebMessageService(org.hisp.dhis.webapi.service.WebMessageService) StringUtils(org.apache.commons.lang3.StringUtils) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) GridUtils(org.hisp.dhis.system.grid.GridUtils) ContextService(org.hisp.dhis.webapi.service.ContextService) DxfNamespaces(org.hisp.dhis.common.DxfNamespaces) OrganisationUnitSelectionMode(org.hisp.dhis.common.OrganisationUnitSelectionMode) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) MediaType(org.springframework.http.MediaType) CacheStrategy(org.hisp.dhis.common.cache.CacheStrategy) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) TrackedEntityInstanceSchemaDescriptor(org.hisp.dhis.schema.descriptors.TrackedEntityInstanceSchemaDescriptor) Collectors(java.util.stream.Collectors) List(java.util.List) RootNode(org.hisp.dhis.node.types.RootNode) Joiner(com.google.common.base.Joiner) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) WebMessageUtils(org.hisp.dhis.dxf2.webmessage.WebMessageUtils) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) Pager(org.hisp.dhis.common.Pager) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Grid(org.hisp.dhis.common.Grid) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ProgramStatus(org.hisp.dhis.program.ProgramStatus) HttpStatus(org.springframework.http.HttpStatus) TextUtils(org.hisp.dhis.commons.util.TextUtils) InputStream(java.io.InputStream) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Date (java.util.Date)3 List (java.util.List)3 Grid (org.hisp.dhis.common.Grid)3 EventStatus (org.hisp.dhis.event.EventStatus)3 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)3 ArrayList (java.util.ArrayList)2 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)2 QueryItem (org.hisp.dhis.common.QueryItem)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 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ObjectUtils (org.apache.commons.lang3.ObjectUtils)1