export default class GetEvent{ static init(){ this.getEvent() } static getEvent(){ let saisie = $('#saisie'); saisie.focus(); let value; let $info = $('.info'); let $infoDon = $('#info-don'); let $infoDonneur = $('#info-donneur'); let $infoPsl = $('#info-psl'); let $don = $('#don'); let $nom = $('#nom'); let $prenom = $('#prenom'); let $naissance = $('#naissance'); let $typeDon = $('#typeDon'); let $typePoche = $('#typePoche'); let $nbreTube = $('#nbreTube'); let $step = $('#step'); let $indication = $('#indication'); let $evolution = $('#evolution'); let $label = $('#label'); let $type = $('#type'); let $current = $('#current'); let $todo = $('#todo'); let $picturePoche = $('#picturePoche'); let $pictureTube = $('#pictureTube'); let $input = $('#inputRange'); let $displayError = $('.error'); let $displaySuccess = $('.displaySuccess'); document.addEventListener('keydown', function (event) { saisie.focus(); if(event.code == 'Tab'){ value = saisie.val(); saisie.val('') $.ajax({ url: '/api/get-code-barre-type', method: "POST", dataType: "json", data: {'codeBarre': value}, success: function(response){ switch(response.data.step){ case '0': if(response.data.status == 'success'){ $don.html(response.data.codeBarre); $nom.html(response.data.nom); $prenom.html(response.data.prenom); $naissance.html(new Date(response.data.birthdate).toLocaleDateString()); $typeDon.html(response.data.type_don); $nbreTube.html(response.data.nbre_tube); $step.html('Pour passer à la suite'); $indication.html('Scannez le DMU'); $pictureTube.css('display', 'none'); $picturePoche.css('display', 'flex'); $info.css('visibility', 'visible') saisie.focus(); } if(response.data.status == 'init'){ let pochesImg = $('.sang'); [...pochesImg].forEach(sang=>{ sang.remove(); }) $don.html(response.data.codeBarre); $nom.html(response.data.nom); $prenom.html(response.data.prenom); $naissance.html(new Date(response.data.birthdate).toLocaleDateString()); $typeDon.html(response.data.type_don); $nbreTube.html(response.data.nbre_tube); $step.html('Pour passer à la suite'); $indication.html('Scannez le DMU'); $typePoche.html(''); $info.css('visibility', 'visible') $evolution.css('visibility', 'hidden') saisie.focus(); } if(response.data.status == 'error'){ saisie.focus(); $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); } break; case '1': if(response.data.status == 'success'){ $typePoche.html(response.data.nbre_poche) $step.html('ETAPE 1 / 2'); $indication.html('Scannez les étiquettes des poches'); saisie.focus(); $evolution.css('visibility', 'visible'); } if(response.data.status == 'error_donneur'){ $displayError.html('erreur donneur') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_doublon'){ $displayError.html('erreur doublon') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } case '2': if(response.data.status == 'success'){ console.log('step 2 success !!') $typePoche.html(response.data.nbre_poche) $current.html(response.data.nbre_poche) $type.html('Poches'); $todo.html(response.data.nbre_poche_max) $input.attr('max', response.data.nbre_poche_max) $input.attr('value', response.data.nbre_poche) if(response.data.nbre_poche !=response.data.nbre_poche_max && response.data.nbre_poche != 0){ $picturePoche.append('
') } saisie.focus(); } if(response.data.status == 'final'){ $typePoche.html(response.data.nbre_poche) $current.html(response.data.nbre_poche) $input.attr('max', response.data.nbre_poche_max) $input.attr('value', response.data.nbre_poche) $indication.html('validez avec un scan de poche!'); $picturePoche.append('') saisie.focus(); } if(response.data.status == 'error_scan'){ $displayError.html("Mauvais type d'étiquette") $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_doublon'){ $displayError.html('Etiquette déjà scannée') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_donneur'){ $displayError.html('Ne correspond pas au donneur') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } break; case '3': if(response.data.status == "success"){ $picturePoche.css('display', 'none'); let pochesImg = $('.sang'); [...pochesImg].forEach(sang=>{ sang.remove(); }) $pictureTube.css('display', 'flex'); $indication.html('Scannez les étiquettes de tubes!'); $input.attr('max', response.data.nbre_tube_max) $todo.html(response.data.nbre_tube_max) $input.attr('value', 0) $current.html(0) $type.html('Tubes') } if(response.data.status == "error_scan"){ $displayError.html("Mauvais type d'étiquette") $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); } break; case '4': if(response.data.status == 'success'){ $step.html('ETAPE 2 / 2'); $nbreTube.html(response.data.nbre_tube) $current.html(response.data.nbre_tube) $input.attr('max', response.data.nbre_tube_max) $type.html('Tubes') $todo.html(response.data.nbre_tube_max) $input.attr('value', response.data.nbre_tube) console.log( response.data.nbre_tube) $pictureTube.append('') saisie.focus(); } if(response.data.status == 'final'){ $nbreTube.html(response.data.nbre_tube) $current.html(response.data.nbre_tube_max) $input.attr('max', response.data.nbre_tube_max) $type.html('Tubes') $todo.html(response.data.nbre_tube_max) $input.attr('value', response.data.nbre_tube) $pictureTube.append('') $displaySuccess.html('Patient '+ response.data.prenom+' '+response.data.nom + ' traité avec succès') $displaySuccess.css('display', 'flex') setTimeout(() => { location.reload(); $displaySuccess.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_scan'){ $displayError.html("Mauvais type d'étiquette") $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_doublon'){ $displayError.html('Etiquette déjà scannée') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none') }, 5000); saisie.focus(); } if(response.data.status == 'error_donneur'){ $displayError.html('Ne correspond pas au donneur') $displayError.css('display', "flex"); setTimeout(() => { $displayError.css('display', 'none'); }, 5000); saisie.focus(); } break; } } }) } }) } }