Browse Source

保存医案相关优化

pull/1/head
pengda 9 months ago
parent
commit
8290cb7dc6
  1. 87
      control/index.php
  2. 68
      model/mUserCase.php

87
control/index.php

@ -75,73 +75,42 @@ class index extends publicBase {
public function ajax_save_user_case() { public function ajax_save_user_case() {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
if(empty($uid) || empty($token))$this->ajax_json(false, '非法请求'); $case_id = $this->post('case_id')+0;
if(empty($uid) || empty($token) || empty($case_id))$this->ajax_json(false, '非法请求');
$mUser = new mUser();
$is_login = $mUser->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$mUserCase = new mUserCase();
$name = $this->post('name');
if(empty($name)) $this->ajax_json(false, '药方名称不能为空');
$id = $this->post('id'); $data = array(
if($id){ 'name' => trim($this->post('name')),
$data = array( 'patient_name' => trim($this->post('patient_name')),
'uid' => $uid, 'patient_age' => $this->post('patient_age')+0,
'name' => $_POST['name'], 'patient_sex' => $this->post('patient_sex')+0,
'feedback' => $_POST['feedback'], 'patient_say' => trim($this->post('patient_say')),
); 'first_diagnosis' => trim($this->post('first_diagnosis')),
'diagnosis' => trim($this->post('diagnosis')),
'prescribe_num' => $this->post('prescribe_num')+0,
'prescribe_herb' => $this->post('prescribe_herb'),
);
$res = $mUserCase->updateUserCase($id,$data); $m_user_case = new mUserCase();
if(!$res)$this->ajax_json(false, $mUserCase->getError()); $id = $m_user_case->createUserCase($uid, $token, $case_id, $data);
if(!$id)$this->ajax_json(false, $m_user_case->getError());
$this->ajax_json(true, '保存成功'); $this->ajax_json(true, '保存成功',array('id' => $id));
} }
$case_id = $this->post('case_id'); public function ajax_update_user_case() {
$patient_name = $this->post('patient_name'); $uid = $this->post('uid');
$patient_age = $this->post('patient_age')+0; $token = $this->post('token');
$patient_sex = $this->post('patient_sex')+0; $id = $this->post('id')+0;
$prescribe_num = $this->post('prescribe_num')+0; if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求');
$prescribe_herb = $this->post('prescribe_herb');
$patient_say = $this->post('patient_say');
$first_diagnosis = $this->post('first_diagnosis');
$diagnosis = $this->post('diagnosis');
if(empty($case_id)) $this->ajax_json(false, '找不到相关药方');
if(empty($patient_name)) $this->ajax_json(false, '患者姓名不能为空');
if(empty($patient_age)) $this->ajax_json(false, '患者年龄不能为空');
if(empty($prescribe_num)) $this->ajax_json(false, '开药数量不能为空');
if(empty($prescribe_herb)) $this->ajax_json(false, '开药详情不能为空');
if(empty($patient_say)) $this->ajax_json(false, '主诉不能为空');
if(empty($first_diagnosis)) $this->ajax_json(false, '舌诊脉诊不能为空');
if(empty($diagnosis)) $this->ajax_json(false, '诊断不能为空');
$prescribe_herb = $mUserCase->formatUserCaseHerbs($uid, $prescribe_herb);
if(!$prescribe_herb)$this->ajax_json(false, $mUserCase->getError());
$data = array( $data = array(
'name' => $name, 'name' => trim($this->post('name')),
'patient_name' => $patient_name, 'feedback' => trim($this->post('feedback')),
'patient_age' => $patient_age,
'patient_sex' => $patient_sex,
'patient_say' => $patient_say,
'first_diagnosis' => $first_diagnosis,
'diagnosis' => $diagnosis,
'prescribe_num' => $prescribe_num,
'prescribe_herb' => $prescribe_herb,
'case_id' => $case_id,
'uid' => $uid,
); );
$id = $mUserCase->createUserCase($data); $m_user_case = new mUserCase();
if(!$id)$this->ajax_json(false, '保存失败'); $res = $m_user_case->updateUserCase($uid, $token, $id, $data);
if(!$res)$this->ajax_json(false, $m_user_case->getError());
//更新药方使用次数 这个后期会增加定时脚本去修正
$mCase = new mCase();
$mCase->updateCaseSearchNum($id);
$this->ajax_json(true, '保存成功',array('id' => $id)); $this->ajax_json(true, '保存成功',array('id' => $id));
} }

68
model/mUserCase.php

@ -15,21 +15,16 @@ class mUserCase extends mBase {
$this->user_herb_tbl = 'tcm_user_herb'; $this->user_herb_tbl = 'tcm_user_herb';
} }
public function updateUserCase($id,$data){ public function updateUserCase($uid, $token, $id, $data){
if(empty($data['name'])){ if(empty($data['name'])){$this->setError('药方名称不能为空');return false;}
$this->setError('药方名称不能为空'); if(empty($data['feedback'])){$this->setError('用药反馈不能为空');return false;}
return false;
}
if(empty($data['feedback'])){
$this->setError('用药反馈不能为空');
return false;
}
$res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $data['uid']))); $m_user = new mUser();
if(!$res){ $is_login = $m_user->validateToken($uid,$token);
$this->setError('更新失败'); if(!$is_login){$this->setError('请登录后操作');return false;}
return false;
} $res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid)));
if(!$res){$this->setError('更新失败');return false;}
return true; return true;
} }
@ -38,10 +33,7 @@ class mUserCase extends mBase {
$mCase = new mCase(); $mCase = new mCase();
$prescribe_herb = json_decode($prescribe_herb,true); $prescribe_herb = json_decode($prescribe_herb,true);
if(empty($prescribe_herb)){ if(empty($prescribe_herb)){$this->setError('开药详情为空');return false;}
$this->setError('开药详情为空');
return false;
}
$data = array(); $data = array();
foreach ($prescribe_herb as $item){ foreach ($prescribe_herb as $item){
@ -68,10 +60,7 @@ class mUserCase extends mBase {
} }
$user_herb_id = $this->obj->insert($this->user_herb_tbl, array('uid' => $uid,'name'=> $item['name'])); $user_herb_id = $this->obj->insert($this->user_herb_tbl, array('uid' => $uid,'name'=> $item['name']));
if(!$user_herb_id){ if(!$user_herb_id){$this->setError('添加自定义药材失败');return false;}
$this->setError('添加自定义药材失败');
return false;
}
$temp['herb_id'] = 'u_'.$user_herb_id; $temp['herb_id'] = 'u_'.$user_herb_id;
$data[] = $temp; $data[] = $temp;
@ -80,8 +69,39 @@ class mUserCase extends mBase {
return json_encode($data); return json_encode($data);
} }
public function createUserCase($info){ public function createUserCase($uid, $token, $case_id, $data){
return $this->obj->insert($this->tbl, $info); if($case_id<=0){$this->setError('找不到相关药方');return false;}
if(empty($data['patient_name'])){$this->setError('患者姓名不能为空');return false;}
if($data['patient_age']<=0){$this->setError('患者年龄不正确');return false;}
if($data['sex']<0){$this->setError('患者性别不能为空');return false;}
if($data['prescribe_num']<=0){$this->setError('开药数量不正确');return false;}
if(empty($data['prescribe_herb'])){$this->setError('开药详情不能为空');return false;}
if(empty($data['patient_say'])){$this->setError('主诉不能为空');return false;}
if(empty($data['first_diagnosis'])){$this->setError('舌诊脉诊不能为空');return false;}
if(empty($data['diagnosis'])){$this->setError('诊断不能为空');return false;}
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login){$this->setError('请登录后操作');return false;}
$m_case = new mCase();
$case = $m_case->getCaseById($case_id);
if(!$case){$this->setError('找不到相关药方');return false;}
//格式化医案开药详情
$prescribe_herb = $this->formatUserCaseHerbs($uid, $data['prescribe_herb']);
$data['prescribe_herb'] = $prescribe_herb;
$data['case_id'] = $case['id'];
$data['uid'] = $uid;
$id = $this->obj->insert($this->tbl, $data);
if(!$id){$this->setError('医案保存失败');return false;}
//更新药方使用次数 这个后期会增加定时脚本去修正
$m_case->updateCaseSearchNum($case_id);
return $id;
} }
public function getUserCaseInfo($id, $uid){ public function getUserCaseInfo($id, $uid){

Loading…
Cancel
Save