Частично реализовал добавление медикаментов в приёме

This commit is contained in:
Роман Бородин 2020-05-05 13:49:11 +03:00
parent d51402e91b
commit 2012391d08
6 changed files with 262 additions and 1 deletions

View File

@ -35,6 +35,9 @@ with open(anamnesis_row_file, 'r') as f:
observe_row_file = os.path.join(ui_dir, 'observe_row.glade')
with open(observe_row_file, 'r') as f:
observe_row_ui_str = f.read()
medicine_row_file = os.path.join(ui_dir, 'medicine_row.glade')
with open(medicine_row_file, 'r') as f:
medicine_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')
@ -46,3 +49,4 @@ new_catalog_win_file = os.path.join(ui_dir, 'new_catalog_win.glade')
choose_patient_win_file = os.path.join(ui_dir, 'choose_patient_win.glade')
open_reception_win_file = os.path.join(ui_dir, 'open_reception_win.glade')
choose_diagnosis_win_file = os.path.join(ui_dir, 'choose_diagnosis_win.glade')
choose_medicine_win_file = os.path.join(ui_dir, 'choose_medicine_win.glade')

81
mods/medicines.py Normal file
View File

@ -0,0 +1,81 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
from mods.files import choose_medicine_win_file, medicine_row_ui_str
from mods.db import db, Rls, RlsIndex
from mods.utils import enable_widget, disable_widget
import re
MAX_SEARCH_RESULTS = 50
def search_medicines(q):
q = re.sub(r'\s+', ' ', q).strip()
q = ' '.join([ f'{x}*' for x in q.split(' ')])
with db.atomic():
return (Rls.select()
.join(
RlsIndex,
on=(Rls.id == RlsIndex.rowid))
.where(RlsIndex.match(q))
.order_by(RlsIndex.bm25())
.limit(MAX_SEARCH_RESULTS))
def get_all_medicines():
with db.atomic():
return Rls.select()
########################################################
class MedicineRow(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
@GObject.Property
def tradename(self):
return self._fio
@tradename.setter
def tradename_setter(self, value):
self._fio = value
def build_medicine_row(medicine):
b = Gtk.Builder()
b.add_from_string(medicine_row_ui_str)
win = b.get_object('win')
box = b.get_object('medicine_box')
tradename = medicine.tradename
b.get_object('tradename').set_text(tradename)
internationalname = medicine.internationalname
b.get_object('internationalname').set_text(internationalname)
win.remove(win.get_children()[0])
row = MedicineRow()
row.props.db_id = medicine.id
row.props.tradename = tradename
row.add(box)
return row
def create_choose_medicine_win(reception_b):
b = Gtk.Builder()
rm_list = reception_b.get_object('medicines_list')
class ChooseMedicineWinHandler:
def medicine_filter_changed(self, filter_widget):
ml.unselect_all()
self.medicine_list_unselected()
for c in ml.get_children():
ml.remove(c)
fstr = med_filter.get_text().strip()
if fstr:
for m in search_medicines(fstr):
ml.add(build_medicine_row(m))
ml.show_all()
def medicine_list_selected(self, *a):
enable_widget([accept_button])
def medicine_list_unselected(self, *a):
disable_widget([accept_button])
b.add_from_file(choose_medicine_win_file)
b.connect_signals(ChooseMedicineWinHandler())
accept_button = b.get_object('accept_button')
ml = b.get_object('medicine_list')
med_filter = b.get_object('medicine_filter')
w = b.get_object('choose_medicine_window')
return w

View File

@ -7,6 +7,7 @@ from mods.files import new_reception_win_file, reception_row_ui_str, reception_l
from mods.files import anamnesis_row_ui_str, observe_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.medicines import create_choose_medicine_win
from mods.lists import get_listrecord, get_list_by_system_id, create_open_list_win, ANAMNEZ_LIST, OBSERVE_LIST
from mods.root import builder
from datetime import datetime, timedelta
@ -200,6 +201,9 @@ def create_open_reception_win():
reception_row = reception_list.get_selected_row()
reception = get_reception(reception_row.props.db_id)
class OpenReceptionWinHandler:
def show_choose_medicine_win(self, button):
choose_medicine_win = create_choose_medicine_win(b)
choose_medicine_win.show_all()
def show_choose_diagnosis_win(self, button):
choose_diagnosis_win = create_choose_diagnosis_win(b)
choose_diagnosis_win.show_all()

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="choose_medicine_window">
<property name="width_request">600</property>
<property name="height_request">500</property>
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="default_width">800</property>
<property name="default_height">500</property>
<property name="type_hint">dialog</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Выбор лекарственного средства</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkButton" id="accept_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-select-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="medicines_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkListBox" id="medicine_list">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="row-selected" handler="medicine_list_selected" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">3</property>
<property name="margin_bottom">3</property>
<child>
<object class="GtkFixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="medicine_filter">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<signal name="changed" handler="medicine_filter_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

50
res/ui/medicine_row.glade Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="win">
<property name="can_focus">False</property>
<property name="decorated">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkBox" id="medicine_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="tradename">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="xalign">0</property>
<attributes>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="internationalname">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">5</property>
<property name="label" translatable="yes">label</property>
<attributes>
<attribute name="style" value="oblique"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkTextBuffer" id="notes_buffer"/>
@ -643,6 +643,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="show_choose_medicine_win" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>