/**
     * @brief 邀请病历头患者发送短信
     * @author oylw
     * @exampleUrl http://dev.mobile-api.haodf.com/doctorapi/patientclub_sendSMS4PatientCase?userId=123456&patientCaseId
     *
     * @Param $userId    用户ID 
  */
 public function sendSMS4PatientCase($userId, $patientCaseId)
 {/*{{{*/
     $user = DAL::get()->find('User', $userId);
     if ($user->isNull())
     {
         $this->setErrorCode(838);
         return 0;
     }
     $patientCase = DAL::get()->find('patientCase', $patientCaseId);
     if($patientCase->isNull())
     {
         $this->setErrorCode(107);
         return 0;
     }
     $doctorOwner = $user->getDoctorOwner();
     if($doctorOwner->source instanceof Space)
     {
         $diseaseId = 0;
         $spaceId = $doctorOwner->source->id;
         $key = md5('haodf2014'.$spaceId.$diseaseId);
         $data = $spaceId.'_'.$diseaseId.'_'.$key;  
         $SMSContent = '亲爱的患者朋友您好,'.$doctorOwner->source->host->hospitalfaculty->hospital->name.$doctorOwner->source->host->hospitalfaculty->name
             .$doctorOwner->source->host->name.'医生邀请您到好大夫网站报到成为医生的老患者,以便后续跟进您的病情,[http://m.haodf.com/touch/d/op.htm?k='.$data.']。';
         SMSClient::getInstance()->sendSMS(array($patientCase->phone), $SMSContent);
         PatientCourseClient::getInstance()->setSendedSMSStatus4PatientCase($patientCase->id);
     }
     $this->content = '1';
 }/*}}}*/
 /**
  * deletePatientCaseByDoctor
  * 修改病历头的状态 
  * @param mixed $patientCaseId 
  * @access public
  * @return void
  */
 public function deletePatientCaseByDoctor($userId, $clientId, $patientCaseId)
 {/*{{{*/
     if(empty($clientId))
     {
         return 0;
     }
     $doctorOwner = DAL::get()->find_by_userid('DoctorOwner',$userId);
     if($doctorOwner->isNull())
     {
         return 0;
     }
     $patientCase = DAL::get()->find('PatientCase', $patientCaseId);
     if($patientCase->isNull() || $patientCase->doctorOwner->id != $doctorOwner->id)
     {
         return 0;
     }
     PatientClubClient::getInstance()->removePatientCaseMember($patientCaseId, $doctorOwner->id);
     PatientCourseClient::getInstance()->deletePatientCaseByDoctor($patientCaseId); 
     $patientCase = DAL::get()->find('PatientCase', $patientCaseId);
     $this->content =  array('clientId'=>$clientId, 'patientCaseId'=>$patientCase->id, 'ver'=>$patientCase->ver);
 }/*}}}*/
 public function nextOrdinarySignin($request, $response)
 {
     /*{{{*/
     $inspectGroupName = $request->inspectgroup;
     $inspectGroup = DAL::get()->find_by_name('PatientSigninInspectGroup', $inspectGroupName);
     if ($inspectGroup->isNull()) {
         $inspectGroup = PatientSigninInspectRule::getPatientSigninInspectGroup();
     }
     $response->msg = $request->msg;
     $user = $this->user;
     $signinId = $request->signinId;
     //老患者报到类型
     $signinType = PatientSignin::TYPE_ORDINARY;
     $response->signinType = $signinType;
     $ticket = new NullEntity();
     //获取工单
     if (empty($signinId)) {
         $inspectGroupId = $request->getRequest('inspectGroupId', $inspectGroup->id);
         $signinGroup = InspectGroup::find($inspectGroupId);
         $orderby = 'desc';
         $ticket = InspectClient::getInstance()->pickTicket($this->curInspector, $signinGroup, $orderby);
         if ($ticket->isNull()) {
             echo "工单审核结束";
             return parent::DIRECT_OUTPUT;
         }
     }
     //报到者
     $patientSignin = new NullEntity();
     if ($ticket->isNull() == false) {
         $patientSignin = $ticket->getSource();
         if (false == $patientSignin->isNull() && $patientSignin->isSrcWeiXin()) {
             $patientSignin = DAL::get()->find('PatientSignin', $patientSignin->id, true);
         }
     } elseif (empty($signinId) == false) {
         $patientSignin = DAL::get()->find('PatientSignin', $signinId);
     }
     if ($patientSignin->isNull()) {
         die('审核结束');
     }
     $response->helpInfos = DAL::get()->find_all_by_patientSigninId('PatientSigninHelpInfo', $patientSignin->id);
     $response->assignerId = $this->curInspector->id;
     $response->patientSignin = $patientSignin;
     $response->ticket = $ticket;
     $doctorPatientRef = DAL::get()->find_by_patientid_and_spaceid('DoctorPatientRef', $patientSignin->patient->id, $patientSignin->space->id);
     $response->doctorPatientRef = $doctorPatientRef;
     //关联疾病
     $signinId = $signinId ? $signinId : $patientSignin->id;
     $diseaseRefList = DAL::get()->find_all_by_signinid('PatientSigninDiseaseRef', $signinId);
     if (empty($diseaseRefList) && false == $doctorPatientRef->isNull()) {
         $mark = DAL::get()->find_by_doctorpatientrefid('FlowDiseaseMark', $doctorPatientRef->id);
         if (false == $mark->isNull()) {
             $diseaseRefList = array($mark);
         }
     }
     if (empty($diseaseRefList)) {
         $response->diseaseRefList = array();
     } else {
         $response->diseaseRefList = array(array_pop($diseaseRefList));
     }
     $response->defaultRefuseReason = $this->defaultRefusePatientSignin($patientSignin);
     $diseaseRef = DAL::get()->find_by_signinid('PatientSigninDiseaseRef', $patientSignin->id);
     $response->isDiseaseHasQuestionSheet = false;
     if (false == $diseaseRef->disease->isNull()) {
         $response->isDiseaseHasQuestionSheet = $this->checkDiseaseQuestionSheet($diseaseRef->disease->id, $patientSignin->space->id);
     }
     $patientId = $patientSignin->patient->id;
     $userName = $patientSignin->space->userName;
     $res = PatientCourseClient::getInstance()->searchPatientCase(null, $userName, '', null, null, null, null, null, true, 1, 10, '', $patientId);
     $response->total = $res["pageInfo"]["total"];
     //判断是否为MSD医生
     $isMsdSpace = FlowMarkClient::getInstance()->isMarkForSpace($patientSignin->space, SpaceSymbol::TYPE_MSD);
     $response->isMsdSpace = $isMsdSpace;
     $groups = DAL::get()->find_all_by_spaceid_and_type('ReGroup', $patientSignin->space->id, ReGroup::TYPE_1, true);
     $groups = DAL::get()->find('regroup', array_keys($groups), true);
     $groupMemberCntList = ForumClient::getInstance()->getAllRegroupMemberCnt($patientSignin->space);
     $unGroup = DAL::get()->find_by_spaceid_and_type('ReGroup', $patientSignin->space->id, ReGroup::TYPE_2);
     $unGroup = DAL::get()->find('regroup', $unGroup->id, true);
     $response->unGroup = $unGroup;
     $defaultGroup = DAL::get()->find_id_ByPatientIdAndSpaceId('regroup', $patientSignin->patient->id, $patientSignin->space->id);
     $response->groups = $groups;
     $response->groupMemberCntList = $groupMemberCntList;
     if (empty($defaultGroup)) {
         $defaultGroup[0] = "-1";
     }
     $response->defaultGroupId = $defaultGroup[0];
     //判断是否为MSD患者
     $isMsdPatient = FlowMarkClient::getInstance()->isMarkPatientForSpace($patientSignin->space, $patientSignin->patient, SpaceSymbol::TYPE_MSD);
     $response->isMsdPatient = $isMsdPatient;
     //获取已标记患者数
     $msdPatientAmount = FlowMarkClient::getInstance()->getPatientAmountForSpace($patientSignin->space, SpaceSymbol::TYPE_MSD);
     $response->msdPatientAmount = $msdPatientAmount;
     $response->inspectGroupName = $inspectGroupName;
 }
 public function ajaxEditPatientCourseDetail($request, $response)
 {
     /*{{{*/
     $patientCourseDetailCategoryId = $request->childCategory ? $request->childCategory : $request->parentCategory;
     PatientCourseClient::getInstance()->editPatientCourseDetail($request->patientCourseDetailContentId, $patientCourseDetailCategoryId, $request->categoryOccurDate);
     return parent::DIRECT_OUTPUT;
 }