与neo4j和csv文件相关

Related to neo4j and csv files

enter image description here我是 neo4j 和 cypher 的新手。我想为多个子节点创建节点。我有患者文件和一个过敏文件,所以首先我想创建节点过敏,然后我想向该节点添加子节点。然后我想将该过敏节点添加到患者。例如 patient-[:has allergies]-allergies<-latex allergy allergies another node for another allergy connected to allergies. 我怎么能在 neo4j 中做到这一点? allergy.csv 文件包含

START       Patent id                           DESCRIPTION 
01/05/1982 1d604da9-9a81-4ba9-80c2-de3375d59b40 Latex allergy 
10/25/1982 034e9e3b-2def-4559-bb2a-7850888ae060 Shellfish allergy 

patient.csv 包含

Id                                   BIRTHDATE   First Name      ADDRESS 
1d604da9-9a81-4ba9-80c2-de3375d59b40 5/25/1989    Josef       427 Balistreri 
034e9e3b-2def-4559-bb2a-7850888ae060 11/14/1983   milo217    422 Farrell      

CITY         STATE        COUNTY 
Chicopee Massachusetts Hampden County 
Chicopee Massachusetts Hampden County 

LOAD CSV WITH HEADERS FROM "file:///patients.csv" as row
MERGE (p:patient {name:row.FIRST, id:row.Id, birhdate:row.BIRTHDATE})
MERGE (ad: address {address : row. ADDRESS, state:row.STATE, country:row.COUNTY})
CREATE (p)-[:belongs to]->(ad);

LOAD CSV WITH HEADERS FROM "file:///allergies.csv" as row
CREATE (a: allergy{name: row. DESCRIPTION, id:row.PATIENT});
MATCH (p:patient), (a: allergy)
WHERE p.id = a.id
MERGE (p)-[:has_allergy] -> (a);

经过长时间的交谈,我不能不回答就离开这个话题。

allery.csv:
START,Patient_id,DESCRIPTION
01/05/1982,1d604da9-9a81-4ba9-80c2-de3375d59b40,Latex allergy
10/25/1982,034e9e3b-2def-4559-bb2a-7850888ae060,Shellfish allergy
10/25/1982,034e9e3b-2def-4559-bb2a-7850888ae060,Pollen allergy


LOAD CSV WITH HEADERS FROM "file:///allergy.csv" as row
CREATE (a: allergy {name: row.DESCRIPTION, id:row.Patient_id}) 
WITH row, a
MERGE (p:patient {id: row.Patient_id})
WITH p, a
MERGE (p)- [:has_alleries] -> (al:allergy) 
WITH al, a
MERGE (al) <- [:allergy] - (a);

给老师的评论:

  1. 不需要过敏源和患者之间的过敏节点。你可以直接从过敏到病人。
  2. 关系类型“allergy”与节点“allergy”相同。你可以使用不同的标签,比如乳胶过敏 - :of_type -> allergy.
  3. 过敏节点id与患者id相同。不合适。

结果: