韩盟盟 1 kuukausi sitten
vanhempi
commit
7ebec1f11e

+ 15 - 3
neo4jApi/app/controller/Cdss.php

@@ -104,6 +104,19 @@ class Cdss extends CommonTwoController
                         $query = $query->where('clinicalFeature', 'like', '%' . $symptom . '%');
                     }
                     $aboutDiseases = $query->limit(200)->select()->toArray();
+
+                    if(empty($aboutDiseases)){
+                        $query = CdssXyDisease::where('1=1');
+                        // 使用AND连接多个症状条件
+                        foreach ($symptoms as $key => $symptom) {
+                            if($key == 0){
+                                $query->where('clinicalFeature', 'like', '%' . $symptom . '%');
+                            }else {
+                                $query = $query->whereOr('clinicalFeature', 'like', '%' . $symptom . '%');
+                            }
+                        }
+                        $aboutDiseases = $query->limit(200)->select()->toArray();
+                    }
                 } else {
                     $aboutDiseases = CdssXyDisease::whereLike('clinicalFeature', '%' . $values . '%')
                         ->limit(200)
@@ -1681,11 +1694,10 @@ class Cdss extends CommonTwoController
      * @param  $name  string  名称
      * @return
      */
-    public function detail()
+    public function detail($params = [])
     {
 
-        $params = $this->request->all();
-
+        $params = $params ?:$this->request->all();
 
         $tag = $params['tag'] ?? 'Disease';
         $value = $params['name'] ?? '';

+ 151 - 20
neo4jApi/app/controller/PatientAuxiliary.php

@@ -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());
+        }
+    }
 } 

+ 3 - 0
neo4jApi/route/app.php

@@ -19,6 +19,9 @@ Route::rule('jmjk/forget-password', 'login/forgetPassword');
 Route::rule('jmjk/zsk/index', 'NeojApi/index');
 Route::rule('v/test', 'Index/index');
 
+/**接口**/
+Route::post('OutPatientRecord', 'XyCdssInterface/OutPatientRecord');
+
 
 Route::group(function () {