2020-05-04 15:48:28 +03:00
|
|
|
from mods.db import db, Settings, Diag, DiagCategory, diag_db, Diagnosis, DiagnosisCategory, DiagnosisIndex, rls_db, RlsInit, RlsInitCountry
|
2020-05-04 20:30:32 +03:00
|
|
|
from mods.db import RlsInitPharmacoTherapeuticGroup, Rls, RlsCountry, RlsPharmacoTherapeuticGroup, RlsIndex
|
2019-11-12 19:30:17 +03:00
|
|
|
|
|
|
|
# Имена ключей параметров
|
|
|
|
S_KEY_RECEPTION_LIST = 'reception_list'
|
|
|
|
S_RECEPTION_LIST_DAY_START = 'day_start'
|
|
|
|
S_RECEPTION_LIST_DAY_END = 'day_end'
|
|
|
|
S_RECEPTION_LIST_INTERVAL = 'interval'
|
|
|
|
|
|
|
|
# Получение параметров
|
|
|
|
def s_get_reception_list():
|
|
|
|
class RLSettings:
|
|
|
|
day_start = None
|
|
|
|
day_end = None
|
|
|
|
interval = None
|
2019-11-19 15:37:53 +03:00
|
|
|
s = Settings.get(Settings.key == S_KEY_RECEPTION_LIST).val
|
2019-11-12 19:30:17 +03:00
|
|
|
o = RLSettings()
|
|
|
|
o.day_start = s[S_RECEPTION_LIST_DAY_START]
|
|
|
|
o.day_end = s[S_RECEPTION_LIST_DAY_END]
|
|
|
|
o.interval = s[S_RECEPTION_LIST_INTERVAL]
|
|
|
|
return o
|
|
|
|
# Установка параметров
|
|
|
|
def s_set_reception_list(dstart, dend, interval):
|
|
|
|
v = {
|
|
|
|
S_RECEPTION_LIST_DAY_START: dstart,
|
|
|
|
S_RECEPTION_LIST_DAY_END: dend,
|
|
|
|
S_RECEPTION_LIST_INTERVAL: interval
|
|
|
|
}
|
2019-11-19 15:37:53 +03:00
|
|
|
with db.atomic():
|
|
|
|
q = Settings.select().where(Settings.key == S_KEY_RECEPTION_LIST)
|
2019-11-12 19:30:17 +03:00
|
|
|
if not len(q):
|
2019-11-19 15:37:53 +03:00
|
|
|
Settings.create(key=S_KEY_RECEPTION_LIST, val=v)
|
2019-11-12 19:30:17 +03:00
|
|
|
else:
|
2019-11-19 15:37:53 +03:00
|
|
|
Settings.update(val=v).where(Settings.key == S_KEY_RECEPTION_LIST).execute()
|
2019-11-12 19:30:17 +03:00
|
|
|
|
|
|
|
### Инициализация начальных значений параметров
|
|
|
|
# Начальный график приёмов
|
2019-11-19 15:37:53 +03:00
|
|
|
with db.atomic():
|
|
|
|
q = Settings.select().where(Settings.key == S_KEY_RECEPTION_LIST)
|
2019-11-12 19:30:17 +03:00
|
|
|
if not len(q):
|
|
|
|
s_set_reception_list([8,0], [17,0], 30)
|
2019-12-24 13:19:35 +03:00
|
|
|
##########################
|
2019-12-17 13:28:52 +03:00
|
|
|
# Загрузка диагнозов МКБ 10
|
2020-05-03 18:40:31 +03:00
|
|
|
q = Diagnosis.select().limit(10)
|
2019-12-17 13:28:52 +03:00
|
|
|
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,
|
2019-12-24 13:19:35 +03:00
|
|
|
DiagnosisIndex.code: new_diag.code,
|
2019-12-17 13:28:52 +03:00
|
|
|
DiagnosisIndex.title: new_diag.title
|
|
|
|
}).execute()
|
|
|
|
del __subcat_map_
|
|
|
|
del __root_cat_map_
|
|
|
|
diag_db.close()
|
2019-12-24 13:19:35 +03:00
|
|
|
###########################
|
2020-05-04 15:48:28 +03:00
|
|
|
q = Rls.select().limit(10)
|
|
|
|
if not len(q):
|
|
|
|
rls_db.connect()
|
|
|
|
__rls_ptg_map_ = {}
|
|
|
|
for ptg in RlsInitPharmacoTherapeuticGroup.select():
|
2020-05-04 20:30:32 +03:00
|
|
|
__rls_ptg_map_[ptg] = RlsPharmacoTherapeuticGroup.create(title=ptg.title)
|
|
|
|
for ptg in __rls_ptg_map_.keys():
|
|
|
|
for ls in RlsInit.select().where(RlsInit.pharmacotherapeuticgroup == ptg):
|
|
|
|
q = RlsCountry.select().where(RlsCountry.title == ls.country.title)
|
|
|
|
if len(q):
|
|
|
|
cnt = q.get()
|
|
|
|
else:
|
|
|
|
cnt = RlsCountry.create(title=ls.country.title)
|
|
|
|
new_rls = Rls.create(
|
|
|
|
regnumber=ls.regnumber,
|
|
|
|
regdate=ls.regdate,
|
|
|
|
enddate=ls.enddate,
|
|
|
|
cancellationdate=ls.cancellationdate,
|
|
|
|
nameregcertificate=ls.nameregcertificate,
|
|
|
|
country=cnt,
|
|
|
|
tradename=ls.tradename,
|
|
|
|
internationalname=ls.internationalname,
|
|
|
|
formrelease=ls.formrelease,
|
|
|
|
stages=ls.stages,
|
|
|
|
barcodes=ls.barcodes,
|
|
|
|
normativedocumentation=ls.normativedocumentation,
|
|
|
|
pharmacotherapeuticgroup=__rls_ptg_map_[ptg]
|
|
|
|
)
|
|
|
|
RlsIndex.insert({
|
|
|
|
RlsIndex.rowid: new_rls.id,
|
|
|
|
RlsIndex.tradename: new_rls.tradename,
|
|
|
|
RlsIndex.internationalname: new_rls.internationalname
|
|
|
|
}).execute()
|
|
|
|
del __rls_ptg_map_
|
|
|
|
rls_db.close()
|
2020-05-04 15:48:28 +03:00
|
|
|
###########################
|