public function newList($request, $response)
    {/*{{{*/
        $response->controller = 'Index';
        $response->object = 'flow';
        $this->initialize($request, $response);
        $this->forceSpaceModuleCheck('Case', $response);

        //threads总数和flow总数
        $threadsCount = ThreadClient::getInstance()->getUnSpacePostThreadsCount($this->_newSpace->id,
            $this->_newUser->id, array('isBrowser'=>$this->_newUser->isNull()));
        $flowsCount = FlowClient::getInstance()->getFlowListCount($this->_newSpace->id, array('p_type'=>'all', 'isBrowser'=>$this->_newUser->isNull()));
        $response->flowCount = $threadsCount + $flowsCount;

        $options = array();
        $options['filterUserId'] = $this->_newUser->id;
        $options['spaceId'] = $this->_newSpace->id;
        $nowPage = intval($request->getRequest('p', 1));
        $nowPage = $nowPage > 0 ? $nowPage : 1;
        $pageSize = 25;

        $freeFlowCount = FlowClient::getInstance()->getFreeFlowCntBySpace($this->_newSpace, $needCache = false);
        $chargeFlowCount = FlowClient::getInstance()->getPaiedFlowCntBySpace($this->_newSpace, $needCache = false);
        $response->chargeFlowCount = $chargeFlowCount;

        $threadOptions = array();
        $threadOptions['nowPage'] = $nowPage;
        $threadOptions['pageSize'] = $pageSize;
        if (false == $this->_newUser->isNull())
        {
            $threadOptions['excludeuser'] = $this->_newUser->id;
        }
        $unPostThreadList = ThreadClient::getInstance()->getUnSpacePostThreads($this->_newSpace->id, $this->_newUser->id, $threadOptions);
        $myThreadIds = array();
        if (false == $this->_newUser->isNull())
        {
            $myThreadIds = ThreadClient::getInstance()->getMyThreadInSpace($this->_newSpace->id, $this->_newUser->id);
        }
        $nowPageThreadCount = count($unPostThreadList);
        if ($nowPageThreadCount < $pageSize)
        {
            if ($nowPageThreadCount > 0)
            {
                $options['from'] = 0;
                $options['pageSize'] = $pageSize - $nowPageThreadCount;
            }
            else
            {
                $options['from'] = (($nowPage-1) * $pageSize == $threadsCount - count($myThreadIds)) ? 0 : (($nowPage - 1) * $pageSize - $threadsCount + count($myThreadIds)) ;
                $options['pageSize'] = $pageSize;
            }
            $res = FlowClient::getInstance()->getAllFlows($options);
            $flowList = $unPostThreadList + $res['refs'];
        }
        else
        {
            $flowList = $unPostThreadList;
        }

        $userSelfFlowCnt = 0;
        if(false == $this->_newUser->isNull())
        {
            $userSelfFlowCnt = FlowClient::getInstance()->getAllFlowCnt(array('spaceId' => $this->_newSpace->id, 'userId' => $this->_newUser->id));
        }

        $pageInfo = Pager::calcPageInfo(($freeFlowCount + $chargeFlowCount + $threadsCount - $userSelfFlowCnt), $nowPage, $pageSize);
        $response->pagelink = PageNav::getNavLink(PageNav::getPageNavTemplate("?&p="), $pageInfo['nowpage'], $pageInfo['pagesize'], $pageInfo['total']);

        $userSelf = array();
        //当前患者的流
        if($nowPage == 1 && $this->_newUser->isNull() == false && $this->_newUser->id != $this->_newSpace->user->id)
        {
            $userSelf = ThreadClient::getInstance()->getMyThreadAndFlowInSpace($this->_newSpace->id, $this->_newUser->id);
            if(false == empty($userSelf))
            {
                $response->lastPostList = DoctorPatientPostClient::getInstance()->getLastPosts4Flows(array_keys($userSelf));
            }
        }

        //取intention
        $intentionList = array();
        if(false == $this->_newUser->isNull())
        {
            $intentionList = IntentionClient::getInstance()->queryThreadIntentions($this->_newUser->id, '', '', $this->_newSpace->id);
        }

        $response->out = array_merge($intentionList, $userSelf , $flowList);
        $response->flowList = $response->out;
        $this->getCommonData($request, $response, $userSelf + $flowList);
    }/*}}}*/
    public function spacePatient($request, $response)
    {/*{{{*/
        $ref = DAL::get()->find('DoctorPatientRef', $request->id);
                
        $groups = ForumClient::getInstance()->getGroupListByPatientIdAndSpaceId($ref->patient->id, $this->_newSpace->id);
        $response->groupList = $groups;
        $response->otherThreads = ThreadClient::getInstance()->getOtherRelatedThreads4Patient($ref->patient->id, $this->_newSpace->id);
        //报道信息内容
        $patientSignin = DAL::get()->find_by_patientid_and_spaceid('FollowupOwner', $ref->patient->id, 
            $this->_newSpace->id);
        $signinProblems = array();
        if($patientSignin->isNull() == false)
        {
            $signinProblems = $patientSignin->getNfsDisease()->getSigninHealthProblems();
        }
        $response->signinProblems = $signinProblems;        
        $response->ref = $ref;
        $response->hasBooking = $request->b;
        $response->hasTel = $request->t;





        
      $doctorPatientRefId = $ref->id;
      $response->refid = $doctorPatientRefId;

      $doctorPatientRef = DAL::get()->find('DoctorPatientRef', $doctorPatientRefId);

      $patientRealName = $doctorPatientRef->patient->name;
      $response->patientRealName = $patientRealName;

      $patientId = $doctorPatientRef->patient->id;
      $spaceId = $doctorPatientRef->space->id;
      $followupOwner = DAL::get()->find_by_spaceid_and_patientid("followupowner", $spaceId, $patientId);

      $followupNote = DAL::get()->find_by_patientsigninid('FollowupNote', $followupOwner->id);

      $response->patientSigninId = $followupOwner->id;
      $response->content = $followupNote->content;

    }/*}}}*/
	/** 查看某个用户的所有问题 */
    public function ajaxUserAllCase($request, $response)
    {
    	header('Content-Type: text/html; charset=GBK');
        $caseId = $request->case_id;
        $page = intval($request->getRequest('page', 1));
        
        $thread = DAL::get()->find('thread', $caseId);
        $results = ThreadClient::getInstance()->getListForUser($thread->user->id, $page, 8);
        
        $pageInfo = array();
        $threadList = array();
        $pagelink= '';
        if($results)
        {
            $threadList = $results['threads'];
            $pageInfo = $results['page'];
        }
        if(empty($pageInfo) == false)
        {
            $pagelink = PageNav::getNavLink(PageNav::getPageNavTemplate(
                'javascript:goUserCasePage(', 2, 5, 1, true, ');'), 
                $pageInfo['nowpage'], $pageInfo['pagesize'], $pageInfo['total']);
        }
        $response->pagelink = $pagelink;
        $response->threadList = $threadList;
        $response->fromCaseId = $caseId;
    }
    public function list4fuwai($request, $response)
    {/*{{{*/
        $user = UserClient::getInstance()->getCurrentUser();
        $patients = $user->patients;
        $patientInfos = array_shift($patients);
        $list = ThreadClient::getInstance()->getListForUser($user->id, 1, 100);
        $flowList = array();
        foreach($list['threads'] as $key=>$thread)
        {
            $threadHospitalId = $thread->space->host->hospitalfaculty->hospital->id;
            if(self::FUWAI_HOSPITALID == $threadHospitalId)
            {
                $flowList[] = $thread;
            }
        }
        $response->isLogin = UserClient::getInstance()->isLogin();

        $response->threadList = $flowList;
        $response->patient = $patientInfos;
        $response->hid = self::FUWAI_HOSPITALID;
    }/*}}}*/
		public function index($request, $response)
		{/*{{{*/
				$page  = intval($request->getRequest('p', 1));
				$pType = $request->getRequest('p_type', 'all');
				$response->pType = $pType;
				$reboardId = $reGroupId = '';

				$GroupCount = PatientClubClient::getInstance()->getResidentEvilGroupCount('regroup', $this->_newSpace->user->id);
				$response->GroupCount = $GroupCount;

				/** 获得患者列表 */
				$options = array('page'=>true);
				if (is_numeric($pType))//具体小组
				{
						$options['categoryId'] = $pType;
						$group = DAL::get()->find('ReGroup', $pType);
						if ($group->isNull() == false){
								$reboardId = $group->reboard->id;
								$reGroupId = $group->id;
						}
				}
				else if ($pType == 'un_category')//未分组
				{
						$options['isVerified'] = 1;
				}
				else if ($pType == 'disable')//已删除
				{
						$options['isDeleted'] = 0;
				}

				$response->reboardId = $reboardId;
				$response->reGroupId = $reGroupId;
				$spacePatientList = array();
				$res = ForumClient::getInstance()->getResidentEvilMemberList($this->_newSpace->id, $page, $pageSize=20, $options);
				foreach ($res['spacePatientList'] as $tmpSpacePatient) {
						if ($tmpSpacePatient->user->isNull() == false && $tmpSpacePatient->user->name)
								$spacePatientList[$tmpSpacePatient->id] = $tmpSpacePatient;
				}
				ksort($spacePatientList);
				$patientIds = array();
				$userFlows = array();
				foreach($spacePatientList as $spacePatient)
				{
						if($spacePatient->user->isNull() == false)
						{
								$patientId = $spacePatient->patientId;
								if(empty($patientId) == false)
								{
										$patientIds[] = $patientId;
										$userFlows[$patientId] = FlowClient::getInstance()->getValidFlowRef($this->_newSpace->id, $patientId);
								}
						}
				}
				$userLatestThreads = array();
				if(empty($patientIds) == false)
						$userLatestThreads = ThreadClient::getInstance()->getPatientLatestThread($this->_newSpace->id, $patientIds, true);

				$response->spacePatientList = $spacePatientList;
				$response->userLatestThreads = $userLatestThreads+$userFlows;

				$pageInfo = $res['pageInfo'];
				$pagelink = '';
				if(empty($pageInfo) == false)
						$pagelink = PageNav::getNavLink(PageNav::getPageNavTemplate($response->router->urlfor('adminpatient/index', array('p_type' => $pType)).'&p='),
										$pageInfo['nowpage'], $pageInfo['pagesize'], $pageInfo['total']);


				//所有组(去掉默认组)
				$spaceId = $this->_newSpace->id;
				$categoryList = DAL::get()->find_all_by_spaceid_and_type('ReGroup', $spaceId, ReGroup::TYPE_1);

				$categoryPairs = array();
				foreach($categoryList as $category)
						$categoryPairs[$category->id] = $category->name;

				$defaultGroup = DAL::get()->find_by_spaceid_and_type('ReGroup', $spaceId, ReGroup::TYPE_0);
				//未分组患者
				$unCategoryCnt = ForumClient::getInstance()->getUnGroupMemberCnt($this->_newSpace->id);
				//已删除患者
				$deletedCnt = ForumClient::getInstance()->getDeletedGroupMemberCnt($this->_newSpace->user->id);

				$response->pagelink = $pagelink;
				$response->categoryList = $categoryList;
				$response->defaultGroup = $defaultGroup;
				$response->unCategoryCnt = $unCategoryCnt;
				$response->deletedCnt = $deletedCnt;
				$response->patientCategoryListPair = $categoryPairs;
		}/*}}}*/