hexOffender
Programmer
This needs to loop through a bunch of report rows and run the function dbo.Turnaround(VisitID)to calculate a time.
In the code below, the function has a few more parameters, but I can rewrite the function to only take the VisitID, I was using it for other reports. The Cursor is really ugly and not good.
--Delivery Record Date and Time to Delivery Record Dictation Date and Time
DECLARE fileCsr CURSOR READ_ONLY FOR
--Declare @From as datetime
--set @From ='20100601'
--declare @Thru as datetime
--set @Thru='20100605'
select distinct AD.VisitID,AD.Name,AD.AccountNumber,AD.UnitNumber,AD.Sex,
AD.BirthDateTime,AD.LocationID,
OeResults1.DictEsByUserName,
OeResults.ReportName,OeResults1.DictDateTime--
--Turnaround
FROM AbstractData as AD
Inner JOIN NurQueryResults as NQR on NQR.SourceID = AD.SourceID and NQR.VisitID = AD.VisitID
Inner Join OeResults ON AD.VisitID=OeResults.PatientVisitID
Inner Join OeResults1 ON OeResults1.ResultID=OeResults.ResultID
WHERE AD.LocationID IN('FBP','FBPI')
and OeResults.ReportName IN('*DELIVERY NOTE*','DELIVERY NOTE')
and NQR.DateTime Between '20100501'and'20100601'
--Order By AD.AccountNumber
Declare @VisitID varchar(15)
Declare @UnitNumber varchar(10)
Declare @Name varchar (40)
Declare @Account as varchar(20)
Declare @LocationID varchar(10)
Declare @Sex varchar(1)
Declare @BirthDateTime datetime
Declare @ReportName varchar(20)
Declare @DictDateTime datetime
Declare @Provider as varchar(50)
OPEN fileCsr
FETCH NEXT FROM fileCsr INTO @VisitID, @Name,@Account, @UnitNumber, @Sex,@BirthDateTime , @LocationID,@Provider,@ReportName, @DictDateTime
WHILE @@FETCH_STATUS = 0
BEGIN
--Pt name, Acct #, Unit #, Sex, DOB, Room ID, Location, Report Name, From and Thru variables, Calculated Turnaround Time.
Select @Name as Name,@Account as AccountNumber,@UnitNumber as UnitNumber,@Sex as Sex,@BirthDateTime as BirthDateTime,
@LocationID as Location,@Provider as Provider, @ReportName as ReportName,@DictDateTime as DictDateTime,
dbo.Turnaround(@VisitID,'NUR.OBDR17','NUR.OBDR99','*DELIVERY NOTE*')as Turnaround
FETCH NEXT FROM fileCsr INTO @VisitID, @Name,@Account, @UnitNumber, @Sex,@BirthDateTime , @LocationID,@Provider,@ReportName, @DictDateTime
END --WHILE
close fileCsr
DEALLOCATE fileCsr
In the code below, the function has a few more parameters, but I can rewrite the function to only take the VisitID, I was using it for other reports. The Cursor is really ugly and not good.
--Delivery Record Date and Time to Delivery Record Dictation Date and Time
DECLARE fileCsr CURSOR READ_ONLY FOR
--Declare @From as datetime
--set @From ='20100601'
--declare @Thru as datetime
--set @Thru='20100605'
select distinct AD.VisitID,AD.Name,AD.AccountNumber,AD.UnitNumber,AD.Sex,
AD.BirthDateTime,AD.LocationID,
OeResults1.DictEsByUserName,
OeResults.ReportName,OeResults1.DictDateTime--
--Turnaround
FROM AbstractData as AD
Inner JOIN NurQueryResults as NQR on NQR.SourceID = AD.SourceID and NQR.VisitID = AD.VisitID
Inner Join OeResults ON AD.VisitID=OeResults.PatientVisitID
Inner Join OeResults1 ON OeResults1.ResultID=OeResults.ResultID
WHERE AD.LocationID IN('FBP','FBPI')
and OeResults.ReportName IN('*DELIVERY NOTE*','DELIVERY NOTE')
and NQR.DateTime Between '20100501'and'20100601'
--Order By AD.AccountNumber
Declare @VisitID varchar(15)
Declare @UnitNumber varchar(10)
Declare @Name varchar (40)
Declare @Account as varchar(20)
Declare @LocationID varchar(10)
Declare @Sex varchar(1)
Declare @BirthDateTime datetime
Declare @ReportName varchar(20)
Declare @DictDateTime datetime
Declare @Provider as varchar(50)
OPEN fileCsr
FETCH NEXT FROM fileCsr INTO @VisitID, @Name,@Account, @UnitNumber, @Sex,@BirthDateTime , @LocationID,@Provider,@ReportName, @DictDateTime
WHILE @@FETCH_STATUS = 0
BEGIN
--Pt name, Acct #, Unit #, Sex, DOB, Room ID, Location, Report Name, From and Thru variables, Calculated Turnaround Time.
Select @Name as Name,@Account as AccountNumber,@UnitNumber as UnitNumber,@Sex as Sex,@BirthDateTime as BirthDateTime,
@LocationID as Location,@Provider as Provider, @ReportName as ReportName,@DictDateTime as DictDateTime,
dbo.Turnaround(@VisitID,'NUR.OBDR17','NUR.OBDR99','*DELIVERY NOTE*')as Turnaround
FETCH NEXT FROM fileCsr INTO @VisitID, @Name,@Account, @UnitNumber, @Sex,@BirthDateTime , @LocationID,@Provider,@ReportName, @DictDateTime
END --WHILE
close fileCsr
DEALLOCATE fileCsr