Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select mc.id, mc.uid, (select sr.id from sr_srv_rendered sr
- where sr.md_case_id = mc.id order by sr.id ASC limit 1)
- , 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)||
- '.',(case when
- pi.birth_dt is not null then '(' || to_char(pi.birth_dt,'dd.mm.yyyy') || ')' else '' end))
- , pi.birth_dt, mc.case_type_id, mct.name, coalesce(mc.open_date,mc.create_date), mc.close_date, :clinicId,
- (select pd.name from pim_department pd
- left join mc_step ms on (ms._department_id = pd.id)
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
- , mc.main_diagnos_id, md1.code || ' ' || md1.name, md1.code, md1.code, :service.id,
- (case when mc.closing_step_id is null then 1 else 2 end)
- ,
- (case when exists(select fbsi.id from sr_srv_rendered ssre
- join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
- where ssre.md_case_id = mc.id limit 1) then 1
- else 2
- end)
- ,
- (select pi.surname ||' '||left(initcap(pi.name),1)||'. '||left(initcap(pi.patr_name),1)|| '. ' ||
- pe.note
- from mc_step ms
- left join pim_employee_position pep on ( ms._responsible_id = pep.id )
- left join pim_employee pe on ( pep.employee_id = pe.id )
- left join pim_individual pi on ( pe.individual_id = pi.id )
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
- ,
- (select ms._responsible_id from mc_step ms
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
- ,
- (select pp.speciality_id
- from mc_step ms
- left join pim_employee_position pep on ( ms._responsible_id = pep.id )
- left join pim_position pp on ( pep.position_id = pp.id )
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
- ,
- (select ms._responsible_id from mc_step ms
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1)
- , :emplPosContext.id, (:emplPosContext.id = (select ms._responsible_id from mc_step ms
- where ms.admission_date = mc.open_date and ms.case_id = mc.id limit 1))
- ,
- (case when exists(select ms.id from mc_step ms
- where ms.case_id = mc.id and ms.profile_id in
- (select srgp.profile_id from sr_res_group_profile srgp where srgp.res_group_id = :mainResGroupId))
- then true else false
- end)
- , (select mscr.id
- FROM mc_step_result_care_result msrcr
- INNER JOIN mc_step_result msr ON ( msrcr.result_id = msr.id )
- INNER JOIN mc_step_care_result mscr ON ( msrcr.care_result_id = mscr.id )
- INNER JOIN mc_step ms on ( ms.result_id = msr.id)
- where mc.closing_step_id = ms.id limit 1)
- , (select msr.id from mc_step_result msr limit 1), mc.init_goal_id, mcig.code || ' - ' || mcig.name, mc.id, mc.id, mc.uid,
- '№' ||coalesce(mc.uid, '') || (case when mc.closing_step_id is null then ' Открыт:' ||
- coalesce(to_char(coalesce(mc.open_date,mc.create_date), 'dd.mm.yyyy'), '')
- else ' Закрыт:' || coalesce(to_char(mc.close_date, 'dd.mm.yyyy'), '') end )
- || ' ' || (select (coalesce(md1pr.code, '') || ' ' || coalesce(md1pr.name, ''))
- from mc_diagnosis mdpr
- left join md_diagnosis md1pr on ( mdpr.diagnos_id = md1pr.id )
- where mdpr.id = mc.main_diagnos_id)
- , mc.create_date, to_char(coalesce(mc.open_date,mc.create_date), 'DD.MM.YYYY'),
- (select row_to_json(fst) from (
- select
- ffst.id as id,
- ffst.name as name) as fst)
- ,
- (select row_to_json(ig) from (
- select
- mpm.id as id,
- mpm.name as name) as ig)
- ,
- (select row_to_json(l) from (
- select
- mcl.id as id,
- mcl.name as name) as l)
- ,
- (select row_to_json(t) from (
- select
- mct.id as id,
- mct.name as name) as t)
- ,
- (select row_to_json(r) from (
- select
- mcr.id as id,
- mcr.name as name) as r)
- ,
- (select row_to_json(pf) from (
- select
- mcpf.id as id,
- mcpf.name as name) as pf)
- ,
- (select row_to_json(ig) from (
- select
- mcig.id as id,
- (mcig.code || ' - ' || mcig.name) as name) as ig)
- ,
- (select row_to_json(pc) from (
- select
- mcpc.id as id,
- mcpc.name as name) as pc)
- ,
- (select row_to_json(pc) from (
- select
- mar.id as id,
- (mar.code || ' - ' || mar.name) as name,
- mar.external_reason_input_is_allowed as is_external_reason) as pc)
- , mar.external_reason_input_is_allowed,
- (select row_to_json(pc) from (
- select
- md2.id as id,
- (md2.code || ' ' || md2.name) as name) as pc)
- , true, false,
- (select (coalesce(md1md.code, '') || ' ' || coalesce(md1md.name, ''))
- from mc_case mcmd
- left join mc_diagnosis mdmd on ( mcmd.main_diagnos_id = mdmd.id )
- left join md_diagnosis md1md on ( mdmd.diagnos_id = md1md.id )
- where mcmd.id = mc.id)
- ,
- (case when mc.closing_step_id is null then :stepResult.name
- else (select msr.name from mc_step_result msr where msr.id = (select ms.result_id from mc_step ms where
- ms.id = mc.closing_step_id)) end)
- ,
- (case when mc.closing_step_id is null then :outcome.name
- else (select msrc.name from mc_step_care_result msrc where msrc.id = (select ms.outcome_id from mc_step
- ms where ms.id = mc.closing_step_id)) end)
- ,
- coalesce((select mrc.name from mc_repeat_count mrc where mrc.id = mc.repeat_count_id),
- :repeatCount.name)
- ,
- (select to_char(ms.outcome_date , 'DD.MM.YYYY') from mc_step ms where id = mc.closing_step_id)
- ,
- (select pi.surname ||' '||left(initcap(pi.name),1)||'. '||left(initcap(pi.patr_name),1)|| '. ' ||
- pe.note
- from mc_step ms
- left join pim_employee_position pep on ( ms._responsible_id = pep.id )
- left join pim_employee pe on ( pep.employee_id = pe.id )
- left join pim_individual pi on ( pe.individual_id = pi.id )
- where ms.id = mc.closing_step_id)
- ,
- (exists(select fbsi.id from sr_srv_rendered ssre
- join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
- where ssre.md_case_id = mc.id limit 1))
- ,
- (exists(select fbsi.id from fin_bill_spec_item fbsi
- join fin_bill fb on ( fb.id = fbsi.bill_id )
- join sr_srv_rendered ssre on (ssre.id = fbsi.service_id)
- where ssre.md_case_id = mc.id and fbsi.bill_id in (select max(f.bill_id) from fin_bill_spec_item f where
- fbsi.service_id = f.service_id)
- and fb.status_id not in (select fbst.id from fin_bill_status fbst where fbst.code = 'NEW' or fbst.code =
- 'GENERATED')limit 1))
- ,
- (select ms.id
- from mc_step ms
- where ms.case_id = mc.id and ms.admission_date + ms.admission_time = (select max(ms1.admission_date +
- ms1.admission_time) from mc_step ms1 where
- ms1.case_id = mc.id limit 1) limit 1)
- ,
- (case when mc.closing_step_id is null then false
- else true end)
- , :isCaseStateFin, :mainResGroupId, :ageBegin, :ageEnd, :fundingSourceType.id
- from mc_case mc
- left join fin_funding_source_type ffst on ( mc.funding_id = ffst.id )
- left join mc_care_level mcl on ( mc.care_level_id = mcl.id )
- left join mc_care_regimen mcr on ( mc.care_regimen_id = mcr.id )
- left join md_care_providing_form mcpf on ( mc.care_providing_form_id = mcpf.id )
- left join mc_case_init_goal mcig on ( mc.init_goal_id = mcig.id )
- left join md_care_provision_condition mcpc on ( mc.provision_condition_id = mcpc.id )
- left join mc_admission_reason mar on ( mc.admission_reason_id = mar.id )
- left join mc_payment_method mpm on ( mc.payment_method_id = mpm.id )
- left join mc_diagnosis md on ( mc.main_diagnos_id = md.id )
- left join md_diagnosis md1 on ( md.diagnos_id = md1.id )
- left join pim_individual pi on ( pi.id = mc.patient_id )
- left join mc_case_type mct on ( mc.case_type_id = mct.id )
- left join md_diagnosis md2 on ( mc.external_reason_mkb_id = md2.id )
- left join mc_disease_type ON md.disease_type_id = mc_disease_type."id"
- 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
- (case when mc.closing_step_id is null then 1 else 2 end)
- =:caseState.id and
- (case when exists(select fbsi.id from sr_srv_rendered ssre
- join fin_bill_spec_item fbsi on ( ssre.id = fbsi.service_id )
- where ssre.md_case_id = mc.id limit 1) then 1
- else 2
- end)
- =:invoiceGenerated.id and :emplPosContext.id = :emplPosContext.id and :mainResGroupId = :mainResGroupId
- order by 1
- limit 10
- caseState.id = 1
- invoiceGenerated.id = 2
- emplPosContext.id = 2572
- mainResGroupId = 35435
- clinicId = 386
- openDate.begin = Thu Jun 22 16:50:00 MSK 2017
- openDate.end = Thu Jun 29 00:00:00 MSK 2017
- mcCase.caseType = null
- mainDiagnos.name = null
- hasFinBill = null
- mcCase.uid = null
- mcCase.careLevel = null
- newCase = null
- mcCase.careProvisionCondition = null
- patient.id = null
- caseType.name = null
- mcCase.name = null
- mcCase.externalReasonMkb = null
- mcCase.admissionReason = null
- mcCase.caseOpenDate = null
- fundingSourceType.id = null
- stepResult.id = null
- mcCase.caseCreateDate = null
- mcCase.fundingSourceType = null
- id = null
- repeatCount.name = null
- diseaseType.name = null
- mcCase.id = null
- department.name = null
- outcome.name = null
- emplPos.id = null
- openDoctor.name = null
- openMoreInfo = null
- isExternalReason = null
- bDate = null
- isCaseStateFin = null
- mainDiagnos.id = null
- hasFinBillWithStatus = null
- ageEnd = null
- isMyEmployee = null
- service.id = null
- isResGroupProfileLikeStepProfile = null
- caseType.id = null
- mcCase.careProvidingForm = null
- openDoctor.id = null
- isStateFin = null
- closeDoctorName = null
- uid = null
- srServiceId = null
- initGoal.name = null
- mcCase.caseInitGoal = null
- initGoal.id = null
- stepCareResult.id = null
- mcCaseHidden.id = null
- mainDiagnos.to.code = null
- mcCase.careRegimen = null
- closeDate = null
- lastVisitId = null
- openDoctorSpeciality.id = null
- outcomeDate = null
- ageBegin = null
- mcCase.paymentMethod = null
- mainDiagnosis = null
- stepResult.name = null
- diseaseType.Id = null
- mainDiagnos.from.code = null
- patient.name = null
- openDate = {begin=22.06.2017 16:50, end=29.06.2017 00:00}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement