Skip to content

Commit

Permalink
Merge pull request #4337 from mikhailprivalov/beds-managment-v2-1
Browse files Browse the repository at this point in the history
Палаты и койки v2
  • Loading branch information
urchinpro authored Oct 4, 2024
2 parents 76cc423 + b82585e commit f1b286f
Show file tree
Hide file tree
Showing 12 changed files with 1,025 additions and 1 deletion.
Empty file added api/chambers/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions api/chambers/sql_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.db import connection
from utils.db import namedtuplefetchall


def patients_stationar_unallocated_sql(department_id):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
family,
name,
patronymic,
sex,
napravleniye_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
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)
""",
params={"department_id": department_id},
)

rows = namedtuplefetchall(cursor)
return rows
15 changes: 15 additions & 0 deletions api/chambers/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.urls import path

from . import views

urlpatterns = [
path('get-unallocated-patients', views.get_unallocated_patients),
path('get-chambers-and-beds', views.get_chambers_and_beds),
path('entrance-patient-to-bed', views.entrance_patient_to_bed),
path('extract-patient-bed', views.extract_patient_bed),
path('get-attending-doctors', views.get_attending_doctors),
path('update-doctor-to-bed', views.update_doctor_to_bed),
path('get-patients-without-bed', views.get_patients_without_bed),
path('save-patient-without-bed', views.save_patient_without_bed),
path('delete-patient-without-bed', views.delete_patient_without_bed),
]
139 changes: 139 additions & 0 deletions api/chambers/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
from laboratory.decorators import group_required
from django.contrib.auth.decorators import login_required

import simplejson as json
from django.http import JsonResponse

from podrazdeleniya.models import Chamber, Bed, PatientToBed, PatientStationarWithoutBeds
from directions.models import Napravleniya
from users.models import DoctorProfile

from utils.response import status_response

import datetime
from .sql_func import patients_stationar_unallocated_sql


@login_required
@group_required("Управления палатами")
def get_unallocated_patients(request):
request_data = json.loads(request.body)
department_pk = request_data.get('department_pk', -1)
patients = [
{
"fio": f'{patient.family} {patient.name} {patient.patronymic if patient.patronymic else None}',
"age": patient.age,
"short_fio": f'{patient.family} {patient.name[0]}. {patient.patronymic[0] if patient.patronymic else None}.',
"sex": patient.sex,
"direction_pk": patient.napravleniye_id,
}
for patient in patients_stationar_unallocated_sql(department_pk)
]
return JsonResponse({"data": patients})


@login_required
@group_required("Управления палатами")
def get_chambers_and_beds(request):
request_data = json.loads(request.body)
chambers = []
for ward in Chamber.objects.filter(podrazdelenie_id=request_data.get('department_pk', -1)):
chamber = {
"pk": ward.pk,
"label": ward.title,
"beds": [],
}
for bed in Bed.objects.filter(chamber_id=ward.pk).prefetch_related('chamber'):
chamber["beds"].append({"pk": bed.pk, "bed_number": bed.bed_number, "doctor": [], "patient": []})
history = PatientToBed.objects.filter(bed_id=bed.pk, date_out__isnull=True).last()
if history:
direction_obj = Napravleniya.objects.get(pk=history.direction.pk)
ind_card = direction_obj.client
patient_data = ind_card.get_data_individual()
chamber["beds"][-1]["patient"] = [
{"fio": patient_data["fio"], "short_fio": patient_data["short_fio"], "age": patient_data["age"], "sex": patient_data["sex"], "direction_pk": history.direction_id}
]
if history.doctor:
chamber["beds"][-1]["doctor"] = [
{
"fio": history.doctor.get_full_fio(),
"pk": history.doctor.pk,
"highlight": False,
"short_fio": history.doctor.get_fio(),
}
]
chambers.append(chamber)
return JsonResponse({"data": chambers})


@login_required
@group_required("Управления палатами")
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')
if not PatientToBed.objects.filter(bed_id=bed_id, date_out=None).exists():
PatientToBed(direction_id=direction_id, bed_id=bed_id).save()
return status_response(True)


@login_required
@group_required("Управления палатами")
def extract_patient_bed(request):
request_data = json.loads(request.body)
direction_pk = request_data.get('patient')
patient = PatientToBed.objects.filter(direction_id=direction_pk, date_out=None).first()
patient.date_out = datetime.datetime.today()
patient.save()
return status_response(True)


@login_required
@group_required("Управления палатами")
def get_attending_doctors(request):
request_data = json.loads(request.body)
department_pk = request_data.get('department_pk', -1)
doctors = [{'fio': doctor.get_full_fio(), 'pk': doctor.pk, 'highlight': False, 'short_fio': doctor.get_fio()} for doctor in DoctorProfile.objects.filter(podrazdeleniye_id=department_pk)]
return JsonResponse({"data": doctors})


@login_required
@group_required("Управления палатами")
def update_doctor_to_bed(request):
request_data = json.loads(request.body)
doctor_obj = request_data.get('doctor')
result = PatientToBed.update_doctor(doctor_obj)
return status_response(result)


@login_required
@group_required("Управления палатами")
def get_patients_without_bed(request):
request_data = json.loads(request.body)
department_pk = request_data.get('department_pk', -1)
patients = []
for patient in PatientStationarWithoutBeds.objects.filter(department_id=department_pk):
direction_obj = Napravleniya.objects.get(pk=patient.direction.pk)
ind_card = direction_obj.client
patient_data = ind_card.get_data_individual()
patients.append({"fio": patient_data["fio"], "short_fio": patient_data["short_fio"], "age": patient_data["age"], "sex": patient_data["sex"], "direction_pk": patient.direction_id})
return JsonResponse({"data": patients})


@login_required
@group_required("Управления палатами")
def save_patient_without_bed(request):
request_data = json.loads(request.body)
department_pk = request_data.get('department_pk')
patient_obj = request_data.get('patient_obj')
PatientStationarWithoutBeds(direction_id=patient_obj["direction_pk"], department_id=department_pk).save()
return status_response(True)


@login_required
@group_required("Управления палатами")
def delete_patient_without_bed(request):
request_data = json.loads(request.body)
patient_obj = request_data.get('patient_obj')
PatientStationarWithoutBeds.objects.get(direction_id=patient_obj["direction_pk"]).delete()
return status_response(True)
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
path('search-param', views.search_param),
path('statistic-params-search', views.statistic_params_search),
path('analyzers/', include('api.analyzers.urls')),
path('chambers/', include('api.chambers.urls')),
path('researches/', include('api.researches.urls')),
path('patients/', include('api.patients.urls')),
path('directions/', include('api.directions.urls')),
Expand Down
1 change: 1 addition & 0 deletions clients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ def get_data_individual(self, empty=False, full_empty=False, only_json_serializa
docs.append(Document.objects.filter(pk=cd[d])[0])
ind_data['doc'] = docs if not full_empty else []
ind_data['fio'] = self.individual.fio()
ind_data['short_fio'] = self.individual.fio(short=True, dots=True)
ind_data['sex'] = self.individual.sex
ind_data['family'] = self.individual.family
ind_data['name'] = self.individual.name
Expand Down
1 change: 1 addition & 0 deletions context_processors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def menu(request):
"nt": False,
"access": ["Управление анализаторами"],
},
{"url": "/ui/chambers", "title": "Палаты", "nt": False, "access": ["Управления палатами"]},
{"url": '/ui/list-wait', "title": "Листы ожидания", "nt": False, "access": ["Лечащий врач", "Оператор лечащего врача"], "module": "l2_list_wait"},
{"url": '/ui/doc-call', "title": "Вызовы врача и заявки", "nt": False, "access": ["Лечащий врач", "Оператор лечащего врача", "Вызов врача"], "module": "l2_doc_call"},
{
Expand Down
11 changes: 11 additions & 0 deletions l2-frontend/src/mainWithRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,17 @@ const router = new Router({
groups: ['Управление анализаторами'],
},
},
{
path: '/ui/chambers',
name: 'ManageChamber',
component: () => import('@/pages/ManageChambers/index.vue'),
meta: {
narrowLayout: true,
title: 'Палаты',
groups: ['Палаты'],
fullPageLayout: true,
},
},
{
path: '/ui/turnovers',
name: 'Turnovers',
Expand Down
33 changes: 33 additions & 0 deletions l2-frontend/src/pages/ManageChambers/components/Filters.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<Treeselect
v-model="departId"
:multiple="false"
:disable-branch-nodes="true"
:options="props.departments"
placeholder="Отделение не выбрано"
:append-to-body="true"
:class="{'treeselect-noborder': props.noBorder}"
@input="$emit('input', departId)"
/>
</template>

<script setup lang="ts">
import Treeselect from '@riophae/vue-treeselect';
import { defineProps, ref } from 'vue';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
const props = defineProps({
departments: {
type: Array,
required: true,
},
noBorder: {
type: Boolean,
required: false,
},
});
const departId = ref(null);
</script>
Loading

0 comments on commit f1b286f

Please sign in to comment.