package org.diagbot.repository;

import org.diagbot.entity.node.Disease;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;
import java.util.Map;

public interface DiseaseRepository extends Neo4jRepository<Disease, Long> {
    List<Disease> findByNameContaining(String token);

    // find High Risk Disease
    @Query("MATCH (d:Disease) WHERE d.name in {0} RETURN d.name as name, d.high_risk as risk")
    List<Map<String, Object>> findHighRiskDisease(List<String> diseaselist);

    //get high risk
    @Query("match(d:Disease) where d.name in {0} return d.name as name, d.high_risk as risk")
    List<Map<String, Object>> getHighRisk(List diagList);


    //删除诊断依据
    //删除关系1
    @Query("match(d:Disease)<-[r:拟诊|:确诊|:警惕]-(c:Condition)<-[r1]-(k:Condition)<-[r2]-(h:Condition) where d.disId={0} detach delete c,k,h")
    void deleteRelation1(Long disId);
    //删除关系2
    @Query("match(d:Disease)<-[r:拟诊|:确诊|:警惕]-(c:Condition)<-[r1]-(k:Condition) where d.disId={0} detach delete c,k")
    void deleteRelation2(Long disId);
    //删除关系3
    @Query("match(d:Disease)<-[r:拟诊|:确诊|:警惕]-(c:Condition) where d.disId={0} detach delete r")
    void deleteRelation3(Long disId);
    //删除排除关系4
    @Query("match(d:Disease)<-[r:排除]-(l) where d.disId={0} detach delete l")
    void deleteRelation4(Long disId);
    //删除排除关系5
    @Query("match(d:Disease)-[r:表现]->(j)-[r1:属于]->(k) where d.disId={0} detach delete r")
    void deleteRelation5(Long disId);
    //删除排除关系6
    @Query("match(d:Disease)-[r:表现]->(j) where d.disId={0} detach delete r")
    void deleteRelation6(Long disId);
    //删除排除关系7
    @Query("match(d:Disease)-[r:推荐]->(j:LIS) where d.disId={0} detach delete r")
    void deleteRelation7(Long disId);
    //删除排除关系8
    @Query("match(d:Disease)-[r:推荐]->(j:PACS) where d.disId={0} detach delete r")
    void deleteRelation8(Long disId);
    //删除排除关系9
    @Query("match(d:Disease)-[r:鉴别诊断]->(b) where d.disId={0} detach delete r")
    void deleteRelation9(Long disId);
    //删除排除关系10
    @Query("match(c:Condition) where c.name={0} detach delete c")
    void deleteRelation10(String conditionName);
    //删除诊断
    @Query("match(c:Disease) where c.disId={0} detach delete c")
    void deleteRelation11(Long disId);
    //更新图谱
    //存储疾病
    @Query("merge(d:Disease{name:{0},disId:{1},emergency:{2}})")
    void mergeDis(String name,Long disId,Integer emergency);
    //存储确诊，拟诊，警惕
    @Query( "merge(c:Condition{name:{0},path:{1}})")
    void mergeCondition(String disName,Integer path);
    @Query("match(c:Condition{name:{0}}),(d:Disease{disId:{1}})" +
            " merge(c)-[:确诊]->(d)")
    void mergeQueNiHigh(String conditionName,Long disId);
    @Query("match(c:Condition{name:{0}}),(d:Disease{disId:{1}})" +
            " merge(c)-[:拟诊]->(d)")
    void mergeNiHigh(String conditionName,Long disId);
    @Query("match(c:Condition{name:{0}}),(d:Disease{disId:{1}})" +
            " merge(c)-[:警惕]->(d)")
    void mergeHigh(String conditionName,Long disId);
    //任几的condition
    @Query("merge(c:Condition{name:{0},path:{1},relation:{2}})")
    void mergeRenCondition(String conditionName,Integer path,String relation);
    @Query("match(c:Condition{name:{0}}),(s:Condition{name:{1}}) merge(c)-[r:诊断依据]->(s)")
    void mergeRenCondition(String c1,String c2);
    //具体code Condition
    @Query("merge(c:Condition{name:{0},path:1,relation:'任一'})")
    void mergeNUMCondition(String disName);
    @Query("match(c:Condition{name:{0}}),(s:Condition{name:{1}}) merge(c)-[r:诊断依据]->(s)")
    void mergeNUMCondition(String c1,String c2);
    //开始添加所有的词语
    //添加症状标准词
    @Query("merge(d:Symptom{name:{0}})")
    void mergeStandardSymptom(String name);
    //疾病表现症状标准词
    @Query("match(d:Disease{disId:{0}}),(s:Symptom{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandard(Long disId,String name);
    //属于症状标准词
    @Query("match(d:Condition{name:{0}}),(s:Symptom{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardshuyu(String conditionName,String name);
    //添加体征标准词
    @Query("merge(d:Vital{name:{0}})")
    void mergeStandardVital(String name);
    //疾病表现体征标准词
    @Query("match(d:Disease{disId:{0}}),(s:Vital{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandardVital(Long disId,String name);
    //属于体征标准词
    @Query("match(d:Condition{name:{0}}),(s:Vital{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardVitalshuyu(String conditionName,String name);
    //添加病史标准词
    @Query("merge(d:History{name:{0}})")
    void mergeStandardHistory(String name);
    //疾病表现病史标准词
    @Query("match(d:Disease{disId:{0}}),(s:History{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandardHistory(Long disId,String name);
    //属于病史标准词
    @Query("match(d:Condition{name:{0}}),(s:History{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardHistoryshuyu(String conditionName,String name);
    //添加诱因标准词
    @Query("merge(d:Cause{name:{0}})")
    void mergeStandardCause(String name);
    //疾病表现诱因标准词
    @Query("match(d:Disease{disId:{0}}),(s:Cause{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandardCause(Long disId,String name);
    //属于诱因标准词
    @Query("match(d:Condition{name:{0}}),(s:Cause{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardCauseshuyu(String conditionName,String name);
    //添加病程标准词
    @Query("merge(d:Prognosis{name:{0}})")
    void mergeStandardPrognosis(String name);
    //疾病表现病程标准词
    @Query("match(d:Disease{disId:{0}}),(s:Prognosis{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandardPrognosis(Long disId,String name);
    //属于病程标准词
    @Query("match(d:Condition{name:{0}}),(s:Prognosis{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardPrognosisshuyu(String conditionName,String name);
    //添加其他标准词
    @Query("merge(d:Other{name:{0}})")
    void mergeStandardOther(String name);
    //疾病表现其他标准词
    @Query("match(d:Disease{disId:{0}}),(s:Other{name:{1}}) merge(d)-[r:表现]->(s)")
    void mergeRelationStandardOther(Long disId,String name);
    //属于其他标准词
    @Query("match(d:Condition{name:{0}}),(s:Other{name:{1}}) merge(d)<-[r:属于]-(s)")
    void mergeRelationStandardOthershuyu(String conditionName,String name);
    //添加鉴别诊断
    @Query("merge(d:DifferentDis{name:{0}})")
    void mergeDifferentDis(String disName);
    //疾病和鉴别诊断创建关系
    @Query("match(d:Disease{disId:{0}}),(s:DifferentDis{name:{1}}) merge(d)-[r:鉴别诊断]->(s)")
    void mergeRelationDifferentDis(Long disId,String name);
    //创建化验大项
    @Query("merge(l:LIS{name:{0}})")
    void mergePublicLIS(String lisName);
    //疾病和化验大项创建关系
    @Query("match(d:Disease{disId:{0}}),(s:LIS{name:{1}}) merge(d)-[r:推荐]->(s)")
    void mergeRelationLIS(Long disId,String name);
    //创建化验公表项
    @Query("merge(l:PublicLIS{name:{0}})")
    void mergePublicLIS_1(String lisName);
    //疾病和化验公表项创建关系
    @Query("match(d:Disease{disId:{0}}),(s:PublicLIS{name:{1}}) merge(d)-[r:推荐]->(s)")
    void mergeRelationLIS_1(Long disId,String name);
    //创建化验结果节点
    @Query("merge(l:LISResult{name:{0}})")
    void mergeLISRESULT(String name);
    //公表名和化验结果创建关系
    @Query("match(d:LIS{name:{0}}),(s:LISResult{name:{1}}) merge(d)-[r:结果]->(s)")
    void mergeRelationPublicLIS(String publicLis,String lisResult);
    //化验结果和对应的codeCondition创建关系
    @Query("match(d:Condition{name:{0}}),(s:LISResult{name:{1}}) merge(d)<-[r:诊断依据]-(s)")
    void mergeRelationCondiLisRes(String codeCondition,String lisRes);
    //公表名和化验结果创建关系
    @Query("match(d:LIS{name:{0}}),(s:PublicLIS{name:{1}}) merge(d)-[r:化验公表]->(s)")
    void mergeRelationPublicAndLIS(String lis,String publicLis);
    //创建辅检项目
    @Query("merge(p:PACS{name:{0}})")
    void mergePacs(String pacsName);
    //疾病推荐辅检
    @Query("match(d:Disease{disId:{0}}),(s:PACS{name:{1}}) merge(d)-[r:推荐]->(s)")
    void mergeRelationDis2Pacs(Long disId,String name);
    //创建辅检结果节点
    @Query("merge(p:PACSResult{name:{0}})")
    void mergePacsResult(String name);
    //创建辅检和辅检结果的关系
    @Query("match(d:PACS{name:{0}}),(s:PACSResult{name:{1}}) merge(d)-[r:结果]->(s)")
    void mergeRelationPacsResult(String pacs,String pacsResult);
    //辅检结果和对应的codeCondition创建关系
    @Query("match(d:Condition{name:{0}}),(s:PACSResult{name:{1}}) merge(d)<-[r:诊断依据]-(s)")
    void mergeRelationCondiPacsRes(String codeCondition,String pacsRes);
}

