Загрузка справочника РЛС из установочной БД

This commit is contained in:
Роман Бородин 2020-05-04 20:30:32 +03:00
parent 340872a85d
commit d51402e91b
2 changed files with 36 additions and 9 deletions

View File

@ -170,17 +170,18 @@ class Rls(BaseModel):
enddate = DateField(null=True, help_text='Дата окончания действия регистрационного удостоверения')
cancellationdate = DateField(null=True, help_text='Дата аннулирования регистрационного удостоверения')
nameregcertificate = TextField(null=True, help_text='Юридическое лицо, на имя которого выдано регистрационное удостоверение')
country = ForeignKeyField(RlsInitCountry, backref='rlsinit', help_text='Страна производства')
country = ForeignKeyField(RlsCountry, backref='rlsinit', help_text='Страна производства')
tradename = TextField(null=True, help_text='Торговое наименование лекарственного средства')
internationalname = TextField(null=True, help_text='Международное непатентованное или химическое наименование лекарственного средства')
formrelease = TextField(null=True, help_text='Формы выпуска')
stages = TextField(null=True, help_text='Сведения о стадиях производства')
barcodes = TextField(null=True, help_text='Штрих-коды потребительской упаковки')
normativedocumentation = TextField(null=True, help_text='Нормативная документация')
pharmacotherapeuticgroup = ForeignKeyField(RlsInitPharmacoTherapeuticGroup, backref='rlsinit', help_text='Фармако-терапевтическая группа')
pharmacotherapeuticgroup = ForeignKeyField(RlsPharmacoTherapeuticGroup, backref='rlsinit', help_text='Фармако-терапевтическая группа')
class RlsIndex(BaseFTSModel):
rowid = RowIDField()
tradename = SearchField()
internationalname = SearchField()
### Настройки
class Settings(BaseModel):
key = TextField()
@ -215,5 +216,6 @@ db.create_tables([
RlsPharmacoTherapeuticGroup,
RlsCountry,
Rls,
RlsIndex,
Settings
])

View File

@ -1,5 +1,5 @@
from mods.db import db, Settings, Diag, DiagCategory, diag_db, Diagnosis, DiagnosisCategory, DiagnosisIndex, rls_db, RlsInit, RlsInitCountry
from mods.db import RlsInitPharmacoTherapeuticGroup, Rls, RlsCountry, RlsPharmacoTherapeuticGroup
from mods.db import RlsInitPharmacoTherapeuticGroup, Rls, RlsCountry, RlsPharmacoTherapeuticGroup, RlsIndex
# Имена ключей параметров
S_KEY_RECEPTION_LIST = 'reception_list'
@ -68,10 +68,35 @@ q = Rls.select().limit(10)
if not len(q):
rls_db.connect()
__rls_ptg_map_ = {}
__rls_cnt_map = {}
for ptg in RlsInitPharmacoTherapeuticGroup.select():
__rls_ptg_map_[ptg.title] = RlsPharmacoTherapeuticGroup.create(title=ptg.title)
for cnt in RlsCountry.select():
__rls_cnt_map[cnt.title] = RlsCountry.create(title=cnt.title)
__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()
###########################