Загружаем в БД справочник МБК 10 при первом запуске
This commit is contained in:
parent
9dba62b751
commit
e26e20662c
2
app.py
2
app.py
|
@ -102,8 +102,6 @@ class MainWinHandler:
|
||||||
self.catalog_list_unselected()
|
self.catalog_list_unselected()
|
||||||
cl.invalidate_filter()
|
cl.invalidate_filter()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_sort_func(row1, row2, *a):
|
def list_sort_func(row1, row2, *a):
|
||||||
text1 = row1.props.name
|
text1 = row1.props.name
|
||||||
text2 = row2.props.name
|
text2 = row2.props.name
|
||||||
|
|
39
mods/db.py
39
mods/db.py
|
@ -2,6 +2,7 @@ import os
|
||||||
from peewee import Model, CharField, DateTimeField, TextField, ForeignKeyField, DateField, fn, BooleanField
|
from peewee import Model, CharField, DateTimeField, TextField, ForeignKeyField, DateField, fn, BooleanField
|
||||||
from playhouse.sqlite_ext import CSqliteExtDatabase, FTS5Model, AutoIncrementField, SearchField, RowIDField, JSONField
|
from playhouse.sqlite_ext import CSqliteExtDatabase, FTS5Model, AutoIncrementField, SearchField, RowIDField, JSONField
|
||||||
import platform
|
import platform
|
||||||
|
from mods.files import init_db_dir
|
||||||
|
|
||||||
if 'windows' in platform.system().lower():
|
if 'windows' in platform.system().lower():
|
||||||
user_dir = os.path.abspath(os.environ['APPDATA'])
|
user_dir = os.path.abspath(os.environ['APPDATA'])
|
||||||
|
@ -17,6 +18,29 @@ if not os.path.exists(var_dir):
|
||||||
if not os.path.exists(db_dir):
|
if not os.path.exists(db_dir):
|
||||||
os.mkdir(db_dir)
|
os.mkdir(db_dir)
|
||||||
|
|
||||||
|
###################################################################
|
||||||
|
diag_db_file = os.path.join(init_db_dir, 'diag.db')
|
||||||
|
diag_db = CSqliteExtDatabase(diag_db_file, pragmas={
|
||||||
|
'foreign_keys': 'on',
|
||||||
|
'ignore_check_constraints': 'off'})
|
||||||
|
|
||||||
|
class DiagBaseModel(Model):
|
||||||
|
'Базовая таблица'
|
||||||
|
class Meta:
|
||||||
|
database = diag_db
|
||||||
|
|
||||||
|
class DiagCategory(DiagBaseModel):
|
||||||
|
id = AutoIncrementField()
|
||||||
|
parent = ForeignKeyField('self', null=True, backref='subcat')
|
||||||
|
title = TextField()
|
||||||
|
class Diag(DiagBaseModel):
|
||||||
|
id = AutoIncrementField()
|
||||||
|
category = ForeignKeyField(DiagCategory, backref='diagnosis')
|
||||||
|
code = CharField(32)
|
||||||
|
title = TextField()
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
|
||||||
db = CSqliteExtDatabase(db_file, pragmas={
|
db = CSqliteExtDatabase(db_file, pragmas={
|
||||||
'journal_mode': 'wal',
|
'journal_mode': 'wal',
|
||||||
'cache_size': -1 * 64000, # 64MB
|
'cache_size': -1 * 64000, # 64MB
|
||||||
|
@ -74,6 +98,18 @@ class Reception(BaseModel):
|
||||||
patient = ForeignKeyField(Patient, backref='receptions', on_delete='CASCADE')
|
patient = ForeignKeyField(Patient, backref='receptions', on_delete='CASCADE')
|
||||||
time = DateTimeField()
|
time = DateTimeField()
|
||||||
attended = BooleanField(default=False)
|
attended = BooleanField(default=False)
|
||||||
|
class DiagnosisCategory(BaseModel):
|
||||||
|
id = AutoIncrementField()
|
||||||
|
parent = ForeignKeyField('self', null=True, backref='subcat')
|
||||||
|
title = TextField()
|
||||||
|
class Diagnosis(BaseModel):
|
||||||
|
id = AutoIncrementField()
|
||||||
|
category = ForeignKeyField(DiagnosisCategory, backref='diagnosis')
|
||||||
|
code = CharField(32)
|
||||||
|
title = TextField()
|
||||||
|
class DiagnosisIndex(BaseFTSModel):
|
||||||
|
rowid = RowIDField()
|
||||||
|
title = SearchField()
|
||||||
class ReceptionDiagnosis(BaseModel):
|
class ReceptionDiagnosis(BaseModel):
|
||||||
id = AutoIncrementField()
|
id = AutoIncrementField()
|
||||||
reception = ForeignKeyField(Reception, backref='reception_diagnosisses', on_delete='CASCADE')
|
reception = ForeignKeyField(Reception, backref='reception_diagnosisses', on_delete='CASCADE')
|
||||||
|
@ -106,6 +142,9 @@ db.create_tables([
|
||||||
CatalogIndex,
|
CatalogIndex,
|
||||||
CatalogRecord,
|
CatalogRecord,
|
||||||
CatalogRecordIndex,
|
CatalogRecordIndex,
|
||||||
|
DiagnosisCategory,
|
||||||
|
Diagnosis,
|
||||||
|
DiagnosisIndex,
|
||||||
Reception,
|
Reception,
|
||||||
ReceptionDiagnosis,
|
ReceptionDiagnosis,
|
||||||
ReceptionAnamnesis,
|
ReceptionAnamnesis,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'res')
|
resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'res')
|
||||||
|
init_db_dir = os.path.join(resource_dir, 'initdb')
|
||||||
ui_dir = os.path.join(resource_dir, 'ui')
|
ui_dir = os.path.join(resource_dir, 'ui')
|
||||||
icon_dir = os.path.join(resource_dir, 'icons')
|
icon_dir = os.path.join(resource_dir, 'icons')
|
||||||
list_row_file = os.path.join(ui_dir, 'list_row.glade')
|
list_row_file = os.path.join(ui_dir, 'list_row.glade')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from mods.db import db, Settings
|
from mods.db import db, Settings, Diag, DiagCategory, diag_db, Diagnosis, DiagnosisCategory, DiagnosisIndex
|
||||||
|
|
||||||
# Имена ключей параметров
|
# Имена ключей параметров
|
||||||
S_KEY_RECEPTION_LIST = 'reception_list'
|
S_KEY_RECEPTION_LIST = 'reception_list'
|
||||||
|
@ -38,3 +38,25 @@ with db.atomic():
|
||||||
q = Settings.select().where(Settings.key == S_KEY_RECEPTION_LIST)
|
q = Settings.select().where(Settings.key == S_KEY_RECEPTION_LIST)
|
||||||
if not len(q):
|
if not len(q):
|
||||||
s_set_reception_list([8,0], [17,0], 30)
|
s_set_reception_list([8,0], [17,0], 30)
|
||||||
|
# Загрузка диагнозов МКБ 10
|
||||||
|
q = Diagnosis.select()
|
||||||
|
if not len(q):
|
||||||
|
diag_db.connect()
|
||||||
|
__root_cat_map_ = {}
|
||||||
|
__subcat_map_ = {}
|
||||||
|
for root_cat in DiagCategory.select().where(DiagCategory.parent == None):
|
||||||
|
__root_cat_ = DiagnosisCategory.create(title=root_cat.title)
|
||||||
|
__root_cat_map_[root_cat] = __root_cat_
|
||||||
|
for root_cat in __root_cat_map_.keys():
|
||||||
|
for sc in DiagCategory.select().where(DiagCategory.parent == root_cat):
|
||||||
|
__subcat_ = DiagnosisCategory.create(parent=__root_cat_map_[root_cat], title=sc.title)
|
||||||
|
__subcat_map_[sc] = __subcat_
|
||||||
|
for diag in Diag.select().where(Diag.category == sc):
|
||||||
|
new_diag = Diagnosis.create(category=__subcat_map_[sc], code=diag.code, title=diag.title)
|
||||||
|
DiagnosisIndex.insert({
|
||||||
|
DiagnosisIndex.rowid: new_diag.id,
|
||||||
|
DiagnosisIndex.title: new_diag.title
|
||||||
|
}).execute()
|
||||||
|
del __subcat_map_
|
||||||
|
del __root_cat_map_
|
||||||
|
diag_db.close()
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue