
				select v_EvnPS.evnps_id, v_EvnPS.evnps_pid, v_EvnPS.evnps_rid, v_EvnPS.evnps_setdt, v_EvnPS.evnps_disdt, v_EvnPS.evnps_diddt, v_EvnPS.evnps_insdt, v_EvnPS.pmuser_insid, v_EvnPS.evnps_upddt, v_EvnPS.pmuser_updid, v_EvnPS.evnps_issigned, v_EvnPS.evnps_istransit, v_EvnPS.evnps_signdt, v_EvnPS.pmuser_signid, v_EvnPS.lpu_id, v_EvnPS.person_id, v_EvnPS.personevn_id, v_EvnPS.server_id, v_EvnPS.morbus_id, v_EvnPS.evnstatus_id, v_EvnPS.evnps_statusdate, v_EvnPS.evnps_count, v_EvnPS.evnps_index, v_EvnPS.evnps_isarchive, v_EvnPS.evnps_iscont, v_EvnPS.evnps_numcard, v_EvnPS.paytype_id, v_EvnPS.evnps_iswithoutdirection, v_EvnPS.evndirection_id, v_EvnPS.evnqueue_id, v_EvnPS.evndirection_setdt, v_EvnPS.evndirection_num, v_EvnPS.prehospdirect_id, v_EvnPS.lpusection_did, v_EvnPS.org_did, v_EvnPS.medstafffact_did, v_EvnPS.medpersonal_did, v_EvnPS.medstafffact_tfomscode, v_EvnPS.orgmilitary_did, v_EvnPS.lpu_did, v_EvnPS.diag_did, v_EvnPS.diag_eid, v_EvnPS.diagsetphase_did, v_EvnPS.evnps_phasedescr_did, v_EvnPS.prehosparrive_id, v_EvnPS.cmpcallcard_id, v_EvnPS.evnps_codeconv, v_EvnPS.evnps_numconv, v_EvnPS.evnps_isplambulance, v_EvnPS.evnps_isimperhosp, v_EvnPS.evnps_isshortvolume, v_EvnPS.evnps_iswrongcure, v_EvnPS.evnps_isdiagmismatch, v_EvnPS.evnps_htmbegdate, v_EvnPS.evnps_htmhospdate, v_EvnPS.evnps_htmticketnum, v_EvnPS.prehosptype_id, v_EvnPS.evnps_hospcount, v_EvnPS.evnps_timedesease, v_EvnPS.okei_id, v_EvnPS.evnps_isneglectedcase, v_EvnPS.prehosptrauma_id, v_EvnPS.evnps_isunlaw, v_EvnPS.evnps_isunport, v_EvnPS.entrancemodetype_id, v_EvnPS.lpusection_pid, v_EvnPS.medpersonal_pid, v_EvnPS.medstafffact_pid, v_EvnPS.lpusectionward_id, v_EvnPS.prehosptoxic_id, v_EvnPS.lpusectiontranstype_id, v_EvnPS.diag_pid, v_EvnPS.diagsetphase_pid, v_EvnPS.diagsetphase_aid, v_EvnPS.evnps_phasedescr_pid, v_EvnPS.evnps_isactive, v_EvnPS.deseasetype_id, v_EvnPS.tumorstage_id, v_EvnPS.evnps_iszno, v_EvnPS.evnps_isznoremove, v_EvnPS.evnps_biopsydate, v_EvnPS.diag_spid, v_EvnPS.evnps_outcomedt, v_EvnPS.lpusection_eid, v_EvnPS.prehospwaifrefusecause_id, v_EvnPS.medpersonal_sid, v_EvnPS.medpersonal_tid, v_EvnPS.medicalcareformtype_id, v_EvnPS.resultclass_id, v_EvnPS.resultdeseasetype_id, v_EvnPS.evnps_istransfcall, v_EvnPS.prehospstatus_id, v_EvnPS.evnps_iswaif, v_EvnPS.prehospwaifarrive_id, v_EvnPS.prehospwaifreason_id, v_EvnPS.evnps_prehospwaifrefusedt, v_EvnPS.evnps_isprehospacceptrefuse, v_EvnPS.evnps_prehospacceptrefusedt, v_EvnPS.evnps_isinreg, v_EvnPS.person_age, v_EvnPS.diag_id, v_EvnPS.mes_id, v_EvnPS.diag_aid, v_EvnPS.leavetype_id, v_EvnPS.lpu_eid, v_EvnPS.evnps_doctrans, v_EvnPS.lpusection_id, v_EvnSection.LeaveType_prmid, v_EvnDirection_all.TimetableStac_id, COALESCE(ED1.EmergencyData_id, ED2.EmergencyData_id) as "EmergencyData_id", v_EvnPS.evnps_indexrep, v_EvnPS.evnps_indexrepinreg, v_EvnPS.evnps_notificationdt, v_EvnPS.medstafffact_id, v_EvnPS.evnps_phone, v_EvnPS.evnps_policeman, v_EvnPS.evnps_rfid, v_EvnPS.evnps_cmptltdt
				from v_EvnPS
				left outer join v_EvnSection on v_EvnPS.EvnPS_id = v_EvnSection.EvnSection_pid and v_EvnSection.EvnSection_Index = 0 left join v_EvnDirection_all on v_EvnDirection_all.EvnDirection_id = v_EvnPS.EvnDirection_id 
				LEFT JOIN LATERAL (
					select EmergencyData_id
					from v_TimetableStac_lite 
					where TimetableStac_id = v_EvnDirection_all.TimetableStac_id
					limit 1
				) ED1 ON true
				LEFT JOIN LATERAL (
					select EmergencyData_id
					from v_TimetableStac_lite 
					where Evn_id = v_EvnPS.EvnPS_id
						and EmergencyData_id is not null
					limit 1
				) ED2 ON true
			
				where v_EvnPS.EvnPS_id = '500801005614354'
			
