Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def trunc_5_minutes(data) -> str:
- return (data + timedelta(minutes=5)).strftime('%H:%M')
- def is_bad_hr(data, critical_value_hr_max, critical_value_hr_min) -> bool:
- print(data, critical_value_hr_min,critical_value_hr_max, data > critical_value_hr_max or data < critical_value_hr_min)
- if data > critical_value_hr_max or data < critical_value_hr_min:
- return True
- else:
- return False
- def is_bad_bo(data, critical_value_bo_min) -> bool:
- print(data, critical_value_bo_min,data < critical_value_bo_min)
- if data < critical_value_bo_min:
- return True
- else:
- return False
- def attach_for_polyclinic_as_critical_value(request, id_polyclinic):
- context = {}
- attach_list_with_critical_parametrs =
- Attachment.objects.prefetch_related('pacient','pacient__pacient_hr','pacient__pacient_bo').filter(
- polyclinic = id_polyclinic,
- confirmation_pacient = True,
- confirmation_polyclynic = True
- )
- d = {}
- result_list=[]
- for i in attach_list_with_critical_parametrs:
- for b in i.pacient.pacient_hr.filter(datetime__date = datetime.today().date()):
- trunced_date = trunc_5_minutes(b.datetime)
- if trunced_date not in d:
- d[trunced_date] = {'hr': [b.HR], 'bo': []}
- else:
- d[trunced_date]['hr'].append(b.HR)
- for b in i.pacient.pacient_bo.filter(datetime__date = datetime.today().date()):
- trunced_date = trunc_5_minutes(b.datetime)
- if trunced_date not in d:
- d[trunced_date] = {'bo': [b.BO], 'hr': []}
- else:
- d[trunced_date]['bo'].append(b.BO)
- for key, values in d.items():
- if any(is_bad_hr(x, i.critical_value.pulse_max, i.critical_value.pulse_min) for x in values['hr']) or any(is_bad_bo(x,i.critical_value.bo_min) for x in values['bo']):
- result_list.append({'date': key, 'patient': i.pacient, 'hr_list': values['hr'], 'bo_list': values['bo']})
- for i in result_list:
- print(i['patient'], '( ' + str(i['hr_list']) + ': HR)', '( ' + str(i['bo_list']) + ': BO)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement