Projet

Général

Profil

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

calebasse / calebasse / static / js / calebasse.dossiers.js @ b057fff0

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, container, 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 + ' ' + container), function(element) {
29
        var block = $(this);
30
        block.addClass('screen-only');
31
        if ($(selector, $(this)).length) {
32
            $.each($(selector, this), function() {
33
                var current = $.datepicker.parseDate('d/m/yy', $(this).text());
34
                if (current < from || (to && current >= to)) {
35
                    $(this).parent().parent().addClass('screen-only');
36
                } else {
37
                    block.removeClass('screen-only');
38
                    $(this).parent().parent().removeClass('screen-only');
39
                }
40
            });
41
        }
42
    })
43
};
44

    
45
function load_add_address_dialog() {
46
  var str = $("#contactform").serialize();
47
  $.cookie('contactform', str, { path: window.location.pathname });
48
  generic_ajaxform_dialog('address/new', 'Ajouter une adresse',
49
      '#address-dlg', '600px', 'Ajouter');
50
}
51

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

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

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

    
170
function load_tab2_adm() {
171
}
172

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

    
231

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

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

    
303
}
304

    
305
function load_tab5_last_acts() {
306
}
307

    
308
function load_tab6_next_rdv() {
309
}
310

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

    
350
function load_tab8_medical() {
351
  calebasse_ajax_form('#tabs-8');
352
  warning_on_unsave_change();
353
}
354

    
355

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

    
382

    
383
    $('#tabs').on("tabsload", function(event, ui) {
384
        location.hash = 'tab=' + $(ui.tab).data('id');
385
    });
386

    
387
    $('#btn_all_state').click(function() {
388
      $('.checkbox_state').attr('checked', true);
389
    });
390
    $('#btn_none_state').click(function() {
391
      $('.checkbox_state').attr('checked', false);
392
    });
393
    $('.checkbox_state').click(function() {
394
        $("#search").click();
395
    });
396

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

    
420
    $('#patientrecord-print-button').on('click', function(event) {
421
        event.preventDefault();
422
        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
423
                                '#ajax-dlg', '450px', 'Imprimer', false, false);
424
    });
425

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

    
454

    
455
    $('.update-patient-state-btn').click(function() {
456
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/update', 'Modifier un état',
457
            '#ajax-dlg', '500px', 'Modifier', '#histo', add_datepickers);
458
    });
459
    $('.del-patient-state-btn').click(function() {
460
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/del', 'Supprimer un état',
461
            '#ajax-dlg', '500px', 'Supprimer', '#histo');
462
    });
463

    
464
    $('button.blind').next().hide();
465
    $('button.blind').click(function() {
466
      $(this).next().toggle('blind');
467
    });
468
    var tabid = $.url($(location).attr('href')).fparam('tab');
469
      if (tabid) {
470
        $tabs.tabs('select',  parseInt(tabid));
471
      }
472
      else {
473
        $tabs.tabs('select',  0);
474
      }
475
    });
476

    
477
})(window.jQuery)
478

    
(7-7/22)