Advertisement
Guest User

Untitled

a guest
Sep 13th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 2018-09-12 10:27:33 MSK [47704]: [21-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 LOG:  duration: 146012.051 ms  execute <unnamed>: with prm(cln,d1,d2) as (select $1::integer,to_date($2,'dd.mm.yyyy'), to_date($3,'dd.mm.yyyy'), $4::text include_mdk)
  2.         --with prm(cln,d1,d2) as (select 89::integer,to_date('01.03.2017','dd.mm.yyyy'), to_date('31.03.2017','dd.mm.yyyy'), 'true'::text include_mdk)
  3.  
  4.         , goal as (select id, e_code
  5.         from mc_case_init_goal
  6.         join prm on true
  7.         where e_code in ('9','13') or (e_code in ('30','4') and prm.include_mdk='true')
  8.         )
  9.  
  10.         , dset2 as (
  11.         select mc.id,
  12.                mc.patient_id,
  13.                mc.open_date,
  14.                mc.soc_group_id,
  15.                mc.clinic_id,
  16.                goal.e_code as goal,
  17.                i.nationality_id
  18.           from prm
  19.           join goal on true
  20.           join mc_case mc on mc.clinic_id = cln and mc.close_date between d1 and d2 and mc.closing_step_id is not null
  21.            and mc.init_goal_id = goal.id
  22.           join pim_individual I on mc.patient_id = I.id)
  23.  
  24.         , t3 as (
  25.         select patient_id,
  26.                sG.code in('11','12','13','14','34') g7001,
  27.                sG.code in('22','24','25','26','27','29') or sg.id is null g7002,
  28.                sG.code in('23','32') g7003,
  29.                 (select bool_and(not ae.is_city) -- то есть все действующие адреса - сельские
  30.                    from pim_party_address A
  31.                    join pim_party_addr_to_addr_type P on P.party_address_id = A.id and A.party_id = patient_id
  32.                     and A.is_valid and A.addr_id is not null
  33.                    join pim_address_type T on P.address_type_id = T.id and T.code = 'REGISTER'
  34.                    join address_element_data ae on ae.id = a.addr_id) g7012,
  35.                mnds.code='Д1.02' as fst_srv,
  36.                ssr.id as srv_id,
  37.                agree.denial,
  38.                n.code::integer in (63,132,140,251,250) or n.code::integer between 80 and 112 or n.code::integer between 114 and 122 as g7005
  39.           from dset2
  40.           join disp.md_event_patient mep on coalesce(mep.case_id,mep.case_id_2stage) = dset2.id and not (mep.is_deleted is true)
  41.           left join md_soc_group sG on dset2.soc_group_id = sG.id
  42.           left join pim_nationality n on n.id = nationality_id
  43.           left join disp.md_event_service_patient mesp on mesp.event_patient_id = mep.id
  44.           left join disp.md_event_service mes on mes.id = mesp.service_id
  45.           left join disp.sr_srv_service_document sssd on sssd.service_id = mes.service_id and (sssd.owner_org_id = dset2.clinic_id or sssd.owner_org_id is null)
  46.           left join md_norm_document_service mnds on mnds.id = sssd.document_service_id
  47.           left join md_norm_document mnd on mnd.id = sssd.document_id and mnd.code in('36ан','1006н')
  48.           left join sr_srv_rendered ssr on ssr.md_case_id = dset2.id
  49.           left join disp.md_event_service_patient_agreement agree on agree.service_id = ssr.id)
  50.  
  51.         , table1 as (
  52.         select count(distinct case when g7001 then patient_id end) as g7001,
  53.                count(distinct case when g7002 then patient_id end) as g7002,
  54.                count(distinct case when g7003 then patient_id end) as g7003,
  55.                count(distinct case when g7005 then patient_id end) as g7005,
  56.                count(distinct case when g7012 then patient_id end) as g7012,
  57.                count(distinct case when denial then srv_id end) as g7009,
  58.                count(distinct case when denial and fst_srv then srv_id end) as g7010
  59.           from t3)
  60.  
  61.         , t4 as (
  62.         select count(distinct case when b.benefit_type_id=14 then dset2.patient_id end) as g7004_1,
  63.                count(distinct case when b.benefit_type_id=15 then dset2.patient_id end) as g7004_2,
  64.                count(distinct case when b.benefit_type_id=6 then dset2.patient_id end) as g7004_3,
  65.                count(distinct case when b.benefit_type_id=7 then dset2.patient_id end) as g7004_4,
  66.                count(distinct case when b.benefit_type_id=8
  67.                      and exists(select null
  68.                                   from pci_benefit b1
  69.                                  where b1.patient_id = dset2.patient_id and b1.benefit_type_id in(4,19,20,21,23,11,14)
  70.                                    and open_date between coalesce(b1.from_dt,open_date) and coalesce(b1.to_dt,open_date))
  71.                               then dset2.patient_id end) as g7004_5,
  72.                count(distinct case when b.benefit_type_id=9 then dset2.patient_id end) as g7004_6,
  73.                count(distinct case when b.benefit_type_id=10 then dset2.patient_id end) as g7004_7,
  74.                count(distinct case when b.benefit_type_id in(4,11,14,19,20,21,23) then dset2.patient_id end) as g7004_8
  75.           from dset2
  76.           join pci_benefit b on b.patient_id = dset2.patient_id
  77.            and open_date between coalesce(b.from_dt,open_date) and coalesce(b.to_dt,open_date))
  78.  
  79.          , t5 as (
  80.          select count(distinct case when me.is_mobile_medical_teams then patient_id end) as g7008,
  81.                 max(me.count_mmt) as g7007,
  82.                 count(distinct sssd.owner_org_id) as g7006
  83.            from dset2
  84.            join disp.md_event_patient mep on coalesce(mep.case_id,mep.case_id_2stage) = dset2.id
  85.            join disp.md_event me on me.id = mep.event_id
  86.            join disp.md_event_service_patient mesp on mesp.event_patient_id = mep.id
  87.            join disp.md_event_service mes on mes.id = mesp.service_id
  88.            join disp.sr_srv_service_document sssd on sssd.service_id = mes.service_id
  89.            join md_norm_document_service mnds on mnds.id = sssd.document_service_id
  90.            join md_norm_document mnd on mnd.id = sssd.document_id and mnd.code in('36ан','1006н'))
  91.  
  92.         , t6 as (
  93.         select count(distinct dset2.patient_id) as g7011
  94.           from dset2
  95.           join sr_srv_rendered msr on msr.md_case_id = dset2.id and goal='9'
  96.           join md_prescription mp on mp.service_id = msr.id
  97.           join disp.sr_srv_service_document sssd on sssd.service_id = mp.service_type_id and (sssd.owner_org_id = dset2.clinic_id or sssd.owner_org_id is null)
  98.           join md_norm_document_service mnds on mnds.id = sssd.document_service_id
  99.           join md_norm_document mnd on mnd.id = sssd.document_id and mnd.code in('1006н_2','36ан_2')
  100.           left join sr_srv_rendered ssr on ssr.md_patient_prescription_id = mp.id
  101.          where ssr.bdate is not null or ssr.id is null)
  102.  
  103.         , ttt as (
  104.         select * from table1 full join t4 on true full join t5 on true full join t6 on true)
  105.  
  106.         select  case when g7001<>0 then g7001 end g7001,
  107.                 case when g7002<>0 then g7002 end g7002,
  108.                 case when g7003<>0 then g7003 end g7003,
  109.                 case when g7004_1<>0 then g7004_1 end g7004_1,
  110.                 case when g7004_2<>0 then g7004_2 end g7004_2,
  111.                 case when g7004_3<>0 then g7004_3 end g7004_3,
  112.                 case when g7004_4<>0 then g7004_4 end g7004_4,
  113.                 case when g7004_5<>0 then g7004_5 end g7004_5,
  114.                 case when g7004_6<>0 then g7004_6 end g7004_6,
  115.                 case when g7004_7<>0 then g7004_7 end g7004_7,
  116.                 case when g7004_8<>0 then g7004_8 end g7004_8,
  117.                 case when g7005<>0 then g7005 end g7005,
  118.                 case when g7006<>0 then g7006 end g7006,
  119.                 case when g7007<>0 then g7007 end g7007,
  120.                 case when g7009<>0 then g7009 end g7008,
  121.                 case when g7009<>0 then g7009 end g7009,
  122.                 case when g7010<>0 then g7010 end g7010,
  123.                 case when g7011<>0 then g7011 end g7011,
  124.                 case when g7012<>0 then g7012 end g7012
  125.         from ttt
  126. 2018-09-12 10:27:33 MSK [47704]: [22-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 DETAIL:  parameters: $1 = '63', $2 = '01.01.2018 00:00', $3 = '12.09.2018 00:00', $4 = 'false'
  127. 2018-09-12 10:27:33 MSK [47704]: [23-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 LOG:  temporary file: path "base/pgsql_tmp/pgsql_tmp47704.4", size 190644224
  128. 2018-09-12 10:27:33 MSK [47704]: [24-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 LOG:  temporary file: path "base/pgsql_tmp/pgsql_tmp47704.2", size 1073741824
  129. 2018-09-12 10:27:33 MSK [47704]: [25-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 LOG:  temporary file: path "base/pgsql_tmp/pgsql_tmp47704.3", size 266346496
  130. 2018-09-12 10:27:33 MSK [47704]: [26-1] db=lsd,appname=192.168.5.13,user=rep_slave,client=192.168.5.14 LOG:  temporary file: path "base/pgsql_tmp/pgsql_tmp47704.5", size 121233408
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement