From d51402e91bb3de5c06faec9eeee3610ce95cbd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD?= Date: Mon, 4 May 2020 20:30:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87=D0=BD=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=A0=D0=9B=D0=A1=20=D0=B8=D0=B7=20=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BE=D1=87=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mods/db.py | 8 +++++--- mods/settings.py | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/mods/db.py b/mods/db.py index 5edc0d7..3e792f3 100644 --- a/mods/db.py +++ b/mods/db.py @@ -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 ]) diff --git a/mods/settings.py b/mods/settings.py index 2099210..6e2d109 100644 --- a/mods/settings.py +++ b/mods/settings.py @@ -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() ###########################