Created
November 12, 2019 10:44
-
-
Save atronah/adfdd71b61c4e3fd90c9861f3d3319c6 to your computer and use it in GitHub Desktop.
РЕГИЗ.Справочники: Шаблон добавления правила загрузки справочника в SynManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Скрипт добавления правила загрузки справочника из РЕГИЗ. | |
Загрузка подразумевается через `SyncManager.exe` в режиме `Справочнике FHIR (API)` | |
из Сервиса Терминологии РЕГИЗ: | |
- Web-интерфейс тестового стенда: `http://r78-rc.zdrav.netrika.ru/nsiui` | |
- RESTful Сервис тестового стенда: `http://r78-rc.zdrav.netrika.ru/nsi/fhir/term` | |
В скрипте необходимо заменить следующие `placeholder`-ы: | |
- <oid> - OID справочника | |
- <refbook_title> - Название справочника | |
- <refbook_name> - Название справочника латиницей с учетом ограничения именования объектов в СУБД FB | |
- <refbook_comment> - Описание справочника | |
*/ | |
set term ^ ; | |
-- Добавление настроек для мастера синхронизации | |
execute block | |
as | |
-- Переменные для повторяющихся строковых констант, используемых для поиска записей | |
declare GROUP_CODE type of column sync_reference.refcode = 'mds_nterm_group'; | |
declare endl varchar(2) = ' | |
'; | |
begin | |
-- Добавление раздела с настройками справочников сервиса Терминологии | |
merge into sync_reference as cur | |
using (select | |
:GROUP_CODE as refcode | |
, 'РЕГИЗ. Сервис Терминологии' as refname | |
, 'Группа правил для синхронизации справочников с сервисом Терминологии от РЕГИЗ (http://api.netrika.ru/docs.php?article=Terminology)' as refcomment | |
from rdb$database | |
) as upd | |
on cur.refcode = upd.refcode | |
when matched then update set | |
refname = upd.refname | |
, refcomment = upd.refcomment | |
when not matched then insert (syncrefid, refcode, refname, refcomment, grouptype) | |
values (next value for sync_reference_gen, upd.refcode, upd.refname, upd.refcomment, 1); | |
-- Добавление самих правил загрузки | |
merge into sync_reference as cur | |
using (select | |
trim(refs.refcode) as refcode | |
, trim(refs.refname) as refname | |
, trim(refs.reftable) as reftable | |
, trim(refs.refmask) as refmask | |
, trim(refs.refencoding) as refencoding | |
, trim(refs.refcomment) as refcomment | |
, trim(refs.refhandler) as refhandler | |
, refs.reftype as reftype | |
, refs.tid | |
, parent_ref.syncrefid as parentrefid | |
from sync_reference as parent_ref | |
inner join (select | |
'<oid>' as refcode | |
, 'Справочник "<refbook_title>" (<oid>) ' as refname | |
, 'mds_nterm_<refbook_name>' as reftable | |
, 'mds_nterm_<refbook_name>_loader' as refhandler | |
, null as refmask | |
, null as refencoding | |
, '<refbook_comment>' as refcomment | |
, 10 as reftype -- 10 - Справочники FHIR | |
, 78 as tid -- привязка к 78 региону | |
from rdb$database | |
) as refs on 1 = 1 | |
where upper(parent_ref.refcode) = upper(:GROUP_CODE) | |
) as upd | |
on cur.refcode = upd.refcode | |
when matched then update set | |
refname = upd.refname | |
, reftable = upd.reftable | |
, refhandler = upd.refhandler | |
, refmask = upd.refmask | |
, refencoding = upd.refencoding | |
, refcomment = upd.refcomment | |
, reftype = upd.reftype | |
, tid = upd.tid | |
, parentrefid = upd.parentrefid | |
when not matched then insert (syncrefid, grouptype, tid, reftype, parentrefid | |
, refcode, refname, reftable, refmask, refencoding | |
, refcomment, refhandler | |
) | |
values (next value for sync_reference_gen, 0, upd.tid, upd.reftype, upd.parentrefid | |
, upd.refcode, upd.refname, upd.reftable, upd.refmask, upd.refencoding | |
, upd.refcomment, upd.refhandler | |
); | |
end^ | |
set term ; ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment