Projet

Général

Profil

Télécharger (18,6 ko) Statistiques
| Branche: | Tag: | Révision:

calebasse / calebasse / static / js / calebasse.dossiers.js @ f93684a4

1
function add_datepickers(that) {
2
  $('input#id_birthdate', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button',
3
    changeMonth: true, changeYear: true, yearRange: 'c-80:c+2' });
4
  $('input#id_start_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
5
  $('input#id_request_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
6
  $('input#id_agree_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
7
  $('input#id_insist_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
8
  $('input#id_end_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
9
  $('input#id_date_selected', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
10
  $('input#id_prolongation_date', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
11
}
12

    
13
function print_cleanup() {
14
    $.each($('textarea'), function() {
15
        if(!$(this).val())
16
            $(this).addClass('screen-only');
17
        else
18
            $(this).removeClass('screen-only');
19
    });
20
}
21

    
22
function filter_date_bounds(tab, selector) {
23
    var from = $(tab + ' form.filter input[name=from]').datepicker('getDate');
24
    var to = $(tab + ' form.filter input[name=to]').datepicker('getDate');
25
    if (to) {
26
        to.setHours(23); to.setMinutes(59); to.setSeconds(59);
27
    }
28
    $.each($(tab + ' ' + selector), function(){
29
        var current = $.datepicker.parseDate('d/m/yy', $(this).text());
30
        if (current < from || (to && current >= to)) {
31
            $(this).parent().parent().addClass('screen-only');
32
        } else {
33
            $(this).parent().parent().removeClass('screen-only');
34
        }
35
    });
36
}
37

    
38
function load_add_address_dialog() {
39
  var str = $("#contactform").serialize();
40
  $.cookie('contactform', str, { path: window.location.pathname });
41
  generic_ajaxform_dialog('address/new', 'Ajouter une adresse',
42
      '#address-dlg', '600px', 'Ajouter');
43
}
44

    
45
function warning_on_unsave_change() {
46
    var form_changed = false;
47
    $(window).on("beforeunload", function() {
48
        if (form_changed) {
49
            return "Vous n'avez pas enregistré vos changements.";
50
        }
51
    });
52
    $("#tabs").on("tabsbeforeactivate", function(event, ui) {
53
        if (form_changed) {
54
            var answer = confirm('Vous avez des changements non sauvegardés. Voulez vous vraiment continuer ?');
55
            if (! answer) {
56
                event.preventDefault();
57
            }
58
            else {
59
                form_changed = false;
60
            }
61
        }
62
    });
63
    $('.autosubmit').on("click", function() {
64
        form_changed = false;
65
    });
66
    $('form').on("change", function() {
67
        form_changed = true;
68
    });
69
    $('button').on("click", function() {
70
        form_changed = false;
71
    });
72
    var tabid = parseInt($.url($(location).attr('href')).fparam('tab')) + 1;
73
    if ($('.errorlist', '#ui-tabs-' + tabid).length != 0) {
74
      form_changed = true;
75
    }
76
}
77

    
78
function state_dialog(url, state_title, state_type) {
79
    $('#change-record').load(url,
80
            function () {
81
                var patient_id = $(this).data('id');
82
                var service_id = $(this).data('service-id');
83
                function onsuccess(response, status, xhr, form) {
84
                    var parse = $(response);
85
                    if ($('.errorlist', parse).length != 0) {
86
                        $('#change-record').html(response);
87
                        $('#change-record form').ajaxForm({
88
                            success: onsuccess,
89
                            data: { patient_id: patient_id,  state_type: state_type, service_id: service_id }
90
                        });
91
                    } else {
92
                        window.location.reload(true);
93
                    }
94
                }
95
                if (state_type == 'CLOS_RDV') {
96
                  var message = $('p.message')
97
                  message.append($('<span id="highlight">Attention ce patient a encore des rendez-vous de planifiés !</span>'));
98
                  state_type = 'CLOS';
99
                }
100
                $('input.date', this).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
101
                $('form', this).ajaxForm({
102
                    success: onsuccess,
103
                    data: { patient_id: patient_id,  state_type: state_type, service_id: service_id }
104
                });
105
                $(this).dialog({title: "Changement - " + state_title,
106
                    width: '500px',
107
                    buttons: [ { text: "Annuler",
108
                        click: function() { $(this).dialog("close"); } },
109
                    { text: "Valider",
110
                        click: function() { $("#change-record form").submit(); } }]});
111
            });
112
}
113

    
114
function load_tab1_general() {
115
    warning_on_unsave_change();
116
    $('#update-paper-id-btn').click(function() {
117
        generic_ajaxform_dialog('update/paper_id', 'Modifier le numéro du dossier papier',
118
            '#ajax-dlg', '500px', 'Modifier');
119
    });
120
    $('#close-patientrecord').click(function() {
121
        state_dialog('update-state', 'Clore', 'CLOS');
122
    });
123
    $('#close-rdv-patientrecord').click(function() {
124
        state_dialog('update-state', 'Clore', 'CLOS_RDV');
125
    });
126
    $('#reopen-patientrecord').click(function() {
127
        state_dialog('update-state', 'Réaccueil', 'ACCUEIL');
128
    });
129
    $('#diagnostic-patientrecord').click(function() {
130
        state_dialog('update-state', 'Diagnostic', 'DIAGNOSTIC');
131
    });
132
    $('#traitement-patientrecord').click(function() {
133
        state_dialog('update-state', 'Traitement', 'TRAITEMENT');
134
    });
135
    $('#finaccueil-patientrecord').click(function() {
136
        state_dialog('update-state', "Fin d'accueil", 'FIN_ACCUEIL');
137
    });
138
    $('#bilan-patientrecord').click(function() {
139
        state_dialog('update-state', 'Bilan', 'BILAN');
140
    });
141
    $('#surveillance-patientrecord').click(function() {
142
        state_dialog('update-state', 'Surveillance', 'SURVEILLANCE');
143
    });
144
    $('#suivi-patientrecord').click(function() {
145
        state_dialog('update-state', 'Suivi', 'SUIVI');
146
    });
147
    $('#patientrecord-history').click(function() {
148
      $('#dossier-histo-dlg').dialog({title: 'Historique dossier',
149
        width: '500px',
150
        buttons: [ { text: "Fermer",
151
          click: function() { $(this).dialog("close"); } }]}
152
        );
153
    });
154
    if (location.hash.indexOf('histo') != -1) {
155
      $('#patientrecord-history').click();
156
      location.hash = '';
157
    }
158
    $('.autosubmit').click(function() {
159
        $('#general-form').submit();
160
    });
161
}
162

    
163
function load_tab2_adm() {
164
}
165

    
166
function load_tab3_addresses() {
167
    function nir_check(that) {
168
      add_datepickers($(that));
169
      $(that).find('#social-security-id input').keyup(function() {
170
        if ($(this).val().length < 13) {
171
             $('p#nir-key span').removeAttr('id')
172
             $('p#nir-key span').text('-');
173
         } else {
174
             $('p#nir-key span').attr('id', 'highlight')
175
             var nir = $(this).val();
176
             var minus = 0;
177
             if (nir.charAt(6) == 'A'){
178
               nir = nir.replace('A', '0');
179
               minus = 1000000;
180
             }
181
             if (nir.charAt(6) == 'B'){
182
               nir = nir.replace('B', '0');
183
               minus = 2000000;
184
             }
185
             nir = parseInt(nir, 10);
186
             nir = nir - minus;
187
             var key = 97 - (nir % 97);
188
             if (isNaN(key)) {
189
                 $('p#nir-key span').text('NIR invalide');
190
             } else {
191
                 $('p#nir-key span').text(key);
192
             }
193
         }
194
      });
195
    }
196
    $('.policyholder-radio').click(function() {
197
        $("#policyholder-form").submit();
198
    });
199
    $('#new-contact-btn').click(function() {
200
        generic_ajaxform_dialog('contact/new', 'Ajouter un contact',
201
            '#ajax-dlg', '900px', 'Ajouter', null, nir_check, 850);
202
    });
203
    $('.update-contact-btn').click(function() {
204
        generic_ajaxform_dialog('contact/' + $(this).data('id') + '/update', 'Modifier un contact',
205
            '#ajax-dlg', '800px', 'Modifier', null, nir_check, null, null, true);
206
    });
207
    $('.del-contact').click(function() {
208
        generic_ajaxform_dialog('contact/' + $(this).data('id') + '/del?address=' + $(this).data('address-id'),
209
                'Supprimer un contact', '#ajax-dlg', '500px', 'Supprimer');
210
    });
211
    $('#new-address-btn').click(function() {
212
        generic_ajaxform_dialog('address/new', 'Ajouter une adresse',
213
            '#ajax-dlg', '600px', 'Ajouter');
214
    });
215
    $('.update-address-btn').click(function() {
216
        generic_ajaxform_dialog('address/' + $(this).data('id') + '/update', 'Modifier une adresse',
217
            '#ajax-dlg', '600px', 'Modifier', null, null, null, null, true);
218
    });
219
    $('.del-address').click(function() {
220
        generic_ajaxform_dialog('address/' + $(this).data('id') + '/del', 'Supprimer une addresse',
221
            '#ajax-dlg', '500px', 'Supprimer');
222
    });
223

    
224

    
225
      $('.place_of_life').click(function() {
226
          if ((this.checked) == true) {
227
              var value = "true";
228
          } else {
229
              var value = "false";
230
          }
231
          var prev = $(this).prev();
232
          $.ajax({
233
              url: '/api/v1/patientaddress/' + $(this).data("id") + '/?format=json',
234
              type: 'PATCH',
235
              async: false,
236
              contentType: 'application/json',
237
              data: '{"place_of_life": ' + value + '}',
238
              success: function(data) {
239
                (prev).show();
240
                (prev).html('<li>Modification appliquée avec succés</li>');
241
                $('.ajax_messages').delay(1500).fadeOut('slow');
242
                location.reload();
243
              }
244
          });
245
      });
246
    var hashes = location.hash.split('&');
247
    for (i in hashes) {
248
      if (hashes[i] == "newcontact") {
249
        var form = $.cookie('contactform');
250
        generic_ajaxform_dialog('contact/new?'+ form, 'Ajouter un contact',
251
            '#ajax-dlg', '900px', 'Ajouter', null, nir_check, 850);
252
        $.removeCookie('contactform', { path: window.location.pathname });
253
      }
254
    }
255
    location.hash = hashes[0];
256
}
257

    
258
function load_tab4_notifs() {
259
    $('#new-hctrait-btn').click(function() {
260
        generic_ajaxform_dialog('healthcare_treatment/new', 'Ajouter une prise en charge de traitement',
261
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
262
    });
263
    $('#new-hcdiag-btn').click(function() {
264
        generic_ajaxform_dialog('healthcare_diagnostic/new', 'Ajouter une prise en charge de diagnostic',
265
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
266
    });
267
    $('#new-notification-btn').click(function() {
268
        generic_ajaxform_dialog('healthcare_notification/new', 'Ajouter une notification',
269
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
270
    });
271
    $('.update-hctrait-btn').click(function() {
272
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/update', 'Modifier une prise en charge de traitement',
273
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
274
    });
275
    $('.update-hcdiag-btn').click(function() {
276
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/update', 'Modifier une prise en charge de diagnostic',
277
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
278
    });
279
    $('.update-notification-btn').click(function() {
280
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/update', 'Modifier une notification',
281
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
282
    });
283
    $('.del-hctrait').click(function() {
284
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de traitement',
285
            '#ajax-dlg', '500px', 'Supprimer');
286
    });
287
    $('.del-hcdiag').click(function() {
288
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de diagnostic',
289
            '#ajax-dlg', '500px', 'Supprimer');
290
    });
291
    $('.del-notification').click(function() {
292
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/del', 'Supprimer une notification',
293
            '#ajax-dlg', '500px', 'Supprimer');
294
    });
295

    
296
}
297

    
298
function load_tab5_last_acts() {
299
}
300

    
301
function load_tab6_next_rdv() {
302
}
303

    
304
function load_tab7_socialisation() {
305
    $('#new-socialisation-duration-btn').on("click", function() {
306
        generic_ajaxform_dialog('socialisation/new', 'Ajouter une période de socialisation',
307
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
308
    });
309
    $('.update-duration-btn').click(function() {
310
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/update', 'Modifier une période de socialisation',
311
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
312
    });
313
    $('.del-duration').click(function() {
314
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/del', 'Supprimer une période de socialisation',
315
            '#ajax-dlg', '500px', 'Supprimer');
316
    });
317
    $('#new-mdph-request-btn').click(function() {
318
        generic_ajaxform_dialog('mdph_request/new', 'Ajouter une demande MDPH',
319
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
320
    });
321
    $('.update-mdph-request-btn').click(function() {
322
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/update', 'Modifier une demande MDPH',
323
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
324
    });
325
    $('.del-mdph-request').click(function() {
326
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/del', 'Supprimer une demande MDPH',
327
            '#ajax-dlg', '500px', 'Supprimer');
328
    });
329
    $('#new-mdph-response-btn').click(function() {
330
        generic_ajaxform_dialog('mdph_response/new', 'Ajouter une réponse MDPH',
331
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
332
    });
333
    $('.update-mdph-response-btn').click(function() {
334
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/update', 'Modifier une réponse MDPH',
335
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
336
    });
337
    $('.del-mdph-response').click(function() {
338
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/del', 'Supprimer une réponse MDPH',
339
            '#ajax-dlg', '500px', 'Supprimer');
340
    });
341
}
342

    
343
function load_tab8_medical() {
344
  calebasse_ajax_form('#tabs-8');
345
  warning_on_unsave_change();
346
}
347

    
348

    
349
(function($) {
350
  $(function() {
351
    var $tabs = $('#tabs').tabs({
352
      load: function(event, ui) {
353
        $('.js-click-to-expand').on('click', function (event) {
354
             $(event.target).parents('.js-expandable').toggleClass('js-expanded');
355
             $(event.target).next().toggle();
356
        });
357
        var tabid = $(ui.tab).attr('id');
358
        if (tabid == "ui-id-1")
359
            load_tab1_general();
360
        else if (tabid == "ui-id-2")
361
            load_tab2_adm();
362
        else if (tabid == "ui-id-3")
363
            load_tab3_addresses();
364
        else if (tabid == "ui-id-4")
365
            load_tab4_notifs();
366
        else if (tabid == "ui-id-7")
367
            load_tab7_socialisation();
368
        else if (tabid == "ui-id-8")
369
            load_tab8_medical();
370
      },
371
        selected: -1,
372
        collapsible: true,
373
    });
374

    
375

    
376
    $('#tabs').on("tabsload", function(event, ui) {
377
        location.hash = 'tab=' + $(ui.tab).data('id');
378
    });
379

    
380
    $('#btn_all_state').click(function() {
381
      $('.checkbox_state').attr('checked', true);
382
    });
383
    $('#btn_none_state').click(function() {
384
      $('.checkbox_state').attr('checked', false);
385
    });
386
    $('.checkbox_state').click(function() {
387
        $("#search").click();
388
    });
389

    
390
    $('.pr-line').click(function() {
391
        window.open($(this).data('link'), $(this).data('link'));
392
    });
393
    $('button#reset').click(function() {
394
        window.location.href = window.location.pathname;
395
        return false;
396
    });
397
    $('#print-button').click(function() {
398
        var button = $(this);
399
        var title = button.html();
400
        button.html('Préparation de l\'impression en cours');
401
        button.attr({disabled: 'disabled'});
402
        button.toggleClass('icon-wip');
403
        $('.pagination').next().remove();
404
        $.get(window.location + '&all', function(data) {
405
            button.toggleClass('icon-wip');
406
            button.removeAttr('disabled');
407
            button.html(title);
408
            $('.content').append(data);
409
            window.print();
410
        });
411
    });
412

    
413
    $('#patientrecord-print-button').on('click', function(event) {
414
        event.preventDefault();
415
        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
416
                                '#ajax-dlg', '450px', 'Imprimer', false, false);
417
    });
418

    
419
    $('#new-patientrecord').click(function() {
420
        generic_ajaxform_dialog('new', 'Nouveau dossier',
421
            '#dossier-dlg', '700px', 'Ajouter', false, function(that) {
422
                    $('input#id_date_selected', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
423
                    $(that).find('#id_last_name').keyup(function() {
424
                            var val = $(this).val();
425
                            if (val.length < 3) {
426
                               $(that).find('#last_name_matches').empty();
427
                               return;
428
                            }
429
                            $.ajax({
430
                               url: "/lookups/ajax_lookup/patientrecord?term=" + val,
431
                               success: function(json) {
432
                                  var list = $(that).find('#last_name_matches');
433
                                  list.empty();
434
                                  $(eval(json)).each(function(a, b) {
435
                                          list.append($('<li><a href="' + b.pk + '/view" target="new">' + b.value + '</a></li>'));
436
                                  });
437
                               }
438
                            });
439
                    });
440
            });
441
    });
442
    $('#patientrecord-delete').click(function() {
443
        generic_ajaxform_dialog('delete', 'Supprimer le dossier',
444
            '#ajax-dlg', '500px', 'Oui', '..');
445
    });
446

    
447

    
448
    $('.update-patient-state-btn').click(function() {
449
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/update', 'Modifier un état',
450
            '#ajax-dlg', '500px', 'Modifier', '#histo', add_datepickers);
451
    });
452
    $('.del-patient-state-btn').click(function() {
453
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/del', 'Supprimer un état',
454
            '#ajax-dlg', '500px', 'Supprimer', '#histo');
455
    });
456

    
457
    $('button.blind').next().hide();
458
    $('button.blind').click(function() {
459
      $(this).next().toggle('blind');
460
    });
461
    var tabid = $.url($(location).attr('href')).fparam('tab');
462
      if (tabid) {
463
        $tabs.tabs('select',  parseInt(tabid));
464
      }
465
      else {
466
        $tabs.tabs('select',  0);
467
      }
468
    });
469

    
470
})(window.jQuery)
471

    
(7-7/22)