Добавлен функционад осмотра в окне приёма
This commit is contained in:
		
							parent
							
								
									3910f9cb24
								
							
						
					
					
						commit
						2c01fb6fd2
					
				| 
						 | 
				
			
			@ -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_diagnosisses(cat=None):
 | 
			
		||||
def get_reception_diagnosis_items(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_diagnosisses(cat):
 | 
			
		||||
            for d in get_reception_diagnosis_items(cat):
 | 
			
		||||
                diagnosis_list.add(build_diagnosis_row(d))
 | 
			
		||||
            diagnosis_list.show_all()
 | 
			
		||||
        def diagnosis_row_selected(self, *a):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,9 @@ with open(diagnosis_row_file, 'r') as f:
 | 
			
		|||
anamnesis_row_file = os.path.join(ui_dir, 'anamnesis_row.glade')
 | 
			
		||||
with open(anamnesis_row_file, 'r') as f:
 | 
			
		||||
    anamnesis_row_ui_str = f.read()
 | 
			
		||||
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()
 | 
			
		||||
 | 
			
		||||
main_win_file = os.path.join(ui_dir, 'main_win.glade')
 | 
			
		||||
new_patient_win_file = os.path.join(ui_dir, 'new_patient_win.glade')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,11 +8,11 @@ import re
 | 
			
		|||
import peewee
 | 
			
		||||
 | 
			
		||||
ANAMNEZ_LIST = 'anamnez'
 | 
			
		||||
OBSERV_LIST = 'observ'
 | 
			
		||||
OBSERVE_LIST = 'observ'
 | 
			
		||||
 | 
			
		||||
lists_map = {
 | 
			
		||||
    ANAMNEZ_LIST: 'Анамнез',
 | 
			
		||||
    OBSERV_LIST: 'Осмотр',
 | 
			
		||||
    OBSERVE_LIST: 'Осмотр',
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
for s_id in lists_map:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,12 +2,12 @@ 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, ReceptionAnamnesis
 | 
			
		||||
from mods.db import db, Reception, Patient, ReceptionDiagnosis, ReceptionAnamnesis, ReceptionObserve
 | 
			
		||||
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.files import anamnesis_row_ui_str
 | 
			
		||||
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.lists import get_listrecord, get_list_by_system_id, create_open_list_win, ANAMNEZ_LIST
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -64,16 +64,26 @@ class ReceptionAnamnesisRow(Gtk.ListBoxRow):
 | 
			
		|||
    @db_id.setter
 | 
			
		||||
    def db_id_setter(self, value):
 | 
			
		||||
        self._db_id = value
 | 
			
		||||
class ReceptionObserveRow(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 get_reception(reception_id):
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        return Reception.get_by_id(reception_id)
 | 
			
		||||
def get_reception_diagnosisses(reception):
 | 
			
		||||
def get_reception_diagnosis_items(reception):
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        return ReceptionDiagnosis.select().where(ReceptionDiagnosis.reception == reception)
 | 
			
		||||
def get_reception_anamnesisses(reception):
 | 
			
		||||
def get_reception_anamnesis_items(reception):
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        return ReceptionAnamnesis.select().where(ReceptionAnamnesis.reception == reception)
 | 
			
		||||
def get_reception_observe_items(reception):
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        return ReceptionObserve.select().where(ReceptionObserve.reception == reception)
 | 
			
		||||
def delete_reception_diagnosisses(reception, diag_id_list):
 | 
			
		||||
    if not len(diag_id_list): return
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +92,10 @@ 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 delete_reception_observe_symptoms(reception, observe_id_list):
 | 
			
		||||
    if not len(observe_id_list): return
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        ReceptionObserve.delete().where((ReceptionObserve.reception == reception) & (ReceptionObserve.symptom.in_(observe_id_list))).execute()
 | 
			
		||||
def add_reception_diagnosisses(reception, diag_id_list):
 | 
			
		||||
    if not len(diag_id_list): return
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
| 
						 | 
				
			
			@ -92,20 +106,32 @@ def add_reception_anamnesisses(reception, anam_id_list):
 | 
			
		|||
    with db.atomic():
 | 
			
		||||
        inserts = list(map(lambda x: {'reception': reception, 'anamnesis': get_listrecord(x)}, anam_id_list))
 | 
			
		||||
        _ = ReceptionAnamnesis.insert_many(inserts).execute()
 | 
			
		||||
def add_reception_observe_symptoms(reception, observe_id_list):
 | 
			
		||||
    if not len(observe_id_list): return
 | 
			
		||||
    with db.atomic():
 | 
			
		||||
        inserts = list(map(lambda x: {'reception': reception, 'symptom': get_listrecord(x)}, observe_id_list))
 | 
			
		||||
        _ = ReceptionObserve.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)))
 | 
			
		||||
    exist_diags = set(map(lambda x: x.diagnosis.id, get_reception_diagnosis_items(reception)))
 | 
			
		||||
    new_diags = set(diag_id_list)
 | 
			
		||||
    to_del = list(exist_diags - new_diags)
 | 
			
		||||
    to_add = list(new_diags - exist_diags)
 | 
			
		||||
    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)))
 | 
			
		||||
    exist_anams = set(map(lambda x: x.anamnesis.id, get_reception_anamnesis_items(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 save_reception_observe(reception, observe_id_list):
 | 
			
		||||
    exist_symptoms = set(map(lambda x: x.symptom.id, get_reception_observe_items(reception)))
 | 
			
		||||
    new_symptoms = set(observe_id_list)
 | 
			
		||||
    to_del = list(exist_symptoms - new_symptoms)
 | 
			
		||||
    to_add = list(new_symptoms - exist_symptoms)
 | 
			
		||||
    delete_reception_observe_symptoms(reception, to_del)
 | 
			
		||||
    add_reception_observe_symptoms(reception, to_add)
 | 
			
		||||
 | 
			
		||||
##################################################################################
 | 
			
		||||
def build_reception_row(reception_datetime):
 | 
			
		||||
| 
						 | 
				
			
			@ -157,6 +183,17 @@ def build_reception_anamnesis_row(anamnesis):
 | 
			
		|||
    row.props.db_id = anamnesis.id
 | 
			
		||||
    row.add(box)
 | 
			
		||||
    return row
 | 
			
		||||
def build_reception_observe_row(observe):
 | 
			
		||||
    b = Gtk.Builder()
 | 
			
		||||
    b.add_from_string(observe_row_ui_str)
 | 
			
		||||
    win = b.get_object('win')
 | 
			
		||||
    box = b.get_object('observe_box')
 | 
			
		||||
    b.get_object('title').set_text(f'{observe.text}')
 | 
			
		||||
    win.remove(win.get_children()[0])
 | 
			
		||||
    row = ReceptionObserveRow()
 | 
			
		||||
    row.props.db_id = observe.id
 | 
			
		||||
    row.add(box)
 | 
			
		||||
    return row
 | 
			
		||||
def create_open_reception_win():
 | 
			
		||||
    b = Gtk.Builder()
 | 
			
		||||
    reception_list = builder.get_object('reception_list')
 | 
			
		||||
| 
						 | 
				
			
			@ -170,6 +207,10 @@ def create_open_reception_win():
 | 
			
		|||
            anam_db_list = get_list_by_system_id(ANAMNEZ_LIST)
 | 
			
		||||
            choose_anamnesis_win = create_open_list_win(anam_db_list.id, choose=True, parent_list=reception_anam_list)
 | 
			
		||||
            choose_anamnesis_win.show_all()
 | 
			
		||||
        def show_choose_observe_win(self, button):
 | 
			
		||||
            observe_db_list = get_list_by_system_id(OBSERVE_LIST)
 | 
			
		||||
            choose_symptom_win = create_open_list_win(observe_db_list.id, choose=True, parent_list=reception_observe_list)
 | 
			
		||||
            choose_symptom_win.show_all()
 | 
			
		||||
        def remove_diagnosis(self, button):
 | 
			
		||||
            row = reception_diag_list.get_selected_row()
 | 
			
		||||
            reception_diag_list.remove(row)
 | 
			
		||||
| 
						 | 
				
			
			@ -180,10 +221,17 @@ def create_open_reception_win():
 | 
			
		|||
            reception_anam_list.remove(row)
 | 
			
		||||
            disable_widget([remove_anam_button])
 | 
			
		||||
            reception_anam_list.show_all()
 | 
			
		||||
        def remove_observe(self, button):
 | 
			
		||||
            row = reception_observe_list.get_selected_row()
 | 
			
		||||
            reception_observe_list.remove(row)
 | 
			
		||||
            disable_widget([remove_observe_button])
 | 
			
		||||
            reception_observe_list.show_all()
 | 
			
		||||
        def diagnosis_selected(self, *s):
 | 
			
		||||
            enable_widget([remove_diag_button])
 | 
			
		||||
        def anamnesis_selected(self, *a):
 | 
			
		||||
            enable_widget([remove_anam_button])
 | 
			
		||||
        def observe_selected(self, *a):
 | 
			
		||||
            enable_widget([remove_observe_button])
 | 
			
		||||
        def save(self, button):
 | 
			
		||||
            # Диагнозы
 | 
			
		||||
            diag_id_list = list(map(lambda x: x.props.db_id, reception_diag_list.get_children()))
 | 
			
		||||
| 
						 | 
				
			
			@ -193,6 +241,10 @@ def create_open_reception_win():
 | 
			
		|||
            anam_id_list = list(map(lambda x: x.props.db_id, reception_anam_list.get_children()))
 | 
			
		||||
            save_reception_anamnesisses(reception, anam_id_list)
 | 
			
		||||
            #######
 | 
			
		||||
            # Осмотр
 | 
			
		||||
            observe_id_list = list(map(lambda x: x.props.db_id, reception_observe_list.get_children()))
 | 
			
		||||
            save_reception_observe(reception, observe_id_list)
 | 
			
		||||
            #######
 | 
			
		||||
            w.destroy()
 | 
			
		||||
    b.add_from_file(open_reception_win_file)
 | 
			
		||||
    b.connect_signals(OpenReceptionWinHandler())
 | 
			
		||||
| 
						 | 
				
			
			@ -203,14 +255,20 @@ 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')
 | 
			
		||||
    reception_anam_list = b.get_object('anamnesis_list')
 | 
			
		||||
    reception_observe_list = b.get_object('observe_list')
 | 
			
		||||
    remove_diag_button = b.get_object('remove_diag_button')
 | 
			
		||||
    remove_anam_button = b.get_object('remove_anam_button')
 | 
			
		||||
    # Анамнезы
 | 
			
		||||
    for ra in [x.anamnesis for x in get_reception_anamnesisses(reception)]:
 | 
			
		||||
    remove_observe_button = b.get_object('remove_observe_button')
 | 
			
		||||
    # Анамнез
 | 
			
		||||
    for ra in [x.anamnesis for x in get_reception_anamnesis_items(reception)]:
 | 
			
		||||
        reception_anam_list.add(build_reception_anamnesis_row(ra))
 | 
			
		||||
    #
 | 
			
		||||
    # Осмотр
 | 
			
		||||
    for ro in [x.symptom for x in get_reception_observe_items(reception)]:
 | 
			
		||||
        reception_observe_list.add(build_reception_observe_row(ro))
 | 
			
		||||
    #
 | 
			
		||||
    # Диагнозы
 | 
			
		||||
    for rd in [x.diagnosis for x in get_reception_diagnosisses(reception)]:
 | 
			
		||||
    for rd in [x.diagnosis for x in get_reception_diagnosis_items(reception)]:
 | 
			
		||||
        reception_diag_list.add(build_reception_diagnosis_row(rd))
 | 
			
		||||
    #
 | 
			
		||||
    w = b.get_object('open_reception_window')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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="observe_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>
 | 
			
		||||
| 
						 | 
				
			
			@ -316,6 +316,7 @@
 | 
			
		|||
                                  <object class="GtkListBox" id="observe_list">
 | 
			
		||||
                                    <property name="visible">True</property>
 | 
			
		||||
                                    <property name="can_focus">False</property>
 | 
			
		||||
                                    <signal name="row-selected" handler="observe_selected" swapped="no"/>
 | 
			
		||||
                                  </object>
 | 
			
		||||
                                </child>
 | 
			
		||||
                              </object>
 | 
			
		||||
| 
						 | 
				
			
			@ -348,6 +349,7 @@
 | 
			
		|||
                                <property name="visible">True</property>
 | 
			
		||||
                                <property name="can_focus">True</property>
 | 
			
		||||
                                <property name="receives_default">True</property>
 | 
			
		||||
                                <signal name="clicked" handler="show_choose_observe_win" swapped="no"/>
 | 
			
		||||
                                <child>
 | 
			
		||||
                                  <object class="GtkImage">
 | 
			
		||||
                                    <property name="visible">True</property>
 | 
			
		||||
| 
						 | 
				
			
			@ -364,11 +366,12 @@
 | 
			
		|||
                              </packing>
 | 
			
		||||
                            </child>
 | 
			
		||||
                            <child>
 | 
			
		||||
                              <object class="GtkButton">
 | 
			
		||||
                              <object class="GtkButton" id="remove_observe_button">
 | 
			
		||||
                                <property name="visible">True</property>
 | 
			
		||||
                                <property name="sensitive">False</property>
 | 
			
		||||
                                <property name="can_focus">True</property>
 | 
			
		||||
                                <property name="receives_default">True</property>
 | 
			
		||||
                                <signal name="clicked" handler="remove_observe" swapped="no"/>
 | 
			
		||||
                                <child>
 | 
			
		||||
                                  <object class="GtkImage">
 | 
			
		||||
                                    <property name="visible">True</property>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue