Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.23 KB | None | 0 0
  1. select mc.id, mc.uid, (select sr.id from sr_srv_rendered sr
  2. where sr.md_case_id = mc.id order by sr.id ASC limit 1)
  3. , mc_disease_type."id", mc_disease_type.code || ' - ' || mc_disease_type.name, mc.patient_id, concat_ws(' ',pi.surname, left(initcap(pi.name),1)|| '.', left(initcap(pi.patr_name),1)||
  4. '.',(case when
  5. pi.birth_dt is not null then '(' || to_char(pi.birth_dt,'dd.mm.yyyy') || ')' else '' end))
  6. , pi.birth_dt, mc.case_type_id, mct.name, coalesce(mc.open_date,mc.create_date), mc.close_date, :clinicId,
  7. (select pd.name from pim_department pd
  8. left join mc_step ms on (ms._department_id = pd.id)
  9. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
  10. , mc.main_diagnos_id, md1.code || ' ' || md1.name, md1.code, md1.code, :service.id,
  11. (case when mc.closing_step_id is null then 1 else 2 end)
  12. ,
  13. (case when exists(select fbsi.id from sr_srv_rendered ssre
  14. join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
  15. where ssre.md_case_id = mc.id limit 1) then 1
  16. else 2
  17. end)
  18. ,
  19. (select pi.surname ||' '||left(initcap(pi.name),1)||'. '||left(initcap(pi.patr_name),1)|| '. ' ||
  20. pe.note
  21. from mc_step ms
  22. left join pim_employee_position pep on ( ms._responsible_id = pep.id )
  23. left join pim_employee pe on ( pep.employee_id = pe.id )
  24. left join pim_individual pi on ( pe.individual_id = pi.id )
  25. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
  26. ,
  27. (select ms._responsible_id from mc_step ms
  28. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
  29. ,
  30. (select pp.speciality_id
  31. from mc_step ms
  32. left join pim_employee_position pep on ( ms._responsible_id = pep.id )
  33. left join pim_position pp on ( pep.position_id = pp.id )
  34. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
  35. ,
  36. (select ms._responsible_id from mc_step ms
  37. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
  38. , :emplPosContext.id, (:emplPosContext.id = (select ms._responsible_id from mc_step ms
  39. where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1))
  40. ,
  41. (case when exists(select ms.id from mc_step ms
  42. where ms.case_id = mc.id and ms.profile_id in
  43. (select srgp.profile_id from sr_res_group_profile srgp where srgp.res_group_id = :mainResGroupId))
  44. then true else false
  45. end)
  46. , (select mscr.id
  47. FROM mc_step_result_care_result msrcr
  48. INNER JOIN mc_step_result msr ON ( msrcr.result_id = msr.id )
  49. INNER JOIN mc_step_care_result mscr ON ( msrcr.care_result_id = mscr.id )
  50. INNER JOIN mc_step ms on ( ms.result_id = msr.id)
  51. where mc.closing_step_id = ms.id limit 1)
  52. , (select msr.id from mc_step_result msr limit 1), mc.init_goal_id, mcig.code || ' - ' || mcig.name, mc.id, mc.id, mc.uid,
  53. '№' ||coalesce(mc.uid, '') || (case when mc.closing_step_id is null then ' Открыт:' ||
  54. coalesce(to_char(coalesce(mc.open_date,mc.create_date), 'dd.mm.yyyy'), '')
  55. else ' Закрыт:' || coalesce(to_char(mc.close_date, 'dd.mm.yyyy'), '') end )
  56. || ' ' || (select (coalesce(md1pr.code, '') || ' ' || coalesce(md1pr.name, ''))
  57. from mc_diagnosis mdpr
  58. left join md_diagnosis md1pr on ( mdpr.diagnos_id = md1pr.id )
  59. where mdpr.id = mc.main_diagnos_id)
  60. , mc.create_date, to_char(coalesce(mc.open_date,mc.create_date), 'DD.MM.YYYY'),
  61. (select row_to_json(fst) from (
  62. select
  63. ffst.id as id,
  64. ffst.name as name) as fst)
  65. ,
  66. (select row_to_json(ig) from (
  67. select
  68. mpm.id as id,
  69. mpm.name as name) as ig)
  70. ,
  71. (select row_to_json(l) from (
  72. select
  73. mcl.id as id,
  74. mcl.name as name) as l)
  75. ,
  76. (select row_to_json(t) from (
  77. select
  78. mct.id as id,
  79. mct.name as name) as t)
  80. ,
  81. (select row_to_json(r) from (
  82. select
  83. mcr.id as id,
  84. mcr.name as name) as r)
  85. ,
  86. (select row_to_json(pf) from (
  87. select
  88. mcpf.id as id,
  89. mcpf.name as name) as pf)
  90. ,
  91. (select row_to_json(ig) from (
  92. select
  93. mcig.id as id,
  94. (mcig.code || ' - ' || mcig.name) as name) as ig)
  95. ,
  96. (select row_to_json(pc) from (
  97. select
  98. mcpc.id as id,
  99. mcpc.name as name) as pc)
  100. ,
  101. (select row_to_json(pc) from (
  102. select
  103. mar.id as id,
  104. (mar.code || ' - ' || mar.name) as name,
  105. mar.external_reason_input_is_allowed as is_external_reason) as pc)
  106. , mar.external_reason_input_is_allowed,
  107. (select row_to_json(pc) from (
  108. select
  109. md2.id as id,
  110. (md2.code || ' ' || md2.name) as name) as pc)
  111. , true, false,
  112. (select (coalesce(md1md.code, '') || ' ' || coalesce(md1md.name, ''))
  113. from mc_case mcmd
  114. left join mc_diagnosis mdmd on ( mcmd.main_diagnos_id = mdmd.id )
  115. left join md_diagnosis md1md on ( mdmd.diagnos_id = md1md.id )
  116. where mcmd.id = mc.id)
  117. ,
  118. (case when mc.closing_step_id is null then :stepResult.name
  119. else (select msr.name from mc_step_result msr where msr.id = (select ms.result_id from mc_step ms where
  120. ms.id = mc.closing_step_id)) end)
  121. ,
  122. (case when mc.closing_step_id is null then :outcome.name
  123. else (select msrc.name from mc_step_care_result msrc where msrc.id = (select ms.outcome_id from mc_step
  124. ms where ms.id = mc.closing_step_id)) end)
  125. ,
  126. coalesce((select mrc.name from mc_repeat_count mrc where mrc.id = mc.repeat_count_id),
  127. :repeatCount.name)
  128. ,
  129. (select to_char(ms.outcome_date , 'DD.MM.YYYY') from mc_step ms where id = mc.closing_step_id)
  130. ,
  131. (select pi.surname ||' '||left(initcap(pi.name),1)||'. '||left(initcap(pi.patr_name),1)|| '. ' ||
  132. pe.note
  133. from mc_step ms
  134. left join pim_employee_position pep on ( ms._responsible_id = pep.id )
  135. left join pim_employee pe on ( pep.employee_id = pe.id )
  136. left join pim_individual pi on ( pe.individual_id = pi.id )
  137. where ms.id = mc.closing_step_id)
  138. ,
  139. (exists(select fbsi.id from sr_srv_rendered ssre
  140. join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
  141. where ssre.md_case_id = mc.id limit 1))
  142. ,
  143. (exists(select fbsi.id from fin_bill_spec_item fbsi
  144. join fin_bill fb on ( fb.id = fbsi.bill_id )
  145. join sr_srv_rendered ssre on (ssre.id = fbsi.service_id)
  146. where ssre.md_case_id = mc.id and fbsi.bill_id in (select max(f.bill_id) from fin_bill_spec_item f where
  147. fbsi.service_id = f.service_id)
  148. and fb.status_id not in (select fbst.id from fin_bill_status fbst where fbst.code = 'NEW' or fbst.code =
  149. 'GENERATED')limit 1))
  150. ,
  151. (select ms.id
  152. from mc_step ms
  153. where ms.case_id = mc.id and ms.admission_date + ms.admission_time = (select max(ms1.admission_date +
  154. ms1.admission_time) from mc_step ms1 where
  155. ms1.case_id = mc.id limit 1) limit 1)
  156. ,
  157. (case when mc.closing_step_id is null then false
  158. else true end)
  159. , :isCaseStateFin, :mainResGroupId, :ageBegin, :ageEnd, :fundingSourceType.id
  160. from mc_case mc
  161. left join fin_funding_source_type ffst on ( mc.funding_id = ffst.id )
  162. left join mc_care_level mcl on ( mc.care_level_id = mcl.id )
  163. left join mc_care_regimen mcr on ( mc.care_regimen_id = mcr.id )
  164. left join md_care_providing_form mcpf on ( mc.care_providing_form_id = mcpf.id )
  165. left join mc_case_init_goal mcig on ( mc.init_goal_id = mcig.id )
  166. left join md_care_provision_condition mcpc on ( mc.provision_condition_id = mcpc.id )
  167. left join mc_admission_reason mar on ( mc.admission_reason_id = mar.id )
  168. left join mc_payment_method mpm on ( mc.payment_method_id = mpm.id )
  169. left join mc_diagnosis md on ( mc.main_diagnos_id = md.id )
  170. left join md_diagnosis md1 on ( md.diagnos_id = md1.id )
  171. left join pim_individual pi on ( pi.id = mc.patient_id )
  172. left join mc_case_type mct on ( mc.case_type_id = mct.id )
  173. left join md_diagnosis md2 on ( mc.external_reason_mkb_id = md2.id )
  174. left join mc_disease_type ON md.disease_type_id = mc_disease_type."id"
  175. where mc.clinic_id=:clinicId and mct.case_mode_id = 1 and coalesce(mc.open_date,mc.create_date) >= :openDate.begin::date and coalesce(mc.open_date,mc.create_date) <= :openDate.end::date and :clinicId = :clinicId and
  176. (case when mc.closing_step_id is null then 1 else 2 end)
  177. =:caseState.id and
  178. (case when exists(select fbsi.id from sr_srv_rendered ssre
  179. join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
  180. where ssre.md_case_id = mc.id limit 1) then 1
  181. else 2
  182. end)
  183. =:invoiceGenerated.id and :emplPosContext.id = :emplPosContext.id and :mainResGroupId = :mainResGroupId
  184. order by 1
  185. limit 10
  186.  
  187. caseState.id = 1
  188. invoiceGenerated.id = 2
  189. emplPosContext.id = 2572
  190. mainResGroupId = 35435
  191. clinicId = 386
  192. openDate.begin = Thu Jun 22 16:50:00 MSK 2017
  193. openDate.end = Thu Jun 29 00:00:00 MSK 2017
  194. mcCase.caseType = null
  195. mainDiagnos.name = null
  196. hasFinBill = null
  197. mcCase.uid = null
  198. mcCase.careLevel = null
  199. newCase = null
  200. mcCase.careProvisionCondition = null
  201. patient.id = null
  202. caseType.name = null
  203. mcCase.name = null
  204. mcCase.externalReasonMkb = null
  205. mcCase.admissionReason = null
  206. mcCase.caseOpenDate = null
  207. fundingSourceType.id = null
  208. stepResult.id = null
  209. mcCase.caseCreateDate = null
  210. mcCase.fundingSourceType = null
  211. id = null
  212. repeatCount.name = null
  213. diseaseType.name = null
  214. mcCase.id = null
  215. department.name = null
  216. outcome.name = null
  217. emplPos.id = null
  218. openDoctor.name = null
  219. openMoreInfo = null
  220. isExternalReason = null
  221. bDate = null
  222. isCaseStateFin = null
  223. mainDiagnos.id = null
  224. hasFinBillWithStatus = null
  225. ageEnd = null
  226. isMyEmployee = null
  227. service.id = null
  228. isResGroupProfileLikeStepProfile = null
  229. caseType.id = null
  230. mcCase.careProvidingForm = null
  231. openDoctor.id = null
  232. isStateFin = null
  233. closeDoctorName = null
  234. uid = null
  235. srServiceId = null
  236. initGoal.name = null
  237. mcCase.caseInitGoal = null
  238. initGoal.id = null
  239. stepCareResult.id = null
  240. mcCaseHidden.id = null
  241. mainDiagnos.to.code = null
  242. mcCase.careRegimen = null
  243. closeDate = null
  244. lastVisitId = null
  245. openDoctorSpeciality.id = null
  246. outcomeDate = null
  247. ageBegin = null
  248. mcCase.paymentMethod = null
  249. mainDiagnosis = null
  250. stepResult.name = null
  251. diseaseType.Id = null
  252. mainDiagnos.from.code = null
  253. patient.name = null
  254. openDate = {begin=22.06.2017 16:50, end=29.06.2017 00:00}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement