123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace App\Model;
- use App\Observers\XyzskObserver;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Pagination\LengthAwarePaginator;
- use Illuminate\Support\Facades\Request;
- class Xyzsk extends Model
- {
- private $host = "https://jm.jiankangche.cn/";
- public $labels = ['Medicine' => '药品' , 'Disease' => '疾病' , 'Inspection' => '检查' , 'Symptom' => '症状'];
- public function paginate()
- {
- $page = Request::get('page' , 1);
- $perPage = Request::get('per_page', 10);
- $label = Request::get('label' , 'SickNess');
- $name = Request::get('name' , '');
- $tag = 'Guide' === $label ? 'guide' : 'xy';
- $start = ($page-1) * $perPage;
- $data = file_get_contents($this->host."neo4j/index?start=$start&perPage=$perPage&label=$label&tag=$tag&name=$name");
- $data = json_decode($data , true);
- $movies = static::hydrate($data['list']);
- $total = $data['count'];
- $paginator = new LengthAwarePaginator($movies, $total, $perPage);
- $paginator->setPath(url()->current());
- return $paginator;
- }
- public static function with($relations)
- {
- return new static;
- }
- // 覆盖`orderBy`来收集排序的字段和方向
- public function orderBy($column, $direction = 'asc')
- {
- }
- // 覆盖`where`来收集筛选的字段和条件
- public function where($column, $operator = null, $value = null, $boolean = 'and')
- {
- }
- // 获取单项数据展示在form中
- public function findOrFail($id)
- {
- $data = file_get_contents($this->host."neo4j/detail?id=$id&zsk=guide");
- $data = json_decode($data, true);
- foreach ($data as $key => $value) {
- if(stripos($value , '<') !== false) {
- $data[$key] = html_entity_decode($value);
- }
- }
- return static::newFromBuilder($data);
- }
- // 获取label
- public function getLabel($id = '')
- {
- $data = file_get_contents($this->host."neo4j/getlabels?id=$id&zsk=guide");
- $labels = json_decode($data, true);
- if(in_array('Document' , $labels)) {
- return 'Document';
- }
- if(in_array('Guide' , $labels)) {
- return 'Guide';
- }
- return isset($labels[1]) ? $labels[1] : $labels[0];
- }
- // 保存提交的form数据
- public function save(array $options = [])
- {
- $attributes = $options;
- $id = $options['id'];
- if($id) {
- $label = $this->getlabel($id);
- switch ($label) {
- case 'SickNess';
- $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";
- break;
- case 'Disease';
- $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";
- break;
- case 'Medicine';
- $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";
- break;
- case 'Inspection';
- $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";
- break;
- case 'Symptom';
- $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";
- break;
- case 'Guide':
- $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';
- break;
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->host."neo4j/setNode");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, ['tag' => 'guide' , 'query' => $query]);
- $result = curl_exec($ch);
- curl_close($ch);
- if("{}" == $result) {
- return 'success';
- } else {
- return 'failure';
- }
- }
- }
- }
|