Browse Source

代码风格

pull/1/head
pengda 9 months ago
parent
commit
537896470f
  1. 3
      control/index.php
  2. 103
      model/mCase.php
  3. 128
      model/mUserCase.php

3
control/index.php

@ -255,8 +255,7 @@ class index extends publicBase {
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url));
}
public function export_pdf()
{
public function export_pdf(){
$key = $this->get('key');
$m_user_case = new mUserCase();

103
model/mCase.php

@ -21,14 +21,32 @@ class mCase extends mBase {
}
public function createCase($name, $source, $original, $method, $herbs) {
if(empty($name)){$this->setError('药方名称不能为空');return false;}
if(empty($source)){$this->setError('药方来源不能为空');return false;}
if(empty($original)){$this->setError('药方原方不能为空');return false;}
if(empty($method)){$this->setError('药方用法不能为空');return false;}
if(empty($herbs)){$this->setError('药方药材不能为空');return false;}
if (empty($name)) {
$this->setError('药方名称不能为空');
return false;
}
if (empty($source)) {
$this->setError('药方来源不能为空');
return false;
}
if (empty($original)) {
$this->setError('药方原方不能为空');
return false;
}
if (empty($method)) {
$this->setError('药方用法不能为空');
return false;
}
if (empty($herbs)) {
$this->setError('药方药材不能为空');
return false;
}
$id = $this->obj->insert($this->tbl, array('name'=>$name, 'source'=>$source, 'original'=>$original, 'method'=>$method));
if(!$id){$this->setError('添加失败');return false;}
if (!$id) {
$this->setError('添加失败');
return false;
}
//格式化药方对应的药材数据
$case_herb = $this->formatCaseHerb($id, $herbs);
@ -39,16 +57,30 @@ class mCase extends mBase {
}
public function updateCase($id, $name, $source, $original, $method, $herbs) {
if(empty($herbs)){$this->setError('药方药材不能为空');return false;}
if (empty($herbs)) {
$this->setError('药方药材不能为空');
return false;
}
$data = array();
if(!empty($name)){$data['name']=$name;}
if(!empty($source)){$data['source']=$source;}
if(!empty($original)){$data['original']=$original;}
if(!empty($method)){$data['method']=$method;}
if (!empty($name)) {
$data['name']=$name;
}
if (!empty($source)) {
$data['source']=$source;
}
if (!empty($original)) {
$data['original']=$original;
}
if (!empty($method)) {
$data['method']=$method;
}
$res = $this->obj->update($this->tbl, $data, array('sql' => '`id`=?', 'vals' => array($id)));
if(!$res){$this->setError('更新失败');return false;}
if (!$res) {
$this->setError('更新失败');
return false;
}
//格式化药方对应的药材数据
$case_herb = $this->formatCaseHerb($id, $herbs);
@ -83,14 +115,20 @@ class mCase extends mBase {
public function createHerb($info) {
$herb_id = $this->obj->insert($this->herb_tbl, $info);
if(empty($herb_id)){$this->setError('添加药材失败');return false;}
if (empty($herb_id)) {
$this->setError('添加药材失败');
return false;
}
return $herb_id;
}
public function createCaseHerb($info) {
$res = $this->obj->mutiInsert($this->case_herb_tbl, $info);
if(!$res){$this->setError('添加药方药材失败');return false;}
if (!$res) {
$this->setError('添加药方药材失败');
return false;
}
return true;
}
@ -106,20 +144,32 @@ class mCase extends mBase {
foreach ($old_data as $key => $value) {
if (!isset($new_data[$key])) {
$res = $this->obj->delete($this->case_herb_tbl, array('sql' => '`id`=?', 'vals' => array($value['id'])));
if(!$res){$this->setError('删除药方药材失败');return false;}
if (!$res) {
$this->setError('删除药方药材失败');
return false;
}
}
$res = $this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql' => '`id`=?', 'vals' => array($value['id'])));
if(!$res){$this->setError('更新药方药材失败');return false;}
if (!$res) {
$this->setError('更新药方药材失败');
return false;
}
}
}else{
//需要增加药方对应的药材
foreach ($new_data as $key => $value) {
if (!isset($old_data[$key])) {
$res = $this->obj->insert($this->case_herb_tbl, $value);
if(!$res){$this->setError('添加药方药材失败');return false;}
if (!$res) {
$this->setError('添加药方药材失败');
return false;
}
}
$res = $this->obj->update($this->case_herb_tbl, $value, array('sql' => '`id`=?', 'vals' => array($old_data[$key]['id'])));
if(!$res){$this->setError('更新药方药材失败');return false;}
if (!$res) {
$this->setError('更新药方药材失败');
return false;
}
}
}
@ -149,16 +199,25 @@ class mCase extends mBase {
public function getCaseInfo($id) {
//药方信息
$case = $this->getCaseById($id);
if(empty($case)){$this->setError('查询不到此药方');return false;}
if (empty($case)) {
$this->setError('查询不到此药方');
return false;
}
//药方药材信息
$case_herb = $this->getCaseHerbByCaseId($case['id']);
if(empty($case_herb)){$this->setError('药方药材查询失败');return false;}
if (empty($case_herb)) {
$this->setError('药方药材查询失败');
return false;
}
//药材名称
$herb_ids = array_column($case_herb,'herb_id');
$herb = $this->getHerbByIds($herb_ids);
if(empty($herb)){$this->setError('药材名称查询失败');return false;}
if (empty($herb)) {
$this->setError('药材名称查询失败');
return false;
}
return array(
'case' => $case,
@ -198,7 +257,7 @@ class mCase extends mBase {
}
public function getCollectLogTotal() {
return $this->obj->count($this->collect_log_tbl, array());
return $this->obj->count($this->collect_log_tbl);
}
}

128
model/mUserCase.php

@ -16,11 +16,20 @@ class mUserCase extends mBase {
}
public function updateUserCase($uid, $id, $data) {
if(empty($data['name'])){$this->setError('药方名称不能为空');return false;}
if(empty($data['feedback'])){$this->setError('用药反馈不能为空');return false;}
if (empty($data['name'])) {
$this->setError('药方名称不能为空');
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, $uid)));
if(!$res){$this->setError('更新失败');return false;}
if (!$res) {
$this->setError('更新失败');
return false;
}
return true;
}
@ -29,7 +38,10 @@ class mUserCase extends mBase {
$mCase = new mCase();
$prescribe_herb = json_decode($prescribe_herb,true);
if(empty($prescribe_herb)){$this->setError('开药详情为空');return false;}
if (empty($prescribe_herb)) {
$this->setError('开药详情为空');
return false;
}
$data = array();
foreach ($prescribe_herb as $item) {
@ -56,7 +68,10 @@ class mUserCase extends mBase {
}
$user_herb_id = $this->obj->insert($this->user_herb_tbl, array('uid' => $uid,'name'=> $item['name']));
if(!$user_herb_id){$this->setError('添加自定义药材失败');return false;}
if (!$user_herb_id) {
$this->setError('添加自定义药材失败');
return false;
}
$temp['herb_id'] = 'u_'.$user_herb_id;
$data[] = $temp;
@ -66,30 +81,66 @@ class mUserCase extends mBase {
}
public function createUserCase($uid, $case_id, $data) {
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;}
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_case = new mCase();
$case = $m_case->getCaseById($case_id);
if(!$case){$this->setError('找不到相关药方');return false;}
if (!$case) {
$this->setError('找不到相关药方');
return false;
}
//格式化医案开药详情
$prescribe_herb = $this->formatUserCaseHerbs($uid, $data['prescribe_herb']);
if(!$prescribe_herb){$this->setError('医案开药详情不正确');return false;}
if (!$prescribe_herb) {
$this->setError('医案开药详情不正确');
return false;
}
$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;}
if (!$id) {
$this->setError('医案保存失败');
return false;
}
//更新药方使用次数 这个后期会增加定时脚本去修正
$m_case->updateCaseSearchNum($case_id);
@ -99,14 +150,20 @@ class mUserCase extends mBase {
public function getUserCaseInfo($uid, $id, $is_format_data = false) {
$user_case = $this->obj->select($this->tbl, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid)));
if(empty($user_case)){$this->setError('找不到相关医案');return false;}
if (empty($user_case)) {
$this->setError('找不到相关医案');
return false;
}
$prescribe_herb = json_decode($user_case['prescribe_herb'],true);
$user_case['prescribe_herb'] = $prescribe_herb;
$mCase = new mCase();
$case = $mCase->getCaseById($user_case['case_id']);
if(empty($case)){$this->setError('找不到相关药方');return false;}
if (empty($case)) {
$this->setError('找不到相关药方');
return false;
}
$herb_ids = $user_herb_ids = array();
foreach ($prescribe_herb as $item) {
@ -116,12 +173,18 @@ class mUserCase extends mBase {
}
$herb_ids[] = $item['herb_id'];
}
if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;}
if (empty($herb_ids) && empty($user_herb_ids)) {
$this->setError('医案开药详情不正确');
return false;
}
$mCase = new mCase();
$herb = $mCase->getHerbByIds($herb_ids);
$user_herb = $this->getUserHerbByIds($user_herb_ids);
if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
if (empty($herb) && empty($user_herb)) {
$this->setError('找不到相关药材');
return false;
}
$data = array(
'data' => $user_case,
@ -137,13 +200,19 @@ class mUserCase extends mBase {
public function getUserCaseList($uid, $page_num, $page_size, $get_case_herb = false, $is_format_data = false) {
$offset = ($page_num - 1) * $page_size;
$user_case = $this->obj->selectAll($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid)), 'case_time desc ', array($offset, $page_size));
if(empty($user_case)){$this->setError('找不到相关医案');return false;}
if (empty($user_case)) {
$this->setError('找不到相关医案');
return false;
}
$case_ids = array_column($user_case,'case_id');
$m_case = new mCase();
$case = $m_case->getCaseByIds($case_ids);
if(empty($case)){$this->setError('找不到相关药方');return false;}
if (empty($case)) {
$this->setError('找不到相关药方');
return false;
}
$case = array_column($case,null,'id');
@ -163,11 +232,17 @@ class mUserCase extends mBase {
$herb_ids[] = $herb_item['herb_id'];
}
}
if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;}
if (empty($herb_ids) && empty($user_herb_ids)) {
$this->setError('医案开药详情不正确');
return false;
}
$herb = $m_case->getHerbByIds($herb_ids);
$user_herb = $this->getUserHerbByIds($user_herb_ids);
if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
if (empty($herb) && empty($user_herb)) {
$this->setError('找不到相关药材');
return false;
}
$data = array(
'list' => $user_case,
@ -221,8 +296,7 @@ class mUserCase extends mBase {
return $data;
}
public function createPdf($uid, $data_key)
{
public function createPdf($uid, $data_key) {
$mpdf = new mPDF();
$htmlContent = file_get_contents(sprintf(RQ_USER_CASE_HTML_URL, $data_key));

Loading…
Cancel
Save