Projet

Général

Profil

Télécharger (19,9 ko) Statistiques
| Branche: | Tag: | Révision:

calebasse / calebasse / static / js / calebasse.dossiers.js @ 0a8aab32

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, null, null, true);
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', null, null, null, null, true);
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
    var hashes = location.hash.split('&');
272
    for (i in hashes) {
273
      if (hashes[i] == "newcontact") {
274
        var form = $.cookie('contactform');
275
        generic_ajaxform_dialog('contact/new?'+ form, 'Ajouter un contact',
276
            '#ajax-dlg', '900px', 'Ajouter', null, nir_check, 850);
277
        $.removeCookie('contactform', { path: window.location.pathname });
278
      }
279
    }
280
    location.hash = hashes[0];
281
}
282

    
283
function load_tab4_notifs() {
284
    $('#new-hctrait-btn').click(function() {
285
        generic_ajaxform_dialog('healthcare_treatment/new', 'Ajouter une prise en charge de traitement',
286
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
287
    });
288
    $('#new-hcdiag-btn').click(function() {
289
        generic_ajaxform_dialog('healthcare_diagnostic/new', 'Ajouter une prise en charge de diagnostic',
290
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
291
    });
292
    $('#new-notification-btn').click(function() {
293
        generic_ajaxform_dialog('healthcare_notification/new', 'Ajouter une notification',
294
            '#ajax-dlg', '600px', 'Ajouter', null, add_datepickers);
295
    });
296
    $('.update-hctrait-btn').click(function() {
297
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/update', 'Modifier une prise en charge de traitement',
298
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
299
    });
300
    $('.update-hcdiag-btn').click(function() {
301
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/update', 'Modifier une prise en charge de diagnostic',
302
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
303
    });
304
    $('.update-notification-btn').click(function() {
305
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/update', 'Modifier une notification',
306
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
307
    });
308
    $('.del-hctrait').click(function() {
309
        generic_ajaxform_dialog('healthcare_treatment/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de traitement',
310
            '#ajax-dlg', '500px', 'Supprimer');
311
    });
312
    $('.del-hcdiag').click(function() {
313
        generic_ajaxform_dialog('healthcare_diagnostic/' + $(this).data('id') + '/del', 'Supprimer une prise en charge de diagnostic',
314
            '#ajax-dlg', '500px', 'Supprimer');
315
    });
316
    $('.del-notification').click(function() {
317
        generic_ajaxform_dialog('healthcare_notification/' + $(this).data('id') + '/del', 'Supprimer une notification',
318
            '#ajax-dlg', '500px', 'Supprimer');
319
    });
320

    
321
}
322

    
323
function load_tab5_last_acts() {
324
}
325

    
326
function load_tab6_next_rdv() {
327
}
328

    
329
function load_tab7_socialisation() {
330
    $('#new-socialisation-duration-btn').on("click", function() {
331
        generic_ajaxform_dialog('socialisation/new', 'Ajouter une période de socialisation',
332
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
333
    });
334
    $('.update-duration-btn').click(function() {
335
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/update', 'Modifier une période de socialisation',
336
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
337
    });
338
    $('.del-duration').click(function() {
339
        generic_ajaxform_dialog('socialisation/' + $(this).data('id') + '/del', 'Supprimer une période de socialisation',
340
            '#ajax-dlg', '500px', 'Supprimer');
341
    });
342
    $('#new-mdph-request-btn').click(function() {
343
        generic_ajaxform_dialog('mdph_request/new', 'Ajouter une demande MDPH',
344
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
345
    });
346
    $('.update-mdph-request-btn').click(function() {
347
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/update', 'Modifier une demande MDPH',
348
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
349
    });
350
    $('.del-mdph-request').click(function() {
351
        generic_ajaxform_dialog('mdph_request/' + $(this).data('id') + '/del', 'Supprimer une demande MDPH',
352
            '#ajax-dlg', '500px', 'Supprimer');
353
    });
354
    $('#new-mdph-response-btn').click(function() {
355
        generic_ajaxform_dialog('mdph_response/new', 'Ajouter une réponse MDPH',
356
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
357
    });
358
    $('.update-mdph-response-btn').click(function() {
359
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/update', 'Modifier une réponse MDPH',
360
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
361
    });
362
    $('.del-mdph-response').click(function() {
363
        generic_ajaxform_dialog('mdph_response/' + $(this).data('id') + '/del', 'Supprimer une réponse MDPH',
364
            '#ajax-dlg', '500px', 'Supprimer');
365
    });
366
}
367

    
368
function load_tab8_medical() {
369
  calebasse_ajax_form('#tabs-8');
370
  warning_on_unsave_change();
371
}
372

    
373

    
374
(function($) {
375
  $(function() {
376
    var $tabs = $('#tabs').tabs({
377
      load: function(event, ui) {
378
        $('.js-click-to-expand').on('click', function (event) {
379
             $(event.target).parents('.js-expandable').toggleClass('js-expanded');
380
             $(event.target).next().toggle();
381
        });
382
        var tabid = $(ui.tab).attr('id');
383
        if (tabid == "ui-id-1")
384
            load_tab1_general();
385
        else if (tabid == "ui-id-2")
386
            load_tab2_adm();
387
        else if (tabid == "ui-id-3")
388
            load_tab3_addresses();
389
        else if (tabid == "ui-id-4")
390
            load_tab4_notifs();
391
        else if (tabid == "ui-id-7")
392
            load_tab7_socialisation();
393
        else if (tabid == "ui-id-8")
394
            load_tab8_medical();
395
      },
396
        selected: -1,
397
        collapsible: true,
398
    });
399

    
400

    
401
    $('#tabs').on("tabsload", function(event, ui) {
402
        location.hash = 'tab=' + $(ui.tab).data('id');
403
    });
404

    
405
    $('#btn_all_state').click(function() {
406
      $('.checkbox_state').attr('checked', true);
407
    });
408
    $('#btn_none_state').click(function() {
409
      $('.checkbox_state').attr('checked', false);
410
    });
411
    $('.checkbox_state').click(function() {
412
        $("#search").click();
413
    });
414

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

    
438
    $('#patientrecord-print-button').on('click', function(event) {
439
        event.preventDefault();
440
        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
441
                                '#ajax-dlg', '450px', 'Imprimer', false, false);
442
    });
443

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

    
472

    
473
    $('.update-patient-state-btn').click(function() {
474
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/update', 'Modifier un état',
475
            '#ajax-dlg', '500px', 'Modifier', '#histo', add_datepickers);
476
    });
477
    $('.del-patient-state-btn').click(function() {
478
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/del', 'Supprimer un état',
479
            '#ajax-dlg', '500px', 'Supprimer', '#histo');
480
    });
481

    
482
    $('button.blind').next().hide();
483
    $('button.blind').click(function() {
484
      $(this).next().toggle('blind');
485
    });
486
    var tabid = $.url($(location).attr('href')).fparam('tab');
487
      if (tabid) {
488
        $tabs.tabs('select',  parseInt(tabid));
489
      }
490
      else {
491
        $tabs.tabs('select',  0);
492
      }
493
    });
494

    
495
})(window.jQuery)
496

    
(7-7/22)