Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Палаты и койки v.2.3 #4367

Merged
merged 18 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions api/chambers/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 37 additions & 13 deletions api/chambers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@
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
@group_required("Оператор лечащего врача", "Лечащий врач")
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 ""}',
Expand All @@ -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})


Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 0 additions & 33 deletions l2-frontend/src/pages/ManageChambers/components/Filters.vue

This file was deleted.

43 changes: 43 additions & 0 deletions l2-frontend/src/pages/ManageChambers/components/VueTippyDiv.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div
v-tippy="{
maxWidth: props.tippyMaxWidth,
}"
:title="show ? props.text : null"
@mouseenter="showTitle"
>
{{ props.text }}
</div>
</template>

<script setup lang="ts">

import { ref } from 'vue';

const props = defineProps({
text: {
type: String,
required: true,
},
tippyMaxWidth: {
type: String,
required: false,
},
});

const show = ref(false);

const showTitle = (event) => {
if (event.target.scrollWidth > event.target.clientWidth) {
show.value = true;
} else {
show.value = false;
event.target.removeAttribute('data-original-title');
}
};

</script>

<style scoped lang="scss">

</style>
Loading
Loading