Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- go
- Alter proc PatientPassInsert
- @pid nvarchar(100),
- @eid nvarchar(100),
- @printNo int,
- @printBy int
- as
- begin
- insert into tblPatientPass (PatientId,EncounterId, NumOfPrints,PrintBy,PrintDate)
- values (@pid,@eid,@printNo,@printBy,GETDATE())
- end
- go
- Alter PROC [dbo].[DepositGetAllPatient_Pagination]
- @patientid nvarchar(max),
- @fromdate date,
- @todate date,
- @duetype nvarchar(max),
- @pagenumber int, @pagesize int
- as
- DECLARE @firstRecord int = (@pagenumber - 1) * @pagesize + 1;
- DECLARE @lastRecord int = @firstRecord + @pagesize - 1;
- create table #temp (
- mobile nvarchar(max),
- PatientID nvarchar(max),
- [Name] nvarchar(max),
- PatientWard nvarchar(max),
- BedNo nvarchar(max),
- strStatus nvarchar(max),
- Receivable decimal(18,2),
- Received decimal(18,2),
- Deposit decimal(18,2),
- DepositReturn decimal(18,2),
- DueType nvarchar(max)
- );
- IF @duetype='Receivable'
- begin
- insert into #temp
- select temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,
- sum(temp.Receivable)as 'Receivable',sum(temp.Received)as 'Received',sum(temp.Deposit)as 'Deposit',sum(temp.DepositReturn)as 'DepositReturn',
- temp.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- case when tm.BillingType='Credit' then isnull(tm.Total-tm.ReceiveAmt,0) else 0 end as 'Receivable',
- 0 as 'Received',
- 0 as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblBillingMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.billdiscount))<>0
- ) as temp
- group by temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,temp.DueType
- union all
- select temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,
- sum(temp1.Receivable)as 'Receivable',sum(temp1.Received)as 'Received',sum(temp1.Deposit)as 'Deposit',sum(temp1.DepositReturn)as 'DepositReturn',
- temp1.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- case when tm.PharmacyType='Credit' then isnull(tm.Total-tm.ReceiveAmt,0) else 0 end as 'Receivable',
- 0 as 'Received',
- 0 as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblPharmacySalesMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.PharmacyDiscount))<>0
- ) as temp1
- group by temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,temp1.DueType
- END
- ELSE IF @duetype='Received'
- BEGIN
- insert into #temp
- select temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,
- sum(temp.Receivable)as 'Receivable',sum(temp.Received)as 'Received',sum(temp.Deposit)as 'Deposit',sum(temp.DepositReturn)as 'DepositReturn',
- temp.DueType
- from (
- select isnull(tp.intmobile,'N/A') mobile, TP.patientID PatientID, Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname
- as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- case when tm.[type]='Due' then isnull(tm.receiveAmt,0) else 0 end as 'Received',
- 0 as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblBillingMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.billdiscount))<>0
- ) as temp
- group by temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,temp.DueType
- union all
- select temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,
- sum(temp1.Receivable)as 'Receivable',sum(temp1.Received)as 'Received',sum(temp1.Deposit)as 'Deposit',sum(temp1.DepositReturn)as 'DepositReturn',
- temp1.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- case when tm.[type]='Due' then isnull(tm.receiveAmt,0) else 0 end as 'Received',
- 0 as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblPharmacySalesMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.PharmacyDiscount))<>0
- ) as temp1
- group by temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,temp1.DueType
- END
- ELSE IF @duetype='Deposit'
- BEGIN
- insert into #temp
- select temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,
- sum(temp.Receivable)as 'Receivable',sum(temp.Received)as 'Received',sum(temp.Deposit)as 'Deposit',sum(temp.DepositReturn)as 'DepositReturn',
- temp.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- 0 as 'Received',
- case when tm.[type]='Deposit' then isnull(tm.receiveAmt,0) else 0 end as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblBillingMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.billdiscount))<>0
- ) as temp
- group by temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,temp.DueType
- union all
- select temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,
- sum(temp1.Receivable)as 'Receivable',sum(temp1.Received)as 'Received',sum(temp1.Deposit)as 'Deposit',sum(temp1.DepositReturn)as 'DepositReturn',
- temp1.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- 0 as 'Received',
- case when tm.[type]='Deposit' then isnull(tm.receiveAmt,0) else 0 end as 'Deposit',
- 0 as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblPharmacySalesMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.PharmacyDiscount))<>0
- ) as temp1
- group by temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,temp1.DueType
- END
- ELSE IF @duetype='Deposit Return'
- BEGIN
- insert into #temp
- select temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,
- sum(temp.Receivable)as 'Receivable',sum(temp.Received)as 'Received',sum(temp.Deposit)as 'Deposit',sum(temp.DepositReturn)as 'DepositReturn',
- temp.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- 0 as 'Received',
- 0 as 'Deposit',
- case when tm.[type]='Return' then isnull(abs(tm.receiveAmt),0) else 0 end as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblBillingMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.billdiscount))<>0
- ) as temp
- group by temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,temp.DueType
- union all
- select temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,
- sum(temp1.Receivable)as 'Receivable',sum(temp1.Received)as 'Received',sum(temp1.Deposit)as 'Deposit',sum(temp1.DepositReturn)as 'DepositReturn',
- temp1.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- 0 as 'Receivable',
- 0 as 'Received',
- 0 as 'Deposit',
- case when tm.[type]='Return' then isnull(abs(tm.receiveAmt),0) else 0 end as 'DepositReturn',
- 'Counter' as 'DueType'
- from tblPharmacySalesMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.PharmacyDiscount))<>0
- ) as temp1
- group by temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,temp1.DueType
- END
- ELSE IF @duetype='All'
- BEGIN
- insert into #temp
- select temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,
- sum(temp.Receivable)as 'Receivable',sum(temp.Received)as 'Received',sum(temp.Deposit)as 'Deposit',sum(temp.DepositReturn)as 'DepositReturn',
- temp.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- case when tm.BillingType='Credit' then isnull(tm.Total-tm.ReceiveAmt,0) else 0 end as 'Receivable',
- case when tm.[type]='Due' then isnull(tm.receiveAmt,0) else 0 end as 'Received',
- case when tm.[type]='Deposit' then isnull(tm.receiveAmt,0) else 0 end as 'Deposit',
- case when tm.[type]='Return' then isnull(abs(tm.receiveAmt),0) else 0 end as 'DepositReturn',
- 'Counter' as 'DueType' from tblBillingMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.billdiscount))<>0
- ) as temp
- group by temp.mobile,temp.PatientID,temp.[Name],temp.PatientWard,temp.BedNo,temp.strStatus,temp.DueType
- union all
- select temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,
- sum(temp1.Receivable)as 'Receivable',sum(temp1.Received)as 'Received',sum(temp1.Deposit)as 'Deposit',sum(temp1.DepositReturn)as 'DepositReturn',
- temp1.DueType
- from (
- select isnull(tp.intmobile,'N/A') as 'mobile',TP.patientID as 'PatientID',Ltrim(Rtrim(TP.srtFname)) +' '+TP.strLname as 'Name',
- '0' as 'PatientWard',
- '0' as 'BedNo',
- '0' as 'strStatus',
- --(select dbo.getLatestDepartment((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))) as 'PatientWard',
- --isnull((select dbo.getLatestbED((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'N/A') as 'BedNo',
- --isnull((select dbo.getpatientCurrentStatus((select top 1 strEncounterID from tblEncounter where strPatientID=tp.patientID order by ID desc))),'')as 'strStatus',
- case when tm.[type]='Credit' then isnull(tm.Total-tm.ReceiveAmt,0) else 0 end as 'Receivable',
- case when tm.[type]='Due' then isnull(tm.receiveAmt,0) else 0 end as 'Received',
- case when tm.[type]='Deposit' then isnull(tm.receiveAmt,0) else 0 end as 'Deposit',
- case when tm.[type]='Return' then isnull(abs(tm.receiveAmt),0) else 0 end as 'DepositReturn',
- 'Counter' as 'DueType' from tblPharmacySalesMaster tm
- INNER JOIN tblEncounter te on te.strencounterid=tm.strEncounterID
- INNER JOIN tblpaitentinfo TP on TP.patientID=te.strPatientID
- where --TM.AcLedgerID=22 and
- Tp.patientID=(case when @patientid='' then Tp.patientID else @patientid end)
- and convert(date,Tm.EntryTime) between convert(date,@fromdate) and convert(date,@todate)
- and (tm.receiveAmt-(tm.Total-tm.PharmacyDiscount))<>0
- ) as temp1
- group by temp1.mobile,temp1.PatientID,temp1.[Name],temp1.PatientWard,temp1.BedNo,temp1.strStatus,temp1.DueType
- END
- ;with totalTem as(
- select * from #temp
- )
- select @pagesize as pageRows , count (*) as totalRows, @firstRecord as firstRecord,
- case when count(*) > @pagesize then @lastRecord
- else @firstRecord + count(*) - 1 end
- as lastRecord, Ceiling(CONVERT(decimal,count(*))/@pagesize)
- as TotalPages, @pagenumber as Currentpage from totalTem
- go
Advertisement
Add Comment
Please, Sign In to add comment