Projet

Général

Profil

Télécharger (20 ko) Statistiques
| Branche: | Tag: | Révision:

calebasse / calebasse / static / js / calebasse.dossiers.js @ bbf89bd4

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

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

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

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

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

    
160
function load_tab2_adm() {
161
    warning_on_unsave_change();
162
    init_magic_dialog();
163
    $('#prescription-transport-btn').click(function() {
164
        $('#ajax-dlg').load('prescription-transport',
165
          function () {
166
             $(this).dialog({title: 'Prescription de transport', width: '800px',
167
                      buttons: [ { text: "Fermer",
168
                          click: function() { $(this).dialog("close"); } },
169
                      { text: "Prescrire",
170
                          click: function() { $("#ajax-dlg form").submit(); $(this).dialog("close"); } }]});
171
             $('.addresses input[type=radio]').first().click();
172
         });
173
         return false;
174
    });
175
    $('#new-protection-btn').click(function() {
176
        generic_ajaxform_dialog('protection/new', 'Ajouter une mesure de protection',
177
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
178
    });
179
    $('.update-protection-btn').click(function() {
180
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/update', 'Modifier une mesure de protection',
181
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
182
    });
183
    $('.del-protection').click(function() {
184
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/del', 'Supprimer une mesure de protection',
185
            '#ajax-dlg', '500px', 'Supprimer');
186
    });
187
    $('input#id_id-birthdate').datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
188
    calebasse_ajax_form('#tabs-2');
189
}
190

    
191
function load_tab3_addresses() {
192
    function nir_check(that) {
193
      add_datepickers($(that));
194
      $(that).find('#social-security-id input').keyup(function() {
195
        if ($(this).val().length < 13) {
196
             $('p#nir-key span').removeAttr('id')
197
             $('p#nir-key span').text('-');
198
         } else {
199
             $('p#nir-key span').attr('id', 'highlight')
200
             var nir = $(this).val();
201
             var minus = 0;
202
             if (nir.charAt(6) == 'A'){
203
               nir = nir.replace('A', '0');
204
               minus = 1000000;
205
             }
206
             if (nir.charAt(6) == 'B'){
207
               nir = nir.replace('B', '0');
208
               minus = 2000000;
209
             }
210
             nir = parseInt(nir, 10);
211
             nir = nir - minus;
212
             var key = 97 - (nir % 97);
213
             if (isNaN(key)) {
214
                 $('p#nir-key span').text('NIR invalide');
215
             } else {
216
                 $('p#nir-key span').text(key);
217
             }
218
         }
219
      });
220
    }
221
    $('.policyholder-radio').click(function() {
222
        $("#policyholder-form").submit();
223
    });
224
    $('#new-contact-btn').click(function() {
225
        generic_ajaxform_dialog('contact/new', 'Ajouter un contact',
226
            '#ajax-dlg', '900px', 'Ajouter', null, nir_check, 850);
227
    });
228
    $('.update-contact-btn').click(function() {
229
        generic_ajaxform_dialog('contact/' + $(this).data('id') + '/update', 'Modifier un contact',
230
            '#ajax-dlg', '800px', 'Modifier', null, nir_check);
231
    });
232
    $('.del-contact').click(function() {
233
        generic_ajaxform_dialog('contact/' + $(this).data('id') + '/del?address=' + $(this).data('address-id'),
234
                'Supprimer un contact', '#ajax-dlg', '500px', 'Supprimer');
235
    });
236
    $('#new-address-btn').click(function() {
237
        generic_ajaxform_dialog('address/new', 'Ajouter une adresse',
238
            '#ajax-dlg', '600px', 'Ajouter');
239
    });
240
    $('.update-address-btn').click(function() {
241
        generic_ajaxform_dialog('address/' + $(this).data('id') + '/update', 'Modifier une adresse',
242
            '#ajax-dlg', '600px', 'Modifier');
243
    });
244
    $('.del-address').click(function() {
245
        generic_ajaxform_dialog('address/' + $(this).data('id') + '/del', 'Supprimer une addresse',
246
            '#ajax-dlg', '500px', 'Supprimer');
247
    });
248

    
249

    
250
      $('.place_of_life').click(function() {
251
          if ((this.checked) == true) {
252
              var value = "true";
253
          } else {
254
              var value = "false";
255
          }
256
          var prev = $(this).prev();
257
          $.ajax({
258
              url: '/api/v1/patientaddress/' + $(this).data("id") + '/?format=json',
259
              type: 'PATCH',
260
              async: false,
261
              contentType: 'application/json',
262
              data: '{"place_of_life": ' + value + '}',
263
              success: function(data) {
264
                (prev).show();
265
                (prev).html('<li>Modification appliquée avec succés</li>');
266
                $('.ajax_messages').delay(1500).fadeOut('slow');
267
                location.reload();
268
              }
269
          });
270
      });
271
    $('.social-security-label').click(function() {
272
      var label = $(this).html();
273
      var data = $(this).next();
274
      if (($(data).is(':hidden'))) {
275
        $(this).html(label.replace('+', '-'));
276
        $(this).css("font-weight", "bold");
277
      } else {
278
        $(this).html(label.replace('-', '+'));
279
        $(this).css("font-weight", "");
280
      }
281
      $(data).toggle();
282
    });
283
    var hashes = location.hash.split('&');
284
    for (i in hashes) {
285
      if (hashes[i] == "newcontact") {
286
        var form = $.cookie('contactform');
287
        generic_ajaxform_dialog('contact/new?'+ form, 'Ajouter un contact',
288
            '#ajax-dlg', '900px', 'Ajouter', null, nir_check, 850);
289
        $.removeCookie('contactform', { path: window.location.pathname });
290
      }
291
    }
292
    location.hash = hashes[0];
293
}
294

    
295
function load_tab4_notifs() {
296
    $('#new-hctrait-btn').click(function() {
297
        generic_ajaxform_dialog('healthcare_treatment/new', 'Ajouter une prise en charge de traitement',
298
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
299
    });
300
    $('#new-hcdiag-btn').click(function() {
301
        generic_ajaxform_dialog('healthcare_diagnostic/new', 'Ajouter une prise en charge de diagnostic',
302
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
303
    });
304
    $('#new-notification-btn').click(function() {
305
        generic_ajaxform_dialog('healthcare_notification/new', 'Ajouter une notification',
306
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
307
    });
308
    $('.update-hctrait-btn').click(function() {
309
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/update', 'Modifier une prise en charge de traitement',
310
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
311
    });
312
    $('.update-hcdiag-btn').click(function() {
313
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/update', 'Modifier une prise en charge de diagnostic',
314
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
315
    });
316
    $('.update-notification-btn').click(function() {
317
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/update', 'Modifier une notification',
318
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
319
    });
320
    $('.del-hctrait').click(function() {
321
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de traitement',
322
            '#ajax-dlg', '500px', 'Supprimer');
323
    });
324
    $('.del-hcdiag').click(function() {
325
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de diagnostic',
326
            '#ajax-dlg', '500px', 'Supprimer');
327
    });
328
    $('.del-notification').click(function() {
329
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/del', 'Supprimer une notification',
330
            '#ajax-dlg', '500px', 'Supprimer');
331
    });
332

    
333
}
334

    
335
function load_tab5_last_acts() {
336
}
337

    
338
function load_tab6_next_rdv() {
339
}
340

    
341
function load_tab7_socialisation() {
342
    $('#new-socialisation-duration-btn').click(function() {
343
        generic_ajaxform_dialog('socialisation/new', 'Ajouter une période de socialisation',
344
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
345
    });
346
    $('.update-duration-btn').click(function() {
347
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/update', 'Modifier une période de socialisation',
348
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
349
    });
350
    $('.del-duration').click(function() {
351
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/del', 'Supprimer une période de socialisation',
352
            '#ajax-dlg', '500px', 'Supprimer');
353
    });
354
    $('#new-mdph-request-btn').click(function() {
355
        generic_ajaxform_dialog('mdph_request/new', 'Ajouter une demande MDPH',
356
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
357
    });
358
    $('.update-mdph-request-btn').click(function() {
359
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/update', 'Modifier une demande MDPH',
360
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
361
    });
362
    $('.del-mdph-request').click(function() {
363
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/del', 'Supprimer une demande MDPH',
364
            '#ajax-dlg', '500px', 'Supprimer');
365
    });
366
    $('#new-mdph-response-btn').click(function() {
367
        generic_ajaxform_dialog('mdph_response/new', 'Ajouter une réponse MDPH',
368
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
369
    });
370
    $('.update-mdph-response-btn').click(function() {
371
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/update', 'Modifier une réponse MDPH',
372
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
373
    });
374
    $('.del-mdph-response').click(function() {
375
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/del', 'Supprimer une réponse MDPH',
376
            '#ajax-dlg', '500px', 'Supprimer');
377
    });
378
}
379

    
380
function load_tab8_medical() {
381
  calebasse_ajax_form('#tabs-8');
382
  warning_on_unsave_change();
383
}
384

    
385

    
386
(function($) {
387
  $(function() {
388
    var $tabs = $('#tabs').tabs({
389
      load: function(event, ui) {
390
        var tabid = $(ui.tab).attr('id');
391
        if (tabid == "ui-id-1")
392
      load_tab1_general();
393
        else if (tabid == "ui-id-2")
394
      load_tab2_adm();
395
        else if (tabid == "ui-id-3")
396
      load_tab3_addresses();
397
        else if (tabid == "ui-id-4")
398
      load_tab4_notifs();
399
        else if (tabid == "ui-id-7")
400
      load_tab7_socialisation();
401
        else if (tabid == "ui-id-8")
402
      load_tab8_medical();
403
      },
404
        selected: -1,
405
        collapsible: true,
406
    });
407

    
408

    
409
    $('#tabs').on("tabsload", function(event, ui) {
410
        location.hash = 'tab=' + $(ui.tab).data('id');
411
    });
412

    
413
    $('#btn_all_state').click(function() {
414
      $('.checkbox_state').attr('checked', true);
415
    });
416
    $('#btn_none_state').click(function() {
417
      $('.checkbox_state').attr('checked', false);
418
    });
419
    $('.checkbox_state').click(function() {
420
        $("#search").click();
421
    });
422

    
423
    $('.pr-line').click(function() {
424
        window.open($(this).data('link'), $(this).data('link'));
425
    });
426
    $('button#reset').click(function() {
427
        window.location.href = window.location.pathname;
428
        return false;
429
    });
430
    $('#print-button').click(function() {
431
        var button = $(this);
432
        var title = button.html();
433
        button.html('Préparation de l\'impression en cours');
434
        button.attr({disabled: 'disabled'});
435
        button.toggleClass('icon-wip');
436
        $('.pagination').next().remove();
437
        $.get(window.location + '&all', function(data) {
438
            button.toggleClass('icon-wip');
439
            button.removeAttr('disabled');
440
            button.html(title);
441
            $('.content').append(data);
442
            window.print();
443
        });
444
    });
445

    
446
    $('#patientrecord-print-button').on('click', function(event) {
447
        event.preventDefault();
448
        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
449
                                '#ajax-dlg', '450px', 'Imprimer', false, false);
450
    });
451

    
452
    $('#new-patientrecord').click(function() {
453
        generic_ajaxform_dialog('new', 'Nouveau dossier',
454
            '#dossier-dlg', '700px', 'Ajouter', false, function(that) {
455
                    $('input#id_date_selected', that).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
456
                    $(that).find('#id_last_name').keyup(function() {
457
                            var val = $(this).val();
458
                            if (val.length < 3) {
459
                               $(that).find('#last_name_matches').empty();
460
                               return;
461
                            }
462
                            $.ajax({
463
                               url: "/lookups/ajax_lookup/patientrecord?term=" + val,
464
                               success: function(json) {
465
                                  var list = $(that).find('#last_name_matches');
466
                                  list.empty();
467
                                  $(eval(json)).each(function(a, b) {
468
                                          list.append($('<li><a href="' + b.pk + '/view" target="new">' + b.value + '</a></li>'));
469
                                  });
470
                               }
471
                            });
472
                    });
473
            });
474
    });
475
    $('#patientrecord-delete').click(function() {
476
        generic_ajaxform_dialog('delete', 'Supprimer le dossier',
477
            '#ajax-dlg', '500px', 'Oui', '..');
478
    });
479

    
480

    
481
    $('.update-patient-state-btn').click(function() {
482
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/update', 'Modifier un état',
483
            '#ajax-dlg', '500px', 'Modifier', '#histo', add_datepickers);
484
    });
485
    $('.del-patient-state-btn').click(function() {
486
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/del', 'Supprimer un état',
487
            '#ajax-dlg', '500px', 'Supprimer', '#histo');
488
    });
489

    
490
    $('button.blind').next().hide();
491
    $('button.blind').click(function() {
492
      $(this).next().toggle('blind');
493
    });
494
    var tabid = $.url($(location).attr('href')).fparam('tab');
495
      if (tabid) {
496
        $tabs.tabs('select',  parseInt(tabid));
497
      }
498
      else {
499
        $tabs.tabs('select',  0);
500
      }
501
    });
502

    
503
})(window.jQuery)
504

    
(7-7/22)