From f8b1f7a4ce7e5c61fabb00d4d961a9b42b3888ce Mon Sep 17 00:00:00 2001 From: Joshua Rubingh Date: Sat, 16 May 2020 21:31:33 +0200 Subject: [PATCH] Update formulier --- .../templates/schedule/schedule_new.html | 170 +++++++++++++++++- 1 file changed, 163 insertions(+), 7 deletions(-) diff --git a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html index 37a51fa..3ec0a01 100644 --- a/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html +++ b/polyclinic_scheduling/apps/schedule/templates/schedule/schedule_new.html @@ -386,11 +386,20 @@ 0 0 + - + +
+ + + + + + + @@ -477,7 +486,11 @@ clone.insertAfter('tr.behandeling:last'); - jQuery('input.behandeling_calc').off('change keyup').on('change keyup',function(){ + jQuery('tr.behandeling input.behandeling_calc').off('change keyup').on('change keyup',function(){ + calculateBehandelingen(); + }); + + jQuery('tr.behandeling select').off('change').on('change',function(){ calculateBehandelingen(); }); @@ -513,8 +526,10 @@ jQuery('tr.behandeling').each(function(counter,row){ row = jQuery(row); - total += (row.find('input[name*="_100p_"]').val() != '' ? row.find('input[name*="_100p_"]').val() * 1 : 0); - percentage += (row.find('input[name*="_30p_"]').val() != '' ? row.find('input[name*="_30p_"]').val() * 1 : 0); + if (row.find('select[name^="behandeling_method_"]').val() == 'live') { + total += (row.find('input[name*="_100p_"]').val() != '' ? row.find('input[name*="_100p_"]').val() * 1 : 0); + percentage += (row.find('input[name*="_30p_"]').val() != '' ? row.find('input[name*="_30p_"]').val() * 1 : 0); + } }); jQuery('tr.behandeling_calc_summary td:nth-child(2)').text(total); @@ -534,7 +549,9 @@ calc_message = 'Dit klopt precies'; class_message = 'alert-success'; } - jQuery('td.behandeling_calc_remarks').removeClass('alert-danger alert-warning alert-success').addClass(class_message).text(calc_message); + jQuery('div.behandeling_calc_remarks').removeClass('alert-danger alert-warning alert-success').addClass(class_message).text(calc_message); + + validate_behandeling_hours(); return ok; } @@ -597,6 +614,142 @@ updateBehandelingen(); } + function validate_behandeling_hours() { + let behandelingen = {}; + jQuery('div.poliekliniek_specialisatie').each(function(index,element){ + element = jQuery(element); + + let specialisme = element.find('input[name^="specialisatie_"]').val(); + + behandelingen[specialisme] = { + name : element.find('input[name^="specialisatie_"]').val(), + artsen : element.find('input[name^="specialisatie_aantal_artsen_"]').val(), + max_time : 0, + used_time : 0 + }; + + let time_start_value = element.find('select[name^="werkdag_start_afdeling_"]').val() * 1; + let time_end_value = element.find('select[name^="werkdag_end_afdeling_"]').val() * 1; + + if ('' != time_start_value && '' != time_end_value && time_start_value > 0 && time_end_value > 0) { + + let time_start = new Date() + time_start.setHours(Math.floor(time_start_value / 100)); + time_start.setMinutes(time_start_value % 100); + time_start.setSeconds(0); + time_start.setMilliseconds(0); + + let time_end = new Date() + time_end.setHours(Math.floor(time_end_value / 100)); + time_end.setMinutes(time_end_value % 100); + time_end.setSeconds(0); + time_end.setMilliseconds(0); + + //console.log(time_start,time_end); + + behandelingen[specialisme]['max_time'] = ((time_end - time_start) / (1000 * 60)); + } + + time_start_value = element.find('select[name^="ochtend_pauze_start_afdeling_"]').val() * 1; + time_end_value = element.find('select[name^="ochtend_pauze_end_afdeling_"]').val() * 1; + + if ('' != time_start_value && '' != time_end_value && time_start_value > 0 && time_end_value > 0) { + + let time_start = new Date() + time_start.setHours(Math.floor(time_start_value / 100)); + time_start.setMinutes(time_start_value % 100); + time_start.setSeconds(0); + time_start.setMilliseconds(0); + + let time_end = new Date() + time_end.setHours(Math.floor(time_end_value / 100)); + time_end.setMinutes(time_end_value % 100); + time_end.setSeconds(0); + time_end.setMilliseconds(0); + + //console.log(time_start,time_end); + + behandelingen[specialisme]['max_time'] -= ((time_end - time_start) / (1000 * 60)); + } + + time_start_value = element.find('select[name^="lunch_pauze_start_afdeling_"]').val() * 1; + time_end_value = element.find('select[name^="lunch_pauze_end_afdeling_"]').val() * 1; + + if ('' != time_start_value && '' != time_end_value && time_start_value > 0 && time_end_value > 0) { + + let time_start = new Date() + time_start.setHours(Math.floor(time_start_value / 100)); + time_start.setMinutes(time_start_value % 100); + time_start.setSeconds(0); + time_start.setMilliseconds(0); + + let time_end = new Date() + time_end.setHours(Math.floor(time_end_value / 100)); + time_end.setMinutes(time_end_value % 100); + time_end.setSeconds(0); + time_end.setMilliseconds(0); + + //console.log(time_start,time_end); + + behandelingen[specialisme]['max_time'] -= ((time_end - time_start) / (1000 * 60)); + } + + time_start_value = element.find('select[name^="middag_pauze_start_afdeling_"]').val() * 1; + time_end_value = element.find('select[name^="middag_pauze_end_afdeling_"]').val() * 1; + + if ('' != time_start_value && '' != time_end_value && time_start_value > 0 && time_end_value > 0) { + + let time_start = new Date() + time_start.setHours(Math.floor(time_start_value / 100)); + time_start.setMinutes(time_start_value % 100); + time_start.setSeconds(0); + time_start.setMilliseconds(0); + + let time_end = new Date() + time_end.setHours(Math.floor(time_end_value / 100)); + time_end.setMinutes(time_end_value % 100); + time_end.setSeconds(0); + time_end.setMilliseconds(0); + + //console.log(time_start,time_end); + + behandelingen[specialisme]['max_time'] -= ((time_end - time_start) / (1000 * 60)); + } + + }); + + jQuery('tr.behandeling').each(function(index,element){ + element = jQuery(element); + + if (element.find('select[name^="behandeling_method_"]').val() == 'live') { + let specialisme = element.find('select[name^="behandeling_specialisme_"]').val(); + let duration = element.find('select[name^="behandeling_duration_"]').val(); + let amount100 = element.find('input[name^="behandeling_100p_"]').val(); + + if (specialisme && duration && amount100) { + behandelingen[specialisme]['used_time'] += duration * amount100; + } + } + }); + + let error = false; + let message = jQuery('td.behandeling_calc_time'); + message.html('') + + jQuery.each(behandelingen,function(specialisme,obj){ + if (obj.max_time - obj.used_time < 0) { + error = true; + message.append(jQuery('
').addClass('alert-danger').html('' + specialisme + ' : Te veel behandelingen voor het aantal arsten en werktijd. ' + (obj.used_time - obj.max_time) + ' Minuten teveel.')); + } else if (obj.max_time - obj.used_time == 0) { + message.append(jQuery('
').addClass('alert-success').html('' + specialisme + ' : Perfect! Alle tijd is ingedeeld.')); + } else { + message.append(jQuery('
').addClass('alert-warning').html('' + specialisme + ' : Uw heeft nog ' + (obj.max_time - obj.used_time) + ' minuten tijd over voor meer afspraken.')); + } + }); + + return error; + } + function validate_working_hours() { jQuery('div.werktijden').each(function(index,element){ jQuery(element).find('select').removeClass('is-invalid'); @@ -722,11 +875,12 @@ jQuery('div.poliekliniek_specialisatie input').off('change').on('change',function(){ updateSpecialisatieValues(); }); - +{% comment %} jQuery('a.add_behandelkamer').on('click',function(event){ event.preventDefault(); addBehandelkamer(); }); +{% endcomment %} jQuery('a.add_behandeling').on('click',function(event){ event.preventDefault(); @@ -735,6 +889,7 @@ jQuery('div.werktijden select').off('change').on('change',function(event){ check_working_hours(this); + calculateBehandelingen(); }); jQuery('table#tabel_behandelingen thead tr th').each(function(index,element){ @@ -749,7 +904,8 @@ jQuery('form#new_schedule_form').on('submit',function(event){ if (validate_working_hours() && - calculateBehandelingen()) { + calculateBehandelingen() && + validate_behandeling_hours()) { let formdata = new FormData(this); formdata.delete('csrfmiddlewaretoken');