...
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 |
...
Блок кода | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
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), 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}' |
...