|
@ -149,56 +149,33 @@ class mUserCase extends mBase { |
|
|
return $id; |
|
|
return $id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserCaseInfo($uid, $id, $is_format_data = false) { |
|
|
public function getUserCaseInfo($uid, $id) { |
|
|
$user_case = $this->obj->select($this->tbl, array('sql' => '`id`=? and `uid`=?', 'vals' => array($id, $uid))); |
|
|
$user_case = $this->obj->select($this->tbl, array('sql' => '`id`=? and `uid`=?', 'vals' => array($id, $uid))); |
|
|
if (empty($user_case)) { |
|
|
if (empty($user_case)) { |
|
|
$this->setError('找不到相关医案'); |
|
|
$this->setError('找不到相关医案'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$prescribe_herb = json_decode($user_case['prescribe_herb'], true); |
|
|
|
|
|
$user_case['prescribe_herb'] = $prescribe_herb; |
|
|
|
|
|
|
|
|
|
|
|
$mCase = new mCase(); |
|
|
$mCase = new mCase(); |
|
|
$case = $mCase->getCaseById($user_case['case_id']); |
|
|
$case = $mCase->getCaseInfo($user_case['case_id']); |
|
|
if (empty($case)) { |
|
|
if (empty($case)) { |
|
|
$this->setError('找不到相关药方'); |
|
|
$this->setError('找不到相关药方'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$herb_ids = $user_herb_ids = array(); |
|
|
$prescribe_herb = json_decode($user_case['prescribe_herb'], true); |
|
|
foreach ($prescribe_herb as $item) { |
|
|
$user_case['prescribe_herb'] = $prescribe_herb; |
|
|
if (strpos($item['herb_id'], 'u_') !== false) { |
|
|
|
|
|
$user_herb_ids[] = str_replace('u_', '', $item['herb_id']); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
$herb_ids[] = $item['herb_id']; |
|
|
|
|
|
} |
|
|
|
|
|
if (empty($herb_ids) && empty($user_herb_ids)) { |
|
|
|
|
|
$this->setError('医案开药详情不正确'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$mCase = new mCase(); |
|
|
$user_case_herb = $this->getUserCaseHerb(array($prescribe_herb)); |
|
|
$herb = $mCase->getHerbByIds($herb_ids); |
|
|
|
|
|
$user_herb = $this->getUserHerbByIds($user_herb_ids); |
|
|
|
|
|
if (empty($herb) && empty($user_herb)) { |
|
|
|
|
|
$this->setError('找不到相关药材'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$data = array( |
|
|
return array( |
|
|
'data' => $user_case, |
|
|
'user_case' => $user_case, |
|
|
|
|
|
'user_case_herb' => $user_case_herb, |
|
|
'case_data' => $case, |
|
|
'case_data' => $case, |
|
|
'herb_data' => array_column($herb,null,'id'), |
|
|
|
|
|
'user_herb_data' => array_column($user_herb,null,'id'), |
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if ($is_format_data) return $this->formatUserCaseData($data); |
|
|
|
|
|
return $data; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserCaseList($uid, $page_num, $page_size, $get_case_herb = false, $is_format_data = false) { |
|
|
public function getUserCaseList($uid, $page_num, $page_size) { |
|
|
$offset = ($page_num - 1) * $page_size; |
|
|
$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)); |
|
|
$user_case = $this->obj->selectAll($this->tbl, array('sql' => '`uid`=?', 'vals' => array($uid)), 'case_time desc ', array($offset, $page_size)); |
|
|
if (empty($user_case)) { |
|
|
if (empty($user_case)) { |
|
@ -215,16 +192,15 @@ class mUserCase extends mBase { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$case = array_column($case, null, 'id'); |
|
|
return array( |
|
|
|
|
|
'user_case' => $user_case, |
|
|
if (!$get_case_herb) return array('list' => $user_case, 'case_data' => $case); |
|
|
'case_data' => array_column($case, null, 'id') |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//获取医案开药详情 |
|
|
public function getUserCaseHerb($prescribe_herb_arr) { |
|
|
$herb_ids = $user_herb_ids = array(); |
|
|
$herb_ids = $user_herb_ids = array(); |
|
|
foreach ($user_case as &$item) { |
|
|
foreach ($prescribe_herb_arr as $prescribe_herb) { |
|
|
$prescribe_herb = json_decode($item['prescribe_herb'], true); |
|
|
|
|
|
$item['prescribe_herb'] = $prescribe_herb; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($prescribe_herb as $herb_item) { |
|
|
foreach ($prescribe_herb as $herb_item) { |
|
|
if (strpos($herb_item['herb_id'], 'u_') !== false) { |
|
|
if (strpos($herb_item['herb_id'], 'u_') !== false) { |
|
|
$user_herb_ids[] = str_replace('u_', '', $herb_item['herb_id']); |
|
|
$user_herb_ids[] = str_replace('u_', '', $herb_item['herb_id']); |
|
@ -233,27 +209,29 @@ class mUserCase extends mBase { |
|
|
$herb_ids[] = $herb_item['herb_id']; |
|
|
$herb_ids[] = $herb_item['herb_id']; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (empty($herb_ids) && empty($user_herb_ids)) { |
|
|
if (empty($herb_ids) && empty($user_herb_ids)) { |
|
|
$this->setError('医案开药详情不正确'); |
|
|
$this->setError('医案开药详情不正确'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$m_case = new mCase(); |
|
|
$herb = $m_case->getHerbByIds($herb_ids); |
|
|
$herb = $m_case->getHerbByIds($herb_ids); |
|
|
|
|
|
if (!empty($user_herb_ids)) { |
|
|
$user_herb = $this->getUserHerbByIds($user_herb_ids); |
|
|
$user_herb = $this->getUserHerbByIds($user_herb_ids); |
|
|
if (empty($herb) && empty($user_herb)) { |
|
|
if (empty($user_herb)) { |
|
|
$this->setError('找不到相关药材'); |
|
|
$this->setError('找不到相关自定义药材'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$data = array( |
|
|
foreach ($user_herb as &$item) { |
|
|
'list' => $user_case, |
|
|
$item['id'] = "u_" . $item['id']; |
|
|
'case_data' => $case, |
|
|
} |
|
|
'herb_data' => array_column($herb,null,'id'), |
|
|
|
|
|
'user_herb_data' => array_column($user_herb,null,'id'), |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if ($is_format_data) return $this->formatUserCaseData($data); |
|
|
$herb = array_merge($herb, $user_herb); |
|
|
return $data; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return array_column($herb, null, 'id'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserCaseListCount($uid) { |
|
|
public function getUserCaseListCount($uid) { |
|
@ -264,15 +242,34 @@ class mUserCase extends mBase { |
|
|
return $this->obj->selectIn($this->user_herb_tbl, array('id' => $ids)); |
|
|
return $this->obj->selectIn($this->user_herb_tbl, array('id' => $ids)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUserCaseListPdfInfo($uid, $page_num, $page_size) { |
|
|
|
|
|
$data = $this->getUserCaseList($uid, $page_num, $page_size); |
|
|
|
|
|
|
|
|
|
|
|
$prescribe_herb_arr = array(); |
|
|
|
|
|
foreach ($data['user_case'] as &$value) { |
|
|
|
|
|
$value['prescribe_herb'] = json_decode($value['prescribe_herb'], true); |
|
|
|
|
|
$prescribe_herb_arr[] = $value['prescribe_herb']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$data['user_case_herb'] = $this->getUserCaseHerb($prescribe_herb_arr); |
|
|
|
|
|
|
|
|
|
|
|
return $this->formatUserCaseData($data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUserCasePdfInfo($uid, $id) { |
|
|
|
|
|
$data = $this->getUserCaseInfo($uid, $id); |
|
|
|
|
|
|
|
|
|
|
|
return $this->formatUserCaseData($data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function formatUserCaseData($data) { |
|
|
public function formatUserCaseData($data) { |
|
|
//兼容单个医案导出pdf |
|
|
//兼容单个医案导出pdf |
|
|
if (isset($data['data'])) { |
|
|
if (isset($data['user_case']['id'])) { |
|
|
$data['list'][0] = $data['data']; |
|
|
$data['user_case'] = array($data['user_case']); |
|
|
unset($data['data']); |
|
|
$data['case_data'] = array($data['case_data']['id'] => $data['case_data']); |
|
|
$data['case_data'] = array_column(array($data['case_data']), null, 'id'); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach ($data['list'] as &$item) { |
|
|
foreach ($data['user_case'] as &$item) { |
|
|
$item['patient_sex'] = $item['patient_sex'] == 0 ? '男' : '女'; |
|
|
$item['patient_sex'] = $item['patient_sex'] == 0 ? '男' : '女'; |
|
|
$item['case_time'] = date('Y年m月d日', strtotime($item['case_time'])); |
|
|
$item['case_time'] = date('Y年m月d日', strtotime($item['case_time'])); |
|
|
|
|
|
|
|
@ -281,12 +278,8 @@ class mUserCase extends mBase { |
|
|
|
|
|
|
|
|
$herb_arr = array(); |
|
|
$herb_arr = array(); |
|
|
foreach ($item['prescribe_herb'] as $herb) { |
|
|
foreach ($item['prescribe_herb'] as $herb) { |
|
|
if (strpos($herb['herb_id'], 'u_') !== false) { |
|
|
$herb_name = $data['user_case_herb'][$herb['herb_id']]['name']; |
|
|
$herb['herb_id'] = str_replace('u_', '', $herb['herb_id']); |
|
|
|
|
|
$herb_name = $data['user_herb_data'][$herb['herb_id']]['name']; |
|
|
|
|
|
} else { |
|
|
|
|
|
$herb_name = $data['herb_data'][$herb['herb_id']]['name']; |
|
|
|
|
|
} |
|
|
|
|
|
$herb_arr[] = $herb_name . $herb['num'] . "克"; |
|
|
$herb_arr[] = $herb_name . $herb['num'] . "克"; |
|
|
} |
|
|
} |
|
|
$herb_str = implode('、', $herb_arr); |
|
|
$herb_str = implode('、', $herb_arr); |
|
@ -297,13 +290,8 @@ class mUserCase extends mBase { |
|
|
return $data; |
|
|
return $data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function createPdf($uid, $data_key) { |
|
|
public function createPdf($uid, $pdf_html) { |
|
|
$mpdf = new mPDF(); |
|
|
$pdf_name = md5($uid); |
|
|
$htmlContent = file_get_contents(sprintf(RQ_USER_CASE_HTML_URL, $data_key)); |
|
|
|
|
|
|
|
|
|
|
|
$mpdf->WriteHTML($htmlContent); |
|
|
|
|
|
|
|
|
|
|
|
$pdf_name = md5($data_key); |
|
|
|
|
|
|
|
|
|
|
|
$temp_dir = sprintf(USER_CASE_PDF_PATH, $uid); |
|
|
$temp_dir = sprintf(USER_CASE_PDF_PATH, $uid); |
|
|
if (!is_dir($temp_dir)) { |
|
|
if (!is_dir($temp_dir)) { |
|
@ -312,6 +300,10 @@ class mUserCase extends mBase { |
|
|
chgrp($temp_dir, 'nobody'); |
|
|
chgrp($temp_dir, 'nobody'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$mpdf = new mPDF(); |
|
|
|
|
|
|
|
|
|
|
|
$mpdf->WriteHTML($pdf_html); |
|
|
|
|
|
|
|
|
$mpdf->Output($temp_dir . $pdf_name . ".pdf", 'F'); // D表示下载,I表示在浏览器中查看 |
|
|
$mpdf->Output($temp_dir . $pdf_name . ".pdf", 'F'); // D表示下载,I表示在浏览器中查看 |
|
|
|
|
|
|
|
|
return sprintf(USER_CASE_PDF_URL, $uid, $pdf_name); |
|
|
return sprintf(USER_CASE_PDF_URL, $uid, $pdf_name); |
|
|