Projet

Général

Profil

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

calebasse / calebasse / static / js / calebasse.dossiers.js @ 54318d2c

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 state_dialog(url, state_title, state_type) {
47
    $('#change-record').load(url,
48
            function () {
49
                var patient_id = $(this).data('id');
50
                var service_id = $(this).data('service-id');
51
                function onsuccess(response, status, xhr, form) {
52
                    var parse = $(response);
53
                    if ($('.errorlist', parse).length != 0) {
54
                        $('#change-record').html(response);
55
                        $('#change-record form').ajaxForm({
56
                            success: onsuccess,
57
                            data: { patient_id: patient_id,  state_type: state_type, service_id: service_id }
58
                        });
59
                    } else {
60
                        window.location.reload(true);
61
                    }
62
                }
63
                if (state_type == 'CLOS_RDV') {
64
                  var message = $('p.message')
65
                  message.append($('<span id="highlight">Attention ce patient a encore des rendez-vous de planifiés !</span>'));
66
                  state_type = 'CLOS';
67
                }
68
                $('input.date', this).datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
69
                $('form', this).ajaxForm({
70
                    success: onsuccess,
71
                    data: { patient_id: patient_id,  state_type: state_type, service_id: service_id }
72
                });
73
                $(this).dialog({title: "Changement - " + state_title,
74
                    width: '500px',
75
                    buttons: [ { text: "Annuler",
76
                        click: function() { $(this).dialog("close"); } },
77
                    { text: "Valider",
78
                        click: function() { $("#change-record form").submit(); } }]});
79
            });
80
}
81

    
82
function load_tab1_general() {
83
    $('#update-paper-id-btn').click(function() {
84
        generic_ajaxform_dialog('update/paper_id', 'Modifier le numéro du dossier papier',
85
            '#ajax-dlg', '500px', 'Modifier');
86
    });
87
    $('#close-patientrecord').click(function() {
88
        state_dialog('update-state', 'Clore', 'CLOS');
89
    });
90
    $('#close-rdv-patientrecord').click(function() {
91
        state_dialog('update-state', 'Clore', 'CLOS_RDV');
92
    });
93
    $('#reopen-patientrecord').click(function() {
94
        state_dialog('update-state', 'Réaccueil', 'ACCUEIL');
95
    });
96
    $('#diagnostic-patientrecord').click(function() {
97
        state_dialog('update-state', 'Diagnostic', 'DIAGNOSTIC');
98
    });
99
    $('#traitement-patientrecord').click(function() {
100
        state_dialog('update-state', 'Traitement', 'TRAITEMENT');
101
    });
102
    $('#finaccueil-patientrecord').click(function() {
103
        state_dialog('update-state', "Fin d'accueil", 'FIN_ACCUEIL');
104
    });
105
    $('#bilan-patientrecord').click(function() {
106
        state_dialog('update-state', 'Bilan', 'BILAN');
107
    });
108
    $('#surveillance-patientrecord').click(function() {
109
        state_dialog('update-state', 'Surveillance', 'SURVEILLANCE');
110
    });
111
    $('#suivi-patientrecord').click(function() {
112
        state_dialog('update-state', 'Suivi', 'SUIVI');
113
    });
114
    $('#patientrecord-history').click(function() {
115
      $('#dossier-histo-dlg').dialog({title: 'Historique dossier',
116
        width: '500px',
117
        buttons: [ { text: "Fermer",
118
          click: function() { $(this).dialog("close"); } }]}
119
        );
120
    });
121
    if (location.hash.indexOf('histo') != -1) {
122
      $('#patientrecord-history').click();
123
      location.hash = '';
124
    }
125
    $('#id_pause').click(function() {
126
        $('#general-form').submit();
127
    });
128
    $('#id_confidential').click(function() {
129
        $('#general-form').submit();
130
    });
131
}
132

    
133
function load_tab2_adm() {
134
    init_magic_dialog();
135
    $('#prescription-transport-btn').click(function() {
136
        $('#ajax-dlg').load('prescription-transport',
137
          function () {
138
             $(this).dialog({title: 'Prescription de transport', width: '800px',
139
                      buttons: [ { text: "Fermer",
140
                          click: function() { $(this).dialog("close"); } },
141
                      { text: "Prescrire",
142
                          click: function() { $("#ajax-dlg form").submit(); $(this).dialog("close"); } }]});
143
             $('.addresses input[type=radio]').first().click();
144
         });
145
         return false;
146
    });
147
    $('#new-protection-btn').click(function() {
148
        generic_ajaxform_dialog('protection/new', 'Ajouter une mesure de protection',
149
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
150
    });
151
    $('.update-protection-btn').click(function() {
152
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/update', 'Modifier une mesure de protection',
153
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
154
    });
155
    $('.del-protection').click(function() {
156
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/del', 'Supprimer une mesure de protection',
157
            '#ajax-dlg', '500px', 'Supprimer');
158
    });
159
    $('input#id_id-birthdate').datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
160
    calebasse_ajax_form('#tabs-2');
161
}
162

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

    
221

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

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

    
305
}
306

    
307
function load_tab5_last_acts() {
308
}
309

    
310
function load_tab6_next_rdv() {
311
}
312

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

    
352
function load_tab8_medical() {
353
  calebasse_ajax_form('#tabs-8');
354
  SelectFilter.init("id_mises_1", "Catégorie", 0, "/static/admin/");
355
  SelectFilter.init("id_mises_2", "Catégorie", 0, "/static/admin/");
356
  SelectFilter.init("id_mises_3", "Catégorie", 0, "/static/admin/");
357
}
358

    
359

    
360
(function($) {
361
  $(function() {
362
    var $tabs = $('#tabs').tabs({
363
      load: function(event, ui) {
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
    $('.atabs').click(function() {
384
        location.hash = 'tab=' + $(this).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)