Projet

Général

Profil

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

calebasse / calebasse / static / js / calebasse.dossiers.js @ fce3e1e6

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).data('start-date'));
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').on('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
    $('.autosubmit').on('click', function() {
204
        $('.autosubmit-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
    $('#read-cv2').click(function() {
231
        generic_ajaxform_dialog('read-cv2', 'Lecture de la Carte Vitale',
232
            '#ajax-dlg', '600px', 'Ok');
233
    });
234

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

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

    
306
}
307

    
308
function load_tab5_last_acts() {
309
}
310

    
311
function load_tab6_next_rdv() {
312
}
313

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

    
353
function load_tab8_medical() {
354
  calebasse_ajax_form('#tabs-8');
355
  warning_on_unsave_change();
356
}
357

    
358

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

    
385

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

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

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

    
427
    $('#patientrecord-print-button').on('click', function(event) {
428
        event.preventDefault();
429
        generic_ajaxform_dialog($(this).attr('href'), 'Impression dossier patient',
430
                                '#ajax-dlg', '450px', 'Imprimer', false, false);
431
    });
432

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

    
461

    
462
    $('.update-patient-state-btn').click(function() {
463
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/update', 'Modifier un état',
464
            '#ajax-dlg', '500px', 'Modifier', '#histo', add_datepickers);
465
    });
466
    $('.del-patient-state-btn').click(function() {
467
        generic_ajaxform_dialog('state/' + $(this).data('id') + '/del', 'Supprimer un état',
468
            '#ajax-dlg', '500px', 'Supprimer', '#histo');
469
    });
470

    
471
    $('button.blind').next().hide();
472
    $('button.blind').click(function() {
473
      $(this).next().toggle('blind');
474
    });
475
    var tabid = $.url($(location).attr('href')).fparam('tab');
476
      if (tabid) {
477
        $tabs.tabs('select',  parseInt(tabid));
478
      }
479
      else {
480
        $tabs.tabs('select',  0);
481
      }
482
    });
483

    
484
})(window.jQuery)
(8-8/23)