Document.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. namespace app\controller;
  3. require_once app()->getRootPath().'vendor/autoload.php';
  4. use Neoxygen\NeoClient\ClientBuilder;
  5. use think\facade\Request;
  6. use function GuzzleHttp\Psr7\str;
  7. use app\model\Guide;
  8. use app\model\GetGuide;
  9. use think\facade\Config;
  10. class Document extends CommonTwoController
  11. {
  12. // 文献指南左侧菜单
  13. public function menu()
  14. {
  15. $lists = [
  16. ['knowledge_base_name' => '文献和指南']
  17. ];
  18. foreach ($lists as $k => $v) {
  19. $lists[0]['subordinate'] = [['name' => '文献' , 'tag' => 'document'] , ['name' => '指南' , 'tag' => 'guide'] , ['name' => '药品' , 'tag' => 'medicine']];
  20. }
  21. return $this->_json_succ($lists);
  22. }
  23. // 文献 | 指南 搜索
  24. public function index()
  25. {
  26. // 标识
  27. $tag = Request::param('tag') ?? 'Document';
  28. // 分页参数
  29. $pn = Request::param('pn') ?? 1;
  30. $pagesize = 10;
  31. $limit = ($pn - 1) * $pagesize;
  32. // 是否搜索标识 is 是 notis 不是
  33. $is_search = Request::param('is_search') ?? 'is';
  34. // 排序标识
  35. $order = Request::param('order') ?? 'desc';
  36. // 搜索值
  37. $search = Request::param('search') ?? '';
  38. if('is' == $is_search) {
  39. if(!$search) {
  40. return $this->_json_succ('请求参数有误!');
  41. }
  42. }
  43. switch ($tag)
  44. {
  45. // 文献
  46. case "Document":
  47. $search = $search ? $search : "Alport综合征";
  48. $query = "CALL db.index.fulltext.queryNodes('documentFullIndex', "."'".$search."'".") YIELD node, score where node.year is not null and node.abstract is not null RETURN node skip $limit limit $pagesize";
  49. $data = $this->getProperty($query);
  50. $data = array_column($data , 'node');
  51. $list = [];
  52. $query_count = "CALL db.index.fulltext.queryNodes('documentFullIndex', "."'".$search."'"." ) YIELD node where node.year is not null and node.abstract is not null RETURN count(node) as count";
  53. $count_ = $this->_getTotalCount($query_count);
  54. foreach ($data as $key => $value)
  55. {
  56. $list[$key]['title'] = $value['name'] ?? '';
  57. $list[$key]['abstract'] = $value['abstract'] ?? '';
  58. $list[$key]['year'] = $value['year'] ?? '';
  59. $list[$key]['author'] = $this->getAuthorByDocument($value['name']) ?? '';
  60. $list[$key]['keyword'] = $this->getKeywordByDocument($value['name']);
  61. //$list[$key]['onlineRead'] = $this->checkDocPdfIsExist('https://zskweb.jiankangche.cn/file/wenxian/file/'.$value['name'].'.pdf');
  62. if(strrpos($value['name'] , '.')) {
  63. $list[$key]['onlineRead'] = $this->checkDocPdfIsExist('https://zskweb.jiankangche.cn/file/wenxian/file/'.$value['name'].'pdf');
  64. } else {
  65. $list[$key]['onlineRead'] = $this->checkDocPdfIsExist('https://zskweb.jiankangche.cn/file/wenxian/file/'.$value['name'].'.pdf');
  66. }
  67. }
  68. // foreach ($list as $k => $v) {
  69. // if(!$list[$k]['abstract'] && !$list[$k]['year'] && !$list[$k]['author'] && !$list[$k]['keyword']) {
  70. // unset($list[$k]);
  71. // }
  72. // }
  73. //return $this->_json_succ($list);
  74. $year = array_column($list , 'year');
  75. if($order) {
  76. if('asc' == $order) {
  77. $order = SORT_ASC;
  78. } else {
  79. $order = SORT_DESC;
  80. }
  81. }
  82. array_multisort($year , $order , $list);
  83. break;
  84. // 指南
  85. case "Guide":
  86. // $search = $search ? $search : "指南";
  87. // $query = "CALL db.index.fulltext.queryNodes('guideFullIndex', "."'".$search."'".") YIELD node, score RETURN node skip $limit limit $pagesize";
  88. // $data = $this->getProperty($query);
  89. // $data = array_column($data , 'node');
  90. // $list = [];
  91. //
  92. // // 统计
  93. // $query_count = "CALL db.index.fulltext.queryNodes('guideFullIndex', "."'".$search."'"." ) YIELD node RETURN count(node) as count";
  94. // $count = $this->_getTotalCount($query_count);
  95. if('is' === $is_search) {
  96. //$data = Guide::where("documentName" , "like" , "%$search%" )->select();
  97. $data_ = GetGuide::where("documentName" , "like" , "%$search%" )->limit($limit , $pagesize)->order('publishDate',$order)->select();
  98. //$count = Guide::where("documentName" , "like" , "%$search%" )->count();
  99. $count_ = GetGuide::where("documentName" , "like" , "%$search%" )->count();
  100. } else {
  101. $data_ = GetGuide::limit($limit , $pagesize)->order('publishDate',$order)->select();
  102. //$count = GetGuide::count();
  103. $count_ = GetGuide::count();
  104. }
  105. $list = [];
  106. //foreach ($data_ as $key => $value)
  107. //{
  108. // $list[$key]['title'] = $value['title_trans'] ?? '';
  109. // $list[$key]['enTitle'] = $value['title'] ?? '';
  110. // $list[$key]['source'] = $value['source'] ?? '';
  111. // $list[$key]['constitutor'] = $value['author'] ?? '';
  112. // $list[$key]['year'] = $value['publish_time'] ?? '';
  113. // $list[$key]['abstract'] = $value['abstract'] ?? '';
  114. // $list[$key]['abstract_trans'] = $value['abstract_trans'] ?? '';
  115. // is_numeric(substr($data_[$key]['publish_time'] , -4)) ? $publish_time = substr($data_[$key]['publish_time'] , -4) : $publish_time = substr($data_[$key]['publish_time'] , 0 , 4);
  116. // $list[$key]['publish_time'] = $publish_time;
  117. // $list[$key]['full_text_url'] = $value['full_text_url'] ?? '';
  118. //$list[$key]['full_text_url'] = 'http://182.43.12.243:8981/lcznpdf/'.rtrim($value['title_trans'],'。').'.pdf';;
  119. // $list[$key]['onlineRead'] = $value['pdf'] ? 'https://jm.admin.jiankangche.cn/uploads/'.$value['pdf'] : '';
  120. //}
  121. //$publishTime = array_column($list , 'publish_time');
  122. //if($order) {
  123. // if('asc' == $order) {
  124. // $order = SORT_ASC;
  125. // } else {
  126. // $order = SORT_DESC;
  127. // }
  128. //}
  129. //array_multisort($publishTime , $order , $list);
  130. foreach ($data_ as $key => $value){
  131. $list[$key]['department'] = $value['department'] ?? '';
  132. $list[$key]['sickName'] = $value['sickName'] ?? '';
  133. $list[$key]['documentName'] = $value['documentName'] ?? '';
  134. $list[$key]['year'] = $value['year'] ?? '';
  135. $list[$key]['publishDate'] = $value['publishDate'] ?? '';
  136. $list[$key]['enTitle'] = $value['enTitle'] ?? '';
  137. $list[$key]['constitutor'] = $value['constitutor'] ?? '';
  138. $list[$key]['source'] = $value['source'] ?? '';
  139. $list[$key]['abstract'] = $value['abstract'] ?? '';
  140. $list[$key]['abstract_trans'] = $value['abstract_trans'] ?? '';
  141. $list[$key]['url'] = $this->checkDocPdfIsExist('http://106.225.184.197:8981/lcznpdf/'.$value['documentName'].'.pdf');
  142. //$list[$key]['url'] = 'http://106.225.184.197:8981/lcznpdf/'.$value['documentName'].'.pdf';
  143. }
  144. break;
  145. }
  146. return $this->_json_succ(['count' => $count_ , 'list' => $list]);
  147. }
  148. private function checkDocPdfIsExist($url)
  149. {
  150. $check = get_headers($url);
  151. if(strstr($check[0] , '200')) {
  152. return $url;
  153. }
  154. return "";
  155. }
  156. // 文献详情
  157. public function detail()
  158. {
  159. $tag = Request::param('tag') ?? 'Document';
  160. $title = Request::param('title') ?? '';
  161. $query = "match(n:Document) where n.name = "."'".$title."'"." return n";
  162. $data = $this->getProperty($query);
  163. $data = array_column($data , 'n');
  164. // 获取 文献的作者 参考文献 引证文献
  165. $query1 = "match p=(n:Document {name:"."'".$title."'"."}) -[r:LinkAuthor|LinkReference|LinkCitationDocument]-(m) return m.name as mname, m.kgid as kgid, r.name as rname";
  166. $data1 = $this->getProperty($query1);
  167. foreach ($data1 as $key => $value)
  168. {
  169. if(($value['rname'] == "作者")) {
  170. $authors[] = ['name' => $value['mname'] , 'kgid' => $value['kgid']];
  171. }
  172. if(($value['rname'] == "参考文献")) {
  173. $rer[] = $value['mname'];
  174. $wx = ['titles' => $rer];
  175. }
  176. }
  177. $list = [
  178. 'title' => $data[0]['name'] ?? '',
  179. 'abstract' => $data[0]['abstract'] ?? '',
  180. 'author' => $authors ?? [],
  181. 'keyword' => '',
  182. 'publishMagazine' => $data[0]['publishMagazine'] ?? '',
  183. 'similarDocument' => $wx ?? [], // 参考文献
  184. 'citationDocument' => [], // 引证文献
  185. ];
  186. return $this->_json_succ($list);
  187. }
  188. // 作者详情
  189. public function authorDetail()
  190. {
  191. $kgid = Request::param('kgid');
  192. $query = "match(n:Thing) where n.kgid = "."'".$kgid."'"."return n.name as name , n.focusField as focusField , n.organization as organization limit 1";
  193. $data = $this->getProperty($query);
  194. $list = [
  195. 'name' => $data[0]['name'],
  196. 'focusField' => explode('||' ,$data[0]['focusField']),
  197. 'organization' => $data[0]['organization'],
  198. 'authorDocument' => $this->getDocumentByAuthor($kgid),
  199. ];
  200. return $this->_json_succ($list);
  201. }
  202. // 热点研究方向
  203. public function getHotList()
  204. {
  205. $title = Request::param('title') ?? '诊断';
  206. $query = "CALL db.index.fulltext.queryNodes('documentFullIndex', "."'".$title."'".") YIELD node match p=(node)-[r:LinkKeyword]-(k:Keyword) with node.year as year, k.name as keyword,
  207. count(*) as cnt order by year desc, cnt desc return year, apoc.agg.slice(keyword, 0, 5) AS hots, apoc.agg.slice(cnt, 0, 5) as count limit 5";
  208. $data = $this->getProperty($query);
  209. foreach ($data as $key => $value) {
  210. for ($i=0;$i<5;$i++) {
  211. $data[$key]['hots'] = [
  212. [
  213. 'name' => $value['hots'][0] ,
  214. 'count' => $value['count'][0]
  215. ],
  216. [
  217. 'name' => $value['hots'][1] ,
  218. 'count' => $value['count'][1]
  219. ],
  220. [
  221. 'name' => $value['hots'][2] ,
  222. 'count' => $value['count'][2]
  223. ],
  224. [
  225. 'name' => $value['hots'][3] ,
  226. 'count' => $value['count'][3]
  227. ],
  228. [
  229. 'name' => $value['hots'][4] ,
  230. 'count' => $value['count'][4]
  231. ]
  232. ];
  233. }
  234. unset($data[0]);
  235. unset($data[$key]['count']);
  236. }
  237. rsort($data);
  238. return $this->_json_succ($data);
  239. }
  240. // 作者图谱
  241. public function authorGraph()
  242. {
  243. $hot = Request::param('hot_name') ?? "心力衰竭";
  244. $id = $this->_getId($hot);
  245. $query = "match (a0:Author)<-[r:LinkAuthor]-(:Document)-[:LinkKeyword]->(k:Keyword {name:"."'".$hot."'"."}) with a0, k, count(r.name) as cnt order by cnt desc with k, apoc.agg.slice(a0, 0,10) as authors unwind authors as author with k, author call apoc.create.vRelationship(k,'LinkToKeyword',{}, author) yield rel return k, author, rel";
  246. $data = $this->getProperty($query);
  247. $lists = [];
  248. foreach ($data as $key => $value)
  249. {
  250. $lists[$key]['start']['identity'] = $id;
  251. $lists[$key]['start']['labels'] = ['Document' , 'Thing'];
  252. $lists[$key]['start']['properties']['name'] = ['name' => '热点名称' , 'text' => $value['k']['name']];
  253. $lists[$key]['end']['identity'] = $this->_getId($value['author']['kgid'] , 'endid');
  254. $lists[$key]['end']['labels'] = ['Thing' , 'Author'];
  255. $lists[$key]['end']['properties']['name'] = ['name' => '作者' , 'text' => $value['author']['name']];
  256. $lists[$key]['end']['properties']['organization'] = ['name' => '所属单位' , 'text' => $value['author']['organization']];
  257. $lists[$key]['relationship']['start'] = $id;
  258. $lists[$key]['relationship']['end'] = $this->_getId($value['author']['kgid'] , 'endid');
  259. $lists[$key]['relationship']['type'] = 'LINKAUTHOR';
  260. $lists[$key]['relationship']['properties']['@type'] = [
  261. "LinkAuthor",
  262. "CnsLink"
  263. ];
  264. $lists[$key]['relationship']['properties']['name'] = '作者';
  265. }
  266. return $this->_json_succ($lists);
  267. }
  268. // 获取热点对应作者的kgid
  269. public function getHotAuthorKgids($hot = '')
  270. {
  271. $query1 = "match(n:Author) where n.focusField ="."'".$hot."'"." return n.name as name, n.kgid as kgid limit 10";
  272. $data1 = $this->getProperty($query1);
  273. //dump($data1);die;
  274. return array_column($data1 , 'kgid');
  275. }
  276. // 获取作者的文献
  277. private function getDocumentByAuthor($kgid)
  278. {
  279. $query = "match(n:Document)-[r:LinkAuthor]-(m:Author) where m.kgid="."'".$kgid."'"." return n.name as name";
  280. $data = $this->getProperty($query) ?? [];
  281. return $data ? array_column($data, 'name') : [];
  282. }
  283. // 获取文献的作者
  284. private function getAuthorByDocument($title)
  285. {
  286. if(strstr($title , "'")) {
  287. $title = trim(str_replace("'","",$title));
  288. $query = "match(n:Document)-[r:LinkAuthor]-(m:Thing) where n.name= "."'".$title."'"." return m.name as name , m.kgid as kgid";
  289. } elseif (strstr($title , '"')) {
  290. $title = trim(str_replace('"',"",$title));
  291. $query = 'match(n:Document)-[r:LinkAuthor]-(m:Thing) where n.name= '.'"'.$title.'"'.' return m.name as name , m.kgid as kgid';
  292. } else {
  293. $query = "match(n:Document)-[r:LinkAuthor]-(m:Thing) where n.name= "."'".$title."'"." return m.name as name , m.kgid as kgid";
  294. }
  295. $data = $this->getProperty($query) ?? [];
  296. return $data ?? [];
  297. }
  298. // 获取文献的关键词
  299. private function getKeywordByDocument($title)
  300. {
  301. if(strstr($title , "'")) {
  302. $title = trim(str_replace("'","",$title));
  303. $query = "match(n:Document)-[r:LinkKeyword]-(m:Keyword) where n.name= "."'".$title."'"." return m.name as name";
  304. } elseif (strstr($title , '"')) {
  305. $title = trim(str_replace('"',"",$title));
  306. $query = 'match(n:Document)-[r:LinkKeyword]-(m:Keyword) where n.name= '."'".$title."'".'return m.name as name';
  307. } else {
  308. $query = "match(n:Document)-[r:LinkKeyword]-(m:Keyword) where n.name= "."'".$title."'"." return m.name as name";
  309. }
  310. $data = $this->getProperty($query) ?? [];
  311. return $data ? array_column($data , 'name') : [];
  312. }
  313. }