public function userMedicineRemindFeedback($userId, $remindId, $result, $reason)
    {/*{{{*/
        $user = DAL::get()->find('user', $userId);
        if($user->isNull())
        {
            $this->setErrorCode(107);//账户不存在
            return 0;
        }

        $remind = DAL::get()->find('medicineuserremind',$remindId);
        if($remind->isNull())
        {
            $this->setErrorCode(400);//该用药提醒Id不存在
            return 0;
        }
        MedicineClient::getInstance()->userMedicineRemindFeedback($user, $remind, $result, $reason);
    }/*}}}*/
    public function showPatientDiseaseInfo($request, $response)
    {/*{{{*/
        $refId = $request->refid;
        $doctorPatientRef = DAL::get()->find('DoctorPatientRef', $refId);
        $followupOwner = $doctorPatientRef->user->getFollowupPatientSignin();
        $response->followupOwner = $followupOwner;

        //获取初始信息 
        $categoryIds = $followupOwner->getNfsDisease()->getInitialInfoCategoryIds();
        $categoryList = DAL::get()->find('HealthRecordProblemCategory', $categoryIds);
        $response->categoryList = $categoryList;
        //用药信息
        $medicineSchemeList = MedicineClient::getInstance()->getUserCurrentMedicineScheme($followupOwner->user->id);
        $response->medicineSchemeList = $medicineSchemeList;

        $response->diseaseName_questionContent_answerContent = FollowupClient::getInstance()->getDiseaseInfo($followupOwner->user);
    }/*}}}*/
 public function modifyMedicineDiarySubmit($request, $response)
 {
     /*{{{*/
     MedicineClient::getInstance()->modifyMedicineDiary($request->diaryid, $request->medicineanswers, $request->content);
     $response->setRedirect($response->router->urlfor('followup/nextmedicinediary', array('ticketId' => $request->ticketid)));
 }
 /**
  * @brief 当前流所对应随访患者的用药历史
  * @author lhl
  * @version branches/v2.14.23
  * @date 2013-07-25
  */
 public function medicineList($request, $response)
 {
     /*{{{*/
     $pageSize = 30;
     $nowPage = $request->getRequest('p', 1);
     $doctorPatientRefId = Codec::getInstance()->decodeId($request->refid);
     $ref = DAL::get()->find('DoctorPatientRef', $doctorPatientRefId);
     $response->ref = $ref;
     $out = MedicineClient::getInstance()->getMedicineEventLog($ref->user->id, $nowPage, $pageSize);
     $response->medicineEventLogList = $out['eventList'];
     $pageInfo = $out['pageInfo'];
     $pagelink = PageNav::getNavLink(PageNav::getPageNavTemplateForSpace('/flow/medicinelist?refid=' . $ref->id . '&userid=' . $ref->user->id . '&p='), $pageInfo['nowpage'], $pageInfo['pagesize'], $pageInfo['total']);
     $response->pageLink = $pagelink;
     $res = FlowClient::getInstance()->getFlowInfos($ref->id, $nowPage, $pageSize, array('curUserId' => $this->user->id));
     list($hasBooking, $hasTel, $bookingOrder, $telCase) = $this->getUnFinishedService($res['objects']);
     $response->hasBooking = $hasBooking;
     $response->hasTel = $hasTel;
     $patientSignin = DAL::get()->find_by_patientid_and_spaceid('FollowupOwner', $ref->patient->id, $this->space->id);
     $signinProblems = $patientSignin->getNfsDisease()->getSigninHealthProblems();
     $response->signinProblems = $signinProblems;
     $response->followupOwner = $patientSignin;
     $medicineUserSchemes = MedicineClient::getInstance()->getUserCurrentMedicineScheme($patientSignin->user->id);
     $response->medicineUserSchemes = $medicineUserSchemes;
 }
    public function medicineInput($request, $response)
    {/*{{{*/
        $user = $this->user;

        $hasMedSchemeEver = true;
        $medScheme = DAL::get()->find_by_userid("medicineuserscheme", $user->id);
        if ($medScheme->isNull() )
        {
            $hasMedSchemeEver = false;
        }
        $response->hasMedSchemeEver = $hasMedSchemeEver;

        $medicineId_dotime_answer = $this->medicineId_dotime_answer(MedicineClient::getInstance()->getLastSomeDaysCurrentMedicineAnswerList($user->id, 5));
        $response->medicineId_dotime_answer = $medicineId_dotime_answer;

        $schemeAnswers  = array();
        $schemesMinTimesArr = MedicineClient::getInstance()->getSchemesAndStartEndTime4user($user->id);
        $today = XDateTime::today();
        $firstDay = XDateTime::today()->addDay(-4);
        foreach (array(0,1,2,3,4) as $daysBefore)
        {
            foreach ($schemesMinTimesArr['list'] as $key => $medicineUserScheme)
            {
                $schemeAnswers[$daysBefore][$medicineUserScheme['scheme']->id] = array();
                $startTime = XDateTime::today()->addDay(-$daysBefore);
                if ($today->between($medicineUserScheme['starttime'], $medicineUserScheme['endtime']) || $firstDay->between($medicineUserScheme['starttime'], $medicineUserScheme['endtime']))
                {
                    if ($startTime->between($medicineUserScheme['starttime'], $medicineUserScheme['endtime']))
                    {
                        $answersId = DAL::get()->queryAnswerMedicineIdAndDoTimeReal("medicineanswer", $user->id, $medicineUserScheme['scheme']->id, $startTime->toShortString());
                        $answer = DAL::get()->find('medicineanswer', array_shift($answersId));
                        $schemeAnswers[$daysBefore][$medicineUserScheme['scheme']->id]['scheme'] = $medicineUserScheme['scheme'];
                        $schemeAnswers[$daysBefore][$medicineUserScheme['scheme']->id]['answer'] = $answer;
                    }
                }
            }
        }
        $response->schemeAnswers = $schemeAnswers;
        // TODO 需要重构到合适的位置, user 实体动态方法或者Answer的静态方法
        $hasMedicineAnswer = false;  // 是否曾记录过用药日记
        $medSchemes = DAL::get()->find_all_by_userid("medicineuserscheme", $user->id);
        foreach ($medSchemes as $key => $medScheme )
        {
            $medicineAnswers = DAL::get()->find_all_by_medicineuserschemeid('medicineAnswer', $medScheme->id); 
            if (count($medicineAnswers) > 0)
            {
                $hasMedicineAnswer = true;
                break;
            }
        }
        $response->hasMedicineAnswer = $hasMedicineAnswer;
    }/*}}}*/
       <th width="10%">剂量/次</th>
       <th width="10%">每日几次</th>
       <th width="20%">服用情况</th>
    </tr>

<?php 
        $dotimes = array();
        $newMedicineAnswers = array();
        foreach ($medicineAnswers as $ans) {
            if (!in_array($ans->doTime->toShortString(), $dotimes)) {
                $dotimes[] = $ans->doTime->toShortString();
            }
            $newMedicineAnswers[$ans->doTime->toShortString()][$ans->medicineUserScheme->id] = $ans;
        }
        foreach ($dotimes as $dotime) {
            $userSometimeMedicines = MedicineClient::getInstance()->getMedicineSchemeAtSomeTime4User($user->id, $diary->ctime->toShortString());
            $i = 0;
            foreach ($userSometimeMedicines as $userMedicine) {
                ?>
			<tr>
				<?php 
                if ($i == 0) {
                    ?>
				<td><?php 
                    echo $dotime;
                    ?>
</td>
				<?php 
                } else {
                    ?>
				<td></td>
 public function getUserCurrentMedicineScheme($request, $response)
 {
     /*{{{*/
     $response->medicineSchemeList = MedicineClient::getInstance()->getUserCurrentMedicineScheme($request->userid);
 }
 public function followupInfo($request, $response)
 {
     /*{{{*/
     $hospitalCaseNo = $request->hospitalcaseno;
     $response->hospitalCaseNo = $hospitalCaseNo;
     $realName = $request->realname;
     $response->realName = $realName;
     $userName = $request->username;
     $response->userName = $userName;
     $spaceId = $this->space->id;
     $currentDiseaseSpaceRef = DAL::get()->find_by_spaceid('NfsDiseaseSpaceRef', $spaceId);
     $ownerIds = array();
     //如果什么都没填直接点击搜索
     if (empty($hospitalCaseNo) && empty($realName) && empty($userName)) {
         $page = $request->getRequest('page', 1);
         $count = 15;
         $res = FollowupClient::getInstance()->getOwnerOfOneDiseaseBySpaceId($page, $count, $spaceId);
         $ownerIds = $res['ids'];
         if (false == empty($res['pageInfo'])) {
             $response->pagelink = PageNav::getNavLink(PageNav::getPageNavTemplate('/adminpatient/followupinfo?page='), $res['pageInfo']['nowpage'], $res['pageInfo']['pagesize'], $res['pageInfo']['total']);
         }
     } else {
         $ownerList = array();
         //如果是点击列表中的链接
         if (false == empty($userName)) {
             $user = UserClient::getInstance()->getByUserName($userName);
             $owner = FollowupClient::getInstance()->getOpenedFollowupOwnerByUser($user->id);
             $diseaseSpaceRef = DAL::get()->find_by_spaceid('NfsDiseaseSpaceRef', $owner->space->id);
             if ($diseaseSpaceRef->nfsDisease->id == $currentDiseaseSpaceRef->nfsDisease->id) {
                 $ownerIds[] = $owner->id;
             }
         } else {
             $ownerIdArr = FollowupClient::getInstance()->getOwnerByHospitalCaseNOAndRealName($hospitalCaseNo, $realName);
             $ownerList = DAL::get()->find('FollowupOwner', $ownerIdArr);
             foreach ($ownerList as $owner) {
                 $diseaseSpaceRef = DAL::get()->find_by_spaceid('NfsDiseaseSpaceRef', $owner->space->id);
                 if ($diseaseSpaceRef->nfsDisease->id == $currentDiseaseSpaceRef->nfsDisease->id) {
                     $ownerIds[] = $owner->id;
                 }
             }
         }
     }
     $response->ownerIds = $ownerIds;
     if (1 == count($ownerIds)) {
         $owner = DAL::get()->find('FollowupOwner', $ownerIds[0]);
         $response->owner = $owner;
         $user = $owner->user;
         $res = FollowupClient::getInstance()->getOwnerOfOneDiseaseBySpaceId(0, 2000, $spaceId);
         $allOwnerIds = $res['ids'];
         $key = array_search($ownerIds[0], $allOwnerIds);
         $preKey = $key - 1;
         if ($preKey >= 0) {
             $preOwner = DAL::get()->find('FollowupOwner', $allOwnerIds[$preKey]);
             $preOwnerUserName = $preOwner->user->name;
             $response->preOwnerUserName = $preOwnerUserName;
         }
         $nextKey = $key + 1;
         if ($nextKey <= count($allOwnerIds) - 1) {
             $nextOwner = DAL::get()->find('FollowupOwner', $allOwnerIds[$nextKey]);
             $nextOwnerUserName = $nextOwner->user->name;
             $response->nextOwnerUserName = $nextOwnerUserName;
         }
         //PCI手术信息
         $category = DAL::get()->find_by_name('HealthRecordProblemCategory', '二、PCI手术信息');
         $healthProblems = $category->problems;
         $problemIds = array_keys($healthProblems);
         $answerList = HealthRecordClient::getInstance()->getHealthAnswerList4Initial($owner->user->id, $problemIds);
         $myAnswerList = array();
         foreach ($answerList as $answer) {
             if ($answer->isNull() == false) {
                 $myAnswerList[$answer->ref->problem->id] = $answer;
             }
         }
         $response->healthProblems = $healthProblems;
         $response->myAnswerList = $myAnswerList;
         //当前用药信息
         $medicineUserSchemes = MedicineClient::getInstance()->getUserCurrentMedicineScheme($user->id);
         $response->medicineUserSchemes = $medicineUserSchemes;
         $ref = DAL::get()->find_by_spaceid_and_patientid('DoctorPatientRef', $owner->space->id, $owner->patient->id);
         $response->refId = $ref->getEncodeId();
         //复查信息
         if ($user->isNull()) {
             echo '操作的用户不存在';
             return parent::DIRECT_OUTPUT;
         }
         $patientSignin = $user->getFollowupPatientSignin($spaceId);
         //随访已经关闭
         if ($patientSignin->isNull() == false && $patientSignin->isCloseFollowup()) {
             echo '所操作的用户不是随访用户或随访已经关闭';
             return parent::DIRECT_OUTPUT;
         }
         $response->ownerUser = $user;
         $response->patient = $patientSignin->patient;
         $ticketId = $request->ticketId;
         $checkupTaskArray = array();
         $checkupQueues = array();
         $customizeQueues = CheckupClient::getInstance()->getUserCustomizeQueue($user->id);
         if (empty($customizeQueues) == false) {
             $checkupQueues = $customizeQueues;
         } else {
             $checkupQueues = CheckupClient::getInstance()->getUserFollowupQueues($user->id);
         }
         foreach ($checkupQueues as $checkupQueue) {
             $filter = 'checkuptaskqueueid=' . $checkupQueue->id;
             $checkupTasks = array();
             // 对任务排序
             $taskArray = DAL::get()->find_all_by_condition('checkuptask', $filter);
             $queue = $checkupQueue;
             $nowTask = $queue->firstTask;
             $nextTaskId = $nowTask->nextTaskId;
             while ($nextTaskId != 0) {
                 $nowTask = $taskArray[$nextTaskId];
                 $nextTaskId = $nowTask->nextTaskId;
                 if ($nowTask->isUsed()) {
                     $checkupTasks[] = $nowTask;
                 }
             }
             $checkupTaskArray[$checkupQueue->id]['checkupTasks'] = $checkupTasks;
         }
         if (empty($ticketId)) {
             $tL = CheckupClient::getInstance()->getUserLastTickets($user->id);
             foreach ($tL as $t) {
                 if ($t->task->isUsed() && ($t->task->isCustomizeTask() || $t->task->isFollowupTask() || $t->task->isTemporaryTask())) {
                     $ticketId = $t->id;
                     break;
                 }
             }
         }
         // 读取临时任务
         $tempTaskList = CheckupClient::getInstance()->getUserEffectedTemporaryTasks($user->id);
         $this->getTaskList($tempTaskList);
         $response->cycleTaskTimeMap = $cycleTaskTimeMap;
         if (empty($checkupTaskArray)) {
             echo '此患者没有复查任务';
             return parent::DIRECT_OUTPUT;
         }
         $response->checkupTaskArray = $checkupTaskArray;
         $checkupTicket = DAL::get()->find('checkupticket', $ticketId);
         $response->ref = DAL::get()->find_by_spaceid_and_patientid('DoctorPatientRef', $patientSignin->space->id, $patientSignin->patient->id);
         $leaveHosDayArr = array();
         if (false == $checkupTicket->isNull()) {
             $leaveHosDayArr = $patientSignin->getDiffLeaveHospitalDay($checkupTicket->startTime->addDay($checkupTicket->task->queue->noticeDay));
         }
         //读取定制复查过去的任务
         $pastTicketTasks = array();
         $checkupPastTaskQueues = CheckupClient::getInstance()->getUserPastCustomizeQueue($user->id);
         foreach ($checkupPastTaskQueues as $queue) {
             $tasks = CheckupClient::getInstance()->getUserPastTicketTask($queue->id);
             foreach ($tasks as $task) {
                 $pastTicketTasks[$queue->id][] = $task;
             }
         }
         $response->pastTicketTasks = $pastTicketTasks;
         $response->ticketId = $ticketId;
         $response->leaveHosDayArr = $leaveHosDayArr;
         $response->checkupTicket = $checkupTicket;
     }
 }
 public function ajaxGetPresentMedicine($request, $response)
 {
     /*{{{*/
     $customerId = $request->customerid;
     $response->modelName = $request->modelname;
     $customer = DAL::get()->find("FollowupCustomer", $customerId);
     DBC::requireFalse($customer->isNull(), "customer{$customerId}不存在");
     $medicineSchemeList = MedicineClient::getInstance()->getUserCurrentMedicineScheme($customer->userId);
     $str = "当前用药:\n";
     foreach ($medicineSchemeList as $medicineScheme) {
         $s = $medicineScheme->medicine->getFullMedicineName() . "  " . $medicineScheme->value . $medicineScheme->unit . "  " . $medicineScheme->medicineUsage;
         $str .= $s . "\n";
     }
     echo $str;
     return parent::DIRECT_OUTPUT;
 }