diff --git a/app.py b/app.py index bcaab78..dd172e5 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,17 @@ import gi import os gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, GObject -from mods.db import Patient, store_patient_index, update_patient_index, search_patients, db -from datetime import date +from gi.repository import Gtk, GObject, Gdk +from mods.db import Patient, Reception, store_patient_index, update_patient_index, search_patients, db +from datetime import date, datetime, timedelta, time import peewee +# FIXME: временно +DAY_START = time(8,0) +DAY_END = time(13,0) +TIME_INTERVAL = timedelta(minutes=30) +# + gender_dict = { 'male': 'Мужской', 'female': 'Женский' @@ -25,6 +31,9 @@ open_patient_win_file = os.path.join(ui_dir, 'open_patient_win.glade') edit_patient_win_file = os.path.join(ui_dir, 'edit_patient_win.glade') male_patient_row_file = os.path.join(ui_dir, 'male_patient_row.glade') female_patient_row_file = os.path.join(ui_dir, 'female_patient_row.glade') +reception_row_file = os.path.join(ui_dir, 'reception_row.glade') +with open(reception_row_file, 'r') as f: + reception_row_ui_str = f.read() gender_ui_str = {} with open(male_patient_row_file, 'r') as f: gender_ui_str['male'] = f.read() @@ -34,6 +43,13 @@ with open(female_patient_row_file, 'r') as f: builder = Gtk.Builder() +def get_reception_timelist(rec_date): + dstart = datetime(rec_date.year, rec_date.month, rec_date.day, DAY_START.hour, DAY_START.minute) + dend = datetime(rec_date.year, rec_date.month, rec_date.day, DAY_END.hour, DAY_END.minute) + work_day_minutes_total = (dend.hour - dstart.hour) * 60 + dend.minute - dstart.minute + shift_minutes_range = range(0, work_day_minutes_total, int(TIME_INTERVAL.seconds / 60)) + return [(dstart + timedelta(minutes=x)).time() for x in shift_minutes_range] + class PatientFilter: def __init__(self): self.reset() @@ -67,6 +83,26 @@ class PatientRow(Gtk.ListBoxRow): def birth_date_setter(self, value): self._birth_date = value +class ReceptionRow(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 datetime(self): + return self._datetime + @datetime.setter + def datetime_setter(self, value): + self._datetime = value + @GObject.Property + def scheduled(self): + return self._scheduled + @scheduled.setter + def scheduled_setter(self, value): + self._scheduled = value + class MainWinHandler: def main_win_close(self, *args): Gtk.main_quit() @@ -102,6 +138,30 @@ class MainWinHandler: pl.add(build_patient_row(p)) pl.show_all()''' +def build_reception_row(reception_datetime): + b = Gtk.Builder() + b.add_from_string(reception_row_ui_str) + win = b.get_object('win') + box = b.get_object('reception_box') + b.get_object('hour').set_text(reception_datetime.strftime('%H')) + b.get_object('minute').set_text(reception_datetime.strftime('%M')) + reception = Reception.select().where(Reception.time == reception_datetime) + row = ReceptionRow() + if len(reception): + row.props.scheduled = True + reception_cont = b.get_object('reception_cont') + reception_cont.props.border_width = 2 + reception_cont.override_background_color(Gtk.StateFlags(0), Gdk.RGBA(red=0.5, green=0.7, blue=0.5, alpha=1.0)) + reception_patient = Gtk.Label() + reception_patient.set_text(' '.join([reception.patient.last_name, reception.patient.first_name, reception.patient.middle_name])) + reception_cont.add(reception_patient) + else: + row.props.scheduled = False + win.remove(win.get_children()[0]) + row.props.datetime = reception_datetime + row.add(box) + return row + def build_patient_row(patient): b = Gtk.Builder() b.add_from_string(gender_ui_str[patient.gender]) @@ -131,8 +191,17 @@ def patient_filter_func(row): return True return row.props.db_id in patient_filter.filter(fstr) +def redraw_reception_list(selected_date): + reception_timelist = get_reception_timelist(selected_date) + reception_list = builder.get_object('reception_list') + for d in reception_timelist: + reception_list.add(build_reception_row(d)) + builder.add_from_file(main_win_file) builder.connect_signals(MainWinHandler()) +##### +redraw_reception_list(datetime.now()) +##### patient_list = builder.get_object('patient_list') patient_list.set_sort_func(patient_sort_func) patient_list.set_filter_func(patient_filter_func) diff --git a/mods/db.py b/mods/db.py index 219b891..faef363 100644 --- a/mods/db.py +++ b/mods/db.py @@ -1,5 +1,5 @@ import os -from peewee import Model, CharField, BigAutoField, DateTimeField, IntegerField, fn, Field, Expression, TextField, ForeignKeyField, DateField +from peewee import Model, CharField, BigAutoField, DateTimeField, IntegerField, fn, Field, Expression, TextField, ForeignKeyField, DateField, TimeField from playhouse.sqlite_ext import CSqliteExtDatabase, FTS5Model, AutoIncrementField, SearchField, RowIDField var_dir = os.path.join(os.path.abspath(os.environ['HOME']), '.eldoc') @@ -99,5 +99,10 @@ def update_patient_index(pat): db.connect() db.create_tables([ Patient, - PatientIndex + PatientIndex, + Reception, + Diagnosis, + ReceptionDiagnosis, + ReceptionAnamnesis, + AnamnesisTemplate ]) diff --git a/res/ui/main_win.glade b/res/ui/main_win.glade index ccb17e6..3b42943 100644 --- a/res/ui/main_win.glade +++ b/res/ui/main_win.glade @@ -33,7 +33,7 @@ True False - + True False vertical @@ -78,7 +78,7 @@ - + True False diff --git a/res/ui/reception_row.glade b/res/ui/reception_row.glade new file mode 100644 index 0000000..69c48dd --- /dev/null +++ b/res/ui/reception_row.glade @@ -0,0 +1,91 @@ + + + + + + False + False + + + + + + True + False + + + 35 + True + False + 3 + 3 + 3 + 3 + 00 + + + + + + + False + True + 0 + + + + + 20 + True + False + 3 + 3 + 3 + 3 + 00 + 0 + + + + + + + False + True + 1 + + + + + True + False + 3 + 3 + 3 + 3 + vertical + + + True + False + + + + + + True + True + 0 + + + + + True + True + 2 + + + + + +