EthikTag/assets/js/getCodeBarre.js

265 lines
14 KiB
JavaScript
Raw Normal View History

2022-10-15 22:24:22 +02:00
export default class GetEvent{
static init(){
this.getEvent()
}
static getEvent(){
let saisie = $('#saisie');
saisie.focus();
let value;
2022-10-17 09:01:49 +02:00
let $info = $('.info');
2022-10-16 10:36:53 +02:00
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');
2022-10-17 09:01:49 +02:00
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');
2022-10-15 22:24:22 +02:00
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){
2022-10-16 10:36:53 +02:00
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);
2022-10-17 09:01:49 +02:00
$step.html('Pour passer à la suite');
$indication.html('Scannez le DMU');
$pictureTube.css('display', 'none');
$picturePoche.css('display', 'flex');
$info.css('visibility', 'visible')
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'init'){
$pictureTube.css('display', 'none');
$picturePoche.css('display', 'none');
let pochesImg = $('.sang');
[...pochesImg].forEach(sang=>{
sang.remove();
})
2022-10-16 10:36:53 +02:00
$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);
2022-10-17 09:01:49 +02:00
$step.html('Pour passer à la suite');
$indication.html('Scannez le DMU');
2022-10-16 10:36:53 +02:00
$typePoche.html('');
2022-10-17 09:01:49 +02:00
$info.css('visibility', 'visible')
$evolution.css('visibility', 'hidden')
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error'){
2022-10-17 09:01:49 +02:00
saisie.focus();
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
}
break;
case '1':
if(response.data.status == 'success'){
$typePoche.html(response.data.nbre_poche)
2022-10-17 09:01:49 +02:00
$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);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
case '2':
if(response.data.status == 'success'){
$typePoche.html(response.data.nbre_poche)
2022-10-17 09:01:49 +02:00
$current.html(response.data.nbre_poche)
console.log(response.data.nbre_poche)
2022-10-17 09:01:49 +02:00
$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 ){
$picturePoche.append('<div class="sang"><img src="/poches/Poche_sang2.png"></div>')
2022-10-17 09:01:49 +02:00
}
saisie.focus();
2022-10-16 10:36:53 +02:00
}
if(response.data.status == 'final'){
$typePoche.html(response.data.nbre_poche)
2022-10-17 09:01:49 +02:00
$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!');
2022-10-17 09:01:49 +02:00
$picturePoche.append('<div class="sang"><img src="/poches/Poche_sang2.png"></div>')
2022-10-17 09:01:49 +02:00
saisie.focus();
2022-10-16 10:36:53 +02:00
}
if(response.data.status == 'error_scan'){
2022-10-17 09:01:49 +02:00
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error_doublon'){
2022-10-17 09:01:49 +02:00
$displayError.html('Etiquette déjà scannée')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error_donneur'){
2022-10-17 09:01:49 +02:00
$displayError.html('Ne correspond pas au donneur')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
break;
case '3':
if(response.data.status == "success"){
2022-10-17 09:01:49 +02:00
$picturePoche.css('display', 'none');
let pochesImg = $('.sang');
[...pochesImg].forEach(sang=>{
sang.remove();
})
2022-10-17 09:01:49 +02:00
$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)
2022-10-17 09:01:49 +02:00
$type.html('Tubes')
2022-10-16 10:36:53 +02:00
}
if(response.data.status == "error_scan"){
2022-10-17 09:01:49 +02:00
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
}
break;
case '4':
if(response.data.status == 'success'){
2022-10-17 09:01:49 +02:00
$step.html('ETAPE 2 / 2');
2022-10-16 10:36:53 +02:00
$nbreTube.html(response.data.nbre_tube)
2022-10-17 09:01:49 +02:00
$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('<div class="sang"><img src="/tubes/Tube'+response.data.nbre_tube+'_check.png"></div>')
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'final'){
$nbreTube.html(response.data.nbre_tube)
$current.html(response.data.nbre_tube_max)
2022-10-17 09:01:49 +02:00
$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('<div class="sang"><img src="/tubes/Tube'+response.data.nbre_tube+'_check.png"></div>')
$displaySuccess.html('Patient '+ response.data.prenom+' '+response.data.nom + ' traité avec succès')
2022-10-17 09:01:49 +02:00
$displaySuccess.css('display', 'flex')
setTimeout(() => {
location.reload();
2022-10-17 09:01:49 +02:00
$displaySuccess.css('display', 'none')
2022-10-17 09:01:49 +02:00
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error_scan'){
2022-10-17 09:01:49 +02:00
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error_doublon'){
2022-10-17 09:01:49 +02:00
$displayError.html('Etiquette déjà scannée')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
if(response.data.status == 'error_donneur'){
2022-10-17 09:01:49 +02:00
$displayError.html('Ne correspond pas au donneur')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none');
2022-10-17 09:01:49 +02:00
}, 5000);
2022-10-16 10:36:53 +02:00
saisie.focus();
}
break;
}
2022-10-15 22:24:22 +02:00
}
})
}
})
}
}