diff --git a/api/chambers/sql_func.py b/api/chambers/sql_func.py index 48ae23186d..4b037f620f 100644 --- a/api/chambers/sql_func.py +++ b/api/chambers/sql_func.py @@ -12,13 +12,15 @@ def load_patients_stationar_unallocated_sql(department_id): patronymic, sex, napravleniye_id, + directions_issledovaniya.id as issledovanie_id, birthday, date_part('year', age(birthday))::int AS age FROM directions_issledovaniya INNER JOIN directions_napravleniya ON directions_issledovaniya.napravleniye_id=directions_napravleniya.id INNER JOIN clients_card ON directions_napravleniya.client_id=clients_card.id INNER JOIN public.clients_individual ON clients_card.individual_id = public.clients_individual.id - WHERE hospital_department_override_id = %(department_id)s + WHERE directions_napravleniya.cancel = false + AND hospital_department_override_id = %(department_id)s AND data_sozdaniya > now() - INTERVAL '2 months' AND NOT EXISTS (SELECT direction_id FROM podrazdeleniya_patienttobed WHERE date_out IS NULL AND napravleniye_id = direction_id) AND NOT EXISTS (SELECT direction_id FROM podrazdeleniya_patientstationarwithoutbeds WHERE napravleniye_id = direction_id) @@ -32,6 +34,31 @@ def load_patients_stationar_unallocated_sql(department_id): return rows +def get_closing_protocols(issledovaniye_ids, titles): + with connection.cursor() as cursor: + cursor.execute( + """ + SELECT + directions_napravleniya.parent_id + + FROM directions_napravleniya + LEFT JOIN directions_issledovaniya ON directions_napravleniya.id = directions_issledovaniya.napravleniye_id + LEFT JOIN directory_researches ON directions_issledovaniya.research_id = directory_researches.id + LEFT JOIN directory_hospitalservice ON directory_researches.id = directory_hospitalservice.slave_research_id + WHERE directions_napravleniya.parent_id IN %(issledovaniye_ids)s + AND + (directory_hospitalservice.site_type = 7 OR (directory_hospitalservice.site_type = 6 AND title IN %(titles)s)) + + AND total_confirmed = true + + """, + params={"issledovaniye_ids": issledovaniye_ids, "titles": titles}, + ) + + rows = namedtuplefetchall(cursor) + return rows + + def load_patient_without_bed_by_department(department_id): with connection.cursor() as cursor: cursor.execute( @@ -60,24 +87,28 @@ def load_patient_without_bed_by_department(department_id): return rows -def load_attending_doctor_by_department(department_id): +def load_attending_doctor_by_department(department_id, group_id): with connection.cursor() as cursor: cursor.execute( """ SELECT - id, - family, - name, - patronymic + users_doctorprofile.id, + users_doctorprofile.family, + users_doctorprofile.name, + users_doctorprofile.patronymic FROM users_doctorprofile - WHERE - users_doctorprofile.podrazdeleniye_id = %(department_id)s + LEFT JOIN auth_user ON users_doctorprofile.user_id = auth_user.id + LEFT JOIN auth_user_groups ON auth_user.id = auth_user_groups.user_id + LEFT JOIN auth_group ON auth_user_groups.group_id = auth_group.id + WHERE + auth_group.id = %(group_id)s + AND users_doctorprofile.podrazdeleniye_id = %(department_id)s AND users_doctorprofile.dismissed = false ORDER BY family """, - params={"department_id": department_id}, + params={"department_id": department_id, "group_id": group_id}, ) rows = namedtuplefetchall(cursor) diff --git a/api/chambers/views.py b/api/chambers/views.py index d45c98f7c5..ec864c9d67 100644 --- a/api/chambers/views.py +++ b/api/chambers/views.py @@ -2,11 +2,19 @@ from django.contrib.auth.decorators import login_required import simplejson as json from django.http import JsonResponse + +from laboratory.settings import CHAMBER_DOCTOR_GROUP_ID from podrazdeleniya.models import Chamber, Bed, PatientToBed, PatientStationarWithoutBeds from slog.models import Log from utils.response import status_response import datetime -from .sql_func import load_patient_without_bed_by_department, load_attending_doctor_by_department, load_patients_stationar_unallocated_sql, load_chambers_and_beds_by_department +from .sql_func import ( + load_patient_without_bed_by_department, + load_attending_doctor_by_department, + load_patients_stationar_unallocated_sql, + load_chambers_and_beds_by_department, + get_closing_protocols, +) @login_required @@ -14,6 +22,14 @@ def get_unallocated_patients(request): request_data = json.loads(request.body) department_pk = request_data.get('department_pk', -1) + transferable_epicrisis_titles = ('переводной эпикриз', 'Переводной эпикриз', 'ПЕРЕВОДНОЙ ЭПИКРИЗ', 'переводной', 'Переводной', 'ПЕРЕВОДНОЙ') + all_histories = load_patients_stationar_unallocated_sql(department_pk) + all_issledovaniya_ids = [history.issledovanie_id for history in all_histories] + all_issledovaniya_ids = tuple(all_issledovaniya_ids) + closed_histories = get_closing_protocols(all_issledovaniya_ids, transferable_epicrisis_titles) + closed_issledovaniya_ids = [extract.parent_id for extract in closed_histories] + closed_issledovaniya_ids = set(closed_issledovaniya_ids) + patients = [ { "fio": f'{patient.family} {patient.name} {patient.patronymic if patient.patronymic else ""}', @@ -23,7 +39,9 @@ def get_unallocated_patients(request): "direction_pk": patient.napravleniye_id, } for patient in load_patients_stationar_unallocated_sql(department_pk) + if patient.issledovanie_id not in closed_issledovaniya_ids ] + return JsonResponse({"data": patients}) @@ -83,6 +101,7 @@ def entrance_patient_to_bed(request): request_data = json.loads(request.body) bed_id = request_data.get('bed_id') direction_id = request_data.get('direction_id') + doctor_id = request_data.get('doctor_id') user = request.user bed: Bed = Bed.objects.filter(pk=bed_id).select_related('chamber').first() if not bed: @@ -92,7 +111,7 @@ def entrance_patient_to_bed(request): if not user_can_edit: return status_response(False, "Пользователь не принадлежит к данному подразделению") if not PatientToBed.objects.filter(bed_id=bed_id, date_out=None).exists(): - patient_to_bed = PatientToBed(direction_id=direction_id, bed_id=bed_id) + patient_to_bed = PatientToBed(direction_id=direction_id, bed_id=bed_id, doctor_id=doctor_id) patient_to_bed.save() Log.log(direction_id, 230000, user.doctorprofile, {"direction_id": direction_id, "bed_id": bed_id, "department_id": bed_department_id, "patient_to_bed": patient_to_bed.pk}) return status_response(True) @@ -131,17 +150,22 @@ def extract_patient_bed(request): def get_attending_doctors(request): request_data = json.loads(request.body) department_pk = request_data.get('department_pk', -1) - attending_doctors = load_attending_doctor_by_department(department_pk) - doctors = [ - { - "pk": doctor.id, - "fio": f'{doctor.family} {doctor.name} {doctor.patronymic if doctor.patronymic else ""}', - "short_fio": f'{doctor.family} {doctor.name[0]}. {doctor.patronymic[0] if doctor.patronymic else ""}.', - "highlight": False, - } - for doctor in attending_doctors - ] - return JsonResponse({"data": doctors}) + if CHAMBER_DOCTOR_GROUP_ID: + group_id = CHAMBER_DOCTOR_GROUP_ID + attending_doctors = load_attending_doctor_by_department(department_pk, group_id) + doctors = [ + { + "pk": doctor.id, + "fio": f'{doctor.family} {doctor.name} {doctor.patronymic if doctor.patronymic else ""}', + "short_fio": f'{doctor.family} {doctor.name[0]}. {doctor.patronymic[0] if doctor.patronymic else ""}.', + "highlight": False, + } + for doctor in attending_doctors + ] + result = {"ok": True, "message": "", "data": doctors} + else: + result = {"ok": False, "message": "Группа прав для врачей не настроена", "data": []} + return JsonResponse(result) @login_required diff --git a/l2-frontend/src/pages/ManageChambers/components/Filters.vue b/l2-frontend/src/pages/ManageChambers/components/Filters.vue deleted file mode 100644 index 2398f1866a..0000000000 --- a/l2-frontend/src/pages/ManageChambers/components/Filters.vue +++ /dev/null @@ -1,33 +0,0 @@ - - - diff --git a/l2-frontend/src/pages/ManageChambers/components/VueTippyDiv.vue b/l2-frontend/src/pages/ManageChambers/components/VueTippyDiv.vue new file mode 100644 index 0000000000..f1c6d7a37e --- /dev/null +++ b/l2-frontend/src/pages/ManageChambers/components/VueTippyDiv.vue @@ -0,0 +1,43 @@ + + + + + diff --git a/l2-frontend/src/pages/ManageChambers/index.vue b/l2-frontend/src/pages/ManageChambers/index.vue index ad6f5f616a..634dc68236 100644 --- a/l2-frontend/src/pages/ManageChambers/index.vue +++ b/l2-frontend/src/pages/ManageChambers/index.vue @@ -1,16 +1,25 @@