eldoc/mods/catalogs.py

34 lines
1.2 KiB
Python

from mods.db import dbo
sys_catalogs = {
'diagnoz': 'Диагноз',
'anamnez': 'Анамнез',
'observ': 'Осмотр',
'druggs': 'Медикаменты'
}
def add_catalog(name, system_id = ''):
catalog = dbo._Catalog.create(name=name, system_id=system_id) # @UndefinedVariable
dbo._CatalogIndex.insert( # @UndefinedVariable
{
dbo._CatalogIndex.rowid: catalog.id,
dbo._CatalogIndex.text: name
}
).execute() # @UndefinedVariable
return catalog
def search_catalogs(q):
with dbo.db.atomic():
return (dbo._Catalog.select() # @UndefinedVariable
.join( # @UndefinedVariable
dbo._CatalogIndex,
on=(dbo._Catalog.id == dbo._CatalogIndex.rowid))
.where(dbo._CatalogIndex.match(q)) # @UndefinedVariable
.order_by(dbo._CatalogIndex.bm25())) # @UndefinedVariable
for s_id in sys_catalogs:
with dbo.db.atomic():
q = dbo._Catalog.select().where(dbo._Catalog.system_id == s_id) # @UndefinedVariable
if not len(q):
add_catalog(sys_catalogs[s_id], s_id) # @UndefinedVariable