com.rr.wabshs.ui.mci.mciController.java Source code

Java tutorial

Introduction

Here is the source code for com.rr.wabshs.ui.mci.mciController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rr.wabshs.ui.mci;

import com.rr.wabshs.ui.security.decryptObject;
import com.rr.wabshs.ui.security.encryptObject;
import com.registryKit.user.User;
import com.registryKit.program.programManager;
import com.registryKit.program.program;
import com.registryKit.client.clientManager;
import com.registryKit.client.mciManager;
import com.registryKit.client.storageClientAddressInfo;
import com.registryKit.client.storageClients;
import com.registryKit.user.userManager;
import com.registryKit.user.userProgramModules;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;

/**
 *
 * @author chadmccue
 */
@Controller
@RequestMapping("/mci")
public class mciController {

    private static Integer moduleId = 2;

    @Autowired
    private programManager programmanager;

    @Autowired
    private clientManager clientmanager;

    @Autowired
    private mciManager mcimanager;

    @Autowired
    private userManager usermanager;

    @Value("${programId}")
    private Integer programId;

    @Value("${topSecret}")
    private String topSecret;

    private static boolean allowReconcile = false;

    /**
     * The '' request will display the list of pending clients.
     *
     * @param request
     * @param response
     * @return   the administrator dashboard view
     * @throws Exception
     */
    @RequestMapping(value = "/client/pending", method = RequestMethod.GET)
    public ModelAndView listPendingClients(HttpServletRequest request, HttpServletResponse response,
            HttpSession session) throws Exception {

        program programDetails = programmanager.getProgramById(programId);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("/clients/pending");

        /* Get a list of completed surveys the logged in user has access to */
        User userDetails = (User) session.getAttribute("userDetails");

        /* Get user permissions */
        userProgramModules modulePermissions = usermanager.getUserModulePermissions(programId, userDetails.getId(),
                moduleId);
        Integer userId = 0;
        if (userDetails.getRoleId() == 2) {
            allowReconcile = true;
        } else {
            allowReconcile = modulePermissions.isAllowReconcile();
            userId = userDetails.getId();
        }

        /* Get the client */
        List<Integer> clientIds = mcimanager.getPendingClients(programId);
        List<clientpending> pendingClients = new ArrayList<clientpending>();

        if (clientIds != null && clientIds.size() > 0) {
            for (Integer id : clientIds) {
                storageClients clientDetails = clientmanager.getClientDetails(id);
                storageClientAddressInfo addressInfo = clientmanager.getClientAddressInfo(id);

                clientpending c = new clientpending();

                if (clientDetails != null) {
                    if (clientDetails.getFirstName() != null && clientDetails.getLastName() != null) {
                        c.setName(clientDetails.getFirstName() + " " + clientDetails.getLastName());
                    }
                    c.setPatientNumber(clientDetails.getSourcePatientId());
                    c.setEmail(clientDetails.getEmail());
                    c.setDateReferred(clientDetails.getDateCreated());
                }

                if (addressInfo != null) {
                    c.setAddress(addressInfo.getAddress1());
                    c.setAddress2(addressInfo.getAddress2());
                    c.setCity(addressInfo.getCity());
                    c.setState(addressInfo.getState());
                    c.setZip(addressInfo.getZipCode());
                    c.setPhoneNumber(addressInfo.getPhone1());
                }

                encryptObject encrypt = new encryptObject();
                Map<String, String> map;

                //Encrypt the use id to pass in the url
                map = new HashMap<String, String>();
                map.put("id", Integer.toString(id));
                map.put("topSecret", topSecret);

                String[] encrypted = encrypt.encryptObject(map);

                c.setEncryptedId(encrypted[0]);
                c.setEncryptedSecret(encrypted[1]);

                pendingClients.add(c);
            }

        }

        mav.addObject("pendingClients", pendingClients);
        mav.addObject("allowReconcile", allowReconcile);

        return mav;
    }

}