категории диагнозов и сами диагнозы

This commit is contained in:
Бородин Роман 2019-12-25 20:15:21 +03:00
parent f3a9d1cd5e
commit 416d78adff
6 changed files with 153 additions and 10 deletions

View File

@ -1,15 +1,97 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from mods.files import choose_diagnosis_win_file
from gi.repository import Gtk, GObject
from mods.files import choose_diagnosis_win_file, diagnosis_row_ui_str
from mods.utils import ConditionalFilter
from mods.db import DiagnosisCategory, Diagnosis, DiagnosisIndex, db
import re
class DiagnosisFilter(ConditionalFilter):
def filter(self, cat, query):
if query != self.fstr:
self.fstr = query
self.ids = list(map(lambda x:x.id, self.search_func(cat, query)))
return self.ids
class DiagnosisRow(Gtk.ListBoxRow):
@GObject.Property
def db_id(self):
return self._db_id
@db_id.setter
def db_id_setter(self, value):
self._db_id = value
def cats_subcats(cat):
cats = [cat]
def append_cat(cat_obj):
cats.append(cat_obj)
for c in cat_obj.subcat:
append_cat(c)
for c in cat.subcat:
append_cat(c)
return cats
def get_categories(parent=None):
with db.atomic():
return DiagnosisCategory.select().where(DiagnosisCategory.parent == parent)
def get_diagnosises(cat=None):
with db.atomic():
if cat:
d = list(Diagnosis.select().where(Diagnosis.category.in_(cats_subcats(cat))).order_by(Diagnosis.code))
return d
else:
return Diagnosis.select()
def get_category(cat_id):
with db.atomic():
return DiagnosisCategory.get_by_id(cat_id)
def search_diagnosises(cat, q):
q = re.sub(r'\s+', ' ', q).strip()
q = ' '.join([ f'{x}*' for x in q.split(' ')])
with db.atomic():
return (Diagnosis.select()
.join(
DiagnosisIndex,
on=(Diagnosis.id == DiagnosisIndex.rowid))
.where((Diagnosis.category.in_(cats_subcats(cat))) & (DiagnosisIndex.match(q)))
.order_by(DiagnosisIndex.bm25()))
diagnosis_filter = DiagnosisFilter(search_diagnosises)
########################################################
def build_diagnosis_row(diagnosis):
b = Gtk.Builder()
b.add_from_string(diagnosis_row_ui_str)
win = b.get_object('win')
box = b.get_object('diagnosis_box')
b.get_object('title').set_markup(f'<span size="x-large">{diagnosis.code:<8} {diagnosis.title}</span>')
win.remove(win.get_children()[0])
row = DiagnosisRow()
row.props.db_id = diagnosis.id
row.add(box)
return row
def create_choose_diagnosis_win(reception):
class ChooseDiagnosisWinHandler:
pass
b = Gtk.Builder()
class ChooseDiagnosisWinHandler:
def cat_selection_changed(self, cat_selection):
sel_iter = cat_selection.get_selected()[1]
model = cat_selection.get_tree_view().get_model()
category = get_category(model.get_value(sel_iter, 1))
self.redraw_diagnosis_list(category)
def redraw_diagnosis_list(self, cat):
for c in diagnosis_list.get_children():
diagnosis_list.remove(c)
for d in get_diagnosises(cat):
diagnosis_list.add(build_diagnosis_row(d))
diagnosis_list.show_all()
b.add_from_file(choose_diagnosis_win_file)
b.connect_signals(ChooseDiagnosisWinHandler())
cat_liststore = b.get_object('category_list')
def insert_cat(cat, parent=None):
cur_parent = cat_liststore.append(parent, [cat.title, cat.id])
for c in get_categories(cat):
insert_cat(c, cur_parent)
for c in get_categories():
insert_cat(c)
diagnosis_list = b.get_object('diagnosis_list')
diagnosis_list.set_sort_func(None, None)
w = b.get_object('choose_diagnosis_window')
return w

View File

@ -26,6 +26,9 @@ with open(reception_row_file, 'r') as f:
catalog_row_file = os.path.join(ui_dir, 'catalog_list_row.glade')
with open(catalog_row_file, 'r') as f:
catalog_row_ui_str = f.read()
diagnosis_row_file = os.path.join(ui_dir, 'diagnosis_row.glade')
with open(diagnosis_row_file, 'r') as f:
diagnosis_row_ui_str = f.read()
main_win_file = os.path.join(ui_dir, 'main_win.glade')
new_patient_win_file = os.path.join(ui_dir, 'new_patient_win.glade')

View File

@ -4,6 +4,7 @@ from gi.repository import Gtk, GObject, Gdk
from mods.db import db, Reception, Patient
from mods.files import new_reception_win_file, reception_row_ui_str, reception_list_settings_win_file, open_reception_win_file
from mods.settings import s_get_reception_list, s_set_reception_list
from mods.diagnosis import create_choose_diagnosis_win
from mods.root import builder
from datetime import datetime, timedelta
@ -85,7 +86,9 @@ def create_open_reception_win():
reception_row = reception_list.get_selected_row()
reception = get_reception(reception_row.props.db_id)
class OpenReceptionWinHandler:
pass
def show_choose_diagnosis_win(self, button):
choose_diagnosis_win = create_choose_diagnosis_win(reception)
choose_diagnosis_win.show_all()
b.add_from_file(open_reception_win_file)
b.connect_signals(OpenReceptionWinHandler())
#
@ -141,7 +144,10 @@ def create_reception_list_settings_win():
end_minute = int(b.get_object('end_minute').get_value())
interval = int(b.get_object('interval').get_value())
s_set_reception_list([start_hour, start_minute], [end_hour, end_minute], interval)
redraw_reception_list(datetime.now())
cal = builder.get_object('reception_cal')
cal_date = cal.get_date()
d = datetime(cal_date.year, cal_date.month + 1, cal_date.day)
redraw_reception_list(d)
b.get_object('reception_list_settings_win').close()
b.add_from_file(reception_list_settings_win_file)
b.connect_signals(ReceptionListSettingsHandler())

View File

@ -2,16 +2,19 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="category_list">
<object class="GtkTreeStore" id="category_list">
<columns>
<!-- column-name str1 -->
<column type="str"/>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name db_id -->
<column type="gint64"/>
</columns>
</object>
<object class="GtkWindow" id="choose_diagnosis_window">
<property name="width_request">800</property>
<property name="height_request">600</property>
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="type_hint">dialog</property>
<child type="titlebar">
@ -45,6 +48,8 @@
<property name="width_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
@ -60,7 +65,20 @@
<property name="level_indentation">4</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
<object class="GtkTreeSelection" id="cat_selection">
<signal name="changed" handler="cat_selection_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
@ -82,6 +100,8 @@
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="win">
<property name="can_focus">False</property>
<property name="decorated">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="diagnosis_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -492,6 +492,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="show_choose_diagnosis_win" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>