Skip to content

Commit

Permalink
protect against double meds in input pasted from atc-mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ace-dvm committed Nov 28, 2023
1 parent 334a7c7 commit a0c742c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 14 deletions.
41 changes: 40 additions & 1 deletion acceptance-test-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,45 @@ c2986',

});

test('multi meds handles duplicates', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);

let paste_me = `Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Paracetamol ACETYLSALICYLZUUR 0-WATER#PARACETAMOL N02BA51 2023-01-01
Celebrex 100 mg, harde capsules CELECOXIB M01AH01 2021-01-01
`;

let medlist = await Selector('#data_entry_med_list');
await t.expect(medlist.withText('N02BA51').exists).notOk();

await t.typeText(Selector('#multi_med'), paste_me);

try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}

let medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('Excedrin').exists).ok();
await t.expect(medlist2.withText('/Paracetamol').exists).ok();
await t.expect(medlist2.withText('N02BA51').exists).ok();

//cleanup first part
try{ await t.click(Selector('#remove_N02BA51')); } catch(error){}
try{ await t.click(Selector('#remove_M01AH01')); } catch(error){}

paste_me = `Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Excedrin, filmomhulde tabletten ACETYLSALICYLZUUR#COFFEINE 0-WATER#PARACETAMOL N02BA51 2023-01-01
Celebrex 100 mg, harde capsules CELECOXIB M01AH01 2021-01-01
`;

await t.typeText(Selector('#multi_med'), paste_me);
try{ await t.click(Selector('#button_submit_multi_med')); } catch(error){}
medlist2 = await Selector('#data_entry_med_list');
await t.expect(medlist2.withText('N02BA51').exists).ok();
await t.expect(medlist2.withText('/').exists).notOk();

//cleanup
try{ await t.click(Selector('#remove_N02BA51')); } catch(error){}
try{ await t.click(Selector('#remove_M01AH01')); } catch(error){}
});

test('enter problems', async t => {
let window1 = await navigate_to_patient(t, 'TEST' + this_test_part);
Expand Down Expand Up @@ -890,4 +929,4 @@ test('going to CDSS submits any fields that have content', async t => {
await t.expect(Selector("#d_user_education_hml").withText("1").exists).ok();
await t.expect(Selector("#d_user_fear").withText("2").exists).ok();

});
});
44 changes: 31 additions & 13 deletions static/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,16 @@ function data_entry_submit_button(){
if (meas_function){
send_message('submit_meas', meas_function);
}

/* var start = new Date().getTime();
var end = start;
while(end < start + 10000) { end = new Date().getTime(); }
*/
localStorage.clear();
window.location.reload(true);
}

function data_entry_med_submit_button(){
let form = document.getElementById('single_med_form');
/*var start = new Date().getTime();
var end = start;
while(end < start + 10000) { end = new Date().getTime(); }
*/
// first check if the med form is complete.
for (let i = 0; i < form.elements.length; ++i) {
if (form.elements[i].value == '') {
Expand Down Expand Up @@ -248,28 +247,47 @@ function user_entered_multi_med(form){
let count_to_4 = 0;
let atc_regex = /[a-zA-Z]\d\d./;

//TODO check for duplicates. If ATC is a duplicate, concatenate the names.
while(counter < strings.length){
let med_msg = {};
let single_med_name, single_med_atc, single_med_startdate;
while(count_to_4 < 4){
if(strings[counter]) {med_msg['single_med_name'] = strings[counter].trim();}
if(strings[counter]) {single_med_name = strings[counter].trim();}
counter++; count_to_4++; // do nothing with generic name
counter++; count_to_4++;
if (strings[counter] && atc_regex.test(strings[counter])) {
med_msg['single_med_atc'] = strings[counter].trim();
single_med_atc = strings[counter].trim();
}
counter++; count_to_4++;
if(strings[counter]) {med_msg['single_med_startdate'] = strings[counter].trim();}
if(strings[counter]) {single_med_startdate = strings[counter].trim();}
count_to_4++;
}
if(Object.keys(med_msg).length == 3){
messages.push(med_msg)
};
if(single_med_name && single_med_atc && single_med_startdate){
let is_duplicate = 0;
for (let i = 0; i < messages.length; ++i) {
//if name = an existing name, drop this entry
if(messages[i]['single_med_name'] == single_med_name){
is_duplicate = 1;
//if atc = an existing atc, concatenate the name and stop further processing
} else if (messages[i]['single_med_atc'] == single_med_atc){
messages[i]['single_med_name'] = messages[i]['single_med_name'] + "/" + single_med_name;
is_duplicate = 1;
}
}
if(!is_duplicate){
med_msg['single_med_name'] = single_med_name;
med_msg['single_med_atc'] = single_med_atc;
med_msg['single_med_startdate'] = single_med_startdate;
messages.push(med_msg)
}
}
single_med_name = null;
single_med_atc = null;
single_med_startdate = null;
count_to_4 = 0;
counter++;
}

// console.log(JSON.stringify(messages,null,4));
console.log(JSON.stringify(messages,null,4));

return function(message) {
message.patient_id = message_globals.patient_id;
Expand Down

0 comments on commit a0c742c

Please sign in to comment.