public function actionView()
 {
     $this->authenUser();
     $caseId = null;
     $caseData = null;
     $patientData = null;
     $caseResponses = null;
     $caseMedData = NULL;
     if (isset($_REQUEST['caseId'])) {
         $caseId = $_REQUEST['caseId'];
         if (!is_numeric($caseId)) {
             $this->redirect($statusCode = 404);
         }
         // invalid request redirected to 404 not found page
     }
     if ($caseId != Null) {
         $caseData = PatientCase::model()->find('cid=?', array($caseId));
         if ($caseData->hms_patient_pid != $this->userId) {
             $this->redirect($statusCode = 404);
         }
         // invalid request redirected to 404 not found page
         $dbConnection = Yii::app()->db;
         $command = $dbConnection->createCommand("SELECT id,response,name,rec_date  FROM hms_patient_case_doc_responses , hms_doctor WHERE \n                    hms_patient_case_cid=" . $caseId . " \n                    AND hms_doctor_did=did ORDER BY rec_date DESC ");
         $caseResponses = $command->queryAll();
         $caseMedData = PatientCaseMed::model()->findAll('patient_case_cid=?', array($caseId));
     }
     $this->render('view', array('patientData' => $patientData, 'caseData' => $caseData, 'caseResponses' => $caseResponses, 'caseMedData' => $caseMedData));
 }
 /**
  * newPatientCase 
  * 创建病历头 
  * @param mixed $doctorOwnerId 必填 
  * @param mixed $name 
  * @param mixed $age 
  * @param mixed $sex 
  * @param mixed $address 
  * @param mixed $phone 
  * @param mixed $$province 
  * @param mixed $city 
  * @param mixed $src 
  * @param mixed $medicalCard 
  * @param mixed $personIdCard 
  * @param mixed $patientIdCard 
  * @param mixed $mark 
  * @param mixed $attachmentids 
  * @param mixed $groupId 
  * @param mixed $isAttention 0 未关注 1 重点关注 
  * @access public
  * @return void
  */
 public function newPatientCase($userId, $caseSummary, $clientCreateTime, $clientUpdateTime, $clientId, $name, $age, $sex, $address, $phone, $province, $city, $src, $medicalCard, $personIdCard, $patientIdCard, $mark, $diagnose, $attachmentIds, $groupId, $isAttention, $patientCaseId)
 {/*{{{*/
     if(empty($clientId))
     {
         return 0;
     }
     $doctorOwner = DAL::get()->find_by_userid('DoctorOwner',$userId);
     if($doctorOwner->isNull())
     {
         return 0;
     }
     if (false == empty($patientCaseId)) 
     {
         $oldPatientCase = DAL::get()->find('PatientCase', $patientCaseId);
     }
     $oldPatientCase = (false == isset($oldPatientCase) || $oldPatientCase->isNull()) ? PatientCase::getCaseByOwnerAndCaseSummary($doctorOwner->id, $caseSummary) : $oldPatientCase;
     if($oldPatientCase->isNull())
     {
         $patientCaseId = PatientCourseClient::getInstance()->createPatientCaseWithAttach($doctorOwner, $caseSummary, $clientCreateTime, $clientUpdateTime, $name, $age, $sex, $address, $phone, $province, $city, $src, $medicalCard, $personIdCard, $patientIdCard, $mark, $diagnose, $attachmentIds);  
         if($this->isOldVersion($_REQUEST['os'], $_REQUEST['v']))
         {
             $this->newPatientCourseWithAllDetail($userId, $patientCaseId, 1, PatientCourse::TYPE_FIRST_MEDICAL,  md5($patientCaseId.XDateTime::now()->toString()), XDateTime::now(), '', array());
         }
     }
     else 
     {
         $patientCaseId = $oldPatientCase->id;
         PatientCourseClient::getInstance()->modifyPatientCaseClientUpdateTime($patientCaseId, $clientUpdateTime);
     }
     $patientCase = DAL::get()->find('patientCase', $patientCaseId);
     $group = DAL::get()->find('regroup', $groupId);
     if($group->isNull())
     {
         $unGroup = DAL::get()->find_by_doctorownerid_and_type('regroup', $doctorOwner->id, ReGroup::TYPE_2);
         $groupId = $unGroup->id;
     }
     if ($groupId > 0) 
     {
         PatientClubClient::getInstance()->updateMember($doctorOwner->user->id, $patientCaseId, $groupId, ReGroupMember::MEMBER_PATIENT_TYPE_MYINPUT, $isAttention);
     }
     $this->content = array('clientId'=>$clientId, 'patientCaseId'=>$patientCase->id, 'ver'=>$patientCase->ver);
 }/*}}}*/
 public function actionAddCase()
 {
     $this->authenUser();
     $patientId;
     $formAddCase = new formAddCase();
     $patientData;
     if (isset($_REQUEST['patientId'])) {
         $patientId = $_REQUEST['patientId'];
         if (!is_numeric($patientId)) {
             $this->redirect($statusCode = 404);
         } else {
             $test;
             $patientData = Patient::model()->find('pid=?', array($patientId));
             if ($patientData == null) {
                 $this->redirect($statusCode = 404);
             }
             // invalid request redirected to 404 not found page
             $caseData = PatientCase::model()->find('hms_patient_pid=?', array($patientId));
             if (isset($_POST['formAddCase'])) {
                 $addPatientCase = new PatientCase();
                 $addPatientCase->attributes = $_POST['formAddCase'];
                 $addPatientCase->hms_patient_pid = $patientId;
                 $addPatientCase->recDate();
                 $addPatientCase->save();
                 //Yii::app()->end();
             }
         }
     } else {
         $this->redirect($statusCode = 404);
     }
     // invalid request redirected to 404 not found page
     $this->render('addCase', array('formAddCase' => $formAddCase, 'patientData' => $patientData));
 }