commit 54318d2c861b48431c656a4c04d300eb486d0084
Author: Serghei MIHAI <smihai@entrouvert.com>
Date:   Thu Jul 31 17:39:40 2014 +0200

    dossiers: printing each patient record tab with filtering past and future appointments by dates
    
    Closes #3109

diff --git a/calebasse/dossiers/forms.py b/calebasse/dossiers/forms.py
index 0fbc495d..5aa3adc1 100644
--- a/calebasse/dossiers/forms.py
+++ b/calebasse/dossiers/forms.py
@@ -398,3 +398,10 @@ class QuotationsForm(Form):
     date_actes_start = forms.DateField(label=u'Date', localize=True)
     date_actes_end = forms.DateField(label=u'Date', localize=True)
     without_quotations = forms.BooleanField()
+
+class PatientRecordPrintForm(Form):
+
+    prev_appointment_start_date = forms.DateField(label=u'De', required=False)
+    prev_appointment_end_date = forms.DateField(label=u'au', required=False)
+    next_appointment_start_date = forms.DateField(label=u'De', required=False)
+    next_appointment_end_date = forms.DateField(label=u'au', required=False)
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab.html
new file mode 100644
index 00000000..0cf9f5f4
--- /dev/null
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab.html
@@ -0,0 +1,14 @@
+{% block print-button %}
+<button class="icon-print right print">Imprimer</button>
+{% endblock %}
+{% block content %}
+{% endblock %}
+<br style="clear:both"/>
+<script type="text/javascript">
+    init_datepickers();
+    $('button.print').on('click', function(event) {
+        {% block print-actions %}{% endblock %}
+        print_cleanup();
+        window.print();
+    });
+</script>
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html
index 656aa578..f00c1246 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab1_general.html
@@ -1,3 +1,5 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+{% block content %}
 <form method="post" action="tab1"  id="general-form" class="patientrecordform">{% csrf_token %}
 <div class="left">
   <ul>
@@ -84,7 +86,7 @@
       {% for state in status %}
       <button type="button" id="{{ state.0 }}">{{ state.1 }}</button>
       {% endfor %}
-      <button type="button" id="patientrecord-history">Historique</button><br/>
+      <button type="button" id="patientrecord-history">Historique</button>
       <hr/>
       <p id="confidential-msg" style="display: none; font-size: 10px;">Confidentialité mise à jour</p>
       {{ form.confidential.label_tag }} : {{ form.confidential }}
@@ -113,4 +115,4 @@
       <button>Créer répertoire patient</button>
     </form>
 </div>
-<br style="clear:both"/>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab2_fiche_adm.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab2_fiche_adm.html
index 465ce3b6..a9ebff73 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab2_fiche_adm.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab2_fiche_adm.html
@@ -1,4 +1,6 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
 {% load dossiers %}
+{% block content %}
 <div id="tabs-2">
   <form method="post" action="tab2" id="administrative-form" class="patientrecordform">{% csrf_token %}
     <p><button class="save enable-on-change">Enregistrer</button></p>
@@ -164,3 +166,4 @@
     {% endfor %}
   </div>
 </div>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab3_adresses.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab3_adresses.html
index 1dbe5ba6..b2f874f9 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab3_adresses.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab3_adresses.html
@@ -1,4 +1,6 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
 {% load dossiers %}
+{% block content %}
 <div id="tabs-3">
   <form method="post" action="tab3" id="policyholder-form" class="patientrecordform">{% csrf_token %}
     <p>
@@ -97,3 +99,4 @@
 {% endfor %}
   </form>
 </div>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab4_notifs.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab4_notifs.html
index 7b4223ac..4350e653 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab4_notifs.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab4_notifs.html
@@ -1,3 +1,5 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+{% block content %}
 <div id="tabs-4">
   {% if object.service.slug == "cmpp" %}
   <div class="notifs">
@@ -215,3 +217,4 @@
     {% endif %}
     {% endif %}
   </div>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab5_actes_passes.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab5_actes_passes.html
index c7c55fcf..4a6e4796 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab5_actes_passes.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab5_actes_passes.html
@@ -1,3 +1,17 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+{% block print-button %}
+<div class="print-container screen-only">
+  <form class="datepicker filter">
+    <h5>Filtrer par date</h5>
+      du <input type="text" name="from" />
+      au <input type="text" name="to" />
+  </form>
+  {{ block.super }}
+</div>
+<br class="clear" />
+{% endblock %}
+
+{% block content %}
 <div id="tabs-5">
   {% for state, last_rdvs in history %}
   <div class="frame">
@@ -10,7 +24,8 @@
       <tbody>
       {% for act, state, missing_workers in last_rdvs %}
       <tr>
-        <td>{{ act.date|date:"SHORT_DATE_FORMAT" }} {{ act.time|date:"H:i" }}{% if missing_workers %} <span title="Au moins un intervenant est absent" class="icon-warning-sign absent"></span>{% endif %}</td>
+        <td><span class="date">{{ act.date|date:"SHORT_DATE_FORMAT" }}</span>
+          <span class="time">{{ act.time|date:"H:i" }}</span>{% if missing_workers %} <span title="Au moins un intervenant est absent" class="icon-warning-sign absent"></span>{% endif %}</td>
         <td>{% if state %}{% if act.is_absent %}<strong>{% endif %}{% if state.state_name == 'ACT_DOUBLE' or state.state_name == 'ACT_LOST' %}Présent ({{ state }}){% else %}{{ state }}{% endif %}{% if act.is_absent %}</strong>{% endif %}{% else %}Non pointé.{% endif %}</td>
         <td>{{ act.act_type }}</td>
         <td class="width-limited">{% for doctor in act.doctors.all %}
@@ -27,3 +42,5 @@
   </div>
   {% endfor %}
 </div>
+{% endblock %}
+{% block print-actions %}filter_date_bounds('#ui-tabs-5', '.frame td span.date');{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab6_next_rdv.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab6_next_rdv.html
index e84f7e5c..5c1e4791 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab6_next_rdv.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab6_next_rdv.html
@@ -1,3 +1,16 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+{% block print-button %}
+<div class="print-container screen-only">
+  <form class="datepicker filter">
+    <h5>Filtrer par date</h5>
+      du <input type="text" name="from" />
+      au <input type="text" name="to" />
+  </form>
+  {{ block.super }}
+</div>
+<br class="clear" />
+{% endblock %}
+{% block content %}
 <div id="tabs-6">
   <table class="basic">
     <thead>
@@ -6,7 +19,8 @@
     <tbody>
     {% for event, state, missing_participants, inactive_participants in next_rdvs %}
     <tr>
-      <td>{% firstof event.start_datetime|date:"l d/m/y H:i"|title %}{% if missing_participants or inactive_participants %} <span title="Au moins un intervenant est absent ou ne fait plus partie du service" class="icon-warning-sign absent"></span>{% endif %}</td>
+      <td><span class="date">{{ event.start_datetime|date:"SHORT_DATE_FORMAT" }}</span>
+          <span class="time">{% firstof event.start_datetime|date:"H:i"|title %}</span>{% if missing_participants or inactive_participants %} <span title="Au moins un intervenant est absent ou ne fait plus partie du service" class="icon-warning-sign absent"></span>{% endif %}</td>
       <td>{% if state %}{% if state.state_name != 'VALIDE' %}<strong>{% endif %}{{ state }}{% if state.state_name != 'VALIDE' %}</strong>{% endif %}{% else %}Non pointé.{% endif %}</td>
       <td>{{ event.act_type }}</td>
       <td class="width-limited">{% for participant in event.participants.all %}
@@ -32,3 +46,5 @@
     </tbody>
   </table>
 </div>
+{% endblock %}
+{% block print-actions %}filter_date_bounds('#ui-tabs-6', '.basic td span.date');{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab7_socialisation.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab7_socialisation.html
index a80a11ba..a9713dc0 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab7_socialisation.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab7_socialisation.html
@@ -1,3 +1,7 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+
+{% block content %}
+<br class="clear" />
 <div id="tabs-7">
   <div class="frame">
     <h3>Périodes de socialisation</h3>
@@ -68,3 +72,4 @@
     {% endfor %}
   </div>
 </div>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_tab8_medical.html b/calebasse/dossiers/templates/dossiers/patientrecord_tab8_medical.html
index 43633f67..24326d11 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_tab8_medical.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_tab8_medical.html
@@ -1,3 +1,6 @@
+{% extends 'dossiers/patientrecord_tab.html' %}
+
+{% block content %}
 <div id="tabs-8">
   <form method="post" action="tab8" id="physiology-form" class="patientrecordform">
     {% csrf_token %}
@@ -16,3 +19,4 @@
     <button class="save enable-on-change">Enregistrer</button>
   </form>
 </div>
+{% endblock %}
diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_update.html b/calebasse/dossiers/templates/dossiers/patientrecord_update.html
index 18356693..71af27a6 100644
--- a/calebasse/dossiers/templates/dossiers/patientrecord_update.html
+++ b/calebasse/dossiers/templates/dossiers/patientrecord_update.html
@@ -1,4 +1,5 @@
 {% extends "dossiers/base.html" %}
+{% load i18n %}
 {% load url from future %}
 {% load dossiers %}
 {% block extrastyles %}
diff --git a/calebasse/static/css/agenda.css b/calebasse/static/css/agenda.css
index 3d3326dc..633aea8e 100644
--- a/calebasse/static/css/agenda.css
+++ b/calebasse/static/css/agenda.css
@@ -1,7 +1,3 @@
-br.clear {
-    clear: both;
-}
-
 td#dispos {
 	vertical-align: top;
 }
diff --git a/calebasse/static/css/dossiers.css b/calebasse/static/css/dossiers.css
index dc958cfe..c1d83329 100644
--- a/calebasse/static/css/dossiers.css
+++ b/calebasse/static/css/dossiers.css
@@ -126,4 +126,29 @@ div#tabs-4 div div.buttons {
 
 input[type=checkbox] + button {
     display: none;
-}
\ No newline at end of file
+}
+
+.patientrecord_print ul {
+    margin: 0;
+    padding: 0;
+}
+
+.patientrecord_print li {
+    list-style-type: none;
+    display: inline;
+}
+
+.patientrecord_print label {
+    margin: 0 .5em;
+}
+
+.print-container {
+    float: right;
+}
+.print-container h5 {
+    margin: 0;
+}
+
+.print-container form {
+    display: inline;
+}
diff --git a/calebasse/static/css/print.css b/calebasse/static/css/print.css
index 92877878..136ad6c8 100644
--- a/calebasse/static/css/print.css
+++ b/calebasse/static/css/print.css
@@ -7,8 +7,12 @@ html {
   color: black;
 }
 
+button {
+    display: none;
+}
+
 div#header, div#splash, div#footer, div#appbar, div#datesel,
-div#djDebugToolbarHandle, button#uncheck-all, button#check-all, input.printable  {
+div#djDebugToolbarHandle, input.printable {
   display: none;
 }
 
@@ -100,4 +104,55 @@ table.main {
 table.main td, table.main th {
     border: 1px solid #555;
     padding: 0 .5em;
+}
+
+
+ /* Patient record printing */
+
+textarea, input[type=text], select {
+    border: 0;
+}
+
+textarea[value=''] {
+    display: none;
+}
+
+input[value=''] {
+    display: none;
+}
+
+#tabs > ul {
+    display: none;
+}
+
+.social-security-contact ul {
+    display: block;
+}
+
+ /* tabs-7 */
+
+#tabs-7 .subframe {
+    padding: 0 .5em;
+}
+
+ /* tabs-8 */
+
+#tabs-8 label {
+    display: inline;
+}
+
+.select2-results {
+    display: none;
+}
+
+.select2-choices {
+    list-style-type:none;
+}
+
+.select2-container + select {
+    display: none;
+}
+
+#tabs-8 label:after {
+    content: ':';
 }
\ No newline at end of file
diff --git a/calebasse/static/css/style.css b/calebasse/static/css/style.css
index 69e6886b..6d2e472c 100644
--- a/calebasse/static/css/style.css
+++ b/calebasse/static/css/style.css
@@ -1407,3 +1407,10 @@ label.social-security-label:hover {
     display: none;
 }
 
+.right {
+    float: right;
+}
+
+.clear {
+    clear: both;
+}
\ No newline at end of file
diff --git a/calebasse/static/js/calebasse.agenda.js b/calebasse/static/js/calebasse.agenda.js
index e2e21083..5a67982e 100644
--- a/calebasse/static/js/calebasse.agenda.js
+++ b/calebasse/static/js/calebasse.agenda.js
@@ -4,15 +4,6 @@ var app_name = path[2];
 var current_date = path[3];
 COOKIE_PATH = '/' + service + '/agenda';
 
-function delete_prompt(text) {
-  var r = prompt(text + '\n Pour cela veuillez entrer DEL');
-  if (r.toLowerCase().replace(/^\s+|\s+$/g, '') == 'del') {
-    return true;
-  } else {
-    return false;
-  }
-}
-
 function get_initial_fields(button, base) {
     var participants = new Array();
     var ressource = null;
@@ -250,11 +241,6 @@ function toggle_ressource(ressource) {
     return $(ressource_target).find('a.tab');
 }
 
-function init_datepickers(dialog) {
-    $('.datepicker-date', dialog).datepicker({dateFormat: 'd/m/yy', showOn: 'button'});
-    $('.datepicker input', dialog).datepicker({dateFormat: 'd/m/yy', showOn: 'button'});
-}
-
 function event_dialog(url, title, width, btn_text) {
     function add_periodic_events(base) {
       init_datepickers(base);
diff --git a/calebasse/static/js/calebasse.dossiers.js b/calebasse/static/js/calebasse.dossiers.js
index 1388a681..b572861a 100644
--- a/calebasse/static/js/calebasse.dossiers.js
+++ b/calebasse/static/js/calebasse.dossiers.js
@@ -10,6 +10,32 @@ function add_datepickers(that) {
   $('input#id_prolongation_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
 }
 
+function print_cleanup() {
+    $.each($('textarea'), function() {
+        if(!$(this).val())
+            $(this).addClass('screen-only');
+        else
+            $(this).removeClass('screen-only');
+    });
+}
+
+function filter_date_bounds(tab, selector) {
+    console.log(tab);
+    var from = $(tab + ' form.filter input[name=from]').datepicker('getDate');
+    var to = $(tab + ' form.filter input[name=to]').datepicker('getDate');
+    if (to) {
+        to.setHours(23); to.setMinutes(59); to.setSeconds(59);
+    }
+    $.each($(tab + ' ' + selector), function(){
+        var current = $.datepicker.parseDate('d/m/yy', $(this).text());
+        if (current < from || (to && current >= to)) {
+            $(this).parent().parent().addClass('screen-only');
+        } else {
+            $(this).parent().parent().removeClass('screen-only');
+        }
+    });
+}
+
 function load_add_address_dialog() {
   var str = $("#contactform").serialize();
   $.cookie('contactform', str, { path: window.location.pathname });
@@ -391,6 +417,12 @@ function load_tab8_medical() {
         });
     });
 
+    $('#patientrecord-print-button').on('click', function(event) {
+        event.preventDefault();
+        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
+                                '#ajax-dlg', '450px', 'Imprimer', false, false);
+    });
+
     $('#new-patientrecord').click(function() {
         generic_ajaxform_dialog('new', 'Nouveau dossier',
             '#dossier-dlg', '700px', 'Ajouter', false, function(that) {
diff --git a/calebasse/static/js/common.js b/calebasse/static/js/common.js
new file mode 100644
index 00000000..8d29cd8b
--- /dev/null
+++ b/calebasse/static/js/common.js
@@ -0,0 +1,13 @@
+function delete_prompt(text) {
+  var r = prompt(text + '\n Pour cela veuillez entrer DEL');
+  if (r.toLowerCase().replace(/^\s+|\s+$/g, '') == 'del') {
+    return true;
+  } else {
+    return false;
+  }
+}
+
+function init_datepickers(on) {
+    $('.datepicker-date', on).datepicker({dateFormat: 'd/m/yy', showOn: 'button'});
+    $('.datepicker input', on).datepicker({dateFormat: 'd/m/yy', showOn: 'button'});
+}
diff --git a/calebasse/templates/calebasse/base.html b/calebasse/templates/calebasse/base.html
index 584ee4b5..eefd03ae 100644
--- a/calebasse/templates/calebasse/base.html
+++ b/calebasse/templates/calebasse/base.html
@@ -20,6 +20,7 @@
     <script src="{{ STATIC_URL }}js/jquery.form.js"></script>
     <script src="{{ STATIC_URL }}js/jquery.sortElements.js"></script>
     <script src="{{ STATIC_URL }}development-bundle/ui/i18n/jquery.ui.datepicker-fr.js"></script>
+    <script src="{{ STATIC_URL }}js/common.js"></script>
     <script src="{{ STATIC_URL }}js/ajax_select.js"></script>
     <script src="{{ STATIC_URL }}js/jquery.mousewheel.js"></script>
     <script src="{{ STATIC_URL }}js/calebasse.mousewheel.js"></script>
