Add behandelingen sortering

This commit is contained in:
Joshua Rubingh 2020-05-16 15:07:58 +02:00
parent 6d495b0cd2
commit bf79ade408
1 changed files with 79 additions and 18 deletions

View File

@ -1,5 +1,6 @@
{% extends 'base.html' %} <!-- Add this for inheritance -->
{% load i18n %}
{% load static %}
{% block title %}{% trans "New schedule" %}{% endblock %}
{% block pagetitle %}{% trans "New schedule" %}{% endblock %}
@ -300,7 +301,6 @@
</table>
</div>
</td>
</tr>
@ -316,12 +316,11 @@
<h1>Behandelingen</h1>
<p>In het model worden slots van 5 minuten gebruikt voor het bepalen van starttijden. etc. Afspraken starten daarmee om bijv. 10.00, 10.05, 10.10.<br />Afspraakduur wordt daarmee ook in veelvouden van 5 minuten gevraagd.</p>
<p>Zowel afspraken waar de patiënt fysiek in het ziekenhuis is, als wel telefoongesprekken worden hier gevraagd. Beide type afspraken kunnen in het raster worden gepland.</p>
<p>Zowel afspraketabel_behandelingenn waar de patiënt fysiek in het ziekenhuis is, als wel telefoongesprekken worden hier gevraagd. Beide type afspraken kunnen in het raster worden gepland.</p>
<p>"Normaal" betekent: zoals het was voor COVID-19<br />30% betekent: als je maar 30% van de patiënten kunt binnenkrijgen, hoeveel afspraken van elk type zou je dan willen inplannen?</p>
<table>
<tbody>
<table id="tabel_behandelingen">
<thead>
<tr>
<th>Naam behandeling</th>
<th>Duur (in minuten)</th>
@ -330,7 +329,8 @@
<th>Normaal aantal</th>
<th>Gewenst als op 30%</th>
</tr>
</thead>
<tbody>
<tr class="behandeling">
<td><input type="text" class="form-control" id="behandeling_0" name="behandeling_0" required></td>
<td>
@ -371,7 +371,7 @@
<td>
<input type="number" class="form-control behandeling_calc" id="behandeling_30p_0" name="behandeling_30p_0" min="0" max="100" required>
<small style="float:right; display:none"><a href="#">Verwijder</a></small>
<small style="float:right;"><a href="#">Verwijder</a></small>
</td>
</tr>
</tbody>
@ -434,7 +434,6 @@
if (selectitem.attr('aria-describedby')) {
selectitem.attr('aria-describedby',selectitem.attr('aria-describedby').replace(/_\d+Help$/,'_' + nr + 'Help'));
}
});
}
});
@ -497,17 +496,15 @@
function updateBehandelingen() {
jQuery('tr.behandeling').each(function(counter,element){
if (counter > 0) {
element = jQuery(element);
var nr = counter;
element.find('select,input').each(function(index,selectitem){
selectitem = jQuery(selectitem);
selectitem.prop('name',selectitem.prop('name').replace(/_\d+$/,'_' + nr));
selectitem.prop('id',selectitem.prop('id').replace(/_\d+$/,'_' + nr));
});
}
jQuery(element).find('select,input').each(function(index,selectitem){
selectitem = jQuery(selectitem);
selectitem.prop('name',selectitem.prop('name').replace(/_\d+$/,'_' + counter));
selectitem.prop('id',selectitem.prop('id').replace(/_\d+$/,'_' + counter));
});
});
jQuery('tr.behandeling td small').show();
jQuery('tr.behandeling:first td small').hide();
}
function calculateBehandelingen() {
@ -542,6 +539,64 @@
return ok;
}
function sort_behandelingen(n) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("tabel_behandelingen");
switching = true;
// Set the sorting direction to ascending:
dir = "asc";
/* Make a loop that will continue until
no switching has been done: */
while (switching) {
// Start by saying: no switching is done:
switching = false;
rows = table.rows;
/* Loop through all table rows (except the
first, which contains table headers): */
for (i = 1; i < (rows.length - 1); i++) {
// Start by saying there should be no switching:
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next: */
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
/* Check if the two rows should switch place,
based on the direction, asc or desc: */
var value_x = jQuery(x).find('select').length > 0 ? jQuery(x).find('select') : jQuery(x).find('input');
var value_y = jQuery(y).find('select').length > 0 ? jQuery(y).find('select') : jQuery(y).find('input');
if (dir == "asc") {
if (value_x.val().toLowerCase() > value_y.val().toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else if (dir == "desc") {
if (value_x.val().toLowerCase() < value_y.val().toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
/* If a switch has been marked, make the switch
and mark that a switch has been done: */
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
// Each time a switch is done, increase this count by 1:
switchcount ++;
} else {
/* If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again. */
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
updateBehandelingen();
}
function validate_working_hours() {
jQuery('div.werktijden').each(function(index,element){
jQuery(element).find('select').removeClass('is-invalid');
@ -682,6 +737,12 @@
check_working_hours(this);
});
jQuery('table#tabel_behandelingen thead tr th').each(function(index,element){
jQuery(element).on('click',function(){
sort_behandelingen(index);
});
});
jQuery('input.behandeling_calc').off('change keyup').on('change keyup',function(event){
calculateBehandelingen();
});