Advertisement
Mochinov

Untitled

Jan 21st, 2021
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1.  
  2. def trunc_5_minutes(data) -> str:
  3.     return (data + timedelta(minutes=5)).strftime('%H:%M')
  4.  
  5. def is_bad_hr(data, critical_value_hr_max, critical_value_hr_min) -> bool:
  6.  
  7.     print(data, critical_value_hr_min,critical_value_hr_max, data > critical_value_hr_max or data < critical_value_hr_min)
  8.     if data > critical_value_hr_max or data < critical_value_hr_min:
  9.         return True
  10.     else:
  11.         return False
  12.  
  13. def is_bad_bo(data, critical_value_bo_min) -> bool:
  14.     print(data, critical_value_bo_min,data < critical_value_bo_min)
  15.     if data < critical_value_bo_min:
  16.         return True
  17.     else:
  18.         return False
  19.  
  20. def attach_for_polyclinic_as_critical_value(request, id_polyclinic):
  21.     context = {}
  22.     attach_list_with_critical_parametrs =
  23. Attachment.objects.prefetch_related('pacient','pacient__pacient_hr','pacient__pacient_bo').filter(
  24.         polyclinic = id_polyclinic,
  25.         confirmation_pacient = True,
  26.         confirmation_polyclynic = True
  27.     )
  28.  
  29.     d = {}
  30.     result_list=[]
  31.     for i in attach_list_with_critical_parametrs:
  32.         for b in i.pacient.pacient_hr.filter(datetime__date = datetime.today().date()):
  33.             trunced_date = trunc_5_minutes(b.datetime)
  34.             if trunced_date not in d:
  35.                 d[trunced_date] = {'hr': [b.HR], 'bo': []}
  36.             else:
  37.                 d[trunced_date]['hr'].append(b.HR)
  38.         for b in i.pacient.pacient_bo.filter(datetime__date = datetime.today().date()):
  39.             trunced_date = trunc_5_minutes(b.datetime)
  40.             if trunced_date not in d:
  41.                 d[trunced_date] = {'bo': [b.BO], 'hr': []}
  42.             else:
  43.                 d[trunced_date]['bo'].append(b.BO)
  44.  
  45.         for key, values in d.items():
  46.             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']):
  47.                 result_list.append({'date': key, 'patient': i.pacient, 'hr_list': values['hr'], 'bo_list': values['bo']})
  48.  
  49.     for i in result_list:
  50.         print(i['patient'], '( ' + str(i['hr_list']) + ': HR)', '( ' + str(i['bo_list']) + ': BO)')
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement