public function flowDetail($request, $response)
 {/*{{{*/
     $ref = DAL::get()->find('DoctorPatientRef', $request->refid);
     if ($ref->isPrivated() && $this->user->id != $ref->user->id) $this->_exit404();
     if ($ref->isDeleted() || $ref->isClosed()) $this->_exit404();
     if ($ref->isNull() || $ref->space->isNull()) $this->_exit404();
     $this->getRelationCaseList($request, $response);
     $this->getRelationArticleList($request, $response);
     $this->loadMoreDetail($request, $response);
     if ($this->user->id == $ref->user->id)
     {
         FlowMarkClient::getInstance()->markPatientRead($ref);
     }
     $attachIds = isset($response->flowSession[$ref->id]['attachIds']) ? $response->flowSession[$ref->id]['attachIds'] :'';
     $attachIds .= ','.$request->attachIds;
     if($attachIds)
     {
         $attachArrays = explode(',',$attachIds);
         $attachs = DAL::get()->find('PatientAttachment',$attachArrays);
         foreach($attachs as $index => $pa)
         {
             if($pa->isNull() || $pa->isDeleted() && empty($spaceId))
             {
                 unset($attachs[$index]);
             }
         }
         $response->attachs = $attachs;
     }
     $response->attachids = $attachIds; 
     $response->isFirstProposalPost = $this->checkFirstProposal($ref);
     $response->orderdesc = $request->orderdesc;
     $response->isFromAttach = $request->getRequest('isfromattach', 0);
 }/*}}}*/
    public function getCaseDetail4Patient($userId, $caseId, $caseType, $lastPostId, $supportLink = '0', $supportRCLabel = '0')
    {/*{{{*/ 
        if ($supportLink === null) $supportLink = '0';
        $fetchCount = 6; //每页多取一个,判断是否有下一页
        $thread = $this->getTheRightThread($caseId);
        $user = DAL::get()->find('user', $userId);
        $isOwner = false;
        if($userId == $thread->userid)
        {
            $isOwner = true;     
        }
        if($thread->isNull())
        {
            $this->setErrorCode(142);
            return 0;
        }
        if($thread instanceof DoctorPatientRef && $thread->space->isNull())
        {
            $this->setErrorCode(1224);
            return 0;
        }
        if($isOwner)
        {
            if ($thread instanceof DoctorPatientRef)
            {
                FlowMarkClient::getInstance()->markPatientRead($thread);
            }
            $postInfos = $this->_getPagedPosts4Owner($thread, $fetchCount, $lastPostId);
        }
        else
        {
            $postInfos = $this->_getPagedPosts4Third($thread, $fetchCount, $lastPostId);
        }
        $hasMore = $postInfos['hasMore'];
        $posts= $postInfos['posts'];
        $postInfos = array();
        if(empty($posts) == false)
        {/*{{{*/
            foreach($posts as $key => $post)
            {
                $postInfo['postId'] = $post->id;
                $postInfo['lastPostId'] = $key;
                $postInfo['userId'] = $post->user->id;
                $postInfo['content'] =  ''; 
                $postInfo['postTime'] = '';
                $postInfo['postType'] = '';
                $postInfo['adminComment'] = '';
                $postInfo['canDelete'] = 0;
                $postInfo['attachments'] = array();
                //返回值是否可以编辑
                $postInfo['canEdit'] = 0;
                $postInfo['isHasUrl'] = 1; 
                $postInfo['isTreated'] = 0;
                $postInfo['postTime'] = substr($post->ctime, 0, 16);
                $postInfo['soundposttime'] = 0;
                $postInfo['postAttachType'] = ($post instanceof DoctorPatientPost  && $post->isSoundPost() && ($isOwner || false == $post->isPrivated())) ? self::SOUND_POST : 0;
                if($thread  instanceof DoctorPatientRef)
                {
                    $postInfo['isTreated'] = $thread->afterTreated(XDateTime::valueOf($post->ctime)) ? 1 : 0;
                }
                if($post instanceof Proposal || $post instanceof DoctorPatientPost || $post instanceof Intention || $post instanceof Post)
                {/*{{{*/
                    if($this->getObjIsDeleted($post) == false || $post instanceof Proposal || $post instanceof Intention)
                    {

                        $headHtml = "";
                        if(($post instanceof Proposal || $post instanceof Intention))
                        {
                            $bingLiSet = BingLiDtoHelper::create($post)->getAll();
                            $search = array();
                            $content = BingLiDtoDisplay::getContent($bingLiSet);
                        }
                        else
                        {
                            $content = ($post instanceof DoctorPatientPost && $post->isPrivated() && !$isOwner) ? "病例资料仅医生及患者本人登录后可见" : $post->content;
                            $content = str_replace(array("\r", "\t"), "", $content);
                        }
                        $pattern = array ( "/<!--[^!]*-->/i", "/&nbsp;/", "/&nbsp/", "/&#160;/", "/&lt;/", "/&gt;/", "/&#60;/", "/&#62;/", "/&#39;/"); 
                        $replace = array ( "", " ", " ", " ", '#lt;', '#gt;', '#lt;', '#gt;', '\''); 
                        $content = preg_replace($pattern, $replace, $content); 
                        $content = str_replace(array("<br>", "<br/>", "<br />"), "\n", $content);
                        if ($supportLink > 0)
                        {
                            if ($post instanceof DoctorPatientPost && $post->isSpaceReply())
                            {
                                $content = htmlspecialchars_decode($content); 
                                //$content = strip_tags($content, '<a>');
                            }
                            else
                            {
                                $content = strip_tags($content);
                                $content = preg_replace(array('/#lt;/', '/#gt;/'), array('<', '>'), $content); 
                                $content = str_replace('<', '﹤', $content); 
                            }
                        }
                        else
                        {
                            $content = htmlspecialchars_decode($content); 
                            $content = strip_tags($content);
                        }
                        $content = preg_replace(array('/#lt;/', '/#gt;/'), array('<', '>'), $content); 
                        $content = str_replace("(发病时间、主要症状、就诊医院等)", "", $content);
                        $content = str_replace(array("\n\n\n"), "\n", $content);
                        $content = str_replace("曾经治疗情况和效果:\n\n\n想得到怎样的帮助:", "想得到怎样的帮助:", $content);
                        $content = preg_replace("/想得到怎样的帮助:\n\n$/", "", $content);

                        if ($supportLink > 0 && $post instanceof DoctorPatientPost && $post->isSpaceReply())
                        {
                            $request = new Request();
                            $os = $request->os;
                            if ($os != 'ios' && strpos($content, 'href') === false && strpos($content, 'http') === false)
                            {
                            }
                            else
                            {
                                $space = $thread->space;
                                ob_start();
                                if ($supportRCLabel > 0)
                                {
                                    include(dirname(__FILE__).'/../../templates/mobileapi/doctorcasepost4ios.php');
                                }
                                else
                                {
                                    include(dirname(__FILE__).'/../../templates/mobileapi/doctorcasepost.php');
                                }
                                $content = ob_get_contents();
                                ob_end_clean();
                            }
                        }
                        if($post instanceof DoctorPatientPost && $post->isHavePicture() && ($os != 'ios' || $_REQUEST['v'] < '3.0.2'))
                        {
                            //暂不支持图片
                            $postInfo['content'] = $post->getNoSupportImgContent();
                        }
                        else
                        {
                            $postInfo['content'] = $content;
                        }
                        if((false == empty($post->adminComment)) &&
                            ($userId == $post->user->id || ($post instanceof DoctorPatientPost &&  $this->getObjIsPrivate($post))))
                        {
                            $postInfo['adminComment'] = '提示:'.strip_tags($post->adminComment);
                        }
                        $postInfo['canDelete'] = $this->isCanDeletePost($userId, $thread, $post);
                        if($isOwner)
                        {
                            if ($post instanceof DoctorPatientPost && $post->isHavePicture() && $post->isSpaceReply())
                            {
                                foreach($post->picturePosts as $picturePost)
                                {
                                    $postInfo['attachments'][] = $this->getPictureAttachment($picturePost);
                                }
                            }
                            else 
                            {
                                foreach($post->attachmentIds as $attachmentId)
                                {
                                    $postInfo['attachments'][] = $this->getAttachmentInfoByAttachId($attachmentId);
                                }
                            }
                         }
                        else if(false == $isOwner && false == empty($post->attachmentIds))
                        {
                            $tmp['attachmentType'] = 'private';
                            $tmp['thumbnailUrl'] = 'http://i1.hdfimg.com/wap/images/mobile_privateattach.png';
                            $tmp['canClick'] = 0;
                            $postInfo['attachments'][0] = $tmp;
                        }
                        $postInfo['canEdit'] = $this->isCanEdit($userId, $post, $thread);
                        if($post instanceof post)
                        {
                            $postInfo['postType'] = 'post';
                        }
                        else if($post instanceof doctorPatientPost)
                        {
                            $postInfo['soundposttime'] = $post->getSoundPostTime();
                            $postInfo['postType'] = 'doctorpatientpost';
                        }

                    }
                }/*}}}*/
                else if($post instanceof PatientSignin || $post instanceof PatientApply)//诊后报到
                {/*{{{*/
                    $postInfo['postType'] = 'patientsignin';
                    $patientName = $thread->patient->getPatientName4Mobile();
                    if(false == $isOwner)
                    {
                        $patientName = $thread->patient->getPrivatePatientNameImp($patientName);
                    }
                    $latestTreatedTime =  date('Y-m-d',strtotime($post->getLastPostTime4Flow()));
                    $postInfo['content'] =  '诊后报到成功'; 
                    $postInfo['isTreated'] = 1;
                    $postInfo['isHasUrl'] = $this->isShowPatientSign($post); 
                    $postInfo['postTime'] = substr($post->getLastPostTime4Flow(), 0, 16);
                }/*}}}*/
                else if($post instanceof DoctorRadioMessage)
                {/*{{{*/
                    $postInfo['postId'] = $post->id;
                    $postInfo['userId'] = $post->user->id;
                    $postInfo['content'] = $post->content;
                    list($flowTitle, $content) = $post->getFlowContentAndTitle();
                    $request = new Request();
                    $os = $request->os;
                    if ($os != 'ios' && strpos($content, 'href') === false && strpos($content, 'http') === false)
                    {
                    }
                    else
                    {
                        $space = $thread->space;
                        ob_start();
                        if ($supportRCLabel > 0)
                        {
                            include(dirname(__FILE__).'/../../templates/mobileapi/doctorcasepost4ios.php');
                        }
                        else
                        {
                            include(dirname(__FILE__).'/../../templates/mobileapi/doctorcasepost.php');
                        }
                        $content = ob_get_contents();
                        ob_end_clean();
                    }
                    $postInfo['content'] = $content;
                }/*}}}*/
                else if($post instanceof BookingLog) //预约门诊
                {/*{{{*/
                    $postInfo['userId'] = $userId;
                    $postInfo['postType'] = 'bookinglog';
                    $userName = $user->name;
                    if(false == $isOwner)
                    {
                        $userName = $thread->patient->user->getPrivateName();
                        $postInfo['userId'] = $thread->userid;
                    }
                    $postInfo['content'] = $userName.',大夫已同意您的门诊预约'; 
                }/*}}}*/
                else if($post instanceof DoctorComment)
                {/*{{{*/
                    $postInfo['postType'] = 'doctorcomment';
                    $postInfo['content'] =  '给'.$thread->space->name.'大夫写了一封感谢信'; 

                    }/*}}}*/
                    else if($post instanceof TelOrder)
                    {/*{{{*/
                        $postInfo['postType'] = 'telorder';
                        $postInfo['content'] =  '申请与'.$thread->space->name.'大夫通电话'; 
                    }/*}}}*/
                    else if($post instanceof TelVisit)
                    {/*{{{*/
                        $postInfo['postType'] = 'telvisit';
                        $postInfo['content'] =  '对和'.$thread->space->name.'的通话做出了评价'; 
                        // todo::jz  flowable for mobile
                    }/*}}}*/
                    else if($post instanceof PresentOrder)
                    {/*{{{*/
                        $postInfo['postType'] = 'presentorder';
                        $postInfo['content'] =  '赠送给大夫 "'.$post->present->name.'" 心意礼物'; 
                        $tmp['thumbnailUrl'] = $post->present->getMiddleImage();
                        $tmp['attachmentType'] = 'presentorder';
                        $tmp['canClick'] = 0;
                        $postInfo['attachments'][0] = $tmp;
                    }/*}}}*/
                    else if ($post instanceof ServiceCard)
                    {/*{{{*/
                        if (false == isset($chargeProduct) || false == isset($freeProduct)) 
                        {
                            $chargeProduct = ProductClient::getInstance()->getDoctorChargeFlowProduct($post->space);
                            $freeProduct = ProductClient::getInstance()->getDoctorFreeFlowProduct($post->space);
                        }
                        if ($post->ware->product->id == $chargeProduct->id) 
                        { 
                            $postInfo['postType'] = 'servicecard';
                            $postInfo['postTime'] = substr($post->getLastPostTime4Flow(), 0, 16);
                            $postInfo['userId'] = $post->getLastPostUser4Flow()->id;
                            $postInfo['content'] = '患者'.$thread->getPatientName($user).'购买了'.$post->space->host->name.'大夫'.$post->ware->product->amount.'次咨询服务';
                        }
                        else if ($post->ware->product->id == $freeProduct->id) 
                        { 
                            $postInfo['postType'] = 'servicecard';
                            $postInfo['postTime'] = substr($post->getLastPostTime4Flow(), 0, 16);
                            $postInfo['userId'] = $post->getLastPostUser4Flow()->id;
                            $postInfo['content'] = $post->space->host->name.'大夫免费增加了患者'.$thread->getPatientName($user).$post->ware->product->amount.'次咨询服务';
                        }
                    }/*}}}*/
                    if (false == empty($postInfo))
                    {/*{{{*/
                        if ($supportRCLabel > 0)
                        {
                            $postInfo['content'] = trim(trim(trim($postInfo['content'], "\r"), "\n")); 
                            $postInfo['content'] = str_replace("   ", " ", $postInfo['content']);

                            $postInfo['content'] = (strpos($postInfo['content'], '<font size=16') === false) ? '<font size=16 face=\'HelveticaNeue-Light\'>'.$postInfo['content'].'</font>' : $postInfo['content'];
                        }
                        if($post instanceof DoctorPatientPost && $post->isSoundPost())
                        {
                            $ver = $this->isSurportSound($_REQUEST['app'], $_REQUEST['v'], $_REQUEST['os']);
                            $tmpContent = $post->getContent($isOwner, $ver, false);
                            if (false !== strpos($tmpContent, DoctorPatientPost::SOUND_VER_CONTENT)) 
                            {
                                $tmpContent =  (false !== strpos($_REQUEST['os'], 'android')) ? self::SOUND_NOT_SUPPORT_ANDROID : self::SOUND_NOT_SUPPORT_IOS;
                            }
                            $postInfo['postContent'] = $postInfo['content'] = $tmpContent;
                        }
                        else
                        {
                            $postInfo['postContent'] =  $postInfo['content'];
                        }
                        $postInfos[] = $postInfo;
                    }/*}}}*/
                    if(isset($postInfo['postAttachType']) && $postInfo['postAttachType'] == self::SOUND_POST)
                    {
                        $postInfo['content'] = '此版本暂不支持医生的语音播放'; 
                    }
                }
        }/*}}}*/
        $this->content = $postInfos;
        $this->hasMore = $hasMore;
    }/*}}}*/
    /**
        * @brief  根据用户id获取患者列表,带有部分医生信息。iOS使用
        * @author cs
        * @exampleUrl  http://dev.mobile-api.haodf.com/patientapi/proposal_getPatientListWithService?userId=3
        *
        * @param $userId
        *
        * @return 
     */
    public function getPatientListWithService($userId, $pageId=1, $pageSize=10)
    {/*{{{*/
        $user = DAL::get()->find('user', $userId);
        if ($user->isNull())
        {
            $this->setErrorCode(107);
            return 0;
        }
        $patients = $this->getPatientsOrderByLastPostTime($user);

        foreach ($patients as $key => $patient)
        {
            $doctorInfo = $doctorList = array();
            $res = FlowClient::getInstance()->getFlowAndFlowProposalSpaceByPatientId($patient->id, 1, 20);
            $patientRefs = isset($res['list']) ? $res['list'] : array();
            if (empty($patientRefs)) 
            {
                unset($patients[$key]);
                continue;
            }
            foreach ($patientRefs as $patientRef)
            {
                $space = $patientRef->space;
                if ($space->isNull() || false == $space->isConfirmed()) continue;
                $doctor = $space->host;
                $doctorInfo['doctorName'] = $doctor->name;
                $doctorInfo['doctorHospital'] = $doctor->hospitalfaculty->hospital->name;
                $doctorInfo['doctorFaculty'] = $doctor->hospitalfaculty->name;
                $doctorList[] = $doctorInfo;
            }
            $pageDoctorList[$patient->id] = $doctorList;
        }

        $pagePatients = array_slice($patients, ($pageId-1)*$pageSize, $pageSize);

        $infos = array();
        foreach ($pagePatients as $pagePatient)
        {
            $doctorList = isset($pageDoctorList[$pagePatient->id]) ? $pageDoctorList[$pagePatient->id] : array();
            $info['id'] = $pagePatient->id;
            $info['name'] = $pagePatient->name;
            $info['doctorCnt'] = count($doctorList);
            $info['unReadCnt'] = FlowMarkClient::getInstance()->getPatientUnreadAmount($pagePatient->id);
            $info['doctorList'] = array_slice($doctorList, 0, 2);
            $infos[] = $info;
        }

        $this->content = $infos;
        $pageInfo = array();
        $pageInfo['pages'] = ceil(count($patients) / $pageSize);
        $pageInfo['pagesize'] = $pageSize;
        $pageInfo['nowpage'] = $pageId;
        $pageInfo['total'] = count($patients);
        $this->pageInfo = $pageInfo;
    }/*}}}*/
 public function ajaxCancelMarkPatientForSpace($request, $response)
 {
     /*{{{*/
     $spaceId = $request->spaceId;
     $patientId = $request->patientId;
     $space = DAL::get()->find("space", $spaceId);
     $patient = DAL::get()->find("patient", $patientId);
     FlowMarkClient::getInstance()->cancelPatientMarkForSpace($space, $patient, SpaceSymbol::TYPE_MSD);
     $defaultGroup = DAL::get()->find_by_spaceid_and_type('regroup', $spaceId, ReGroup::TYPE_2);
     $doctorOwner = DAL::get()->find_by_sourceid('doctorowner', $space->id);
     $memberIds = ForumClient::getInstance()->getMemberIdByPatientIdAndDoctorOwnerId('regroupmember', $patient->id, $doctorOwner->id);
     if (false == empty($memberIds)) {
         ForumClient::getInstance()->changeGroupMember($memberIds[0], $defaultGroup->id, $space->id);
     } else {
         ForumClient::getInstance()->createGroupMember($space, $patient->user, $patient->id, $defaultGroup->id, true);
         //新加的组
     }
     echo "1";
     return self::DIRECT_OUTPUT;
 }
    if (false == empty($flows))
    {
?>
<div class="borderDiv" id="convertpostdiv">
    <div class="detail-module">
        <div class="detail-module_title">
            <h3>代患者提交对话</h3>
        </div>
        <p class="mt10 mb10 f14">患者医患流关系如下,可勾选后为患者提交post</p>
        <form method="post" action="convert2post" id="convertform">
        <input type="hidden" name="id" value="<?=$record->id?>" />
            <p>
            <?php foreach ($flows as $flow) { 
                if ($flow->space->isNull()) continue;
            ?>
            <?php $isTrue = FlowMarkClient::getInstance()->isMarkForSpace($flow->space, SpaceSymbol::TYPE_MSD );?>
            <input type="radio" name="flowid"<?php if(false == empty($recordPatientIds) && $isTrue){?>
            onclick='addUrl()' <?}else{?>onclick='delUrl()'<?}?>value="<?=$flow->id?>"/><a href="<?=$flow->getUrl()?>" target="_blank"><?=$flow->id?></a>(<?=$flow->space->name?>)
                <span style="color:green"><?= ($isTrue)?"默沙东项目医生":''?></span>
            <?php } ?>
            </p>
            <div>
                <textarea name="content" id="convertcontent" style="width:65%;height:200px;" class="ml10 mt10 f14"><?=$record->getAnswersContent()?></textarea>
                <textarea hidden="true" id="convertcontent2" style="width:65%;height:200px;" class="ml10 mt10 f14"><?=$record->getAnswersContent()?></textarea>
                <span><a class="blueA ml20" style="position:relative;top:-100px;" onclick="return checkConvertForm();">转换</a>
                 <?php if(false == empty($recordPatientIds)){?>
                 <span><a class="blueA ml20" style="position:relative;top:-100px;" href="recorddetaillist?patientId=<?=$record->patient->id?>" target="_black">查看健康日记</a>
                <?php } ?>
                </div>
        <div class="m10" id="convertattachment">
        <?php if (false == empty($uploadArr)) { 
 /**
  * @brief 患者本人视角的流详情展示
  * @author lhl
  * @version branches/v2.14.23
  * @date 2013-07-25
  */
 private function detailForPatient($response, $request, $ref)
 {
     /*{{{*/
     $ref->getSpaceLeftAllowCnt();
     //在取详情之前触发修复老数据服务卡的逻辑
     $nowPage = $request->getRequest('p', 1);
     $pageSize = 20;
     $pagelink = '';
     $options = array();
     $options['flowOrder'] = SpaceAttribute::FLOW_ORDER_DESC;
     $options['nocache'] = true;
     $res = FlowClient::getInstance()->getFlowInfos($ref->id, $nowPage, $pageSize, $options);
     $response->isFirstProposalPost = $this->checkFirstProposal($ref);
     if (false == empty($res['pageInfo'])) {
         $pageInfo = $res['pageInfo'];
         $pagelink = PageNav::getNavLink(PageNav::getPageNavTemplateForSpace($ref->url . '?p='), $pageInfo['nowpage'], $pageInfo['pagesize'], $pageInfo['total']);
     }
     //免费随访用户不允许回复
     $canPost4Flow = FollowupClient::getInstance()->canPost4Flow($this->user, $ref->space);
     $response->canEdit = $this->space->isCaseOpen() && false == $ref->isClosePost() && $canPost4Flow;
     $response->flowList = $res['objects'];
     $response->pagelink = $pagelink;
     if ($ref->space->isOpenFollowup()) {
         list($hasBooking, $hasTel, $bookingOrder, $telCase) = $this->getUnFinishedService($res['objects']);
         $response->hasBooking = $hasBooking;
         $response->hasTel = $hasTel;
         $response->bookingOrder = $bookingOrder;
         $response->telCase = $telCase;
         //标注异常状态的随访流详情内容
         $response->abnormalStatus = $this->getAbnormalStatus($res['objects']);
         //报道信息内容
         $signinProblems = array();
         $followupSpaceAttribute = $this->space->followupSpaceAttribute;
         if (false == $followupSpaceAttribute->isNull()) {
             $signinProblems = $followupSpaceAttribute->getNfsDisease()->getSigninHealthProblems();
         }
         $response->signinProblems = $signinProblems;
     }
     //获取病例
     $response->patientAttachments = $ref->patient->attachments;
     // 增加能修改post功能
     $editPostId = $request->editpostid;
     $editPost = DAL::get()->find('DoctorPatientPost', $editPostId);
     if ($editPost->user->id != $this->user->id) {
         $editPost = NullEntity::create();
     }
     $response->editPost = $editPost;
     //页面加载完,附加动作  待重构。把所有type=xxx的url改成callback=xxx&callbackparams的形式
     $this->processCallBack($ref, $request, $response);
     //医生可提供服务
     $response->doctorServices = SpaceClient::getInstance()->getServiceInfo($this->space->id, $this->user->id);
     if ($this->space->isPhoneOpenedForFront()) {
         $telVisitList = PaymentClient::getInstance()->getPatientPhoneServiceList($this->space->user->id, 1, 10);
         $response->telVisitTotalCnt = isset($telVisitList['pageInfo']['total']) ? $telVisitList['pageInfo']['total'] : 0;
         $telVisitInfos = DAL::get()->queryLatestCompleteOrderIdsBySpaceId('TelOrder', $this->space->user->id, $count = 10);
         $response->telVisitInfos = $telVisitInfos;
         $response->ScoreDesc = TelVisit::$scoreDesc;
         $response->callingLogs = PaymentClient::getInstance()->getDoctorRecentPhoneRecords($this->space);
     }
     $response->spaceRelatedFacultyName = $this->space->host->hospitalfaculty->faculty->name;
     //右侧广告信息
     $facultyDoctorIds = DoctorClient::getInstance()->getFacultyDoctor($this->space->host);
     $response->facultyDoctorList = DAL::get()->find('doctor', $facultyDoctorIds);
     $response->doctorSatisfactionList = PaymentClient::getInstance()->getDoctorSatisfactionList($facultyDoctorIds);
     $response->doctorChargeFlowProduct = ProductClient::getInstance()->getDoctorChargeFlowProduct($this->space);
     FlowMarkClient::getInstance()->markPatientRead($ref);
 }
 public function ajaxMarkSpace($request, $response)
 {
     $spaceId = $request->spaceId;
     $space = DAL::get()->find("space", $spaceId);
     FlowMarkClient::getInstance()->markSpace($space, SpaceSymbol::TYPE_MSD);
     echo "1";
     return parent::DIRECT_OUTPUT;
 }
    /**
        * @brief 获取当前用户最新开通健康管理的患者以及是否已使用网站服务
        * @author zjj 
        *
        * @param $userId 用户ID
        *
        * @return array('patientId' => $patientId, 'patientName' => $patientName, 'hasService' => $hasService, 'unReadRecordCount' => count($unReadRecordIds), 'mydoctorCount'=> $mydoctorCount, 'hasdingyue' => $hasdingyue, 'myPatientCount' => $myPatientCount)
     */
    public function getCurrentUserStatus($userId)
    {/*{{{*/
        $user = DAL::get()->find('user', $userId);
        if ($user->isNull())
        {
            $this->setErrorCode(107);
            return 0;
        }

        $this->getHealthApplyPatientList($user->id);
        $patientInfos = $this->content;
        $patientId = $patientName = '';
        if (false == empty($patientInfos))
        {
            foreach ($patientInfos as $patientInfo)
            {
                if ($patientInfo['status'] == PatientHealthApply::$statusDesc[PatientHealthApply::STATUS_VALID])
                {
                    $patientId = $patientInfo['id'];
                    $patientName = $patientInfo['name'];
                    break;
                }
            }
        }

        $hasService = $this->hasService($user);

        $vars = array();
        $vars['UserName'] = $user->name;
        $vars['IsRead'] = (string) PatientHealthRecord::IS_READ_NO;
        $unReadRecordIds = DAL::get()->find_id_list4Search('PatientHealthRecord', $vars);
        $myPatients = $user->getPatients();
        $mydoctorCount = 0;
        $myPatientCount = count($myPatients);
        if(false == empty($myPatients))
        {
            $mydoctorCount = FlowMarkClient::getInstance()->queryGetPatientUnreadAmount('flowmark', FlowMark::PATIENT_UNREAD, array_keys($myPatients));
        }

        $lastSubscribedDiseaseArticleId = DAL::get()->queryLastSubscriptionRecordId('usersubscriptionrecord', $user->id);
        $lastSubscribedDiseaseArticleId = $lastSubscribedDiseaseArticleId ? $lastSubscribedDiseaseArticleId : 0;
        $lastSubscribedDoctorDynamicInfoId = $this->getLastDoctorSubscriptionId($user);

        $diseaseSubscriptionUnreadCnt = DAL::get()->queryUnreadDiseaseCntByUserId('usersubscriptionrecord', $user->id);
        $doctorSubscriptionUnreadCnt = $this->getDoctorSubscriptionUnreadCnt($user->id);

        $subcribedDiseaseIds = DAL::get()->find_id_by_fld_userid_and_isdelete('SubscriptDisease', $user->id, SubscriptDisease::ISDELETE_NO);
        $subcribedDiseaseCount = count($subcribedDiseaseIds);
        $subcribedDoctorIds = DAL::get()->find_id_by_fld_userid_and_isdelete('UserDoctor', $user->id, UserDoctor::ISDELETE_NO);
        $subcribedDoctorCount = count($subcribedDoctorIds);

        $this->content = array('patientId' => $patientId, 'patientName' => $patientName, 'hasService' => $hasService, 
            'unReadRecordCount' => count($unReadRecordIds), 'mydoctorCount'=> $mydoctorCount, 'myPatientCount' => $myPatientCount, 
            'lastSubscribedDiseaseArticleId' => $lastSubscribedDiseaseArticleId, 'lastSubscribedDoctorDynamicInfoId' => $lastSubscribedDoctorDynamicInfoId, 
            'diseaseSubscriptionUnreadCnt' => $diseaseSubscriptionUnreadCnt, 'doctorSubscriptionUnreadCnt' => $doctorSubscriptionUnreadCnt,
            'subcribedDiseaseCount' => $subcribedDiseaseCount, 'subcribedDoctorCount' => $subcribedDoctorCount);
    }/*}}}*/