Error in cypher query

I'm loading data from a csv file and when I see an already existing edge attribute, then I want to pass that already existing edge attribute else it'll be blank. I'm getting the following when trying to run this cypher query ...

Cypher query

LOAD CSV WITH HEADERS FROM $csv_file_path AS line // FOR UPDATING QUANTITY DATA
MATCH (d:Diagnosis)
WHERE d.diagnosis_id=line.diagnosisID
MERGE (t:Treatment {treatment_id:line.treatmentID})
MERGE (d)-[r:DiagnosisToTreatment]-(t)

WITH apoc.convert.fromJsonMap(replace(CASE WHEN EXISTS r.qty_dict THEN r.qty_dict ELSE {} END, '`', '')) as map, apoc.convert.fromJsonMap(replace(line.qty_dict, '`', '')) as map1
............

The error I'm getting is:
Query failed: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input 'r': expected

Thanks
(migrated from khoros post Solved: Re: Error in cypher query - Neo4j - 62888)

Instead of ‘exists’ try ‘is not null’ also, does the else value have to be a string, I.e. ‘{}’ ?