Revert "statistics : one unique form and view for all stats, fisrt stat implementation."
This reverts commit ebd4ae0748
.
Unexpected commit in master.
This commit is contained in:
parent
c082b14ee1
commit
c98ba2cc05
|
@ -1,35 +0,0 @@
|
|||
(function($) {
|
||||
$(function() {
|
||||
$('.stats').click(function() {
|
||||
var url = 'form/' + this.id;
|
||||
generic_ajaxform_dialog(url, 'Choix des parametres',
|
||||
'#stat-form', '700px', 'Extraire', false,
|
||||
function (dialog) {
|
||||
var deck = $('#id_participants_on_deck');
|
||||
$(deck).bind('added', function() {
|
||||
var added = $(deck).find('div:last');
|
||||
var t = added.attr('id').indexOf('_group:');
|
||||
if ( t == -1) return;
|
||||
var query = added.attr('id').substr(t+1);
|
||||
|
||||
/* remove group element and fake id */
|
||||
added.remove();
|
||||
var val = $('#id_participants').val();
|
||||
$('#id_participants').val(val.substr(0, val.substr(0, val.length-1).lastIndexOf('|')+1));
|
||||
|
||||
/* add all workers */
|
||||
var receive_result = $('#id_participants_text').autocomplete('option', 'select');
|
||||
$.getJSON($('#id_participants_text').autocomplete('option', 'source') + '?term=' + query,
|
||||
function(data) {
|
||||
$.each(data, function(key, val) {
|
||||
if (key==0) return; /* ignore first element as it's the group itself */
|
||||
var ui = Object();
|
||||
ui.item = val;
|
||||
receive_result(null, ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})(window.jQuery)
|
|
@ -1,14 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django import forms
|
||||
from django.forms import ModelForm, Form
|
||||
|
||||
from ajax_select import make_ajax_field
|
||||
|
||||
from statistics import Statistic
|
||||
|
||||
|
||||
class StatForm(Form):
|
||||
start_date = forms.DateField(label=u'Date de début', required=False, localize=True)
|
||||
end_date = forms.DateField(label=u'Date de fin', required=False, localize=True)
|
||||
patients = make_ajax_field(Statistic, 'patients', 'patientrecord', True)
|
||||
participants = make_ajax_field(Statistic, 'participants', 'worker-or-group', True)
|
|
@ -1,102 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
|
||||
from django.db import models
|
||||
|
||||
from calebasse.dossiers.models import PatientRecord
|
||||
from calebasse.personnes.models import Worker
|
||||
from calebasse.actes.models import Act
|
||||
|
||||
|
||||
STATISTICS = {
|
||||
'patients_per_worker_for_period_per_service' :
|
||||
{
|
||||
'display_name': 'Liste des enfants suivis par intervenant sur une '
|
||||
'période pour un service',
|
||||
'category': 'Suivi'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def patients_per_worker_for_period_per_service(statistic):
|
||||
if not (statistic.in_start_date and statistic.in_end_date
|
||||
and statistic.in_service):
|
||||
return None
|
||||
data = []
|
||||
data.append(['Intervenants', 'Patients'])
|
||||
values = []
|
||||
# Get all acts in the period with a patient in the service
|
||||
# Make a dic with intervene for keys
|
||||
acts = None
|
||||
if statistic.in_patients:
|
||||
acts = Act.objects.filter(date__gte=statistic.in_start_date,
|
||||
date__lte=statistic.in_end_date,
|
||||
patient__service=statistic.in_service,
|
||||
patient__in=statistic.in_patients)
|
||||
else:
|
||||
acts = Act.objects.filter(date__gte=statistic.in_start_date,
|
||||
date__lte=statistic.in_end_date,
|
||||
patient__service=statistic.in_service)
|
||||
analyse = dict()
|
||||
for act in acts:
|
||||
for intervene in act.doctors.all():
|
||||
if statistic.in_participants:
|
||||
if intervene in statistic.in_participants:
|
||||
analyse.setdefault(intervene, []).append(act.patient)
|
||||
else:
|
||||
analyse.setdefault(intervene, []).append(act.patient)
|
||||
o_analyse = OrderedDict(sorted(analyse.items(), key=lambda t: t[0]))
|
||||
for intervene, patients in o_analyse.iteritems():
|
||||
values.append([intervene, list(set(patients))])
|
||||
data.append(values)
|
||||
return data
|
||||
|
||||
|
||||
class Statistic(models.Model):
|
||||
patients = models.ManyToManyField('dossiers.PatientRecord',
|
||||
null=True, blank=True, default=None)
|
||||
participants = models.ManyToManyField('personnes.People',
|
||||
null=True, blank=True, default=None)
|
||||
|
||||
def __init__(self, name=None, inputs=dict()):
|
||||
self.name = name
|
||||
params = STATISTICS.get(name, {})
|
||||
self.display_name = params['display_name']
|
||||
self.category = params['category']
|
||||
self.inputs = inputs
|
||||
self.in_participants = list()
|
||||
participants = inputs.get('participants')
|
||||
if participants:
|
||||
p_str_ids = [p for p in participants.split('|') if p]
|
||||
for str_id in p_str_ids:
|
||||
try:
|
||||
self.in_participants.append(Worker.objects.get(pk=int(str_id)))
|
||||
except:
|
||||
pass
|
||||
self.in_patients = list()
|
||||
patients = inputs.get('patients')
|
||||
if patients:
|
||||
p_str_ids = [p for p in patients.split('|') if p]
|
||||
for str_id in p_str_ids:
|
||||
try:
|
||||
self.in_patients.append(PatientRecord.objects.get(pk=int(str_id)))
|
||||
except:
|
||||
pass
|
||||
self.in_service = inputs.get('service')
|
||||
self.in_start_date = None
|
||||
try:
|
||||
self.in_start_date = datetime.strptime(inputs.get('start_date'),
|
||||
"%d/%m/%Y")
|
||||
except:
|
||||
pass
|
||||
self.in_end_date = None
|
||||
try:
|
||||
self.in_end_date = datetime.strptime(inputs.get('end_date'),
|
||||
"%d/%m/%Y")
|
||||
except:
|
||||
pass
|
||||
|
||||
def get_data(self):
|
||||
func = globals()[self.name]
|
||||
return func(self)
|
|
@ -1,7 +1,3 @@
|
|||
{% extends "calebasse/base.html" %}
|
||||
|
||||
{% block extrascripts %}
|
||||
<script src="{{ STATIC_URL }}js/calebasse.statistics.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}{{ block.super }} - Statistiques {% endblock %}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
{% extends "ressources/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
{{ block.super }}
|
||||
<span>Statistiques - {{ service_name }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>Statistique {{ dn }}</h2>
|
||||
<a href="../..">Retourner aux statistiques</a>
|
||||
<span id="ajax-redirect" data-url="{{ url }}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if data %}
|
||||
<table class="basic">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for col in data.0 %}
|
||||
<th>{{ col }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for values in data.1 %}
|
||||
<tr>
|
||||
{% for value in values %}
|
||||
{% if value.id %}
|
||||
<td>{{ value }}</td>
|
||||
{% else %}
|
||||
<td>
|
||||
<ul>
|
||||
{% for val in value %}
|
||||
<li>{{ val }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,10 +0,0 @@
|
|||
{% load widget_tweaks %}
|
||||
|
||||
<form action="{{ request.get_full_path }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<script type="text/javascript">
|
||||
$('#id_start_date').datepicker({showOn: 'button'});
|
||||
$('#id_end_date').datepicker({showOn: 'button'});
|
||||
</script>
|
||||
</form>
|
|
@ -1,5 +1,4 @@
|
|||
{% extends "statistics/base.html" %}
|
||||
{% load url from future %}
|
||||
{% extends "ressources/base.html" %}
|
||||
|
||||
{% block header %}
|
||||
{{ block.super }}
|
||||
|
@ -13,16 +12,8 @@
|
|||
|
||||
{% block content %}
|
||||
<ul>
|
||||
{% for category, stats in statistics.iteritems %}
|
||||
<h3>{{ category }}</h3>
|
||||
{% for n, dn in stats %}
|
||||
<button id="{{ n }}" class="stats">{{ dn }}</button>
|
||||
{% endfor %}
|
||||
{% for statistic in statistics %}
|
||||
<li><a href="{{ statistic }}">{{ statistic }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
{% block dialogs %}
|
||||
<div id="stat-form" style="display: none;">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
|
||||
from views import StatisticsHomepageView, StatisticsFormView, StatisticsDetailView
|
||||
from views import StatisticsHomepageView
|
||||
|
||||
statistics_patterns = patterns('calebasse.statistics.views', )
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^(?P<model_name>[a-z-]*)/', include(statistics_patterns)),
|
||||
url(r'^$', StatisticsHomepageView.as_view()),
|
||||
url(r'^detail/(?P<name>\w{1,50})/$', view=StatisticsDetailView.as_view()),
|
||||
url(r'^form/(?P<name>\w{1,50})/$', view=StatisticsFormView.as_view()),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,52 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import urllib
|
||||
|
||||
from calebasse.cbv import TemplateView, FormView
|
||||
from calebasse.statistics import forms
|
||||
|
||||
from statistics import STATISTICS, Statistic
|
||||
|
||||
from calebasse.cbv import TemplateView
|
||||
|
||||
class StatisticsHomepageView(TemplateView):
|
||||
|
||||
template_name = 'statistics/index.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(StatisticsHomepageView, self).get_context_data(**kwargs)
|
||||
statistics = dict()
|
||||
for name, statistic in STATISTICS.iteritems():
|
||||
statistics.setdefault(statistic['category'], []).append((name,
|
||||
statistic['display_name']))
|
||||
context['statistics'] = statistics
|
||||
context['statistics'] = list()
|
||||
return context
|
||||
|
||||
|
||||
class StatisticsDetailView(TemplateView):
|
||||
template_name = 'statistics/detail.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(StatisticsDetailView, self).get_context_data(**kwargs)
|
||||
name = kwargs.get('name')
|
||||
inputs = dict()
|
||||
inputs['service'] = self.service
|
||||
inputs['start_date'] = self.request.GET.get('start_date')
|
||||
inputs['end_date'] = self.request.GET.get('end_date')
|
||||
inputs['participants'] = self.request.GET.get('participants')
|
||||
inputs['patients'] = self.request.GET.get('patients')
|
||||
statistic = Statistic(name, inputs)
|
||||
target = 'detail/%s?%s' % (self.kwargs.get('name'),
|
||||
self.request.META['QUERY_STRING'])
|
||||
context['url'] = target
|
||||
context['dn'] = statistic.display_name
|
||||
context['data'] = statistic.get_data()
|
||||
return context
|
||||
|
||||
|
||||
class StatisticsFormView(FormView):
|
||||
form_class = forms.StatForm
|
||||
template_name = 'statistics/form.html'
|
||||
success_url = '..'
|
||||
|
||||
def get_success_url(self):
|
||||
qs = urllib.urlencode(self.request.POST)
|
||||
target = '../../detail/%s?%s' % (self.kwargs.get('name'), qs)
|
||||
return target
|
||||
|
|
Reference in New Issue