Dynamic queries or metaqueries (queries to manage genericv input)

I'm using neo4j Desktop with neo4j 5.7 on a mac M2 computer

I have a lot of files coming from HL7 (a Health Level 7 framewotk for medical software).

They have a lot (60k) definitions of constants, in 569 CSV files, all of them are similar.

Their generic format is as follow, while the name of this particular file is action-code.csv

Code,Display,Definition
 ††send-message,Send a message,The action indicates that ....
 ††collect-information,Collect information,The action indicates ...
 ††prescribe-medication,Prescribe a medication,The action indicates that a ...

I need at first to extract the node name from the table (file) name (action-code.csv must became ActionCode).

Then, I need to load all the rows as ActionCode nodes, giving them all property with tghe right name (first caracter lowercae and the others cameled.

I don't know what is the name of the properties, only that the first one must become the Unique Index

Here is my query (at the 20th attempt): it runs and create all the nodes

MATCH (n) delete n;
LOAD CSV  FROM "file:///ValueSetsCSV/listafiles.txt" AS fn 

LOAD CSV WITH HEADERS FROM 'file:///ValueSetsCSV/' + fn[0] AS line FIELDTERMINATOR ","

WITH line ,replace(fn[0],".csv","") AS fileName
WITH line, apoc.text.capitalize(apoc.text.camelCase(fileName) ) as nodeName, line["Code"] as key

call apoc.create.node([nodeName], {id : 1}) yield node   
    set node = line
    set node.Code = trim(replace(key,"ďż˝",""))

//CREATE CONSTRAINT IF NOT EXISTS "c_"+node.Code for (node:nodeName) REQUIRE (n.Code) IS UNIQUE;

return node

My problems are:

  1. I don't know how to create the index
  2. I don't know how to lowercase the initial for the property name

Hello @paolodipietro58 :slight_smile:

I guess the procedure apoc.cypher.run() is what you need.

Regards,
Cobra

Hi Paolo, those'd be your apocs:

  • apoc.cypher.runSchema
  • apoc.text.decapitalize

Best! :slight_smile: