public function indexAction()
 {
     echo '<pre>';
     $tTime = time();
     $tH = date('H', $tTime);
     $tWhere = ' and PUNCTURE_NURSE is not NULL';
     if ($tH >= 22 && $tH <= 23) {
         $tWhere = '';
     }
     $tTRMO = new BqetreatmentrecordModel();
     $tUAMO = new UserassessmentModel();
     $tDWLMO = new DryweightlogModel();
     $tUMO = new UserModel();
     $tOci = new Orm_Oci();
     $tHSql = 'select patient_id,treatment_times,fluid_volume,dialyzer,dialysis_mach,volume_na,volume_ca,volume_hc,volume_quantity,vascular_access,body_weight,bodyweight_bef,bodyweight_increase,ultrafilt_quantity,ufr,treat_time,blood_quantity,first_agent,maitain,additional,total_quantity,t,p,r,bp1,bp2,actual_treat_time,bodyweight_after,actual_ultrafilt_quantity,t_after,p_after,bp1_after,bp2_after,treate_summary,puncture_nurse,treate_nurse,doctor_user,to_char(treate_date,\'YYYY-mm-dd\') treate_date,treate_mode,dfz,vein_puncture,artery_puncture,kidney_solidification,dialyze_allergy,takeoff_needle from  treatment_record where to_char(TREATE_DATE,\'YYYY-mm-dd\')  = \'' . date('Y-m-d', $tTime) . '\' ' . $tWhere;
     #$tHSql = 'select patient_id,treatment_times,fluid_volume,dialyzer,dialysis_mach,volume_na,volume_ca,volume_hc,volume_quantity,vascular_access,body_weight,bodyweight_bef,bodyweight_increase,ultrafilt_quantity,ufr,treat_time,blood_quantity,first_agent,maitain,additional,total_quantity,t,p,r,bp1,bp2,actual_treat_time,bodyweight_after,actual_ultrafilt_quantity,t_after,p_after,bp1_after,bp2_after,treate_summary,puncture_nurse,treate_nurse,doctor_user,to_char(treate_date,\'YYYY-mm-dd\') treate_date,treate_mode,dfz,vein_puncture,artery_puncture,kidney_solidification,dialyze_allergy,takeoff_needle from  treatment_record where to_char(TREATE_DATE,\'YYYY-mm-dd\')  between \'2015-10-08\' and \'2015-12-08\'';
     $tDatas = $tOci->getAll($tHSql);
     foreach ($tDatas as $tRow) {
         $tTRRow = $tTRMO->field('count(0) c')->where('patient_id = \'' . $tRow['PATIENT_ID'] . '\' and treate_date = \'' . $tRow['TREATE_DATE'] . '\'')->fRow();
         if (!empty($tTRRow['c'])) {
             continue;
         }
         foreach ($tRow as $k => $v) {
             $k = strtolower($k);
             $tData[$k] = $v;
         }
         $tUARow = $tUAMO->field('uid')->where('patient_id = \'' . $tRow['PATIENT_ID'] . '\'')->fRow();
         $tData['uid'] = empty($tUARow['uid']) ? 0 : $tUARow['uid'];
         echo $tTRMO->insert($tData);
         echo "\r\n";
         if (empty($tRow['BODY_WEIGHT'])) {
             continue;
         }
         if (!empty($tUid) && date('Y-m-d', $tTime) == $tRow['TREATE_DATE']) {
             #用户存在 并且干体重记录日期是今日 的话更新用户信息表
             $tData = array('id' => $tUid, 'dry_weight' => $tRow['BODY_WEIGHT']);
             $tUMO->update($tData);
         }
         $tDWLRow = $tDWLMO->field('id')->where('patient_id = \'' . $tRow['PATIENT_ID'] . '\' and date = \'' . $tRow['TREATE_DATE'] . '\'')->fRow();
         if (!empty($tDWLRow['id'])) {
             $tData = array('id' => $tDWLRow['id'], 'weight' => $tRow['BODY_WEIGHT'], 'updated' => $tTime);
             $tDWLMO->update($tData);
         } else {
             #干体重log
             $tData = array('weight' => $tRow['BODY_WEIGHT'], 'created' => $tTime, 'date' => $tRow['TREATE_DATE'], 'month' => date('Y-m', strtotime($tRow['TREATE_DATE'])), 'year' => date('Y', strtotime($tRow['TREATE_DATE'])), 'patient_id' => $tRow['PATIENT_ID']);
             $tDWLMO->insert($tData);
         }
     }
     exit;
 }
Example #2
0
 public function indexAction()
 {
     $p = $_REQUEST;
     if (!count($p)) {
         Tool_Fnc::ajaxMsg('参数错误');
     }
     $pPhone = empty($p['phone']) ? '' : trim($p['phone']);
     if (!Tool_Validate::mo($pPhone)) {
         Tool_Fnc::ajaxMsg('手机号不正确');
     }
     //判断手机号是否是白求恩
     $tBUserInfo = Oci_User::isPhone($pPhone);
     if (empty($tBUserInfo)) {
         Tool_Fnc::ajaxMsg('非白求恩用户,下一步完善必须资料', 1, array('user_type' => 0));
     }
     $pPassword = empty($p['ptxt']) ? '' : trim($p['ptxt']);
     #客户端发送的必须是md5的 密码
     $pCode = empty($p['code']) ? '0' : trim($p['code']);
     $pDid = empty($p['did']) ? '' : trim($p['did']);
     $tTime = time();
     if (empty($pPassword)) {
         Tool_Fnc::ajaxMsg('密码不能为空');
     }
     if (empty($pCode)) {
         Tool_Fnc::ajaxMsg('验证码不能为空');
     }
     if (!Tool_Validate::integer($pCode)) {
         Tool_Fnc::ajaxMsg('验证码格式错误');
     }
     if (strlen($pPassword) != 32) {
         Tool_Fnc::ajaxMsg('接口发送的必须是密文密码');
     }
     if (empty($pDid) || !Tool_Validate::az09($pDid)) {
         Tool_Fnc::ajaxMsg('did error');
     }
     $tUMO = new UserModel();
     $tUMO->begin();
     $tRow = $tUMO->field('count(0) c')->where('phone = \'' . $pPhone . '\'')->fRow();
     if (!empty($tRow['c'])) {
         Tool_Fnc::ajaxMsg('该手机已被他人使用,请重新输入');
     }
     $tKey = Tool_Fnc::newrand(4);
     $tMd5str = Tool_Fnc::markmd5($pPassword, $tKey);
     $tCodeMO = new PhonecodeModel();
     $tCodeCRow = $tCodeMO->check($pPhone, 1, $pCode);
     if ($tCodeCRow['status'] == 0) {
         Tool_Fnc::ajaxMsg($tCodeCRow['msg']);
     }
     $tData = array('phone' => $pPhone, 'reg_ip' => Tool_Fnc::realip(), "passwd" => $tMd5str, "reg_time" => $tTime, 'private_key' => $tKey, 'reg_did' => $pDid, 'user_type' => 1);
     if (!($tID = $tUMO->insert($tData))) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 001');
     }
     //did入库
     $tUDMO = new UserdidModel();
     $tUDRow = $tUDMO->field('count(0) c')->where('uid = ' . $tID . ' and did = \'' . $pDid . '\'')->fRow();
     if (empty($tUDRow['c'])) {
         $tData = array('uid' => $tID, 'did' => $pDid, 'created' => $tTime, 'ip' => Tool_Fnc::realip());
         if (!$tUDMO->insert($tData)) {
             $tUMO->back();
             Tool_Fnc::ajaxMsg('错误异常 002');
         }
     }
     $tTokenarr = $this->creattoken($tID);
     //获取数据
     $tSex = $tBUserInfo['SEX'] == '男' ? 1 : 0;
     $tPatientId = $tBUserInfo['PATIENT_ID'];
     //提取干体重
     $tDryWeight = Oci_User::getDryWeight($tPatientId);
     $tDatas = array('id' => $tID, 'nickname' => $tBUserInfo['NAME'], 'sex' => $tSex, 'dry_weight' => $tDryWeight['BODY_WEIGHT'], 'date_of_birth' => $tBUserInfo['DATE_OF_BIRTH'], 'headimg' => $tBUserInfo['PHOTO']);
     if (!$tUMO->update($tDatas)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 003');
     }
     //新建健康档案
     $tUserAssessment = Oci_User::getAssessment($tPatientId);
     $tUserAssessment['uid'] = $tID;
     $tUserAssessment['name'] = $tBUserInfo['NAME'];
     //his系统数据更新
     $tCMO = new CenterModel();
     $tCRow = $tCMO->field('id,name')->where(' center_id = \'' . $tBUserInfo['CENTER_ID'] . '\'')->fRow();
     if (!empty($tCRow['id'])) {
         $tUserAssessment['medical_id'] = $tCRow['id'];
         //用户透析中心字段更新
         $tUMedicalData = array('id' => $tID, 'center_id' => $tCRow['id'], 'medical_addr' => $tCRow['name']);
         if (!$tUMO->update($tUMedicalData)) {
             $tUMO->back();
             Tool_Fnc::ajaxMsg('错误异常 003');
         }
     } else {
         $tCenterdict = Oci_User::getCenterdict($tBUserInfo['CENTER_ID']);
         $tCData = array('center_id' => $tCenterdict['CENTER_ID'], 'center_code' => $tCenterdict['CENTER_CODE'], 'name' => $tCenterdict['CENTER_NAME'], 'position' => $tCenterdict['POSITION'], 'created' => $tTime);
         if (!($tUserAssessment['medical_id'] = $tCMO->insert($tCData))) {
             $tUMO->back();
             Tool_Fnc::ajaxMsg('错误异常 008');
         }
         //用户透析中心字段更新
         $tUMedicalData = array('id' => $tID, 'center_id' => $tUserAssessment['medical_id'], 'medical_addr' => $tCenterdict['CENTER_NAME']);
         if (!$tUMO->update($tUMedicalData)) {
             $tUMO->back();
             Tool_Fnc::ajaxMsg('错误异常 003');
         }
     }
     //健康档案
     $tUA = new UserassessmentModel();
     foreach ($tUserAssessment as $k => $v) {
         $tUserAssessmentData[strtolower($k)] = $v;
     }
     $tUserAssessmentData['created'] = $tTime;
     //添加透析方式默认值
     $tUserAssessmentData['method'] = 1;
     if (!$tUA->insert($tUserAssessmentData)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 004');
     }
     //干重记录表数据更新
     $tDWMO = new DryweightlogModel();
     /*$tDryWeightLog = array(
           'uid' => $tID,
           'weight' => $tDryWeight['BODY_WEIGHT'],
           'date' => $tDryWeight['TREATE_DATE'],
           'month' => date('Y-m',strtotime($tDryWeight['TREATE_DATE'])),
           'year' => date('Y',strtotime($tDryWeight['TREATE_DATE'])),
           'patient_id' => $tPatientId,
           'created' => time(),
       );*/
     $tSql = 'update ' . $tDWMO->table . ' set uid=' . $tID . ' where patient_id = \'' . $tPatientId . '\'';
     if (!$tDWMO->exec($tSql)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 005');
     }
     #更新白求恩排班表
     $tSDMO = new BqeschedulingdetailModel();
     $tSql = 'update ' . $tSDMO->table . ' set uid = ' . $tID . ' where patient_id = \'' . $tPatientId . '\'';
     if (!$tSDMO->exec($tSql)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 006');
     }
     #透析 - 治疗单主记录
     $tTRMO = new BqetreatmentrecordModel();
     $tSql = 'update ' . $tTRMO->table . ' set uid = ' . $tID . ' where patient_id = \'' . $tPatientId . '\'';
     if (!$tTRMO->exec($tSql)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('错误异常 007');
     }
     $tUMO->commit();
     //匿名转实名
     $tUMO->incognito_real($pDid, $tID);
     $tTokenarr = array_merge($tTokenarr, array('user_type' => 1));
     Tool_Fnc::ajaxMsg("注册成功,白求恩用户", 1, $tTokenarr);
     //注册成功返回token
 }
 public function yearAction()
 {
     $p = $_REQUEST;
     $pDate = empty($p['date']) ? '' : trim($p['date']);
     $pOpt = empty($p['opt']) ? 'left' : Tool_Fnc::safe_string($p['opt']);
     if (!empty($pDate) && !Tool_Validate::is_date($pDate)) {
         Tool_Fnc::ajaxMsg('日期不正确');
     }
     $tWhere = '';
     $tTime = strtotime($pDate);
     if ($pOpt == 'left') {
         if (!empty($pDate)) {
             $tEnd = date('Y-m-d', $tTime - 86400);
         } else {
             $tTime = time();
             $tEnd = date('Y-m-d');
         }
         $tStart = date('Y-m-d', $tTime - 86400 * 364);
     } else {
         if (!empty($pDate)) {
             $tStart = date('Y-m-d', $tTime + 86400);
         } else {
             $tTime = time();
             $tStart = date('Y-m-d');
         }
         $tEnd = date('Y-m-d', $tTime + 86400 * 364);
     }
     $tTRMO = new BqetreatmentrecordModel();
     $tTRDatas = $tTRMO->field('bodyweight_bef,bodyweight_after,treate_date')->where('uid = ' . $this->tUid . ' and treate_date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->order('treate_date asc')->fList();
     $tDWLMO = new DryweightlogModel();
     $tDWLDatas = $tDWLMO->field('weight,date')->where('uid = ' . $this->tUid . ' and date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->fList();
     //最开始日期
     $tSql = 'select treate_date from ' . $tTRMO->table . ' where uid = ' . $this->tUid . ' order by treate_date asc limit 1';
     $tTRMOList = $tTRMO->query($tSql);
     #用户最新干体重
     $tUMO = new UserModel();
     $tURow = $tUMO->field('dry_weight')->where('id = ' . $this->tUid)->fRow();
     //如果没有干体重 初始化
     $tDatearr = array();
     for ($i = 0; $i < 364; $i++) {
         $tDatearr[] = date('Y-m-d', strtotime($tStart) + 86400 * $i);
     }
     $tDWLDate = array();
     foreach ($tDWLDatas as $tRow) {
         $tDWLDate[] = $tRow['date'];
     }
     $tDatediff = array_diff($tDatearr, $tDWLDate);
     $tDiffarr = array();
     foreach ($tDatediff as $tDate) {
         break;
         #判断该日期之前的干体重
         $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date < ' . $tDate)->order('date desc')->limit('1')->fRow();
         if (count($tDWLRow)) {
             $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']);
             continue;
         }
         #判断该日期之后临近的干体重
         $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date > ' . $tDate)->order('date desc')->limit('1')->fRow();
         if (count($tDWLRow)) {
             $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']);
             continue;
         }
         #当前用户干体重
         $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tURow['dry_weight']);
     }
     #将没有干体重的天入库
     foreach ($tDiffarr as $tRow) {
         break;
         if ($tDWLMO->in_weight($this->tUid, $tRow['date'])) {
             continue;
         }
         $tData = array('weight' => $tRow['weight'], 'uid' => $this->tUid, 'created' => $tTime, 'date' => $tRow['date'], 'month' => date('Y-m', strtotime($tRow['date'])), 'year' => date('Y-m', strtotime($tRow['date'])));
         $tDWLMO->insert($tData);
     }
     #排除 只要有体重的 干体重╮(╯▽╰)╭
     $tTRDate = array();
     foreach ($tTRDatas as $tRow) {
         $tTRDate[] = $tRow['treate_date'];
     }
     foreach ($tDWLDatas as $tKey => $tRow) {
         if (!in_array($tRow['date'], $tTRDate)) {
             unset($tDWLDatas[$tKey]);
         }
     }
     $tDWLDatas = Tool_Fnc::arraySort($tDWLDatas, 'date', 'asc');
     Tool_Fnc::ajaxMsg('', 1, array('dry_weight' => $tDWLDatas, 'weight' => $tTRDatas, 'start_treate_date' => $tTRMOList[0]['treate_date']));
 }