/*
"set dateformat dmy select * from rpt50.hosp_RegOMS_InternalReport_KSG_Usl_2015("+
params["paramLpu"].value+","+ 
params["paramLpuBuilding"].value+","+ 
params["paramLpuUnit"].value+","+
params["paramLpuSection"].value+","+
params["paramIncludeDopDisp"].value+","+
params["paramSex"].value+","+
params["paramBegPersonAge"].value+","+
params["paramEndPersonAge"].value+","+
params["paramPayType"].value+",
dbo.GetDiagCodeByID("+params["paramBegDiag"].value+"),
dbo.GetDiagCodeByID("+params["paramEndDiag"].value+"),"+
params["paramMes"].value+","+
params["paramMedStaffFact"].value+",'"+ 
params["paramBegDate"].value+"','"+
params["paramEndDate"].value+"') 
order by Record_Num,EvnUsluga_setDate"
*/

select *
from rpt50.hosp_regoms_internalreport_ksg_usl_2015_pg(
cast($1 as int8), 
cast($2 as int8), 
cast($3 as int8), 
cast($4 as int8), 
cast($5 as int8), 
cast($6 as int8), 
cast($7 as int), 
cast($8 as int), 
cast($9 as int8), 
dbo.GetDiagCodeByID(cast($10 as int8)),
dbo.GetDiagCodeByID(cast($11 as int8)),
cast($12 as int8), 
cast($13 as int8), 
cast(to_timestamp($14,'dd.mm.yyyy') as timestamp), 
cast(to_timestamp($15,'dd.mm.yyyy') as timestamp))
order by "Record_Num","EvnUsluga_setDate"
