-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4337 from mikhailprivalov/beds-managment-v2-1
Палаты и койки v2
- Loading branch information
Showing
12 changed files
with
1,025 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
l2-frontend/src/pages/ManageChambers/components/Filters.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.