
            --variables
            with mv as (
                select
                localtimestamp as dt
            )
            --end variables
        
            select
                 count(  * ) AS cnt 
            from
                -- from
         dbo.v_PersonState PS 
                inner join v_EvnPLDispProf EPLDP on PS.Person_id = EPLDP.Person_id
                    and date_part('year', EvnPLDispProf_setDate) = 2023
            
            inner join v_Lpu L on L.Lpu_id = EPLDP.Lpu_id
            left join v_EvnCostPrint ecp on ecp.Evn_id = EPLDP.EvnPLDispProf_id
            left join YesNo IsFinish on IsFinish.YesNo_id = coalesce(EPLDP.EvnPLDispProf_IsEndStage, 1)
            left join v_HealthKind HK on HK.HealthKind_id = EPLDP.HealthKind_id
            left join v_Address UAdd on UAdd.Address_id = ps.UAddress_id
                left join v_Address PAdd on PAdd.Address_id = ps.PAddress_id
        
                        -- end from
                    where
                        -- where
                        (1 = 1) and coalesce(EPLDP.EvnPLDispProf_IsEndStage, 1) = '2'  and ( exists (
                        select
                            PC.personcard_id
                        from
                            
                                v_PersonCard_all PC
                                left join v_LpuRegion LR on LR.LpuRegion_id = PC.LpuRegion_id
                                left join v_LpuRegion LR_Fap on LR_Fap.LpuRegion_id = PC.LpuRegion_fapid
                            
                        where
                            PC.Person_id = PS.Person_id and PC.Lpu_id = '13102006'
                        limit 1
                    ))  and EPLDP.EvnPLDispProf_insDT::date >= '2023-07-01'::date and EPLDP.EvnPLDispProf_insDT::date <= '2023-07-31'::date
                        -- end where
                
                    
                
