Функции работы с анамнезом приёма

This commit is contained in:
Роман Бородин 2020-01-23 10:02:47 +03:00
parent 1a9cd54a88
commit 6995916d8a
3 changed files with 40 additions and 14 deletions

View File

@ -35,7 +35,7 @@ def cats_subcats(cat):
def get_categories(parent=None):
with db.atomic():
return DiagnosisCategory.select().where(DiagnosisCategory.parent == parent)
def get_reception_diagnosises(cat=None):
def get_reception_diagnosisses(cat=None):
with db.atomic():
if cat:
d = list(Diagnosis.select().where(Diagnosis.category == cat).order_by(Diagnosis.code))
@ -87,7 +87,7 @@ def create_choose_diagnosis_win(reception_b):
def redraw_diagnosis_list(self, cat):
for c in diagnosis_list.get_children():
diagnosis_list.remove(c)
for d in get_reception_diagnosises(cat):
for d in get_reception_diagnosisses(cat):
diagnosis_list.add(build_diagnosis_row(d))
diagnosis_list.show_all()
def diagnosis_row_selected(self, *a):

View File

@ -7,9 +7,12 @@ from mods.utils import show_msg, disable_widget, enable_widget, ConditionalFilte
import re
import peewee
ANAMNEZ_LIST = 'anamnez'
OBSERV_LIST = 'observ'
lists_map = {
'anamnez': 'Анамнез',
'observ': 'Осмотр',
ANAMNEZ_LIST: 'Анамнез',
OBSERV_LIST: 'Осмотр',
}
for s_id in lists_map:

View File

@ -2,10 +2,11 @@ import gi
from mods.utils import disable_widget, enable_widget
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk
from mods.db import db, Reception, Patient, ReceptionDiagnosis
from mods.db import db, Reception, Patient, ReceptionDiagnosis, ReceptionAnamnesis
from mods.files import new_reception_win_file, reception_row_ui_str, reception_list_settings_win_file, open_reception_win_file, diagnosis_row_ui_str
from mods.settings import s_get_reception_list, s_set_reception_list
from mods.diagnosis import create_choose_diagnosis_win, get_giagnosis
from mods.lists import get_listrecord
from mods.root import builder
from datetime import datetime, timedelta
@ -59,25 +60,44 @@ class ReceptionDiagnosisRow(Gtk.ListBoxRow):
def get_reception(reception_id):
with db.atomic():
return Reception.get_by_id(reception_id)
def get_reception_diagnosises(reception):
def get_reception_diagnosisses(reception):
with db.atomic():
return ReceptionDiagnosis.select().where(ReceptionDiagnosis.reception == reception)
def delete_reception_diagnosises(reception, diag_id_list):
def get_reception_anamnesisses(reception):
with db.atomic():
return ReceptionAnamnesis.select().where(ReceptionAnamnesis.reception == reception)
def delete_reception_diagnosisses(reception, diag_id_list):
if not len(diag_id_list): return
with db.atomic():
ReceptionDiagnosis.delete().where((ReceptionDiagnosis.reception == reception) & (ReceptionDiagnosis.diagnosis.in_(diag_id_list))).execute()
def add_reception_diagnosises(reception, diag_id_list):
def delete_reception_anamnesisses(reception, anam_id_list):
if not len(anam_id_list): return
with db.atomic():
ReceptionAnamnesis.delete().where((ReceptionAnamnesis.reception == reception) & (ReceptionAnamnesis.anamnesis.in_(anam_id_list))).execute()
def add_reception_diagnosisses(reception, diag_id_list):
if not len(diag_id_list): return
with db.atomic():
inserts = list(map(lambda x: {'reception': reception, 'diagnosis': get_giagnosis(x)}, diag_id_list))
_ = ReceptionDiagnosis.insert_many(inserts).execute()
def save_reception_diagnosises(reception, diag_id_list):
exist_diags = set(map(lambda x: x.diagnosis.id, get_reception_diagnosises(reception)))
def add_reception_anamnesisses(reception, anam_id_list):
if not len(anam_id_list): return
with db.atomic():
inserts = list(map(lambda x: {'reception': reception, 'anamnesis': get_listrecord(x)}, anam_id_list))
_ = ReceptionAnamnesis.insert_many(inserts).execute()
def save_reception_diagnosisses(reception, diag_id_list):
exist_diags = set(map(lambda x: x.diagnosis.id, get_reception_diagnosisses(reception)))
new_diags = set(diag_id_list)
to_del = list(exist_diags - new_diags)
to_add = list(new_diags - exist_diags)
delete_reception_diagnosises(reception, to_del)
add_reception_diagnosises(reception, to_add)
delete_reception_diagnosisses(reception, to_del)
add_reception_diagnosisses(reception, to_add)
def save_reception_anamnesisses(reception, anam_id_list):
exist_anams = set(map(lambda x: x.anamnesis.id, get_reception_anamnesisses(reception)))
new_anams = set(anam_id_list)
to_del = list(exist_anams - new_anams)
to_add = list(new_anams - exist_anams)
delete_reception_anamnesisses(reception, to_del)
add_reception_anamnesisses(reception, to_add)
##################################################################################
def build_reception_row(reception_datetime):
@ -138,7 +158,7 @@ def create_open_reception_win():
def save(self, button):
# Диагнозы
diag_id_list = list(map(lambda x: x.props.db_id, reception_diag_list.get_children()))
save_reception_diagnosises(reception, diag_id_list)
save_reception_diagnosisses(reception, diag_id_list)
#######
#######
@ -152,8 +172,11 @@ def create_open_reception_win():
reception_dt.set_markup(f'<span size="x-large">{reception_row.props.datetime.strftime("%d.%m.%Y - %H:%M")}</span>')
reception_diag_list = b.get_object('diagnosis_list')
remove_diag_button = b.get_object('remove_diag_button')
# Анамнезы
#
# Диагнозы
for rd in [x.diagnosis for x in get_reception_diagnosises(reception)]:
for rd in [x.diagnosis for x in get_reception_diagnosisses(reception)]:
reception_diag_list.add(build_reception_diagnosis_row(rd))
#
w = b.get_object('open_reception_window')