|
@@ -3,8 +3,10 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace app\controller;
|
|
|
|
|
|
+use app\model\SymptomDictionary;
|
|
|
use think\App;
|
|
|
use think\facade\Request;
|
|
|
+use think\helper\Arr;
|
|
|
use think\response\Json;
|
|
|
use app\model\PatientAuxiliaryDiagnosis;
|
|
|
use app\controller\Cdss;
|
|
@@ -83,24 +85,8 @@ class PatientAuxiliary extends CommonTwoController
|
|
|
if (!empty($params['ZSZZ']) && !empty($params['XB']) && !empty($params['NL'])) {
|
|
|
try {
|
|
|
// 从主诉症状中提取关键词
|
|
|
- $mainSymptoms = '';
|
|
|
- $symptomKeywords = Db::table('jm_cdss_symptom_keywords')
|
|
|
- ->column('keyword');
|
|
|
-
|
|
|
- foreach ($symptomKeywords as $keyword) {
|
|
|
- // 确保keyword是字符串类型
|
|
|
- $keyword = (string)$keyword;
|
|
|
- // 确保ZSZZ是字符串类型
|
|
|
- $zszz = (string)$params['ZSZZ'];
|
|
|
-
|
|
|
- if (stripos($zszz, $keyword) !== false) {
|
|
|
- if ($mainSymptoms === '') {
|
|
|
- $mainSymptoms = $keyword;
|
|
|
- } else {
|
|
|
- $mainSymptoms .= ',' . $keyword;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $dictionary = SymptomDictionary::field('symptom')->whereRaw("'".$params['ZSZZ']."'".' LIKE CONCAT("%", symptom, "%")')->select()->toArray();
|
|
|
+ $mainSymptoms = $dictionary ? implode(',',array_column($dictionary,'symptom')) : '';
|
|
|
|
|
|
// 如果提取到了症状关键词,才调用辅助诊疗
|
|
|
if (!empty($mainSymptoms)) {
|
|
@@ -186,8 +172,6 @@ class PatientAuxiliary extends CommonTwoController
|
|
|
|
|
|
$hasKnowledgeResult = !empty($knowledgeResult) && count($knowledgeResult) > 0;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
// 返回结果 - 任何一个匹配就设置req=1
|
|
|
return $this->_json_succ(
|
|
@@ -208,6 +192,7 @@ class PatientAuxiliary extends CommonTwoController
|
|
|
{
|
|
|
// 获取住院号
|
|
|
$zyh = $this->request->param('zyh');
|
|
|
+ \think\facade\Log::info(__FUNCTION__.': zyh='.$zyh);
|
|
|
if (!$zyh) {
|
|
|
return $this->_json_error('住院号不能为空');
|
|
|
}
|
|
@@ -239,4 +224,150 @@ class PatientAuxiliary extends CommonTwoController
|
|
|
return $this->_json_error('获取失败: ' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存患者辅助诊疗信息
|
|
|
+ * @return Json
|
|
|
+ */
|
|
|
+ public function savePatientAuxiliaryInfoInterfece($params): Json
|
|
|
+ {
|
|
|
+ // 设置默认值
|
|
|
+ $params = array_merge([
|
|
|
+ 'ZYH' => '',
|
|
|
+ 'ZSZZ' => '',
|
|
|
+ 'name' => '',
|
|
|
+ 'tag' => '',
|
|
|
+ 'XB' => '',
|
|
|
+ 'NL' => 0,
|
|
|
+ 'document' => '',
|
|
|
+ 'docter' => '',
|
|
|
+ 'YGDM' => '',
|
|
|
+ 'KSDM' => ''
|
|
|
+ ], $params);
|
|
|
+
|
|
|
+ // 参数验证
|
|
|
+ $validate = validate([
|
|
|
+ 'ZYH' => 'require|number', // 只验证住院号必填
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!$validate->check($params)) {
|
|
|
+ return $this->_json_error($validate->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 准备基础数据
|
|
|
+ $baseData = [
|
|
|
+ 'name' => $params['name'],
|
|
|
+ 'tag' => $params['tag'],
|
|
|
+ 'zszz' => $params['ZSZZ'],
|
|
|
+ 'xb' => $params['XB'],
|
|
|
+ 'nl' => intval($params['NL']),
|
|
|
+ 'document' => $params['document'],
|
|
|
+ 'docter' => $params['docter'],
|
|
|
+ 'ygdm' => $params['YGDM'],
|
|
|
+ 'ksdm' => $params['KSDM']
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 辅助诊疗 - 只要有zszz和性别年龄就调用
|
|
|
+ if (!empty($params['ZSZZ']) && !empty($params['XB']) && !empty($params['NL'])) {
|
|
|
+ try {
|
|
|
+ // 从主诉症状中提取关键词
|
|
|
+ $dictionary = SymptomDictionary::field('symptom')->whereRaw("'".$params['ZSZZ']."'".' LIKE CONCAT("%", symptom, "%")')->select()->toArray();
|
|
|
+ $mainSymptoms = $dictionary ? implode(',',array_column($dictionary,'symptom')) : '';
|
|
|
+ // 如果提取到了症状关键词,才调用辅助诊疗
|
|
|
+ if (!empty($mainSymptoms)) {
|
|
|
+ $auxiliaryResult = $this->cdss->getSymptomAboutDisease(
|
|
|
+ $mainSymptoms, // 使用提取的症状关键词
|
|
|
+ $params['NL'],
|
|
|
+ stripos($params['XB'], '男') !== false ? 1 : 2
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!empty($auxiliaryResult)) {
|
|
|
+ $data = array_merge($baseData, [
|
|
|
+ 'content' => json_encode($auxiliaryResult, JSON_UNESCAPED_UNICODE)
|
|
|
+ ]);
|
|
|
+ $res = PatientAuxiliaryDiagnosis::updateOrInsert(
|
|
|
+ (string)$params['ZYH'],
|
|
|
+ PatientAuxiliaryDiagnosis::TAG_AUXILIARY,
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ var_dump($res);die;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->_json_error('辅助诊疗调用失败: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 知识库 - 需要name和tag
|
|
|
+ if ($params['name'] && $params['tag']) {
|
|
|
+ try {
|
|
|
+ // 调用detail方法
|
|
|
+ $response = $this->cdss->detail([
|
|
|
+ 'name' => $params['name'],
|
|
|
+ 'tag' => $params['tag']
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 从Json响应中获取数据
|
|
|
+ $knowledgeResult = $response->getData();
|
|
|
+
|
|
|
+ if (!empty($knowledgeResult)) {
|
|
|
+ $data = array_merge($baseData, [
|
|
|
+ 'content' => json_encode($knowledgeResult, JSON_UNESCAPED_UNICODE)
|
|
|
+ ]);
|
|
|
+ PatientAuxiliaryDiagnosis::updateOrInsert(
|
|
|
+ (string)$params['ZYH'],
|
|
|
+ PatientAuxiliaryDiagnosis::TAG_KNOWLEDGE,
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->_json_error('知识库调用失败: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 医嘱审核 - 需要name和性别
|
|
|
+ $hasReviewResult = false;
|
|
|
+ if ($params['name'] && $params['XB']) {
|
|
|
+ $gender = stripos($params['XB'], '男') !== false ? 1 : 2;
|
|
|
+ try {
|
|
|
+ $reviewResult = $this->cdss->yzEamine([
|
|
|
+ 'name' => $params['name'],
|
|
|
+ 'gender' => $gender
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!empty($reviewResult)) {
|
|
|
+ $data = array_merge($baseData, [
|
|
|
+ 'content' => json_encode($reviewResult, JSON_UNESCAPED_UNICODE)
|
|
|
+ ]);
|
|
|
+ PatientAuxiliaryDiagnosis::updateOrInsert(
|
|
|
+ (string)$params['ZYH'],
|
|
|
+ PatientAuxiliaryDiagnosis::TAG_REVIEW,
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ $hasReviewResult = true;
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->_json_error('医嘱审核调用失败: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查辅助诊疗结果
|
|
|
+ $hasAuxiliaryResult = !empty($auxiliaryResult) && count($auxiliaryResult) > 0;
|
|
|
+
|
|
|
+ // 检查知识库结果 - detail()返回的是Json对象
|
|
|
+
|
|
|
+ $hasKnowledgeResult = !empty($knowledgeResult) && count($knowledgeResult) > 0;
|
|
|
+
|
|
|
+
|
|
|
+ // 返回结果 - 任何一个匹配就设置req=1
|
|
|
+ return $this->_json_succ(
|
|
|
+ ['req' => ($hasAuxiliaryResult || $hasKnowledgeResult || $hasReviewResult) ? 1 : 0],
|
|
|
+ 0,
|
|
|
+ '保存成功'
|
|
|
+ );
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->_json_error('保存失败: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|