Xyzsk.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Model;
  3. use App\Observers\XyzskObserver;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Pagination\LengthAwarePaginator;
  6. use Illuminate\Support\Facades\Request;
  7. class Xyzsk extends Model
  8. {
  9. private $host = "https://jm.jiankangche.cn/";
  10. public $labels = ['Medicine' => '药品' , 'Disease' => '疾病' , 'Inspection' => '检查' , 'Symptom' => '症状'];
  11. public function paginate()
  12. {
  13. $page = Request::get('page' , 1);
  14. $perPage = Request::get('per_page', 10);
  15. $label = Request::get('label' , 'SickNess');
  16. $name = Request::get('name' , '');
  17. $tag = 'Guide' === $label ? 'guide' : 'xy';
  18. $start = ($page-1) * $perPage;
  19. $data = file_get_contents($this->host."neo4j/index?start=$start&perPage=$perPage&label=$label&tag=$tag&name=$name");
  20. $data = json_decode($data , true);
  21. $movies = static::hydrate($data['list']);
  22. $total = $data['count'];
  23. $paginator = new LengthAwarePaginator($movies, $total, $perPage);
  24. $paginator->setPath(url()->current());
  25. return $paginator;
  26. }
  27. public static function with($relations)
  28. {
  29. return new static;
  30. }
  31. // 覆盖`orderBy`来收集排序的字段和方向
  32. public function orderBy($column, $direction = 'asc')
  33. {
  34. }
  35. // 覆盖`where`来收集筛选的字段和条件
  36. public function where($column, $operator = null, $value = null, $boolean = 'and')
  37. {
  38. }
  39. // 获取单项数据展示在form中
  40. public function findOrFail($id)
  41. {
  42. $data = file_get_contents($this->host."neo4j/detail?id=$id&zsk=guide");
  43. $data = json_decode($data, true);
  44. foreach ($data as $key => $value) {
  45. if(stripos($value , '&lt') !== false) {
  46. $data[$key] = html_entity_decode($value);
  47. }
  48. }
  49. return static::newFromBuilder($data);
  50. }
  51. // 获取label
  52. public function getLabel($id = '')
  53. {
  54. $data = file_get_contents($this->host."neo4j/getlabels?id=$id&zsk=guide");
  55. $labels = json_decode($data, true);
  56. if(in_array('Document' , $labels)) {
  57. return 'Document';
  58. }
  59. if(in_array('Guide' , $labels)) {
  60. return 'Guide';
  61. }
  62. return isset($labels[1]) ? $labels[1] : $labels[0];
  63. }
  64. // 保存提交的form数据
  65. public function save(array $options = [])
  66. {
  67. $attributes = $options;
  68. $id = $options['id'];
  69. if($id) {
  70. $label = $this->getlabel($id);
  71. switch ($label) {
  72. case 'SickNess';
  73. $query = "match (n: SickNess) where id(n) = $id set n.name='".$attributes['name']."' ,n.alias='".$attributes['alias']."' ,n.ICD10='".$attributes['ICD10']."' , n.department='".$attributes['department']."' ,n.introduction='".$attributes['introduction']."' ,n.epidemiology='".$attributes['epidemiology']."' ,n.suitableFood='".$attributes['suitableFood']."' ,n.notEat='".$attributes['notEat']."' , n.diagnostiCtriage='".$attributes['diagnostiCtriage']."' , n.precaution='".$attributes['precaution']."' ,n.warmPrompt='".$attributes['warmPrompt']."' ,n.nursingInfo='".$attributes['nursingInfo']."' ,n.recommendedRecipe='".$attributes['recommendedRecipe']."' ,n.treatmentOverview='".$attributes['treatmentOverview']."' ,n.pathogenesis='".$attributes['pathogenesis']."' ,n.basicKnowledgel='".$attributes['basicKnowledgel']."' ,n.dietHealth='".$attributes['dietHealth']."' ,n.symptom='".$attributes['symptom']."' ,n.complicationsOverview='".$attributes['complicationsOverview']."' ,n.treatmentInfo='".$attributes['treatmentInfo']."'RETURN n";
  74. break;
  75. case 'Disease';
  76. $query = "match (n: Disease) where id(n) = $id set n.name='".$attributes['name']."' ,n.nameEn='".$attributes['nameEn']."' ,n.alias='".$attributes['alias']."' , n.icd='".$attributes['icd']."' ,n.department='".$attributes['department']."' ,n.epidemiology='".$attributes['epidemiology']."' ,n.sickOverview='".$attributes['sickOverview']."' ,n.clinicalFeature='".$attributes['clinicalFeature']."' , n.diagnosis='".$attributes['diagnosis']."' , n.treatment='".$attributes['treatment']."' ,n.pathogenesis='".$attributes['pathogenesis']."' ,n.inspection='".$attributes['inspection']."' ,n.laboratoryInspection='".$attributes['laboratoryInspection']."' ,n.etiology='".$attributes['etiology']."' ,n.pathogenesis='".$attributes['pathogenesis']."' ,n.auxiliaryExamination='".$attributes['auxiliaryExamination']."' ,n.prognosis='".$attributes['prognosis']."' ,n.complicationsOverview='".$attributes['complicationsOverview']."' ,n.precaution='".$attributes['precaution']."'RETURN n";
  77. break;
  78. case 'Medicine';
  79. $query = "match (n: Medicine) where id(n) = $id set n.name='".$attributes['name']."' ,n.pinyi='".$attributes['pinyi']."' ,n.oldUse='".$attributes['oldUse']."' , n.chilldUse='".$attributes['chilldUse']."' ,n.medicinePregnant='".$attributes['medicinePregnant']."' ,n.usageDosage='".$attributes['usageDosage']."' ,n.notes='".$attributes['notes']."' ,n.periodValidity='".$attributes['periodValidity']."' , n.indication='".$attributes['indication']."' , n.storage='".$attributes['storage']."' ,n.character='".$attributes['character']."' ,n.contraindication='".$attributes['contraindication']."' ,n.pharmacologyToxicology='".$attributes['pharmacologyToxicology']."' ,n.specification='".$attributes['specification']."' ,n.approvalNumber='".$attributes['approvalNumber']."' ,n.productionEnterprise='".$attributes['productionEnterprise']."' ,n.relateSick='".$attributes['relateSick']."' ,n.untowardEffect='".$attributes['untowardEffect']."' ,n.majorConstituent='".$attributes['majorConstituent']."'RETURN n";
  80. break;
  81. case 'Inspection';
  82. $query = "match (n: Inspection) where id(n) = $id set n.name='".$attributes['name']."' ,n.annotation='".$attributes['annotation']."' , n.principle='".$attributes['principle']."' ,n.normalValue='".$attributes['normalValue']."' ,n.clinicalSignificance='".$attributes['clinicalSignificance']."' ,n.reagent='".$attributes['reagent']."' ,n.operation='".$attributes['operation']."'RETURN n";
  83. break;
  84. case 'Symptom';
  85. $query = "match (n: Symptom) where id(n) = $id set n.name='".$attributes['name']."' ,n.identify='".$attributes['identify']."' ,n.abstract='".$attributes['abstract']."' , n.precaution='".$attributes['precaution']."' ,n.inspection='".$attributes['inspection']."' ,n.etiology='".$attributes['etiology']."'RETURN n";
  86. break;
  87. case 'Guide':
  88. $query = 'match (n: Guide) where id(n) = $id set n.abstract="'.$attributes['abstract'].'" ,n.source="'.$attributes['source'].'" , n.constitutor="'.$attributes['constitutor'].'" ,n.year="'.$attributes['year'].'" ,n.name="'.$attributes['name'].'"RETURN n';
  89. break;
  90. }
  91. $ch = curl_init();
  92. curl_setopt($ch, CURLOPT_URL, $this->host."neo4j/setNode");
  93. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  94. curl_setopt($ch, CURLOPT_POST, 1);
  95. curl_setopt($ch, CURLOPT_POSTFIELDS, ['tag' => 'guide' , 'query' => $query]);
  96. $result = curl_exec($ch);
  97. curl_close($ch);
  98. if("{}" == $result) {
  99. return 'success';
  100. } else {
  101. return 'failure';
  102. }
  103. }
  104. }
  105. }