String comparison does not work

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:

// vaccines[index] is the string to compare
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'; // diphtheria
    }
    else if(val === 'Epatite' || val === 'Epatite B' || val === 'EpatiteƔB' || val === 'EpB3') {
        return 'EP B'; // hepatitis B
    }
    else if(val === 'HIB' || val === 'Hib3' || val === 'Hib') {
        return 'HIB'; // haemophilus influenzae B
    }
    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

+4
source share
2 answers

:

UPDATE coverages set vaccine = 'EP B' WHERE vaccine LIKE 'Epatite%' OR vaccine = 'EpB3';

- .

+1

= (val === "Epatite% E1B% 21" )

function makeUniform(val) {
    if(val === 'DIF' || val === 'Difterite') {
        return 'DIPH'; // diphtheria
    }
    else if(val === 'Epatite' || val === 'Epatite B' || val==="Epatite%E1B%21" || val === 'EpatiteƔB' || val === 'EpB3') {
        return 'EP B'; // hepatitis B
    }
    else if(val === 'HIB' || val === 'Hib3' || val === 'Hib') {
        return 'HIB'; // haemophilus influenzae B
    }
    else {
        return val;
    }
}
+1

Source: https://habr.com/ru/post/1695684/


All Articles