def post(self, request): ids = get_patient_ids(request.POST) action = request.POST.get('action') if action in ('', None): return HttpResponseRedirect(reverse('patient_list')) if len(ids) == 0: messages.error(request, _(u'Por favor seleccione uno o varios pacientes')) return HttpResponseRedirect(reverse('patient_list')) patients = Patient.objects.filter(id__in=ids) try: template = self.TEMPLATES[action] except KeyError: messages.error(request, _(u'Por favor escoja una opción válida')) return HttpResponseRedirect(reverse('patient_list')) data = {'patients': patients} return HttpResponse(render(request, template, data))
def get(self, request): ids = get_patient_ids(request.GET) patients = Patient.objects.filter(id__in=ids) stat_type = request.GET.get('stat_type', self.MEDIA) indicator = request.GET.get('indicator', self.ORIGINAL) interval_start = request.GET.get('interval_start') interval_end = request.GET.get('interval_end') time_offset = int(request.GET.get('utc_offset', 0)) segment_size = TIME_MULTIPLIER[request.POST.get( 'segment_unit', 'minutes')]\ * int(request.POST.get('segment_size', 1)) title = None if interval_start is None or interval_end is None: return HttpResponse(status=400) if stat_type not in self.STAT_TYPES: return HttpResponse(status=400) colors = {} plot.plt.clf() for patient in patients: channel = patient.get_last_channel() colors[patient] = random.rand(3, 1) if channel is None: continue initial, ending = convert_hour_to_milli(channel, interval_start, interval_end, time_offset) if indicator == self.MEDIA: title = _('Promedio de los RR de los pacientes') plot.get_media_image(channel, None, initial, ending, segment_size, clear=False, color=colors[patient], title=title) elif indicator == self.STD_DEV: title = _(u'Desviación estándar de los RR de los pacientes') plot.get_standard_deviation_image(channel, None, initial, ending, segment_size, clear=False, color=colors[patient], title=title) elif indicator == self.PNN50: title = _(u'PNN50 de los RR de los pacientes') plot.get_PNN50_image(channel, None, initial, ending, segment_size, clear=False, color=colors[patient], title=title) elif indicator == self.RETURN: title = _(u'Mapa de retorno de los RR de los pacientes') plot.get_return_map_image(channel, None, initial, ending, segment_size, clear=False, color=colors[patient], title=title) elif indicator == self.SDSD: title = _(u'SDSD de los RR de los pacientes') plot.get_SDSD_image(channel, None, initial, ending, segment_size, clear=False, color=colors[patient], title=title) response = HttpResponse(content_type='image/png') plot.save(response) return response
def post(self, request): ids = get_patient_ids(request.POST) Patient.objects.filter(id__in=ids).update(active=True) messages.info(request, _(u'Pacientes activados éxitosamente')) return HttpResponseRedirect(reverse('patient_list'))