def available_hospitalization_plan(request): data = data_parse( request.body, { 'research_pk': int, 'resource_id': int, 'date_start': str, 'date_end': str }, { 'research_pk': None, 'resource_id': None, 'date_start': None, 'date_end': None, }, ) research_pk = data[0] resource_id = data[1] date_start = data[2] date_end = data[3] is_cito = has_group(request.user, 'Цито-запись в расписании') result, counts = get_available_hospital_plans(research_pk, resource_id, date_start, date_end) return JsonResponse({"data": result, "counts": counts, "cito": is_cito})
def available_slots(request): data = data_parse(request.body, { 'research_pk': int, 'date_start': str, 'date_end': str }) research_pk: int = data[0] date_start: str = data[1] date_end: str = data[2] result = get_available_hospital_resource_slot( research_pk, date_start, date_end, allow_cito=has_group(request.user, 'Цито-запись в расписании')) return JsonResponse({"result": result})
def available_slots_of_dates(request): data = data_parse(request.body, { 'research_pk': int, 'date_start': str, 'date_end': str }) research_pk = data[0] date_start = data[1] date_end = data[2] result = get_available_slots_of_dates(research_pk, date_start, date_end, allow_cito=has_group( request.user, 'Цито-запись в расписании')) return JsonResponse({"data": result})
def can_edit_resource(request, resource_pk): if has_group(request.user, *ADMIN_SCHEDULE_GROUPS): return True return can_access_user_to_modify_resource(request.user.doctorprofile, resource_pk=resource_pk)
def save(request): data = data_parse( request.body, { 'id': int, 'cardId': int, 'status': str, 'planId': int, 'serviceId': int, 'date': str, 'resource': str }, { 'planId': None, 'cardId': None, 'serviceId': None, 'status': 'reserved', 'date': None, 'resource': None }, ) pk: int = data[0] card_pk: int = data[1] status: str = data[2] plan_id: int = data[3] service_id: int = data[4] date: str = data[5] resource: int = data[6] if not card_pk: return status_response(False, 'Пациен не выбран') is_cito = False if has_group( request.user, 'Цито-запись в расписании') and pk == -10 and date and resource: d = try_strptime(f"{date}", formats=('%Y-%m-%d', )) start_date = datetime.datetime.combine(d, datetime.time.min) end_date = datetime.datetime.combine(d, datetime.time.max) slots = SlotPlan.objects.filter(datetime__range=(start_date, end_date)) free_slot: SlotPlan = slots.filter( slotfact__isnull=True).order_by('datetime').first() if not free_slot: last_any_slot: SlotPlan = slots.order_by('-datetime').first() if last_any_slot: next_time = last_any_slot.datetime + datetime.timedelta( minutes=last_any_slot.duration_minutes) duration = last_any_slot.duration_minutes else: next_time = try_strptime(f"{date} 08:00", formats=('%Y-%m-%d %H:%M', )) duration = 3 end_time = next_time + datetime.timedelta(minutes=duration) new_slot_plan = SlotPlan.objects.create( resource_id=resource, datetime=next_time, datetime_end=end_time, duration_minutes=duration, available_systems=[SlotPlan.LOCAL], disabled=False, is_cito=True, ) pk = new_slot_plan.pk else: pk = free_slot.pk is_cito = True s: SlotPlan = SlotPlan.objects.filter(pk=pk).first() if s: status = { 'reserved': 0, 'cancelled': 1, 'success': 2, }.get(status, 0) slot_fact: SlotFact = SlotFact.objects.filter( plan=s).order_by('-pk').first() if not slot_fact: slot_fact = SlotFact.objects.create(plan=s, status=status) slot_fact.patient_id = card_pk slot_fact.status = status slot_fact.service_id = service_id slot_fact.is_cito = is_cito slot_fact.save() if plan_id: ph: PlanHospitalization = PlanHospitalization.objects.get( pk=plan_id) ph.slot_fact = slot_fact ph.work_status = 3 ph.exec_at = s.datetime ph.save() return status_response(True) return status_response(False, 'Слот не найден')
def create(request): data = data_parse( request.body, { 'card_pk': 'card', 'comment': 'str_strip', 'date': str, 'researches': list, 'phone': 'str_strip', 'hospitalDepartment': int, 'diagnosis': 'str_strip' }, { 'hospitalDepartment': None, 'diagnosis': None }, ) card: Card = data[0] comment: str = data[1] date: str = data[2] researches: List[int] = data[3] phone: str = data[4] hosp_department_id: Optional[int] = data[5] diagnosis: Optional[str] = data[6] if phone != card.phone: card.phone = phone card.save(update_fields=['phone']) hospital_researches = [ r for r in Researches.objects.filter(pk__in=researches) if r.is_hospital ] if len(hospital_researches) > 1: return JsonResponse({ "ok": False, "message": "Выбрано больше одной услуги" }) if len(hospital_researches) == 1: if not hosp_department_id: hosp_department_id = hospital_researches[0].podrazdeleniye.pk has_free_slots = check_available_hospital_slot_before_save( hospital_researches[0].pk, None, date) is_cito = has_group(request.user, 'Цито-запись в расписании') if not has_free_slots and not is_cito: return JsonResponse({ "ok": False, "message": "Нет свободных слотов" }) PlanHospitalization.plan_hospitalization_save( { 'card': card, 'research': hospital_researches[0].pk, 'date': date, 'comment': comment, 'phone': phone, 'action': 0, 'hospital_department_id': hosp_department_id, 'diagnos': diagnosis, }, request.user.doctorprofile, ) else: for research_pk in researches: ListWait.list_wait_save( { 'card': card, 'research': research_pk, 'date': date, 'comment': comment, 'phone': phone, }, request.user.doctorprofile, ) return JsonResponse({"ok": True})