-
Notifications
You must be signed in to change notification settings - Fork 74
/
snomed_g_graphdb_cypher_create.template
executable file
·129 lines (110 loc) · 5.25 KB
/
snomed_g_graphdb_cypher_create.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -----------------------------------------------------------------------------------------
// Module: snomed_g_graphdb_create.cypher
// Author: Jay Pedersen, University of Nebraska, August 2015
// Concept: Update a SNOMED_G Graph Database from input CSV files which describe the changes
// to concepts, descriptions, ISA relationships and defining relationships.
// Input Files:
// concept_new.csv
// descrip_new.csv
// isa_rel_new.csv
// defining_rel_new.csv
// NEXT STEP -- create INDEXES
CREATE CONSTRAINT FOR (c:ObjectConcept) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT FOR (c:ObjectConcept) REQUIRE c.sctid IS UNIQUE;
// id,sctid index created, requiring uniqueness
// Note: Can't have "FSN is UNIQUE"" constraint, can have dups (inactive concepts)
// for example -- "retired procedure" is FSN of multiple inactive concepts
CREATE CONSTRAINT FOR (c:Description) REQUIRE c.id IS UNIQUE;
CREATE INDEX FOR (x:Description) ON (x.sctid);
// need index so setting HAS_DESCRIPTION edges doesn't stall
// there can be more than one description for the same sctid, sctid not unique, but id is unique
// ROLE_GROUP nodes. Index needed for defining relationship assignment.
CREATE INDEX FOR (x:RoleGroup) ON (x.sctid);
// NEXT STEP -- create CONCEPT nodes
RETURN 'Creating NEW ObjectConcept nodes';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>concept_new.csv" as line
CALL {
with line
CREATE (n:ObjectConcept
{ nodetype: 'concept',
id: line.id,
sctid: line.id,
active: line.active,
effectiveTime: line.effectiveTime,
moduleId: line.moduleId,
definitionStatusId: line.definitionStatusId,
FSN: line.FSN,
history: line.history} )
} IN TRANSACTIONS OF 200 ROWS;
// NEXT STEP -- create DESCRIPTION nodes (info from Language+Description file)
RETURN 'Creating NEW Description nodes';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>descrip_new.csv" as line
CALL {
with line
CREATE (n:Description
{ nodetype:'description',
id: line.id,
sctid: line.sctid,
active: line.active,
typeId: line.typeId,
moduleId: line.moduleId,
descriptionType: line.descriptionType,
id128bit: line.id128bit,
term: line.term,
effectiveTime: line.effectiveTime,
acceptabilityId: line.acceptabilityId,
refsetId: line.refsetId,
caseSignificanceId: line.caseSignificanceId,
languageCode: line.languageCode,
history: line.history} )
} IN TRANSACTIONS OF 200 ROWS;
// NEXT STEP - create DESCRIPTION edges
RETURN 'Creating HAS_DESCRIPTION edges for new Description nodes related to ObjectConcept nodes';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>descrip_new.csv" as line
CALL {
with line
MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id })
MERGE (c)-[:HAS_DESCRIPTION]->(f)
} IN TRANSACTIONS OF 200 ROWS;
// --------------------------------------------------------------------------------------
// NEXT STEP -- create ISA relationships
// --------------------------------------------------------------------------------------
RETURN 'Creating NEW ISA edges';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>isa_rel_new.csv" as line
CALL {
with line
MATCH (c1:ObjectConcept { id: line.sourceId }), (c2:ObjectConcept { id: line.destinationId })
MERGE (c1)-[:ISA { id: line.id,
active: line.active,
effectiveTime: line.effectiveTime,
moduleId: line.moduleId,
relationshipGroup: line.relationshipGroup,
typeId: line.typeId,
characteristicTypeId: line.characteristicTypeId,
sourceId: line.sourceId,
destinationId: line.destinationId,
history: line.history }]->(c2)
} IN TRANSACTIONS OF 200 ROWS;
// --------------------------------------------------------------------------------------
// NEXT STEP -- create RoleGroup nodes
// --------------------------------------------------------------------------------------
RETURN 'Creating RoleGroup nodes';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>rolegroups.csv" as line
CALL {
with line
MERGE (rg:RoleGroup
{ nodetype:'rolegroup',
sctid: line.sctid,
rolegroup: line.rolegroup})
} IN TRANSACTIONS OF 500 ROWS;
// Add edge in 2nd step, Java memory issue
RETURN 'Creating HAS_ROLE_GROUP edges';
LOAD csv with headers from "<<<file_protocol>>><<<output_dir>>>rolegroups.csv" as line
CALL {
with line
MATCH (c:ObjectConcept { sctid: line.sctid }), (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup })
MERGE (c)-[:HAS_ROLE_GROUP]->(rg)
} IN TRANSACTIONS OF 500 ROWS;
// --------------------------------------------------------------------------------------
// NEXT STEP -- create Defining relationships
// --------------------------------------------------------------------------------------