I have strings that I need to insert in db, but I want to change their value first if they fall under certain conditions.
For example, I have a line Epatite, Epatite B, EpatiteƔB, EpB3, I want them to be replaced by a EP Bbefore inserting into db.
This is part of my code:
var vac = makeUniform(vaccines[index]);
const queryInsert = {
text: 'INSERT INTO coverages (vaccine) VALUES ($1) ON CONFLICT DO NOTHING;',
values: [vac]
}
var printText = '[INSERT Italy IN coverages]';
promises.push(postgreSQLlib.query(queryInsert, printText, false));
function makeUniform(val) {
if(val === 'DIF' || val === 'Difterite') {
return 'DIPH';
}
else if(val === 'Epatite' || val === 'Epatite B' || val === 'EpatiteƔB' || val === 'EpB3') {
return 'EP B';
}
else if(val === 'HIB' || val === 'Hib3' || val === 'Hib') {
return 'HIB';
}
else {
return val;
}
}
When I execute SELECT DISTINCT vaccine FROM coverages ORDER BY vaccine;in psql shell, I get:
DIPH
DT-DTP3
DTP3
EP A
EP B
EpatiteƔB
Hib
HIB
M-MPR1
M-MPR1-MPRV ...
There is EpatiteƔB, which theoretically should have changed in EP B. Why is this not working?
EDIT 1
vaccines[index]comes from an online pdf from which I made a web scraper using textractpackage Node.js.
thank
source
share