Advertisement
aliGo

Untitled

Jul 19th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. SELECT act_list.id,
  2. act_list.list_number,
  3. act_list.list_name,
  4. max(f003d.nam_mok::text) AS medical_organization_name,
  5. max(v006d.name_type_usl::text) AS med_work_type_name,
  6. expertise_class_decomposed.expertise_purpose::text AS expertise_purpose,
  7. expertise_class_decomposed.expertise_type::text AS expertise_type,
  8. expertise_class_decomposed.expertise_theme_type::text AS expertise_theme_type,
  9. act_list.status::text AS status,
  10. acts_count.cnt AS count_acts,
  11. concat_ws(' '::text, max(users.last_name::text), max(users.first_name::text)) AS expert_last_name,
  12. ''::text AS expert_first_name,
  13. ''::text AS expert_patronymic,
  14. act_list.date_create,
  15. max(f003d.region_code) AS region_code,
  16. act_list.user_id,
  17. max(theme.name::text) AS theme_name,
  18. max(category.name::text) AS category_name,
  19. act_list.date_upload,
  20. max(f003d.mcode::text) AS medical_organization_code,
  21. sum(COALESCE(sanction.sum_rem, 0.0)) AS retention_sum,
  22. act_list.zpmd_id,
  23. theme_category.id AS list_theme_category_id,
  24. zpmd_tc.id AS zpmd_theme_category_id,
  25. act_list.has_cover_letter_date,
  26. cv.number AS cover_letter_number,
  27. cv.date AS cover_letter_date,
  28. act_list.date_print,
  29. act_list.date_send,
  30. act_list.date_sign,
  31. concat_ws(' '::text, exp.family_name, exp.first_name, exp.patronymic) AS assigned_expert,
  32. exp.id AS assigned_expert_id,
  33. sum(sanction.sum_fine) AS total_sum_fine,
  34. zpmd.podr_id,
  35. max(COALESCE(podr_omsk.nam_mop, podr_tula.name)::text) AS podr_name,
  36. max(COALESCE(podr_omsk.lpu_1::character varying, podr_tula.podr_id)::text) AS podr_code,
  37. max(act_list.old_id::text) AS old_id
  38. FROM expert.acts_list act_list
  39. JOIN expert.act act ON act.act_list_id = act_list.id
  40. JOIN expert.theme_category theme_category ON act_list.theme_category_id = theme_category.id
  41. JOIN expert.expertise_class_decomposed
  42. ON expertise_class_decomposed.expertise_class = theme_category.expertise_class
  43. JOIN zpmd.zpmd ON zpmd.id = act_list.zpmd_id
  44. JOIN expert.theme_category zpmd_tc ON zpmd_tc.id = zpmd.theme_category_id
  45. JOIN directory.f003 f003d ON f003d.mcode= act_list.medical_organization_code and f003d.region_code = '74'
  46. JOIN (SELECT count(1) cnt, act_list_id FROM expert.act GROUP BY act_list_id HAVING count(1) = coalesce( :countActs,count(1))) acts_count
  47. on acts_count.act_list_id = act_list.id
  48. LEFT JOIN expert.theme ON theme_category.theme_id = theme.id
  49. LEFT JOIN expert.category ON category.id = theme_category.category_id
  50. LEFT JOIN expert.expertise_result re
  51. ON act.id = re.act_id AND re.status <> 'DELETED'::expert.expertise_result_status
  52. LEFT JOIN expert.expertise_sanction sanction ON re.id = sanction.expertise_result_id AND
  53. (sanction.sum_fine IS NOT NULL OR sanction.sum_rem IS NOT NULL)
  54. LEFT JOIN directory.v006 v006d ON v006d.code_type_usl = act_list.med_work_type_id
  55.  
  56. LEFT JOIN expert.users users ON users.id = act_list.user_id
  57. LEFT JOIN expert.document cv ON act_list.id = cv.act_list_id AND cv.type = 'COVER_LETTER'::expert.document_type
  58. LEFT JOIN directory.expert exp ON exp.id = act_list.assigned_expert_id
  59. LEFT JOIN directory.podr_omsk podr_omsk
  60. ON act_list.region= 'OMSK' AND podr_omsk.id = zpmd.podr_id
  61. LEFT JOIN directory.t_podr_tula podr_tula
  62. ON act_list.region = 'TULA' AND podr_tula.id = zpmd.podr_id
  63. WHERE NOT EXISTS(SELECT 1
  64. FROM bills.zsl_additional_mek mek
  65. WHERE mek.zsl_id = act.zsl_id
  66. AND mek.status = 'LOCKED'
  67. AND (mek.region = 'CHELYABINSK'::expert.region AND act_list.region = 'CHELYABINSK'::expert.region
  68. OR mek.region = 'NOVGOROD'::expert.region AND act_list.region = 'NOVGOROD'::expert.region))
  69. GROUP BY act_list.id, act_list.list_number, act_list.list_name, (expertise_class_decomposed.expertise_purpose::text),
  70. (expertise_class_decomposed.expertise_type::text), (expertise_class_decomposed.expertise_theme_type::text),
  71. (act_list.status::text), ''::text, act_list.date_create, act_list.user_id, act_list.date_upload, acts_count.cnt,
  72. act_list.zpmd_id, theme_category.id, zpmd_tc.id, act_list.has_cover_letter_date, cv.number, cv.date, exp.id,
  73. zpmd.podr_id
  74. order by act_list.date_create
  75. limit 25;
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement