Спецификация метода доступна по ссылке.
Внутренняя логика:
На БД указанной ЛПУ выполняется следующий запрос
select distinct kl_NomServiceID as id,oms_kl_NomService.code as code, oms_kl_NomService.name as from lbr_ResearchType lbr with (NOLOCK) inner join oms_kl_NomService with (NOLOCK) on rf_kl_NomServiceID = kl_NomServiceID where lbr.rf_kl_NomServiceID > 0 |
Спецификация метода доступна по ссылке.
Внутренняя логика:
1) Получение полезной нагрузки из CodToken;
2) Получение списка ЛПУ-МКАБ через PersonClient;
3) Через multiTicketIemkClient собираем данные о направлениях по всем ЛПУ пациента:
3.1) Пытаемся получить MKABID в БД ЛПУ по Guid из МИП. Если не получилось - статус 400;
3.2) Получаем направления на консультации и исследования по MKABID следующим запросом:
declare @@mkabID int = @0 select convert(varchar(50), dir.GUID) as Guid, dir.Num as Number, 'consultation' as typeDirection, 'консультации узкопрофильных специалистов' typeName, convert(datetime, dir.Date) DateBeginDirection, convert(datetime, dateAdd(month, 1, dir.Date)) as DateEndDirection, prvs.C_PRVS as CodeEvent, prvs.PRVS_NAME as NameEvent, prvd.GUID as doctorSourceGuid, prvs.C_PRVS as SpecialityCodeDestination, dir.rf_lpuSenderID LpuSourceId, dir.rf_lpuID LpuDestinationId from hlt_direction dir with (NOLOCK) inner join hlt_Typedirection typ with (NOLOCK) on typ.TypeDirectionID = dir.rf_TypeDirectionID inner join oms_PRVS prvs with (NOLOCK) on dir.rf_PRVSID = prvs.PRVSID inner join oms_lpu lpufrom with (NOLOCK) on lpuFrom.LPUID = dir.rf_LPUSenderID inner join hlt_DocPRVD prvd with (NOLOCK) on prvd.DocPRVDID = dir.rf_DocPRVDID inner join oms_lpu lputo with (NOLOCK) on lputo.LPUID = dir.rf_LPUID where dateAdd(month, 1, dir.Date) > getdate() and prvs.PRVSID > 0 and typ.Cod = 3 AND dir.rf_MKABID = @@mkabID union all Select convert(varchar(50), dir.GUID) as Guid, dir.Number as Number, 'diagnostic' as typeDirection, 'клинико-диагностические исследования' typeName, convert(datetime, dir.Date_Direction) DateBeginDirection, convert(datetime, dateAdd(month, 1, dir.Date_Direction)) as DateEndDirection, nomservice.CODE as CodeEvent, nomservice.NAME as NameEvent, docFrom.UGUID as doctorSourceGuid, '' as SpecialityCodeDestination, dir.rf_LPUSenderID LpuSourceId, dir.rf_lpuID LpuDestinationId from lbr_LaboratoryResearch dir with (NOLOCK) inner join lbr_Research reseach with (NOLOCK) on reseach.rf_LaboratoryResearchGUID = dir.GUID inner join lbr_ResearchType reseachType with (NOLOCK) on reseachType.UGUID = reseach.rf_ResearchTypeUGUID inner join oms_kl_NomService nomservice with (NOLOCK) on nomservice.kl_NomServiceID = reseachType.rf_kl_NomServiceID inner join hlt_LPUDoctor docFrom with (NOLOCK) on docFrom.LPUDoctorID = dir.rf_LPUDoctorID where DATEDiff(month, Date_Direction, GETDATE()) < 1 and nomservice.kl_NomServiceID>0 AND dir.rf_MKABID = @@mkabID |
3.3) Получаем "направления" по диспансерному учёту по MKABID следующим запросом:
declare @@mkabID int = @0 Select convert(varchar(50), dir.GUID) as Guid, '' as Number, 'duvisit' as typeDirection, 'диспансерное наблюдение' typeName, convert(datetime, dir.DateRegistration) DateBeginDirection, convert(datetime, dateAdd(month, 1, dir.Dateoff)) as DateEndDirection, prvs.C_PRVS as CodeEvent, prvs.PRVS_NAME as NameEvent, docFrom.UGUID as doctorSourceGuid, prvs.C_PRVS as SpecialityCodeDestination, dir.rf_lpuID LpuSourceId, dir.rf_lpuID LpuDestinationId from hlt_RegMedicalCheck dir with (NOLOCK) inner join hlt_LPUDoctor docFrom with (NOLOCK) on docFrom.LPUDoctorID = dir.rf_LPUDoctorID inner join oms_Prvs prvs with (NOLOCK) on prvs.PrvsID = dir.rf_prvsID where dir.rf_MKABID = @@mkabID and Dateoff >= getdate() and dir.rf_LPUID > 0 and dir.rf_PRVSID > 0 |
3.4) Сортируем данные по диспансерному учёту по дате начала, группируем по врачу и объединяем со списком направлений на консультации и исследования;
3.5) Далее для всех направлений проставляется TicketGuid, LpuDestinationGuid и LpuSourceGuid:
* Для typeDirection = "duvisit" - string.Empty;
* Для typeDirection = "diagnostic" - результат выполнения запроса:
select case when dtt.Begin_Time > getdate() then CONVERT(varchar(36), docvisit.UGUID) else '0' end from lbr_LaboratoryResearch dir with (NOLOCK) inner join hlt_ActionSchedule actSched with (NOLOCK) on actSched.rf_DocTypeID = dir.LaboratoryResearchID and DocTypeDefID = 586 inner join hlt_DoctorVisitTable docvisit with (NOLOCK) on docvisit.DoctorVisitTableID = actSched.rf_DoctorVisitTableID inner join hlt_DoctorTimeTable dtt with (NOLOCK) on docvisit.rf_DoctorTimeTableID = dtt.DoctorTimeTableID where dir.GUID = @0 |
* Для typeDirection = "consultation" - результат выполнения запроса:
select case when dtt.Begin_Time > getdate() then CONVERT(varchar(36), docvisit.UGUID) else '0' end from hlt_direction dir with (NOLOCK) left join hlt_DoctorVisitTable docvisit with (NOLOCK) on docvisit.rf_DirectionID = dir.DirectionID inner join hlt_DoctorTimeTable dtt with (NOLOCK) on docvisit.rf_DoctorTimeTableID = dtt.DoctorTimeTableID where dir.GUID = @0 |
* ЛПУ источник направления и ЛПУ назначения получаются следующим запросом:
Select GUIDLPU GuidLpu from oms_Lpu where LpuID = @0 |
3.6) Удаляем все направления, где TicketGuid = "0"
4) Получаем информацию о врачах по направлениям следующим запросом:
Select hlt_LPUDoctor.UGUID Guid, IM_V Name, FAM_V SurName, OT_V Lastname, oms_PRVD.Name Role, oms_PRVS.prvs_name Speciality from hlt_LPUDoctor with (NOLOCK) inner join oms_lpu with (NOLOCK) on rf_LpuID = LpuID inner join hlt_DocPRVD with (NOLOCK) ON hlt_DocPRVD.rf_LPUDoctorID=hlt_LPUDoctor.LPUDoctorID inner join oms_PRVD with (NOLOCK) ON hlt_DocPRVD.rf_PRVDID = PRVDID inner join oms_PRVS with (NOLOCK) ON hlt_DocPRVD.rf_PRVSID = PRVSID where hlt_DocPRVD.GUID = @0 |
5) Удаляем дубли направлений из списка
Спецификация метода доступна по ссылке.
Внутренняя логика:
1) Валидация CodToken;
2) Получение списка LpuPrvd по направлению:
* Для directionType = "diagnostic" получение происходит следующим запросом в ЦОД:
Select distinct prvd.GUID Prvd, lpu.GUIDLPU Lpu from hlt_DocPRVD prvd with (NOLOCK) inner join hlt_DocPrvdNomService docnom with (NOLOCK) on docnom.rf_DocPRVDID = prvd.DocPRVDID inner join oms_kl_NomService nom with (NOLOCK) on nom.kl_NomServiceID = docnom.rf_kl_NomServiceID inner join oms_Department dep with (NOLOCK) on rf_DepartmentID = DepartmentID inner join oms_Lpu lpu with (NOLOCK) on lpu.LpuID = dep.rf_LPUID where nom.CODE = '{0}' |
* При остальных типах получение происходит следующим запросом в ЦОД:
Select distinct prvd.GUID Prvd, lpu.GUIDLPU Lpu from hlt_DocPRVD prvd with (NOLOCK) inner join oms_PRVS prvs with (NOLOCK) on prvd.rf_PRVSID = prvs.PRVSID inner join oms_Department dep with (NOLOCK) on rf_DepartmentID = DepartmentID inner join oms_Lpu lpu with (NOLOCK) on lpu.LpuID = dep.rf_LPUID where prvs.C_PRVS = '{0}' |
3) Получаем список подразделений ЛПУ по гуиду следующим запросом:
SELECT distinct lpu.GUIDLPU as [LpuGuid], case when lpu.HostID != 0 then lpu.HostID else lpuWithHostOrChild.HostID end as [HostId] FROM oms_LPU lpu with (NOLOCK) LEFT JOIN oms_LPU lpuWithHostOrChild with (NOLOCK) on lpu.rf_MainLPUID = lpuWithHostOrChild.LPUID WHERE lpu.DATE_E > getdate() |
4) Из всех LpuPrvd выбираются только те, которые относятся к ЛПУ из списка, полученного в п. 3.
Спецификация метода доступна по ссылке.
Внутренняя логика:
1) Получение данных из тела запроса;
2) Получение полезной нагрузки из CodToken;
3) Получение списка ЛПУ-МКАБов с помощью PersonClient;
4) Получение ЛПУ токена через AuthClient со специальными параметрами: если не смогли получить ЛПУ токен, мы КОПИРУЕМ МКАБ из ЛПУ источника направлений.
5) Получение типа направления происходит выполнением следующего запроса:
Select'consultation' as typeDirection from hlt_direction dir with (NOLOCK) where dir.GUID = @0 union all Select 'diagnostic' as typeDirection from lbr_LaboratoryResearch dir with (NOLOCK) where dir.GUID = @0 union all Select 'duvisit' as typeDirection from hlt_RegMedicalCheck dir with (NOLOCK) where dir.GUID = @0 |
6) Создание направления в ЛПУ, в которое оно было выписано, по гуидам обоих ЛПУ + гуиду направления + типу направления (по факту это просто копирование направления)
* если тип направления null (не получилось определить), выбрасываем исключение с сообщением: "По выбранному идентификатору направление не найдено";
* если тип направления duvisit, результатом будет идентификатор, полученный выполнением следующего запроса:
select RegMedicalCheckID from hlt_regMedicalCheck where guid = @0 |
* если тип направления diagnostic, то мы получаем направление из ЛПУ источника следующим запросом:
Select convert(varchar(50), dir.GUID) as Guid, isnull(dir.Number, '') as Number, isnull(nomservice.CODE, '') as CodeNomservice, isnull(nomservice.NAME, '') as NameNomservice, isnull(convert(varchar(50),lpufrom.GUIDLPU), '00000000-0000-0000-0000-000000000000') as LpuSourceGuid, isnull(mkab.N_POL, '') as NumberPolis, isnull(mkab.S_POL, '') as SeriesPolis, isnull(mkb.DS, '') as CodeMkb, reseachType.Code as CodeReseachType from lbr_LaboratoryResearch dir with (NOLOCK) inner join lbr_Research reseach with (NOLOCK) on reseach.rf_LaboratoryResearchGUID = dir.GUID inner join lbr_ResearchType reseachType with (NOLOCK) on reseachType.UGUID = reseach.rf_ResearchTypeUGUID inner join oms_kl_NomService nomservice with (NOLOCK) on nomservice.kl_NomServiceID = reseachType.rf_kl_NomServiceID inner join hlt_MKAB mkab with (NOLOCK) on mkab.MKABID = dir.rf_MKABID inner join oms_mkb mkb with (NOLOCK) on mkb.MkbId = dir.rf_MKBID inner join oms_lpu lpufrom with (NOLOCK) on lpuFrom.LPUID = dir.rf_LPUSenderID where dir.GUID = @0 |
и добавляем это направление в ЛПУ назначения следующим запросом:
if not exists (select * from lbr_LaboratoryResearch with (NOLOCK) where Number = '{4}') begin insert into lbr_LaboratoryResearch(Date_Direction, rf_MKABID, rf_mkbId, Number, Pat_Birthday, Pat_Family, Pat_Name, Pat_Ot, Pat_S_POL, Pat_N_POL, rf_LPUSenderID, rf_LPUID, DateCreate) values (convert(datetime,'{0}'), isnull((Select top 1 MKABID from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- MKABID isnull((Select MKBID from oms_mkb with (NOLOCK) where DS = '{3}'), 0), -- МКБ '{4}', -- номер направления isnull((Select top 1 convert(datetime, DATE_BD, 104) from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- дата рождения isnull((Select top 1 FAMILY from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), --фамилия isnull((Select top 1 NAME from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- имя isnull((Select top 1 OT from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- отчество '{1}', -- серия полиса '{2}', -- номер полиса isnull((Select top 1 LPUID from oms_lpu with (NOLOCK) where GUIDLPU = '{5}'), 0), -- ЛПУ источник isnull((Select top 1 LPUID from oms_lpu with (NOLOCK) where GUIDLPU = '{6}'), 0), -- ЛПУ назначения GetDAte()) Select scope_identity() declare @@researchTypeGuid uniqueidentifier, @@laboratoryResearchGuid uniqueidentifier Select @@researchTypeGUID = UGuid from lbr_ResearchType with (NOLOCK) where code = '{7}' Select @@laboratoryResearchGuid = GUID from lbr_LaboratoryResearch with (NOLOCK) where LaboratoryResearchId = scope_identity() insert into lbr_Research(rf_LaboratoryResearchGuid, rf_ResearchTypeUGUID) values (@@laboratoryResearchGuid, @@researchTypeGuid) end select top 1 LaboratoryResearchID from lbr_LaboratoryResearch where Number = '{4}' |
* если тип направления consultation, получаем объект направления из ЛПУ источника следующим запросом:
Select convert(varchar(50), dir.GUID) as Guid, isnull(dir.Num, '') as Number, isnull(prvs.C_PRVS, '') as CodeSpecialty, isnull(prvs.PRVS_NAME, '') as NameSpecialty, isnull(convert(varchar(50), lpufrom.GUIDLPU), '00000000-0000-0000-0000-000000000000') as lpuSourceGuid, isnull(mkab.N_POL, '') as NumberPolis, isnull(mkab.S_POL, '') as SeriesPolis, isnull(mkb.DS, '') as CodeMkb from hlt_direction dir with (NOLOCK) inner join hlt_Typedirection typ with (NOLOCK) on typ.TypeDirectionID = dir.rf_TypeDirectionID inner join oms_PRVS prvs with (NOLOCK) on dir.rf_PRVSID = prvs.PRVSID inner join oms_lpu lpufrom with (NOLOCK) on lpuFrom.LPUID = dir.rf_LPUSenderID inner join hlt_LPUDoctor docFrom with (NOLOCK) on docFrom.LPUDoctorID = dir.rf_LPUDoctorID inner join hlt_MKAB mkab with (NOLOCK) on mkab.MKABID = dir.rf_MKABID inner join oms_mkb mkb with (NOLOCK) on mkb.MkbId = dir.rf_MKBID inner join oms_lpu lputo with (NOLOCK) on lputo.LPUID = dir.rf_LPUID where convert(varchar(50), dir.GUID) = @0 |
и затем создаётся в ЛПУ назначения следующим запросом:
if not exists (select * from hlt_Direction with (NOLOCK) where Num = '{6}') begin insert into hlt_Direction(Date, rf_MKABID, rf_mkbID, rf_LPUID, rf_TypeDirectionID, rf_LPUSenderID, FAMILY, NAME, OT, BD, Address, S_POL, N_POL, Num, rf_PRVSID, DatePlan) values (convert(datetime,'{0}'), isnull((Select top 1 MKABID from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- MKABID isnull((Select MKBID from oms_mkb with (NOLOCK) where DS = '{3}'), 0), -- MKBID isnull((Select top 1 LPUID from oms_lpu with (NOLOCK) where GUIDLPU = '{4}'), 0), -- ЛПУ назначения 3, -- тип направления isnull((Select top 1 LPUID from oms_lpu with (NOLOCK) where GUIDLPU = '{5}'), 0), -- ЛПУ источник isnull((Select top 1 FAMILY from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- Фамилия isnull((Select top 1 NAME from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- Имя isnull((Select top 1 OT from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- Отчество isnull((Select top 1 convert(datetime, DATE_BD, 104) from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- ДР isnull((Select top 1 Adres from hlt_mkab with (NOLOCK) where S_POL = '{1}' and N_pol = '{2}'), 0), -- Адрес '{1}', -- Серия полиса '{2}', -- Номер полиса '{6}', -- Номер направления isnull((Select top 1 PRVSID from oms_PRVS with (NOLOCK) where C_PRVS = '{7}'), 0), -- специальность convert(datetime,'{0}')) -- Дата направления Select scope_identity() end else select DirectionID from hlt_Direction with (NOLOCK) where Num = '{6}' |
7) Далее происходит запись по направлению, на время, указанное пользователем, через метод CreateVisitDirectionFromTime в VisitClient;