USE RADIOLOGY SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultList] @Type AS varChar(1), @Names AS varChar(30) AS IF @Type = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.LastName AS Lastname, tbCTRequest.FirstName AS Firstname, tbCTRequest.MiddleName AS Middlename, tbCTRequest.Code AS Code, tbCTRequest.TypeDescription AS Description, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDate, tbPatient.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbCTResult.Interpretation, tbCTResult.ResultDate, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbCTResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.CTnum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbCTRequest LEFT OUTER JOIN tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCTResult ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbCTRequest.Lastname LIKE @Names+'%' AND tbCTRequest.SwFin = 'Y' END IF @Type = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.LastName AS Lastname, tbXRRequest.FirstName AS Firstname, tbXRRequest.MiddleName AS Middlename, tbXRRequest.Code AS Code, tbXRRequest.TypeDescription AS Description, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDate, tbXRRequest.Film8 AS [8X10], tbXRRequest.Film10 AS [10X12], tbXRRequest.Film11 AS [11X14], tbXRRequest.Film14 AS [14X14], tbXRRequest.Film17 AS [14X17], tbPatient.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbXRResult.Interpretation, tbXRResult.ResultDate, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbXRResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.XRayNum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbXRRequest LEFT OUTER JOIN tbPatient ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbXRRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbXRResult ON tbXRRequest.RequestNum = tbXRResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbXRRequest.Lastname LIKE @Names+'%' AND tbXRRequest.SwFin = 'Y' END IF @Type = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbULRequest.LastName AS Lastname, tbULRequest.FirstName AS Firstname, tbULRequest.MiddleName AS Middlename, tbULRequest.Code AS Code, tbULRequest.TypeDescription AS Description, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDate, tbPatient.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbULResult.Interpretation, tbULResult.ResultDate, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbULResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.UltraNum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbULRequest LEFT OUTER JOIN tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbULResult ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbULRequest.Lastname LIKE @Names+'%' AND tbULRequest.SwFin = 'Y' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spMRI_CashPatientDetails] @HospNum as varchar(10), @Ornumber as varchar(10) /*Set @Hospnum = 'T3446576' set @Ornumber = 'OR1971017' */ as if isnumeric(@Hospnum) =1 select M.Hospnum,M.LastName, M.FirstName, M.MiddleName, M.HospNum, 'CASH' Room, 'CASH' OPDNo, M.CivilStatus, M.BirthDate, M.Age, A.RequestDocID, A.DoctorName from billing..tbcashassessment A Inner Join Patient_data..tbMaster M on A.Hospnum = m.HospNum where a.ornumber = @Ornumber else select M.LastName, M.FirstName, M.MiddleName, M.HospNum, 'CASH' Room, 'CASH' OPDNo, M.CivilStatusID, M.BirthDate, M.Age, A.RequestDocID, A.DoctorName from billing..tbcashassessment A Inner Join Patient_data..tbCashPatient M on A.Hospnum = m.HospNum where a.ornumber = @Ornumber GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_StatisticalReport] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2), @Miscellaneous as varchar(1) AS --set @StartDate = '10/01/2005' --set @EndDate = '10/10/2005' --set @RevenueID = 'MI'; --set @Miscellaneous = 'N'; select max(convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], max(case @RevenueID when 'MI' then E.OtherRevenue end) as Exam, sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_In, 0 as TotalTest_Out, sum(Amount) as Amount_In, 0 as Amount_Out from BILLING..tbBillDailyBill B left outer join BUILD_FILE..tbcoOtherRevenue E on B.ItemID = E.OtherRevenueID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID group by b.refnum having sum(cast(isnull(Amount,0) as Money)) <> 0 union all select max(convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], max(case @RevenueID when 'MI' then E.OtherRevenue end) as Exam, 0 as TotalTest_In, sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_Out, 0 as Amount_In, sum(Amount) as Amount_Out from BILLING..tbBillOPDailyOut B left outer join BUILD_FILE..tbcoOtherRevenue E on B.ItemID = E.OtherRevenueID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID group by b.refnum having sum(cast(isnull(Amount,0) as Money)) <> 0 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReturnedFilm] @RevenueID varchar(2), @SortType varchar(1) AS declare @cSQL varchar(1000) if @RevenueID = 'XR' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.XrayExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbxrborrowedfilm b ' + ' left join tbxrrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoXRayExam e ' + ' on r.code = e.xrayexamid ' + ' left join tbxrresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 1 ' end if @RevenueID = 'CT' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.CTExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbctborrowedfilm b ' + ' left join tbctrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoCTExam e ' + ' on r.code = e.CTExamid ' + ' left join tbctresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 1 ' end if @RevenueID = 'US' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.UltraExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbulborrowedfilm b ' + ' left join tbulrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoUltraExam e ' + ' on r.code = e.ultraexamid ' + ' left join tbulresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 1 ' end if @SortType = 'A' begin set @cSQL = @cSQL + ' order by Patient' end if @SortType = 'B' begin set @cSQL = @cSQL + ' order by Exam' end if @SortType = 'C' begin set @cSQL = @cSQL + ' order by ResultDate' end if @SortType = 'D' begin set @cSQL = @cSQL + ' order by BorrowedBy' end if @SortType = 'E' begin set @cSQL = @cSQL + ' order by BorrowedDate' end if @SortType = 'F' begin set @cSQL = @cSQL + ' order by b.Location' end if @SortType = 'G' begin set @cSQL = @cSQL + ' order by BorrowUserID' end if @SortType = 'H' begin set @cSQL = @cSQL + ' order by Returnedby' end if @SortType = 'I' begin set @cSQL = @cSQL + ' order by ReturnedDate' end if @SortType = 'J' begin set @cSQL = @cSQL + ' order by ReturnUserID' end exec (@cSQL) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spMRI_CashPatientCharges] @OrNumber as Varchar(10) As select A.RevenueID, A.ItemID, OtherRevenue, A.Amount / A.Quantity As Price, A.Quantity, A.Amount from billing..tbcashassessment A Left Join Build_File..tbcoOtherRevenue B on A.ItemID = B.OtherREvenueID where ornumber = @OrNumber GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_StatisticalReportPerPhysician] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS --set @StartDate = '10/01/2005'; --set @EndDate = '10/10/2005'; --set @RevenueID = 'MI' Select max(Y.[Procedure]) [Procedure], sum(Case When Y.PatientType = 'IN' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYIN, sum(Case When Y.PatientType = 'OUT' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYOUT, sum(Case When Y.PatientType = 'IN' Then Y.Amount Else 0 End) AmountIN, sum(Case When Y.PatientType = 'OUT' Then Y.Amount Else 0 End) AmountOUT, sum(Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * -1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End) TotalQTY, Sum(Y.Amount) TotalAmount, max(ltrim(Y.Physician)) Physician From (Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else 'OUT' End PatientType, sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician] From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum Union All Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else (Case When max(A.CashType) = 'I' Then 'IN' Else 'OUT' End) End PatientType, sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician] From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum ) Y Group By Y.Physician, Y.[Procedure] Having Sum(Y.Amount) > 0 GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_RevokeNurseRequest] @RequestNum varchar(10), @UserID varchar(10) AS update STATION..tbNurseCommunicationFile set RecordStatus = 'R' where RequestNum = @RequestNum update STATION..tbNurseLogBook set RecordStatus = 'R', ChangeDate = GETDATE(), ChangeBy = @UserID where RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Inv_XRFilmStocks] --Declare @SummaryCode varchar(2), @Hospnum varchar(10), @Idnum varchar(10), @ItemID varchar(10), @TransDate datetime, @RevenueID varchar(2), @RefNum varchar(10), @Quantity as float, @Balance as float, @NetCost as float, @Amount as float, @LocationID varchar(5), @UserID varchar(10) AS --DISPENSE FILM if @RevenueID = 'CS' Begin Insert Into Inventory..tbInvStockCard (SummaryCode,Hospnum,Idnum,ItemID,TransDate,RevenueID,RefNum,Quantity,Balance,NetCost,Amount,LocationID,UserID) Values(@SummaryCode,@Hospnum,@Idnum,@ItemID,@TransDate,@RevenueID,@RefNum,@Quantity,@Balance,@NetCost,@Amount,@LocationID,@UserID) Update Inventory..TbInvent set onHand = onHand - @Quantity where itemid = @ItemID and LocationID = @LocationID End else --RETURN FILM Begin Insert Into Inventory..tbInvStockCard (SummaryCode,Hospnum,Idnum,ItemID,TransDate,RevenueID,RefNum,Quantity,Balance,NetCost,Amount,LocationID,UserID) Values(@SummaryCode,@Hospnum,@Idnum,@ItemID,@TransDate,@RevenueID,@RefNum,@Quantity,@Balance,@NetCost,@Amount,@LocationID,@UserID) Update Inventory..TbInvent set onHand = onHand + @Quantity where itemid = @ItemID and LocationID = @LocationID end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spAssess_Revoke] @AssessNum as varchar(10), @RefNum as varchar(10), @RevenueID as varchar(2) AS UPDATE BILLING..tbCashAssessment SET RecordStatus = 'R', ORNumber = 'REVOKED' WHERE AssessNum = @AssessNum AND RefNum = @RefNum AND RevenueID = @RevenueID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Radio_BriefHistory] @Type varchar(2), @IDNum varchar(20), @ImagingReason varchar(50) = '', @SurgicalReason varchar(50) = '' AS /* 0 - Retrieve 1 - Update 2 - Insert */ if @Type = '0' Begin if isnumeric(@IdNum) = 0 Begin Select top 1 cast(isnull(PH.ChiefComplaints,'')as text)as ChiefComplaint, -- cast(isnull(PH.AdmDiagnosis,'')as text) as AdmDiagnosis, '' as AdmDiagnosis, cast(isnull(PH.ImagingReason,'')as text) as ImagingReason, cast(isnull(PH.SurgicalReason,'')as text) as SurgicalReason From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum Where P.IdNum = @IdNum End; if isnumeric(@IdNum) = 1 begin Select top 1 cast(isnull(PH.ChiefComplaint,'')as text)as ChiefComplaint, cast(isnull(PH.AdmDiagnosis,'')as text) as AdmDiagnosis, cast(isnull(PH.ImagingReason,'')as text) as ImagingReason, cast(isnull(PH.SurgicalReason,'')as text) as SurgicalReason From PATIENT_DATA..tbPatient P left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum Where P.IdNum = @IdNum end; End --if @Type = '1' -- Begin -- if isnumeric(@IdNum) = 0 -- Begin -- Update PATIENT_DATA..tbOUTPatientHistory -- Set ImagingReason = @ImagingReason, -- SurgicalReason = @SurgicalReason -- Where IDNum = @IDNum; -- End; -- if isnumeric(@IdNum) = 1 -- Begin -- Update PATIENT_DATA..tbPatientHistory -- Set ImagingReason = @ImagingReason, -- SurgicalReason = @SurgicalReason -- Where IDNum = @IDNum; -- End; -- End if @Type = '1' Begin if isnumeric(@IdNum) = 0 Begin if not exists(Select IDNum From Patient_Data..tbOutPatientHistory Where IDNum= @IDNum) Begin Insert Into PATIENT_DATA..tbOUTPatientHistory(IDNum, ImagingReason, SurgicalReason) Values(@IDNum, @ImagingReason, @SurgicalReason); End ELSE Begin Update PATIENT_DATA..tbOUTPatientHistory Set ImagingReason = @ImagingReason, SurgicalReason = @SurgicalReason Where IDNum = @IDNum; End End; if isnumeric(@IdNum) = 1 Begin if not exists(Select IDNum From Patient_Data..tbPatientHistory Where IDNum= @IDNum) Begin Insert Into PATIENT_DATA..tbPatientHistory(IDNum, ImagingReason, SurgicalReason) Values(@IDNum, @ImagingReason, @SurgicalReason); End ELSE Begin Update PATIENT_DATA..tbPatientHistory Set ImagingReason = @ImagingReason, SurgicalReason = @SurgicalReason Where IDNum = @IDNum; End; End; End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[spRadio_GetMammoGram] @HospNum as varchar(10) AS If isNumeric(@HospNum) = 1 Begin Select MammoNum From Patient_Data..tbMaster Where HospNum = @Hospnum; End; Else Begin Select MammoNum From Patient_Data..tbCashPatient Where HospNum = @Hospnum; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveExamFormFormats] @DepartmentID as varchar(2), @ExamID as varchar(5), @FormType as varchar(2) AS if @DepartmentID = 'CT' begin Update BUILD_FILE..tbCoCtExam Set FormType = @FormType where CTExamID = @ExamID end; if @DepartmentID = 'XR' begin Update BUILD_FILE..tbCoXrayExam Set FormType = @FormType where XrayExamID = @ExamID end; if @DepartmentID = 'US' begin Update BUILD_FILE..tbCoUltraExam Set FormType = @FormType where UltraExamID = @ExamID end; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_CashPatients] @Current varchar(1), @SearchType varchar(1), @SearchCriteria varchar(50) AS IF @SearchType = '0' BEGIN select m.HospNum [Hosp. #], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from patient_data..tbcashpatient m where m.lastname like @SearchCriteria + '%' and isnumeric(m.HospNum) = 0 /* union all select m.HospNum [Hosp. #], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from patient_data..tbMaster m where m.lastname like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename */ END IF @SearchType = '1' BEGIN -- if isnumeric(@SearchCriteria) = 0 -- begin select m.hospnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, m.civilstatusid [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbcashpatient m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.HospNum = @SearchCriteria and isnumeric(m.HospNum) = 0 -- end /* else begin select m.hospnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbMaster m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.HospNum = @SearchCriteria end */ END IF @SearchType = '2' BEGIN select count(*) [RecCount] from ( select HospNum from patient_data..tbcashpatient m where m.lastname like @SearchCriteria + '%' and isnumeric(m.HospNum) = 0 /* union all select HospNum from patient_data..tbMaster m where m.lastname like @SearchCriteria + '%' */ ) as a END IF @SearchType = '4' BEGIN select m.hospnum, m.lastname, m.firstname, m.middlename, m.civilstatusid [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbcashpatient m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' and isnumeric(m.HospNum) = 0 -- order by m.lastname /* union all select m.hospnum, m.lastname, m.firstname, m.middlename, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbMaster m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' order by m.lastname */ END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_ConfinedPatients] @Current varchar(1), @SearchType varchar(1), @SearchCriteria varchar(50) AS IF @SearchType = '0' BEGIN select p.idnum [Adm. #], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name], CONVERT(VARCHAR, p.admdate, 101) [Adm. Date] from patient_data..tbpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' and (@Current = '0'and p.dcrdate is null) order by m.lastname, m.firstname, m.middlename END IF @SearchType = '1' BEGIN select p.idnum, p.hospnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, -- p.admdate, p.dcrdate, p.billingdate, CONVERT(VARCHAR, p.admdate, 101) admdate, isnull(CONVERT(VARCHAR, p.dcrdate, 101),'') dcrdate, isnull(CONVERT(VARCHAR, p.billingdate, 101),'') billingdate, p.accountnum, case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else isnull(c.company,'') end as company, m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province, p.RoomID, r.RoomClassID, p.AttendingDr1 [AttendingDrID], isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') + ' ' + isnull(d.MiddleName, '') [AttendingDr], isnull(p2.OkeyXRay, 0) OkeyXRay, isnull(p2.OkeyUltra, 0) OkeyUltra, isnull(p2.OkeyCT, 0) OKeyCT from patient_data..tbpatient p left join patient_data..tbpatient2 p2 on p.idnum = p2.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode left join build_file..tbCoRoom r on p.roomid = r.roomid left join build_file..tbCoDoctor d on p.AttendingDr1 = d.DoctorID where p.idnum = @SearchCriteria END IF @SearchType = '2' BEGIN select count(*) [RecCount] from patient_data..tbpatient p left join tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' END IF @SearchType = '4' BEGIN select p.idnum, p.hospnum, m.lastname, m.firstname, m.middlename, p.admdate, p.dcrdate, p.billingdate, p.accountnum, case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else c.company end as company, m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' order by m.lastname END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_InpatientCensus] AS select m.lastname + ', ' + m.firstname + ' ' + m.middlename patient, p.idnum, p.admdate, p.accountnum, isnull(c.company, p.accountnum) company, p.roomid, p.attendingdr1, left(d.firstname, 1) + '. ' + d.lastname doctor, p2.remarks, r.stationid, s.station, s.reportorder+r.stationid [reportorder] from PATIENT_DATA..tbpatient p left join PATIENT_DATA..tbpatient2 p2 on p.idnum = p2.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BUILD_FILE..tbcocompany c on p.accountnum = c.accountnum left join BUILD_FILE..tbcodoctor d on p.attendingdr1 = d.doctorid left join BUILD_FILE..tbcoroom r on p.roomid = r.roomid left join BUILD_FILE..tbcostation s on r.stationid = s.stationid where p.dcrdate is null GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO --BSL for Saving of Discounts March 13,2003 CREATE PROCEDURE [dbo].[spRadio_SaveDiscount] @IdNum as varchar(10), @HospNum as varchar(10), @RevenueID as varchar(5), @ItemID as varchar(5), @RefNum as varchar(10), @Amount as float, @UserID as varchar(10) AS declare @DrCr as varchar(10) set @DrCr = 'D' /*(select case left(@Amount,1) when '-' then 'D' else 'C' end as [DrCr])*/ Insert into Billing..tbBillOPDailyOut (IdNum,HospNum, TransDate, RevenueID, DrCr, ItemID, RefNum, Amount, UserID) Values (@IdNum, @HospNum, getdate(), @RevenueID, @DrCr, @ItemID, @RefNum, (@Amount * -1), @UserID); GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_ListWalkIn] @Type as varchar(1), @Criteria as varchar(30) AS select hospnum, lastname, firstname, middlename from PATIENT_DATA..tbcashpatient where lastname like @Criteria + '%' order by lastname, firstname, middlename GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_VerifySlip] @RefNum varchar(10) AS select S.IDNUM [ADM. #], S.REVENUEID + S.ITEMID [CODE], CASE S.REVENUEID WHEN 'MI' THEN MR.OtherRevenue WHEN 'MD' THEN 'DR. ' + MD.LASTNAME + ', ' + MD.FIRSTNAME + ' ' + MD.MIDDLENAME ELSE R.ITEMNAME END DESCRIPTION, S.QUANTITY, convert(numeric(15, 2), S.AMOUNT) AMOUNT, S.USERID [ENCODER] FROM ( select idnum, transdate, revenueid, itemid, quantity, amount, userid from billing..tbbilldailybill where refnum = @RefNum union all select idnum, transdate, revenueid, Itemid, quantity, amount, userid from billing..tbbillopdailyout where refnum = @RefNum ) AS S LEFT OUTER JOIN BUILD_FILE..TBCOREVENUECODE R ON S.REVENUEID = R.REVENUEID LEFT OUTER JOIN BUILD_FILE..TBCOOtherRevenue MR ON S.ITEMID = MR.OtherRevenue LEFT OUTER JOIN BUILD_FILE..TBCODOCTOR MD ON S.ITEMID = MD.DOCTORID ORDER BY S.TRANSDATE GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveExamBuild] @RevenueID varchar(2), @ExamID varchar(10), @Exam varchar(50), @SectionID varchar(3), @RateA float, @RateB float, @RateC float, @RateD float, @RateE float, @Status varchar(1), @Classification varchar(1) AS declare @NewExamID varchar(10) if @RevenueID = 'XR' begin if exists(select * from BUILD_FILE..tbCoXRayExam where XRayExamID = @ExamID) begin update BUILD_FILE..tbCoXRayExam set XRayExam = @Exam, XRaySectionID = @SectionID, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, RateE = @RateE, Status = @Status, Classification = @Classification where XRayExamID = @ExamID end else begin if @ExamID = 'NEW' begin select @NewExamID = max(cast(XRayExamID as int)) + 1 from BUILD_FILE..tbCoXrayExam where isnumeric(XRayExamID) = 1 end else begin set @NewExamID = @ExamID end insert into BUILD_FILE..tbCoXrayExam (XRayExamID, XrayExam, XRaySectionID, RateA, RateB, RateC, RateD, RateE, Status, Classification) values (@NewExamID, @Exam, @SectionID, @RateA, @RateB, @RateC, @RateD, @RateE, @Status, @Classification) end end if @RevenueID = 'CT' begin if exists(select * from BUILD_FILE..tbCoCTExam where CTExamID = @ExamID) begin update BUILD_FILE..tbCoCTExam set CTExam = @Exam, CTSectionID = @SectionID, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, RateE = @RateE, Status = @Status, Classification = @Classification where CTExamID = @ExamID end else begin if @ExamID = 'NEW' begin select @NewExamID = max(cast(CTExamID as int)) + 1 from BUILD_FILE..tbCoCTExam where isnumeric(CTExamID) = 1 end else begin set @NewExamID = @ExamID end insert into BUILD_FILE..tbCoCTExam (CTExamID, CTExam, CTSectionID, RateA, RateB, RateC, RateD, RateE, Status, Classification) values (@NewExamID, @Exam, @SectionID, @RateA, @RateB, @RateC, @RateD, @RateE, @Status, @Classification) end end if @RevenueID = 'US' begin if exists(select * from BUILD_FILE..tbCoUltraExam where UltraExamID = @ExamID) begin update BUILD_FILE..tbCoUltraExam set UltraExam = @Exam, UltraSectionID = @SectionID, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, RateE = @RateE, Status = @Status, Classification = @Classification where UltraExamID = @ExamID end else begin if @ExamID = 'NEW' begin select @NewExamID = max(cast(UltraExamID as int)) + 1 from BUILD_FILE..tbCoUltraExam where isnumeric(UltraExamID) = 1 end else begin set @NewExamID = @ExamID end insert into BUILD_FILE..tbCoUltraExam (UltraExamID, UltraExam, UltraSectionID, RateA, RateB, RateC, RateD, RateE, Status, Classification) values (@NewExamID, @Exam, @SectionID, @RateA, @RateB, @RateC, @RateD, @RateE, @Status, @Classification) end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_LoadWalkIn] @HospNum varchar(10) AS select isnull(c.hospnum, '') HospNum, isnull(c.lastname, '') LastName, isnull(c.firstname, '') FirstName, isnull(c.middlename, '') MiddleName, isnull(c.housestreet, '') Address1, isnull(c.barangay, '') as Address2, isnull(c.zipcode, '') ZipCode, case when a.zipcode is null then '' else a.town + ', ' + a.province end as Address3, c.Sex, c.BirthDate, c.CivilStatusID, c.Age from PATIENT_DATA..tbcashpatient c left join BUILD_FILE..tbcoaddress a on c.zipcode = a.zipcode where hospnum = @HospNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveExams] @XrayExamID AS varChar(4), @XrayExam AS varChar(45), @RateA AS Float, @RateB AS Float, @RateC AS Float, @RateD AS Float AS INSERT INTO tbCoXrayExam ( XrayExamID, XrayExam, RateA, RateB, RateC, RateD) VALUES ( @XrayExamID, @XrayExam, @RateA, @RateB, @RateC, @RateD) GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --alter Date: April 04, 2003 11:33 BSL CREATE PROCEDURE [dbo].[spGlobal_RegisteredER] @Current varchar(1), @SearchType varchar(1), @SearchCriteria varchar(50) AS declare @Today datetime set @Today = cast(convert(varchar(10), getdate(), 101) as datetime) IF @SearchType = '0' BEGIN select p.idnum [Adm. #], isnull(m.lastname,'') [Last Name], isnull(m.firstname,'') [First Name], isnull(m.middlename,'') [Middle Name], CONVERT(VARCHAR, p.admdate, 101) [Adm. Date] from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' and isnull(P.ERNum,'') <> '' --and (@Current = '0' or p.dcrdate is null) and (@Current = '0' or p.admdate >= @Today) order by m.lastname, m.firstname, m.middlename END IF @SearchType = '1' BEGIN select isnull(p.idnum,'') [IDNum], isnull(p.hospnum,'') [HospNum], isnull(m.lastname,'') [LastName], isnull(m.firstname,'') [FirstName], isnull(m.middlename,'') [MiddleName], isnull(p.admdate,'') [AdmDate], isnull(p.dcrdate,'') [DCRDate], isnull(convert(varchar(50), p.billingdate, 100),'') [BillingDate], isnull(p.accountnum,'') [AccountNum], case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else c.company end as company, c.Class [CompanyClassID], m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where p.idnum = @SearchCriteria and isnull(P.ERNum,'') <> '' END IF @SearchType = '2' BEGIN select count(*) [RecCount] from patient_data..tboutpatient p left join tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' and isnull(P.ERNum,'') <> '' END IF @SearchType = '4' BEGIN select p.idnum, p.hospnum, m.lastname, m.firstname, m.middlename, isnull(p.admdate,'') [admdate], isnull(p.dcrdate,'') [dcrdate], isnull(p.billingdate,'') [billingdate], isnull(p.accountnum,'') [accountnum], case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else c.company end as company, m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' and isnull(P.ERNum,'') <> '' order by m.lastname END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_RegisteredOPD] @Current varchar(1), @SearchType varchar(1), @SearchCriteria varchar(50) AS declare @Today datetime set @Today = cast(convert(varchar(10), getdate(), 101) as datetime) IF @SearchType = '0' BEGIN if @SearchCriteria = '' begin set @SearchCriteria = 'A' end if @Current = '0' begin select p.idnum [Adm. #], isnull(m.lastname,'') [Last Name], isnull(m.firstname,'') [First Name], isnull(m.middlename,'') [Middle Name], CONVERT(VARCHAR, p.admdate, 101) [Adm. Date] from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' -- and p.dcrdate is null --**unmarked by BSL 05/28/2004 and p.admdate >= @Today and p.billingdate is null --**marked by BSL 05/28/2004 and P.OPDStatus <> 'R' and P.PatientType <> 'W' ----January 26'06 order by m.lastname, m.firstname, m.middlename end if @Current = '1' begin select p.idnum [Adm. #], isnull(m.lastname,'') [Last Name], isnull(m.firstname,'') [First Name], isnull(m.middlename,'') [Middle Name], CONVERT(VARCHAR, p.admdate, 101) [Adm. Date] from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' and (P.OPDStatus <> 'R' and isnull(p.dcrdate,'') <> '') order by m.lastname, m.firstname, m.middlename end END IF @SearchType = '1' BEGIN select isnull(p.idnum,'') [IDNum], isnull(p.hospnum,'') [HospNum], isnull(m.lastname,'') [LastName], isnull(m.firstname,'') [FirstName], isnull(m.middlename,'') [MiddleName], isnull(p.admdate,'') [AdmDate], isnull(p.dcrdate,'') [DCRDate], isnull(convert(varchar(50), p.billingdate, 100),'') [BillingDate], isnull(p.accountnum,'') [AccountNum], case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else c.company end as company, c.Class [CompanyClassID], m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where p.idnum = @SearchCriteria and (@Current = '0' or p.DcrDate is NULL)-- p.admdate >= @Today) marked 05/28/2004 by BSl END IF @SearchType = '2' BEGIN select count(*) [RecCount] from patient_data..tboutpatient p left join tbmaster m on p.hospnum = m.hospnum where m.lastname like @SearchCriteria + '%' END IF @SearchType = '4' BEGIN select p.idnum, p.hospnum, m.lastname, m.firstname, m.middlename, isnull(p.admdate,'') [admdate], isnull(p.dcrdate,'') [dcrdate], isnull(p.billingdate,'') [billingdate], isnull(p.accountnum,'') [accountnum], case when isnull(p.accountnum, '') = p.hospnum then 'PERSONAL' when isnull(p.accountnum, '') = '' then 'PERSONAL' else c.company end as company, m.civilstatus, m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tboutpatient p left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcocompany c on p.accountnum = c.accountnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' order by m.lastname END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[Radio_InterpretationTable] @Mode as varchar(2), @InterpretCode as varchar(10), @RevenueID as varchar(2), @FieldName1 as varchar(100) = '', @FieldName2 as varchar(100) = '', @FieldName3 as varchar(100) = '', @FieldName4 as varchar(100) = '', @FieldName5 as varchar(100) = '', @FieldName6 as varchar(100) = '', @FieldName7 as varchar(100) = '', @FieldName8 as varchar(100) = '', @FieldName9 as varchar(100) = '', @FieldName10 as varchar(100) = '', @FieldName11 as varchar(100) = '', @FieldName12 as varchar(100) = '', @FieldName13 as varchar(100) = '', @ResultGrid1 as varchar(100) = '', @ResultGrid2 as varchar(100) = '', @ResultGrid3 as varchar(100) = '', @ResultGrid4 as varchar(100) = '', @ResultGrid5 as varchar(100) = '', @ResultGrid6 as varchar(100) = '', @ResultGrid7 as varchar(100) = '', @ResultGrid8 as varchar(100) = '', @ResultGrid9 as varchar(100) = '', @ResultGrid10 as varchar(100) = '', @ResultGrid11 as varchar(100) = '', @ResultGrid12 as varchar(100) = '', @ResultGrid13 as varchar(100) = '', @ResultGrid14 as varchar(100) = '', @ResultGrid15 as varchar(100) = '', @ResultGrid16 as varchar(100) = '', @ResultGrid17 as varchar(100) = '', @ResultGrid18 as varchar(100) = '', @ResultGrid19 as varchar(100) = '', @ResultGrid20 as varchar(100) = '', @ResultGrid21 as varchar(100) = '', @ResultGrid22 as varchar(100) = '', @ResultGrid23 as varchar(100) = '', @ResultGrid24 as varchar(100) = '', @ResultGrid25 as varchar(100) = '', @ResultGrid26 as varchar(100) = '', @ResultGrid27 as varchar(100) = '', @ResultGrid28 as varchar(100) = '' AS if @Mode = '0' Begin if exists(Select Top 1 * from Radiology..tbRadioInterpretTable Where RevenueID = @RevenueID and InterpretCode = @InterpretCode) Begin Update Radiology..tbRadioInterpretTable Set ResultGrid1 = @ResultGrid1, ResultGrid2 = @ResultGrid2, ResultGrid3 = @ResultGrid3, ResultGrid4 = @ResultGrid4, ResultGrid5 = @ResultGrid5, ResultGrid6 = @ResultGrid6, ResultGrid7 = @ResultGrid7, ResultGrid8 = @ResultGrid8, ResultGrid9 = @ResultGrid9, ResultGrid10 = @ResultGrid10, ResultGrid11 = @ResultGrid11, ResultGrid12 = @ResultGrid12, ResultGrid13 = @ResultGrid13, ResultGrid14 = @ResultGrid14, ResultGrid15 = @ResultGrid15, ResultGrid16 = @ResultGrid16, ResultGrid17 = @ResultGrid17, ResultGrid18 = @ResultGrid18, ResultGrid19 = @ResultGrid19, ResultGrid20 = @ResultGrid20, ResultGrid21 = @ResultGrid21, ResultGrid22 = @ResultGrid22, ResultGrid23 = @ResultGrid23, ResultGrid24 = @ResultGrid24, ResultGrid25 = @ResultGrid25, ResultGrid26 = @ResultGrid26, ResultGrid27 = @ResultGrid27, ResultGrid28 = @ResultGrid28, FieldName1 = @FieldName1, FieldName2 = @FieldName2, FieldName3 = @FieldName3, FieldName4 = @FieldName4, FieldName5 = @FieldName5, FieldName6 = @FieldName6, FieldName7 = @FieldName7, FieldName8 = @FieldName8, FieldName9 = @FieldName9, FieldName10 = @FieldName10, FieldName11 = @FieldName11, FieldName12 = @FieldName12, FieldName13 = @FieldName13 Where RevenueID = @RevenueID and InterpretCode = @InterpretCode End else Begin Insert into Radiology..tbRadioInterpretTable( InterpretCode, RevenueID, ResultGrid1, ResultGrid2, ResultGrid3, ResultGrid4, ResultGrid5, ResultGrid6, ResultGrid7, ResultGrid8, ResultGrid9, ResultGrid10, ResultGrid11, ResultGrid12, ResultGrid13, ResultGrid14, ResultGrid15, ResultGrid16, ResultGrid17, ResultGrid18, ResultGrid19, ResultGrid20, ResultGrid21, ResultGrid22, ResultGrid23, ResultGrid24, ResultGrid25, ResultGrid26, ResultGrid27, ResultGrid28, FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, FieldName6, FieldName7, FieldName8, FieldName9, FieldName10, FieldName11, FieldName12, FieldName13, Active) Values( @InterpretCode, @RevenueID, @ResultGrid1, @ResultGrid2, @ResultGrid3, @ResultGrid4, @ResultGrid5, @ResultGrid6, @ResultGrid7, @ResultGrid8, @ResultGrid9, @ResultGrid10, @ResultGrid11, @ResultGrid12, @ResultGrid13, @ResultGrid14, @ResultGrid15, @ResultGrid16, @ResultGrid17, @ResultGrid18, @ResultGrid19, @ResultGrid20, @ResultGrid21, @ResultGrid22, @ResultGrid23, @ResultGrid24, @ResultGrid25, @ResultGrid26, @ResultGrid27, @ResultGrid28, @FieldName1, @FieldName2, @FieldName3, @FieldName4, @FieldName5, @FieldName6, @FieldName7, @FieldName8, @FieldName9, @FieldName10, @FieldName11, @FieldName12, @FieldName13, '1') End End if @Mode = '1' Begin Select * From Radiology..tbRadioInterpretTable Where InterpretCode = @InterpretCode and RevenueID = @RevenueID End --if @Mode = '2' --Begin -- --if exists(Select Top 1 * from Radiology..tbRadioInterpretTable Where RequestNum = @InterpretCode) -- Begin -- Update Radiology..tbRadioInterpretTable -- Set FieldName1 = @FieldName1, FieldName2 = @FieldName2, FieldName3 = @FieldName3, FieldName4 = @FieldName4, -- FieldName5 = @FieldName5, FieldName6 = @FieldName6, FieldName7 = @FieldName7, FieldName8 = @FieldName8, -- FieldName9 = @FieldName9, FieldName10 = @FieldName10, FieldName11 = @FieldName11, FieldName12 = @FieldName12, -- FieldName13 = @FieldName13, FieldName14 = @FieldName14, FieldName15 = @FieldName15 -- Where RequestNum = @InterpretCode and RevenueID = @RevenueID -- End --else -- Begin -- Insert into Radiology..tbRadioInterpretTable( -- RequestNum, RevenueID, -- FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, -- FieldName6, FieldName7, FieldName8, FieldName9, FieldName10, -- FieldName11, FieldName12, FieldName13, FieldName14, FieldName15) -- Values( -- @InterpretCode, @RevenueID, -- @FieldName1, @FieldName2, @FieldName3, @FieldName4, @FieldName5, -- @FieldName6, @FieldName7, @FieldName8, @FieldName9, @FieldName10, -- @FieldName11, @FieldName12, @FieldName13, @FieldName14, @FieldName15) -- End --End -- -- -- --if @Mode = '3' --Begin -- Select * From Radiology..tbRadioInterpretTable -- Where RequestNum = @InterpretCode and RevenueID = @RevenueID --End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Radio_ReportDoctorsContribution] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Declare @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) Set @StartDate = '08/01/2003'; Set @EndDate = '08/31/2003'; set @RevenueID = 'XR' */ Select max(isnull(RequestDocID,'')) DoctorID, Case When isnull(max(RequestDocID),'0') = '0' or isnull(max(RequestDocID),'0') = '' Then isnull(max(A.DoctorName),'') Else Cardio.dbo.fn_GetDoctorsName(max(RequestDocID)) End as DoctorName, max(C.[Description]) as [Procedure], Cardio.dbo.fn_GetPatientName(max(B.Hospnum)) PatientName, isnull(Case When @RevenueID = 'XR' Then max(XrayNum) When @RevenueID = 'US' Then max(UltraNum) When @RevenueID = 'CT' Then max(CTNum) End,'') as [Control #], max(Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate)) Age, max(D.Sex) as Sex, max(B.RoomID) as RoomID, max(A.TransDate) as Transdate, sum(A.Amount) as Amount, max(isnull(CO.Company,'Personal')) as Company From Billing..tbBilldailybill A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum left outer join BUILD_FILE..tbCoCompany CO ON B.AccountNum = CO.AccountNum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemId, A.IdNum Union All Select max(RequestDocID) DoctorID, Case When isnull(max(RequestDocID),'0') = '0' or isnull(max(RequestDocID),'0') = '' Then max(A.DoctorName) Else Cardio.dbo.fn_GetDoctorsName(max(RequestDocID)) End as DoctorName, max(C.[Description]) as [Procedure], Case When Left(A.Refnum,2) = 'OR' Then isnull(max(F.PaymentFrom),'') Else Cardio.dbo.fn_GetPatientName(max(B.Hospnum)) End PatientName, isnull(Case When @RevenueID = 'XR' Then max(D.XrayNum) When @RevenueID = 'US' Then max(D.UltraNum) When @RevenueID = 'CT' Then max(D.CTNum) End,'') as [Control #], max(Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate)) Age, (Case When Left( ltrim(max(A.HospNum)), 1) = 'T' Then max(E.Sex) Else max(D.Sex) End) as Sex, Case When len(isnull(max(B.ERnum),'')) > 0 then 'ER' Else 'OPD' End RoomID, max(A.TransDate) as TransDate, sum(A.Amount) as Amount, max(isnull(CO.Company,'Personal')) as Company From Billing..tbBillOpDailyOut A Left Outer Join Patient_Data..tbOutPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Left Outer Join Patient_Data..tbCashPatient E On A.HospNum = E.HospNum Left Outer Join Billing..tbCashORMaster F On A.Refnum = F.RefNum left outer join BUILD_FILE..tbCoCompany CO ON B.AccountNum = CO.AccountNum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemId, A.IdNum /* Select Distinct RequestDocID DoctorID, Case When isnull(RequestDocID,'0') = '0' or isnull(RequestDocID,'0') = '' Then isnull(A.DoctorName,'') Else Cardio.dbo.fn_GetDoctorsName(RequestDocID) End as DoctorName, C.[Description] as [Procedure], Cardio.dbo.fn_GetPatientName(B.Hospnum) PatientName, isnull(Case When @RevenueID = 'XR' Then XrayNum When @RevenueID = 'US' Then UltraNum When @RevenueID = 'CT' Then CTNum End,'') as [Control #], Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate) Age, D.Sex, B.RoomID, A.TransDate, A.Amount From Billing..tbBilldailybill A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Union All Select Distinct RequestDocID DoctorID, Case When isnull(RequestDocID,'0') = '0' or isnull(RequestDocID,'0') = '' Then A.DoctorName Else Cardio.dbo.fn_GetDoctorsName(RequestDocID) End as DoctorName, C.[Description] as [Procedure], Case When Left(A.Refnum,2) = 'OR' Then isnull(F.PaymentFrom,'') Else Cardio.dbo.fn_GetPatientName(B.Hospnum) End PatientName, isnull(Case When @RevenueID = 'XR' Then D.XrayNum When @RevenueID = 'US' Then D.UltraNum When @RevenueID = 'CT' Then D.CTNum End,'') as [Control #], Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate) Age, (Case When Left( ltrim(A.HospNum), 1) = 'T' Then E.Sex Else D.Sex End) as Sex, Case When len(isnull(B.ERnum,'')) > 0 then 'ER' Else 'OPD' End RoomID, A.TransDate, A.Amount From Billing..tbBillOpDailyOut A Left Outer Join Patient_Data..tbOutPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Left Outer Join Patient_Data..tbCashPatient E On A.HospNum = E.HospNum Left Outer Join Billing..tbCashORMaster F On A.Refnum = F.RefNum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID*/ GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_RegularPatients] @Current varchar(1), @SearchType varchar(1), @SearchCriteria varchar(50) AS IF @SearchType = '0' BEGIN select m.HospNum [Hosp. #], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from patient_data..tbMaster m where m.lastname like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename END IF @SearchType = '1' BEGIN select m.hospnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbMaster m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.HospNum = @SearchCriteria END IF @SearchType = '2' BEGIN select count(*) [RecCount] from ( select HospNum from patient_data..tbMaster m where m.lastname like @SearchCriteria + '%' ) as a END IF @SearchType = '4' BEGIN select m.hospnum, m.lastname, m.firstname, m.middlename, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as int) end as age, m.housestreet, m.barangay, a.town, a.province from patient_data..tbMaster m left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.lastname like @SearchCriteria+'%' order by m.lastname END IF @SearchType = '5' BEGIN select m.hospnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, m.civilstatusid [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province from Hemodialysis..tbHemoMaster H left outer join Patient_Data..tbCashPatient M on M.HospNum = H.HospNum left join build_file..tbcoaddress a on m.zipcode = a.zipcode where m.HospNum = @SearchCriteria and isnumeric(H.HospNum) = 0 END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Created By Jetty P. OMo --October 06,2007 CREATE PROCEDURE [dbo].[XRAY_PatientLedger] @PatientType varchar(1), @IDNum varchar(10) AS if @PatientType = 'I' begin SELECT B.RefNum As Refnum, case when B.DrCr = 'C' then (B.Amount * -1) else B.Amount END As Amount, B.RevenueID As Account, B.Quantity As Quantity, B.ItemID As ItemID, E.XrayExam As Exam, PasswordMain.initial as UserID,--rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, B.TransDate As Transdate, 'X-Ray' as Dept FROM Billing..tbBillDailyBill B LEFT OUTER JOIN Build_File..tbCoXRayExam E ON B.ItemID = E.XrayExamID LEFT OUTER JOIN (Select EmployeeID, Max(Initial) [Initial] From Password..tbPasswordMain Group by EmployeeID ) as PasswordMain ON B.UserID = PasswordMain.EmployeeID LEFT OUTER JOIN (Patient_Data..tbPatient inner join Patient_Data..tbMaster on Patient_Data..tbMaster.hospnum = Patient_Data..tbPatient.hospnum) on Patient_Data..tbPatient.idnum = B.idnum WHERE B.RevenueID = 'XR' and B.IDNum = @IDNum --and Substring(tbBillDailyBill.Refnum,len(tbBillDailyBill.Refnum),1) = 'L' UNION ALL SELECT B.RefNum As Refnum, case when B.DrCr = 'C' then (B.Amount * -1) else B.Amount END As Amount, B.RevenueID As Account, B.Quantity As Quantity, B.ItemID As ItemID, E.CTExam As Exam, PasswordMain.initial as UserID,--rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, B.TransDate As Transdate, 'CT-Scan' as Dept FROM Billing..tbBillDailyBill B LEFT OUTER JOIN Build_File..tbCoCTExam E ON B.ItemID = E.CTExamID LEFT OUTER JOIN (Select EmployeeID, Max(Initial) [Initial] From Password..tbPasswordMain Group by EmployeeID ) as PasswordMain ON B.UserID = PasswordMain.EmployeeID LEFT OUTER JOIN (Patient_Data..tbPatient inner join Patient_Data..tbMaster on Patient_Data..tbMaster.hospnum = Patient_Data..tbPatient.hospnum) on Patient_Data..tbPatient.idnum = B.idnum WHERE B.RevenueID = 'CT' and B.IDNum = @IDNum --and Substring(tbBillDailyBill.Refnum,len(tbBillDailyBill.Refnum),1) = 'L' UNION ALL SELECT B.RefNum As Refnum, case when B.DrCr = 'C' then (B.Amount * -1) else B.Amount END As Amount, B.RevenueID As Account, B.Quantity As Quantity, B.ItemID As ItemID, E.ULTRAExam As Exam, PasswordMain.initial as UserID,--rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, B.TransDate As Transdate, 'Ultrasound' as Dept FROM Billing..tbBillDailyBill B LEFT OUTER JOIN Build_File..tbCoULTRAExam E ON B.ItemID = E.ULTRAExamID LEFT OUTER JOIN (Select EmployeeID, Max(Initial) [Initial] From Password..tbPasswordMain Group by EmployeeID ) as PasswordMain ON B.UserID = PasswordMain.EmployeeID LEFT OUTER JOIN (Patient_Data..tbPatient inner join Patient_Data..tbMaster on Patient_Data..tbMaster.hospnum = Patient_Data..tbPatient.hospnum) on Patient_Data..tbPatient.idnum = B.idnum WHERE B.RevenueID = 'US' and B.IDNum = @IDNum end else --UNION ALL /*OutPatientBill*/ begin SELECT B.RefNum As RefNum, case when B.DrCr = 'C' then (B.Amount * -1) else B.Amount END As Amount, B.RevenueID As Account, B.Quantity As Quantity, B.ItemID As ItemID, E.XrayExamID As Exam, PasswordMain.Initial, --rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, B.TransDate As Transdate FROM Billing..tbBillOpDailyOut B LEFT OUTER JOIN Build_File..tbCoXRayExam E ON B.ItemID = E.XrayExamID LEFT OUTER JOIN ( Select EmployeeID, Max(Initial) [Initial] From Password..tbPasswordMain Group by EmployeeID ) as PasswordMain ON B.UserID = PasswordMain.EmployeeID LEFT OUTER JOIN (Patient_Data..tbOutPatient inner join Patient_Data..tbMaster on Patient_Data..tbMaster.hospnum = Patient_Data..tbOutPatient.hospnum) on Patient_Data..tbOutPatient.idnum = B.idnum WHERE B.RevenueID = 'XR' and B.IDNum = @IDNum --and Substring(tbBillOpDailyOut.Refnum,len(tbBillOpDailyOut.Refnum),1) = 'L' end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_RevokeAssessmentID] @AssessID int AS update BILLING..tbCashAssessment set Recordstatus = 'R', ORNumber = 'REVOKED' where AssessID = @AssessID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spGlobal_UpdateWalkIn] @HospNum varchar(8), @LastName varchar(50), @FirstName varchar(50), @MiddleName varchar(50), @BirthDate varchar(10), @Age varchar(5), @Sex varchar(1), @CivilStatusID varchar(1), @HouseStreet varchar(30), @Barangay varchar(20), @ZipCode varchar(4) AS DECLARE @dBirthDate as datetime IF @BirthDate = '' BEGIN SET @dBirthDate = NULL END ELSE BEGIN SET @dBirthDate = @BirthDate END UPDATE PATIENT_DATA..tbCashPatient SET LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, BirthDate = @dBirthDate, Age = @Age, Sex = @Sex, CivilStatusID = @CivilStatusID, HouseStreet = @HouseStreet, Barangay = @Barangay, ZipCode = @ZipCode WHERE HospNum = @HospNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By Jetty P. Omo Added the inventory Item for report Nov 26,2007 */ CREATE PROCEDURE [dbo].[spRadio_Inventory_Report] @Type varchar(2), @StartDate varchar(10), @EndDate varchar(10) AS if @type = 'CT' begin select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station, 'In Patient' as PatientType, Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 1 and RIGHT(REFNUM,1) = 'S' AND LEFT(REFNUM,1) = 'C' and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and RIGHT(REFNUM,1) = 'S' AND LEFT(REFNUM,1) = 'C' AND ISNUMERIC(IDNUM) = 1 ) > 0 Union all select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'OPD' as Station, 'Out Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 0 and RIGHT(REFNUM,1) = 'S' AND LEFT(REFNUM,1) = 'C' and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and (RIGHT(REFNUM,1) = 'S' AND LEFT(REFNUM,1) = 'C' And Left(Requestnum,2) = 'CT' ) AND ISNUMERIC(IDNUM) = 0 ) > 0 Union all select Q.userid, q.idnum, cash.Name [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'Cash' as Station, 'Cash Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left Outer Join billing..tbcashassessment cash on q.refnum = cash.Ornumber and q.itemid = Cash.itemid and cash.refnum = Q.requestnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and Q.idnum = 'cash' and q.itemid = Cash.itemid and cash.refnum = Q.requestnum and (Left(Requestnum,2) = 'CT' and Locationid = '141') and (Select sum(Amount) From Inventory..tbInvStockCard Where ItemID = Q.ItemID and (Left(Requestnum,2) = 'CT' and Locationid = '141') AND IDNUM = 'Cash' ) > 0 end if @type = 'XR' begin select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station, 'In Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 1 and RIGHT(REFNUM,1) = 'X' AND LEFT(REFNUM,1) = 'C' and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and RIGHT(REFNUM,1) = 'X' AND LEFT(REFNUM,1) = 'C' AND ISNUMERIC(IDNUM) = 1 ) > 0 Union all select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'OPD' as Station, 'Out Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 0 and (RIGHT(REFNUM,1) = 'X' AND LEFT(REFNUM,1) = 'C' or Left(Requestnum,2) = 'XR' and Locationid = '141') and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and RIGHT(REFNUM,1) = 'X' AND LEFT(REFNUM,1) = 'C' AND ISNUMERIC(IDNUM) = 0 ) > 0 Union all select Q.userid, q.idnum, cash.Name [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'Cash' as Station, 'Cash Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left Outer Join billing..tbcashassessment cash on q.refnum = cash.Ornumber and q.itemid = Cash.itemid and cash.refnum = Q.requestnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and Q.idnum = 'cash' and (Left(Requestnum,2) = 'XR' and Locationid = '141') and (Select sum(Amount) From Inventory..tbInvStockCard Where refnum = cash.Ornumber and ItemID = CAsh.ItemID and (Left(Requestnum,2) = 'XR' and Locationid = '141') AND IDNUM = 'cash' ) > 0 end if @type = 'US' begin select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station, 'In Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 1 and RIGHT(REFNUM,1) = 'U' AND LEFT(REFNUM,1) = 'C' and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and RIGHT(REFNUM,1) = 'U' AND LEFT(REFNUM,1) = 'C' AND ISNUMERIC(IDNUM) = 1 ) > 0 UNION ALL select Q.userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'OPD' as Station, 'Out Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and ISNUMERIC(Q.idnum ) = 0 and (RIGHT(REFNUM,1) = 'U' AND LEFT(REFNUM,1) = 'C' and (Left(Requestnum,2) = 'US' and Locationid = '141')) and (Select sum(Amount) From Inventory..tbInvStockCard Where Refnum = Q.Refnum and ItemID = Q.ItemID and RIGHT(REFNUM,1) = 'U' AND LEFT(REFNUM,1) = 'C' AND ISNUMERIC(IDNUM) = 0 ) > 0 Union all select Q.userid, q.idnum, cash.Name [patient], 'OPD'[roomid] , q.refnum, e.Itemname [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, 'Cash' as Station, 'Cash Patient' as PatientType,Q.Transdate from Inventory..tbInvStockCard q left join Inventory..tbInvMaster e on q.ItemID = e.itemid left Outer Join billing..tbcashassessment cash on q.refnum = cash.Ornumber and q.itemid = Cash.itemid and Q.requestnum = cash.refnum where (q.transdate Between @StartDate and @EndDate + ' 23:59:59.99') -- and isnull(swfin, '') <> 'C' and Q.idnum = 'cash' and q.itemid = Cash.itemid and cash.refnum = Q.requestnum and (Left(Requestnum,2) = 'US' and Locationid = '141') and (Select sum(Amount) From Inventory..tbInvStockCard Where ItemID = Q.ItemID and (Left(Requestnum,2) = 'US' and Locationid = '141') AND IDNUM = 'Cash' ) > 0 end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AddCashPatient] @strHospNum varChar(8), @strLastName varChar(50), @strFirstName varChar(50), @strMiddleName varChar(50), @strHouseStreet varChar(30), @strBarangay varChar(30), @strZipCode varChar(4), @strBirthDate varChar(10), @strCivilStatus varChar(1), @strAge varChar(3), @strSex varChar(1) AS INSERT INTO PATIENT_DATA..tbCashPatient (Hospnum,LastName,FirstName,MiddleName,HouseStreet,Barangay,ZipCode,Sex,BirthDate,CivilStatusID,Age) VALUES (@strHospNum,@strLastName,@strFirstName,@strMiddleName,@strHouseStreet,@strBarangay,@strZipCode,@strSex, @strBirthDate,@strCivilStatus,@strAge) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_Assessment Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_Assessment] @Type AS varChar(1), @Name AS varChar(60), @Transdate AS DateTime, @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @RefNum AS varChar(10) AS DECLARE @AssessmentNum AS varChar(10), @RevenueID AS varChar(2), @DrCr AS varChar(1), @AssessNum AS varChar(10) IF @Type = '1' /* CT-Scan */ BEGIN SET @RevenueID = 'CT' SET @DrCr = 'D' END IF @Type = '2' /* XRay */ BEGIN SET @RevenueID = 'XR' SET @DrCr = 'D' END IF @Type = '3' /* Ultrasound */ BEGIN SET @RevenueID = 'US' SET @DrCr = 'D' END /* Assessment Number */ SELECT @AssessmentNum = RTRIM(Convert(varChar(10), AssessmentNum)) FROM tbAssessmentNum UPDATE tbAssessmentNum SET AssessmentNum = AssessmentNum + 1 SET @AssessNum = 'AS' + RTRIM(@AssessmentNum) INSERT INTO tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, RefNum, Amount, RevenueID, UserID) VALUES ('ASSESS', @Name, GETDATE(), @AssessNum, @RevenueID, @DrCr, @ItemID, @Quantity, @RefNum, @Amount, @RevenueID, @UserID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_AssessmentEntry] @Type AS varChar(1), @Name AS varChar(60), @Transdate AS DateTime, @RevenueID as varchar(2), @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @RefNum AS varChar(10), @IdNum as varchar(10), @Hospnum as varchar(10), @RequestDocID as varchar(5) = null, @DoctorName as varchar(50) = null, @DeptCode as varchar(2) = NULL, @Film1 as varchar(10) = NULL, @Film2 as varchar(10) = NULL, @Film3 as varchar(10) = NULL, @Film4 as varchar(10) = NULL, @Film5 as varchar(10) = NULL, @Film6 as varchar(10) = NULL, @Film7 as varchar(10) = NULL, @ImagingReason as varchar(1000) = NULL, @SurgicalReason as varchar(1000) = NULL AS DECLARE @AssessmentNum AS varChar(10), @DrCr AS varChar(1), @AssessNum AS varChar(10) If @RequestDocID <> '0' Begin set @DoctorName = null; End IF @RevenueID = 'MD' BEGIN SET @DrCr = 'P' END ELSE BEGIN SET @DrCr = 'D' END /* Assessment Number */ SELECT @AssessmentNum = RTRIM(Convert(varChar(10), RequestNum)) FROM BILLING..tbAssessmentNum UPDATE BILLING..tbAssessmentNum SET RequestNum = RequestNum + 1 SET @AssessNum = 'AS' + RTRIM(@AssessmentNum) INSERT INTO BILLING..tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, RefNum, Amount, RevenueID, UserID, DepartmentID, Hospnum, RequestDocID, DoctorName, Film1,Film2, Film3, Film4, Film5, Film6, Film7, ImagingReason, SurgicalReason) VALUES (@IdNum, @Name, GETDATE(), @AssessNum, @RevenueID, @DrCr, @ItemID, @Quantity, @RefNum, @Amount, @RevenueID, @UserID, @DeptCode, @Hospnum, @RequestDocID, @DoctorName, @Film1,@Film2, @Film3, @Film4, @Film5, @Film6, @Film7, @ImagingReason, @SurgicalReason) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_LoadSOP] @DeptID as varchar(5), @SearchCriteria as varchar(30), @Type as varchar AS if @Type = '1' BEGIN select A.SOPCode, A.QPNumber, A.SOPTitle, A.SOPDescription, B.Department from Build_File..tbSOPMaster A LEFT OUTER JOIN Password..tbPasswordDepartment B ON A.DeptCode = B.DepartmentID where A.DeptCode = @DeptID and A.SOPTitle like @SearchCriteria + '%' END if @Type = '2' BEGIN select A.SOPCode, A.QPNumber, A.SOPTitle, A.SOPDescription from Build_File..tbSOPMaster A where A.DeptCode = @DeptID and A.SOPCode = @SearchCriteria END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /* replaces spRadio_AssessmentEntryHospNum */ CREATE PROCEDURE [dbo].[spRadio_AssessmentEntryDoctor] @Type AS varChar(1), @Name AS varChar(60), @Transdate AS DateTime, @RevenueID as varchar(2), @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @RefNum AS varChar(10), @HospNum as varchar(8), @IDNum as varchar(10), @DoctorID as varchar(4), @DoctorName as varchar(50) AS DECLARE @AssessmentNum AS varChar(10), @DrCr AS varChar(1), @AssessNum AS varChar(10), @DepartmentID as varchar(2) IF @RevenueID = 'MD' BEGIN SET @DrCr = 'P' END ELSE BEGIN SET @DrCr = 'D' END if @Type = '1' begin set @DepartmentID = 'CT' end if @Type = '2' begin set @DepartmentID = 'XR' end if @Type = '3' begin set @DepartmentID = 'US' end /* Assessment Number */ SELECT @AssessmentNum = RTRIM(Convert(varChar(10), RequestNum)) FROM BILLING..tbAssessmentNum UPDATE BILLING..tbAssessmentNum SET RequestNum = RequestNum + 1 SET @AssessNum = 'AS' + RTRIM(@AssessmentNum) INSERT INTO BILLING..tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, RefNum, Amount, RevenueID, UserID, HospNum, DepartmentID, RequestDocID, DoctorName) VALUES (@IDNum, @Name, GETDATE(), @AssessNum, @RevenueID, @DrCr, @ItemID, @Quantity, @RefNum, @Amount, @RevenueID, @UserID, @HospNum, @DepartmentID, @DoctorID, @DoctorName) GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AssessmentEntryHospNum] @Type AS varChar(1), @Name AS varChar(60), @Transdate AS DateTime, @RevenueID as varchar(2), @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @RefNum AS varChar(10), @HospNum as varchar(8), @IDNum as varchar(10) AS DECLARE @AssessmentNum AS varChar(10), @DrCr AS varChar(1), @AssessNum AS varChar(10), @DepartmentID as varchar(2) IF @RevenueID = 'MD' BEGIN SET @DrCr = 'P' END ELSE BEGIN SET @DrCr = 'D' END if @Type = '1' begin set @DepartmentID = 'CT' end if @Type = '2' begin set @DepartmentID = 'XR' end if @Type = '3' begin set @DepartmentID = 'US' end /* Assessment Number */ SELECT @AssessmentNum = RTRIM(Convert(varChar(10), RequestNum)) FROM BILLING..tbAssessmentNum UPDATE BILLING..tbAssessmentNum SET RequestNum = RequestNum + 1 SET @AssessNum = 'AS' + RTRIM(@AssessmentNum) INSERT INTO BILLING..tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, RefNum, Amount, RevenueID, UserID, HospNum, DepartmentID) VALUES (@IDNum, @Name, GETDATE(), @AssessNum, @RevenueID, @DrCr, @ItemID, @Quantity, @RefNum, @Amount, @RevenueID, @UserID, @HospNum, @DepartmentID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_Scheduler Script Date: 07/01/2000 1:19:32 AM ******/ CREATE PROCEDURE [dbo].[spRadio_Scheduler] @Type AS varChar(1) AS GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AssessmentStatus] @RevenueID varchar(2) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'XR' then x.XRayExam when 'CT' then c.CTExam when 'US' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where a.revenueid = @RevenueID or a.DepartmentID = @RevenueID order by [Patient Name], a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO --updated by Jetty P. Omo --september 9,2008 --reconstructed the query because result is not the same with income report --updated by alejandro 03/22/2007 --for the displaying of Woman Center Audit Report CREATE PROCEDURE [dbo].[spRadio_AuditReport] @RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS DECLARE @StartDate datetime, @EndDate datetime --SET @StartDate = CONVERT(datetime, @FirstDay, 101) ---SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) Select b.refnum, b.amount, Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End as Quantity , b.itemid, Case @RevenueID when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'WC' then o.otherrevenue End as exam, b.userid, Convert(varchar(10), b.transdate, 101) transdate, b.idnum, p.hospnum, m.lastname + ', ' + m.firstname patient From billing..tbbilldailybill b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join build_file..tbcootherrevenue o on b.itemid = o.otherrevenueid Where b.transdate between @FirstDay and @LastDay + ' 23:59:59.99' and b.revenueid = @RevenueID union all Select b.refnum, b.amount, Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End as Quantity, b.itemid, Case @RevenueID when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'WC' then o.otherrevenue End as exam, b.userid, Convert(varchar(10), b.transdate, 101) transdate, b.idnum, p.hospnum, Case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom End as patient From billing..tbbillopdailyout b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum left join build_file..tbcootherrevenue o on b.itemid = o.otherrevenueid Where b.transdate between @FirstDay and @LastDay + ' 23:59:59.99' and b.revenueid = @RevenueID Order by patient GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Radio_ReportDoctorsContributionINOut] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2), @Option as integer AS /*Declare @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) Set @StartDate = '08/01/2003'; Set @EndDate = '08/31/2003'; set @RevenueID = 'XR' */ IF @Option = 1 Begin Select max(RequestDocID) DoctorID, Case When isnull(max(RequestDocID),'0') = '0' or isnull(max(RequestDocID),'0') = '' Then isnull(max(A.DoctorName),'') Else Cardio.dbo.fn_GetDoctorsName(max(RequestDocID)) End as DoctorName, max(C.[Description]) as [Procedure], Cardio.dbo.fn_GetPatientName(max(B.Hospnum)) PatientName, isnull(Case When @RevenueID = 'XR' Then max(XrayNum) When @RevenueID = 'US' Then max(UltraNum) When @RevenueID = 'CT' Then max(CTNum) End,'') as [Control #], max(Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate)) Age, max(D.Sex) as Sex, max(B.RoomID) as RoomID, max(A.TransDate) as TransDate, sum(A.Amount) as Amount From Billing..tbBilldailybill A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemId, A.IdNum End; Else Begin Select max(RequestDocID) DoctorID, Case When isnull(max(RequestDocID),'0') = '0' or isnull(max(RequestDocID),'0') = '' Then max(A.DoctorName) Else Cardio.dbo.fn_GetDoctorsName(max(RequestDocID)) End as DoctorName, max(C.[Description]) as [Procedure], Case When Left(A.Refnum,2) = 'OR' Then isnull(max(F.PaymentFrom),'') Else Cardio.dbo.fn_GetPatientName(max(B.Hospnum)) End PatientName, isnull(Case When @RevenueID = 'XR' Then max(D.XrayNum) When @RevenueID = 'US' Then max(D.UltraNum) When @RevenueID = 'CT' Then max(D.CTNum) End,'') as [Control #], max(Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate)) Age, (Case When Left( ltrim(max(A.HospNum)), 1) = 'T' Then max(E.Sex) Else max(D.Sex) End) as Sex, Case When len(isnull(max(B.ERnum),'')) > 0 then 'ER' Else 'OPD' End RoomID, max(A.TransDate) as Transdate, sum(A.Amount) as Amount From Billing..tbBillOpDailyOut A Left Outer Join Patient_Data..tbOutPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Left Outer Join Patient_Data..tbCashPatient E On A.HospNum = E.HospNum Left Outer Join Billing..tbCashORMaster F On A.Refnum = F.RefNum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemId, A.IdNum Order by [Procedure] End; /* IF @Option = 1 Begin Select Distinct RequestDocID DoctorID, Case When isnull(RequestDocID,'0') = '0' or isnull(RequestDocID,'0') = '' Then isnull(A.DoctorName,'') Else Cardio.dbo.fn_GetDoctorsName(RequestDocID) End as DoctorName, C.[Description] as [Procedure], Cardio.dbo.fn_GetPatientName(B.Hospnum) PatientName, isnull(Case When @RevenueID = 'XR' Then XrayNum When @RevenueID = 'US' Then UltraNum When @RevenueID = 'CT' Then CTNum End,'') as [Control #], Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate) Age, D.Sex, B.RoomID, A.TransDate, A.Amount From Billing..tbBilldailybill A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID End; Else Begin Select Distinct RequestDocID DoctorID, Case When isnull(RequestDocID,'0') = '0' or isnull(RequestDocID,'0') = '' Then A.DoctorName Else Cardio.dbo.fn_GetDoctorsName(RequestDocID) End as DoctorName, C.[Description] as [Procedure], Case When Left(A.Refnum,2) = 'OR' Then isnull(F.PaymentFrom,'') Else Cardio.dbo.fn_GetPatientName(B.Hospnum) End PatientName, isnull(Case When @RevenueID = 'XR' Then D.XrayNum When @RevenueID = 'US' Then D.UltraNum When @RevenueID = 'CT' Then D.CTNum End,'') as [Control #], Cardio.dbo.fn_GetPatientAge(A.TransDate, D.BirthDate) Age, (Case When Left( ltrim(A.HospNum), 1) = 'T' Then E.Sex Else D.Sex End) as Sex, Case When len(isnull(B.ERnum,'')) > 0 then 'ER' Else 'OPD' End RoomID, A.TransDate, A.Amount From Billing..tbBillOpDailyOut A Left Outer Join Patient_Data..tbOutPatient B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On A.ItemID = C.ItemID and A.RevenueID = C.RevenueID Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.Hospnum Left Outer Join Patient_Data..tbCashPatient E On A.HospNum = E.HospNum Left Outer Join Billing..tbCashORMaster F On A.Refnum = F.RefNum Where A.Transdate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID End;*/ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO -- encrypted CREATE PROCEDURE [dbo].[spRadio_SearchEmployee] @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin select LastName + ', ' + FirstName + ' ' + MiddleName [Employee], EmployeeID [Code] from PASSWORD..tbPasswordMaster where LastName + ', ' + FirstName + ' ' + MiddleName like @SearchCriteria + '%' Order by [Employee] end if @SearchType = '1' begin select * from PASSWORD..tbPasswordMaster where EmployeeID = @SearchCriteria end if @SearchType = '2' begin select Count(*) [RecCount] from PASSWORD..tbPasswordMaster where LastName + ', ' + FirstName + ' ' + MiddleName like @SearchCriteria + '%' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchSonologists] @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin select r.LastName + ', ' + r.FirstName + ' ' + r.MiddleName [Description], r.DoctorID [Code] from BUILD_FILE..tbCoDoctor r where isnull(r.Sonologist, '') = 'Y' and r.LastName like @SearchCriteria + '%' and r.Status = 'A' order by Description end if @SearchType = '1' begin select r.* from BUILD_FILE..tbCoDoctor r where /*isnull(r.Radiologist, '') = 'Y' and*/ r.Status = 'A' and r.DoctorID = @SearchCriteria end if @SearchType = '2' begin select Count(*) [RecCount] from BUILD_FILE..tbCoDoctor r where /*isnull(r.Radiologist, '') = 'Y' and */r.Status = 'A' and r.LastName like @SearchCriteria + '%' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_BorrowedFilm] @RevenueID varchar(2), @SortType varchar(1) AS declare @cSQL varchar(1000) --declare @cSQL2 varchar(2000) if @RevenueID = 'XR' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.XrayExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbxrborrowedfilm b ' + ' left join tbxrrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoXRayExam e ' + ' on r.code = e.xrayexamid ' + ' left join tbxrresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 0 ' /* set @cSQL2 = 'select b.requestnum, r.hospnum,'+ ' case when m.hospnum is null'+ ' then "" '+ ' else m.lastname + ", " + m.firstname + " " + m.middlename '+ ' end [patient], '+ ' r.code [examid], e.XrayExam [exam], '+ ' s.resultdate, '+ ' b.borrowedby, b.borroweddate, '+ ' b.location, b.isreturned,'+ ' b.borrowedbyId, b.returnedbyID, '+ ' case isnull(b.BorrowedByID,'') '+ ' when '' then b.BorrowedBy '+ ' else dA.LastName '+ ' end as [ReturnedBy], '+ ' case isnull(b.returnedbyID,'') '+ ' when '' then b.returnedby '+ ' else dB.LastName '+ ' end as [ReturnedBy], '+ ' b.borroweddate, b.returneddate, '+ ' b.borrowuserid, b.returnuserid '+ 'from tbxrborrowedfilm b '+ ' left join tbxrrequest r '+ ' on b.requestnum = r.requestnum '+ ' left join vwpatientmaster m '+ ' on r.hospnum = m.hospnum '+ ' left join BUILD_FILE..tbCoXRayExam e '+ ' on r.code = e.xrayexamid '+ ' left join tbxrresult s '+ ' on r.requestnum = s.requestnum '+ ' left join BUILD_FILE..tbCoDoctor dA '+ ' on dA.DoctorID = BorrowedByID '+ ' left join BUILD_FILE..tbCoDoctor dB '+ ' on dB.DoctorID = ReturnedByID '+ 'where isreturned = 0 '*/ end if @RevenueID = 'CT' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.CTExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbctborrowedfilm b ' + ' left join tbctrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoCTExam e ' + ' on r.code = e.CTExamid ' + ' left join tbctresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 0 ' end if @RevenueID = 'US' begin set @cSQL = 'select b.requestnum, r.hospnum, ' + ' case when m.hospnum is null ' + ' then "" ' + ' else m.lastname + ", " + m.firstname + " " + m.middlename ' + ' end [patient], ' + ' r.code [examid], e.UltraExam [exam], ' + ' s.resultdate, ' + ' b.borrowedby, b.borroweddate, ' + ' b.location, b.isreturned, ' + ' b.returnedby, b.returneddate, ' + ' b.borrowuserid, b.returnuserid ' + 'from tbulborrowedfilm b ' + ' left join tbulrequest r ' + ' on b.requestnum = r.requestnum ' + ' left join vwpatientmaster m ' + ' on r.hospnum = m.hospnum ' + ' left join BUILD_FILE..tbCoUltraExam e ' + ' on r.code = e.ultraexamid ' + ' left join tbulresult s ' + ' on r.requestnum = s.requestnum ' + 'where isreturned = 0 ' end if @SortType = 'A' begin set @cSQL = @cSQL + ' order by Patient' end if @SortType = 'B' begin set @cSQL = @cSQL + ' order by Exam' end if @SortType = 'C' begin set @cSQL = @cSQL + ' order by ResultDate' end if @SortType = 'D' begin set @cSQL = @cSQL + ' order by BorrowedBy' end if @SortType = 'E' begin set @cSQL = @cSQL + ' order by BorrowedDate' end if @SortType = 'F' begin set @cSQL = @cSQL + ' order by b.Location' end if @SortType = 'G' begin set @cSQL = @cSQL + ' order by BorrowUserID' end exec (@cSQL) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchRadiologists] @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin select isnull(r.LastName,'') + ', ' + isnull(r.FirstName,'') + ' ' + isnull(r.MiddleName,'') [Description], r.DoctorID [Code] from BUILD_FILE..tbCoDoctor r where isnull(r.Radiologist, '') = 'Y' and r.LastName like @SearchCriteria + '%' and r.Status = 'A' order by Description end if @SearchType = '1' begin select r.* from BUILD_FILE..tbCoDoctor r where isnull(r.Radiologist, '') = 'Y' and r.Status = 'A' and r.DoctorID like @SearchCriteria + '%' end if @SearchType = '2' begin select Count(*) [RecCount] from BUILD_FILE..tbCoDoctor r where isnull(r.Radiologist, '') = 'Y' and r.Status = 'A' and r.LastName like @SearchCriteria + '%' end if @SearchType = '9989'--previous 3 begin select isnull(r.LastName,'') + ', ' + isnull(r.FirstName,'') + ' ' + isnull(r.MiddleName,'') [Description], r.DoctorID [Code] from BUILD_FILE..tbCoDoctor r --left outer join PASSWORD..tbPasswordMain where isnull(r.Radiologist, '') = 'Y' and r.Status = 'A' and r.DoctorID like @SearchCriteria + '%' end if @SearchType = '3' begin --declare @SearchCriteria varchar(12) --set @SearchCriteria = 'c' select distinct isnull(build.LastName,'') + ', ' + isnull(build.FirstName,'') + ' ' + isnull(build.MiddleName,'') [Description], main.employeeid [Code] from BUILD_FILE..tbcodoctor build left outer join password..tbpasswordmain main on main.doctorid = build.doctorid where main.employeeid like @SearchCriteria + '%' and build.radiologist like 'Y' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_StatisticalReportPerPhysician] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Declare @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) set @StartDate = '08/01/2003'; set @EndDate = '08/01/2003'; set @RevenueID = 'XR'*/ Select max(Y.[Procedure]) [Procedure], sum(Case When Y.PatientType = 'IN' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYIN, sum(Case When Y.PatientType = 'OUT' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYOUT, sum(Case When Y.PatientType = 'IN' Then Y.Amount Else 0 End) AmountIN, sum(Case When Y.PatientType = 'OUT' Then Y.Amount Else 0 End) AmountOUT, sum(Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * -1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End) TotalQTY, Sum(Y.Amount) TotalAmount, max(ltrim(Y.Physician)) Physician From (Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else 'OUT' End PatientType, sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician] From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum Union All Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else (Case When max(A.CashType) = 'I' Then 'IN' Else 'OUT' End) End PatientType, sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician] From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum ) Y Group By Y.Physician, Y.[Procedure] Having Sum(Y.Amount) > 0 /* Select max(Y.[Procedure]) [Procedure], sum(Case When Y.PatientType = 'IN' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYIN, sum(Case When Y.PatientType = 'OUT' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYOUT, sum(Case When Y.PatientType = 'IN' Then Y.Amount Else 0 End) AmountIN, sum(Case When Y.PatientType = 'OUT' Then Y.Amount Else 0 End) AmountOUT, sum(Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * -1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End) TotalQTY, Sum(Y.Amount) TotalAmount, max(ltrim(Y.Physician)) Physician From (Select Description [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else 'OUT' End PatientType, Case When A.Quantity = 0 Then 1 Else A.Quantity End as Quantity, Amount, Patient_Data.dbo.fn_GetDrName(A.RequestDocID) [Physician] From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Union All Select Description [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else (Case When A.CashType = 'I' Then 'IN' Else 'OUT' End) End PatientType, Case When A.Quantity = 0 Then 1 Else A.Quantity End as Quantity, Amount, Patient_Data.dbo.fn_GetDrName(A.RequestDocID) [Physician] From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID ) Y Group By Y.Physician, Y.[Procedure] Having Sum(Y.Amount) > 0*/ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ChargesbyPatient] @RevenueID varchar(2), @IDNum varchar(10) AS IF @RevenueID = 'WC' begin select b.refnum, b.transdate, b.itemid, case b.revenueid when 'WC' then U.Description-- OBUL when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where B.Refnum like 'C%W' and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'WC' then U.Description --OB when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where B.Refnum like 'C%W' and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(OBActive,'') = 'Y') order by b.refnum, b.transdate end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CancelList] @Type AS varChar(1), @Names AS varChar(30) AS IF @Type = '1' /* CT-Scan */ BEGIN SELECT tbCTRequest.IdNum AS AdmNo, tbCTRequest.RefNum as CSLip, tbCTRequest.LastName AS Lastname, tbCTRequest.FirstName AS Firstname, tbCTRequest.MiddleName AS Middlename, tbCTRequest.Code AS Code, tbCTRequest.TypeDescription AS Description, tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.TransDate AS TransDate, '' AS Film8, '' AS Film10, '' AS Film11, '' AS Film14, '' AS Film17, tbCTRequest.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, (SELECT CASE tbCTRequest.RoomID WHEN 'OPD' THEN tbOutPatient.AdmDate ELSE tbPatient.AdmDate END) AS AdmDate FROM tbCTRequest LEFT OUTER JOIN tbPatient ON tbCTRequest.HospNum = tbPatient.HospNum LEFT OUTER JOIN tbOutPatient ON tbCTRequest.HospNum = tbOutPatient.HospNum LEFT OUTER JOIN tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum WHERE tbCTRequest.Lastname LIKE @Names +'%' AND tbCTRequest.SwFin IS NULL ORDER BY tbCTRequest.LastName, tbCTRequest.FirstName, tbCTRequest.MiddleName END IF @Type = '2' /* XRay */ BEGIN SELECT tbXRRequest.IdNum AS AdmNo, tbXRRequest.Refnum as CSLip, tbXRRequest.LastName AS Lastname, tbXRRequest.FirstName AS Firstname, tbXRRequest.MiddleName AS Middlename, tbXRRequest.Code AS Code, tbXRRequest.TypeDescription AS Description, tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.TransDate AS TransDate, tbXRRequest.Film8 AS Film8, tbXRRequest.Film10 AS Film10, tbXRRequest.Film11 AS Film11, tbXRRequest.Film14 AS Film14, tbXRRequest.Film17 AS Film17, tbXRRequest.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, (SELECT CASE tbXRRequest.RoomID WHEN 'OPD' THEN tbOutPatient.AdmDate ELSE tbPatient.AdmDate END) AS AdmDate FROM tbXRRequest LEFT OUTER JOIN tbPatient ON tbXRRequest.HospNum = tbPatient.HospNum LEFT OUTER JOIN tbOutPatient ON tbXRRequest.HospNum = tbOutPatient.HospNum LEFT OUTER JOIN tbCoDoctor ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbXRRequest.HospNum = tbMaster.HospNum WHERE tbXRRequest.Lastname LIKE @Names +'%' AND tbXRRequest.SwFin IS NULL ORDER BY tbXRRequest.LastName, tbXRRequest.FirstName, tbXRRequest.MiddleName END IF @Type = '3' /* Ultrasound */ BEGIN SELECT tbULRequest.IdNum AS AdmNo, tbULRequest.Refnum as CSlip, tbULRequest.LastName AS Lastname, tbULRequest.FirstName AS Firstname, tbULRequest.MiddleName AS Middlename, tbULRequest.Code AS Code, tbULRequest.TypeDescription AS Description, tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbULRequest.TransDate AS TransDate, '' AS Film8, '' AS Film10, '' AS Film11, '' AS Film14, '' AS Film17, tbULRequest.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, (SELECT CASE tbULRequest.RoomID WHEN 'OPD' THEN tbOutPatient.AdmDate ELSE tbPatient.AdmDate END) AS AdmDate FROM tbULRequest LEFT OUTER JOIN tbPatient ON tbULRequest.HospNum = tbPatient.HospNum LEFT OUTER JOIN tbOutPatient ON tbULRequest.HospNum = tbOutPatient.HospNum LEFT OUTER JOIN tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbULRequest.HospNum = tbMaster.HospNum WHERE tbULRequest.Lastname LIKE @Names +'%' AND tbULRequest.SwFin IS NULL ORDER BY tbULRequest.LastName, tbULRequest.FirstName, tbULRequest.MiddleName END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_AssessmentStatus] AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'MM' then r.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status from BILLING..tbcashassessment a left join BUILD_FILE..tbCoOtherRevenue r on a.ItemID = r.OtherRevenueID and r.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on a.ItemID = d.DoctorID where ISNULL(a.revenueid, '') = 'MM' or ISNULL(a.DepartmentID, '') = 'MM' order by a.TransDate GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO -- Created by : FRIGILLANA, Rodney J. -- Date Updated : 13 August 2002 CREATE PROCEDURE [dbo].[spRadio_SearchResidentDoctor] @SearchType AS varchar(1), @SearchCriteria AS varchar(50) AS if @SearchType = '0' begin SELECT r.LastName + ', ' + r.FirstName + ' ' + r.MiddleName [Description], r.DoctorID [Code] FROM BUILD_FILE..tbCoDoctor r WHERE ISNULL(r.XrayResident, '') = 'Y' AND r.LastName like @SearchCriteria + '%' AND r.Status = 'A' ORDER BY Description end if @SearchType = '1' begin SELECT r.* FROM BUILD_FILE..tbCoDoctor r WHERE r.Status = 'A' AND r.DoctorID = @SearchCriteria end if @SearchType = '2' begin SELECT Count(*) [RecCount] FROM BUILD_FILE..tbCoDoctor r WHERE r.Status = 'A' AND r.LastName like @SearchCriteria + '%' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_AuditReport] @StartDate as varchar(10), @EndDate as varchar(10) AS DECLARE @StartTime as datetime DECLARE @EndTime as datetime SET @StartTime = CAST(@StartDate as datetime) SET @EndTime = CAST(@EndDate + ' 23:59:59' as datetime) select b.transdate, b.refnum, b.idnum, p.hospnum, m.lastname + ', ' + m.firstname [patient], b.revenueid, b.itemid, case b.RevenueID when 'MM' then r.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName, 1) + '. ' + d.LastName end as Description, case when isnull(b.quantity, 0) = 0 then case when b.amount > 0 then 1 when b.amount = 0 then 0 when b.amount < 0 then -1 end else b.quantity end as quantity, b.amount, b.userid from BILLING..tbbilldailybill b left join PATIENT_DATA..tbpatient p on b.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on b.ItemID = d.DoctorID where (b.transdate between @StartTime and @EndTime) and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') union all select b.transdate, b.refnum, b.idnum, p.hospnum, case when b.idnum = 'CASH' then z.paymentfrom else m.lastname + ', ' + m.firstname end as Patient, b.revenueid, b.itemid, case b.RevenueID when 'MM' then r.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName, 1) + '. ' + d.LastName end as Description, case when isnull(b.quantity, 0) = 0 then case when b.amount > 0 then 1 when b.amount = 0 then 0 when b.amount < 0 then -1 end else b.quantity end as quantity, b.amount, b.userid from BILLING..tbbillopdailyout b left join PATIENT_DATA..tbOutPatient p on b.idnum = p.idnum left join BILLING..tbcashormaster z on b.RefNum = z.RefNum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on b.ItemID = d.DoctorID where (b.transdate between @StartTime and @EndTime) and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_CashList Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_CashList] @Type AS varChar(1), @PaymentFrom as varchar(20) /*set @Type ='4' set @PaymentFrom = ''*/ AS IF @Type = '1' /* CT-Scan */ SELECT Cash.RefNum, Cash.PaymentFrom as Name, Cash.ItemID, CTExam.CTExam [Description], Cash.Amount FROM BILLING..tbCashCommunication Cash LEFT OUTER JOIN BUILD_FILE..tbCoCTExam CTExam ON CTExam.CTExamID = Cash.ItemID WHERE (Cash.RevenueID = 'CT' OR Cash.DepartmentID = 'CT' )AND ISNULL(Cash.RecordStatus, '') = '' and Cash.PaymentFrom like @PaymentFrom + '%' ORDER BY Cash.Name IF @Type = '2' /* XRay */ SELECT Cash.RefNum, Cash.PaymentFrom as Name, Cash.ItemID, XrayExam.XRayExam [Description], Cash.Amount FROM BILLING..tbCashCommunication Cash LEFT OUTER JOIN BUILD_FILE..tbCoXrayExam XrayExam ON XrayExam.XrayExamID = Cash.ItemID WHERE (Cash.RevenueID = 'XR' OR Cash.DepartmentID = 'XR' ) AND ISNULL(Cash.RecordStatus, '') = '' and Cash.PaymentFrom like @PaymentFrom + '%' ORDER BY Cash.Name IF @Type = '3' /* Ultrasound */ SELECT Cash.RefNum, Cash.Name as Name, Cash.ItemID, case when Cash.RevenueID = 'US' then UltraExam.UltraExam else A.OtherRevenue end [Description], Cash.Amount FROM BILLING..tbCashassessment Cash LEFT OUTER JOIN BUILD_FILE..tbCoUltraExam UltraExam ON UltraExam.UltraExamID = Cash.ItemID Left Outer Join Build_File..tbcoOtherRevenue A On Cash.ItemID = A.OtherRevenueID WHERE (Cash.RevenueID = 'US' OR Cash.DepartmentID = 'US' ) AND (iSNULL(Cash.RecordStatus, '') = '' or Cash.RecordStatus = '1') and Cash.Name like @PaymentFrom + '%' ORDER BY Name IF @Type = '4' /* MRI */ SELECT Cash.RefNum, Cash.PaymentFrom as Name, Cash.ItemID, MRIExam.oTHERrEVENUE [Description], Cash.Amount ,Cash.hospnum, Cash.RecordStatus FROM BILLING..tbCashCommunication Cash LEFT OUTER JOIN BUILD_FILE..tbCoOtherRevenue MRIExam ON MRIExam.OtherRevenueID = Cash.ItemID WHERE (Cash.RevenueID = 'MI' AND Cash.DepartmentID = 'MI' ) AND (ISNULL(Cash.RecordStatus, '') not in ('R','X')) and Cash.PaymentFrom like @PaymentFrom + '%' ORDER BY Cash.Name GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchRevenueCodes] @DeptCode varchar(2), @SearchType varchar(1), @SearchCriteria varchar(50) AS /*set @DeptCode ='WC' set @SearchType = '2' set @SearchCriteria ='' */ if @SearchType = '0' begin select r.ItemName [Description], r.RevenueID [Code] from BUILD_FILE..tbCoRevenueCode r where ( (@DeptCode = 'XR' and r.XRActive = 'Y') or (@DeptCode = 'US' and r.USActive = 'Y') or (@DeptCode = 'CT' and r.CTActive = 'Y') or (@DeptCode = 'MI' and r.MRIActive = 'Y') or (@DeptCode = 'WC' and r.OBActive = 'Y') ) and r.ItemName like @SearchCriteria + '%' and r.RecordStatus = 'A' order by r.ItemName end if @SearchType = '1' begin select r.ItemName [Revenue], r.RevenueID, r.RWith [WithItems], r.DrCr [AccountCode], r.LGRP [GroupCode], r.SearchInventory, r.LocationID, r.CashCommunication, b.RevenueID [InvCode] from BUILD_FILE..tbCoRevenueCode r left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID where ( (@DeptCode = 'XR' and r.XRActive = 'Y') or (@DeptCode = 'US' and r.USActive = 'Y') or (@DeptCode = 'CT' and r.CTActive = 'Y') or (@DeptCode = 'MI' and r.MRIActive = 'Y') OR(@DeptCode = 'WC' and r.OBActive = 'Y') ) and r.RecordStatus = 'A' and r.RevenueID = @SearchCriteria end if @SearchType = '2' begin select Count(*) [RecCount] from BUILD_FILE..tbCoRevenueCode r where ( (@DeptCode = 'XR' and r.XRActive = 'Y') or (@DeptCode = 'US' and r.USActive = 'Y') or (@DeptCode = 'CT' and r.CTActive = 'Y') or (@DeptCode = 'MI' and r.MRIActive = 'Y') OR (@DeptCode = 'WC' and r.OBActive = 'Y') ) and r.RecordStatus = 'A' and r.ItemName like @SearchCriteria + '%' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CashPatient] @Names AS varChar(30) AS SELECT CashPatient.Hospnum, CashPatient.HospNum [IDNum], CashPatient.Lastname, CashPatient.FirstName, CashPatient.Middlename, CashPatient.HouseStreet, CashPatient.Barangay, Address.Town + ', ' + Address.Province AS Town, case when CashPatient.BirthDate is null then '' when CashPatient.BirthDate <= '01/01/1900' then '' else convert(varchar(10), CashPatient.BirthDate, 101) end BirthDate, case when CashPatient.BirthDate is null then isnull(Cast(CashPatient.Age as varchar(3)), '') when CashPatient.BirthDate <= '01/01/1900' then isnull(Cast(CashPatient.Age as varchar(3)), '') else Cast(DateDiff(year, CashPatient.BirthDate, GetDate()) as varchar(3)) end Age, CashPatient.CivilStatusID, CashPatient.Sex FROM PATIENT_DATA..tbCashPatient CashPatient LEFT OUTER JOIN BUILD_FILE..tbCoAddress Address ON CashPatient.ZipCode = Address.ZipCode WHERE CashPatient.Lastname LIKE @Names +'%' ORDER BY CashPatient.LastName, CashPatient.FirstName, CashPatient.MiddleName GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_NurseRequestByIdNum] @IdNum varchar(8), @DepartmentID varchar(2) = ' ' /*set @Type = '3' set @IdNum = '166404' set @DepartmentID = 'wc'*/ AS /* Woman Center Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, tbOtherRevenue.OtherRevenue as Exam, Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, isnull(Nurse.DoctorName,'') DoctorName, Nurse.RequestNum From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID -- Left Outer Join Build_File..tbocOtherRevenue On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End ELSE Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, tbOtherRevenue.OtherRevenue as Exam, Cast(tbOtherRevenue.RateA as Money) as [Price], '1' as Quantity, Cast(tbOtherRevenue.RateA as Money) as [Amount], Nurse.Remarks, Nurse.DoctorID, isnull(Nurse.DoctorName,'') DoctorName, Nurse.RequestNum From Station..tbNurseCommunicationFile Nurse --Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchSection] @RevenueID varchar(2), @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin select SectionName [Section], SectionID [Code] from BUILD_FILE..tbCoSection where RevenueID = @RevenueID and SectionName like @SearchCriteria + '%' order by SectionName end if @SearchType = '1' begin select SectionID, SectionName from BUILD_FILE..tbCoSection where RevenueID = @RevenueID and SectionID = @SearchCriteria end if @SearchType = '2' begin select Count(*) [RecCount] from BUILD_FILE..tbCoSection where RevenueID = @RevenueID and SectionName like @SearchCriteria + '%' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CashUpdate] @strOrNum AS varchar(10), @strItemID AS varchar(4), @strRevenueID AS varchar(2) AS UPDATE billing..tbCashCommunication SET recordstatus='Y' WHERE RefNum=@strOrNum AND ItemID=@strItemID AND RevenueID=@strRevenueID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadiology_AssessmentStatus] @RevenueID varchar(2) AS declare @StartDate as varchar(10) set @StartDate = convert(varchar(10),getdate(),101) select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'XR' then x.XRayExam when 'CT' then c.CTExam when 'US' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else isnull(E.Description,'') end, a.RevenueID) as Description, case isnull(a.RecordStatus, '') when '' then 'Unpaid' when '1' then 'Paid' when 'R' then 'Cancelled' end as Remarks , case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, cast(a.Transdate as varchar) as [Trans. Date], a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount] from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID Left Outer Join Billing..tbBillExamListing E On A.ItemID = E.ItemID and A.RevenueID = E.RevenueID where (a.revenueid = @RevenueID or a.DepartmentID = @RevenueID) and a.transdate between @StartDate and getdate() order by [Patient Name], a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_ChargesbyPatient Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_ChargesbyPatient] @RevenueID varchar(2), @IDNum varchar(10) AS if @RevenueID = 'XR' BEGIN /*select b.refnum, b.transdate, b.itemid, case b.revenueid when 'XR' then e.xrayexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'XR' then e.xrayexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(XrActive,'') = 'Y') order by b.refnum, b.transdate */ select b.refnum, b.transdate, b.itemid, case b.revenueid when 'XR' then U.Description--u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%X' and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'XR' then U.Description --u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%X' and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(xrActive,'') = 'Y') order by b.refnum, b.transdate END; IF @RevenueID = 'CT' begin select b.refnum, b.transdate, b.itemid, case b.revenueid when 'CT' then c.ctexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'CT' then c.ctexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(CTActive,'') = 'Y') order by b.refnum, b.transdate end; IF @RevenueID = 'US' begin select b.refnum, b.transdate, b.itemid, case b.revenueid when 'US' then U.Description--u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%U' and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'US' then U.Description --u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%U' and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(USActive,'') = 'Y') order by b.refnum, b.transdate end; IF @RevenueID = 'MI' begin select b.refnum, b.transdate, b.itemid, case b.revenueid when 'MI' then U.Description--u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbilldailybill b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%W' and b.idnum = @IDNum union all select b.refnum, b.transdate, b.itemid, case b.revenueid when 'MI' then U.Description --u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname else U.Description end as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from billing..tbbillopdailyout b -- left join build_file..tbcoultraexam u -- on b.itemid = u.ultraexamid Left Outer Join Billing..tbBillExamListing U On B.ItemID = U.itemID and B.RevenueID = U.REvenueID left join build_file..tbcodoctor d on b.itemid = d.doctorid where --(b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) B.Refnum like 'C%W' and b.idnum = @IDNum UNION ALL select b.refnum, b.transdate, b.itemid, e.itemname as description, b.quantity, b.amount, ISNULL(b.userid, '') USERID from INVENTORY..tbInvStockCard b left join INVENTORY..tbInvMaster e on b.itemid = e.ItemID where b.Idnum = @IDNum and b.locationid in (Select LocationID From BUILD_FILE..tbCoRevenueCode Where isnull(MRIActive,'') = 'Y') order by b.refnum, b.transdate end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ChargesbyPatient] @IDNum as varchar(10) AS if isnumeric(@IDNum) = 1 begin select b.refnum, CONVERT(varchar, b.transdate, 101) transdate, b.itemid, case b.revenueid when 'MM' then r.otherrevenue when 'MD' then d.firstname + ' ' + d.lastname end description, b.quantity, b.amount, b.userid from BILLING..tbbilldailybill b left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoDoctor d on b.itemid = d.doctorid where b.refnum in ( select refnum from BILLING..tbbilldailybill where idnum = @IDNum and (revenueid = 'MM' OR SUMMARYCODE = 'MM') group by refnum having sum(amount) <> 0 ) and (b.revenueid = 'MM' OR b.SUMMARYCODE = 'MM') end if isnumeric(@IDNum) = 0 begin select b.refnum, CONVERT(varchar, b.transdate, 101), b.itemid, case b.revenueid when 'MM' then r.otherrevenue when 'MD' then d.firstname + ' ' + d.lastname end description, b.quantity, b.amount, b.userid from BILLING..tbbillopdailyout b left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoDoctor d on b.itemid = d.doctorid where b.refnum in ( select refnum from BILLING..tbbillopdailyout where idnum = @IDNum and (revenueid = 'MM' OR SUMMARYCODE = 'MM') group by refnum having sum(amount) <> 0 ) and (b.revenueid = 'MM' OR b.SUMMARYCODE = 'M') end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_ChargesbySlip Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_ChargesbySlip] @ChargeSlip varchar(10), @UserID varchar(10), @RevenueID varchar(2) = '' AS delete REPORTS..tbChargeSlip where UserID = @UserID; insert into REPORTS..tbChargeSlip (Code, Description, Price, Quantity, Amount, UserID) select b.itemid, case b.revenueid when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end as description, case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end as price, b.quantity, b.amount, @UserID from billing..tbbilldailybill b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and (B.Transdate between '09/02/2003' and getdate()) and B.RevenueID like @RevenueID + '%' union all select b.itemid, case b.revenueid when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end as description, case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end as price, b.quantity, b.amount, @UserID from billing..tbbillopdailyout b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and (B.Transdate between '09/02/2003' and getdate()) and B.RevenueID like @RevenueID + '%' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_UpdateControlNum] @strDept varchar(2), @strControlNum varchar(8), @strHospNum varchar(8) AS if @strDept = 'CT' begin update tbMaster set CTNum = @strControlNum where HospNum = @strHospNum end if @strDept = 'XR' begin update tbMaster set XRayNum = @strControlNum where HospNum = @strHospNum end if @strDept = 'UL' begin update tbMaster set UltraNum = @strControlNum where HospNum = @strHospNum end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_ChargesbySlip Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_ChargesbySlip1] @ChargeSlip varchar(10), @Code varchar(10), --added by BSL @UserID varchar(10) AS delete REPORTS..tbChargeSlip where UserID = @UserID and Code = @Code; insert into REPORTS..tbChargeSlip (Code, Description, Price, Quantity, Amount, NetAmount, DiscountType, UserID) select b.itemid, max(case b.revenueid when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end) as description, sum(case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end) as price, sum(b.quantity), sum(b.amount), sum(b.amount) [NetAmount], '' [DiscountType], @UserID from billing..tbbilldailybill b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and b.ItemID = @Code group by b.ItemID having sum(b.Amount) <> 0 union all select b.itemid, max(case b.revenueid when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end) as description, sum(case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end) as price, sum(b.quantity), sum(b.amount), sum(b.NetAmount) [NetAmount], max(b.DiscountType) [DiscountType], @UserID from billing..tbbillopdailyout b left join build_file..tbcoxrayexam e on b.itemid = e.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and b.ItemID = @Code group by b.ItemID having sum(b.Amount) <> 0 union all select s.ItemID, max(m.ItemName + ' ' + m.ItemDesc), sum(case isnumeric(S.IdNum) when 1 then I.SellingPriceIn when 0 then I.SellingPriceOut end) as Price, sum(s.Quantity), sum(s.Amount+s.Discount) [Amount], sum(s.Amount) [NetAmount], '' [DiscountType], @UserID from inventory..tbInvStockCard s left join inventory..tbInvMaster m on s.ItemID = m.ItemID left join Inventory..tbInvent I on s.ItemID = I.ItemID and s.LocationID = I.LocationId where refnum = @ChargeSlip and s.ItemID = @Code group by s.ItemID having sum(s.Amount) <> 0 GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --alter Date: March 20, 2003 1:36PM CREATE PROCEDURE [dbo].[spRadio_CheckPatientClass] @IdNum as varchar(10) AS if isnumeric(@IdNum) = 1 begin SELECT left(isnull(PatientClass,'P'),1)[PatientClass] FROM PATIENT_DATA..tbPatient2 WHERE IdNum = @IdNum end; else begin SELECT left(isnull(PatientType,'P'),1) [PatientClass] FROM PATIENT_DATA..tbOutPatient WHERE IdNum = @IdNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_UpdateExam] @Type varchar(1), @ExamID varchar(5), @Exam varchar(30), @RateA float, @RateB float, @RateC float, @RateD float, @Status varchar(1) AS /* by FredC */ DECLARE @NewExamID varchar(5) IF @Type = '1' BEGIN IF @ExamID = 'NEW' BEGIN SELECT @NewExamID = MAX(CAST(CTExamID as int)) + 1 FROM build_file..tbCoCTExam INSERT INTO build_file..tbCoCTExam (CTExamID, CTExam, MedicareType, RateA, RateB, RateC, RateD, Status) VALUES (@NewExamID, @Exam, '3', @RateA, @RateB, @RateC, @RateD, @Status) END ELSE BEGIN UPDATE build_file..tbCoCTExam SET CTExam = @Exam, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, Status = @Status WHERE CTExamID = @ExamID END END IF @Type = '2' BEGIN IF @ExamID = 'NEW' BEGIN SELECT @NewExamID = MAX(CAST(XRayExamID as int)) + 1 FROM build_file..tbCoXRayExam INSERT INTO build_file..tbCoXRayExam (XRayExamID, XRayExam, MedicareType, RateA, RateB, RateC, RateD, Status) VALUES (@NewExamID, @Exam, '3', @RateA, @RateB, @RateC, @RateD, @Status) END ELSE BEGIN UPDATE build_file..tbCoXRayExam SET XRayExam = @Exam, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, Status = @Status WHERE XrayExamID = @ExamID END END IF @Type = '3' BEGIN IF @ExamID = 'NEW' BEGIN SELECT @NewExamID = MAX(CAST(UltraExamID as int)) + 1 FROM build_file..tbCoUltraExam INSERT INTO build_file..tbCoUltraExam (UltraExamID, UltraExam, MedicareType, RateA, RateB, RateC, RateD, Status) VALUES (@NewExamID, @Exam, '3', @RateA, @RateB, @RateC, @RateD, @Status) END ELSE BEGIN UPDATE build_file..tbCoUltraExam SET UltraExam = @Exam, RateA = @RateA, RateB = @RateB, RateC = @RateC, RateD = @RateD, Status = @Status WHERE UltraExamID = @ExamID END END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_Communication] @SearchType varchar(1), @SearchCriterion varchar(50) AS IF @SearchType = '0' BEGIN select c.refnum [OR #], c.paymentfrom [Patient], c.itemid [Code], case c.revenueid when 'MM' then isnull(r.OtherRevenue, 'MM ' + c.itemid) when 'MD' then isnull(d.LastName, '') + ', ' + isnull(d.firstname,'') end as [Exam], convert(varchar(10), c.transdate, 101) [Date] from BILLING..tbcashcommunication c left join BUILD_FILE..tbCoOtherRevenue r on c.itemid = r.OtherRevenueID and r.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on c.itemid = d.DoctorID where isnull(c.recordstatus, '') = '' and (c.revenueid = 'MM' or isnull(c.departmentid, '') = 'MM') and c.paymentfrom like @SearchCriterion + '%' order by c.paymentfrom END IF @SearchType = '1' BEGIN select c.refnum [OR #], c.paymentfrom [Patient], c.itemid [Code], case c.revenueid when 'MM' then isnull(r.OtherRevenue, 'MM ' + c.ItemID) when 'MD' then isnull(d.LastName, '') + ', ' + isnull(d.firstname,'') end as [Exam], convert(varchar(10), c.transdate, 101) [Date] from BILLING..tbcashcommunication c left join BUILD_FILE..tbCoOtherRevenue r on c.itemid = r.OtherRevenueID and r.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on c.itemid = d.DoctorID where isnull(c.recordstatus, '') = '' and (c.revenueid = 'MM' or isnull(c.departmentid, '') = 'MM') and c.refnum = @SearchCriterion order by c.paymentfrom END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CheckPending] @RevenueID varchar(2) AS if @RevenueID = 'US' Begin select count(*) as TotalPending from STATION..tbNurseCommunicationFile A inner join Billing..tbBillExamListing B ON (A.RevenueID = B.Revenueid) and (A.ItemID = B.ItemID) inner join ( select IdNum, BillingDate from Patient_Data..tbPatient P where P.BillingDate is NULL union all select IdNum, BillingDate from Patient_Data..tbOutPatient P where P.BillingDate is NULL) P on A.IdNum = P.IdNum where A.Revenueid in ('US', 'WC') and isnull(A.RecordStatus,'') = '' End; else Begin ------ modified by cynthia (to ensure that all requested items exist in build_file------- select count(*) as TotalPending from STATION..tbNurseCommunicationFile A inner join Billing..tbBillExamListing B ON (A.RevenueID = B.Revenueid) and (A.ItemID = B.ItemID) inner join ( select IdNum, BillingDate from Patient_Data..tbPatient P where P.BillingDate is NULL union all select IdNum, BillingDate from Patient_Data..tbOutPatient P where P.BillingDate is NULL) P on A.IdNum = P.IdNum where A.Revenueid = @RevenueID and isnull(A.RecordStatus,'') = '' End; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_InDailyRep Script Date: 07/01/2000 1:20:54 AM ******/ CREATE PROCEDURE [dbo].[spRadio_InOutDailyRep] @Date AS varChar(10), @UserID as varchar(10) AS Declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = cast(@Date as datetime) set @ReportDate2 = dateadd(day, 1, @ReportDate1) DELETE tbXRDailyRep WHERE UserID = @UserID; INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XRayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE isnumeric(tbXRRequest.IDNUm) = 1 --tbXRRequest.RoomId <> 'OPD' -- AND CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date AND (tbXRRequest.TransDate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') and Exists(Select top 1 * from Billing..tbBillDailyBill Where Refnum = tbXRRequest.Refnum); INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XrayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE --tbXRRequest.RoomId = 'OPD' AND /*CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date */ ISNUMERIC(tbXRRequest.IDNum) = 0 AND (tbXRRequest.Transdate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') and Exists(Select top 1 * from tbBillOpDailyOut Where Refnum = tbXRRequest.Refnum); GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_RevokedStatusNurse] @RevenueID as varchar(2), @ItemID as varchar(5), @Idnum as varchar(10) AS Update Station..tbnursecommunicationfile set RecordStatus = 'R' Where Revenueid = @RevenueID and ItemID = @ItemID and IDNum = @Idnum and RecordStatus = ''; Update Station..tbnurselogbook set RecordStatus = 'R' Where Revenueid = @RevenueID and ItemID = @ItemID and IDNum = @Idnum and RecordStatus = ''; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_MRI_ListAll_PACS_Result] @LastName As Varchar(15), @FirstName As Varchar(10), @ExamDate As Varchar(10) AS BEGIN Select B.StudyDescription,B.StudyDate, Isnull(RefDoc.LastName,'') + ', ' + Isnull(RefDoc.FirstName,'') As RefDoctor,A.RefDoctor_ID, Isnull(RadDoc.LastName,'') + ', ' + Isnull(RadDoc.FirstName,'') As RadDoctor,A.Radiologist_ID,A.Exam_Result, C.PatientID,A.StudyID,A.StudyUID From DICOM..tblExamResult A Inner Join StudyTable B On A.StudyID = B.StudyID Left Outer Join PatientTable C On B.PatientID_FKey = C.PatientID Left Outer Join Build_file..tbcoDoctor RefDoc On A.RefDoctor_ID = RefDoc.DoctorID Left Outer Join Build_file..tbcoDoctor RadDoc On A.Radiologist_ID = RadDoc.DoctorID Where A.Date_Created between @ExamDate and GETDATE() and C.Name_Last Like @LastName+'%' and C.Name_First like @FirstName+'%' and A.modality ='MR' Order By B.StudyDate; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Created by jetty P. Omo Davao Doctors retrieval of DOS Results 10/22/07 This strored procedure will get he results by using the fileno */ CREATE Procedure [dbo].[sp_get_DOS_Interpretation] @Fileno as varchar(20) as Select Interpretation from history..reading where fileno = @Fileno GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ClearPatientForDischarge] @IDNum varchar(10), @DepartmentID varchar(2), @UserID varchar(8), @Remarks text AS IF @DepartmentID = 'XR' BEGIN UPDATE STATION..tbNurseDischargeNotice SET XRClearDate = GETDATE(), XRUserID = @UserID, XRRemarks = @Remarks, --CTClearDate = GETDATE(), -- CTUserID = @UserID, --CTRemarks = @Remarks, --USClearDate = GETDATE(), --USUserID = @UserID, --USRemarks = @Remarks, MMClearDate = GETDATE(), MMUserID = @UserID, MMRemarks = @Remarks WHERE IDNum = @IDNum; /* UPDATE STATION..tbNurseDischargeNotice SET USClearDate = GETDATE(), USUserID = @UserID, USRemarks = @Remarks WHERE IDNum = @IDNum */ END IF @DepartmentID = 'US' BEGIN /* UPDATE STATION..tbNurseDischargeNotice SET XRClearDate = GETDATE(), XRUserID = @UserID, XRRemarks = @Remarks WHERE IDNum = @IDNum; */ UPDATE STATION..tbNurseDischargeNotice SET USClearDate = GETDATE(), USUserID = @UserID, USRemarks = @Remarks WHERE IDNum = @IDNum END IF @DepartmentID = 'CT' BEGIN UPDATE STATION..tbNurseDischargeNotice SET CTClearDate = GETDATE(), CTUserID = @UserID, CTRemarks = @Remarks WHERE IDNum = @IDNum END IF @DepartmentID = 'MM' BEGIN UPDATE STATION..tbNurseDischargeNotice SET MMClearDate = GETDATE(), MMUserID = @UserID, MMRemarks = @Remarks WHERE IDNum = @IDNum END IF @DepartmentID = 'EL' BEGIN UPDATE STATION..tbNurseDischargeNotice SET ELClearDate = GETDATE(), ELUserID = @UserID, ELRemarks = @Remarks WHERE IDNum = @IDNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_StatisticalReport] @BeginDate varchar(10), @EndDate varchar(10) AS declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = @BeginDate set @ReportDate2 = dateadd(day, 1, @EndDate) /* set @BeginDate ='07/01/2007' set @EndDate = '07/20/2007' */ Select max(type)Type,Code,max(Description) Description, sum(case type when '1' then quantity else 0 end)InQty, sum(case type when '1' then Amount else 0 end)InAmount, sum(Case type when '0' then isnull(quantity,0) else 0 end) OutQty, sum(case type when '0' then isnull(Amount,0) else 0 end)OutAmount from( SELECT '1' as Type, B.ItemID as Code, max(C.OtherRevenue) as [Description], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as Quantity, sum(B.Amount) as Amount FROM BILLING..tbBillDailyBill B Left Join Build_File..tbcoOtherRevenue C on B.ItemID = C.OtherRevenueid where B.RevenueId = 'WC' and B.Transdate between @BeginDate and @EndDate + ' 23:59:59.99' group by B.ItemID having sum(b.amount) > 0 union all SELECT '0' as Type, B.ItemID as Code, max(c.OtherRevenue) as [Description], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as Quantity, sum(b.amount) as Amount FROM BILLING..tbBillOPDailyOut B Left Join Build_File..tbcoOtherRevenue C on B.ItemID = C.OtherRevenueid where B.RevenueId = 'WC' and B.Transdate between @BeginDate and @EndDate + ' 23:59:59.99' group by B.ItemID having sum(b.amount) > 0 )A group by code GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ControlList] @Type AS varChar(1), @Hospnum AS varChar(8) AS IF @Type = '1' BEGIN SELECT tbCTResult.ControlNum, tbCTRequest.TypeDescription AS Examination, CONVERT(varChar(12), tbCTResult.ResultDate, 101) AS ResultDate, CONVERT(varChar(12), tbCTRequest.TransDate,101) AS TransDate, tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.LastName AS Lastname, tbCTRequest.FirstName AS Firstname, tbCTRequest.MiddleName AS Middlename, tbCTRequest.Code AS Code, tbCTRequest.IdNum AS IDNum, tbPatient.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbCTResult.Interpretation, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbCTResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.CTnum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbCTRequest LEFT OUTER JOIN tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCTResult ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbCTRequest.Hospnum = @Hospnum AND tbCTRequest.SwFin = 'Y' END IF @Type = '2' BEGIN SELECT tbXRResult.ControlNum, tbXRRequest.TypeDescription AS Examination, CONVERT(varChar(12), tbXRResult.ResultDate, 101) AS ResultDate, CONVERT(varChar(12), tbXRRequest.TransDate, 101) AS TransDate, tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.LastName AS Lastname, tbXRRequest.FirstName AS Firstname, tbXRRequest.MiddleName AS Middlename, tbXRRequest.Code AS Code, tbXRRequest.IdNum AS IDNum, tbXRRequest.Film8 AS [8X10], tbXRRequest.Film10 AS [10X12], tbXRRequest.Film11 AS [11X14], tbXRRequest.Film14 AS [14X14], tbXRRequest.Film17 AS [14X17], tbPatient.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbXRResult.Interpretation, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbXRResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.XRayNum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbXRRequest LEFT OUTER JOIN tbPatient ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbXRRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbXRResult ON tbXRRequest.RequestNum = tbXRResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbXRRequest.Hospnum = @Hospnum AND tbXRRequest.SwFin = 'Y' END IF @Type = '3' BEGIN SELECT tbULResult.ControlNum, tbULRequest.TypeDescription AS Examination, CONVERT(varChar(12), tbULResult.ResultDate, 101) AS ResultDate, CONVERT(varChar(12), tbULRequest.TransDate, 101) AS TransDate, tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbULRequest.LastName AS Lastname, tbULRequest.FirstName AS Firstname, tbULRequest.MiddleName AS Middlename, tbULRequest.Code AS Code, tbULRequest.IdNum AS IDNum, tbPatient.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbULResult.Interpretation, (SELECT DoctorID + ' - ' + Lastname + ', ' + Firstname FROM tbCoDoctor WHERE tbULResult.RadCode = tbCoDoctor.DoctorID) AS Radiologist, tbMaster.UltraNum AS FileNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbULRequest LEFT OUTER JOIN tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbULResult ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbULRequest.Hospnum = @Hospnum AND tbULRequest.SwFin = 'Y' END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchAccount] @IDNum varchar(10) AS If IsNumeric(@IDNum) = 1 Begin Select IsNull(A.AccountNum,'') as AccountNum, IsNull(B.Company,'') as Company --'' as Company From Patient_Data..tbPatient A Left Outer Join Build_File..tbCoCompany B On A.AccountNum = B.AccountNum Where A.IdNum = @IdNum End Else Begin Select IsNull(A.AccountNum,'') as AccountNum, IsNull(B.Company,'') as Company -- '' as Company From Patient_Data..tbOutPatient A Left Outer Join Build_File..tbCoCompany B On A.AccountNum = B.AccountNum Where A.IdNum = @IdNum End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spRadio__Mammo_StatisticalReport_perRoom] --declare @StartDate as Varchar(10), @EndDate as Varchar(10) --@RevenueID as varchar(2) --set @StartDate = '01/01/2008' --set @EndDate = '01/31/2008' as --if @RevenueID = 'MM' Begin --Xray SELECT E.otherrevenue as Exam, case when Class.Roomclass = 'Ward' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [WARD], case when Class.Roomclass = 'Private' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [PRIVATE], case when Class.Roomclass = 'SEMI-PRIVATE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [SEMI-PRIVATE], case when Class.Roomclass = 'EXECUTIVE SUITE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [EXECUTIVE SUITE], 0 as [OPD], 'MAMMO DEPARTMENT' as Dept FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN BUILD_FILE..tbCootherrevenue E on B.ItemID = E.otherrevenueID LEFT OUTER JOIN PATIENT_DATA..TBPATIENT InPx on InPx.idnum = B.idnum Left Outer Join build_file..tbcoroom Room On InPx.Roomid = Room.Roomid Left Outer Join build_file..tbcoroomclass Class On Room.roomclassid = Class.roomclassid WHERE (B.RevenueID = 'MM') --or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' AND B.AMOUNT <> 0 UNION ALL SELECT E.otherrevenue as Exam, 0 as [WARD], 0 as [PRIVATE], 0 as [SEMI-PRIVATE], 0 as [EXECUTIVE SUITE], case when ISNUMERIC(B.idnum) = 0 then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 END as [OPD], 'MAMMO DEPARTMENT' as Dept FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BUILD_FILE..tbCootherrevenue E on B.ItemID = E.otherrevenueID --LEFT OUTER JOIN radiology..tbxrrequest O --on B.refnum = o.refnum WHERE (B.RevenueID = 'MM') --or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and ISNUMERIC(B.idnum) = 0 --AND isnull(swfin, '') not in ('C','R') AND B.AMOUNT <> 0 order by Exam Asc end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ControlCash] @Type varchar(1), @HospNum varchar(8), @FileNum varchar(10) AS DECLARE @ControlNum float SELECT @ControlNum = ISNULL(ControlNum, 0) FROM tbCashPatient WHERE HospNum = @HospNum IF @Type = '1' BEGIN UPDATE PATIENT_DATA..tbCashPatient SET CTNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END IF @Type = '2' BEGIN UPDATE PATIENT_DATA..tbCashPatient SET XRayNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END IF @Type = '3' BEGIN UPDATE PATIENT_DATA..tbCashPatient SET UltraNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_VerifySlip] @RefNum varchar(10) AS select S.IDNUM [ADM. #], S.REVENUEID + S.ITEMID [CODE], CASE S.REVENUEID WHEN 'WC' THEN MR.OtherRevenue WHEN 'MD' THEN 'DR. ' + MD.LASTNAME + ', ' + MD.FIRSTNAME + ' ' + MD.MIDDLENAME ELSE R.ITEMNAME END DESCRIPTION, S.QUANTITY, convert(numeric(15, 2), S.AMOUNT) AMOUNT, S.USERID [ENCODER] FROM ( select idnum, transdate, revenueid, itemid, quantity, amount, userid from billing..tbbilldailybill where refnum = @RefNum union all select idnum, transdate, revenueid, Itemid, quantity, amount, userid from billing..tbbillopdailyout where refnum = @RefNum ) AS S LEFT OUTER JOIN BUILD_FILE..TBCOREVENUECODE R ON S.REVENUEID = R.REVENUEID LEFT OUTER JOIN BUILD_FILE..TBCOOtherRevenue MR ON S.ITEMID = MR.OtherRevenue LEFT OUTER JOIN BUILD_FILE..TBCODOCTOR MD ON S.ITEMID = MD.DOCTORID ORDER BY S.TRANSDATE GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_StatisticalReportPerSpecialty] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Declare @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) set @StartDate = '08/20/2003'; set @EndDate = '08/28/2003'; set @RevenueID = 'US' */ Select max(Case When Y.Physician = '' Then 'Code 0' Else Y.Physician End) Physician, max(Y.Specialization) Specialization, sum(Case When Y.PatientType = 'IN' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYIN, sum(Case When Y.PatientType = 'OUT' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYOUT, sum(Case When Y.PatientType = 'IN' Then Y.Amount Else 0 End) AmountIN, sum(Case When Y.PatientType = 'OUT' Then Y.Amount Else 0 End) AmountOUT, sum(Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * -1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End) TotalQTY, Sum(Y.Amount) TotalAmount From (Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else 'OUT' End PatientType, Sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, Sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician], Build_File.dbo.fn_GetDoctorsSpecialization(max(A.RequestDocID)) Specialization From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum Union All Select max(Description) [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else (Case When max(A.CashType) = 'I' Then 'IN' Else 'OUT' End) End PatientType, sum(Case When A.Quantity = 0 Then 1 Else A.Quantity End) as Quantity, Sum(Amount) as Amount, Patient_Data.dbo.fn_GetDrName(max(A.RequestDocID)) [Physician], Build_File.dbo.fn_GetDoctorsSpecialization(max(A.RequestDocID)) Specialization From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Group by A.RefNum, A.ItemID, A.IdNum ) Y Group By Y.Specialization, Y.Physician Having Sum(Y.Amount) > 0 /* Select max(Case When Y.Physician = '' Then 'Code 0' Else Y.Physician End) Physician, max(Y.Specialization) Specialization, sum(Case When Y.PatientType = 'IN' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYIN, sum(Case When Y.PatientType = 'OUT' Then Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * - 1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End Else 0 End) QTYOUT, sum(Case When Y.PatientType = 'IN' Then Y.Amount Else 0 End) AmountIN, sum(Case When Y.PatientType = 'OUT' Then Y.Amount Else 0 End) AmountOUT, sum(Case When Y.Amount < 0 Then abs(Case When Y.Quantity = 0 then 1 else Y.Quantity end) * -1 Else Case When Y.Quantity = 0 then 1 else Y.Quantity end End) TotalQTY, Sum(Y.Amount) TotalAmount From (Select Description [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else 'OUT' End PatientType, Case When A.Quantity = 0 Then 1 Else A.Quantity End as Quantity, Amount, Patient_Data.dbo.fn_GetDrName(A.RequestDocID) [Physician], Build_File.dbo.fn_GetDoctorsSpecialization(A.RequestDocID) Specialization From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Union All Select Description [Procedure], Patient_Data.dbo.funcGetFullName(A.Idnum) PatientName, Case When isnumeric(A.Idnum) = 1 Then 'IN' Else (Case When A.CashType = 'I' Then 'IN' Else 'OUT' End) End PatientType, Case When A.Quantity = 0 Then 1 Else A.Quantity End as Quantity, Amount, Patient_Data.dbo.fn_GetDrName(A.RequestDocID) [Physician], Build_File.dbo.fn_GetDoctorsSpecialization(A.RequestDocID) Specialization From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.RevenueID = B.RevenueID and A.ItemID = B.ItemID Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID ) Y Group By Y.Specialization, Y.Physician Having Sum(Y.Amount) > 0 */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ControlMaster] @Type varchar(1), @HospNum varchar(8), @FileNum varchar(10) AS DECLARE @ControlNum float SELECT @ControlNum = ISNULL(ControlNum, 0) FROM tbMaster WHERE HospNum = @HospNum IF @Type = '1' BEGIN UPDATE PATIENT_DATA..tbMaster SET CTNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END IF @Type = '2' BEGIN UPDATE PATIENT_DATA..tbMaster SET XRayNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END IF @Type = '3' BEGIN UPDATE PATIENT_DATA..tbMaster SET UltraNum = @FileNum, ControlNum = @ControlNum + 1 WHERE HospNum = @HospNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_AuditReportSummaryXray] @StartDate as varchar(10), @EndDate as varchar(10) AS --select * from build_file..tbcosection where revenueid = 'XR' /*set @StartDate = '01/15/2004'; set @EndDate = '01/18/2004'; */ Select sum([XrayCount InPatient]) as XrayIn, sum([XrayCount OutPatient]) as XrayOut, sum([XrayCount PrePaid]) as XrayPrepaid, sum([Mammo InPatient]) as MammoIn, sum([Mammo OutPatient]) as MammoOut, sum([Mammo PrePaid]) as MammoPrePaid, sum([PrePaid Local]) as PLocal, sum([PrePaid Taiwan]) as PTaiwan From (Select --WithOut miscellaneous (Diagnostic Xray) Case When Isnumeric(A.IDnum) = 1 and Not B.SectionID in ('I','Q') and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount InPatient], Case When Isnumeric(A.IDnum) = 0 and Not B.SectionID in ('I','Q') and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount OutPatient], Case When Not B.SectionID in ('I','Q') and A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount PrePaid], --WithOut miscellaneous (Mammography) Case When Isnumeric(A.IDnum) = 1 and B.SectionID = 'Q' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo InPatient], Case When Isnumeric(A.IDnum) = 0 and B.SectionID = 'Q' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo OutPatient], Case When B.SectionID = 'Q' and A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo PrePaid], --PrePaid Case When A.Refnum like 'C%I' and PrePaid.dbo.fn_isLocalOrTaiwan(A.Idnum) = 1 Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid Local], Case When A.Refnum like 'C%I' and PrePaid.dbo.fn_isLocalOrTaiwan(A.Idnum) = 0 Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid Taiwan] From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.ItemID = B.ItemID and B.RevenueID = 'XR' Left Outer Join Build_File..tbCoSection C On B.SectionID = C.SectionID and C.RevenueID = 'XR' Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = 'XR' Union All Select --WithOut miscellaneous (Diagnostic Xray) Case When Isnumeric(A.IDnum) = 1 and Not B.SectionID in ('I','Q') and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount InPatient], Case When Isnumeric(A.IDnum) = 0 and Not B.SectionID in ('I','Q') and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount OutPatient], Case When Not B.SectionID in ('I','Q') and A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [XrayCount PrePaid], --WithOut miscellaneous (Mammography) Case When Isnumeric(A.IDnum) = 1 and B.SectionID = 'Q' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo InPatient], Case When Isnumeric(A.IDnum) = 0 and B.SectionID = 'Q' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo OutPatient], Case When B.SectionID = 'Q' and A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [Mammo PrePaid], --PrePaid Case When A.Refnum like 'C%I' and PrePaid.dbo.fn_isLocalOrTaiwan(A.Idnum) = 1 Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid Local], Case When A.Refnum like 'C%I' and PrePaid.dbo.fn_isLocalOrTaiwan(A.Idnum) = 0 Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid Taiwan] From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.ItemID = B.ItemID and B.RevenueID = 'XR' Left Outer Join Build_File..tbCoSection C On B.SectionID = C.SectionID and C.RevenueID = 'XR' Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = 'XR' ) A GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_VerifySlip] @RefNum varchar(10) AS select S.IDNUM [ADM. #], S.REVENUEID + S.ITEMID [CODE], CASE S.REVENUEID WHEN 'XR' THEN XR.XRAYEXAM WHEN 'CT' THEN CT.CTEXAM WHEN 'US' THEN US.ULTRAEXAM WHEN 'MD' THEN 'DR. ' + MD.LASTNAME + ', ' + MD.FIRSTNAME + ' ' + MD.MIDDLENAME ELSE R.ITEMNAME END DESCRIPTION, S.QUANTITY, convert(numeric(15, 2), S.AMOUNT) AMOUNT, S.USERID [ENCODER] FROM ( select idnum, transdate, revenueid, itemid, quantity, amount, userid from billing..tbbilldailybill where refnum = @RefNum union all select idnum, transdate, revenueid, Itemid, quantity, amount, userid from billing..tbbillopdailyout where refnum = @RefNum ) AS S LEFT OUTER JOIN BUILD_FILE..TBCOREVENUECODE R ON S.REVENUEID = R.REVENUEID LEFT OUTER JOIN BUILD_FILE..TBCOXRAYEXAM XR ON S.ITEMID = XR.XRAYEXAMID LEFT OUTER JOIN BUILD_FILE..TBCOCTEXAM CT ON S.ITEMID = CT.CTEXAMID LEFT OUTER JOIN BUILD_FILE..TBCOULTRAEXAM US ON S.ITEMID = US.ULTRAEXAMID LEFT OUTER JOIN BUILD_FILE..TBCODOCTOR MD ON S.ITEMID = MD.DOCTORID ORDER BY S.TRANSDATE GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetRequestingDoctor] @Refnum as varchar(10), @Type as varchar(1) AS If @Type = 'I' Begin Select top 1 Case When isnull(A.RequestDocID,'0') <> '0' Then Cardio.dbo.fn_GetDoctorsName(A.RequestDocID) Else isnull(DoctorName,'') End DoctorName From Billing..tbBillDailyBill A Where RefNum = @Refnum End; Else Begin Select top 1 Case When isnull(A.RequestDocID,'0') <> '0' Then Cardio.dbo.fn_GetDoctorsName(A.RequestDocID) Else isnull(DoctorName,'') End DoctorName From Billing..tbBillOpDailyOut A Where RefNum = @Refnum End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_DailyInpatient] @Type varchar(1), @ReportDate varchar(10) /* format mm/dd/yyyy */ AS declare @begindate as datetime declare @enddate as datetime set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) if @type = '1' begin select q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ctexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbctrequest q left join tbcoctexam e on q.code = e.ctexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null end if @type = '2' begin select q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.xrayexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbxrrequest q left join tbcoxrayexam e on q.code = e.xrayexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum where (q.transdate >= @begindate and q.transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null end if @type = '3' begin select q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ultraexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbulrequest q left join tbcoultraexam e on q.code = e.ultraexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_AuditReportSummaryRadiology] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS --select * from build_file..tbcosection where revenueid = 'XR' /*set @StartDate = '01/15/2004'; set @EndDate = '01/18/2004'; */ Select sum([InPatient]) as InPatient, sum([OutPatient]) as OutPatient, sum([PrePaid]) as PrepaidPatient, sum([ERPatient]) as ERPatient From (Select --WithOut miscellaneous Case When Isnumeric(A.IDnum) = 1 and Not B.SectionID = 'O' and not A.Refnum like 'C%I' and isnull(D.ERNum,'') = '' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [InPatient], Case When Isnumeric(A.IDnum) = 0 and Not B.SectionID = 'O' and not A.Refnum like 'C%I' and isnull(D.ERNum,'') = '' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [OutPatient], Case When A.Refnum like 'C%I' and isnull(D.ERNum,'') = '' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid], Case When Not isnull(D.ERNum,'') = '' and Not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [ERPatient] From Billing..tbBillOpDailyOut A Left Outer Join Billing..tbBillExamListing B On A.ItemID = B.ItemID and B.RevenueID = @RevenueID Left Outer Join Build_File..tbCoSection C On B.SectionID = C.SectionID and C.RevenueID = @RevenueID Left Outer Join Patient_Data..tbOutPatient D On A.Idnum = D.Idnum Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID Union All Select --WithOut miscellaneous Case When Isnumeric(A.IDnum) = 1 and Not B.SectionID = 'O' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [InPatient], Case When Isnumeric(A.IDnum) = 0 and Not B.SectionID = 'O' and not A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [OutPatient], Case When A.Refnum like 'C%I' Then Case When A.Amount > 0 Then 1 Else -1 End Else 0 End as [PrePaid], 0 as [ERPatient] From Billing..tbBillDailyBill A Left Outer Join Billing..tbBillExamListing B On A.ItemID = B.ItemID and B.RevenueID = @RevenueID Left Outer Join Build_File..tbCoSection C On B.SectionID = C.SectionID and C.RevenueID = @RevenueID Where A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.RevenueID = @RevenueID ) A GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ViewExams] @RevenueID varchar(2), @Status varchar(1), @Criteria varchar(50) AS if @RevenueID = 'XR' begin select XRayExamID [Code], XRayExam [Description] from build_file..tbCoXRayExam where Status = @Status and XrayExam like @Criteria + '%' Order by XRayExam end if @RevenueID = 'CT' begin select CTExamID [Code], CTExam [Description] from build_file..tbCoCTExam where Status = @Status and CTExam like @Criteria + '%' Order by CTExam end if @RevenueID = 'US' begin select UltraExamID [Code], UltraExam [Description] from build_file..tbCoUltraExam where Status = @Status and UltraExam like @Criteria + '%' Order by UltraExam end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_AssessmentStatus] @RevenueID varchar(2) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'WC' then o.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID from billing..tbcashassessment a left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID left join build_file..tbcoOtherRevenue O on A.ItemID = O.OtherRevenueID and A.Revenueid = O.OtherSectionID where a.revenueid = @RevenueID or a.DepartmentID = @RevenueID order by [Patient Name], a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_AuditReport Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spRadio_BMDAuditReport] @RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS DECLARE @StartDate datetime, @EndDate datetime SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) Select b.refnum, b.amount, Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End as Quantity , b.itemid, Case @RevenueID when 'BM' then e.OtherRevenue End as exam, b.userid, Convert(varchar(10), b.transdate, 101) transdate, b.idnum, p.hospnum, m.lastname + ', ' + m.firstname patient From billing..tbbilldailybill b Left Join Build_File..tbcoOtherRevenue E on B.itemID = E.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID union all Select b.refnum, b.amount, Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End as Quantity, b.itemid, Case @RevenueID when 'BM'then e.OtherRevenue End as exam, b.userid, Convert(varchar(10), b.transdate, 101) transdate, b.idnum, p.hospnum, Case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom End as patient From billing..tbbillopdailyout b left Join build_file..tbcoOtherRevenue E on B.ItemID = E.OtherREvenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID Order by patient GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_DailyOutpatient] @Type varchar(1), @ReportDate varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = CAST(@ReportDate as datetime) set @enddate = dateadd(day, 1, @begindate) if @type = '1' begin select q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.ctexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbctrequest q left join tbcoctexam e on q.code = e.ctexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end if @type = '2' begin select q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.xrayexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbxrrequest q left join tbcoxrayexam e on q.code = e.xrayexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum where (q.transdate >= @begindate and q.transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end if @type = '3' begin select q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.ultraexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbulrequest q left join tbcoultraexam e on q.code = e.ultraexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetPatientAddress] @HospNum as varchar(10) as --Set @HospNum = '110128' Select isnull(HouseStreet,'') + ', ' + isnull(Barangay,'') + ' ' + isnull((Select isnull(Town,'') + ', ' + isnull(Province,'') From Build_File..tbcoAddress Where ZipCode = A.ZipCode),'') as Address From Patient_Data..tbmaster A Where HospNum = @HospNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetPHMembership] @IdNum as varchar(10) AS select isnull(M.PHICDescription,'') as PHICDescription, isnull(AD.AdmissionType,'') as AdmissionType from PATIENT_DATA..tbPatient P LEFT OUTER JOIN PATIENT_DATA..tbPatient2 P2 ON P.IdNum = P2.IdNum left outer join patient_data..tbAdmPHICTable M ON P.MedicareType = M.PHICCode LEFT OUTER JOIN BUILD_fILE..tbCoAdmissionType AD on P2.AdmissionTypeID = AD.AdmissionTypeID where P.Idnum = @IdNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_AddBill Script Date: 07/01/2000 1:19:24 AM ******/ /* by : mary ann gungon*/ CREATE PROCEDURE [dbo].[sp_NucAddBill] @strPatientType Varchar(1), @strIdNum Varchar(10), @strTransDate Varchar(25), @strRefNum Varchar(10), @strItemID Varchar(4), @strAmount Varchar(15), @strRevenueID Varchar(4), @strUserID Varchar(8), @Quantity float, @SummaryCode varchar(2), @DrCr varchar(1) AS if @strPatientType = 'I' begin insert into billing..tbBillDailyBill (IdNum,TransDate,RevenueID,DrCr,ItemID,RefNum,Amount,UserID,Quantity,SummaryCode) values (@strIdNum,@strTransDate,@strRevenueID,@DrCr,@strItemID,@strRefNum,convert(money,@strAmount,0),@strUserID,@Quantity,@SummaryCode) end else begin insert into billing..tbBillOPDailyOut (IdNum,TransDate,RevenueID,DrCr,ItemID,RefNum,Amount,UserID,Quantity,SummaryCode) values (@strIdNum,@strTransDate,@strRevenueID,@DrCr,@strItemID,@strRefNum,cast(@strAmount as money),@strUserID,@Quantity,@SummaryCode) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DoctorCharge Script Date: 07/01/2000 1:19:32 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DoctorCharge] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10) AS declare @DeptCode as varchar(2) IF right(ltrim(@RefNum),1) = 'X' begin set @DeptCode = 'XR' end; IF right(ltrim(@RefNum),1) = 'U' begin set @DeptCode = 'US' end; IF right(ltrim(@RefNum),1) = 'S' begin set @DeptCode = 'CT' end; IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '', @DeptCode ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @DeptCode) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_AddCashAsses Script Date: 07/01/2000 1:20:04 AM ******/ /*by: mary ann gunon */ CREATE PROCEDURE [dbo].[sp_NucAddCashAsses] @strIdNum Varchar(10), @strName Varchar(50), @strTransDate Varchar(25), @strAssessNum Varchar(10), @strItemID Varchar(4), @strAmount Varchar(10), @strUserID Varchar(10), @strRefNum Varchar(10), @strRevenueID Varchar(2), @strDepartmentID varchar(2) AS insert into billing..tbCashAssessment (idnum,name,transdate,assessnum,drcr,itemid, refnum,amount,userid,revenueid,departmentid) values (@strIdNum,@strName,@strTransDate,@strAssessNum,'D',@strItemID,@strRefNum, cast(@strAmount as money),@strUserId,@strRevenueID,@strDepartmentID) GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DoctorCharge Script Date: 07/01/2000 1:19:32 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DoctorCharge1] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10), @HospNum as varchar(12) AS IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID,HospNum) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @HospNum) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_AddCashPatient Script Date: 07/01/2000 1:20:04 AM ******/ /* by: mary ann gungon */ CREATE PROCEDURE [dbo].[sp_NucAddCashPatient] @strSwitch Varchar(1), @strHospNum Varchar(8), @strLastName Varchar(50), @strFirstName Varchar(50), @strMiddleName Varchar(50), @strHouseStreet Varchar(30), @strBarangay Varchar(30), @strZipCode Varchar(4), @strSex Varchar(1), @strBirthDate Varchar(10), @strCivilStatus Varchar(1), @strAge Varchar(3) AS DECLARE @cBirthDate varchar(10) DECLARE @cAge varchar(3) if @strBirthDate = '' begin SET @cBirthDate = NULL SET @cAge = NULL end else begin SET @cBirthDate = @strBirthDate SET @cAge = @strAge end if @strSwitch='0' begin insert into patient_data..tbCashPatient (Hospnum,LastName,FirstName,MiddleName,HouseStreet,Barangay,ZipCode,Sex,BirthDate,CivilStatusID,Age) values(@strHospNum,@strLastName,@strFirstName,@strMiddleName,@strHouseStreet,@strBarangay,@strZipCode,@strSex,@cBirthDate,@strCivilStatus,@cAge) end else begin update patient_data..tbCashPatient set lastname=@strLastName,firstname=@strFirstName,MiddleName=@strMiddleName,HouseStreet=@strHouseStreet, Barangay=@strBarangay,ZipCode=@strZipCode,Sex=@strSex,BirthDate=@cBirthDate,CivilStatusID=@strCivilStatus,age = @cAge where hospnum = @strHospNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_EntryExams] @Type varchar(1), @IDNum varchar(10) AS select R.RequestNum, R.TransDate, R.Code, /*R.TypeDescription*/ E.XRayExam [TypeDescription], E.XRaySectionID from tbXRRequest R left join tbCoXrayExam E on R.Code = E.XrayExamID where R.IDNum = @IDNum and R.SwFin is null and (E.XRaySectionID = 'PRC' or E.XraySectionID = 'VIS') order by R.RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_EntryList] @Type varchar(1), @LastName varchar(20) AS SELECT IDNUM [R.AdmNum], RTRIM(MAX(R.LASTNAME)) + ', ' + RTRIM(MAX(R.FIRSTNAME)) + ' ' + RTRIM(MAX(R.MIDDLENAME)) [Patient] FROM TBXRREQUEST R LEFT JOIN TBCOXRAYEXAM E ON R.CODE = E.XRAYEXAMID WHERE R.SWFIN IS NULL AND R.LASTNAME LIKE @LastName + '%' AND (E.XRAYSECTIONID = 'PRC' OR E.XRAYSECTIONID = 'VIS') GROUP BY IDNUM, LASTNAME, FIRSTNAME, MIDDLENAME ORDER BY LASTNAME, FIRSTNAME, MIDDLENAME GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_MRI_Yearly_Report] @Year As Varchar(4) --@Start As Varchar(10), --@End As Varchar(10) AS DECLARE @Start As Varchar(10),@End As Varchar(10) Set @Start = '01/01/' + @Year; Set @End = '12/31/' + @Year; BEGIN Select DATENAME(month,A.Transdate) As TransDate, 0 As InPx, 1 As OutPx, Case Isnull(Rtrim(Ltrim(B.GSIS)),'') When 'M' then 1 Else 0 End As GMem, Case Isnull(Rtrim(Ltrim(B.GSIS)),'') When 'D' then 1 Else 0 End As GDep, Case Isnull(Rtrim(Ltrim(B.GSIS)),'') When 'S' then 1 Else 0 End As SC, 0 As Co From ( Select sum(A.amount) Amount ,A.refnum RefNum,A.chargeslip ChargeSlip, convert(Varchar(10),A.Transdate,101) TransDate From Billing..tbBillOPDailyOut A --Inner Join Build_file..tbCoOtherRevenue B -- On A.ItemID = b.OtherRevenueID and B.OthersectionID ='MI' Where A.Transdate between @Start and @End + ' 23:59:59' and A.RevenueID = 'MI' and A.IDNum = 'CASH' Group By A.refnum,A.chargeslip,A.Transdate Having sum(A.amount) > 0 ) A Inner Join Billing..tbCashAssessment B On A.Refnum = B.ORNumber and A.ChargeSlip = B.RefNum and B.RevenueID ='MI' Where B.ItemID <> '263' UNION ALL Select DATENAME(month,A.Transdate) As TransDate, 0 As InPx, 0 As OutPx, 0 As GMem, 0 As GDep, 0 As SC, 1 As Co From ( Select sum(A.amount) Amount ,A.refnum,A.chargeslip,convert(Varchar(10),A.Transdate,101) Transdate From Billing..tbBillOPDailyOut A Where A.Transdate between @Start and @End + ' 23:59:59' and A.RevenueID = 'MI' and A.IDNum <> 'CASH' --and A.ItemID <> '263' Group By A.refnum,A.chargeslip,convert(Varchar(10),A.Transdate,101) Having sum(A.amount) > 0 ) A UNION ALL Select DATENAME(month,A.Transdate) As TransDate, 1 As InPx, 0 As OutPx, Case Isnull(P.MedicareType,'') When 'GM' then 1 When 'GSM' then 1 Else 0 End As GMem, Case Isnull(P.MedicareType,'') When 'GD' then 1 When 'GSD' then 1 Else 0 End As GDep, Case Isnull(BF.ReveNueID,'') When 'SC' then 1 Else 0 End As SC, Case When Isnull(P.AccountNum,'') <> Isnull(P.HospNum,'') then 1 Else 0 End As Co From ( Select sum(A.amount) Amount ,A.IDNum,convert(Varchar(10),A.Transdate,101) Transdate ,A.refnum --,A.chargeslip From Billing..tbBillDailyBill A Where A.Transdate between @Start and @End + ' 23:59:59' and A.RevenueID = 'MI' --and A.ItemID <> '263' Group By A.IDNum,convert(Varchar(10),A.Transdate,101),A.refnum--,A.chargeslip Having sum(A.amount) > 0 ) A Left Outer Join Billing..tbBillDailyBill B On A.IDNum = B.IDnum Left Outer Join Patient_Data..tbPatient P On A.IDNum = P.IDnum Left Outer Join Build_File..tbCoRevenueCode BF On B.ReveNueID = BF.RevenueID and BF.Lgrp = 'D' Where B.DrCr = 'C' and BF.Lgrp = 'D' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spRadio_Mammo_StatisticalReport_perRoom] --declare @StartDate as Varchar(10), @EndDate as Varchar(10) --@RevenueID as varchar(2) --set @StartDate = '01/01/2008' --set @EndDate = '01/31/2008' as --if @RevenueID = 'MM' Begin --Xray SELECT E.otherrevenue as Exam, case when Class.Roomclass = 'Ward' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [WARD], case when Class.Roomclass = 'Private' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [PRIVATE], case when Class.Roomclass = 'SEMI-PRIVATE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [SEMI-PRIVATE], case when Class.Roomclass = 'EXECUTIVE SUITE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [EXECUTIVE SUITE], 0 as [OPD], 'MAMMO DEPARTMENT' as Dept FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN BUILD_FILE..tbCootherrevenue E on B.ItemID = E.otherrevenueID LEFT OUTER JOIN PATIENT_DATA..TBPATIENT InPx on InPx.idnum = B.idnum Left Outer Join build_file..tbcoroom Room On InPx.Roomid = Room.Roomid Left Outer Join build_file..tbcoroomclass Class On Room.roomclassid = Class.roomclassid WHERE (B.RevenueID = 'MM') --or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' AND B.AMOUNT <> 0 UNION ALL SELECT E.otherrevenue as Exam, 0 as [WARD], 0 as [PRIVATE], 0 as [SEMI-PRIVATE], 0 as [EXECUTIVE SUITE], case when ISNUMERIC(B.idnum) = 0 then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 END as [OPD], 'MAMMO DEPARTMENT' as Dept FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BUILD_FILE..tbCootherrevenue E on B.ItemID = E.otherrevenueID --LEFT OUTER JOIN radiology..tbxrrequest O --on B.refnum = o.refnum WHERE (B.RevenueID = 'MM') --or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and ISNUMERIC(B.idnum) = 0 --AND isnull(swfin, '') not in ('C','R') AND B.AMOUNT <> 0 order by Exam Asc end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_AddNurseLogBook Script Date: 07/01/2000 1:20:04 AM ******/ /* By: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucAddNurseLogBook] @strHospNum Varchar(8), @strIdNum Varchar(10), @strItemId Varchar(4), @strDescription Varchar(30), @strAmount Varchar(15), @strUserID Varchar(8), @strProcessBy Varchar(8), @strRefNum Varchar(10), @strRevenueID Varchar(2), @strPatientType Varchar(1), @strRequestNum Varchar(8), @Quantity integer, @strStationID varchar(2) AS declare @strProcessDate datetime declare @strRequestDate datetime set @strProcessDate = getdate() set @strRequestDate = getdate() insert into station..tbNurseLogBook (HospNum,IdNum,RevenueID,RequestDate,ItemID,Description,Amount, RecordStatus,UserId,ProcessBy,ProcessDate,ReferenceNum,PatientType, Remarks,RequestNum,Quantity,StationID) values (@strHospNum,@strIdNum,@strRevenueID,@strRequestDate,@strItemID,@strDescription,cast(@strAmount as money), 'X',@strUserID,@strProcessBy,@strProcessDate,@strRefNum,@strPatientType, 'Manually Posted',@strRequestNum,@Quantity,@strStationID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_EntryMaster] @HospNum varchar(8) AS IF LEFT(@HospNum,1) <> 'T' BEGIN select isnull(ControlNum, 0) [ControlNum], isnull(CTNum, '') [CTNum], isnull(XRayNum, '') [XRayNum], isnull(UltraNum, '') [UltraNum], Sex, CivilStatus, isnull(BirthDate, '') [BirthDate], isnull(Age, '') [Age] from tbMaster where HospNum = @HospNum END ELSE BEGIN select isnull(ControlNum, 0) [ControlNum], isnull(CTNum, '') [CTNum], isnull(XRayNum, '') [XRayNum], isnull(UltraNum, '') [UltraNum], Sex, CivilStatusID [CivilStatus], Isnull(BirthDate, '') [BirthDate], isnull(Age, '') [Age] from tbCashPatient where HospNum = @HospNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucAssessment] AS Select billing..tbCashAssessment.[Name] as PatientName, billing..tbCashAssessment.ItemID as Code, (case billing..tbCashAssessment.DepartmentID when 'NU' then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.NucExam end) as Exam, billing..tbCashAssessment.RefNum as RefNum, billing..tbCashAssessment.Amount as Amount, (Case IsNull(billing..tbCashAssessment.RecordStatus,'') when '' then Convert(varchar(26),billing..tbCashAssessment.TransDate,105) when '1' then isnull(billing..tbCashAssessment.OrNumber,'') else 'REVOKED' End) as Status From billing..tbCashAssessment Left Outer Join build_file..tbCoNucExam on billing..tbCashAssessment.ItemID = build_file..tbCoNucExam.NucExamID Left Outer Join build_file..tbCoDoctor on build_file..tbCoDoctor.DoctorID = billing..tbCashAssessment.ItemID Where billing..tbCashAssessment.RevenueID = 'NU' or billing..tbCashAssessment.DepartmentID = 'NU' Order By billing..tbCashAssessment.[Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CheckSectionID] @ExamID as varchar(10) AS Select XraysectionId as SectionID From Build_file..tbcoxrayexam Where XrayExamID = @ExamID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_EntryRequest] @Type varchar(1), @RequestNum varchar(8) AS select R.Requestnum, R.Transdate, case when R.HospNum = 'CASH' then R.IDNum else R.HospNum end as HospNum, R.IDNum, R.Lastname, R.Firstname, R.Middlename, R.RoomID, R.RequestDoctorCode [DoctorID], RTrim(D.FirstName + ' ' + D.LastName) [Doctor] from tbXRRequest R left join tbCoDoctor D on R.RequestDoctorCode = D.DoctorID Where RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Modified by: Stephanie Mae Bravo Date: December 01,2007 Time: 4:56 PM*/ CREATE PROCEDURE [dbo].[spRadio_MammoRevokeNurseRequest] @Idnum varchar(10), @ItemId varchar(10), @RevenueId varchar(2) --@UserID varchar(10) AS update STATION..tbNurseCommunicationFile set RecordStatus = 'R' where Idnum = @Idnum and itemid = @itemid update STATION..tbNurseLogBook set RecordStatus = 'R', ChangeDate = GETDATE() --ChangeBy = @UserID where Idnum = @Idnum and itemid = @itemid GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucAssessmentByAssessNum] @RefNum varchar(10) AS Update billing..tbCashAssessment Set RecordStatus = 'R' Where (RevenueID = 'NU' or DepartmentID = 'NU') and RefNum = @RefNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_NurseRequestByIdNum_New] @Type As varChar(1), @IdNum varchar(8) AS IF @Type = '1' /* CT-Scan Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount]--, --Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Price], '1' as Quantity, --Cast(tbExam.RateA as Money) as [Amount], Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Amount]--, --Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '2' /* XRay Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'XR' as Department, Nurse.ItemID as Code, tbExam.XRayExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount]--, --Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoXRayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'XR' as Department, Nurse.ItemID as Code, tbExam.XrayExam as Exam, Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Price], '1' as Quantity, -- Cast(tbExam.RateA as Money) as [Amount], Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Amount]--, -- Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoXrayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '3' /* Ultrasound Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'US' as Department, Nurse.ItemID as Code, tbExam.UltraExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount]--, --Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Where Nurse.RevenueID = 'US' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'US' as Department, Nurse.ItemID as Code, tbExam.UltraExam as Exam, Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Price], '1' as Quantity, --Cast(tbExam.RateA as Money) as [Amount], Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateC as Money) Else Cast(tbExam.RateA as Money) End as [Amount]--, --Nurse.Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Where Nurse.RevenueID = 'US' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucAssessmentByName] @Name as varchar(50) AS Select billing..tbCashAssessment.[Name] as PatientName, billing..tbCashAssessment.ItemID as Code, (case billing..tbCashAssessment.DepartmentID when 'NU' then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.NucExam end) as Exam, billing..tbCashAssessment.RefNum as RefNum, billing..tbCashAssessment.Amount as Amount, (Case IsNull(billing..tbCashAssessment.RecordStatus,'') when '' then Convert(varchar(26),billing..tbCashAssessment.TransDate,105) when '1' then isnull(billing..tbCashAssessment.ornumber,'') else 'REVOKED' End) as Status From billing..tbCashAssessment Left Outer Join build_file..tbCoNucExam on billing..tbCashAssessment.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on build_file..tbCoDoctor.DoctorID = billing..tbCashAssessment.ItemID Where (billing..tbcashassessment.RevenueID = 'NU' or billing..tbcashassessment.DepartmentID = 'NU') and billing..tbCashAssessment.[Name] like @Name+'%' Order By billing..tbCashAssessment.[Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrepaidRequestPrintStatus] @Refnum as varchar(10) AS Update Prepaid..tbPrepaidCharges Set PrintStatus = 1 Where ChargeSlip = @Refnum and RevenueId in('XR', 'US', 'CT') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucAuditReport Script Date: 07/01/2000 1:20:23 AM ******/ CREATE PROCEDURE [dbo].[sp_NucAuditReport] @StartDate varchar(10), @EndDate varchar(10) AS SELECT DISTINCT billing..tbBillDailyBill.RefNum As Refnum, case when billing..tbBillDailyBill.DrCr = 'C' then (billing..tbBillDailyBill.Amount * -1) else billing..tbBillDailyBill.Amount END As Amount, billing..tbBillDailyBill.RevenueID As Account, billing..tbBillDailyBill.Quantity As Quantity, billing..tbBillDailyBill.ItemID As ItemID, (case billing..tbBillDailyBill.RevenueID when 'MD' then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbconucexam.nucexam end) As NucExam, password..tbPasswordMain.initial as UserID, rtrim(patient_data..tbMaster.Lastname) + ' ,' + rtrim(patient_data..tbMaster.Firstname) + ' '+ rtrim(patient_data..tbMaster.Middlename) As Patient, billing..tbBillDailyBill.TransDate As Transdate FROM billing..tbBillDailyBill LEFT OUTER JOIN build_file..tbCoNucExam ON billing..tbBillDailyBill.ItemID = build_file..tbCoNucExam.nucexamID LEFT OUTER JOIN build_file..tbCoDoctor on billing..tbBillDailyBill.ItemID = build_file..tbCoDoctor.DoctorID LEFT OUTER JOIN password..tbPasswordMain ON billing..tbBillDailyBill.UserID = password..tbPasswordMain.EmployeeID LEFT OUTER JOIN (patient_data..tbpatient inner join patient_data..tbmaster on patient_data..tbmaster.hospnum = patient_data..tbpatient.hospnum) on patient_data..tbpatient.idnum = billing..tbbilldailybill.idnum WHERE (billing..tbBillDailyBill.RevenueID = 'NU' or billing..tbBillDailyBill.SummaryCode = 'NU') and (billing..tbBillDailyBill.Transdate between @StartDate and (@EndDate + ' 11:59:59 PM')) --and Substring(tbBillDailyBill.Refnum,len(tbBillDailyBill.Refnum),1) = 'Y' UNION ALL /*OutPatientBill*/ SELECT DISTINCT billing..tbBillOpDailyOut.RefNum As RefNum, case when billing..tbBillOpDailyOut.DrCr = 'C' then (billing..tbBillOpDailyOut.Amount * -1) else billing..tbBillOpDailyOut.Amount END As Amount, billing..tbBillOpDailyOut.RevenueID As Account, billing..tbBillOpDailyOut.Quantity As Quantity, billing..tbBillOpDailyOut.ItemID As ItemID, (case billing..tbBillOpDailyOut.RevenueID when 'MD' then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.nucexam end) As NucExam, password..tbPasswordMain.Initial, (case substring(billing..tbBillOpDailyOut.refnum,1,2) -- when 'OR' then rtrim(tbCashPatient.Lastname) + ', ' + rtrim(tbCashPatient.FirstName) + ' ' + rtrim(tbCashPatient.Middlename) when 'OR' then billing..tbCashOrMaster.PaymentFrom else rtrim(patient_data..tbMaster.Lastname) + ' ,' + rtrim(patient_data..tbMaster.Firstname) + ' '+ rtrim(patient_data..tbMaster.Middlename) end) As Patient, billing..tbBillOpDailyOut.TransDate As Transdate FROM billing..tbBillOpDailyOut LEFT OUTER JOIN build_file..tbCoNucExam ON billing..tbBillOpDailyOut.ItemID = build_file..tbCoNucExam.nucexamid LEFT OUTER JOIN build_file..tbCoDoctor on billing..tbBillOpDailyOut.ItemID = build_file..tbCoDoctor.DoctorID LEFT OUTER JOIN password..tbPasswordMain ON billing..tbBillOpDailyOut.UserID = password..tbPasswordMain.EmployeeID LEFT OUTER JOIN (patient_data..tboutpatient a inner join patient_data..tbmaster on patient_data..tbmaster.hospnum = a.hospnum left outer join build_file..tbCoCompany on build_file..tbCoCompany.accountnum = a.accountnum) on a.idnum = billing..tbBillOpDailyOut.idnum -- LEFT OUTER JOIN (tboutpatient b inner join tbCashPatient on b.HospNum = tbCashPatient.HospNum) -- on b.IdNum = tbBillOpDailyOut.IDNum LEFT OUTER JOIN billing..tbCashOrMaster on billing..tbCashOrMaster.RefNum = billing..tbBillOpDailyOut.RefNum WHERE ( billing..tbBillOpDailyOut.RevenueID = 'NU' or billing..tbBillOpDailyOut.SummaryCode = 'NU') and ( billing..tbBillOpDailyOut.Transdate between @StartDate and (@EndDate + ' 11:59:59 PM')) --and Substring(tbBillOpDailyOut.Refnum,len(tbBillOpDailyOut.Refnum),1) = 'Y' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ExamRate] @Type AS varChar(1) AS IF @Type = '1' /* CT-Scan Listing */ BEGIN SELECT CTExamID [Code], CTExam [Exam], RateA, RateB, RateC, RateD, Status FROM build_file..tbcoCTExam ORDER BY CTExam END IF @Type = '2' /* Xray Listing */ BEGIN SELECT XrayExamID [Code], XrayExam [Exam], RateA, RateB, RateC, RateD, Status FROM tbcoXrayExam ORDER BY XrayExam END IF @Type = '3' /* Ultrasound Listing */ BEGIN SELECT UltraExamID [Code], UltraExam [Exam], RateA, RateB, RateC, RateD, Status FROM tbcoUltraExam ORDER BY UltraExam END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.sp_NucCashGetPatient Script Date: 07/01/2000 1:20:34 AM ******/ /*for Nuclear ; By: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucCashGetPatient] @strSearchBy Varchar(1), @strLastName Varchar(50), @strFirstName Varchar(50), @strHospNum Varchar(8) AS if @strSearchBy = 'L' begin if len(@strFirstName) > 0 begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbCashPatient where lastname = @strLastName + '%' and firstname like @strFirstName + '%' order by lastname end else begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbCashPatient where lastname like @strLastName + '%' order by lastname end end if @strSearchBy = 'H' begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbCashPatient where hospnum = @strHospNum order by lastname end if @strSearchBy = '0' begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from tbCashPatient order by lastname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucCashLink Script Date: 07/01/2000 1:20:23 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucCashLink] AS select paymentfrom as [Patient Name], (select nucexam from build_file..tbCoNucExam where build_file..tbConucexam.nucexamid = billing..tbCashCommunication.itemid ) as [Exam], Convert(varchar(10), transdate,101) + ' ' + Convert(varchar(8),transdate,108) as [Trans. Date], refnum as [Official Receipt No.],amount as [Amount],userid as [User ID] from billing..tbCashCommunication where revenueid='NU' and (recordstatus is null or recordstatus='') order by paymentfrom GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_CheckCashAsses Script Date: 07/01/2000 1:20:19 AM ******/ /*by: mary ann gungon */ CREATE PROCEDURE [dbo].[sp_NucCheckCashAsses] @strRevenueID Varchar(2), @strItemID Varchar(4), @strRefNum Varchar(10) AS select * from billing..tbcashassessment where revenueid=@strRevenueID and itemid=@strItemID and refnum = @strRefNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_DoctorCharge] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10) AS declare @DeptCode as varchar(2) IF right(ltrim(@RefNum),1) = 'W' begin set @DeptCode = 'WC' end; IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '', @DeptCode ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @DeptCode) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_CheckNurseCommunicationFile Script Date: 07/01/2000 1:20:19 AM ******/ /* by: Mary Ann Gungon*/ CREATE PROCEDURE [dbo].[sp_NucCheckNurseCommunicationFile] @strSwitch Varchar(1), @strPatientType Varchar(1), @strRevenueID Varchar(2), @strItemID Varchar(4), @strIdNum Varchar(10), @strNurseRequestNum Varchar(8) AS if @strSwitch = '0' begin SELECT * FROM Station..tbNurseCommunicationFile WHERE idnum = @strIdNum and itemid = @strItemID and revenueid = @strRevenueID and recordstatus <> 'R' and patienttype=@strPatientType and requestnum=@strNurseRequestNum end else begin SELECT * FROM station..tbNurseCommunicationFile WHERE idnum = @strIdNum AND itemid = @strItemID and revenueid = @strRevenueID and recordstatus = 'X' and patienttype=@strPatientType and requestnum=@strNurseRequestNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_NurseRequestByIdNum] --declare @Type As varChar(1), @IdNum varchar(8), @DepartmentID varchar(2) = ' ' /*set @Type = '2' set @IdNum = '11187' set @DepartmentID = 'XR'*/ AS IF @Type = '1' /* CT-Scan Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateE as money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateH as Money) Else Cast(tbExam.RateA as Money) End as [Price], '1' as Quantity, --Cast(tbExam.RateA as Money) as [Amount], Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateH as Money) Else Cast(tbExam.RateA as Money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '2' /* XRay Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select top 1 'XR' as Department, Nurse.ItemID as Code, tbExam.XRayExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateE as money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoXRayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'XR' as Department, Nurse.ItemID as Code, tbExam.XrayExam as Exam, Cast(tbExam.RateA as Money) as [Price], '1' as Quantity, -- Cast(tbExam.RateA as Money) as [Amount], Cast(tbExam.RateA as Money) as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoXrayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '3' /* Ultrasound Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select top 1 Nurse.RevenueID as Department, Nurse.ItemID as Code, --case Nurse.RevenueiD tbExam.UltraExam as Exam, --When 'WC' then tbOtherRevenue.OtherRevenue --Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateB as money) End as [Price], /*else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End End*/ '1' as Quantity, --Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) When Room.RoomClassId = 'E' then cast(tbExam.RateE as money) Else cast (tbExam.RateB as money) End as [Amount], /*else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End End*/ Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID --Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue -- On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('US' ) and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End ELSE Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, tbExam.UltraExam as Exam, --Case Nurse.RevenueID --When 'US' then Cast(tbExam.RateA as Money) as [Price], --When 'WC' then Cast(tbOtherRevenue.RateA as Money) --end '1' as Quantity, --Case Nurse.RevenueID --When 'US' then Cast(tbExam.RateA as Money) as [Amount], --When 'WC' then Cast(tbOtherRevenue.RateA as Money) --end Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID --Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue -- On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('US') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End END IF @Type = '4' /* Woman Center Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, case Nurse.RevenueiD When 'US' then tbExam.UltraExam When 'WC' then tbOtherRevenue.OtherRevenue end as Exam, Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateB as money) End else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateC as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateD as money) Else cast (tbOtherRevenue.RateB as money) End End as [Price], '1' as Quantity, Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateB as money) End else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateC as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateD as money) Else cast (tbOtherRevenue.RateB as money) End End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End ELSE Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, tbExam.UltraExam as Exam, Case Nurse.RevenueID When 'US' then Cast(tbExam.RateA as Money) When 'WC' then Cast(tbOtherRevenue.RateA as Money) end as [Price], '1' as Quantity, Case Nurse.RevenueID When 'US' then Cast(tbExam.RateA as Money) When 'WC' then Cast(tbOtherRevenue.RateA as Money) end as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName, Nurse.RequestNum,Nurse.IsPortable From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End END /* IF @Type = '1' -- CT-Scan Request BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.CTExam as Exam, Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateH as Money) Else Cast(tbExam.RateA as Money) End as [Price], '1' as Quantity, --Cast(tbExam.RateA as Money) as [Amount], Case When Clinical_Area.dbo.fn_IsHMO(Nurse.IDnum) = 'Y' Then Cast(tbExam.RateH as Money) Else Cast(tbExam.RateA as Money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoCTExam tbExam On Nurse.ItemID = tbExam.CTExamID Where Nurse.RevenueID = 'CT' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '2' -- XRay Request BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'XR' as Department, Nurse.ItemID as Code, tbExam.XRayExam as Exam, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Price], '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoXRayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'XR' as Department, Nurse.ItemID as Code, tbExam.XrayExam as Exam, Cast(tbExam.RateA as Money) as [Price], '1' as Quantity, -- Cast(tbExam.RateA as Money) as [Amount], Cast(tbExam.RateA as Money) as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoXrayExam tbExam On Nurse.ItemID = tbExam.XrayExamID Where Nurse.RevenueID = 'XR' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END IF @Type = '3' -- Ultrasound Request BEGIN IF isnumeric(@IDNum) = 1 Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, case Nurse.RevenueiD When 'US' then tbExam.UltraExam When 'WC' then tbOtherRevenue.OtherRevenue end as Exam, Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateB as money) When Room.RoomClassId = 'D' then cast(tbExam.RateB as money) Else cast (tbExam.RateB as money) End else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End End as [Price], '1' as Quantity, Case When Nurse.RevenueID = 'US' then Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateB as money) When Room.RoomClassId = 'D' then cast(tbExam.RateB as money) Else cast (tbExam.RateB as money) End else Case When Room.RoomClassID = 'A' then cast(tbOtherRevenue.RateA as money) When Room.RoomClassId = 'B' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'C' then cast(tbOtherRevenue.RateB as money) When Room.RoomClassId = 'D' then cast(tbOtherRevenue.RateB as money) Else cast (tbOtherRevenue.RateB as money) End End as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('US' , 'WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End ELSE Begin Select Nurse.RevenueID as Department, Nurse.ItemID as Code, tbExam.UltraExam as Exam, Case Nurse.RevenueID When 'US' then Cast(tbExam.RateA as Money) When 'WC' then Cast(tbOtherRevenue.RateA as Money) end as [Price], '1' as Quantity, Case Nurse.RevenueID When 'US' then Cast(tbExam.RateA as Money) When 'WC' then Cast(tbOtherRevenue.RateA as Money) end as [Amount], Nurse.Remarks, Nurse.DoctorID, Nurse.DoctorName From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoUltraExam tbExam On Nurse.ItemID = tbExam.UltraExamID Left Outer Join Build_file..tbcoOtherRevenue tbOtherRevenue On Nurse.ItemID = tbOtherRevenue.OtherRevenueID Where Nurse.RevenueID in ('US' , 'WC') and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(Nurse.ItemID) = 1 End END*/ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchERPatient] @Idnum as varchar(10) AS Select ERNum From Patient_Data..tbOutPatient Where Idnum = @Idnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_CheckNurseLogBook Script Date: 07/01/2000 1:20:19 AM ******/ /* by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucCheckNurseLogBook] @strSwitch Varchar(1), @strPatientType Varchar(1), @strIdNum Varchar(10), @strRevenueID Varchar(2), @strItemID Varchar(4), @strNurseRequestNum Varchar(8) AS if @strSwitch = '0' begin SELECT * FROM station..tbNurseLogBook WHERE idnum = @strIdNum AND itemid = @strItemID AND revenueid = @strRevenueID and recordstatus <> 'R' and patienttype=@strPatientType and requestnum=@strNurseRequestNum end else begin SELECT * FROM station..tbNurseLogBook WHERE idnum = @strIdNum AND itemid = @strItemID AND revenueid = @strRevenueID and recordstatus = 'X' and patienttype=@strPatientType and requestnum=@strNurseRequestNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_FinancialStatistics] @RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS declare @startdate datetime declare @enddate datetime set @startdate = convert(datetime, @firstday, 101) set @enddate = dateadd(day, 1, convert(datetime, @lastday, 101)) select b.itemid, case @RevenueID when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam end as [description], case @RevenueID when 'XR' then e.xraysectionid when 'CT' then c.ctsectionid when 'US' then u.ultraexam end as [sectionid], case @RevenueID when 'XR' then se.sectionname when 'CT' then sc.sectionname when 'US' then su.sectionname end as sectionname, case when p.idnum is not null then b.quantity else 0 end inquantity, case when p.idnum is not null then b.amount else 0 end inamount, case when p.idnum is null then b.quantity else 0 end outquantity, case when p.idnum is null then b.amount else 0 end outamount, b.quantity, b.amount, b.refnum from tbbilldailybill b left join tbcoxrayexam e on b.itemid = e.xrayexamid left join tbcoctexam c on b.itemid = c.ctexamid left join tbcoultraexam u on b.itemid = u.ultraexamid left join tbcosection se on e.xraysectionid = se.sectionid and se.revenueid = 'XR' left join tbcosection sc on c.ctsectionid = sc.sectionid and sc.revenueid = 'CT' left join tbcosection su on u.ultrasectionid = su.sectionid and su.revenueid = 'US' left join tbpatient p on b.idnum = p.idnum where b.transdate >= @startdate and b.transdate < @enddate and b.revenueid = @RevenueID union all select b.itemid, case @RevenueID when 'XR' then e.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam end as [description], case @RevenueID when 'XR' then e.xraysectionid when 'CT' then c.ctsectionid when 'US' then u.ultraexam end as [sectionid], case @RevenueID when 'XR' then se.sectionname when 'CT' then sc.sectionname when 'US' then su.sectionname end as sectionname, case when p.idnum is not null then b.quantity else 0 end inquantity, case when p.idnum is not null then b.amount else 0 end inamount, case when p.idnum is null then b.quantity else 0 end outquantity, case when p.idnum is null then b.amount else 0 end outamount, b.quantity, b.amount, b.refnum from tbbillopdailyout b left join tbcoxrayexam e on b.itemid = e.xrayexamid left join tbcoctexam c on b.itemid = c.ctexamid left join tbcoultraexam u on b.itemid = u.ultraexamid left join tbcosection se on e.xraysectionid = se.sectionid and se.revenueid = 'XR' left join tbcosection sc on c.ctsectionid = sc.sectionid and sc.revenueid = 'CT' left join tbcosection su on u.ultrasectionid = su.sectionid and su.revenueid = 'US' left join tbpatient p on b.idnum = p.idnum where b.transdate >= @startdate and b.transdate < @enddate and b.revenueid = @RevenueID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* ALter by Jetty P. omo Added out patient as a pending request for Prepaid Modified the age and used the function in computing the age Date : 01/22/2008 */ CREATE PROCEDURE [dbo].[spRadio_SearchPrepaidRequest] @RevenueID as varchar(10) --set @RevenueID = 'wC' AS Select A.HospNum, A.Idnum, B.LastName, B.FirstName, B.MiddleName, C.ItemID, C.Description, B.Chargeslip, Case When isnull(B.PrintStatus,0) = 1 Then 'Printed' Else '' End Status, convert(varchar(25),B.TransDate, 101) as RequestDate, A.RoomID,Age =Laboratory.dbo.fn_LabComputeAge(d.BirthDate, getdate()), convert(varchar(10),D.BirthDate, 101) as BirthDate From Patient_Data..tbPatient A Left Outer Join Prepaid..tbPrepaidCharges B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On B.ItemCode = C.ItemID and C.RevenueID = @RevenueID Left Outer Join Patient_Data..tbMaster D On A.HospNum = D.HospNum Where (A.DcrDate is null or BillingDate is null) and B.RevenueID = @RevenueID and isnull(B.Cancelled,0) <> '1' and isnull(B.PrintStatus, 0) = 0 Union all Select A.HospNum, A.Idnum, B.LastName, B.FirstName, B.MiddleName, C.ItemID, C.Description, B.Chargeslip, Case When isnull(B.PrintStatus,0) = 1 Then 'Printed' Else '' End Status, convert(varchar(25),B.TransDate, 101) as RequestDate, 'OPD' as RoomID, Age =Laboratory.dbo.fn_LabComputeAge(d.BirthDate, getdate()), convert(varchar(10),D.BirthDate, 101) as BirthDate From Patient_Data..tbOutPatient A Left Outer Join Prepaid..tbPrepaidCharges B On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On B.ItemCode = C.ItemID and C.RevenueID = @RevenueID Left Outer Join Patient_Data..tbMaster D On A.HospNum = D.HospNum Where (A.DcrDate is null or BillingDate is null) and B.RevenueID = @RevenueID and isnull(B.Cancelled,0) <> '1' and isnull(B.PrintStatus, 0) = 0 -------------------------------------------------------- GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucCheckPending] AS select count(*) TotalPending from station..tbNurseCommunicationFile where (recordstatus IS NULL or recordstatus='') and revenueID='NU' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_EndoCommSearchExam Script Date: 07/01/2000 1:20:23 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucCommSearchExam] @strIdNum Varchar(10) AS SELECT station..tbnursecommunicationfile.itemid, build_file..tbconucexam.nucexam as [Exam], station..tbnursecommunicationfile.amount, station..tbnursecommunicationfile.requestnum, station..tbnursecommunicationfile.quantity FROM station..tbNurseCommunicationFile left outer join build_file..tbconucexam on station..tbnursecommunicationfile.itemid = build_file..tbconucexam.nucexamid WHERE station..tbnursecommunicationfile.idnum = @strIdNum and station..tbnursecommunicationfile.revenueid='NU' and (station..tbnursecommunicationfile.recordstatus='' or station..tbnursecommunicationfile.recordstatus IS NULL) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ListPatientDiagnosis] @Idnum as varchar(10) AS Select AdmDiagnosis, ChiefComplaint From Patient_Data..tbPatientHistory Where IDnum = @IDnum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --BSL get the discount type and discount priority March 17, 3:09PM CREATE PROCEDURE [dbo].[spRadio_GetDiscountType] @HospNum as varchar(12), @IdNum as varchar(12) AS DECLARE @PatientClass as varchar(1) DECLARE @DiscType as varchar(2) DECLARE @DiscTypeA as varchar(2) DECLARE @DiscTypeB as varchar(2) DECLARE @MSS as bit DECLARE @Senior as bit if isnumeric(@IdNum) = 1 begin SET @PatientClass = (SELECT left(isnull(PatientClass,'P'),1)[PatientClass] FROM PATIENT_DATA..tbPatient2 WHERE IdNum = @IdNum) end; else begin SET @PatientClass = (SELECT left(isnull(PatientType,'P'),1) [PatientClass] FROM PATIENT_DATA..tbOutPatient WHERE IdNum = @IdNum) end; if @PatientClass = 'S' begin SET @MSS = (SELECT CASE isnull(MSSClassification,'') When '' then 0 else 1 end as [MSS] FROM PATIENT_DATA..tbMaster WHERE HospNum = @HospNum) end; else begin SET @MSS = 0 end; SET @Senior = (SELECT SeniorCitizen FROM PATIENT_DATA..tbMaster WHERE HospNum = @HospNum); SET @DiscTypeB = (SELECT DiscountType FROM PATIENT_DATA..tbOutPatient WHERE IdNum = @IdNum); SET @DiscTypeA = (SELECT CASE @MSS When 0 then (SELECT Case @Senior WHEN 1 then 'SM' end as [Senior]) When 1 then 'QF' end as [DiscTypeA]); SET @DiscType = (SELECT CASE @DiscTypeA WHEN 'QF' then 'QF' WHEN 'SM' then @DiscTypeB ELSE @DiscTypeB END as [DiscType]); select @DiscType as DiscType; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucCommunication Script Date: 07/01/2000 1:20:23 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucCommunication] AS select a.idnum,b.lastname,b.firstname,b.middlename, build_file..tbCoNucExam.nucexam as [Exam], a.requestdate,a.remarks,a.userid,a.patienttype,a.itemid,a.requestnum from station..tbNurseCommunicationFile a INNER JOIN patient_data..tbMaster b ON a.hospnum = b.hospnum left outer join build_file..tbconucexam on build_file..tbconucexam.nucexamid = a.itemid where (a.recordstatus IS NULL or a.recordstatus='') and a.revenueID='NU' order by b.lastname GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetPrepaid] @RevenueID as varchar(2), @IDnum as varchar(10), @Chargeslip as varchar(10) AS select A.HospNum,A.Idnum,A.LastName,A.FirstName,A.MiddleName, A.TransDate, A.ItemDescription, A.Chargeslip, B.RoomID, B.AGe,D.Sex from Prepaid..tbPrepaidCharges A Left Join Patient_data..tbpatient B on A.IDnum = B.Idnum Left Join Build_File..tbcoCompany C On B.AccountNum = C.AccountNum Left Outer Join Patient_Data..tbMaster D on B.hospNum = D.HospNum where A.Revenueid = @RevenueID and A.IDNum = @IDnum and A.ChargesLip = @Chargeslip GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCancelByFirstName Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear , by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCancelByFirstName] @strLastName Varchar(50), @strFirstName Varchar(50) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.NucExamID Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and ((select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) = @strLastName or (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) = @strLastName) and ((select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) like @strFirstName+'%' or (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) like @strFirstName+'%') order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created by Jetty P. Omo November 27,2007 This statistical report is group by room classification EXEC RADIOLOGY.dbo.spRadio_StatisticalReport_perRoomClass '11/01/2007', '11/01/2007' */-- CREATE Procedure [dbo].[spRadio_StatisticalReport_perRoomClass] @StartDate as Varchar(10), @EndDate as Varchar(10), @RevenueID as varchar(2) = '' /* set @StartDate = '01/01/2008' set @EndDate = '01/31/2008' set @RevenueID = 'xr' */ as if @RevenueID = 'XR' Begin --Xray SELECT E.XrayExam as Exam, case when Class.Roomclass = 'Ward' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [WARD], case when Class.Roomclass = 'Private' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [PRIVATE], case when Class.Roomclass = 'SEMI-PRIVATE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [SEMI-PRIVATE], case when Class.Roomclass = 'EXECUTIVE SUITE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [EXECUTIVE SUITE], 0 as [OPD], 'XRAY SECTION' as Dept FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID LEFT OUTER JOIN PATIENT_DATA..TBPATIENT InPx on InPx.idnum = B.idnum Left Outer Join build_file..tbcoroom Room On InPx.Roomid = Room.Roomid Left Outer Join build_file..tbcoroomclass Class On Room.roomclassid = Class.roomclassid WHERE (B.RevenueID = 'XR' or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' AND B.AMOUNT <> 0 UNION ALL SELECT E.XrayExam as Exam, 0 as [WARD], 0 as [PRIVATE], 0 as [SEMI-PRIVATE], 0 as [EXECUTIVE SUITE], case when ISNUMERIC(B.idnum) = 0 then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 END as [OPD], 'XRAY SECTION' as Dept FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID --LEFT OUTER JOIN radiology..tbxrrequest O --on B.refnum = o.refnum WHERE (B.RevenueID = 'XR' or SummaryCode = 'XR') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and ISNUMERIC(B.idnum) = 0 --AND isnull(swfin, '') not in ('C','R') AND B.AMOUNT <> 0 order by Exam Asc end --Ultrasound if @RevenueID = 'US' Begin SELECT E.ULtraExam as Exam, case when Class.Roomclass = 'Ward' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [WARD], case when Class.Roomclass = 'Private' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [PRIVATE], case when Class.Roomclass = 'SEMI-PRIVATE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [SEMI-PRIVATE], case when Class.Roomclass = 'EXECUTIVE SUITE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [EXECUTIVE SUITE], 0 as [OPD], 'ULTRASOUND SECTION' as Dept FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN BUILD_FILE..tbCoULtraExam E on B.ItemID = E.ULtraExamID LEFT OUTER JOIN PATIENT_DATA..TBPATIENT InPx on InPx.idnum = B.idnum Left Outer Join build_file..tbcoroom Room On InPx.Roomid = Room.Roomid Left Outer Join build_file..tbcoroomclass Class On Room.roomclassid = Class.roomclassid WHERE (B.RevenueID = 'US' or SummaryCode = 'US') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' AND B.AMOUNT <> 0 UNION ALL SELECT E.ULtraExam as Exam, 0 as [WARD], 0 as [PRIVATE], 0 as [SEMI-PRIVATE], 0 as [EXECUTIVE SUITE], case when ISNUMERIC(B.idnum) = 0 then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 END as [OPD], 'ULTRASOUND SECTION' as Dept FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BUILD_FILE..tbCoULtraExam E on B.ItemID = E.ULtraExamID WHERE (B.RevenueID = 'US' or SummaryCode = 'US') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and ISNUMERIC(B.idnum) = 0 AND B.AMOUNT <> 0 order by Exam Asc end if @RevenueID = 'CT' Begin SELECT E.CTExam as Exam, case when Class.Roomclass = 'Ward' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [WARD], case when Class.Roomclass = 'Private' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end End else 0 End as [PRIVATE], case when Class.Roomclass = 'SEMI-PRIVATE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [SEMI-PRIVATE], case when Class.Roomclass = 'EXECUTIVE SUITE' then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 End as [EXECUTIVE SUITE], 0 as [OPD], 'CT-Scan SECTION' as Dept FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN BUILD_FILE..tbCoCTExam E on B.ItemID = E.CTExamID LEFT OUTER JOIN PATIENT_DATA..TBPATIENT InPx on InPx.idnum = B.idnum Left Outer Join build_file..tbcoroom Room On InPx.Roomid = Room.Roomid Left Outer Join build_file..tbcoroomclass Class On Room.roomclassid = Class.roomclassid WHERE (B.RevenueID = 'CT' or SummaryCode = 'CT') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' AND B.AMOUNT <> 0 UNION ALL SELECT E.CTExam as Exam, 0 as [WARD], 0 as [PRIVATE], 0 as [SEMI-PRIVATE], 0 as [EXECUTIVE SUITE], case when ISNUMERIC(B.idnum) = 0 then case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end else 0 END as [OPD], 'CT-Scan SECTION' as Dept FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BUILD_FILE..tbCoCTExam E on B.ItemID = E.CTExamID WHERE (B.RevenueID = 'CT' or SummaryCode = 'CT') AND B.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and ISNUMERIC(B.idnum) = 0 AND B.AMOUNT <> 0 order by Exam Asc end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearcRadioUsers] @departmentID as varchar(2) , @employeename as varchar(30) = '' AS select EmployeeID, LastName + ', ' + FirstName + ' ' + IsNull(MiddleName,'') AS [Name], isnull(Position,'') as Position from PASSWORD..tbPasswordMain where DepartmentID in ('00',@departmentID, '11', '23', '13') and (@employeename = '' OR lastname like @employeename + '%' OR EmployeeID = @employeename) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ChargeSlip] @RefNum as varchar(10), @IdNum as varchar(10) /*set @RefNum = 'c24652w' set @idnum ='187599' */ As select A.itemID, Case A.RevenueID When 'WC' then B.OtherRevenue When 'MD' then Doc.LastName +', ' + Doc.FirstName + ' ' +Doc.MiddleName End as Exam, A.Quantity, A.Amount, A.TransDate,A.RoomID, C.HospNum,C.IdNum, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as PxName, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName as RequestDoc, F.LastName + ', ' + F.FirstName + ' ' + F.MiddleName as ProcessedBy, case when isnull(G.Company,'') = '' then 'PERSONAL' else G.Company end AccountName --convert(varchar(10), D.BirthDate,101) as BirthDate from billing..tbbilldailybill A Left Outer Join Build_File..TbcoOtherRevenue B On A.ItemID = B.OtherRevenueID Left Outer Join Patient_Data..TbPatient C On A.Idnum = C.IDnum Left Outer Join Patient_data..tbMaster D On C.HospNum = D.HospNum Left Outer Join Build_File..tbcoDoctor E on A.RequestDocID = E.DoctorID Left Outer Join Password..tbpasswordmaster F on a.UserID = F.EmployeeID Left Outer Join Build_File..tbcoCompany G on C.AccountNum = G.AccountNum Left Outer Join Build_file..tbcoDoctor Doc on A.itemID = Doc.DoctorID where RefNum = @Refnum Union All select A.itemID, Case A.RevenueID When 'WC' then B.OtherRevenue When 'MD' then Doc.LastName +', ' + Doc.FirstName + ' ' +Doc.MiddleName End as Exam, A.Quantity, A.Amount, A.TransDate,A.RoomID, c.HospNum,C.IdNum, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as PxName, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName as RequestDoc, F.LastName + ', ' + F.FirstName + ' ' + F.MiddleName as ProcessedBy, case when isnull(G.Company,'') = '' then 'PERSONAL' else G.Company end AccountName --convert(varchar(10), D.BirthDate,101) as BirthDate from billing..tbbillopdailyout A Left Outer Join Build_File..TbcoOtherRevenue B On A.ItemID = B.OtherRevenueID Left Outer Join Patient_Data..tbOutpatient C On A.Idnum = C.IDnum Left Outer Join Patient_data..tbMaster D On C.HospNum = D.HospNum Left Outer Join Build_File..tbcoDoctor E on A.RequestDocID = E.DoctorID Left Outer Join Password..tbpasswordmaster F on a.UserID = F.EmployeeID Left Outer Join Build_File..tbcoCompany G on C.AccountNum = G.AccountNum Left Outer Join Build_file..tbcoDoctor Doc on A.itemID = Doc.DoctorID where RefNum = @Refnum Union All select A.ItemID, Case A.RevenueID When 'WC' then B.OtherRevenue When 'MD' then Doc.LastName +', ' + Doc.FirstName + ' ' +Doc.MiddleName End as Exam, A.Quantity, A.Amount, A.TransDate,'OPD', A.HospNum,A.Idnum,A.Name, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName as RequestDoc, F.LastName + ', ' + F.FirstName + ' ' + F.MiddleName as ProcessedBy, 'CASH' as AccountName --'' as BirthDate from billing..tbcashassessment A Left Outer Join Build_File..TbcoOtherRevenue B On A.ItemID = B.OtherRevenueID Left Outer Join Build_File..tbcoDoctor E on A.RequestDocID = E.DoctorID Left Outer Join Password..tbpasswordmaster F on a.UserID = F.EmployeeID Left Outer Join Build_file..tbcoDoctor Doc on A.itemID = Doc.DoctorID where RefNum = @Refnum union all select A.ItemID, B.ItemName, A.Quantity, A.Amount, A.TransDate, case when isnumeric(A.RoomID) = 1 then A.Roomid else 'OPD' end RoomID, A.HospNum, A.Idnum, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as PxName, '' RequestDoc, c.LastName + ', ' + c.FirstName + ' ' + c.MiddleName as ProcessedBy, '' AccountName --convert(varchar(10), D.BirthDate,101) as BirthDate from Inventory..tbInvStockCard A Left Join Inventory..tbInvMaster B on A.ItemId = B.itemID Left Outer Join Password..tbpasswordmaster C on a.UserID = C.EmployeeID Left Outer Join Patient_data..tbMaster D On A.HospNum = D.HospNum where RefNum = @Refnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spGlobal_Assess Script Date: 07/01/2000 1:20:51 AM ******/ CREATE PROCEDURE [dbo].[spGlobal_Assess] @RefNum varchar(10), @Name varchar(50), @ItemID varchar(4), @RevenueID varchar(2), @Quantity float, @Amount float, @DepartmentID varchar(2), @UserID varchar(8), @IdNum varchar(10), @HospNum varchar(10), @DoctorID varchar(5), @DoctorName varchar(30) AS DECLARE @AssessNum varchar(10) DECLARE @nAssess float SELECT @nAssess = RequestNum FROM BILLING..tbAssessmentNum UPDATE BILLING..tbAssessmentNum SET RequestNum = @nAssess + 1 --SET @AssessNum = 'AS' + CONVERT(varchar(10), @nAssess) SET @AssessNum = LEFT(@RefNum, 2) + CONVERT(varchar(10), @nAssess) INSERT INTO BILLING..tbCashAssessment ([Name], TransDate, AssessNum, DrCr, ItemID, Quantity, Amount, RefNum, UserID, RevenueID, Indicator, DepartmentID, IdNum, HospNum, RequestDocID, DoctorName ) VALUES (@Name, GETDATE(), @AssessNum, 'D', @ItemID, @Quantity, @Amount, @RefNum, @UserID, @RevenueID, @RevenueID, @DepartmentID, @IdNum, @HospNum, @DoctorID, @DoctorName); GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCashExam Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear by: mary ann gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCashExam] @strOrNum Varchar(10) AS select billing..tbCashCommunication.itemid, build_file..tbCoNucExam.nucexam as exam, billing..tbCashCommunication.amount, billing..tbCashCommunication.quantity from billing..tbCashCommunication left outer join build_file..tbCoNucExam on billing..tbCashCommunication.itemid = build_file..tbCoNucExam.nucexamid where billing..tbCashCommunication.refnum = @strOrNum and (billing..tbCashCommunication.revenueid = 'NU' or billing..tbCashCommunication.departmentid = 'NU') and isnull(billing..tbCashCommunication.recordstatus,'') <> 'Y' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_InNurseUpdate Script Date: 07/01/2000 1:20:54 AM ******/ CREATE PROCEDURE [dbo].[spRadio_InNurseUpdate] @HospNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(4), @RevenueID AS varChar(2), @RequestNum as varchar(10) = null AS UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and RequestNum = @RequestNum UPDATE station..tbNurselogbook SET RecordStatus = 'X' WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and RequestNum = @RequestNum --HospNum = @HospNum AND GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.sp_NucGetPatient Script Date: 07/01/2000 1:20:35 AM ******/ /*for Nuclear ; By: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatient] @strSearchBy Varchar(1), @strLastName Varchar(50), @strFirstName Varchar(50), @strHospNum Varchar(8) AS if @strSearchBy = 'L' begin if len(@strFirstName) > 0 begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbMaster where lastname = @strLastName + '%' and firstname like @strFirstName + '%' order by lastname end else begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbMaster where lastname like @strLastName + '%' order by lastname end end else begin select hospnum as [Hosp. No.],isnull(lastname,'') + ',' + ' ' + isnull(firstname,'') + ' ' + isnull(middlename,'') as [Patient Name] from patient_data..tbMaster where hospnum = @strHospNum order by lastname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InquiryList] @Type varchar(1), @Name varchar(20) AS IF @TYPE = '1' BEGIN /* SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, REQ.Lastname, REQ.Firstname, REQ.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbCTRequest REQ LEFT JOIN tbCTResult RES ON REQ.RequestNum = RES.RequestNum WHERE REQ.Lastname LIKE @Name + '%' AND REQ.SwFin = 'Y' ORDER BY REQ.LastName, REQ.FirstName, REQ.MiddleName, RES.ControlNum */ select r.RequestNum, r.HospNum, r.IDnum, case when isnumeric(r.hospnum) = 1 then isnull(m.lastname, '') else isnull(c.lastname, '') end as Lastname, case when isnumeric(r.hospnum) = 1 then isnull(m.firstname, '') else isnull(c.firstname, '') end as Firstname, case when isnumeric(r.hospnum) = 1 then isnull(m.middlename, '') else isnull(c.middlename, '') end as Middlename, isnull(s.controlnum, '') as ControlNum, isnull(e.ctexam, '') as Exam, case when isdate(s.ResultDate) = 1 then convert(varchar(10), cast(s.resultdate as datetime), 101) else '' end as ResultDate from tbCTRequest r left join tbmaster m on r.hospnum = m.hospnum left join tbcashpatient c on r.hospnum = c.hospnum left join tbCTResult s on r.requestnum = s.requestnum left join tbcoCTExam e on r.code = e.CTExamID where isnull(r.swfin, '') = 'Y' and (isnull(m.lastname, '') like @Name + '%' or isnull(c.lastname, '') like @Name + '%') Order by LastName, FirstName, MiddleName, ControlNum END IF @TYPE = '2' BEGIN /* SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, REQ.Lastname, REQ.Firstname, REQ.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbXRRequest REQ LEFT JOIN tbXRResult RES ON REQ.RequestNum = RES.RequestNum WHERE REQ.Lastname LIKE @Name + '%' AND REQ.SwFin = 'Y' ORDER BY REQ.LastName, REQ.FirstName, REQ.MiddleName, RES.ControlNum */ select r.RequestNum, r.HospNum, r.IDnum, case when isnumeric(r.hospnum) = 1 then isnull(m.lastname, '') else isnull(c.lastname, '') end as Lastname, case when isnumeric(r.hospnum) = 1 then isnull(m.firstname, '') else isnull(c.firstname, '') end as Firstname, case when isnumeric(r.hospnum) = 1 then isnull(m.middlename, '') else isnull(c.middlename, '') end as Middlename, isnull(s.controlnum, '') as ControlNum, isnull(e.xrayexam, '') as Exam, case when isdate(s.ResultDate) = 1 then convert(varchar(10), cast(s.resultdate as datetime), 101) else '' end as ResultDate from tbXRRequest r left join tbmaster m on r.hospnum = m.hospnum left join tbcashpatient c on r.hospnum = c.hospnum left join tbxrresult s on r.requestnum = s.requestnum left join tbcoXRayExam e on r.code = e.XRayExamID where isnull(r.swfin, '') = 'Y' and (isnull(m.lastname, '') like @Name + '%' or isnull(c.lastname, '') like @Name + '%') Order by LastName, FirstName, MiddleName, ControlNum END IF @TYPE = '3' BEGIN /* SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, REQ.Lastname, REQ.Firstname, REQ.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbULRequest REQ LEFT JOIN tbULResult RES ON REQ.RequestNum = RES.RequestNum WHERE REQ.Lastname LIKE @Name + '%' AND REQ.SwFin = 'Y' ORDER BY REQ.LastName, REQ.FirstName, REQ.MiddleName, RES.ControlNum */ select r.RequestNum, r.HospNum, r.IDnum, case when isnumeric(r.hospnum) = 1 then isnull(m.lastname, '') else isnull(c.lastname, '') end as Lastname, case when isnumeric(r.hospnum) = 1 then isnull(m.firstname, '') else isnull(c.firstname, '') end as Firstname, case when isnumeric(r.hospnum) = 1 then isnull(m.middlename, '') else isnull(c.middlename, '') end as Middlename, isnull(s.controlnum, '') as ControlNum, isnull(e.UltraExam, '') as Exam, case when isdate(s.ResultDate) = 1 then convert(varchar(10), cast(s.resultdate as datetime), 101) else '' end as ResultDate from tbULRequest r left join tbmaster m on r.hospnum = m.hospnum left join tbcashpatient c on r.hospnum = c.hospnum left join tbxrresult s on r.requestnum = s.requestnum left join tbcoUltraExam e on r.code = e.UltraExamID where isnull(r.swfin, '') = 'Y' and (isnull(m.lastname, '') like @Name + '%' or isnull(c.lastname, '') like @Name + '%') Order by LastName, FirstName, MiddleName, ControlNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /***Will Return all the Used ChargeSlip Number.****/ -- by Alejandro F. Molina -- July 31, 2007 CREATE Procedure [dbo].[spRadio_CheckCSlip] AS Select substring(refnum,2,len(refnum)- 2) Refnum From BILLING..tbBillDailyBill where Drcr <> 'C' and refnum not like 'CM%' and refnum like 'C%' UNION ALL Select substring(refnum,2,len(refnum)- 2) Refnum From BILLING..tbbillOPDailyOUt where Drcr <> 'C' and refnum not like 'CM%' and refnum like 'C%' UNION ALL Select substring(refnum,2,len(refnum)- 2) Refnum From Inventory..tbInvStockcard where refnum not like 'CM%' and refnum like 'C%' order by RefNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InquiryMaster] @Type varchar(1), @HospNum varchar(10) AS if @Type = '1' begin select p.HouseStreet, p.Barangay, a.Town, a.Province, p.Sex, p.BirthDate, p.CivilStatus, p.Age, p.TelNum, p.XRayNum, p.UltraNum, p.CTNum from tbMaster p left join tbCoAddress a on p.ZipCode = a.ZipCode where p.hospnum = @HospNum end if @Type = '2' begin select p.HouseStreet, p.Barangay, a.Town, a.Province, p.Sex, p.BirthDate, p.CivilStatusID [CivilStatus], p.Age, '' [TelNum] from tbCashPatient p left join tbCoAddress a on p.ZipCode = a.ZipCode where p.hospnum = @HospNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InquiryPatient] @IDNum varchar(10) AS select AdmDate, RoomID from tbPatient where IDNum = @IDNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_CashUpdate] @RefNum varchar(8), @RevenueID varchar(2), @ItemID varchar(4), @Marker varchar(1) AS UPDATE BILLING..tbCashCommunication SET RecordStatus = @Marker WHERE RefNum = @RefNum AND RevenueID = @RevenueID AND ItemID = @ItemID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Pharma_CheckClearance] @IDnum as varchar(10), @RevenueID as varchar(2) = null AS Select Case When Case @RevenueID When 'XR' Then isnull(XRCleardate,'') When 'US' Then isnull(XRCleardate,'') When 'CT' Then isnull(XRCleardate,'') End = '' Then 0 Else 1 End as RecordStatus From Station..tbNurseDischargeNotice Where Idnum = @IDnum --and (RecordStatus = 'F' or RecordStatus = 'P') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_WalkIn] @SearchType varchar(1), @SearchCriterion varchar(25) AS SELECT HospNum, ISNULL(LastName, '') LastName, ISNULL(FirstName, '') FirstName, ISNULL(MiddleName, '') MiddleName FROM PATIENT_DATA..tbCashPatient WHERE LastName LIKE @SearchCriterion + '%' ORDER BY LastName, FirstName, MiddleName GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_CashInPatient Script Date: 07/01/2000 1:19:38 AM ******/ /* by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_CashInPatient] AS select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbPatient a, patient_data..tbMaster b, patient_data..tbPatient2 c where a.hospnum = b.hospnum and a.idnum = c.idnum and (c.okeynu = 0 or c.okeyau=0 or c.okeyhs=0 or c.okeyrts=0) and (a.dcrdate is null or a.dcrdate = '') order by b.lastname GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Radio_CheckClearance] @IDnum as varchar(10), @RevenueID as varchar(2) = null AS Select Case When Case @RevenueID When 'XR' Then isnull(XRCleardate,'') When 'US' Then isnull(USCleardate,'') When 'CT' Then isnull(CTCleardate,'') End = '' Then 0 Else 0 End as RecordStatus From Station..tbNurseDischargeNotice Where Idnum = @IDnum --and (RecordStatus = 'F' or RecordStatus = 'P') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_NurseRequest] As BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.OtherrevenueID as [ItemID] , C.OtherRevenue as [ItemDesc], Case When R.RoomClassID = 'A' then cast(isnull(C.RateA,0)as money) When R.RoomClassID = 'B' then cast(isnull(C.RateB,0)as money) When R.RoomClassID = 'C' then cast(isnull(C.RateC,0)as money) When R.RoomClassID = 'D' then cast(isnull(C.RateD,0)as money) When R.RoomClassID = 'E' then cast(isnull(C.RateE,0)as money) End as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, D.RoomID, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID ='MI' and D.BillingDate is Null Union All Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.OtherRevenueID as [ItemID] , C.OtherRevenue as [ItemDesc], cast(isnull(C.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID, convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID = 'CT' and D.BillingDate is Null Order By [Date Request], [LastName], [FirstName] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_NucPatient Script Date: 07/01/2000 1:19:38 AM ******/ /* for : heart station, by : Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_Patient] @strPatientType Varchar(1) AS if @strPatientType = 'I' begin select a.hospnum as [Hosp. No.], a.idnum as [Adm. No.], b.lastname+','+' '+b.firstname+' '+b.middlename as [Patient Name], cast(a.billingdate as varchar) as [Billed Date], case c.askcashbasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [Charging Status], case c.okeynu when 0 then 'Not Okey' when 1 then 'Okey' end as [Nuc Status], cast(a.DcrDate as varchar) [Discharge Date] from patient_data..tbPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum left outer join patient_data..tbPatient2 c on a.idnum = c.idnum where (convert(varchar(10),a.billingdate,101) = convert(varchar(10),getdate(),101) or a.billingdate is null or a.billingdate = '') order by b.lastname,b.firstname end else if @strPatientType = 'O' begin select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbOutPatient a left outer join tbMaster b on a.hospnum = b.hospnum where isnull(a.opdstatus,'') <> 'R' order by b.lastname,b.firstname end else begin select hospnum, hospnum as idnum, lastname, firstname, middlename from patient_data..tbCashPatient order by lastname,firstname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_DailyCensusOut] --declare @ReportDate varchar(10) --set @reportDate = '11/28/2007' AS declare @begindate as datetime declare @enddate as datetime --set @ReportDate ='07/04/2007' set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) select IdNum, [Name] as Patient, 'CASH' as Room, OrNumber as Refnum, Case A.RevenueID when 'WC' then B.OtherRevenue when 'MD' then C.LastName + ', ' + C.FirstName + ' ' + C.MiddleName else inv.ItemName end Exam, isnull(A.quantity,'1') as quantity, A.Amount as Amount, C.LastName + ', ' + C.FirstName + ' ' + C.MiddleName as RequestDoc --a.Recordstatus, --A.Revenueid from Billing..tbcashassessment A Left Outer Join Build_file..tbcoOtherRevenue B on A.itemID = B.OtherRevenueID Left Join Build_File..tbcoDoctor C on A.RequestDocID = C.DoctorID left Join Inventory..tbinvMaster Inv on A.ItemID = Inv.itemID where (A.transdate >= @begindate and transdate < @enddate) and isnull(A.RecordStatus,'') not in ('','R') and left(A.Refnum,2) ='WC' Union ALL select A.Idnum, D.LastName + ', '+ D.FirstName + ' ' + D.MiddleName as Patient, 'OPD' as Room, A.REfnum, Case A.RevenueID When 'WC' then B.OtherRevenue When 'MD' then C.LastName + ', ' + C.FirstName + ' ' + C.MiddleName else Inv.ItemName end Exam, isnull(A.Quantity,1) as Quantity, A.Amount as Amount, C.LastName + ', ' + C.FirstName + ' ' + C.MiddleName as RequestDoc --a.Recordstatus, ---A.Revenueid from Billing..tbbillopdailyout A Left Outer Join Build_file..tbcoOtherRevenue B on A.itemID = B.OtherRevenueID Left Join Build_File..tbcoDoctor C on A.RequestDocID = C.DoctorID or A.itemID = C.DoctorID Left Outer Join Patient_Data..tbOutpatient E on A.Idnum = E.idnum Left join PATIENT_DATA..tbmaster D on E.hospnum = D.hospnum Left Join Inventory..tbInvMaster Inv on A.ItemID = Inv.ItemID where (revenueid ='WC' or Summarycode = 'WC') and (A.transdate >= @begindate and transdate < @enddate) and a.Idnum <> 'CASH' Union All Select A.IdNum, C.LastName + ', ' + C.FirstName + ' ' + C.Middlename as Patient, 'OPD' as RoomID, A.Refnum, B.ItemName, A.Quantity, A.Amount, '' RequestDoc From Inventory..tbinvStockCard A Left Join Inventory..tbinvMaster B on A.itemID = B.itemID left Join Patient_Data..tbMaster C on A.HospNum = C.HospNum where A.locationID = '188' and isnumeric(A.IDNum) = 0 and (A.transdate >= @begindate and transdate < @enddate) order by Patient --select * from Billing..tbcashassessment where revenueid = 'WC' and ornumber <> 'REVOKED' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_CashExams] @RefNum varchar(10), @RevenueID varchar(2) AS select c.itemid [Code], case c.revenueID when @RevenueID then isnull(e.OtherRevenue, c.RevenueID + ' ' + c.itemid) when 'MD' then d.firstname + ' ' + d.lastname end as [Exam], c.quantity, c.amount, c.revenueID from BILLING..tbcashcommunication c left join BUILD_FILE..tbCoOtherRevenue e on c.itemid = e.OtherRevenueID and e.OtherSectionID = @RevenueID left join BUILD_FILE..tbCoDoctor d on c.itemid = d.doctorid where (c.revenueid = @RevenueID or c.DepartmentID = @RevenueID) and isnull(c.recordstatus, '') = '' and c.refnum = @RefNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_OutMaster] --declare @Type varchar(1), @IDNumber varchar(10) AS --set @Type = 'O' --set @IDNumber ='204905B' IF @Type = 'O' BEGIN SELECT P.IDNum, case when isnull(P.HospNum,'')= '' then MM.Hospnum else P.Hospnum end as Hospnum, M.LastName, M.FirstName, M.MiddleName, M.CivilStatus, M.Sex, M.HouseStreet, M.Barangay, A.Town, A.Province, M.BirthDate, M.Age, P.DoctorID1 [DoctorID], D.LastName [DrLastName], D.FirstName [DrFirstName], D.MiddleName [DrMiddleName], 'OPD' [RoomID], P.AdmDate, P.BillingDate, P.OPDStatus, M.AccountNum, ISNULL(C.Company, P.AccountNum) [Company], p.DcrDate FROM laboratory..vwPatientResultEntry M LEFT JOIN PATIENT_DATA..tbOutPatient P ON M.HospNum = P.HospNum LEFT JOIN BUILD_FILE..tbCoAddress A ON M.ZipCode = A.ZipCode LEFT JOIN BUILD_FILE..tbCoDoctor D ON P.DoctorID1 = D.DoctorID LEFT JOIN BUILD_FILE..tbCoCompany C ON M.AccountNum = C.AccountNum LEFT OUTER JOIN PATIENT_DATA..TBMASTER MM ON M.Hospnum = MM.Hospnum WHERE P.Idnum = @IDNumber END IF @Type = 'C' BEGIN SELECT m.HospNum [IDNum], m.HospNum, m.LastName, m.FirstName, m.MiddleName, m.CivilStatusID [CivilStatus], m.Sex, m.HouseStreet, m.Barangay, a.Town, a.Province, m.BirthDate, m.Age, NULL [DoctorID], NULL [DrLastName], NULL [DrFirstName], NULL [DrMiddleName], 'OPD' [RoomID], NULL [AdmDate], NULL [BillingDate], NULL [AccountNum], NULL [Company], NULL [DcrDate] FROM PATIENT_DATA..tbCashPatient m LEFT JOIN BUILD_FILE..tbCoAddress a ON m.ZipCode = a.ZipCode WHERE m.HospNum = @IDNumber END IF @Type = '' BEGIN SELECT m.HospNum [IDNum], m.HospNum, m.LastName, m.FirstName, m.MiddleName, m.CivilStatusID [CivilStatus], m.Sex, m.HouseStreet, m.Barangay, a.Town, a.Province, m.BirthDate, m.Age, NULL [DoctorID], NULL [DrLastName], NULL [DrFirstName], NULL [DrMiddleName], 'OPD' [RoomID], NULL [AdmDate], NULL [BillingDate], NULL [AccountNum], NULL [Company], NULL [DcrDate] FROM PATIENT_DATA..tbCashPatient m LEFT JOIN BUILD_FILE..tbCoAddress a ON m.ZipCode = a.ZipCode WHERE m.HospNum = @IDNumber END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_NucPatientByFirstName Script Date: 07/01/2000 1:19:38 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_PatientByFirstName] @strPatientType Varchar(1), @strLastName Varchar(50), @strFirstName Varchar(50) AS if @strPatientType = 'I' begin select a.hospnum as [Hosp. No.], a.idnum as [Adm. No.], b.lastname+','+' '+b.firstname+' '+b.middlename as [Patient Name], a.billingdate as [Billed Date], case c.askcashbasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [Charging Status], case c.okeynu when 0 then 'Not Okey' when 1 then 'Okey' end as [Nuc Status], a.DcrDate [Discharge Date] from patient_data..tbPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum left outer join patient_data..tbPatient2 c on a.idnum = c.idnum where b.lastname = @strLastName and b.firstname like @strFirstName + '%' and (convert(varchar(10),a.billingdate,101) = convert(varchar(10),getdate(),101) or a.billingdate='' or a.billingdate is null) order by b.lastname,b.firstname end else if @strPatientType = 'O' begin select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbOutPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum where b.lastname = @strLastName and b.firstname like @strFirstName+'%' and isnull(a.opdstatus,'') <> 'R' and a.admdate between convert(varchar(10),getdate(),101) and convert(varchar(10),getdate(),101) + ' 11:59:59' order by b.lastname,b.firstname end else begin select hospnum, hospnum as idnum, lastname, firstname, middlename from patient_data..tbCashPatient where lastname = @strLastName and firstname like @strFirstName+'%' order by lastname,firstname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_SaveCharges] @PatientType varchar(1), @IDNum varchar(10), @HospNum varchar(8), @RefNum varchar(10), @RevenueID varchar(10), @ItemID varchar(10), @Quantity float, @Amount float, @RequestDocID varchar(4), @UserID varchar(8), @RoomID varchar(8), @DrCr varchar(1), @SummaryCode varchar(2) AS IF @PatientType = 'I' BEGIN INSERT INTO BILLING..tbBillDailyBill (TransDate, IDNum, RefNum, ItemID, Quantity, Amount, RequestDocID, UserID, RevenueID, DrCr, RoomID, SummaryCode) VALUES (GETDATE(), @IDNum, @RefNum, @ItemID, @Quantity, @Amount, @RequestDocID, @UserID, @RevenueID, @DrCr, @RoomID, @SummaryCode) END IF @PatientType = 'O' BEGIN INSERT INTO BILLING..tbBillOPDailyOut (TransDate, IDNum, HospNum, RefNum, ItemID, Quantity, Amount, RequestDocID, UserID, RevenueID, DrCr, RoomID, SummaryCode) VALUES (GETDATE(), @IDNum, @HospNum, @RefNum, @ItemID, @Quantity, @Amount, @RequestDocID, @UserID, @RevenueID, @DrCr, @RoomID, @SummaryCode) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_NucPatientByHospNum Script Date: 07/01/2000 1:19:38 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_PatientByHospNum] @strPatientType Varchar(1), @strHospNum Varchar(8) AS if @strPatientType = 'I' begin select a.hospnum as [Hosp. No.], a.idnum as [Adm. No.], b.lastname+','+' '+b.firstname+' '+b.middlename as [Patient Name], cast(a.billingdate as varchar) as [Billed Date], case c.askcashbasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [Charging Status], case c.okeynu when 0 then 'Not Okey' when 1 then 'Okey' end as [Nuc Status], cast(a.DcrDate as varchar) [Discharge Date] from patient_data..tbPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum left outer join patient_data..tbPatient2 c on a.idnum = c.idnum where a.hospnum = @strHospNum and (convert(varchar(10),a.billingdate,101) = convert(varchar(10),getdate(),101) or a.billingdate IS NULL or a.billingdate='') order by b.lastname,b.firstname end else if @strPatientType = 'O' begin select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbOutPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum where a.hospnum = @strHospNum and isnull(a.opdstatus,'') <> 'R' and a.admdate between convert(varchar(10),getdate(),101) and convert(varchar(10),getdate(),101) + ' 11:59:59' order by b.lastname,b.firstname end else begin select hospnum, hospnum as idnum, lastname, firstname, middlename from patient_data..tbCashPatient where hospnum = @strHospNum order by lastname,firstname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_NucPatientByIdNum Script Date: 07/01/2000 1:19:39 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_PatientByIdNum] @strPatientType Varchar(1), @strIdNum Varchar(8) AS if @strPatientType = 'I' begin select a.hospnum as [Hosp. No.], a.idnum as [Adm. No.], b.lastname+','+' '+b.firstname+' '+b.middlename as [Patient Name], cast(a.billingdate as varchar) as [Billed Date], case c.askcashbasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [Charging Status], case c.okeynu when 0 then 'Not Okey' when 1 then 'Okey' end as [Nuc Status], cast(a.DcrDate as varchar) [Discharge Date] from patient_data..tbPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum left outer join patient_data..tbPatient2 c on a.idnum = c.idnum where a.idnum = @strIdNum and (convert(varchar(10),a.billingdate,101) = convert(varchar(10),getdate(),101) or a.billingdate IS NULL or a.billingdate='') order by b.lastname,b.firstname end else if @strPatientType = 'O' begin select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbOutPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum where a.hospnum = b.hospnum and a.idnum = @strIdNum and isnull(opdstatus,'') <> 'R' and a.admdate between convert(varchar(10),getdate(),101) and convert(varchar(10),getdate(),101) + ' 11:59:59' order by b.lastname,b.firstname end else begin select hospnum, hospnum as idnum, lastname, firstname, middlename from patient_data..tbCashPatient where hospnum = @strIdNum order by lastname,firstname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_AuditReport] @FirstDay varchar(10), @LastDay varchar(10) /*SET @FirstDay = '07/01/2007' SET @LastDay = '07/06/2007'*/ AS DECLARE @StartDate datetime, @EndDate datetime SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) select max(b.refnum) Refnum, sum(b.amount)Amount, max(b.quantity)Quantity, max(b.itemid)ItemID, max(case b.RevenueID when 'WC' then e.OtherRevenue when 'MD' then doc.LastName + ', ' + doc. FirstName end) as exam, max(b.userid) UserID, max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)Idnum, Max(p.hospnum)Hospnum, max(m.lastname + ', ' + m.firstname) patient from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum Left join Build_file..tbcoDoctor Doc on b.itemid = Doc.DoctorID where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = 'WC' group by b.Refnum, B.itemId Having sum(B.Amount) > 0 union all select b.refnum, sum(b.amount)Amount, max(b.quantity)Quantity, b.itemid, max(case B.RevenueID when 'WC' then e.OtherRevenue when 'MD' then doc.LastName + ', ' + doc. FirstName end) as exam, max(b.userid)UserID, max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)IdNum, max(p.hospnum)HospNum, max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum Left join Build_file..tbcoDoctor Doc on b.itemid = Doc.DoctorID where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = 'WC' group by B.refnum,B.ItemID Having sum(B.Amount) > 0 order by patient GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_AssessmentStatusNew] @RevenueID varchar(2), @PatientName varchar(30), @ShowPrevious as varchar(1) AS declare @StartDate as varchar(10) set @StartDate = convert(varchar(10),getdate(),101) if @ShowPrevious = 'N' begin select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'XR' then x.XRayExam when 'CT' then c.CTExam when 'US' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else isnull(E.Description,'') end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, cast(a.Transdate as varchar) as [Trans. Date] from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID Left Outer Join Billing..tbBillExamListing E On A.ItemID = E.ItemID and A.RevenueID = E.RevenueID where (a.revenueid = @RevenueID or a.DepartmentID = @RevenueID) and a.name like @PatientName + '%' and a.transdate between @StartDate and getdate() order by [Patient Name], a.TransDate end; else begin select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'XR' then x.XRayExam when 'CT' then c.CTExam when 'US' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else isnull(E.Description,'') end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, cast(a.Transdate as varchar) as [Trans. Date] from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID Left Outer Join Billing..tbBillExamListing E On A.ItemID = E.ItemID and A.RevenueID = E.RevenueID where (a.revenueid = @RevenueID or a.DepartmentID = @RevenueID) and a.name like @PatientName + '%' order by [Patient Name], a.TransDate end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Get_NucPatientByLastName Script Date: 07/01/2000 1:19:39 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGet_PatientByLastName] @strPatientType Varchar(1), @strLastName Varchar(50) AS if @strPatientType = 'I' begin select a.hospnum as [Hosp. No.], a.idnum as [Adm. No.], b.lastname+','+' '+b.firstname+' '+b.middlename as [Patient Name], cast(a.billingdate as varchar) as [Billed Date], case c.askcashbasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [Charging Status], case c.okeynu when 0 then 'Not Okey' when 1 then 'Okey' end as [Nuc Status], cast(a.DcrDate as varchar) [Discharge Date] from patient_data..tbPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum left outer join patient_data..tbPatient2 c on a.idnum = c.idnum where b.lastname LIKE @strLastName + '%' and (convert(varchar(10),a.billingdate,101) = convert(varchar(10),getdate(),101) or a.billingdate IS NULL or a.billingdate = '') order by b.lastname,b.firstname end else if @strPatientType = 'O' begin select a.hospnum, a.idnum, b.lastname, b.firstname, b.middlename from patient_data..tbOutPatient a left outer join patient_data..tbMaster b on a.hospnum = b.hospnum where b.lastname like @strLastName +'%' and isnull(a.opdstatus,'') <> 'R' and a.admdate between convert(varchar(10),getdate(),101) and convert(varchar(10),getdate(),101) + ' 11:59:59' order by b.lastname,b.firstname end else begin select hospnum, hospnum as idnum, lastname, firstname, middlename from patient_data..tbCashPatient where lastname like @strLastName+'%' order by lastname,firstname end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetPackageName] @Refnum as varchar(10) AS if Exists(Select top 1 PrepaidPackage From Billing..tbBillDailyBill Where Refnum = @Refnum) Begin Select top 1 isnull(B.Package,'') Package From Billing..tbBillDailyBill A Left Outer Join Patient_Data..tbPatient2 C On A.Idnum = C.Idnum Left Outer Join Build_File..tbcoAdmPackage B On C.PackageID = B.PackageID Where Refnum = @Refnum End; Else Begin Select top 1 isnull(B.Package,'') Package From Billing..tbBillOpDailyOut A Left Outer Join Patient_Data..tbOutPatient C On A.Idnum = C.IDnum Left Outer Join Build_File..tbcoAdmPackage B On C.PackageID = B.PackageID Where Refnum = @Refnum; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_ListOutExams Script Date: 07/01/2000 1:20:55 AM ******/ CREATE PROCEDURE [dbo].[spRadio_ListOutExams] @RefNum varchar(10), @Type varchar(1) AS IF @Type = '1' BEGIN Select IsNull(C.ItemID,'') [Code], IsNull(X.CTExam,'') [Description], case when isnull(c.quantity, 0) = 0 then IsNull(c.Amount,0) else IsNull(C.Amount,0) / IsNull(C.Quantity,0) end [Price], case when isnull(C.Quantity, 0) = 0 then 1 else IsNull(c.Quantity,0) end [Quantity], IsNull(C.Amount,0) [Amount] from BILLING..tbCashCommunication C left join BUILD_FILE..tbCoCTExam X on C.ItemID = X.CTExamID where (ISNULL(C.RecordStatus, '') = '' or C.RecordStatus = '1') and C.RefNum = @RefNum and (C.RevenueID = 'CT' OR C.DepartmentId = 'CT') END IF @Type = '2' BEGIN Select IsNull(C.ItemID,'') [Code], IsNull(X.XRayExam,'') [Description], case when isnull(c.quantity, 0) = 0 then IsNull(c.Amount,0) else IsNull(C.Amount,0) / IsNull(C.Quantity,0) end [Price], case when isnull(C.Quantity, 0) = 0 then 1 else IsNull(c.Quantity,0) end [Quantity], IsNull(C.Amount,0) [Amount] from BILLING..tbCashCommunication C left join BUILD_FILE..tbCoXRayExam X on C.ItemID = X.XRayExamID where (ISNULL(C.RecordStatus, '') = '' or C.RecordStatus = '1') and C.RefNum = @RefNum and (C.RevenueID = 'XR' OR C.DepartmentId = 'XR') END IF @Type = '3' BEGIN Select IsNull(C.ItemID,'') [Code], IsNull(X.UlTraExam,'') [Description], case when IsNull(c.quantity,0) = 0 then IsNull(c.Amount,0) else IsNull(C.Amount,0) / IsNull(C.Quantity,0) end [Price], case when isnull(C.Quantity, 0) = 0 then 1 else IsNull(c.Quantity,0) end [Quantity], IsNull(C.Amount,0) [Amount] from BILLING..tbCashCommunication C left join BUILD_FILE..tbCoUltraExam X on C.ItemID = X.UltraExamID where (ISNULL(C.RecordStatus, '') = '' or C.RecordStatus = '1') and C.RefNum = @RefNum and (C.RevenueID = 'US' OR C.DepartmentId = 'US') END IF @Type = '4' BEGIN Select IsNull(C.ItemID,'') [Code], IsNull(X.OtherRevenue,'') [Description], case when IsNull(c.quantity,0) = 0 then IsNull(c.Amount,0) else IsNull(C.Amount,0) / IsNull(C.Quantity,0) end [Price], case when isnull(C.Quantity, 0) = 0 then 1 else IsNull(c.Quantity,0) end [Quantity], IsNull(C.Amount,0) [Amount] from BILLING..tbCashCommunication C -- left join BUILD_FILE..tbCoUltraExam X -- on C.ItemID = X.UltraExamID left outer join build_file..tbcoOtherrevenue X on C.ItemID = X.OtherrevenueID and X.OthersectionID ='MI' where ( ISNULL(C.RecordStatus, '') = ''or C.RecordStatus = '1') and C.RefNum = @RefNum and (C.RevenueID = 'MI' or C.DepartmentId = 'MI') END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_GetPHMembership_OPD] @IdNum as varchar(10) AS select isnull(M.PHICDescription,'') as PHICDescription from PATIENT_DATA..tbOutPatient P LEFT OUTER JOIN patient_data..tbAdmPHICTable M ON P.MedicareType = M.PHICCode where P.Idnum = @IdNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucMonthlyReport Script Date: 07/01/2000 1:20:24 AM ******/ CREATE PROCEDURE [dbo].[sp_NucMonthlyReport] @StartDate varchar(10), @EndDate varchar(10) AS SELECT DISTINCT billing..tbBillDailyBill.RefNum As Refnum, case when billing..tbBillDailyBill.DrCr = 'C' then (billing..tbBillDailyBill.Amount * -1) else billing..tbBillDailyBill.Amount END As Amount, build_file..tbCoCompany.Company as Company, billing..tbBillDailyBill.ItemID As ItemID, (case billing..tbBillDailyBill.RevenueID when 'MD' then build_file..tbCoDoctor.LastName +', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.nucexam end) As NucExam, rtrim(patient_data..tbMaster.Lastname) + ' ,' + rtrim(patient_data..tbMaster.Firstname) + ' '+ rtrim(patient_data..tbMaster.Middlename) As Patient, billing..tbBillDailyBill.TransDate As Transdate FROM billing..tbBillDailyBill LEFT OUTER JOIN build_file..tbCoNucexam ON billing..tbBillDailyBill.ItemID = build_file..tbCoNucexam.nucexamid LEFT OUTER JOIN build_file..tbCoDoctor on billing..tbBillDailyBill.ItemID = build_file..tbCoDoctor.DoctorID LEFT OUTER JOIN (patient_data..tbpatient inner join patient_data..tbmaster on patient_data..tbmaster.hospnum = patient_data..tbpatient.hospnum left outer join build_file..tbCoCompany on build_file..tbCoCompany.accountnum = patient_data..tbpatient.accountnum) on patient_data..tbpatient.idnum = billing..tbbilldailybill.idnum WHERE (billing..tbBillDailyBill.RevenueID = 'NU' or billing..tbBillDailyBill.SummaryCode = 'NU') and (billing..tbBillDailyBill.Transdate between @StartDate and (@EndDate + ' 11:59:59 PM')) --and Substring(tbBillDailyBill.Refnum,len(tbBillDailyBill.Refnum),1) = 'Y' UNION ALL /*OutPatientBill*/ SELECT DISTINCT billing..tbBillOpDailyOut.RefNum As RefNum, case when billing..tbBillOpDailyOut.DrCr = 'C' then (billing..tbBillOpDailyOut.Amount * -1) else billing..tbBillOpDailyOut.Amount END As Amount, build_file..tbCoCompany.Company as Company, billing..tbBillOpDailyOut.ItemID As ItemID, (case billing..tbBillOpDailyOut.RevenueID when 'MD' then build_file..tbCoDoctor.LastName +', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucexam.nucexam end) As NucExam, (case substring(billing..tbBillOpDailyOut.refnum,1,2) -- when 'OR' then rtrim(tbCashPatient.Lastname) + ', ' + rtrim(tbCashPatient.FirstName) + ' ' + rtrim(tbCashPatient.Middlename) when 'OR' then billing..tbCashOrMaster.PaymentFrom else rtrim(patient_data..tbMaster.Lastname) + ' ,' + rtrim(patient_data..tbMaster.Firstname) + ' '+ rtrim(patient_data..tbMaster.Middlename) end) As Patient, billing..tbBillOpDailyOut.TransDate As Transdate FROM billing..tbBillOpDailyOut LEFT OUTER JOIN build_file..tbCoNucexam ON billing..tbBillOpDailyOut.ItemID = build_file..tbCoNucexam.nucexamid LEFT OUTER JOIN build_file..tbCoDoctor on billing..tbBillOpDailyOut.ItemID = build_file..tbCoDoctor.DoctorID LEFT OUTER JOIN (patient_data..tboutpatient a inner join patient_data..tbmaster on patient_data..tbmaster.hospnum = a.hospnum left outer join build_file..tbCoCompany on build_file..tbCoCompany.accountnum = a.accountnum) on a.idnum = billing..tbBillOpDailyOut.idnum -- LEFT OUTER JOIN (tboutpatient b inner join tbCashPatient on b.HospNum = tbCashPatient.HospNum) -- on b.IdNum = tbBillOpDailyOut.IDNum LEFT OUTER JOIN billing..tbCashOrMaster on billing..tbCashOrMaster.RefNum = billing..tbBillOpDailyOut.RefNum WHERE ( billing..tbBillOpDailyOut.RevenueID = 'NU' or billing..tbBillOpDailyOut.SummaryCode = 'NU') and ( billing..tbBillOpDailyOut.Transdate between @StartDate and (@EndDate + ' 11:59:59 PM')) --and Substring(tbBillOpDailyOut.Refnum,len(tbBillOpDailyOut.Refnum),1) = 'Y' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadCancel] @Type varchar(1), @LastName varchar(50) AS IF @Type = '1' BEGIN select q.RequestNum, q.RefNum [Reference], case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.ctexam [Request], convert(varchar(10), q.transdate, 101) [Request Date] from tbctrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoctexam e on q.code = e.ctexamid where isnull(q.swfin, '') = '' and (isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%') order by patient END IF @Type = '2' BEGIN select q.RequestNum, q.RefNum [Reference], case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.xrayexam [Request], convert(varchar(10), q.transdate, 101) [Request Date] from tbxrrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoxrayexam e on q.code = e.xrayexamid where /*isnull(q.swfin, '') = ''*/ q.swfin = 'X' and (isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%') order by patient END IF @Type = '3' BEGIN select q.RequestNum, q.RefNum [Reference], case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.ultraexam [Request], convert(varchar(10), q.transdate, 101) [Request Date] from tbulrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoultraexam e on q.code = e.ultraexamid where isnull(q.swfin, '') = '' and (isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%') order by patient END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_NurseRequestDoctor] @RevennueID as varchar(2), @IdNum as varchar(10) AS /* declare @IdNum as varchar(10) set @IdNum = '400488B' */ if isnumeric(@IdNum) = 0 begin select P.DoctorID1 as DoctorID, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as DoctorName, P.IdNum from patient_data..tbOutPatient P left outer join BUILD_FILE..tbCoDoctor D on P.DoctorID1 = D.DoctorID where idnum = @IdNum end; else begin select P.AttendingDr1 as DoctorID, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as DoctorName, P.IdNum from patient_data..tbPatient P left outer join BUILD_FILE..tbCoDoctor D on P.AttendingDr1 = D.DoctorID where idnum = @IdNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucPatientLedger Script Date: 07/01/2000 1:20:24 AM ******/ CREATE PROCEDURE [dbo].[sp_NucPatientLedger] @PatientType varchar(1), @IDNum varchar(10) AS if @PatientType = 'I' begin SELECT Distinct billing..tbBillDailyBill.RefNum As Refnum, case when billing..tbBillDailyBill.DrCr = 'C' then (billing..tbBillDailyBill.Amount * -1) else billing..tbBillDailyBill.Amount END As Amount, billing..tbBillDailyBill.RevenueID As Account, billing..tbBillDailyBill.Quantity As Quantity, billing..tbBillDailyBill.ItemID As ItemID, build_file..tbCoNucExam.nucexam As NucExam, password..tbPasswordMain.initial as UserID,--rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, billing..tbBillDailyBill.TransDate As Transdate FROM billing..tbBillDailyBill LEFT OUTER JOIN build_file..tbCoNucexam ON billing..tbBillDailyBill.ItemID = build_file..tbCoNucexam.nucexamid LEFT OUTER JOIN password..tbPasswordMain ON billing..tbBillDailyBill.UserID = password..tbPasswordMain.EmployeeID WHERE (billing..tbBillDailyBill.RevenueID = 'NU' or billing..tbBillDailyBill.SummaryCode = 'NU' ) and billing..tbBillDailyBill.IDNum = @IDNum --and Substring(tbBillDailyBill.Refnum,len(tbBillDailyBill.Refnum),1) = 'Y' end else --UNION ALL /*OutPatientBill*/ begin SELECT Distinct billing..tbBillOpDailyOut.RefNum As RefNum, case when billing..tbBillOpDailyOut.DrCr = 'C' then (billing..tbBillOpDailyOut.Amount * -1) else billing..tbBillOpDailyOut.Amount END As Amount, billing..tbBillOpDailyOut.RevenueID As Account, billing..tbBillOpDailyOut.Quantity As Quantity, billing..tbBillOpDailyOut.ItemID As ItemID, build_file.tbCoNucExam.nucexam As NucExam, password..tbPasswordMain.Initial, --rtrim(tbMaster.Lastname) + ' ,' + rtrim(tbMaster.Firstname) + ' '+ rtrim(tbMaster.Middlename) As Patient, billing..tbBillOpDailyOut.TransDate As Transdate FROM billing..tbBillOpDailyOut LEFT OUTER JOIN build_file..tbCoNucexam ON billing..tbBillOpDailyOut.ItemID = build_file..tbCoNucExam.nucexamid LEFT OUTER JOIN password..tbPasswordMain ON billing..tbBillOpDailyOut.UserID = password..tbPasswordMain.EmployeeID WHERE ( billing..tbBillOpDailyOut.RevenueID = 'NU' or billing..tbBillOpDailyOut.SummaryCode = 'NU') and billing..tbBillOpDailyOut.IDNum = @IDNum --and Substring(tbBillOpDailyOut.Refnum,len(tbBillOpDailyOut.Refnum),1) = 'Y' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AssessmentStatus_Search] @RevenueID varchar(2), @Search varchar(2) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'MR' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where a.revenueid = @RevenueID AND A.[NAME] LIKE @Search +'%' order by [Patient Name], a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadDischargeNoticeCount] @DepartmentID varchar(10) AS SELECT Count(n.IDNum) as RecCount FROM Station..tbNurseDischargenotice n left outer join Patient_Data..tbPatient tbPatient on n.Idnum = TbPatient.Idnum Where tbPatient.BillingDate is Null and isnull(n.recordstatus,'') = 'F' and ( case when @DepartmentID = 'XR' and n.XRClearDate is null then 1 when @DepartmentID = 'US' and n.USClearDate is null then 1 when @DepartmentID = 'CT' and n.CTClearDate is null then 1 when @DepartmentID = 'MM' and n.MMClearDate is null then 1 when @DepartmentID = 'EL' and n.ELClearDate is null then 1 when @DepartmentID = 'WC' and n.WCClearDate is null then 1 else 0 end ) = 1 and tbPatient.Hospnum is not null; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_AssessmentStatus_Search] @RevenueID varchar(2), @Search varchar(2) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'MI' then x.otherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID from billing..tbcashassessment a left join build_file..tbcoOtherRevenue x on a.ItemID = x.OtherRevenueID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where (a.revenueid = @RevenueID or a.DepartmentID =@RevenueID) AND A.[NAME] LIKE @Search +'%' order by [Patient Name], a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CheckIfFileNum] @strFileNum as varchar(15), @RevenueID as varchar(3) AS /* declare @strFileNum as varchar(15) declare @RevenueID as varchar(3) */ if @RevenueID = 'XR' begin select isnull(XrayNum,'') as XrayNum from patient_data..tbmaster where XrayNum = @strFileNum end; if @RevenueID = 'CT' begin select isnull(CTNum,'') as CTNum from patient_data..tbmaster where CTNum = @strFileNum end; if @RevenueID = 'US' begin select isnull(UltraNum,'') as CTNum from patient_data..tbmaster where CTNum = @strFileNum end; if @RevenueID = 'MI' begin select isnull(MRINum,'') as CTNum from patient_data..tbmaster where MRINum = @strFileNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucSearchCashLink Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucSearchCashLink] @EmpName varchar(50) AS select billing..tbCashCommunication.paymentfrom as [Patient Name], --(select nucexam from tbCoNucExam where tbCoNucExam.nucexamid = tbCashCommunication.itemid) as [Exam], build_file..tbCoNucexam.nucexam as exam, Convert(varchar(10), billing..tbCashCommunication.transdate,101) + ' ' + Convert(varchar(8),billing..tbCashCommunication.transdate,108) as [Trans. Date], billing..tbCashCommunication.refnum as [Official Receipt No.], billing..tbCashCommunication.amount as [Amount], billing..tbCashCommunication.userid as [User ID] from billing..tbCashCommunication left outer join build_file..tbCoNucexam on billing..tbCashCommunication.itemid = build_file..tbCoNucexam.nucexamid where billing..tbCashCommunication.revenueid='NU' and (billing..tbCashCommunication.recordstatus is null or billing..tbCashCommunication.recordstatus = '') and billing..tbCashCommunication.paymentfrom like @EmpName+'%' order by paymentfrom GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadDischargeNoticePatient] @IDNum varchar(10), @Department varchar(2) AS IF @Department = 'XR' BEGIN select n.IDNum, p.HospNum, m.LastName, m.FirstName, m.MiddleName, p.RoomID, p.AdmDate, p.AttendingDr1, d.LastName + ', ' + d.FirstName + ' ' + d.MiddleName [Doctor], n.NoticeDate, n.OrderedDate, '(' + n.DischargeNurse + ') ' + pm1.LastName + ', ' + pm1.FirstName [DischargeNurse], n.Remarks, n.XRClearDate [ClearDate], '(' + n.XRUserID + ') ' + pm2.LastName + ', ' + pm2.FirstName [UserID], n.XRRemarks [ClearRemarks] from station..tbnursedischargenotice n left join patient_data..tbpatient p on n.IDNum = p.IDNum left join patient_data..tbmaster m on p.HospNum = m.HospNum left join build_file..tbcodoctor d on p.AttendingDr1 = d.DoctorID left join password..tbPasswordMaster pm1 on n.DischargeNurse = pm1.EmployeeID left join password..tbPasswordMaster pm2 on n.XRUserID = pm2.EmployeeID where n.IDNum = @IDNum END IF @Department = 'US' BEGIN select n.IDNum, p.HospNum, m.LastName, m.FirstName, m.MiddleName, p.RoomID, p.AdmDate, p.AttendingDr1, d.LastName + ', ' + d.FirstName + ' ' + d.MiddleName [Doctor], n.NoticeDate, n.OrderedDate, '(' + n.DischargeNurse + ') ' + pm1.LastName + ', ' + pm1.FirstName [DischargeNurse], n.Remarks, n.USClearDate [ClearDate], '(' + n.USUserID + ') ' + pm2.LastName + ', ' + pm2.FirstName [UserID], n.USRemarks [ClearRemarks] from station..tbnursedischargenotice n left join patient_data..tbpatient p on n.IDNum = p.IDNum left join patient_data..tbmaster m on p.HospNum = m.HospNum left join build_file..tbcodoctor d on p.AttendingDr1 = d.DoctorID left join password..tbPasswordMaster pm1 on n.DischargeNurse = pm1.EmployeeID left join password..tbPasswordMaster pm2 on n.USUserID = pm2.EmployeeID where n.IDNum = @IDNum END IF @Department = 'CT' BEGIN select n.IDNum, p.HospNum, m.LastName, m.FirstName, m.MiddleName, p.RoomID, p.AdmDate, p.AttendingDr1, d.LastName + ', ' + d.FirstName + ' ' + d.MiddleName [Doctor], n.NoticeDate, n.OrderedDate, '(' + n.DischargeNurse + ') ' + pm1.LastName + ', ' + pm1.FirstName [DischargeNurse], n.Remarks, n.CTClearDate [ClearDate], '(' + n.CTUserID + ') ' + pm2.LastName + ', ' + pm2.FirstName [UserID], n.CTRemarks [ClearRemarks] from station..tbnursedischargenotice n left join patient_data..tbpatient p on n.IDNum = p.IDNum left join patient_data..tbmaster m on p.HospNum = m.HospNum left join build_file..tbcodoctor d on p.AttendingDr1 = d.DoctorID left join password..tbPasswordMaster pm1 on n.DischargeNurse = pm1.EmployeeID left join password..tbPasswordMaster pm2 on n.CTUserID = pm2.EmployeeID where n.IDNum = @IDNum END IF @Department = 'MM' BEGIN select n.IDNum, p.HospNum, m.LastName, m.FirstName, m.MiddleName, p.RoomID, p.AdmDate, p.AttendingDr1, d.LastName + ', ' + d.FirstName + ' ' + d.MiddleName [Doctor], n.NoticeDate, n.OrderedDate, '(' + n.DischargeNurse + ') ' + pm1.LastName + ', ' + pm1.FirstName [DischargeNurse], n.Remarks, n.MMClearDate [ClearDate], '(' + n.MMUserID + ') ' + pm2.LastName + ', ' + pm2.FirstName [UserID], n.MMRemarks [ClearRemarks] from station..tbnursedischargenotice n left join patient_data..tbpatient p on n.IDNum = p.IDNum left join patient_data..tbmaster m on p.HospNum = m.HospNum left join build_file..tbcodoctor d on p.AttendingDr1 = d.DoctorID left join password..tbPasswordMaster pm1 on n.DischargeNurse = pm1.EmployeeID left join password..tbPasswordMaster pm2 on n.MMUserID = pm2.EmployeeID where n.IDNum = @IDNum END IF @Department = 'EL' BEGIN select n.IDNum, p.HospNum, m.LastName, m.FirstName, m.MiddleName, p.RoomID, p.AdmDate, p.AttendingDr1, d.LastName + ', ' + d.FirstName + ' ' + d.MiddleName [Doctor], n.NoticeDate, n.OrderedDate, '(' + n.DischargeNurse + ') ' + pm1.LastName + ', ' + pm1.FirstName [DischargeNurse], n.Remarks, n.ELClearDate [ClearDate], '(' + n.ELUserID + ') ' + pm2.LastName + ', ' + pm2.FirstName [UserID], n.ELRemarks [ClearRemarks] from station..tbnursedischargenotice n left join patient_data..tbpatient p on n.IDNum = p.IDNum left join patient_data..tbmaster m on p.HospNum = m.HospNum left join build_file..tbcodoctor d on p.AttendingDr1 = d.DoctorID left join password..tbPasswordMaster pm1 on n.DischargeNurse = pm1.EmployeeID left join password..tbPasswordMaster pm2 on n.ELUserID = pm2.EmployeeID where n.IDNum = @IDNum END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_TransReport Script Date: 07/01/2000 1:20:57 AM ******/ CREATE PROCEDURE [dbo].[spRadio_TransReport_BackUp] @RevenueID AS varChar(2), @StartDate AS DateTime, @EndDate AS DateTime, @UserID as varchar(10) AS DELETE tbRadioTransReport WHERE UserID = @UserID; /* IF @RevenueID = 'US' BEGIN INSERT tbRadioTransReport SELECT RTRIM(tbULRequest.LastName) + ', ' + RTRIM(tbULRequest.FirstName) AS PatientName, tbULRequest.TypeDescription AS Description, (SELECT CASE tbULRequest.RoomID WHEN 'OPD' THEN OutBill.RefNum ELSE InBill.Refnum END) AS CSlip, (SELECT CASE tbULRequest.RoomID WHEN 'OPD' THEN (SELECT CASE LEFT(OutBill.RefNum, 2) WHEN 'OR' THEN CONVERT(varChar(12),tbULRequest.Amount) ELSE '' END) ELSE (SELECT CASE LEFT(InBill.RefNum, 2) WHEN 'OR' THEN CONVERT(varChar(12),tbULRequest.Amount) ELSE '' END) END) AS Cash, (SELECT CASE tbULRequest.RoomID WHEN 'OPD' THEN (SELECT CASE LEFT(OutBill.RefNum, 2) WHEN 'OR' THEN '' ELSE CONVERT(varChar(12),tbULRequest.Amount) END) ELSE (SELECT CASE LEFT(InBill.RefNum, 2) WHEN 'OR' THEN '' ELSE CONVERT(varChar(12),tbULRequest.Amount) END) END) AS Charge, @UserID FROM tbULRequest LEFT OUTER JOIN tbBillDailyBill InBill ON tbULRequest.IDNum = InBill.IDNum AND InBill.RevenueID = @RevenueID AND tbULRequest.Code = InBill.ItemID LEFT OUTER JOIN tbBillOPDailyOut OutBill ON tbULRequest.IDNum = OutBill.IDNum AND OutBill.RevenueID = @RevenueID AND tbULRequest.Code = OutBill.ItemID WHERE tbULRequest.TransDate BETWEEN @StartDate AND @EndDate +' 23:59:59' AND (tbULRequest.SwFin ='Y' or tbUlRequest.SwFin is NULL) ORDER BY PatientName END */ IF @RevenueID = 'CT' BEGIN INSERT tbRadioTransReport SELECT CASE WHEN ISNUMERIC(C.HospNum) = 1 THEN isnull(tbMaster.LastName, '') + ', ' + isnull(tbMaster.FirstName, '') ELSE tbCashPatient.LastName + ', ' + tbCashPatient.FirstName END AS PatientName, tbCoCTExam.CTExam AS Description, C.RefNum as CSlip, CASE WHEN LEFT(C.RefNum, 2) = 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Cash, CASE WHEN LEFT(C.RefNum, 2) <> 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Charge, @UserID FROM tbCTRequest C LEFT JOIN PATIENT_DATA..tbMaster tbMaster ON C.HospNum = tbMaster.HospNum LEFT JOIN PATIENT_DATA..tbCashPatient tbCashPatient ON C.HospNum = tbCashPatient.HospNum LEFT JOIN BUILD_FILE..tbCoCTExam tbCoCTExam ON C.Code = tbCoCTExam.CTExamID WHERE C.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND ISNULL(C.SwFin,'') <> 'C' ORDER BY PatientName END IF @RevenueID = 'US' BEGIN INSERT tbRadioTransReport SELECT CASE WHEN ISNUMERIC(C.HospNum) = 1 THEN tbMaster.LastName + ', ' + tbMaster.FirstName ELSE tbCashPatient.LastName + ', ' + tbCashPatient.FirstName END AS PatientName, tbCoUltraExam.UltraExam AS Description, C.RefNum as CSlip, CASE WHEN LEFT(C.RefNum, 2) = 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Cash, CASE WHEN LEFT(C.RefNum, 2) <> 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Charge, @UserID FROM tbUlRequest C LEFT JOIN PATIENT_DATA..tbMaster tbMaster ON C.HospNum = tbMaster.HospNum LEFT JOIN PATIENT_DATA..tbCashPatient tbCashPatient ON C.HospNum = tbCashPatient.HospNum LEFT JOIN BUILD_FILE..tbCoUltraExam tbCoUltraExam ON C.Code = tbCoUltraExam.UltraExamID WHERE C.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND ISNULL(C.SwFin,'') <> 'C' ORDER BY PatientName END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_AssessmentEntry] @Name AS varChar(60), @Transdate AS DateTime, @RevenueID as varchar(2), @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @RefNum AS varChar(10), @IdNum as varchar(10), @Hospnum as varchar(10), @RequestDocID as varchar(5), @DoctorName as varchar(50), @DepartmentID as varchar(2), @Gsis as varchar(1), @GsisNum as varchar(20) AS DECLARE @AssessmentNum AS varChar(10), @DrCr AS varChar(1), @AssessNum AS varChar(10) If @RequestDocID <> '0' Begin set @DoctorName = null; End IF @RevenueID = 'MD' BEGIN SET @DrCr = 'P' END ELSE BEGIN SET @DrCr = 'D' END /* Assessment Number */ SELECT @AssessmentNum = RTRIM(Convert(varChar(10), RequestNum)) FROM BILLING..tbAssessmentNum UPDATE BILLING..tbAssessmentNum SET RequestNum = RequestNum + 1 SET @AssessNum = 'AS' + RTRIM(@AssessmentNum) INSERT INTO BILLING..tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, RefNum, Amount, RevenueID, UserID, DepartmentID, Hospnum, RequestDocID, DoctorName, Gsis,GsisNumber) VALUES (@IdNum, @Name, GETDATE(), @AssessNum, @RevenueID, @DrCr, @ItemID, @Quantity, @RefNum, @Amount, @RevenueID, @UserID, @DepartmentID, @Hospnum, @RequestDocID, @DoctorName,@Gsis,@GsisNum) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_SearchCashPatient Script Date: 07/01/2000 1:20:49 AM ******/ CREATE PROCEDURE [dbo].[sp_NucSearchCashPatient] @strHospNum Varchar(8) AS select * from patient_data..tbCashPatient where hospnum=@strHospNum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_AssessmentReprint] @Refnum as varchar(12) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'MI' then x.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, A.Quantity from billing..tbcashassessment a left join build_file..tbcoOtherRevenue x on a.ItemID = x.OtherREvenueID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where A.Refnum = @Refnum order by a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadDischargeNotice] @DepartmentID varchar(10) AS SELECT tbpatient.hospnum as HospNum, (isnull(tbMaster.LastName,'') + ', ' + isnull(tbMaster.FirstName,'') + ' ' + isnull(left(tbMaster.MiddleName, 1) + '.','')) as PatientName, tbPatient.Idnum as Idnum, n.DischargeNurse, tbPatient.RoomID as RoomID, n.NoticeDate AS NoticeDate, n.BillingClerk AS BillingClerk, CASE WHEN @DepartmentID = 'XR' then XRClearDate WHEN @DepartmentID = 'US' then USClearDate WHEN @DepartmentID = 'CT' then CTClearDate WHEN @DepartmentID = 'MM' then MMClearDate WHEN @DepartmentID = 'EL' then ELClearDate ELSE null END ClearDate FROM Station..tbNurseDischargenotice n left outer join Patient_Data..tbPatient tbPatient on n.Idnum = TbPatient.Idnum left outer join Patient_Data..tbMaster tbMaster on Tbpatient.Hospnum = TbMaster.Hospnum Where BillingDate is Null and tbPatient.Hospnum is not null and isnull(n.recordstatus,'') = 'F' Order By ClearDate,NoticeDate, tbMaster.LastName, tbMaster.FirstName GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_NurseRequest] --@Type As varChar(1) AS /* Woman Center Request */ BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], c.OtherRevenueID as [ItemID] , C.otherRevenue as [ItemDesc], Case When R.RoomClassID = 'A' then cast(isnull(C.RateA,0)as money) When R.RoomClassID = 'B' then cast(isnull(C.RateB,0)as money) When R.RoomClassID = 'C' then cast(isnull(C.RateC,0)as money) When R.RoomClassID = 'D' then cast(isnull(C.RateD,0)as money) When R.RoomClassID = 'E' then cast(isnull(C.RateE,0)as money) End as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, D.RoomID, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left outer Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID --Left outer Join Build_file..tbcoOtherRevenue X on X.OtherRevenueID = A.ItemID and x.othersectionid = 'WC' Where (isnull(A.RecordStatus,'')='') and A.RevenueID in ('WC') and D.BillingDate is Null Union All Select Distinct D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.OtherRevenueID as [ItemID] , C.OtherRevenue as [ItemDesc], cast(isnull(c.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID, convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left Outer Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 --Left outer Join Build_file..tbcoOtherRevenue X on X.OtherRevenueID = A.ItemID and X.OthersectionID ='WC' Where (isnull(A.RecordStatus,'')='') and A.RevenueID IN ('WC') and D.BillingDate is Null Order By [Date Request], [LastName], [FirstName] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadExamEntry] @RevenueID varchar(2), @SearchCriteria varchar(50) AS if @RevenueID = 'XR' begin select e.XRayExamID [ExamID], e.XRayExam [Exam], e.XRaySectionID [SectionID], s.SectionName [Section], e.RateA, e.RateB, e.RateC, e.RateD, e.RateE, e.Status, e.Classification, IsNull(e.FixRate,'Y') as FixRate from BUILD_FILE..tbCoXrayExam e left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'XR') and (s.SectionID = e.XRaySectionID) where e.XrayExamID = @SearchCriteria end if @RevenueID = 'CT' begin select e.CTExamID [ExamID], e.CTExam [Exam], e.CTSectionID [SectionID], s.SectionName [Section], e.RateA, e.RateB, e.RateC, e.RateD, e.RateE, e.Status, e.Classification, IsNull(e.FixRate,'Y') as FixRate from BUILD_FILE..tbCoCTExam e left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'CT') and (s.SectionID = e.CTSectionID) where e.CTExamID = @SearchCriteria end if @RevenueID = 'US' begin select e.UltraExamID [ExamID], e.UltraExam [Exam], e.UltraSectionID [SectionID], s.SectionName [Section], e.RateA, e.RateB, e.RateC, e.RateD, e.RateE, e.Status, e.Classification, IsNull(e.FixRate,'Y') as FixRate from BUILD_FILE..tbCoUltraExam e left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'US') and (s.SectionID = e.UltraSectionID) where e.UltraExamID = @SearchCriteria end if @RevenueID = 'WC' begin select e.OtherRevenueID [ExamID], e.OtherRevenue [Exam], ''[SectionID], ''[Section], e.RateA, e.RateB, e.RateC, e.RateD, e.RateE, e.Status, ''Classification, IsNull(e.FixRate,'Y') as FixRate from BUILD_FILE..tbcoOtherRevenue e -- left join BUILD_FILE..tbCoSection s -- on (s.RevenueID = 'US') and (s.SectionID = e.UltraSectionID) where e.OtherRevenueID = @SearchCriteria end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_SearchOutPatient Script Date: 07/01/2000 1:20:49 AM ******/ /* By: mary ann gungon */ CREATE PROCEDURE [dbo].[sp_NucSearchOutPatient] @strIdNum Varchar(10) AS select * from patient_data..tbOutPatient where idnum=@strIdNum and (opdstatus <> 'R' or opdstatus is null) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* ALter by Jetty P. omo added out patient as a pending request for Prepaid Date : 01/22/2008 */ CREATE PROCEDURE [dbo].[spRadio_CheckPrepaidRequest] @RevenueID as varchar(10) AS --set @RevenueID = 'wC' Select top 1 A.HospNum, A.Idnum, B.LastName, B.FirstName, B.MiddleName, C.ItemID, C.Description, B.Chargeslip From Patient_Data..tbPatient A Left Outer Join Prepaid..tbPrepaidCharges B with (Index(tbPrepaidCharges_ItemID)) On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On B.ItemCode = C.ItemID and C.RevenueID = @RevenueID -- with (Index(B.tbPrepaidCharges_ItemCode)) Where (A.DcrDate is null or BillingDate is null) and B.RevenueID = @RevenueID and isnull(B.PrintStatus, 0) = 0 and isnull(B.Cancelled,0) <> 1 Union All Select top 1 A.HospNum, A.Idnum, B.LastName, B.FirstName, B.MiddleName, C.ItemID, C.Description, B.Chargeslip From Patient_Data..tboutPatient A Left Outer Join Prepaid..tbPrepaidCharges B with (Index(tbPrepaidCharges_ItemID)) On A.Idnum = B.Idnum Left Outer Join Billing..tbBillExamListing C On B.ItemCode = C.ItemID and C.RevenueID = @RevenueID Where (A.DcrDate is null or BillingDate is null) and B.RevenueID = @RevenueID and isnull(B.PrintStatus, 0) = 0 and isnull(B.Cancelled,0) <> 1 ; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_DoctorsCommisionReport] @StartDate as varchar(10), @EndDate as varchar(10) , @RevenueID as varchar(3) AS /* DECLARE @StartDate as varchar(10) DECLARE @EndDate as varchar(10) SET @StartDate ='04/01/2005' SET @EndDate ='04/30/2005' */ SELECT max(TransDate) as TransDate, IdNum, max(Patientname) as PatientName, AccountNum as AccountNum, isnull(max(Company),'PERSONAL') AS Company, ItemID, max(ExamName) as ExamName, DoctorId, isnull(max(Doctorname),'NOT SPECIFIED') as DoctorName, RefNum, sum(Amount) as Amount, PatientType, 'PAID' AS PayType FROM ( SELECT max(B.TransDate) as TransDate, B.IdNum, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, max(P.AccountNum) as AccountNum, max(C.Company) as Company, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, sum(B.Amount) as Amount, 'I' as PatientType FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN PATIENT_DATA..tbPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On P.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID group by B.refNum, B.itemId, B.IdNum, B.RequestDocID union all SELECT max(B.TransDate) as TransDate, B.IdNum, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, max(P.AccountNum) as AccountNum, max(C.Company) as Company, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, sum(B.Amount) as Amount, 'O' as PatientType FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN PATIENT_DATA..tbOutPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On P.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID and B.IdNum <> 'CASH' group by B.refNum, B.itemId, B.IdNum, B.RequestDocID ) A GROUP BY A.RefNum, A.ItemID, A.IdNum, A.DoctorID, A.AccountNum, A.PatientType having isnull( billing.dbo.fn_GetTotalReceivable(A.Idnum,A.AccountNum),0) = 0 and sum(A.amount) > 0 union all SELECT max(B.TransDate) as TransDate, B.CashIdNum as IdNum, isnull(max(O.paymentFrom),'CASH') as PatientName, '' as AccountNum, 'CASH' as Company, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, sum(B.Amount) as Amount, 'O' AS PatientType, 'PAID' AS PayType FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BILLING..tbCashORMaster O On B.refNum = O.refNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID and B.IdNum = 'CASH' group by B.refNum, B.itemId, B.CashIdNum, B.RequestDocID HAVING sum(b.amount) > 0 UNION ALL SELECT max(TransDate) as TransDate, IdNum, max(Patientname) as PatientName, AccountNum as AccountNum, isnull(max(Company),'PERSONAL') AS Company, ItemID, max(ExamName) as ExamName, DoctorId, isnull(max(Doctorname),'NOT SPECIFIED') as DoctorName, RefNum, sum(Amount) as Amount, PatientType, 'RECEIVABLE' AS PayType FROM ( SELECT max(B.TransDate) as TransDate, B.IdNum, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, max(P.AccountNum) as AccountNum, max(C.Company) as Company, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, sum(B.Amount) as Amount, 'I' as PatientType FROM BILLING..tbBillDailyBill B LEFT OUTER JOIN PATIENT_DATA..tbPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On P.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID group by B.refNum, B.itemId, B.IdNum, B.RequestDocID union all SELECT max(B.TransDate) as TransDate, B.IdNum, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, max(P.AccountNum) as AccountNum, max(C.Company) as Company, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, sum(B.Amount) as Amount, 'O' as PatientType FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN PATIENT_DATA..tbOutPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On P.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID and B.IdNum <> 'CASH' group by B.refNum, B.itemId, B.IdNum, B.RequestDocID ) A GROUP BY A.RefNum, A.ItemID, A.IdNum, A.DoctorID, A.AccountNum, A.PatientType having isnull( billing.dbo.fn_GetTotalReceivable(A.Idnum,A.AccountNum),0) <> 0 and sum(A.amount) > 0 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_AuditReport Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spMRI_AuditReport] @RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS DECLARE @StartDate datetime, @EndDate datetime SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) select b.refnum, sum(b.amount) as Amount, max(b.quantity) as Qty, max(b.itemid) as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(b.userid) as UserID, max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)IDNum, max(p.hospnum)HospNum, max(m.lastname) + ', ' + max(m.firstname) patient from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID group by B.Refnum, itemid having sum(b.amount) > 0 union all select max(b.refnum), sum(b.amount) as Amount, max(b.quantity), b.itemid, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(b.userid), max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum), max(p.hospnum), max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID group by B.Refnum, itemid having sum(b.amount) > 0 order by tRANSDATE GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_AssessmentStatus] @RevenueID varchar(2) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], case isnull(a.RevenueID,'') when 'MI' then x.OtherRevenue when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else i.itemname end as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, a.HospNum,a.IDNum,a.GSIS As DiscountType from billing..tbcashassessment a left join build_file..tbcoOtherRevenue x on a.ItemID = x.OtherRevenueID left join inventory..tbInvMaster i on a.itemid = i.itemid left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where a.revenueid = @RevenueID or a.DepartmentID = @RevenueID and (NOT isnull(a.RecordStatus, '') ='R') order by a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_CashUpdate] @Refnum as varchar(15), @ItemID as varchar(10) as update BILLING..TBCASHCOMMUNICATION set RecordStatus = 'Y' Where refnum = @Refnum and ItemID = @ItemID and revenueID ='MI' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_Search_FullCashPatient Script Date: 07/01/2000 1:20:47 AM ******/ CREATE PROCEDURE [dbo].[sp_NucSearch_FullCashPatient] @HospNum varchar(10) AS Select * From patient_data..tbCashPatient Where @HospNum = patient_data..tbCashPatient.HospNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_DoctorsCommisionPayment] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(3) AS /* DECLARE @StartDate as varchar(10) DECLARE @EndDate as varchar(10) SET @StartDate ='04/01/2005' SET @EndDate ='04/30/2005' */ select B.IdNum, A.AccountNum, isnull(max(A.Company),'PERSONAL') as Company, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, max(B.ORNumber) as ORNumber, sum(B.Amount) as Amount, max(B.TransDate) as TransDate, max(A.PaymentDate) as PaymentDate from BILLING..tbBillDailyBill B inner join (select B.IdNum, P.AccountNum, max(C.Company) as Company, max(Transdate) as PaymentDate, P.HospNum, b.RefNum as ORNumber from BILLING..tbBillDailyBill B LEFT OUTER JOIN PATIENT_DATA..tbPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company where revenueid = 'PP' AND B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' group by B.IdNum, P.AccountNum, P.HospNum, B.refNum having isnull( billing.dbo.fn_GetTotalReceivable(B.Idnum,P.AccountNum),0) = 0) A on B.IdNum = A.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On A.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID where B.RevenueID = @RevenueID GROUP BY B.IdNum, B.refNum, B.itemID, A.AccountNum, B.RequestDocID having sum(B.Amount) > 0 UNION ALL select B.IdNum, A.AccountNum, isnull(max(A.Company),'PERSONAL') as Company, max(M.Lastname) + ', ' + max(M.firstname) + ' ' + max(M.MiddleName) as PatientName, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, B.RefNum, max(B.ORNumber) as ORNumber, sum(B.Amount) as Amount, max(B.TransDate) as TransDate, max(A.PaymentDate) as PaymentDate from BILLING..tbBillOPDailyOut B inner join (select B.IdNum, P.AccountNum, max(C.Company) as Company, max(Transdate) as PaymentDate, P.HospNum, B.RefNum as ORNumber from BILLING..tbBillOPDailyOut B LEFT OUTER JOIN PATIENT_DATA..tbOutPatient P On B.IdNum = P.IdNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany C on P.AccountNum = C.Company where revenueid = 'PP' AND B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' group by B.IdNum, P.AccountNum, P.HospNum, B.RefNum having isnull( billing.dbo.fn_GetTotalReceivable(B.Idnum,P.AccountNum),0) = 0) A on B.IdNum = A.IdNum LEFT OUTER JOIN PATIENT_DATA..tbMaster M On A.HospNum = M.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID where B.RevenueID = @RevenueID and B.IdNum <> 'CASH' GROUP BY B.IdNum, B.refNum, B.itemID, A.AccountNum, B.RequestDocID having sum(B.Amount) > 0 UNION ALL SELECT b.CashIdNum as IdNum, '' AS AccountNum, 'CASH' AS Company, isnull(max(O.paymentFrom),'CASH') as PatientName, B.itemID, max(E.Description) as ExamName, B.RequestDocID as DoctorID, max(D.Lastname) + ', ' + max(D.Firstname) + ' ' + max(D.MiddleName) as DoctorName, max(B.Chargeslip) as RefNum, B.RefNum as OrNumber, sum(B.Amount) as Amount, max(B.TransDate) as TransDate, max(O.TransDate) as PaymentDate FROM BILLING..tbBillOPDailyOut B LEFT OUTER JOIN BILLING..tbCashORMaster O On B.refNum = O.refNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.RequestDocID = D.DoctorID LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID WHERE B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID = @RevenueID and B.IdNum = 'CASH' group by B.refNum, B.itemId, B.CashIdNum, B.RequestDocID HAVING sum(b.amount) > 0 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_CashAssessmentInfo] @Option as varchar(1), --1.Cash Patient, 2.RegularPatient, 3. ConfinedPatient @Option2 as varchar(1), --1. Search by Lastname, 2. Search by ID @Search as varchar(30) -- Search String AS /*Declare @Option as varchar(1); --Cash Patient Declare @Option2 as varchar(1); Declare @Search as varchar(30); set @Option = '1'; set @Option2 = '2'; set @Search = 'T82'; */ If @Option = '1' Begin If @Option2 = '1' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbCashPatient A Where Lastname Like @Search + '%' ; End; If @Option2 = 2 Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatusID From Patient_Data..tbCashPatient A Where HospNum = @Search; End; End; If @Option = '2' Begin If @Option2 = '1' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbMaster A Where Lastname Like @Search + '%' ; End; If @Option2 = '2' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatus as CivilStatusID From Patient_Data..tbMaster A Where HospNum = @Search; End; End; If @Option = '3' ---- IN Patient Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And DcrDate is null ; End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, C.RoomClassID as RoomClassID From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Left Outer Join Build_File..tbcoRoom C on A.RoomID = C.RoomID Where A.HospNum = @Search ---A.Idnum = @Search And DcrDate is null; End; End; If @Option = '4' ---- Out Patient Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And BillingDate is null And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.HospNum Where A.Hospnum = @Search --A.Idnum = @Search And BillingDate is null -- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; End; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[Get_Columns] @TableName AS VARCHAR(30) AS EXEC sp_Columns @TableName GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_ChargesbySlip Script Date: 07/01/2000 1:20:52 AM ******/ CREATE PROCEDURE [dbo].[spMRI_ChargesbySlip] @ChargeSlip varchar(10) = 0, --@Code varchar(10) = 0, @UserID varchar(10) = 0, @RevenueID varchar(2) = '' AS BEGIN delete REPORTS..tbChargeSlip where UserID = @UserID; END BEGIN insert into REPORTS..tbChargeSlip (Code, [Description], Price, Quantity, Amount, UserID) select b.itemid, max(case b.revenueid when 'MI' then e.OtherRevenue when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end) as description, sum(case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end) as price, sum(b.quantity), sum(b.amount), @UserID from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID and e.OtherSectionID='MI' left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and (b.revenueid = @revenueID or b.summarycode = @revenueid) group by b.ItemID having sum(b.Amount) <> 0 UNION ALL select b.itemid, max(case b.revenueid when 'MI' then e.OtherRevenue when 'MD' then 'DR. ' + d.lastname + ', ' + d.firstname end) as description, sum(case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end) as price, sum(b.quantity), sum(b.amount), @UserID from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID and e.OtherSectionID='MI' left join build_file..tbcodoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip and (b.revenueid = @revenueID or b.summarycode = @revenueid) group by b.ItemID having sum(b.Amount) <> 0 ; /* UNION ALL select s.ItemID, max(m.ItemName + ' ' + m.ItemDesc), sum(case when s.Quantity = 0 then 0 else s.Amount / s.Quantity end) Price, sum(s.Quantity), sum(s.Amount), @UserID from inventory..tbInvStockCard s left join inventory..tbInvMaster m on s.ItemID = m.ItemID where refnum = @ChargeSlip group by s.ItemID having sum(s.Amount) <> 0 ; */ END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_UpdateCash Script Date: 07/01/2000 1:20:49 AM ******/ /* by : mary ann gungon */ CREATE PROCEDURE [dbo].[sp_NucUpdateCash] @strOrNum Varchar(10), @strItemId Varchar(4), @strRevenueID Varchar(2), @strDepartmentID varchar(2) AS update billing..tbcashcommunication set recordstatus='Y' where refnum=@strOrNum and itemid=@strItemID and revenueid=@strRevenueID and departmentid = @strDepartmentID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadRequests] @Type varchar(1), @LastName varchar(50) AS IF @Type = '1' BEGIN select q.RequestNum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.ctexam [Exam], convert(varchar(10), q.transdate, 101) [Exam Date] from tbctrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoctexam e on q.code = e.ctexamid where isnull(q.swfin, '') = '' and (isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%') order by patient END IF @Type = '2' BEGIN select q.RequestNum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.xrayexam [Exam], convert(varchar(10), q.transdate, 101) [Exam Date] from tbxrrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoxrayexam e on q.code = e.xrayexamid where /*isnull(q.swfin, '') = ''*/ q.swfin = 'X' and ((isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%')) order by patient END IF @Type = '3' BEGIN select q.RequestNum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end Patient, e.ultraexam [Exam], convert(varchar(10), q.transdate, 101) [Exam Date] from tbulrequest q left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum left join tbcoultraexam e on q.code = e.ultraexamid where isnull(q.swfin, '') = '' and (isnull(m.lastname, '') like @LastName + '%' or isnull(c.lastname, '') like @LastName + '%') order by patient END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_NurseCommUpdate] @RequestNum varchar(10) AS UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spKidney_SearchPatient] @strMode as varchar(1), @strSearch as varchar(30) AS declare @DateToday as varchar(10) set @DateToday = convert(varchar(10),getdate(),101) if @strMode = 'I' -- For In-Patient begin select isnull(A.HospNum,'') [HospNum], isnull(A.IdNum,'') [IdNum], B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName [PatientName], isnull(cast(A.BillingDate as varchar), '') [BillingDate], case C.AskCashBasis when 0 then 'Charge Basis' when 1 then 'Cash Basis' end as [ChargingStatus], isnull(cast(A.DcrDate as varchar),'') [DcrDate] from Patient_Data..tbPatient A left outer join Patient_Data..tbMaster B on A.HospNum = B.HospNum left outer join Patient_Data..tbPatient2 C on A.IdNum = C.IdNum where (B.LastName like @strSearch + '%' or A.HospNum = @strSearch or A.IdNum = @strSearch) and A.BillingDate not between @DateToday and @DateToday + ' 23:59:59.99' and A.BillingDate is not null order by B.LastName, B.FirstName end; else if @strMode = 'O' -- For Out-Patient begin select isnull(A.HospNum,'') [HospNum], isnull(A.IdNum,'') [IdNum], B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName [PatientName], isnull(cast(A.BillingDate as varchar),'') [BillingDate], 'OPD', isnull(cast(A.dcrdate as varchar),'') [DcrDate] from Patient_Data..tbOutPatient A left outer join Patient_Data..tbMaster B on A.HospNum = B.HospNum where (B.LastName like @strSearch + '%' or A.HospNum = @strSearch or A.IdNum = @strSearch) and A.AdmDate not between @DateToday and @DateToday + ' 11:59:59.99' and A.BillingDate is not null order by B.LastName, B.FirstName end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_ExamStatistics] @RevenueID varchar(2), @StartDate varchar(10), @LastDate varchar(10) AS declare @BeginDate datetime, @EndDate datetime set @BeginDate = cast(@StartDate as datetime) set @EndDate = dateadd(day, 1, cast(@LastDate as datetime)) if @RevenueID = 'MI' begin select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.OtherRevenue [ExamName], a.amount, case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 end InpatientCount, case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 end OutpatientCount from ( select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid from billing..tbbilldailybill b left join vwMRIrequestmaster v on b.refnum = v.refnum left join patient_data..tbpatient p on b.idnum = p.idnum where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'MI' union all select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid from billing..tbbillopdailyout b left join vwMRIrequestmaster v on b.refnum = v.refnum left join patient_data..tboutpatient p on b.idnum = p.idnum where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'MI' ) as a left join build_file..tbcodoctor d on a.doctorid = d.doctorid left join build_file..tbcoOtherRevenue e on a.itemid = e.OtherRevenueID end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetHospitalNumber] @Idnum as Varchar(10) AS If isnumeric(@Idnum) = 1 Begin Select isnull(Hospnum, '') [HospNum] From Patient_data..tbPatient Where IdNum = @Idnum; End; Else Begin Select isnull(Hospnum , '') [HospNum] From Patient_Data..tbOutPatient Where IdNum = @Idnum; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_PARS_RepStatementOfAccountSummarized] @IDNum as varchar(10) AS /* declare @IDNum as varchar(10) set @IDNum = '539661' */ Declare @Billingdate as varchar(10) ----------------------OUT PATIENT----------------------------- IF isNumeric(@IDNum) = 0 BEGIN Set @BillingDate = (Select convert(varchar(10),BillingDate,101) from Patient_Data..tbOutPatient where IDNum = @IDNum) Select isnull(max(R.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Department as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..OPBillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where L.IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) Group by L.Department UNION ALL Select isnull(max(L.RevenueID),'') as RevenueID, isnull(max(L.LGRP),'') as Type, max(isnull(L.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then max(A.ItemName) When max(L.RevenueID) in ('DE','CP','PY','PP') Then max(Department) + ' (' + max(L.RefNum) + ')' else IsNull(LEFT(SP.Specification, 40), Department ) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..OPBillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode A on L.ItemID = A.RevenueID and L.RevenueID in ('GS','SS') Left Outer Join Billing..tbBillSpecialProceduresSpecification SP on SP.IDNum = L.IDNum and SP.RevenueID = L.RevenueID and SP.RefNum = L.RefNum and SP.RequestNum = L.RequestNum Where L.IDNum = @IDNum and L.DrCr <> 'P' and (L.TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) and L.RevenueID not in ('PH','PC','CS','CC', 'BB', 'TB') Group by L.Department, SP.Specification, A.RevenueID UNION ALL Select isnull(max(RevenueID),'') as RevenueID, isnull(max(LGRP),'') as Type, max(isnull(DrCr,'D')) as DrCr, Case When max(L.RevenueID) in ('DE','CP','PY','PP') Then max(L.Department) + ' (' + max(L.RefNum) + ')' else max(L.Department) end as Description , sum(Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money)) as Charges, Sum(Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money)) as Credit, max(D.Description) as PaymentType , Sum(Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money)) as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..OPBillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and L.DrCr = 'P' and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) and RevenueID not in ('PH','PC','CS','CC' , 'BB', 'TB') Group by ItemID Order by Description END ELSE ----------------------IN PATIENT----------------------------- BEGIN Set @BillingDate = (Select convert(varchar(10),BillingDate,101) from Patient_Data..tbPatient where IDNum = @IDNum) Select isnull(max(R.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, L.Department as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..BillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) Group by L.Department UNION ALL Select isnull(max(L.RevenueID),'') as RevenueID, isnull(max(L.LGRP),'') as Type, max(isnull(L.DrCr,'D')) as DrCr, LEFT(Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then max(A.ItemName) When max(L.RevenueID) in ('DE','CP','PY','PP') Then max(Department) + ' (' + max(L.RefNum) + ')' else IsNull( LEFT(SP.Specification, 40), Department ) end, 40) as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..BillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode A on L.ItemID = A.RevenueID and L.RevenueID in ('GS','SS') Left Outer Join Billing..tbBillSpecialProceduresSpecification SP on SP.IDNum = L.IDNum and SP.RevenueID = L.RevenueID and SP.RefNum = L.RefNum and SP.RequestNum = L.RequestNum Where L.IDNum = @IDNum and L.DrCr <> 'P' and (L.TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) and L.RevenueID not in ('PH','PC','CS','CC', 'BB', 'TB') Group by L.Department, SP.Specification, A.RevenueID UNION ALL Select isnull(max(RevenueID),'') as RevenueID, isnull(max(LGRP),'D') as Type, max(isnull(DrCr,'')) as DrCr, Case When max(L.RevenueID) in ('DE','CP','PY','PP') Then max(L.Department) + ' (' + max(L.RefNum) + ')' else max(L.Department) end as Description , sum(Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money)) as Charges, Sum(Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money)) as Credit, max(D.Description) as PaymentType , Sum(Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money)) as Discount, case when isdate(max(L.RefNum)) = 1 then '' else isnull(max(L.RefNum), '') end as RefNum from Billing..BillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) and RevenueID not in ('PH','PC','CS','CC', 'BB', 'TB') Group by ItemID Order by Description END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO -- Created by : FRIGILLANA, Rodney J. -- Date Updated : 12 August, 2002 CREATE PROCEDURE [dbo].[spRadio_NurseRequestPrinted] @IDNum AS varChar(10), @RevenueID AS varChar(2) AS UPDATE STATION..tbNurseLogBook SET RecordStatus = 'P' WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND RecordStatus = 'X'; UPDATE STATION..tbNurseCommunicationFile SET RecordStatus = 'P' WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND RecordStatus = 'X'; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Radio_UpdateCashCommunicationFile] @RefNum as varchar(15), @Revenueid as varchar(10) AS update billing..tbCashAssessCommunication set recordStatus = 'X' where refNum = @refNum and (revenueid = @Revenueid or departmentid = @Revenueid); GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_GSISReport] @StartDate as varchar(10), @EndDate as varchar(10) AS Select P.IDNum as IDNUm, max(P.HospNum) as HospNum , max(P.AdmDate) as AdmDate , max(P.DcrDate) as DcrDate , sum(Case when not R.LGRP in ( 'L', 'S', 'D') then cast(isnull(case L.DrCr when 'D' then isnull(L.Amount,0) else 0 end,0) as money) - cast(isnull(case L.DrCr when 'C' then isnull(L.Amount,0) else 0 end,0) as money) else 0 end) as HospitalBill, sum(Cast( Case when R.LGRP = 'D' and L.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(L.Amount,0) else 0 end as money)) as GSISDiscount , max(L.Revenueid) as RevenueID, Max(M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName ) as PxName, 'O' as PatientType From Billing..tbBillOPDailyOut L Left JOIN Patient_Data..tbOutPatient P on P.IDNum = L.IDNum LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID Left outer Join Patient_Data..tbMaster M On P.HospNum = M.HospNum Where L.Idnum in(Select A.Idnum from Billing..tbBillOPdailyOut A Inner join patient_data..tbOutPatient B on A.Idnum = b.Idnum and RevenueID ='MI' Where B.admdate between @StartDate and @EndDate + ' 23:59:59.99') and L.RevenueID in('MI','G1', 'G2', 'G3', 'G4', 'G5', 'G6') group by P.Idnum Union All Select P.IDNum as IDNUm, max(P.HospNum) as HospNum , max(P.AdmDate) as AdmDate , max(P.DcrDate) as DcrDate , sum(Case when not R.LGRP in ( 'L', 'S', 'D') then cast(isnull(case L.DrCr when 'D' then isnull(L.Amount,0) else 0 end,0) as money) - cast(isnull(case L.DrCr when 'C' then isnull(L.Amount,0) else 0 end,0) as money) else 0 end) as HospitalBill, sum(Cast( Case when R.LGRP = 'D' and L.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(L.Amount,0) else 0 end as money)) as GSISDiscount , max(L.Revenueid)as RevenueID, Max(M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName ) as PxName, 'I' as PatientType From Billing..tbBillDailyBill L Left JOIN Patient_Data..tbPatient P on P.IDNum = L.IDNum LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID Left Join Patient_Data..tbMaster M On P.HospNum = M.HospNum Where L.Idnum in(Select A.Idnum from Billing..tbBilldailybill A Inner join patient_data..tbPatient B on A.Idnum = b.Idnum and RevenueID ='MI' Where B.admdate between @StartDate and @EndDate + ' 23:59:59.99') and L.RevenueID in('MI','G1', 'G2', 'G3', 'G4', 'G5', 'G6') group by P.Idnum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CashPatientListing] @Option as varchar(1), --1.Cash Patient, 2.RegularPatient, 3. ConfinedPatient, 4. OutPatient @Option2 as varchar(1), --1. Search by Lastname, 2. Search by ID @Search as varchar(30) -- Search String AS If @Option = '1' Begin If @Option2 = '1' Begin Select HospNum [IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbCashPatient A Where Lastname Like @Search + '%' ; End; If @Option2 = 2 Begin Select HospNum [IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatusID, Age, 'OPD' as RoomID From Patient_Data..tbCashPatient A Where HospNum = @Search; End; End; If @Option = '2' Begin If @Option2 = '1' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbMaster A Where Lastname Like @Search + '%' ; End; If @Option2 = '2' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatus as CivilStatusID, Age, 'OPD' as RoomID From Patient_Data..tbMaster A Where HospNum = @Search; End; End; If @Option = '3' Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And DcrDate is null ; End; If @Option2 = 2 Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, B.Age, A.RoomID From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where A.IDnum = @Search And DcrDate is null; End; End; If @Option = '4' ---- Out Patient Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And BillingDate is null And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; If @Option2 = 2 Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, B.Age, 'OPD' as RoomID From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where A.IDnum = @Search And BillingDate is null -- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; End; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO -- Created by : FRIGILLANA, Rodney J. -- Date Updated : 12 August, 2002 CREATE PROCEDURE [dbo].[spRadio_NurseRequestCharged] @Type AS varchar(1), @RevenueID AS varchar(2) AS IF @Type = '1' BEGIN SELECT DISTINCT A.*, B.Lastname, B.Firstname, B.Middlename, B.Age, B.Sex, CONVERT(varChar(10), B.BirthDate, 101) AS BirthDate, B.HouseStreet, B.Barangay, C.Town, C.Province, B.TelNum, D.RoomID, E.Lastname AS DrLast, E.Firstname AS DrFirst, E.Middlename AS DrMiddle, F.Lastname AS NLast, F.Firstname AS NFirst, G.PatientClass FROM STATION..tbNurseLogBook A LEFT OUTER JOIN Patient_Data..tbMaster B ON A.Hospnum = B.Hospnum LEFT OUTER JOIN Build_File..tbCoAddress C ON B.ZipCode = C.ZipCode LEFT OUTER JOIN Patient_Data..tbPatient D ON A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoDoctor E ON D.AttendingDr1 = E.DoctorID LEFT OUTER JOIN [Password]..tbPasswordMain F ON A.UserID = F.EmployeeID LEFT OUTER JOIN Patient_Data..tbPatient2 G ON A.IDNum = G.IDNum WHERE /*CONVERT(varChar(10), A.Requestdate,101) = CONVERT(varChar(10), GetDate(),101) AND*/ (A.RecordStatus = 'X' AND NOT ISNULL(A.StationID, '') = '') AND A.Revenueid = @RevenueID ; END IF @Type = '2' BEGIN SELECT DISTINCT A.HospNum, A.IDNum, B.Lastname, B.Firstname, B.Middlename, A.[Description], CONVERT(varChar(10), A.RequestDate, 101) AS RequestDate, A.Quantity, A.Amount, B.Age, B.Sex, CONVERT(varChar(10), B.BirthDate, 101) AS BirthDate, B.HouseStreet, B.Barangay, C.Town, C.Province, B.TelNum, D.RoomID, E.Lastname AS DrLast, E.Firstname AS DrFirst, E.Middlename AS DrMiddle, A.RecordStatus, A.UserID, A.StationID, A.Remarks, A.RequestNum, A.ReferenceNum, A.UserID, F.Lastname AS NLast, F.Firstname AS NFirst, G.PatientClass FROM STATION..tbNurseLogBook A LEFT OUTER JOIN Patient_Data..tbMaster B ON A.Hospnum = B.Hospnum LEFT OUTER JOIN Build_File..tbCoAddress C ON B.ZipCode = C.ZipCode LEFT OUTER JOIN Patient_Data..tbPatient D ON A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoDoctor E ON D.AttendingDr1 = E.DoctorID LEFT OUTER JOIN [Password]..tbPasswordMain F ON A.UserID = F.EmployeeID LEFT OUTER JOIN Patient_Data..tbPatient2 G ON A.IDNum = G.IDNum WHERE CONVERT(varChar(10), A.Requestdate,101) BETWEEN CONVERT(varChar(10), GetDate()-1,101) AND CONVERT(varChar(10), GetDate(),101) AND (A.RecordStatus = 'P' AND NOT ISNULL(A.StationID, '') = '') AND A.Revenueid = @RevenueID ; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_NursingRequest Script Date: 07/01/2000 1:20:55 AM ******/ CREATE PROCEDURE [dbo].[spRadio_NursingRequest] @Type As varChar(1) AS IF @Type = '1' /* CT-Scan Request */ BEGIN SELECT DISTINCT tbNurseCommunicationFile.Hospnum AS HospNum, tbNurseCommunicationFile.IDnum AS IDNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbNurseCommunicationFile.ItemID AS ItemID, tbCoCTExam.CtExam AS ItemDesc, tbNurseCommunicationFile.Amount AS Amount, tbNurseCommunicationFile.RequestDate AS RequestDate, tbMaster.HouseStreet AS HouseStreet, tbMaster.Barangay AS Barangay, tbCoAddress.Town + ', ' + tbCoAddress.Province AS Town, tbMaster.Sex AS Sex, tbMaster.CivilStatus AS CivilStatus, tbMaster.BirthDate AS Birthdate, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbPatient.RoomID AS RoomID, tbPatient.AttendingDr1 + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS DrName FROM tbNurseCommunicationFile LEFT OUTER JOIN tbMaster ON tbNurseCommunicationFile.Hospnum = tbMaster.HospNum LEFT OUTER JOIN tbPatient ON tbNurseCommunicationFile.IDnum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbPatient.AttendingDr1 = tbCoDoctor.DoctorID LEFT OUTER JOIN tbCoCTExam ON tbNurseCommunicationFile.ItemID = tbCoCTExam.CtExamID LEFT OUTER JOIN tbCoAddress ON tbMaster.ZipCode = tbCoAddress.ZipCode WHERE tbNurseCommunicationFile.RevenueID = 'CT' AND tbNurseCommunicationFile.RecordStatus = '' END IF @Type = '2' /* XRay Request */ BEGIN SELECT DISTINCT tbNurseCommunicationFile.Hospnum AS HospNum, tbNurseCommunicationFile.IDnum AS IDNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbNurseCommunicationFile.ItemID AS ItemID, tbCoXrayExam.XrayExam AS ItemDesc, tbNurseCommunicationFile.Amount AS Amount, tbNurseCommunicationFile.RequestDate AS RequestDate, tbMaster.HouseStreet AS HouseStreet, tbMaster.Barangay AS Barangay, tbCoAddress.Town + ', ' + tbCoAddress.Province AS Town, tbMaster.Sex AS Sex, tbMaster.CivilStatus AS CivilStatus, tbMaster.BirthDate AS Birthdate, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbPatient.RoomID AS RoomID, tbPatient.AttendingDr1 + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS DrName FROM tbNurseCommunicationFile LEFT OUTER JOIN tbMaster ON tbNurseCommunicationFile.Hospnum = tbMaster.HospNum LEFT OUTER JOIN tbPatient ON tbNurseCommunicationFile.IDnum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbPatient.AttendingDr1 = tbCoDoctor.DoctorID LEFT OUTER JOIN tbCoXrayExam ON tbNurseCommunicationFile.ItemID = tbCoXrayExam.XrayExamID LEFT OUTER JOIN tbCoAddress ON tbMaster.ZipCode = tbCoAddress.ZipCode WHERE tbNurseCommunicationFile.RevenueID = 'XR' AND tbNurseCommunicationFile.RecordStatus = '' END IF @Type = '3' /* Ultrasound Request */ BEGIN SELECT DISTINCT tbNurseCommunicationFile.Hospnum AS HospNum, tbNurseCommunicationFile.IDnum AS IDNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbNurseCommunicationFile.ItemID AS ItemID, tbCoUltraExam.UltraExam AS ItemDesc, tbNurseCommunicationFile.Amount AS Amount, tbNurseCommunicationFile.RequestDate AS RequestDate, tbMaster.HouseStreet AS HouseStreet, tbMaster.Barangay AS Barangay, tbCoAddress.Town + ', ' + tbCoAddress.Province AS Town, tbMaster.Sex AS Sex, tbMaster.CivilStatus AS CivilStatus, tbMaster.BirthDate AS Birthdate, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbPatient.RoomID AS RoomID, tbPatient.AttendingDr1 + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS DrName FROM tbNurseCommunicationFile LEFT OUTER JOIN tbMaster ON tbNurseCommunicationFile.Hospnum = tbMaster.HospNum LEFT OUTER JOIN tbPatient ON tbNurseCommunicationFile.IDnum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbPatient.AttendingDr1 = tbCoDoctor.DoctorID LEFT OUTER JOIN tbCoUltraExam ON tbNurseCommunicationFile.ItemID = tbCoUltraExam.UltraExamID LEFT OUTER JOIN tbCoAddress ON tbMaster.ZipCode = tbCoAddress.ZipCode WHERE tbNurseCommunicationFile.RevenueID = 'US' AND tbNurseCommunicationFile.RecordStatus = '' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_BilledPatients] @SearchCriteria as varchar(50) AS /* declare @SearchCriteria as varchar(50) set @SearchCriteria = 'laba, a' */ declare @Lastname as varchar(30) declare @Firstname as varchar(30) declare @MiddleName as varchar(30) declare @Length as integer Set @FirstName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@SearchCriteria,',') where code = 2); Set @LastName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@SearchCriteria,',') where code = 1); Set @MiddleName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@SearchCriteria,',') where code = 3); set @Length = (select len(rtrim(ltrim(@SearchCriteria)))) if isnumeric(@SearchCriteria) = 1 or (right(rtrim(@SearchCriteria),1) = 'B' and isnumeric(left(@SearchCriteria,@length-1))=1) begin select m.hospnum, pm.Idnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, p.roomid, p.admdate, p.dcrdate, p.billingdate, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province, isnull(C.Company,'') as Company, isnull(C.Class,'') as CompanyClassID, isnull(m.bloodtype,'') as BloodType, isnull(D.DoctorID,'') as DoctorID, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') + ' ' + isnull(D.Middlename,'') as DoctorName from patient_data..tbMaster m inner join billing..tbparsMaster PM on m.HospNum = PM.HospNum inner join patient_data..tbPatient p on pm.Idnum = p.IdNum left join build_file..tbcoaddress a on m.zipcode = a.zipcode left join build_file..tbCoCompany C on p.AccountNum = C.AccountNum left join build_File..tbCoDoctor D on p.AttendingDr1 = D.DoctorID where p.billingdate is not Null and pm.IdNum = @SearchCriteria and isnull(PM.InvoiceNumber,'') = '' union all select m.hospnum, pm.Idnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, 'OPD' as roomid, p.admdate, p.dcrdate, p.billingdate, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province, isnull(C.Company,'') as Company, isnull(C.Class,'') as CompanyClassID, isnull(m.bloodtype,'') as BloodType, isnull(D.DoctorID,'') as DoctorID, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') + ' ' + isnull(D.Middlename,'') as DoctorName from patient_data..tbMaster m inner join billing..tbparsMaster PM on m.HospNum = PM.HospNum inner join patient_data..tbOutPatient p on pm.IdNum = p.idnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode left join build_file..tbCoCompany C on p.AccountNum = C.AccountNum left join build_File..tbCoDoctor D on p.DoctorID1 = D.DoctorID where p.billingdate is not Null and p.IdNum = @SearchCriteria and isnull(PM.InvoiceNumber,'') = '' order by lastname, firstname, middlename end; else begin select m.hospnum, pm.Idnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, p.roomid, p.admdate, p.dcrdate, p.billingdate, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province, isnull(C.Company,'') as Company, isnull(C.Class,'') as CompanyClassID, isnull(m.bloodtype,'') as BloodType, isnull(D.DoctorID,'') as DoctorID, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') + ' ' + isnull(D.Middlename,'') as DoctorName from patient_data..tbMaster m inner join billing..tbparsMaster PM on m.HospNum = PM.HospNum inner join patient_data..tbPatient p on pm.idnum = p.idnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode left join build_file..tbCoCompany C on p.AccountNum = C.AccountNum left join build_File..tbCoDoctor D on p.AttendingDr1 = D.DoctorID where p.billingdate is not Null and (m.lastname like @LastName + '%' and m.Firstname like isnull(@FirstName,'') + '%' and m.Middlename like isnull(@MiddleName,'') + '%' ) and isnull(PM.InvoiceNumber,'') = '' union all select m.hospnum, p.Idnum, isnull(m.lastname, '') lastname, isnull(m.firstname, '') firstname, isnull(m.middlename, '') middlename, 'OPD' as roomid, p.admdate, p.dcrdate, p.billingdate, m.civilstatus [civilstatus], m.sex, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar(10), m.birthdate, 101) end as birthdate, case when m.birthdate is null then m.age when m.birthdate <= '01/01/1900' then m.age else cast(datediff(year, m.birthdate, getdate()) as varchar(3)) end as age, m.housestreet, m.barangay, a.town, a.province, isnull(C.Company,'') as Company, isnull(C.Class,'') as CompanyClassID, isnull(m.bloodtype,'') as BloodType, isnull(D.DoctorID,'') as DoctorID, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') + ' ' + isnull(D.Middlename,'') as DoctorName from patient_data..tbMaster m inner join billing..tbparsMaster PM on m.HospNum = PM.HospNum inner join patient_data..tbOutPatient p on pm.idnum = p.idnum left join build_file..tbcoaddress a on m.zipcode = a.zipcode left join build_file..tbCoCompany C on p.AccountNum = C.AccountNum left join build_File..tbCoDoctor D on p.DoctorID1 = D.DoctorID where p.billingdate is not Null and (m.lastname like @LastName + '%' and m.Firstname like isnull(@FirstName,'') + '%' and m.Middlename like isnull(@MiddleName,'') + '%' ) and isnull(PM.InvoiceNumber,'') = '' order by lastname, firstname, middlename end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_OPDExams] @RefNum varchar(8), @DeptNo int AS if @deptno = '1' begin Select C.ItemID [Exam Code], X.CTExam [Description], C.Amount, '' [Films] from tbCashCommunication C left join tbCoCTExam X on C.ItemID = X.CTExamID where C.RecordStatus is null and C.RefNum = @RefNum and C.RevenueID = 'CT' end else if @deptno = '2' begin Select C.ItemID [Exam Code], X.XRayExam [Description], C.Amount, '' [Films] from tbCashCommunication C left join tbCoXRayExam X on C.ItemID = X.XRayExamID where C.RecordStatus is null and C.RefNum = @RefNum and C.RevenueID = 'XR' end else if @deptno = '3' begin Select C.ItemID [Exam Code], X.UltraExam [Description], C.Amount, '' [Films] from tbCashCommunication C left join tbCoUltraExam X on C.ItemID = X.UltraExamID where C.RecordStatus is null and C.RefNum = @RefNum and C.RevenueID = 'US' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_DR_AssessmentStatus] @IDNum As Varchar(10) AS Declare @DateToDay as varchar(10); set @DateToDay = Convert(varchar(10),GetDate(),101); select DISTINCT a.assessid [TransNum], a.[Name] [Patient Name], a.Revenueid [RevenueID],a.ItemID [Code], r.otherrevenue as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], /* Add New Fields*/ isnull(b.Lastname,'') + ' ,' + isnull(b.Firstname,'') + ' ' + isnull(b.Middlename,'') AS [Requesting Nurse], CONVERT(varchar(10), a.TransDate, 101) AS [Date],'' AS Shift, case isnull(a.RecordStatus, '') when '' then 'Pending'--CONVERT(varchar(10), a.TransDate, 101) when '1' then 'Given'--a.ORNumber + ' (' + convert(varchar(10), Communication.TransDate, 101) + ')' when 'R' then 'REVOKED' end as Status from billing..tbcashassessment a left join build_file..tbcootherrevenue r on a.ItemID = r.otherrevenueID and r.othersectionid = a.revenueid left join (select RefNum, Max(TransDate) [TransDate] from billing..tbCashCommunication group by RefNum ) as Communication on a.ORNumber = Communication.RefNum left outer join password..tbPasswordMain b On a.userid = b.employeeid where a.DepartmentID = 'DR' and (Communication.TransDate Between @DateToDay and @DateToDay + ' 23:59:59' or Communication.TransDate is null) and a.IdNum = @IDNum and a.revenueid in(Select revenueid from build_file..tbcorevenuecode where DRactive='Y' and isnull(locationid,'') = '') UNION ALL /*------ ER Supplies/Medicines ------*/ select DISTINCT a.assessid [TransNum], a.[Name] [Patient Name], a.Revenueid [RevenueID],a.ItemID [Code], r.ItemName as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], /* Add New Fields*/ isnull(b.Lastname,'') + ' ,' + isnull(b.Firstname,'') + ' ' + isnull(b.Middlename,'') AS [Requesting Nurse], CONVERT(varchar(10), a.TransDate, 101) AS [Date],'' AS Shift, case isnull(a.RecordStatus, '') when '' then 'Pending'--CONVERT(varchar(10), a.TransDate, 101) when '1' then 'Given'--a.ORNumber + ' (' + convert(varchar(10), Communication.TransDate, 101) + ')' when 'R' then 'REVOKED' end as Status from billing..tbcashassessment a left join inventory..tbInvMaster r on a.ItemID = r.itemID left join (select RefNum, Max(TransDate) [TransDate] from billing..tbCashCommunication group by RefNum ) as Communication on a.ORNumber = Communication.RefNum left outer join password..tbPasswordMain b On a.userid = b.employeeid where a.DepartmentID = 'DR' and (Communication.TransDate Between @DateToDay and @DateToDay + ' 23:59:59' or Communication.TransDate is null) and a.IdNum = @IDNum and a.revenueid in (Select revenueid from build_file..tbcorevenuecode where DRactive='Y' and isnull(locationid,'') <> '') --update by BSL 01/21/2005 order by [Date]; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Radio_SaveCashBill] @strIdNum Varchar(10), @strTransDate Varchar(25), @strRefNum Varchar(10), @strItemID Varchar(5), @strAmount Varchar(15), @strRevenueID Varchar(4), @strUserID Varchar(8), @Quantity float, @SummaryCode varchar(2), @DrCr varchar(1), @HospNum varchar(10) AS If isnumeric(@strIdNum) = 1 begin insert into Billing..tbBillDailyBill (IdNum,TransDate,RevenueID,DrCr,ItemID,RefNum,Amount,UserID,Quantity,SummaryCode) values (@strIdNum,@strTransDate,@strRevenueID,@DrCr,@strItemID,@strRefNum,cast(@strAmount as money),@strUserID,@Quantity,@SummaryCode) end else begin insert into Billing..tbBillOPDailyOut (IdNum,TransDate,RevenueID,DrCr,ItemID,RefNum,Amount,UserID,Quantity,SummaryCode, HospNum) values (@strIdNum,Getdate(),@strRevenueID,@DrCr,@strItemID,@strRefNum,cast(@strAmount as money),@strUserID,@Quantity,@SummaryCode, @HospNum) end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AssessmentReprint] @Refnum as varchar(12) AS select a.assessnum [TransNum], a.[Name] [Patient Name], a.ItemID [Code], ISNULL(case a.RevenueID when 'XR' then x.XRayExam when 'CT' then c.CTExam when 'US' then u.UltraExam when 'MD' then 'DR. ' + LEFT(d.FirstName,1) + '. ' + d.LastName else a.RevenueID end, a.RevenueID) as Description, a.RefNum [Assess #], cast(a.Amount as numeric(12,2)) [Amount], case isnull(a.RecordStatus, '') when '' then CONVERT(varchar(10), a.TransDate, 101) when '1' then a.ORNumber when 'R' then 'REVOKED' end as Status, a.RevenueID, A.Quantity from billing..tbcashassessment a left join build_file..tbCoXRayExam x on a.ItemID = x.XRayExamID left join build_file..tbCoCTExam c on a.ItemID = c.CTExamID left join build_file..tbCoUltraExam u on a.ItemID = u.UltraExamID left join build_file..tbCoDoctor d on a.ItemID = d.DoctorID where A.Refnum = @Refnum order by a.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_StatisticalReport] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2), @Miscellaneous as varchar(1) AS select (convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], (case @RevenueID when 'CT' then C.CtExam when 'XR' then E.XrayExam when 'US' then U.UltraExam end) as Exam, (case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_In, 0 as TotalTest_Out, Amount as Amount_In, 0 as Amount_Out from BILLING..tbBillDailyBill B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoCTExam C on B.ItemID = C.CTExamID left outer join BUILD_FILE..tbCoUltraExam U on B.ItemID = U.UltraExamID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID union all select (convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], (case @RevenueID when 'CT' then C.CtExam when 'XR' then E.XrayExam when 'US' then U.UltraExam end) as Exam, 0 as TotalTest_In, (case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_Out, 0 as Amount_In, Amount as Amount_Out from BILLING..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoCTExam C on B.ItemID = C.CTExamID left outer join BUILD_FILE..tbCoUltraExam U on B.ItemID = U.UltraExamID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID /*Declare @StartDate as varchar(10); Declare @EndDate as varchar(10); Declare @RevenueID as varchar(2); Declare @Miscellaneous as varchar(1); set @StartDate = '03/10/2003'; set @EndDate = '03/10/2003'; set @RevenueID = 'XR'; set @Miscellaneous = 'N'; */ /* select max(convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], max(case @RevenueID when 'CT' then C.CtExam when 'XR' then E.XrayExam when 'US' then U.UltraExam end) as Exam, sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_In, 0 as TotalTest_Out, sum(Amount) as Amount_In, 0 as Amount_Out from BILLING..tbBillDailyBill B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoCTExam C on B.ItemID = C.CTExamID left outer join BUILD_FILE..tbCoUltraExam U on B.ItemID = U.UltraExamID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID group by b.refnum having sum(cast(isnull(Amount,0) as Money)) <> 0 union all select max(convert(varchar(10),B.Transdate,101)) AS Transdate, @RevenueID as RevenueId, 'MISC' AS [Section], max(case @RevenueID when 'CT' then C.CtExam when 'XR' then E.XrayExam when 'US' then U.UltraExam end) as Exam, 0 as TotalTest_In, sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as TotalTest_Out, 0 as Amount_In, sum(Amount) as Amount_Out from BILLING..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoCTExam C on B.ItemID = C.CTExamID left outer join BUILD_FILE..tbCoUltraExam U on B.ItemID = U.UltraExamID Where B.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and B.RevenueID= @RevenueID group by b.refnum having sum(cast(isnull(Amount,0) as Money)) <> 0 */ /* select max(TransDate) TransDate, @RevenueID, [Section], Exam, isnull(Sum(Case When Type = 'I' then ExamCount else 0 End),0) as TotalTest_In, isnull(Sum(Case When Type = 'O' then ExamCount else 0 End),0) as TotalTest_Out, isnull(Sum(Case When Type = 'I' then Amount else 0 End),0) as Amount_In, isnull(Sum(Case When Type = 'O' then Amount else 0 End),0) as Amount_Out from ( Select Max(CASE WHEN (B.RevenueID = 'PT' or B.RevenueID = 'US' or B.RevenueID = 'AU' or B.RevenueID = 'NU' or B.RevenueID = 'HS' or B.RevenueID = 'LB' or B.RevenueID = 'CT' or B.RevenueID = 'XR' or B.RevenueID = 'PA' or B.RevenueID = 'CT' or B.RevenueID = 'EL' or B.RevenueID = 'SS' or B.RevenueID = 'BA' or B.RevenueID = 'BB' or B.RevenueID = 'GS') THEN D .Description WHEN R.DrCr = 'P' THEN 'Dr. ' + isnull(Doctor.FirstName,'') + ' ' + isnull(Doctor.MiddleName,'') + ' ' + isnull(Doctor.LastName,'') + ' ' + isnull(Doctor.Clnic,'') WHEN R.Rwith = 'Y' then D.Description ELSE R.ItemName END) as Exam, isnull(S.SectionName,'MISCELLANEOUS') as [Section], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as examcount, sum(cast(isnull(B.Amount,0) as Money)) as Amount, 'I' as Type, max(Convert(varchar(10),B.TransDate, 101)) as TransDate from BILLING..tbBillDailyBill B LEFT OUTER JOIN Billing..tbBillExamListing D ON B.ItemID = D.ItemID AND B.RevenueID = D.RevenueID LEFT OUTER JOIN Build_File..tbCoRevenueCode R ON B.RevenueID = R.RevenueID LEFT OUTER JOIN Build_File..tbCoDoctor Doctor ON Doctor.DoctorID = B.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoSection s on D.Sectionid = S.Sectionid and S.RevenueID = @RevenueID Where refnum in (Select refnum from Billing..tbBillDailyBill where revenueid = @RevenueID group by refnum having sum(cast(isnull(Amount,0) as Money)) <> 0) and (B.TransDate between @StartDate and @EndDate + ' 23:59:59.99') and B.RevenueID = @RevenueID Group by B.ItemID, S.SectionName UNION ALL Select Max(CASE WHEN (B.RevenueID = 'PT' or B.RevenueID = 'US' or B.RevenueID = 'AU' or B.RevenueID = 'NU' or B.RevenueID = 'HS' or B.RevenueID = 'LB' or B.RevenueID = 'CT' or B.RevenueID = 'XR' or B.RevenueID = 'PA' or B.RevenueID = 'CT' or B.RevenueID = 'EL' or B.RevenueID = 'SS' or B.RevenueID = 'BA' or B.RevenueID = 'BB' or B.RevenueID = 'GS') THEN D .Description WHEN R.DrCr = 'P' THEN 'Dr. ' + isnull(Doctor.FirstName,'') + ' ' + isnull(Doctor.MiddleName,'') + ' ' + isnull(Doctor.LastName,'') + ' ' + isnull(Doctor.Clnic,'') WHEN R.Rwith = 'Y' then D.Description ELSE R.ItemName END) as Exam, isnull(S.SectionName,'MISCELLANEOUS') as [Section], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as examcount, sum(cast(isnull(B.Amount,0) as Money)) as Amount, Case When Max(B.CashType) = 'I' then 'I' Else 'O' End as Type, max(Convert(varchar(10),B.TransDate, 101)) as TransDate from BILLING..tbBillOpDailyOut B LEFT OUTER JOIN Billing..tbBillExamListing D ON B.ItemID = D.ItemID AND B.RevenueID = D.RevenueID LEFT OUTER JOIN Build_File..tbCoRevenueCode R ON B.RevenueID = R.RevenueID LEFT OUTER JOIN Build_File..tbCoDoctor Doctor ON Doctor.DoctorID = B.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoSection s on D.Sectionid = S.Sectionid and S.RevenueID = @RevenueID Where refnum in (Select refnum from Billing..tbBillOpDailyOut where revenueid = @RevenueID group by refnum having sum(cast(isnull(Amount,0) as Money)) <> 0) and (B.TransDate between @StartDate and @EndDate + ' 23:59:59.99') and B.RevenueID = @RevenueID Group by B.ItemID, S.SectionName, B.CashType ) Summary group by Exam, [Section]; */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_PatientInfo] @HospNum varchar(8) AS if isnumeric(LEFT(@HospNum, 1)) = 1 begin select m.HospNum, m.LastName, m.FirstName, m.MiddleName, m.HouseStreet, m.Barangay, m.ZipCode, isnull(a.Town, '') [Town], isnull(a.Province, '') [Province], m.Sex, m.CivilStatus, m.Occupation, m.TelNum, case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar, m.BirthDate, 101) end BirthDate, case when m.birthdate is null then isnull(m.Age, '') when m.birthdate <= '01/01/1900' then isnull(m.Age, '') else convert(varchar, datediff(year, m.birthdate, getdate())) end Age, m.XRayNum, m.UltraNum, m.CTNum, m.ControlNum from patient_data..tbmaster m left join build_file..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end else begin select m.HospNum, m.LastName, m.FirstName, m.MiddleName, m.HouseStreet, m.Barangay, m.ZipCode, isnull(a.Town, '') [Town], isnull(a.Province, '') [Province], m.Sex, m.CivilStatusID [CivilStatus], m.Occupation, '' [TelNum], case when m.birthdate is null then '' when m.birthdate <= '01/01/1900' then '' else convert(varchar, m.BirthDate, 101) end BirthDate, case when m.birthdate is null then isnull( convert( varchar, m.Age ), '' ) when m.birthdate <= '01/01/1900' then isnull( convert(varchar, m.Age ), '' ) else convert( varchar, datediff( year, m.birthdate, getdate() ) ) end Age, m.XRayNum, m.UltraNum, m.CTNum, m.ControlNum from patient_data..tbcashpatient m left join build_file..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PendingRequestPatient] @IDNum varchar(10), @Department varchar(2) AS SELECT * FROM STATION..tbNurseCommunicationFile WHERE RevenueID = @Department AND RecordStatus = '' AND IDNum = @IDNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_AssessmentReport] @Mode as varchar(1), @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*declare @Mode as varchar(1) declare @StartDate as varchar(10) declare @EndDate as varchar(10) declare @RevenueID as varchar(2) set @Mode = '1' set @StartDate = '03/01/2005' set @EndDate = '03/05/2005' set @RevenueID = 'XR'*/ if @Mode = '1' begin select isnull(HospNum,'') as HospNum, IdNum, [Name] as PatientName, Transdate, B.RefNum, B.OrNumber, B.revenueID, B.ItemID, case isnull(B.RevenueId,'') when 'MD' THEN D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName when @RevenueID then E.[Description] else M.ItemName end as Exam, B.Quantity, B.Amount, B.UserID, B.RecordStatus, b.revenueid, b.RequestDocID, RequestDocID as DoctorID, case isnull(D2.Lastname,'') when '' then D2.LastName + ', ' + D2.Firstname + ' ' + D2.MiddleName else isnull(DoctorName,'') end as DoctorName from BILLING..tbCashAssessment B LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster M on B.ItemID = M.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.ItemID = D.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID where (B.revenueid = @RevenueID or B.DepartmentID = @RevenueID) and isnull(B.RecordStatus, '1') = '1' and B.Transdate between @StartDate AND @EndDate + ' 23:59:59.99' ORDER BY PatientName; end; if @Mode = 'X' begin select isnull(HospNum,'') as HospNum, IdNum, [Name] as PatientName, Transdate, B.RefNum, ISNULL(B.OrNumber,'') AS OrNumber, B.revenueID, B.ItemID, case isnull(B.RevenueId,'') when 'MD' THEN D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName when @RevenueID then E.[Description] else M.ItemName end as Exam, B.Quantity, B.Amount, B.UserID, B.RecordStatus, RequestDocID as DoctorID, case isnull(D2.Lastname,'') when '' then D2.LastName + ', ' + D2.Firstname + ' ' + D2.MiddleName else isnull(DoctorName,'') end as DoctorName from BILLING..tbCashAssessment B LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster M on B.ItemID = M.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.ItemID = D.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID where (B.revenueid = @RevenueID or B.DepartmentID = @RevenueID) and B.RecordStatus = 'R' and B.Transdate between @StartDate AND @EndDate + ' 23:59:59.99' ORDER BY PatientName; end; if @Mode = 'A' begin select isnull(HospNum,'') as HospNum, IdNum, [Name] as PatientName, Transdate, B.RefNum, ISNULL(B.OrNumber,'') AS OrNumber, B.revenueID, B.ItemID, case isnull(B.RevenueId,'') when 'MD' THEN D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName when @RevenueID then E.[Description] else M.ItemName end as Exam, B.Quantity, B.Amount, B.UserID, B.RecordStatus, RequestDocID as DoctorID, case isnull(D2.Lastname,'') when '' then D2.LastName + ', ' + D2.Firstname + ' ' + D2.MiddleName else isnull(DoctorName,'') end as DoctorName from BILLING..tbCashAssessment B LEFT OUTER JOIN BILLING..tbBillExamListing E on B.ItemID = E.ItemID and B.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster M on B.ItemID = M.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on B.ItemID = D.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID where (B.revenueid = @RevenueID or B.DepartmentID = @RevenueID) and B.Transdate between @StartDate AND @EndDate + ' 23:59:59.99' ORDER BY PatientName; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_ListOutExams] @RefNum varchar(10) --@Refnum ='OR588506' AS Select IsNull(C.ItemID,'') [Code], IsNull(X.OtherRevenue,'') [Description], case when isnull(c.quantity, 0) = 0 then IsNull(c.Amount,0) else IsNull(C.Amount,0) / IsNull(C.Quantity,0) end [Price], case when isnull(C.Quantity, 0) = 0 then 1 else IsNull(c.Quantity,0) end [Quantity], IsNull(C.Amount,0) [Amount],Refnum,C.RequestdocID, D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName as ReqDoc from BILLING..tbCashCommunication C left join BUILD_FILE..tbcoOtherRevenue X on C.ItemID = X.OtherRevenueID Left Outer Join Build_File..tbcodoctor D on C.RequestdocID = D.DoctorID where ISNULL(C.RecordStatus, '') = '' and C.RefNum = @RefNum and (C.RevenueID = 'MI' OR C.DepartmentID = 'MI') --and X.SectionID ='MP' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_LoadExamEntry] @SearchCriteria varchar(50) AS begin select e.OtherRevenueID [ExamID], e.OtherRevenue [Exam], /* e.XRaySectionID [SectionID], s.SectionName [Section],*/ e.RateA, e.RateB, e.RateC, e.RateD, e.RateE, e.Status-- e.Classification--, e.ReportGroup, isnull(g.description,'') as ReportGroupName from BUILD_FILE..tbcoOtherRevenue e /*left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'MS') and (s.SectionID = e.XRaySectionID) left join RADIOLOGY..tbRadio_BuildExamGroup g on e.ReportGroup = g.ReportGroup*/ where e.OtherRevenueID = @SearchCriteria end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_MonthlyReport] @RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) --set @RevenueID = 'MI' --SET @FirstDay = '08/01/2005' --SET @LastDay ='08/30/2005' AS DECLARE @StartDate datetime, @EndDate datetime SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) select b.refnum, sum(b.amount) as Amount, max(b.quantity) as Qty, max(b.itemid) as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)IDNum, max(p.hospnum)HospNum, max(m.lastname) + ', ' + max(m.firstname) patient,max(B.Revenueid)RevenueD,max(b.userid) as UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount , max(C.DoctorName) doctor -- max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) as Doctor from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join Station..tbnursecommunicationfile C on B.Refnum = C.Referencenum --left join Build_file..tbcodoctor D --on D.DoctorID = c.DoctorID where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID group by B.Refnum, B.itemid having sum(b.amount) > 0 union all select max(b.refnum)as Refnum, sum(b.amount) as Amount, max(b.quantity) Qty, max(b.itemid)as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) as transdate, max(b.idnum)IdNum, max(p.hospnum) HospNum, max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient, max(B.Revenueid)RevenueD, max(b.userid) UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount, max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) Doctor from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum left join billing..tbcashassessment C on C.Ornumber = B.Refnum left join Build_file..tbcodoctor D on C.RequestDociD = D.DoctorID where b.Refnum in (Select Refnum from Billing..tbBillOPdailyOut where RevenueID ='MI' and idnum ='CASH') and B.transdate between @StartDate and @EndDate + ' 23:59:59.99' and b.revenueid in('MI','G1', 'G2', 'G3', 'G4', 'G5', 'G6') group by B.Refnum,B.itemid--, B.idnum --having sum(b.amount) > 0 union all select max(b.refnum)as Refnum, sum(b.amount) as Amount, max(b.quantity) Qty, max(b.itemid)as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) as transdate, max(b.idnum)IdNum, max(p.hospnum) HospNum, max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient, max(B.Revenueid)RevenueD, max(b.userid) UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount, max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) Doctor from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum left join billing..tbcashassessment C on C.Ornumber = B.Refnum left join Build_file..tbcodoctor D on C.RequestDociD = D.DoctorID where b.Refnum in (Select Refnum from Billing..tbBillOPdailyOut where RevenueID ='MI' and idnum <>'CASH') and B.transdate between @StartDate and @EndDate + ' 23:59:59.99' and b.revenueid in('MI') group by B.Refnum, B.itemid having sum(b.amount) > 0 order by a.tRANSDATE , refnum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_MonthlyReport_MADELOCT] @RevenueID varchar(2), @STARTDATE varchar(10), @ENDDATE varchar(10) AS /*DECLARE @RevenueID varchar(2) DECLARE @STARTDATE varchar(10) DECLARE @ENDDATE varchar(10) SET @RevenueID ='MI' SET @STARTDATE='09/01/2005' SET @ENDDATE = '09/30/2005'*/ select b.refnum, sum(b.amount) as Amount, max(b.quantity) as Qty, max(b.itemid) as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)IDNum, max(p.hospnum)HospNum, max(m.lastname) + ', ' + max(m.firstname) patient,max(B.Revenueid)RevenueD,max(b.userid) as UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount, -- max(C.DoctorName) doctor max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) as Doctor from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum --left join Station..tbnursecommunicationfile C --on B.Refnum = C.Referencenum left join Build_file..tbcodoctor D on B.RequestDociD = D.DoctorID where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID -- and e.RateA > 2599 group by B.Refnum, B.itemid having sum(b.amount) > 0 union all select max(b.refnum)as Refnum, sum(b.amount) as Amount, max(b.quantity) Qty, max(b.itemid)as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) as transdate, max(b.idnum)IdNum, max(p.hospnum) HospNum, max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient, max(B.Revenueid)RevenueD, max(b.userid) UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount, max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) Doctor from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum /*--left join billing..tbcashassessment C --on C.Ornumber = B.Refnum*/ left join Build_file..tbcodoctor D on B.RequestDociD = D.DoctorID where b.Refnum in (Select Refnum from Billing..tbBillOPdailyOut where RevenueID ='MI' and idnum ='CASH') and B.transdate between @StartDate and @EndDate + ' 23:59:59.99' and b.revenueid in('MI','G1', 'G2', 'G3', 'G4', 'G5', 'G6') -- and e.RateA > 2599 -- I added this line to include those items with amount greater then 2599 group by B.Refnum,B.itemid--, B.idnum having sum(b.amount) > 0 union all select max(b.refnum)as Refnum, sum(b.amount) as Amount, max(b.quantity) Qty, max(b.itemid)as ItemID, max(case @RevenueID when 'MI' then e.OtherRevenue end) as exam, max(convert(varchar(10), b.transdate, 101)) as transdate, max(b.idnum)IdNum, max(p.hospnum) HospNum, max(case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom end) as patient, max(B.Revenueid)RevenueD, max(b.userid) UserID, sum(Cast( Case when B.RevenueID in ('G1', 'G2', 'G3', 'G4', 'G5', 'G6') then isnull(B.Amount,0) else 0 end as money)) as GSISDiscount, max(D.LastName) + ', ' + max(D.Firstname) + ' ' + max(d.Middlename) Doctor from billing..tbbillopdailyout b left join build_file..tbcoOtherRevenue e on b.itemid = e.OtherRevenueID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum -- left join billing..tbcashassessment C --on C.Ornumber = B.Refnum left join Build_file..tbcodoctor D on B.RequestDociD = D.DoctorID where b.Refnum in (Select Refnum from Billing..tbBillOPdailyOut where RevenueID ='MI' and idnum <>'CASH') and B.transdate between @StartDate and @EndDate + ' 23:59:59.99' and b.revenueid in('MI') -- and e.RateA > 2599 group by B.Refnum, B.itemid having sum(b.amount) > 0 order by a.tRANSDATE , refnum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReportGrossIncomeReport] AS GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_StatisticalReport] @StartDate as varchar(10), @EndDate as varchar(10) AS /* declare @StartDate as varchar(10) declare @EndDate as varchar(10) set @StartDate = '09/29/2007' set @EndDate = '09/29/2007' */ select tbBillDailyBill.ItemID, max(Exam.Description) as ExamName, sum(case when isnull(tbBillDailyBill.Quantity, 0) = 0 then case when isnull(tbBillDailyBill.Amount,0) > 0 then 1 when isnull(tbBillDailyBill.Amount,0) = 0 then 0 when isnull(tbBillDailyBill.Amount,0) < 0 then -1 end Else case when isnull(tbBillDailyBill.Amount,0) < 0 then ABS(IsNull(tbBillDailyBill.Quantity,1)) * -1 when isnull(tbBillDailyBill.Amount,0) = 0 then 0 else ABS(IsNull(tbBillDailyBill.Quantity,1)) end end) as InPatient, 0 as OutPatient, cast(sum(tbBillDailyBill.Amount) as money) as InPatientAmount, 0 as OutPatientAmount from BILLING..tbBillDailyBill tbBillDailyBill --CLINICAL_AREA..tbAudMaster tbAudMaster left outer join BILLING..tbBillExamListing Exam on Exam.ItemID = tbBillDailyBill.ItemID and Exam.RevenueID = tbBillDailyBill.RevenueID where tbBillDailyBill.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and tbBillDailyBill.RevenueID = 'MM' group by tbBillDailyBill.ItemID having sum(tbBillDailyBill.Amount) > 0 union all select tbBillOPDailyOut.ItemID, max(Exam.Description) as ExamName, 0 as InPatient, sum(case when isnull(tbBillOPDailyOut.Quantity, 0) = 0 then case when isnull(tbBillOPDailyOut.Amount,0) > 0 then 1 when isnull(tbBillOPDailyOut.Amount,0) = 0 then 0 when isnull(tbBillOPDailyOut.Amount,0) < 0 then -1 end Else case when isnull(tbBillOPDailyOut.Amount,0) < 0 then ABS(IsNull(tbBillOPDailyOut.Quantity,1)) * -1 when isnull(tbBillOPDailyOut.Amount,0) = 0 then 0 else ABS(IsNull(tbBillOPDailyOut.Quantity,1)) end end) as OutPatient, 0 as InPatientAmount, cast(sum(tbBillOPDailyOut.Amount) as money) as OutPatientAmount from BILLING..tbBillOPDailyOut tbBillOPDailyOut --CLINICAL_AREA..tbAudMaster tbAudMaster left outer join BILLING..tbBillExamListing Exam on Exam.ItemID = tbBillOPDailyOut.ItemID and Exam.RevenueID = tbBillOPDailyOut.RevenueID where tbBillOPDailyOut.Transdate between @StartDate and @EndDate + ' 23:59:59.99' and tbBillOPDailyOut.RevenueID = 'MM' group by tbBillOPDailyOut.ItemID having sum(tbBillOPDailyOut.Amount) > 0 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_NurseRequestByIdNum] @Type As varChar(1), @IdNum varchar(8) AS /* MRI Request */ BEGIN IF isnumeric(@IDNum) = 1 Begin Select 'MI' as Department, Nurse.ItemID as Code, tbExam.OtherRevenue as Exam, '1' as Quantity, Case When Room.RoomClassID = 'A' then cast(tbExam.RateA as money) When Room.RoomClassId = 'B' then cast(tbExam.RateB as money) When Room.RoomClassId = 'C' then cast(tbExam.RateC as money) When Room.RoomClassId = 'D' then cast(tbExam.RateD as money) Else cast (tbExam.RateE as money) End as [Amount], ISNULL(Nurse.Remarks,'') as Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Patient_Data..tbPatient tbPatient on tbPatient.IdNum = Nurse.IdNum Left Outer Join Build_File..tbCoRoom Room On Room.RoomID = tbPatient.RoomID Left Outer Join Build_File..tbCoOtherRevenue tbExam On Nurse.ItemID = tbExam.OtherRevenueID Where Nurse.RevenueID = 'MI' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End ELSE Begin Select 'CT' as Department, Nurse.ItemID as Code, tbExam.OTherRevenue as Exam, --Cast(tbExam.RateA as Money) as [Amount], /*Case When RADIOLOGY.dbo.fn_IsJonelta(Nurse.IDnum) = 1 Then Cast(tbExam.RateF as Money) Else Cast(tbExam.RateA as Money) End as [Price], isnull(Nurse.Stat,'N') as MarkUp,*/ '1' as Quantity, Case When RADIOLOGY.dbo.fn_IsJonelta(Nurse.IDnum) = 1 Then Cast(tbExam.RateF as Money) Else Cast(tbExam.RateA as Money) End as [Amount] , ISNULL(Nurse.Remarks,'') as Remarks From Station..tbNurseCommunicationFile Nurse Left Outer Join Build_File..tbCoOtherRevenue tbExam On Nurse.ItemID = tbExam.OtherREvenueID Where Nurse.RevenueID = 'MS' and Nurse.IDNum = @IDNum and IsNull(Nurse.RecordStatus,'') = '' and IsNumeric(ItemID) = 1 End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_InNurseUpdate] @HospNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(4), @RevenueID AS varChar(2) AS if Exists(Select * from station..tbNurseCommunicationFile WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and isnull(RecordStatus,'') = '') Begin UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and isnull(RecordStatus,'') = '' end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_RequestList] @Type varChar(1), @Names varchar(30) AS IF @Type = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.LastName AS Lastname, tbCTRequest.FirstName AS Firstname, tbCTRequest.MiddleName AS Middlename, tbCTRequest.Code AS Code, tbCTRequest.TypeDescription AS Description, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDate, tbCTRequest.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbMaster.CTNum As ControlNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbCTRequest LEFT OUTER JOIN tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN tbCoCTExam ON tbCTRequest.Code = tbCoCTExam.CTExamID WHERE tbCTRequest.Lastname LIKE @Names +'%' AND tbCTRequest.SwFin IS NULL AND tbCoCTExam.CTSectionID = 'RTE' ORDER BY tbCTRequest.LastName, tbCTRequest.FirstName, tbCTRequest.MiddleName END IF @Type = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.LastName AS Lastname, tbXRRequest.FirstName AS Firstname, tbXRRequest.MiddleName AS Middlename, tbXRRequest.Code AS Code, tbXRRequest.TypeDescription AS Description, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDate, tbXRRequest.Film8 AS [8X10], tbXRRequest.Film10 AS [10X12], tbXRRequest.Film11 AS [11X14], tbXRRequest.Film14 AS [14X14], tbXRRequest.Film17 AS [14X17], tbXRRequest.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbMaster.XRayNum AS ControlNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbXRRequest LEFT OUTER JOIN tbPatient ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbXRRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN tbCoXRayExam ON tbXRRequest.Code = tbCoXRayExam.XRayExamID WHERE tbXRRequest.Lastname LIKE @Names +'%' AND tbXRRequest.SwFin IS NULL AND (tbCoXRayExam.XRaySectionID = 'PRC' or tbCoXRayExam.XRaySectionID = 'VIS') ORDER BY tbXRRequest.LastName, tbXRRequest.FirstName, tbXRRequest.MiddleName END IF @Type = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbULRequest.LastName AS Lastname, tbULRequest.FirstName AS Firstname, tbULRequest.MiddleName AS Middlename, tbULRequest.Code AS Code, tbULRequest.TypeDescription AS Description, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDate, tbULRequest.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate AS AdmDate, tbMaster.UltraNum as ControlNum, tbMaster.HouseStreet + ' ' + tbmaster.Barangay + ', ' + tbCoAddress.Town + ', ' + tbCoAddress.Province, tbMaster.TelNum FROM tbULRequest LEFT OUTER JOIN tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCoAddress ON tbMaster.Zipcode = tbCoAddress.Zipcode WHERE tbULRequest.Lastname LIKE @Names +'%' AND tbULRequest.SwFin IS NULL ORDER BY tbULRequest.LastName, tbULRequest.FirstName, tbULRequest.MiddleName END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered by : Jetty P. Omo Date : 01/28/08 Details : Included Oupatient and In Patient in classification */ CREATE PROCEDURE [dbo].[Radiology_CheckIfHMO] @IdNum as varchar(10) AS --declare @IdNum as varchar(10) --set @IdNum = '5916' Declare @Class as varchar(1) if isnumeric(@IdNum) = 1 Begin set @Class = (select c.Class from PATIENT_DATA..tbPatient p left outer join build_file..tbCoCompany C on p.Accountnum = C.Accountnum where idnum = @IdNum) if @Class in ('xx') Begin set @Class = 'P' select @Class as Class End ELSE select '' as Class End else Begin set @Class = (select c.Class from PATIENT_DATA..tbOutPatient p left outer join build_file..tbCoCompany C on p.Accountnum = C.Accountnum where idnum = @IdNum ) if @Class in ('xx') Begin set @Class = 'P' select @Class as Class End ELSE select '' as Class End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_NurseRequest] as BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.OtherRevenueID as [ItemID] , C.Otherrevenue as [ItemDesc], Case When R.RoomClassID = 'A' then cast(isnull(C.RateA,0)as money) When R.RoomClassID = 'B' then cast(isnull(C.RateB,0)as money) When R.RoomClassID = 'C' then cast(isnull(C.RateC,0)as money) When R.RoomClassID = 'D' then cast(isnull(C.RateD,0)as money) When R.RoomClassID = 'E' then cast(isnull(C.RateE,0)as money) End as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, D.RoomID, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID, A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID and Othersectionid = 'MM' left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID='MM' and D.BillingDate is Null Union All Select Distinct D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.OtherRevenueID as [ItemID] , C.OtherRevenue as [ItemDesc], cast(isnull(C.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, MasterIn.BirthDate, MasterIn.Age, D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, A.UserID, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID, convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID, A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbcoOtherRevenue C on A.ItemID = C.OtherRevenueID and Othersectionid = 'MM' left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID = 'MM' and D.BillingDate is Null Order By [Date Request], [LastName], [FirstName] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_InNurseUpdate] @HospNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(4), @RevenueID AS varChar(2), @RequestNum as varchar(10) = null AS if exists(Select * from Station..tbnursecommunicationfile WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and isnull(Recordstatus,'') = '') Begin UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE IDNum = @IDNum AND ItemID = @ItemID AND RevenueID = @RevenueID and isnull(Recordstatus,'') = '' UPDATE station..tbnurselogbook set Recordstatus = 'X' Where idnum = @idnum and ItemID = @itemid and Revenueid = @Revenueid and isnull (Recordstatus,'') = '' end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_TransReport Script Date: 07/01/2000 1:20:57 AM ******/ CREATE PROCEDURE [dbo].[spMRI_TransReport] @StartDate AS varchar(10), @EndDate AS varchar(10), @UserID as varchar(10) AS DELETE tbMRITransReport --WHERE UserID = @UserID; BEGIN INSERT tbMRITransReport SELECT distinct CASE WHEN ISNUMERIC(C.HospNum) = 1 THEN isnull(tbMaster.LastName, '') + ', ' + isnull(tbMaster.FirstName, '') ELSE tbCashPatient.LastName + ', ' + tbCashPatient.FirstName END AS PatientName, mri.OtherRevenue AS Description, C.RefNum as CSlip, CASE WHEN LEFT(C.RefNum, 2) = 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Cash, CASE WHEN LEFT(C.RefNum, 2) <> 'OR' THEN CAST(C.Amount AS VARCHAR) ELSE '' END As Charge, @UserID FROM tbMRIRequest C LEFT JOIN PATIENT_DATA..tbMaster tbMaster ON C.HospNum = tbMaster.HospNum LEFT JOIN PATIENT_DATA..tbCashPatient tbCashPatient ON C.HospNum = tbCashPatient.HospNum LEFT JOIN BUILD_FILE..tbcoOtherRevenue mri ON C.Code = mri.OtherRevenueID WHERE C.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND ISNULL(C.SwFin,'') <> 'C' ORDER BY PatientName END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_FilmInventory] @StartDate as varchar(10), @EndDate as varchar(10) AS select tbXRRequest.HospNum, tbXrRequest.IdNum, tbXrRequest.Transdate, tbXrRequest.Requestnum, isnull(tbXrResult.XrayNum,'NoResult') [XrayNum], tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.Middlename [PatientName], tbXrRequest.Code, tbCoXrayExam.XrayExam, tbXrRequest.Film1, tbXrRequest.Film2, tbXrRequest.Film3, tbXrRequest.Film4, tbXrRequest.Film5, tbXrRequest.Film6, tbXrRequest.Film7, tbXrRequest.Film8, isnull(tbXrWaste.WasteFilm1,'0') [WasteFilm1], isnull(tbXrWaste.WasteFilm2,'0') [WasteFilm2], isnull(tbXrWaste.WasteFilm3,'0') [WasteFilm3], isnull(tbXrWaste.WasteFilm4,'0') [WasteFilm4], isnull(tbXrWaste.WasteFilm5,'0') [WasteFilm5], isnull(tbXrWaste.WasteFilm6,'0') [WasteFilm6], isnull(tbXrWaste.WasteFilm7,'0') [WasteFilm7], isnull(tbXrWaste.WasteFilm8,'0') [WasteFilm8], isnull(tbXrWaste.WastageCause,'') [WastageCause], isnull(tbXrRequest.RadTech,'') [RadCode], isnull(tbXrWaste.UserID,'') [UserID], isnull(tbXrRequest.Location,'') [Location], tbXrRequest.xraydate from Radiology..tbXRRequest tbXrRequest left outer join Patient_Data..tbMaster tbMaster on tbXrRequest.hospNum = tbMaster.HospNum left outer join Radiology..tbXrResult tbXrResult on tbXrRequest.RequestNum = tbXrResult.RequestNum left outer join Radiology..tbXrWaste tbXrWaste on tbXrRequest.RequestNum = tbXrWaste.RequestNum left outer join Build_File..tbCoXrayExam tbCoXrayExam on tbXrRequest.Code = tbCoXrayExam.XrayExamID where isnumeric(tbXrRequest.HospNum) = 1 and tbXrRequest.TRANSDATE between @StartDate and @EndDate + ' 23:59:59.99' union all select tbXRRequest.HospNum, tbXrRequest.IdNum, tbXrRequest.Transdate, tbXrRequest.Requestnum, isnull(tbXrResult.XrayNum,'NoResult') [XrayNum], tbCashPatient.LastName + ', ' + tbCashPatient.FirstName + ' ' + tbCashPatient.Middlename [PatientName], tbXrRequest.Code, tbCoXrayExam.XrayExam, tbXrRequest.Film1, tbXrRequest.Film2, tbXrRequest.Film3, tbXrRequest.Film4, tbXrRequest.Film5, tbXrRequest.Film6, tbXrRequest.Film7, tbXrRequest.Film8, isnull(tbXrWaste.WasteFilm1,'0') [WasteFilm1], isnull(tbXrWaste.WasteFilm2,'0') [WasteFilm2], isnull(tbXrWaste.WasteFilm3,'0') [WasteFilm3], isnull(tbXrWaste.WasteFilm4,'0') [WasteFilm4], isnull(tbXrWaste.WasteFilm5,'0') [WasteFilm5], isnull(tbXrWaste.WasteFilm6,'0') [WasteFilm6], isnull(tbXrWaste.WasteFilm7,'0') [WasteFilm7], isnull(tbXrWaste.WasteFilm8,'0') [WasteFilm8], isnull(tbXrWaste.WastageCause,'') [WastageCause], isnull(tbXrRequest.RadTech,'') [RadCode], isnull(tbXrWaste.UserID,'') [UserID], isnull(tbXrRequest.Location,'') [Location], tbXrRequest.xraydate from Radiology..tbXRRequest tbXrRequest left outer join Patient_Data..tbCashPatient tbCashPatient on tbXrRequest.hospNum = tbCashPatient.HospNum left outer join Radiology..tbXrResult tbXrResult on tbXrRequest.RequestNum = tbXrResult.RequestNum left outer join Radiology..tbXrWaste tbXrWaste on tbXrRequest.RequestNum = tbXrWaste.RequestNum left outer join Build_File..tbCoXrayExam tbCoXrayExam on tbXrRequest.Code = tbCoXrayExam.XrayExamID where isnumeric(tbXrRequest.HospNum) = 0 and tbXrRequest.TRANSDATE between @StartDate and @EndDate + ' 23:59:59.99' order by [patientname] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_UpdateFilmsUsed_Waste] @Type as varchar(1), @RequestNum as varchar(10), @Code as varchar(10), @WFilm1 as int, @WFilm2 as int, @WFilm3 as int, @WFilm4 as int, @WFilm5 as int, @WFilm6 as int, @WFilm7 as int, @Cause as varchar(50), @UserID as varchar(10), @Location as varchar(2), @RadTech as varchar(10), @XrayDate as datetime = 0, @WFilm8 as int = null AS if @Type = '2' BEGIN if exists (select RequestNum from Radiology..tbXrWaste where RequestNum = @RequestNum) begin update Radiology..tbXrWaste set Code = @Code, [Date] = getdate(), WasteFilm1 = @WFilm1, WasteFilm2 = @WFilm2, WasteFilm3 = @WFilm3, WasteFilm4 = @WFilm4, WasteFilm5 = @WFilm5, WasteFilm6 = @WFilm6, WasteFilm7 = @WFilm7, WasteFilm8 = @WFilm8, WastageCause = @Cause, UserId = @UserID where RequestNum = @RequestNum; update Radiology..tbXrRequest set RadTech = @RadTech, Location = @Location, XrayDate = @XrayDate where RequestNum = @RequestNum; end; else begin insert into Radiology..tbXrWaste (RequestNum, Code, [Date], WasteFilm1, WasteFilm2, WasteFilm3, WasteFilm4, WasteFilm5, WasteFilm6, WasteFilm7, WasteFilm8, WastageCause, UserID) values (@RequestNum, @Code, getdate(), @WFilm1, @WFilm2, @WFilm3, @WFilm4, @WFilm5, @WFilm6, @WFilm7, @WFilm8, @Cause, @UserID); update Radiology..tbXrRequest set RadTech = @RadTech, Location = @Location, XrayDate = @XrayDate where RequestNum = @RequestNum; end; END; /*@Type as varchar(1), -- From Kuya Attic @RequestNum as varchar(10), @Film1 as int, @Film2 as int, @Film3 as int, @Film4 as int, @Film5 as int, @Film6 as int, @Film7 as int, @Remarks as varchar(60) AS IF @Type = '2' BEGIN UPDATE tbXRRequest SET FilmWaste1 = @Film1, FilmWaste2 = @Film2, FilmWaste3 = @Film3, FilmWaste4 = @Film4, FilmWaste5 = @Film5, FilmWaste6 = @Film6, FilmWaste7 = @Film7, WastageCause= @Remarks WHERE RequestNum = @RequestNum END*/ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_LoadRequest_Waste] @TYPE varchar(4), @RequestNum varchar(10) AS /* declare @TYPE varchar(4), @RequestNum varchar(10) set @TYPE = 'MM' set @RequestNum = '48' */ IF @TYPE = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.RefNum, CASE isnull(tbXRRequest.SwFin,'') WHEN 'Y' THEN isnull(tbXrResult.XrayNum, '') WHEN 'X' THEN 'No Result' ELSE 'No Result' END AS [XrayNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbXRRequest.Code AS Code, tbCoXrayExam.XRayExam AS Description, tbCoXrayExam.XRaySectionID AS SectionId, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDate, isnull(tbXRRequest.RadTech,'') [RadTechCode], Radiology.dbo.fn_GetEmployeeName(tbXRRequest.RadTech) [RadTech], -- isnull(tbRadioRadTech.EmployeeID,'') [RadTechCode], -- tbRadioRadTech.LastName + ', ' + tbRadioRadTech.FirstName + ' ' + tbRadioRadTech.MiddleName [RadTech], isnull(tbXrWaste.WasteFilm1,'') [FilmWaste1], isnull(tbXrWaste.WasteFilm2,'') [FilmWaste2], isnull(tbXrWaste.WasteFilm3,'') [FilmWaste3], isnull(tbXrWaste.WasteFilm4,'') [FilmWaste4], isnull(tbXrWaste.WasteFilm5,'') [FilmWaste5], isnull(tbXrWaste.WasteFilm6,'') [FilmWaste6], isnull(tbXrWaste.WasteFilm7,'') [FilmWaste7], isnull(tbXrWaste.WasteFilm8,'') [FilmWaste8], isnull(tbXrWaste.WastageCause,'') [WastageCause], case isnull(tbXrBorrowedFilm.RequestNum,'') WHEN '' then isnull(tbXrRequest.Location,'') else 'BR' END as Location, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE 'OPD' END AS RoomID, tbXRRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.XRayNum ELSE tbCashPatient.XRayNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbXRRequest.Amount, tbXRRequest.XrayDate, ISNULL(tbXRRequest.FilmsReleased,getdate()) FilmsReleased, ISNULL(tbXRRequest.FilmsUser,'') FilmsUserCode, ISNULL(Radiology.dbo.fn_GetUserName(tbXRRequest.FilmsUser),'') FilmsUser, ISNULL(tbXRRequest.FilmsReceivedBy,'') FilmsReceivedBy, ISNULL(tbXRRequest.ResultOnly,'0') ResultOnly, ISNULL(tbXRRequest.FilmOnly,'0') FilmOnly, ISNULL(tbXRRequest.FilmResult,'0') FilmResult FROM tbXRRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbXRRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbXRRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbXRRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN RADIOLOGY..tbXrResult [tbXrResult] ON tbXrRequest.RequestNum = tbXrResult.RequestNum LEFT OUTER JOIN RADIOLOGY..tbXrWaste [tbXrWaste] ON tbXRRequest.RequestNum = tbXrWaste.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam [tbCoXRayExam] ON tbXRRequest.Code = tbCoXRayExam.XRayExamID LEFT OUTER JOIN RADIOLOGY..tbRadioRadTech [tbRadioRadTech] ON tbXRRequest.RadTech = tbRadioRadTech.Employeeid LEFT OUTER JOIN RADIOLOGY..tbXrBorrowedFilm [tbXrBorrowedFilm] ON tbXrBorrowedFilm.RequestNum = tbXrRequest.RequestNum WHERE tbXRRequest.RequestNum = @RequestNum END IF @TYPE = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.RefNum, CASE isnull(tbCTRequest.SwFin,'') WHEN 'Y' THEN isnull(tbCTResult.XrayNum, '') WHEN 'X' THEN 'No Result' ELSE 'No Result' END AS [CTNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbCTRequest.Code AS Code, tbCoCTExam.CTExam AS Description, tbCoCTExam.CTSectionID AS SectionId, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDate, isnull(tbCTRequest.RadTech,'') [RadTechCode], Radiology.dbo.fn_GetEmployeeName(tbCTRequest.RadTech) [RadTech], isnull(tbCTFILMWaste.WasteFilm1,'') [FilmWaste1], isnull(tbCTFILMWaste.WasteFilm2,'') [FilmWaste2], isnull(tbCTFILMWaste.WasteFilm3,'') [FilmWaste3], isnull(tbCTFILMWaste.WasteFilm4,'') [FilmWaste4], isnull(tbCTFILMWaste.WasteFilm5,'') [FilmWaste5], isnull(tbCTFILMWaste.WasteFilm6,'') [FilmWaste6], isnull(tbCTFILMWaste.WasteFilm7,'') [FilmWaste7], isnull(tbCTFILMWaste.WasteFilm8,'') [FilmWaste8], isnull(tbCTFILMWaste.WastageCause,'') [WastageCause], case isnull(tbCTBorrowedFilm.RequestNum,'') WHEN '' then isnull(tbCTRequest.Location,'') else 'BR' END as Location, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE 'OPD' END AS RoomID, tbCTRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CTNum ELSE tbCashPatient.CTNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbCTRequest.Amount, tbCTRequest.CTDate, ISNULL(tbCTRequest.FilmsReleased,tbCTRequest.TransDate) FilmsReleased, ISNULL(tbCTRequest.FilmsUser,'') FilmsUserCode, ISNULL(Radiology.dbo.fn_GetUserName(tbCTRequest.FilmsUser),'') FilmsUser, ISNULL(tbCTRequest.FilmsReceivedBy,'') FilmsReceivedBy, ISNULL(tbCTRequest.ResultOnly,'0') ResultOnly, ISNULL(tbCTRequest.FilmOnly,'0') FilmOnly, ISNULL(tbCTRequest.FilmResult,'0') FilmResult FROM tbCTRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbCTRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbCTRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN RADIOLOGY..tbCTResult [tbCTResult] ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN RADIOLOGY..tbCTFILMWaste [tbCTFILMWaste] ON tbCTRequest.RequestNum = tbCTFILMWaste.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN RADIOLOGY..tbRadioRadTech [tbRadioRadTech] ON tbCTRequest.RadTech = tbRadioRadTech.Employeeid LEFT OUTER JOIN RADIOLOGY..tbCTBorrowedFilm [tbCTBorrowedFilm] ON tbCTBorrowedFilm.RequestNum = tbCTRequest.RequestNum WHERE tbCTRequest.RequestNum = @RequestNum END IF @TYPE = 'MM' BEGIN SELECT tbMammoMaster.HospNum AS HospNum, tbMammoMaster.RequestNum AS RequestNum, tbMammoMaster.RefNum, CASE isnull(tbMammoMaster.ResultStatus,'') WHEN 'Z' THEN isnull(tbMammoResult.XrayNum, '') ELSE 'No Result' END AS [MammoNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbMammoMaster.ItemID AS Code, tbCoCTExam.CTExam AS Description, tbCoCTExam.CTSectionID AS SectionId, tbMammoMaster.IdNum AS IDNum, tbMammoMaster.TransDate AS TransDate, isnull(tbRadioRadTech.EmployeeID,'') [RadTechCode], tbRadioRadTech.LastName + ', ' + tbRadioRadTech.FirstName + ' ' + tbRadioRadTech.MiddleName [RadTech], isnull(tbCTFILMWaste.WasteFilm1,'') [FilmWaste1], isnull(tbCTFILMWaste.WasteFilm2,'') [FilmWaste2], isnull(tbCTFILMWaste.WasteFilm3,'') [FilmWaste3], isnull(tbCTFILMWaste.WasteFilm4,'') [FilmWaste4], isnull(tbCTFILMWaste.WasteFilm5,'') [FilmWaste5], isnull(tbCTFILMWaste.WasteFilm6,'') [FilmWaste6], isnull(tbCTFILMWaste.WasteFilm7,'') [FilmWaste7], isnull(tbCTFILMWaste.WasteFilm8,'') [FilmWaste8], isnull(tbCTFILMWaste.WastageCause,'') [WastageCause], '' as Location, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE 'OPD' END AS RoomID, tbMammoMaster.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CTNum ELSE tbCashPatient.CTNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbMammoMaster.Amount, tbMammoMaster.TransDate, ISNULL(tbMammoMaster.FilmsReleased,tbMammoMaster.TransDate) FilmsReleased, ISNULL(tbMammoMaster.FilmsUser,'') FilmsUserCode, ISNULL(Radiology.dbo.fn_GetUserName(tbMammoMaster.FilmsUser),'') FilmsUser, ISNULL(tbMammoMaster.FilmsReceivedBy,'') FilmsReceivedBy, ISNULL(tbMammoMaster.ResultOnly,'0') ResultOnly, ISNULL(tbMammoMaster.FilmOnly,'0') FilmOnly, ISNULL(tbMammoMaster.FilmResult,'0') FilmResult FROM tbMammoMaster LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbMammoMaster.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbMammoMaster.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbMammoMaster.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbMammoMaster.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbMammoMaster.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN RADIOLOGY..tbMammoResult [tbMammoResult] ON tbMammoMaster.RequestNum = tbMammoResult.RequestNum LEFT OUTER JOIN RADIOLOGY..tbCTFILMWaste [tbCTFILMWaste] ON tbMammoMaster.RequestNum = tbCTFILMWaste.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoCTExam [tbCoCTExam] ON tbMammoMaster.ItemID = tbCoCTExam.CTExamID LEFT OUTER JOIN RADIOLOGY..tbRadioRadTech [tbRadioRadTech] ON tbMammoResult.RadiologistID = tbRadioRadTech.Employeeid LEFT OUTER JOIN RADIOLOGY..tbCTBorrowedFilm [tbCTBorrowedFilm] ON tbCTBorrowedFilm.RequestNum = tbMammoMaster.RequestNum WHERE tbMammoMaster.RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_UpdateCounter] @RevenueID as varchar(2), @EmpID as varchar(10) AS If @RevenueID = 'XR' begin UPDATE RADIOLOGY..tbXRChargeSlip set Counter = 0 where EmpID = @EmpID; end; if @RevenueID = 'CT' begin UPDATE RADIOLOGY..tbCTChargeSlip set Counter = 0 where EmpID = @EmpID; end; if @RevenueID = 'US' begin UPDATE RADIOLOGY..tbULChargeSlip set Counter = 0 where EmpID = @EmpID; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_InsertUpdateChargeSlip] @RevenueID as varchar(2), @ChargeSlipNum as varchar(10), @EmpID as varchar(5) /* set @RevenueID = 'XR' set @ChargeSlipNum = '123458' set @empID = '28' */ AS if @RevenueID = 'XR' BEGIN if exists(Select * from RADIOLOGY..tbXRChargeSlip where EmpID = @EmpID) BEGIN UPDATE RADIOLOGY..tbXRChargeSlip set ChargeSlipNum = @ChargeSlipNum, Counter = 1 where EmpId = @EmpID; END; else BEGIN INSERT INTO RADIOLOGY..tbXRChargeSlip(ChargeSlipNum, EmpID, Counter) VALUES(@ChargeSlipNum, @EmpID, 1) END; END; if @RevenueID = 'CT' BEGIN if exists(Select * from RADIOLOGY..tbCTChargeSlip where EmpID = @EmpID) BEGIN UPDATE RADIOLOGY..tbCTChargeSlip set ChargeSlipNum = @ChargeSlipNum, Counter = 1 where EmpId = @EmpID; END; else BEGIN INSERT INTO RADIOLOGY..tbCTChargeSlip(ChargeSlipNum, EmpID, Counter) VALUES(@ChargeSlipNum, @EmpID, 1) END; END; if @RevenueID = 'US' BEGIN if exists(Select * from RADIOLOGY..tbULChargeSlip where EmpID = @EmpID) BEGIN UPDATE RADIOLOGY..tbULChargeSlip set ChargeSlipNum = @ChargeSlipNum, Counter = 1 where EmpId = @EmpID; END; else BEGIN INSERT INTO RADIOLOGY..tbULChargeSlip(ChargeSlipNum, EmpID, Counter) VALUES(@ChargeSlipNum, @EmpID, 1) END; END; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ChargeSlipNew] @RefNum as varchar(10), @IdNum as varchar(10), @revenueID as varchar(2) = 'XR' AS /* declare @RefNum as varchar(10) declare @IdNum as varchar(10) declare @revenueID as varchar(2) set @RefNum = 'C77841X' set @IdNum = '435673B' set @revenueID = 'xr' */ declare @HospNum as varchar(10) declare @PatientName as varchar(100) declare @Age as varchar(5) declare @Sex as varchar(2) declare @Membership as varchar(50) declare @Diagnosis as varchar(200) declare @RequestDate as datetime declare @AccountName as varchar(50) declare @Printed as varchar(1) declare @AdmissionType as varchar(50) declare @Portable as varchar(20) set @RequestDate = (select max(RequestDate) as RequestDate from station..tbNurseCommunicationFile where ReferenceNum = @RefNum) if isnumeric(@IdNum) = 1 begin select @HospNum = P.HospNum, @PatientName = V.LastName + ', ' + V.FirstName + ' ' + V.MiddleName , @Age = patient_data.dbo.fn_ComputeAge(V.BirthDate,getdate()), @Sex = V.Sex, @Diagnosis = isnull(cast(H.AdmDiagnosis as varchar),''), @Membership = isnull(M.PHICDescription,''), @AccountName = isnull(C.Company,'Personal') , @AdmissionType = isnull(AD.AdmissionType,'') from PATIENT_DATA..tbPatient P left outer join dbo.vwPatientMaster V on P.HospNum = V.Hospnum left outer join patient_data..tbPatient2 P2 on P.IdNum = P2.IdNum left outer join BUILD_FILE..tbcoCompany C on P.AccountNum= C.AccountNum left outer join patient_data..tbAdmPHICTable M ON P.MedicareType = M.PHICCode LEFT OUTER JOIN patient_data..tbPatientHistory H on P.IdNum = H.IdNum LEFT OUTER JOIN BUILD_fILE..tbCoAdmissionType AD on P2.AdmissionTypeID = AD.AdmissionTypeID where P.Idnum = @IdNum end; else begin if exists(Select IdNum from PATIENT_DATA..tbOutPatient where IdNum = @IdNum) begin select @HospNum = P.HospNum, @PatientName = V.LastName + ', ' + V.FirstName + ' ' + V.MiddleName , @Age = patient_data.dbo.fn_ComputeAge(V.BirthDate,getdate()), @Sex = V.Sex, @Diagnosis = isnull(cast(H.Findings as varchar),''), @Membership = '', @AccountName = isnull(C.Company,'Personal') from PATIENT_DATA..tbOutPatient P left outer join dbo.vwPatientMaster V on P.HospNum = V.Hospnum left outer join BUILD_FILE..tbcoCompany C on P.AccountNum= C.AccountNum LEFT OUTER JOIN patient_data..tbOutPatientHistory H on P.IdNum = H.IdNum where P.Idnum = @IdNum end; else begin select @HospNum = A.HospNum, @PatientName = CASE ISNULL(V.LastName,'') WHEN '' THEN a.[Name] ELSE V.LastName + ', ' + V.FirstName + ' ' + V.MiddleName end, @Age = patient_data.dbo.fn_ComputeAge(V.BirthDate,getdate()), @Sex = V.Sex, @Diagnosis = '', @Membership = '', @AccountName = 'CASH-PERSONAL' from BILLING..tbCashAssessment A LEFT OUTER JOIN dbo.vwPatientMaster V on A.HospNum = V.HospNum where A.refNum = @RefNum end; end; if @revenueID = 'XR' begin if isnumeric(@IdNum) = 1 and left(ltrim(@RefNum),2) not in ('OR','CC','XR') -- and isnumeric(left(ltrim(@RefNum),2) ) = 1 begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.XrayExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillDailyBill B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum-- and B.IDNum = @IDNum end; else begin if exists(Select RefNum from Billing..tbBillOPDailyOut where Refnum = @RefNum and isnull(idnum,'') <> 'CASH' union all Select RefNum from INVENTORY..tbInvStockCard where Refnum = @RefNum and isnull(idnum,'') <> 'CASH') begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.XrayExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin select distinct isnull(@HospNum,'CASH') as HospNum, B.IdNum as IdNum, ISNULL(@PatientName, B.[Name]) as PatientName, isnull(@Age,'') as Age, isnull(@Sex,'') as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName when 'XR' then E.XrayExam else M.ItemName end as Exam, B.Quantity, B.Amount as Price, B.Amount, B.UserID, 'CASH' AS RoomID, '' AS Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, 'CASH' as AccountName, '' as Diagnosis, '' as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbCashAssessment B left outer join INVENTORY..tbInvMaster M on B.ItemID = m.ItemID left outer join BUILD_FILE..tbCoXrayExam E on B.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; end; end; if @revenueID = 'CT' begin if isnumeric(@IdNum) = 1 and left(ltrim(@RefNum),2) not in ('OR','CC','CT') -- isnumeric(left(ltrim(@RefNum),2) ) = 1 begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.CTExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillDailyBill B left outer join BUILD_FILE..tbCoCTExam E on B.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin if exists(Select RefNum from Billing..tbBillOPDailyOut where Refnum = @RefNum and isnull(idnum,'') <> 'CASH' union all Select RefNum from INVENTORY..tbInvStockCard where Refnum = @RefNum and isnull(idnum,'') <> 'CASH') begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.CTExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoCTExam E on B.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName when 'CT' then E.CTExam else M.ItemName end as Exam, B.Quantity, B.Amount as Price, B.Amount, B.UserID, 'CASH' AS RoomID, '' AS Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, 'CASH' as AccountName, '' as Diagnosis, '' as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbCashAssessment B left outer join INVENTORY..tbInvMaster M on B.ItemID = m.ItemID left outer join BUILD_FILE..tbCoCTExam E on B.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; end; end; if @revenueID = 'US' begin if isnumeric(@IdNum) = 1 and left(ltrim(@RefNum),2) not in ('OR','CC','US') --isnumeric(left(ltrim(@RefNum),2) ) = 1 begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.UltraExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, case isnull(R.RoomClassID,'') when 'A' then E.RateA * B.Quantity when 'B' then E.RateB * B.Quantity when 'C' then E.RateC * B.Quantity when 'D' then E.RateD * B.Quantity when 'E' then E.RateE * B.Quantity when 'F' then E.RateF * B.Quantity when 'G' then E.RateG * B.Quantity when 'H' then E.RateH * B.Quantity ELSE E.RateA * B.Quantity end as Amount, --B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillDailyBill B left outer join BUILD_FILE..tbCoUltraExam E on B.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin if exists(Select RefNum from Billing..tbBillOPDailyOut where Refnum = @RefNum and isnull(idnum,'') <> 'CASH' union all Select RefNum from INVENTORY..tbInvStockCard where Refnum = @RefNum and isnull(idnum,'') <> 'CASH') begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.UltraExam end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoUltraExam E on B.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName when 'US' then E.UltraExam else M.ItemName end as Exam, B.Quantity, B.Amount as Price, B.Amount, B.UserID, 'CASH' AS RoomID, '' AS Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, 'CASH' as AccountName, '' as Diagnosis, '' as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbCashAssessment B left outer join INVENTORY..tbInvMaster M on B.ItemID = m.ItemID left outer join BUILD_FILE..tbCoUltraExam E on B.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; end; end; if @revenueID = 'WC' begin if isnumeric(@IdNum) = 1 and left(ltrim(@RefNum),2) not in ('OR','CC','WC') --isnumeric(left(ltrim(@RefNum),2) ) = 1 begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.OtherRevenue end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, case isnull(R.RoomClassID,'') when 'A' then E.RateA * B.Quantity when 'B' then E.RateB * B.Quantity when 'C' then E.RateC * B.Quantity when 'D' then E.RateD * B.Quantity when 'E' then E.RateE * B.Quantity when 'F' then E.RateF * B.Quantity when 'G' then E.RateG * B.Quantity when 'H' then E.RateH * B.Quantity ELSE E.RateA * B.Quantity end as Amount, --B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillDailyBill B left outer join BUILD_FILE..tbCoOtherRevenueID E on B.ItemID = E.OtherRevenueID and OtherSectionID = 'WC' left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin if exists(Select RefNum from Billing..tbBillOPDailyOut where Refnum = @RefNum and isnull(idnum,'') <> 'CASH' union all Select RefNum from INVENTORY..tbInvStockCard where Refnum = @RefNum and isnull(idnum,'') <> 'CASH') begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName else E.OtherRevenue end as Exam, B.Quantity, case isnull(B.RevenueID,'') when 'MD' then '' else case isnull(R.RoomClassID,'') when 'A' then E.RateA when 'B' then E.RateB when 'C' then E.RateC when 'D' then E.RateD when 'E' then E.RateE when 'F' then E.RateF when 'G' then E.RateG when 'H' then E.RateH ELSE E.RateA end end as Price, B.Amount, B.UserID, R.RoomID, S.Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbBillOPDailyOut B left outer join BUILD_FILE..tbCoOtherRevenueID E on B.ItemID = E.OtherRevenueID and OtherSectionID = 'WC' left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join BUILD_FILE..tbCoRoom R on B.RoomID = R.RoomID left outer join BUILD_FILE..tbCoStation S on R.StationID = S.StationID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum and B.IDNum = @IDNum union all select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, E.ItemName as Exam, B.Quantity, B.amount as Price, B.Amount, '' as UserID, '' as RoomID, '' as Station, '' as DoctorName, @AccountName as AccountName, @Diagnosis as Diagnosis, @Membership as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from INVENTORY..tbInvStockCard B left outer join INVENTORY..tbInvMaster E on B.ItemID = E.ItemID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; else begin select distinct @HospNum as HospNum, B.IdNum as IdNum, @PatientName as PatientName, @Age as Age, @Sex as Sex, isnull(@RequestDate,B.transdate) as RequestDate, B.Transdate, B.RefNum as RefNum, B.RevenueID, B.ItemID as Code, case isnull(B.revenueID,'') when 'MD' then D.LastName + ', ' + D.Firstname + ' ' + d.MiddleName when 'WC' then E.OtherRevenue else M.ItemName end as Exam, B.Quantity, B.Amount as Price, B.Amount, B.UserID, 'CASH' AS RoomID, '' AS Station, D2.LastName + ', ' + D2.Firstname + ' ' + d2.MiddleName as DoctorName, 'CASH' as AccountName, '' as Diagnosis, '' as Membership, PW.LastName + ', ' + PW.Firstname + ' ' + PW.MiddleName as ProcessedBy, @Printed as Printed, isnull(@AdmissionType,'') as AdmissionType, @Portable as Portable from billing..tbCashAssessment B left outer join INVENTORY..tbInvMaster M on B.ItemID = m.ItemID left outer join BUILD_FILE..tbCoOtherRevenueID E on B.ItemID = E.OtherRevenueID and OtherSectionID = 'WC' left outer join BUILD_FILE..tbCoDoctor D on B.ItemId = DoctorID left outer join BUILD_FILE..tbCoDoctor D2 on B.RequestDocID = D2.DoctorID left outer join PASSWORD..tbPasswordMain PW on PW.EmployeeID = B.UserID where RefNum = @RefNum end; end; end; set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrintNurseRequestByIdNum_Mammo] --declare @IdNum as varchar(10), @StationID as varchar(10), @DepartmentID as varchar(10), @HospNum as varchar(10) = null AS --set @IdNum = '9070734' --set @StationID = 'S10' --set @DepartmentID = 'MM' declare @RequestNum as varchar(10) --declare @HospNum as varchar(50) --declare @IdNum as varchar(50) declare @LastName as varchar(50) declare @FirstName as varchar(50) declare @MiddleName as varchar(50) declare @Age as varchar(50) declare @Sex as varchar(50) declare @CStatus as varchar(50) declare @FileNum as varchar(50) declare @Unit as varchar(50) declare @Room as varchar(50) declare @Doctor as varchar(50) declare @RequestDate as varchar(50) declare @ChargeDate as varchar(50) declare @ItemID as varchar(50) declare @ItemName as varchar(50) declare @Medhistory as varchar(50) declare @Account as varchar(50) declare @User as varchar(50) declare @Nurse as varchar(50) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) if isnumeric(@IdNum) = 0 begin Select @Room = 'OPD', @Account = C.Company, @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar),char(13),''))), @BriefHistory = @ChiefComplaints + char(13) + @Findings From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum end; if isnumeric(@IdNum) = 1 begin Select @Room = P.RoomID, @Account = C.Company, @RequestDate = L.RequestDate, @Nurse = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMaster PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.IdNum = @IdNum end; if @DepartmentID = 'MM' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.OtherRevenue, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.LastName+' ,'+P.FirstName+' '+P.MiddleName as Pxname, -- P.lastname, -- P.Firstname, -- p.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum, P.HOUSESTREET+', '+P.BARANGAY+','+Address.town+','+Address.Province+','+Address.ZipCode as Address, ISNULL(P.TELNUM,'') [TELNO] From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemID = E.OtherRevenueID and othersectionid = 'MM' left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID left outer join BUILD_FILE..tbCoAddress Address ON P.ZipCode = Address.ZipCode Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID and R.HospNum = isnull(@Hospnum, R.HospNum) union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.OtherRevenue, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.LastName+' ,'+P.FirstName+' '+P.MiddleName as Pxname, -- P.lastname, -- P.Firstname, -- P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum, P.HOUSESTREET+', '+P.BARANGAY+','+Address.town+','+Address.Province+','+Address.ZipCode as Address, ISNULL(P.TELNUM,'') [TELNO] From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemCode = E.OtherRevenueID left outer join BUILD_FILE..tbCoAddress Address ON P.ZipCode = Address.ZipCode Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.HospNum = isnull(@Hospnum, R.HospNum) UNION ALL Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.OtherRevenue, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.LastName+' ,'+P.FirstName+' '+P.MiddleName as Pxname, -- P.lastname, -- P.Firstname, -- P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum, P.HOUSESTREET+', '+P.BARANGAY+','+Address.town+','+Address.Province+','+Address.ZipCode as Address, ISNULL(cast(P.TELNUM as varchar),'') [TELNO] From TBMAMMOMASTER R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemID = E.OtherRevenueID left outer join BUILD_FILE..tbCoAddress Address ON P.ZipCode = Address.ZipCode Where R.IDNUM= @IDNUM and R.HospNum = isnull(@Hospnum, R.HospNum) end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_PrintResult] --declare @RequestNum as varchar(8) AS --set @Requestnum = '1612' select top 1 B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName as PatientName, B.Age, Case B.Sex When 'M' then 'Male' else 'Female' end as Sex, C.OtherRevenue Exam, case isnumeric(A.IdNum) when '1' then P.RoomID else 'OPD' end Room, A.RequestDate as ExamDate, D.LastName + ', ' + D.FirstName + ' ' + isnull(D.MiddleName,'') as Attending, E.FirstName + ' ' + E.MiddleName + ' ' + E.LastName + ', M.D., FPCR' as Radiologist, A.Hospnum,A.RequestNum,A.Idnum,A.RoomID,A.SWFIN,A.Itemid,A.RequestDate,A.resultdate,A.DoctorID, A.Interpretation,A.RadiologistiD,B.Mammonum as FileNum, F.LastName+' ,'+F.FirstName+ ', RRT' as Radtech from Radiology..tbMammoResult A Inner Join radiology..vwpatientmaster B on A.HospNum = B.HospNum Left Join Patient_Data..tbPatient P on A.Idnum = P.Idnum Left Join Build_File..tbcoOtherRevenue C on A.itemID = C.otherRevenueID and othersectionid = 'MM' Left Join Build_File..tbcoDoctor D on P.AttendingDr1 = D.DoctorID Left Join Build_File..tbcoDoctor E on a.RadiologistID = E.DoctorID Left Outer Join Password..tbPasswordMain F on A.userId = F.Employeeid Where A.RequestNum = @RequestNum --select * from Radiology..tbMammoResult GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_GetResultPrint] @Requestnum as varchar(15) AS select H.HospNum, H.IdNum, M.LastName + ', ' + M.Firstname + ' ' + M.MiddleName as PatientName, M.Sex, M.BirthDate, RADIOLOGY.dbo.fn_ComputeAge (M.BirthDate,getdate()) as Age , M.HouseStreet + ' ' + M.Barangay + ', ' + A.Province as Address, D.LastName + ', ' + D.Firstname + ' ' + D.MiddleName as DoctorName, E.OtherRevenueID as ItemID, E.OtherRevenue as Exam, isnull(E.Formtype,'') as FormType, isnull(P.RoomID,'OPD'), H.ResultDate, H.requestnum, isnull(H.XrayNum,'') as Filenum, replace(cast(h.Interpretation as varchar(2000)),' ','') as Interpretation, case isnull(DensityCode,'') when '1' then 'The breast is entirely fat.' when '2' then 'There are scattered fibrograndular densities that could obscure a lesion on mammography.' when '3' then 'The breast is heterogeneously dense. This may lower the sensitivity of the mammography.' when '4' then 'The breast is extremely dense with lowers the sensitivity of the mammography.' else '' end as Density, case isnull(FindingsCode,'') when '1' then 'Category 0 - Need additional imaging evaluation.' when '2' then 'Category 1 - Negative.' when '3' then 'Category 2 - Benign finding.' when '4' then 'Category 4 - Suspicious abnormality; biopsy should be considered.' when '5' then 'Category 5 - Highly suggestive of malignancy; appropriate action should be taken.' else '' end as Findings, case isnull(RD.LastName,'') when '' then H.Radiologist else RD.LastName + ', ' + RD.Firstname + ' ' + RD.MiddleName end as Radiologist, H.RequestDate, MM.RefNum from radiology..tbMammoResult H INNER JOIN RADIOLOGY..tbMammoMaster MM on H.RequestNum = MM.RequestNum LEFT OUTER JOIN RADIOLOGY.DBO.vwPatientMaster M on H.HospNum = M.HospNum LEFT OUTER JOIN PATIENT_DATA..tbPatient P on H.IdNum = P.IdNum LEFT OUTER JOIN BUILD_FILE..tbCoOtherRevenue E on H.ItemID = E.OtherRevenueID and E.OtherSectionID = 'MM' LEFT OUTER JOIN BUILD_FILE..tbCoAddress A on M.ZipCode = A.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on H.DoctorId = D.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor RD on H.RadiologistID = RD.DoctorID where H.requestnum = @Requestnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_RadiologistPatientList_CG] @RadCode AS varchar(3), @BeginDate AS varchar(10), @EndDate AS varchar(10) AS /* declare @RadCode AS varchar(3), @BeginDate AS varchar(10), @EndDate AS varchar(10) set @RAdCode = '124' Set @BeginDate = '06/01/2010' Set @EndDate = '06/30/2010' */ SELECT A.XrayNum, A.RoomID, E.Lastname, E.Firstname, A.ExamTaken, B.Amount, B.RefNum, F.Firstname AS Fname, F.Middlename AS Mname, F.Lastname AS Lname, F.Title, case when p.HospNum <> p.accountnum then (SELECT isnull(Company,'Non-Member') from BUILD_FILE..tbCoCompany where AccountNum = P.AccountNum) else 'Non-Member' end as AccountNum, B.TransDate, A.IDNum FROM tbXRResult A LEFT OUTER JOIN tbXRRequest B ON A.RequestNum = B.RequestNum LEFT OUTER JOIN Patient_Data..tbMaster D ON A.HospNum = D.HospNum LEFT OUTER JOIN vwpatientmaster E ON A.HospNum = E.HospNum LEFT OUTER JOIN Build_File..tbCoDoctor F ON A.RadCode = F.DoctorID LEFT OUTER JOIN (Select AccountNum, IDNum, HospNum From PATIENT_DATA..tbPatient Union All Select AccountNum, IDNum, HospNum From PATIENT_DATA..tbOutPatient) P on A.HospNum = P.HospNum And A.IDNum = P.IDNum WHERE (B.Transdate >= @BeginDate AND B.Transdate < @EndDate + ' 23:59:59.99') AND A.RadCode = @RadCode AND NOT ISNULL(A.ResultDate, '') = '' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_DailyFilmRep] @Date AS varChar(10) AS /* declare @Date AS varChar(10), @UserID as varchar(10) */ Declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = cast(@Date as datetime) set @ReportDate2 = dateadd(day, 1, @ReportDate1) SELECT tbXRRequest.HospNum, tbXRRequest.IdNum, RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, E.XRayExam as Description, isnull(case left(ltrim(Bill.Refnum),2) when 'OR' then Bill.ChargeSlip when 'CC' then Bill.ChargeSlip else Bill.Refnum end,'') AS CSlip, isnull(case left(ltrim(Bill.Refnum),2) when 'OR' then Bill.refNum when 'CC' then Bill.RefNum else Bill.ChargeSlip end,'') AS OrNumber, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, tbXRRequest.[By] as UserID, PW.initial as RD, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest INNER JOIN BILLING..tbBillDailyBill Bill ON tbXRRequest.RefNum = Bill.RefNum and tbXRRequest.Code = Bill.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on tbXRRequest.[By] = PW.EmployeeID WHERE isnumeric(tbXRRequest.IDNUm) = 1 AND (tbXRRequest.TransDate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin <>'C' OR tbXRRequest.SwFin = 'R') union all SELECT tbXRRequest.HospNum, tbXRRequest.IdNum, case isnull(tbXRRequest.HospNum,'') when '' then (Select PaymentFrom From Billing..tbCashORMaster Where Refnum = Bill.RefNum) else RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) end AS PatientName, tbXRRequest.RoomID, E.XrayExam as Description, case left(ltrim(Bill.Refnum),2) when 'OR' then Bill.ChargeSlip when 'CC' then Bill.ChargeSlip else Bill.Refnum end AS CSlip, isnull(case left(ltrim(Bill.Refnum),2) when 'OR' then Bill.refNum when 'CC' then Bill.RefNum else Bill.ChargeSlip end,'') AS OrNumber, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, tbXRRequest.[By] as UserID, PW.initial as RD, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest INNER JOIN BILLING..tbBillOPDailyOut Bill ON tbXRRequest.RefNum = Bill.RefNum and tbXRRequest.Code = Bill.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on tbXRRequest.[By] = PW.EmployeeID WHERE ISNUMERIC(tbXRRequest.IDNum) = 0 AND (tbXRRequest.Transdate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin <> 'R' OR tbXRRequest.SwFin <> 'C'); GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_PrintResult2] @RequestNum as varchar(8) AS --SET @REQUESTNUM = '11' select B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName as PatientName, B.Age, Case B.Sex When 'M' then 'Male' else 'Female' end as Sex, C.OtherRevenue Exam, --case when isnumeric(A.IdNum) = 1 then P.RoomID else 'OPD' end Room, --A.RequestDate as ExamDate, D.LastName + ', ' + D.FirstName + ' ' + isnull(D.MiddleName,'') as Attending, A.HospNum, --A.RequestNum, A.IDNum, A.RoomID, --A.XRayNum, --A.SWFIN, --A.DrCr, --A.ItemID, A.RequestDate, --A.ResultDate, --A.TransDate, --A.LTIME, --A.DoctorID, A.Interpretation, --A.RadiologistID, A.Radiologist --, --A.UserID, --A.EDEYT, --A.TECHNICIAN, --A.SIGN, --A.SNO, --A.TEMPO, --A.CSLIP, --A.OR, --A.DensityCode, --A.FindingsCode from Radiology..tbMammoResult A Inner Join radiology..vwpatientmaster B on A.HospNum = B.HospNum Left Join Patient_Data..tbPatient P on A.Idnum = P.Idnum Left Join Build_File..tbcoOtherRevenue C on A.itemID = C.otherRevenueID Left Join Build_File..tbcoDoctor D on P.AttendingDr1 = D.DoctorID Where A.RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_ResultMaster] @RevenueID varchar(2), @Criteria varchar(50), @Type Varchar(1) ='1' AS if @RevenueID = 'MI' begin IF @Type = '1' BEGIN select distinct m.hospnum HospNum,r.IDNum IDNum, m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m inner join tbMRIrequest r on m.hospnum = r.hospnum where isnull(r.swfin,'') IN ('Y') and m.lastname like @Criteria + '%' and Isnull(r.Code,'') <> '263' order by m.lastname, m.firstname, m.middlename; END ELSE BEGIN select distinct m.hospnum HospNum,r.IDNum IDNum, m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m inner join tbMRIrequest r on m.hospnum = r.hospnum where isnull(r.swfin,'') IN ('Y') and --m.lastname like @Criteria + '%' r.IDNum = Ltrim(Rtrim(@Criteria)) and Isnull(r.Code,'') <> '263' order by m.lastname, m.firstname, m.middlename; END end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered by Jetty P. Omo December 02,2007 This will only show the list of patient under the log-in code added an option to view all for radiologist to see the work of the resident doctors Legend @Mode: If @Mode is true then it will show the verified results else it will only show the list of exams for verification */ CREATE PROCEDURE [dbo].[spRadio_RequestMaster] @Type varchar(1), @RevenueID varchar(2), @Criteria varchar(50), @DoctorID varchar(20),-- = '', @Mode varchar(2) = '', @Patient varchar(20) = null /* set @Type = '1' set @RevenueID = 'XR' set @Criteria = '' set @DoctorID = '' */ AS if @RevenueID = 'XR' begin if @Mode = 1 Begin if @Doctorid = '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is not null and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename end if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is not null and isnumeric(outp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is not null and r.idnum = 'cash' order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is not null --and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End End else -- if doctor is not '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum inner join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and RadCode = @DoctorID and verifybyid is not null and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum inner join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and RadCode = @DoctorID and verifybyid is not null and isnumeric(outp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and RadCode = @DoctorID and verifybyid is not null and r.idnum = 'CASH' order by m.lastname, m.firstname, m.middlename End else begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and RadCode = @DoctorID and verifybyid is not null --and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename end End end else -- if not mode 1 Begin if @Doctorid = '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum inner join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and verifybyid is null order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and verifybyid is null order by m.lastname, m.firstname, m.middlename End IF @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'CASH' and verifybyid is null order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null order by m.lastname, m.firstname, m.middlename End End else Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum inner join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'CASH' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbxrrequest r on m.hospnum = r.hospnum Inner join tbxrresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End End End End /* select * from vwpatientmaster select * from tbctresult patient_data..tbpatient */ if @RevenueID = 'CT' begin if @Mode = 1 Begin if @Doctorid = '' Begin if @Patient = '1' --if patient is inpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tbpatient inp on inp.idnum = r.idnum --and inp.idnum = result.idnum --select * from tbctrequest where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End if @Patient = '2' ---if patient is outpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum --and outp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End IF @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' order by m.lastname, m.firstname, m.middlename End Else --if both patients Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum /*Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum select * from patient_data..tboutpatient Inner join patient_data..tbpatient inp on inp.idnum = r.idnum*/ where m.lastname like @Criteria + '%' and r.HospNum <> 'C' --and isnumeric(inp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End End else --if doctor is not '' Begin if @patient = '1' --if patient is inpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tbpatient Inp on inp.idnum = r.idnum --and inp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and RadCode = @DoctorID--verifyByID = @DoctorID--RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '2' -- if patient is outpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum --and outp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and RadCode = @DoctorID--verifyByID = @DoctorID--transcribedbyid = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' and RadCode = @DoctorID--verifyByID = @DoctorID--transcribedbyid = @DoctorID order by m.lastname, m.firstname, m.middlename End Else -- if both in and out patients Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum /*Inner Join patient_data..tbpatient Inp on inp.idnum = r.idnum inner join patient_data..tbpatient outp on outp.idnum = r.idnum*/ where m.lastname like @Criteria + '%' and r.HospNum <> 'C'-- and isnumeric(inp.idnum) = '1' and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End End end else -- if mode is not 1 Begin if @Doctorid = '' Begin if @patient = '1' --if patient is inpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tbpatient inp on inp.idnum = r.idnum and inp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and verifybyid is null order by m.lastname, m.firstname, m.middlename End if @patient = '2' --if outpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum and outp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and verifybyid is null order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' and verifybyid is null order by m.lastname, m.firstname, m.middlename End else -- in and outpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum /*Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum inner join patient_data..tbpatient inp on inp.idnum = r.idnum*/ where m.lastname like @Criteria + '%' and r.HospNum <> 'C' --and isnumeric(outp.idnum) = '0' and verifybyid is null order by m.lastname, m.firstname, m.middlename End End else -- if doctor is not '' Begin if @patient = '1' -- if inpatient Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tbpatient inp on inp.idnum = r.idnum --and inp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null and RadCode = @DoctorID and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum Inner join patient_data..tboutpatient outp on outp.idnum = r.idnum -- and outp.idnum = result.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null and RadCode = @DoctorID and isnumeric(outp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null and RadCode = @DoctorID and r.idnum = 'cash' order by m.lastname, m.firstname, m.middlename End Else -- if in and out Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbCTrequest r on m.hospnum = r.hospnum Inner join tbCTresult Result on R.Requestnum = Result.Requestnum /*Inner join patient_data..tbpatient inp on inp.idnum = r.idnum inner join patient_data..tboutpatient outp on outp.idnum = r.idnum*/ where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and verifybyid is null and RadCode = @DoctorID --and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End End End End if @RevenueID = 'US' begin if @Mode = 1 Begin if @Doctorid = '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' order by m.lastname, m.firstname, m.middlename End End else --if not doctor = '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner join tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.dinum) = '1' and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner join tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.dinum) = '0' and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' --and isnumeric(inp.dinum) = '1' and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End End end else --if not mode 1 Begin if @Doctorid = '' Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and verifybyid is null order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and verifybyid is null order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' and verifybyid is null order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' --and isnumeric(inp.idnum) = '1' and verifybyid is null order by m.lastname, m.firstname, m.middlename End End else -- if doctor is not '' and mode is not 1 Begin if @patient = '1' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tbpatient inp on inp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(inp.idnum) = '1' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '2' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum Inner Join patient_data..tboutpatient outp on outp.idnum = r.idnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and isnumeric(outp.idnum) = '0' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End if @patient = '3' Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' and r.idnum = 'cash' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End else Begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m Inner join tbULrequest r on m.hospnum = r.hospnum Inner join tbULresult Result on R.Requestnum = Result.Requestnum where m.lastname like @Criteria + '%' and r.HospNum <> 'C' --and isnumeric(inp.dinum) = '1' and verifybyid is null and RadCode = @DoctorID order by m.lastname, m.firstname, m.middlename End End End End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrintOPDRequest] @Requestnum as varchar(10), @DepartmentID as varchar(10) AS /* declare @Requestnum as varchar(10) declare @DepartmentID as varchar(10) set @Requestnum = 'XR11083' set @DepartmentID = 'XR' */ declare @HospNum as varchar(50) declare @IdNum as varchar(50) declare @LastName as varchar(50) declare @FirstName as varchar(50) declare @MiddleName as varchar(50) declare @Age as varchar(50) declare @Sex as varchar(50) declare @CStatus as varchar(50) declare @FileNum as varchar(50) declare @Unit as varchar(50) declare @Room as varchar(50) declare @Doctor as varchar(50) declare @RequestDate as varchar(50) declare @ChargeDate as varchar(50) declare @ItemID as varchar(50) declare @ItemName as varchar(50) declare @Medhistory as varchar(50) declare @Account as varchar(50) declare @User as varchar(50) declare @Nurse as varchar(50) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) declare @BirthDate as varchar(10) if @DepartmentID = 'XR' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.XrayExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101) From PATIENT_DATA..tbOPDCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoXrayExam E On R.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if @DepartmentID = 'US' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.UltraExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101) From PATIENT_DATA..tbOPDCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoUltraExam E On R.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if @DepartmentID = 'CT' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.CTExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101) From PATIENT_DATA..tbOPDCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoCTExam E On R.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if isnumeric(@IdNum) = 0 begin Select @Room = 'OPD', @Account = C.Company, @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar),char(13),''))), @BriefHistory = @ChiefComplaints + char(13) + @Findings From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum end; if isnumeric(@IdNum) = 1 begin Select @Room = P.RoomID, @Account = C.Company, @RequestDate = L.RequestDate, @Nurse = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMaster PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.RequestNum = @Requestnum end; select @RequestNum as RequestNum, @HospNum as HospNum, @IdNum as IdNum, @LastName as LastName, @FirstName as FirstName, @MiddleName as MiddleName, @Age as Age, @Sex as Sex, @CStatus as CivilStatus, @FileNum as FileNum, @Unit as Unit, @Room as Room, @Doctor as Doctor, @RequestDate as RequestDate, @ChargeDate as ChargeDate, @ItemID as ItemId, @ItemName as ItemName, @Account as Account, @User as UserName, @Nurse as Nurse, @ChiefComplaints as ChiefComplaints, @Diagnosis as Diagnosis, @Findings as Findings, @BriefHistory as BriefHistory, @BirthDate as BirthDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrintNurseRequest] --declare @Requestnum as varchar(10), @DepartmentID as varchar(10) AS --select * from radiology..tbulrequest where idnum = '6960' --set @Requestnum = '4807' --set @DepartmentID = 'XR' declare @HospNum as varchar(50) declare @IdNum as varchar(50) declare @LastName as varchar(50) declare @FirstName as varchar(50) declare @MiddleName as varchar(50) declare @Age as varchar(50) declare @Sex as varchar(50) declare @CStatus as varchar(50) declare @FileNum as varchar(50) declare @Unit as varchar(50) declare @Room as varchar(50) declare @Doctor as varchar(50) declare @RequestDate as varchar(50) declare @ChargeDate as varchar(50) declare @ItemID as varchar(50) declare @ItemName as varchar(50) declare @Medhistory as varchar(50) declare @Account as varchar(50) declare @User as varchar(50) declare @Nurse as varchar(50) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) declare @BirthDate as varchar(10) declare @Remarks as varchar(50) declare @ImagingReason as varchar(50) declare @SurgicalReason as varchar(50) if @DepartmentID = 'XR' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.XrayExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101), @Remarks = R.Remarks From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoXrayExam E On R.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if @DepartmentID = 'US' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.UltraExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101), @Remarks = R.Remarks From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoUltraExam E On R.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if @DepartmentID = 'CT' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.CTExam, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101), @Remarks = R.Remarks From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoCTExam E On R.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if @DepartmentID = 'WC' begin Select distinct @IdNum = R.IdNum, @HospNum = R.HospNum, @requestNum = R.requestNum, @ItemId = r.ItemID, @ItemName = E.OtherRevenue, @ChargeDate = r.RequestDate, @Doctor = isnull(D.LastName,'') + ', ' + isnull(D.Firstname,''), @User = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @Lastname = P.lastname, @Firstname = P.Firstname, @Middlename = P.MiddleName, @Age = P.Age, @Sex = P.Sex, @CStatus = P.CivilStatus, @BirthDate = convert(varchar(10), P.BirthDate, 101), @Remarks = R.Remarks From station..tbNurseCommunicationFile R left outer join Radiology..vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemID = E.OtherRevenueID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.UserID = PWORD.EmployeeID Where R.RequestNum = @Requestnum and R.RevenueID = @DepartmentID end; if isnumeric(@IdNum) = 0 begin Select @Room = 'OPD', @Account = C.Company, @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar),char(13),''))), @BriefHistory = @ChiefComplaints + char(13) + @Findings, @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar),char(13),''))) From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum end; if isnumeric(@IdNum) = 1 begin Select @Room = P.RoomID, @Account = C.Company, @RequestDate = L.RequestDate, @Nurse = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar),char(13),''))), @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMain PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.RequestNum = @Requestnum end; select @RequestNum as RequestNum, @HospNum as HospNum, @IdNum as IdNum, @LastName as LastName, @FirstName as FirstName, @MiddleName as MiddleName, @Age as Age, @Sex as Sex, @CStatus as CivilStatus, @FileNum as FileNum, @Unit as Unit, @Room as Room, @Doctor as Doctor, @RequestDate as RequestDate, @ChargeDate as ChargeDate, @ItemID as ItemId, @ItemName as ItemName, @Account as Account, @User as UserName, @Nurse as Nurse, @ChiefComplaints as ChiefComplaints, @Diagnosis as Diagnosis, @Findings as Findings, @BriefHistory as BriefHistory, @BirthDate as BirthDate, @Remarks as Remarks, @ImagingReason as ImagingReason, @SurgicalReason as SurgicalReason GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_RequestData] @Requestnum as varchar(10), @RevenueId as varchar(2) AS /* DECLARE @Requestnum as varchar(10), @RevenueId as varchar(2) set @RequestNum = '121901' set @RevenueId = 'XR' */ if @RevenueID = 'XR' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, R.Code, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbXrRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE RequestNum = @RequestNum end; if @RevenueID = 'US' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, R.Code, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbULRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE RequestNum = @RequestNum end; if @RevenueID = 'CT' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, R.Code, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbCTRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE RequestNum = @RequestNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_RequestDataByRefNum] @RefNum as varchar(10), @HospNum as varchar(10), @RevenueId as varchar(2) AS /* DECLARE @RefNum as varchar(10), @RevenueId as varchar(2) set @RefNum = '121901' set @RevenueId = 'XR' */ if @RevenueID = 'XR' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbXrRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE (RefNum = @RefNum OR R.HospNum = @HospNum) and (isnull(R.Hospnum,'') <> '' and isnull(R.RefNum,'') <> '') end; if @RevenueID = 'US' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbULRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE (RefNum = @RefNum OR R.HospNum = @HospNum) and (isnull(R.Hospnum,'') <> '' and isnull(R.RefNum,'') <> '') end; if @RevenueID = 'CT' begin SELECT R.HospNum, R.IdNum, dbo.fn_RadioGetFileNum(@RevenueId, R.HospNum) as FileNum, M.FirstName, M.MiddleName, M.LastName, M.Sex, laboratory.dbo.fn_LabComputeAge(M.BirthDate,getdate()) as Age, R.refNum, R.TransDate, dbo.fn_RadioGetExamName(@RevenueId,R.Code) as Exam, R.RequestDoctorCode, case isnull(R.RequestDoctorCode,'') when '' then R.DoctorName when '0' then R.DoctorName else D.FirstName + ' ' + D.LastName end as DoctorName, isnull(R.SWFin,'') as ResultStatus, isnull(R.Logbook,'') as LogbookStatus FROM tbCTRequest R left outer join dbo.vwPatientMaster M on R.Hospnum = M.HospNum left outer join BUILD_FILE..tbCoDoctor D on R.RequestDoctorCode = D.DoctorID WHERE (RefNum = @RefNum OR R.HospNum = @HospNum) and (isnull(R.Hospnum,'') <> '' and isnull(R.RefNum,'') <> '') end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGlobal_ViewAge] @strHospNum as varchar(10) AS select radiology.dbo.fn_ComputeAge(Birthdate,getdate()) as Age from radiology..vwPatientMaster where hospnum = @strHospNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_RadiologistPatientList] @RadCode AS varchar(3), @BeginDate AS varchar(10), @EndDate AS varchar(10) AS /* declare @RadCode AS varchar(3), @BeginDate AS varchar(10), @EndDate AS varchar(10) set @RAdCode = '124' Set @BeginDate = '06/01/2010' Set @EndDate = '06/30/2010' */ SELECT A.XrayNum, A.RoomID, E.Lastname, E.Firstname, A.ExamTaken, B.Amount, B.RefNum, F.Firstname AS Fname, F.Middlename AS Mname, F.Lastname AS Lname, F.Title, case when p.hospnum <> p.accountnum then (SELECT isnull(Company,'Non-Member') from BUILD_FILE..tbCoCompany where AccountNum = P.AccountNum) else 'Non-Member' end as AccountNum , B.TransDate, A.IDNum FROM tbXRResult A LEFT OUTER JOIN tbXRRequest B ON A.RequestNum = B.RequestNum --LEFT OUTER JOIN tbXRFileNum C ON A.Hospnum = C.Hospnum //Disabled By Raymund Tacuban Due to double output 01.27.2010// LEFT OUTER JOIN Patient_Data..tbMaster D ON A.Hospnum = D.Hospnum LEFT OUTER JOIN vwpatientmaster E ON A.Hospnum = E.Hospnum LEFT OUTER JOIN Build_File..tbCoDoctor F ON A.RadCode = F.DoctorID LEFT OUTER JOIN (Select AccountNum, IDNum, HospNum From PATIENT_DATA..tbPatient Union All Select AccountNum, IDNum, HospNum From PATIENT_DATA..tbOutPatient) P on A.HospNum = P.HospNum And A.IDNum = P.IDNum WHERE (B.Transdate >= @BeginDate AND B.Transdate < @EndDate + ' 23:59:59.99') AND A.RadCode = @RadCode AND NOT ISNULL(A.ResultDate, '') = '' --select radcode,resultdate,* from tbxrresult where year(resultdate) = 2010 and month(resultdate) = 6 -- --select * from tbxrrequest where year(transdate) = 2010 and month(transdate) = 6 --union all -- -- --SELECT A.XrayNum, A.RoomID, E.Lastname, E.Firstname, A.ExamTaken, B.Amount, B.RefNum, --F.Firstname AS Fname, F.Middlename AS Mname, F.Lastname AS Lname, F.Title, --case when po.hospnum <> pO.accountnum then (SELECT isnull(Company,'Non-Member') from BUILD_FILE..tbCoCompany where AccountNum = PO.AccountNum) else 'Non-Member' end as AccountNum -- --FROM tbXRResult A LEFT OUTER JOIN tbXRRequest B --ON A.RequestNum = B.RequestNum LEFT OUTER JOIN tbXRFileNum C --ON A.Hospnum = C.Hospnum LEFT OUTER JOIN Patient_Data..tbMaster D --ON A.Hospnum = D.Hospnum LEFT OUTER JOIN vwpatientmaster E --ON A.Hospnum = E.Hospnum LEFT OUTER JOIN Build_File..tbCoDoctor F --ON A.RadCode = F.DoctorID --LEFT OUTER JOIN PATIENT_DATA..tboutpatient PO --on A.HospNum = PO.HospNum --WHERE (A.Transdate >= @BeginDate AND A.Transdate < @EndDate) --AND A.RadCode = @RadCode --AND NOT ISNULL(A.ResultDate, '') = '' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchRequestFileNum] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) AS if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'CT' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], CTExam [Exam], CTSectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbCTRequest R left join build_file..tbCoCTExam on R.Code = CTExamID where @SearchCriteria = R.RequestNum end if @SearchRevenue = 'XR' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], XRayExam [Exam], XRaySectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbXRRequest R left join build_file..tbCoXRayExam on R.Code = XRayExamID --where @SearchCriteria like '%' + R.RequestNum + '%' where @SearchCriteria = R.RequestNum end if @SearchRevenue = 'US' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], UltraExam [Exam], UltraSectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbULRequest R left join build_file..tbCoUltraExam on R.Code = UltraExamID -- where @SearchCriteria like '%' + R.RequestNum + '%' where @SearchCriteria = R.RequestNum end end if @SearchType = '1' -- Search by FileNum begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.CTExam [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.CTNum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.XRayExam [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.XrayNum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.UltraExam [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoUltraExam c on r.code = c.Ultraexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.UltraNum like @SearchCriteria + '%' -- and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.CTExam [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' -- and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.XRayExam [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.UltraExam [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoUltraExam c on r.code = c.Ultraexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ResultLogbook] @RevenueID as varchar(2), @Mode as varchar(1) AS if @Mode = 'A' -- Show All begin select R.Rank, R.RequestNum, R.HospNum, dbo.fn_RadioGetFileNum (R.RevenueID, R.HospNum) as FileNum, P.LastName + ', ' + P.Firstname + ' ' + isnull(P.MiddleName,'') as PatientName, R.RefNum, R.ItemID, dbo.fn_RadioGetExamName (R.RevenueID,R.ItemID) as Exam, isnull(R.Remarks,'') as Remarks, case isnull(R.Status,'') when 'D' then 'Done' when 'V' then 'Verified' when 'P' then 'Printed' else 'Pending' end as Status, R.transDate, isnull(R.UserID,'') as UserID, isnull(dbo.fn_RadioGetUserName (R.UserID),'') as UserID, isnull(R.Status,'') as StatusCode from tbradioResultLog R left outer join vwPatientMaster P ON R.Hospnum = P.HospNum where R.RevenueID = @RevenueID and ResultDate between convert(varchar(10),getdate(),101) and getdate() order by R.Rank asc end; if @Mode = 'B' -- Show Only Pending begin select R.Rank, R.RequestNum, R.HospNum, dbo.fn_RadioGetFileNum (R.RevenueID, R.HospNum) as FileNum, P.LastName + ', ' + P.Firstname + ' ' + isnull(P.MiddleName,'') as PatientName, R.RefNum, R.ItemID, dbo.fn_RadioGetExamName (R.RevenueID,R.ItemID) as Exam, isnull(R.Remarks,'') as Remarks, case isnull(R.Status,'') when 'D' then 'Done' when 'V' then 'Verified' when 'P' then 'Printed' else 'Pending' end as Status, R.transDate, isnull(R.UserID,'') as UserID, isnull(dbo.fn_RadioGetUserName (R.UserID),'') as UserID, isnull(R.Status,'') as StatusCode from tbradioResultLog R left outer join vwPatientMaster P ON R.Hospnum = P.HospNum where R.RevenueID = @RevenueID and ResultDate between convert(varchar(10),getdate(),101) and getdate() and isnull(R.Status ,'') not in ('D','V','P') order by R.Rank asc end; if @Mode = 'C' -- Show Only with result begin select R.Rank, R.RequestNum, R.HospNum, dbo.fn_RadioGetFileNum (R.RevenueID, R.HospNum) as FileNum, P.LastName + ', ' + P.Firstname + ' ' + isnull(P.MiddleName,'') as PatientName, R.RefNum, R.ItemID, dbo.fn_RadioGetExamName (R.RevenueID,R.ItemID) as Exam, isnull(R.Remarks,'') as Remarks, case isnull(R.Status,'') when 'D' then 'Done' when 'V' then 'Verified' when 'P' then 'Printed' else 'Pending' end as Status, R.transDate, isnull(R.UserID,'') as UserID, isnull(dbo.fn_RadioGetUserName (R.UserID),'') as UserID, isnull(R.Status,'') as StatusCode, '' as Tag from tbradioResultLog R left outer join vwPatientMaster P ON R.Hospnum = P.HospNum where R.RevenueID = @RevenueID and ResultDate between convert(varchar(10),getdate(),101) and getdate() and isnull(R.Status ,'') in ('D','V') order by R.Rank asc end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_VerificationList] @Type AS varChar(1), @Names AS varChar(30), @Encoder as varchar(20) = '', @Mode As varchar(1) = '' AS if @Encoder = '' Begin IF @Type = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbCTRequest.Code AS Code, -- tbCTRequest.TypeDescription AS Description dbo.fn_GetExamDescription( tbCTRequest.Code, 'CT') AS Description, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDdate, tbCTRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + Case When tbCTRequest.RequestDoctorCode = '0' Then tbCTRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbCTResult.Interpretation, tbCTResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbCTResult.TranscribedByID FROM tbCTRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum /* LEFT OUTER JOIN PATIENT_DATA..tbMaster tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum */ LEFT OUTER JOIN tbCTResult ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbCTResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbCTResult.VerifyByID,'') = '') and --(isnull(tbCTResult.VerifyDate,'') = '') tbCTResult.VerifyDate is null ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END IF @Type = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbXRRequest.Code AS Code, -- tbXRRequest.TypeDescription AS Description, dbo.fn_GetExamDescription( tbXRRequest.Code, 'XR') AS Description, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDdate, tbXRRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + Case When tbXRRequest.RequestDoctorCode = '0' Then tbXRRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbXRResult.Interpretation, tbXRResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbXRResult.TranscribedByID FROM tbXRRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXRRequest.HospNum = tbMaster.HospNum Inner Join tbXRResult On tbXRRequest.RequestNum = tbXRResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [Radio] ON tbXRResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbXRResult.VerifyByID,'') = '') and tbXRResult.VerifyDate is null ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END IF @Type = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbULRequest.Code AS Code, dbo.fn_GetExamDescription( tbULRequest.Code, 'US') AS Description, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDdate, tbULRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + Case When tbULRequest.RequestDoctorCode = '0' Then tbULRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbULResult.Interpretation, tbULResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbULResult.TranscribedByID FROM tbULRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbULResult ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbULResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbULResult.VerifyByID,'') = '') and tbULResult.VerifyDate is null ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END end else Begin if @Mode = '1' Begin IF @Type = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbCTRequest.Code AS Code, dbo.fn_GetExamDescription( tbCTRequest.Code, 'CT') AS Description, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDdate, tbCTRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + Case When tbCTRequest.RequestDoctorCode = '0' Then tbCTRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbCTResult.Interpretation, tbCTResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbCTResult.TranscribedByID FROM tbCTRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCTResult ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbCTResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND tbCTResult.VerifyByID = @Encoder and tbCTResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END IF @Type = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbXRRequest.Code AS Code, dbo.fn_GetExamDescription( tbXRRequest.Code, 'XR') AS Description, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDdate, tbXRRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + Case When tbXRRequest.RequestDoctorCode = '0' Then tbXRRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbXRResult.Interpretation, tbXRResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbXRResult.TranscribedByID FROM tbXRRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXRRequest.HospNum = tbMaster.HospNum Inner Join tbXRResult On tbXRRequest.RequestNum = tbXRResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [Radio] ON tbXRResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND tbXRResult.VerifyByID = @Encoder and tbXRResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName end IF @Type = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbULRequest.Code AS Code, dbo.fn_GetExamDescription( tbULRequest.Code, 'US') AS Description, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDdate, tbULRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + Case When tbULRequest.RequestDoctorCode = '0' Then tbULRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbULResult.Interpretation, tbULResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbULResult.TranscribedByID FROM tbULRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbULResult ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbULResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND tbULResult.VerifyByID = @Encoder and tbULResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName End end else Begin IF @Type = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbCTRequest.Code AS Code, dbo.fn_GetExamDescription( tbCTRequest.Code, 'CT') AS Description, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDdate, tbCTRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbCTRequest.RequestDoctorCode + ' - ' + Case When tbCTRequest.RequestDoctorCode = '0' Then tbCTRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbCTResult.Interpretation, tbCTResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbCTResult.TranscribedByID FROM tbCTRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbCTResult ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbCTResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbCTResult.VerifyByID,'') = '') and --(isnull(tbCTResult.VerifyDate,'') = '') tbCTResult.VerifyDate is null and tbCTResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END IF @Type = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbXRRequest.Code AS Code, dbo.fn_GetExamDescription( tbXRRequest.Code, 'XR') AS Description, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDdate, tbXRRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbXRRequest.RequestDoctorCode + ' - ' + Case When tbXRRequest.RequestDoctorCode = '0' Then tbXRRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbXRResult.Interpretation, tbXRResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbXRResult.TranscribedByID FROM tbXRRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXRRequest.HospNum = tbMaster.HospNum Inner Join tbXRResult On tbXRRequest.RequestNum = tbXRResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [Radio] ON tbXRResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbXRResult.VerifyByID,'') = '') and tbXRResult.VerifyDate is null and tbXRResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName end IF @Type = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbULRequest.Code AS Code, dbo.fn_GetExamDescription( tbULRequest.Code, 'US') AS Description, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDdate, tbULRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbULRequest.RequestDoctorCode + ' - ' + Case When tbULRequest.RequestDoctorCode = '0' Then tbULRequest.DoctorName Else tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname End AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbULResult.Interpretation, tbULResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist, tbULResult.TranscribedByID FROM tbULRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbULResult ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbULResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbULResult.VerifyByID,'') = '') and tbULResult.VerifyDate is null and tbULResult.TranscribedByID = @Encoder ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END End end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_Patient_ResultMaster] @RevenueID varchar(2), @Criteria varchar(50), @Type Varchar(1) ='1' AS if @RevenueID = 'MI' begin IF @Type = '1' BEGIN select distinct m.hospnum HospNum,r.IDNum IDNum, m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m inner join tbMRIrequest r on m.hospnum = r.hospnum where --isnull(r.swfin,'') IN ('Y') and m.lastname like @Criteria + '%' and Isnull(r.Code,'') <> '263' order by m.lastname, m.firstname, m.middlename; END ELSE BEGIN select distinct m.hospnum HospNum,r.IDNum IDNum, m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name] from vwpatientmaster m inner join tbMRIrequest r on m.hospnum = r.hospnum where --isnull(r.swfin,'') IN ('Y') and --m.lastname like @Criteria + '%' r.IDNum = Ltrim(Rtrim(@Criteria)) and Isnull(r.Code,'') <> '263' order by m.lastname, m.firstname, m.middlename; END end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SearchRequest] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) AS if @SearchType = '0' -- Search by RequestNum Begin if @SearchRevenue = 'WC' select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], OtherRevenue [Exam], SectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbOBULRequest R left join build_file..tbcoOtherRevenue on R.Code = OtherRevenueID where R.RequestNum = @SearchCriteria end if @SearchType = '1' -- Search by Name Begin if @SearchRevenue = 'WC' -- in ob select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.OtherRevenue [Description], convert(varchar, r.transdate, 101) [Date] from tbOBULRequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbcoOtherRevenue c on r.code = c.OtherRevenueID where isnull(r.swfin, '') in ('', 'X') and m.lastname like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'WC' -- ob begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.OtherRevenue [Description], convert(varchar, r.transdate, 101) [Date] from tbOBULRequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherRevenue c on r.code = c.OtherRevenueID where isnull(r.swfin, '') in ('', 'X') and r.refnum like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spDICOM_ExamResultReport] /*@StudyUID varchar(64), @Modality varchar(50), @PatientAge varchar(10) */ @PatientID As Varchar(10) AS SELECT ST.StudyID, CONVERT(varchar(10),ST.StudyDate,101) AS StudyDate, --CONVERT(varchar(10),A.Transdate,101) AS StudyDate, ST.StudyDescription, PT.PatientID, (PT.Name_Last + ', ' + PT.Name_First +' '+ PT.Name_Middle) AS Patient_Name, PT.Sex, --ISNULL(ER.room_no,'') AS room_no, Case Isnumeric(A.IDNum) When 1 then A.RoomID Else 'OPD' End As room_no, ISNULL(ER.service_rate,'') AS service_rate, (SELECT FirstName + ' ' + LastName FROM Build_File..tbCoDoctor WHERE DoctorID=ER.refdoctor_id) AS refdoctor_name, ISNULL((SELECT FirstName + ' ' + LastName FROM Build_File..tbCoDoctor WHERE DoctorID=ER.attdoctor_id),'') AS attdoctor_name, ISNULL(ER.technologist,'') AS technologist, ISNULL(ER.exam_result,'') AS exam_result, --A.ResultDate As exam_result, (SELECT FirstName + ' ' + MiddleName + ' ' + LastName + ', ' + Title FROM Build_File..tbCoDoctor WHERE DoctorID=ER.radiologist_id) AS radiologist_name, (SELECT FirstName + ' ' + MiddleName + ' ' + LastName FROM Build_File..tbCoDoctor WHERE DoctorID=Patient.AttendingDr1) AS AttendingDR, Case Isnumeric(A.IDNum) When 1 then A.RoomID Else 'OPD' End As RoomID, A.HospNum, A.IDNum, Patient_Data.dbo.Compute_Age(Master.BirthDate,ST.StudyDate) As Age, Patient_Data.dbo.fn_GetCompleteAddress(A.HospNum) As Address FROM RADIOLOGY..tbMRIResult A INNER JOIN DICOM..StudyTable ST On A.PatientID = ST.PatientID_FKey--A.StudyUID = ST.StudyUID INNER JOIN DICOM..PatientTable PT ON ST.PatientID_FKey=PT.PatientID -- INNER JOIN SeriesTable SE ON ST.StudyUID=SE.StudyUID_FKey LEFT OUTER JOIN DICOM..tblExamResult ER ON ER.StudyUID=ST.StudyUID INNER JOIN RADIOLOGY.dbo.vwPatientMaster Master On A.Hospnum = Master.Hospnum LEFT OUTER JOIN Patient_Data..tbPatient Patient On A.IDnum = Patient.IDNum WHERE A.PatientID = @PatientID and ER.Modality='MR'; --ST.StudyUID=@StudyUID AND ER.Modality=@Modality GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SearchRequestCancel] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) /*set @SearchType = '1' set @SearchRevenue = 'WC' set @SearchCriteria ='' */ AS if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'WC' Begin select R.RequestNum RequestNum , R.RefNum Refnum, R.TransDate Transdate, R.HospNum HospNum, R.IDNum IDNum, R.Code [ExamID], case r.revenueid when 'WC' then c.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Exam], C.SectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbOBULRequest R left join build_file..tbCoOtherRevenue C on R.Code = C.OtherrevenueID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where R.RequestNum = @SearchCriteria and not R.RefNum Like 'OR%' end end if @SearchType = '1' -- Search by Name begin if @SearchRevenue = 'WC' -- in obultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'WC' then c.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbOBULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherRevenue C on R.Code = C.OtherRevenueID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') and m.lastname like @SearchCriteria + '%' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'WC' -- in OBultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'WC' then c.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbOBULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherExam C on R.Code = C.OtherExamID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By Jetty P. Omo Added the remarks from Nurse Station (Cash assesment) Included the room if it is cash basis Date : Spetember 17, 2008 */ CREATE PROCEDURE [dbo].[spRadio_RequestForm] @RefNum as varchar(10), @DepartmentID as varchar(10) AS /* DECLARE @RefNum as varchar(10), @DepartmentID as varchar(10) SET @RefNum = 'C78828X' SET @DepartmentID = 'XR' */ declare @Room as varchar(50) declare @Idnum as varchar(10) declare @Account as varchar(50) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) declare @RequestDate as varchar(50) declare @Nurse as varchar(50) declare @Hospnum as varchar(50) declare @ImagingReason as varchar(900) declare @SurgicalReason as varchar(900) declare @AdmImpression as varchar(900) If @RefNum like 'C%I' begin set @Idnum = (Select distinct IDnum from Prepaid..tbPrepaidCharges where Chargeslip = @refnum and revenueid = @DepartmentID) set @Hospnum = (Select distinct Hospnum from Prepaid..tbPrepaidCharges where Chargeslip = @refnum and revenueid = @DepartmentID) end else begin set @Idnum = (Select distinct IDnum from Station..tbNurseLogbook where ReferenceNum = @refnum and revenueid = @DepartmentID) set @Hospnum = (Select distinct Hospnum from Station..tbNurseLogbook where ReferenceNum = @refnum and revenueid = @DepartmentID) end if isnumeric(@IdNum) = 0 begin Select @Room = 'OPD', @Account = C.Company, @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar(900)),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar(900)),char(13),''))), @BriefHistory = @ChiefComplaints + CHAR(13) + @Findings, @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum end; if isnumeric(@IdNum) = 1 begin Select @Room = P.roomid, @Account = C.Company, @RequestDate = L.RequestDate, @Nurse = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar(900)),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar(900)),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar(900)),char(13),''))), @AdmImpression = ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar(900)),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar(2000)),char(13),''))), @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMain PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.ReferenceNum = @RefNum end; if @IdNum is null if @DepartmentID = 'XR' set @IdNum = (select top 1 IdNum from TBXrrequest Where RefNum = @RefNum ) else if @DepartmentID = 'US' set @IdNum = (select top 1 IdNum from TBULrequest Where RefNum = @RefNum ) else if @DepartmentID = 'CT' set @IdNum = (select top 1 IdNum from TBCTrequest Where RefNum = @RefNum ) set @Room = (select top 1 roomid from PATIENT_DATA..tbPatient where idnum = @IdNum) if @DepartmentID = 'XR' begin Select Distinct R.IdNum, R.HospNum, R.RequestNum, r.Code as ItemId, E.XrayExam as ItemName, r.TransDate as ChargeDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'')as UserName, P.LastName, P.Firstname, P.MiddleName, dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age , P.Sex, P.CivilStatus, convert(varchar(10), P.BirthDate, 101) as BirthDate,isnull(@Room,'OPD') as Room, XRayNum as FileNum,'' as Unit,@RequestDate as RequestDate, isnull(@Account,'') as Account, @Nurse as Nurse, @ChiefComplaints as ChiefComplaints, @Diagnosis as Diagnosis, @Findings as Findings, @BriefHistory as BriefHistory, isnull(S.Remarks,'') as NurseRemarks, isnull(S.Reason,'') as NurseReason, @ImagingReason as ImagingReason, @SurgicalReason as SurgicalReason, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash, IsNull(@AdmImpression,'') as AdmImpression From tbXRRequest R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoXrayExam E On R.Code = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D On R.RequestDoctorCode = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.[By] = PWORD.EmployeeID Left Outer Join Station..tbNurseCommunicationFile S On R.Idnum = S.Idnum and R.Hospnum = S.Hospnum and R.refnum = S.Referencenum Left Outer Join Billing..tbCashAssessment B On R.RefNum = B.ORNumber and Indicator = 'XR' and B.IDNum = R.IDNum Where R.RefNum = @RefNum end; if @DepartmentID = 'US' begin Select Distinct R.IdNum, R.HospNum, R.RequestNum, r.Code as ItemId, E.UltraExam as ItemName, r.TransDate as ChargeDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'')as UserName, P.LastName, P.Firstname, P.MiddleName, dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age , P.Sex, P.CivilStatus, convert(varchar(10), P.BirthDate, 101) as BirthDate,isnull(@Room,'OPD') as Room, UltraNum as FileNum ,'' as Unit,@RequestDate as RequestDate, isnull(@Account,'') as Account, @Nurse as Nurse, @ChiefComplaints as ChiefComplaints, @Diagnosis as Diagnosis, @Findings as Findings, @BriefHistory as BriefHistory, isnull(S.Remarks,'') as NurseRemarks, isnull(S.Reason,'') as NurseReason, @ImagingReason as ImagingReason, @SurgicalReason as SurgicalReason, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash, IsNull(@AdmImpression,'') as AdmImpression From tbULRequest R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoUltraExam E On R.Code = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D On R.RequestDoctorCode = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.[By] = PWORD.EmployeeID Left Outer Join Station..tbNurseCommunicationFile S On R.Idnum = S.Idnum and R.Hospnum = S.Hospnum and R.refnum = S.Referencenum Left Outer Join Billing..tbCashAssessment B On R.RefNum = B.ORNumber and Indicator = 'US' and B.IDNum = R.IDNum Where R.RefNum = @RefNum end; if @DepartmentID = 'CT' begin Select Distinct R.IdNum, R.HospNum, R.RequestNum, r.Code as ItemId, E.CTExam as ItemName, r.TransDate as ChargeDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.LastName, P.Firstname, P.MiddleName, dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age, P.Sex, P.CivilStatus, convert(varchar(10), P.BirthDate, 101) as BirthDate,isnull(@Room,'OPD') as Room, CTNum as FileNum,'' as Unit,@RequestDate as RequestDate, isnull(@Account,'') as Account, @Nurse as Nurse, @ChiefComplaints as ChiefComplaints, @Diagnosis as Diagnosis, @Findings as Findings, @BriefHistory as BriefHistory, isnull(S.Remarks,'') as NurseRemarks, isnull(S.Reason,'') as NurseReason, @ImagingReason as ImagingReason, @SurgicalReason as SurgicalReason, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash, IsNull(@AdmImpression,'') as AdmImpression From tbCTRequest R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoCTExam E On R.Code = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D On R.RequestDoctorCode = D.DoctorID left outer join PASSWORD..tbPasswordMain PWORD ON R.[By] = PWORD.EmployeeID Left Outer Join Station..tbNurseCommunicationFile S On R.Idnum = S.Idnum and R.Hospnum = S.Hospnum and R.refnum = S.Referencenum Left Outer Join Billing..tbCashAssessment B On R.RefNum = B.ORNumber and Indicator = 'CT' and B.IDNum = R.IDNum Where R.RefNum = @RefNum end; set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrintNurseRequestByIdNum] @IdNum as varchar(10), @StationID as varchar(10), @DepartmentID as varchar(10) AS /* declare @Requestnum as varchar(10) declare @DepartmentID as varchar(10) */ /*set @IdNum = '115' SET @sTATIONID = '5A' set @DepartmentID = 'MM' */ declare @RequestNum as varchar(10) declare @HospNum as varchar(50) --declare @IdNum as varchar(50) declare @LastName as varchar(50) declare @FirstName as varchar(50) declare @MiddleName as varchar(50) declare @Age as varchar(50) declare @Sex as varchar(50) declare @CStatus as varchar(50) declare @FileNum as varchar(50) declare @Unit as varchar(50) declare @Room as varchar(50) declare @Doctor as varchar(50) declare @RequestDate as varchar(50) declare @ChargeDate as varchar(50) declare @ItemID as varchar(50) declare @ItemName as varchar(50) declare @Medhistory as varchar(50) declare @Account as varchar(50) declare @User as varchar(50) declare @Nurse as varchar(50) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) if isnumeric(@IdNum) = 0 begin Select @Room = 'OPD', @Account = C.Company, @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar),char(13),''))), @BriefHistory = @ChiefComplaints + char(13) + @Findings From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum end; if isnumeric(@IdNum) = 1 begin Select @Room = P.RoomID, @Account = C.Company, @RequestDate = L.RequestDate, @Nurse = isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,''), @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMaster PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.IdNum = @IdNum end; if @DepartmentID = 'XR' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.XrayExam, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.XrayNum as FileNum From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoXrayExam E On R.ItemID = E.XrayExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.XrayExam, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.XrayNum as FileNum From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoXrayExam E On R.ItemCode = E.XrayExamID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum end; if @DepartmentID = 'US' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.UltraExam, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.lastname, P.Firstname, p.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoUltraExam E On R.ItemID = E.UltraExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.UltraExam, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoUltraExam E On R.ItemCode = E.UltraExamID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum end; if @DepartmentID = 'CT' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.CTExam, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.CTNum as FileNum From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoCTExam E On R.ItemID = E.CTExamID left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.CTExam, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.CTNum as FileNum From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbCoCTExam E On R.ItemCode = E.CTExamID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum end; if @DepartmentID = 'MM' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.OtherRevenue, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.lastname, P.Firstname, p.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemID = E.OtherRevenueID and othersectionid = 'MM' left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.OtherRevenue, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemCode = E.OtherRevenueID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum end; if @DepartmentID = 'MI' begin Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemID, E.OtherRevenue, r.RequestDate, isnull(D.LastName,'') + ', ' + isnull(D.Firstname,'') as Doctor, isnull(PWord.LastName,'') + ', ' + isnull(PWORD.FirstName,'') as UserName, P.lastname, P.Firstname, p.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From station..tbNurseCommunicationFile R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemID = E.OtherRevenueID and othersectionid = 'MI' left outer join BUILD_FILE..tbCoDoctor D On R.DoctorID = D.DoctorID left outer join PASSWORD..tbPasswordMaster PWORD ON R.UserID = PWORD.EmployeeID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum and R.StationID = @StationID union all Select distinct R.IdNum, R.HospNum, R.requestNum, r.ItemCode, E.OtherRevenue, r.Transdate as RequestDate, '' as Doctor, '' as UserName, P.lastname, P.Firstname, P.MiddleName, P.Age, P.Sex, P.CivilStatus, r.RequestNum, @Room as Room, @Account as Company, R.TransDate as RequestDate, @Nurse as NurseRequest, @ChiefComplaints as ChiefComplaints, @Findings as Findings, @Diagnosis as Diagnosis, @BriefHistory as BriefHistory, p.UltraNum as FileNum From Prepaid..tbPrepaidCharges R left outer join vwPatientMaster P On R.HospNum = P.HospNum left outer join BUILD_FILE..tbcoOtherRevenue E On R.ItemCode = E.OtherRevenueID Where R.RevenueID = @DepartmentID and R.IdNum = @IdNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ResultMaster] @Type varchar(1) , @RevenueID varchar(2), @Criteria varchar(50) AS if @RevenueID = 'WC' begin select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name], m.ctNum as [File Num] from vwpatientmaster m inner join tbobulrequest r on m.hospnum = r.hospnum where r.swfin = 'Y' and (m.lastname like @Criteria + '%' or m.UltraNum = @Criteria or m.HospNum = @Criteria or r.idnum = @Criteria ) order by m.lastname, m.firstname, m.middlename end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_VerificationList] @Names AS varChar(30) AS BEGIN SELECT tbMRIRequest.HospNum AS HospNum, tbMRIRequest.RequestNum AS RequestNum, tbMaster.LastName AS Lastname, tbMaster.FirstName AS Firstname, tbMaster.MiddleName AS Middlename, tbMRIRequest.Code AS Code, tbMRIRequest.TypeDescription AS Description, tbMRIRequest.IdNum AS IDNum, tbMRIRequest.TransDate AS TransDdate, tbMRIRequest.FilmsUsed AS Films, tbPatient.RoomID AS RoomID, tbMRIRequest.RequestDoctorCode + ' - ' + tbCoDoctor.Lastname + ', ' + tbCoDoctor.Firstname AS Doctor, tbMaster.Sex AS Sex, tbMaster.BirthDate AS Birth, tbMaster.CivilStatus AS CivilStatus, tbMaster.Age AS Age, tbPatient.AdmDate, tbMRIResult.Interpretation, tbMRIResult.ResultDate, Radio.DoctorID + ' - ' + Radio.LastName + ', ' + Radio.FirstName AS Radiologist FROM tbMRIRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient tbPatient ON tbMRIRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor tbCoDoctor ON tbMRIRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster tbMaster ON tbMRIRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN tbMRIResult ON tbMRIRequest.RequestNum = tbMRIResult.RequestNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Radio ON tbMRIResult.RadCode = Radio.DoctorID WHERE tbMaster.Lastname LIKE @Names+'%' AND (isnull(tbMRIResult.VerifyByID,'') = '') and (isnull(tbMRIResult.VerifyDate,'') = '') and tbMRIRequest.SwFin = 'Y' ORDER BY tbMaster.LastName, tbMaster.FirstName, tbMaster.MiddleName END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SearchRequestCancel] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) AS if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'MI' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], case when r.RevenueID = 'MI' then OtherRevenue when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ' ' + isnull(d.FirstName, '') when isnull(rev.LocationID, '') <> '' then m.ItemName + ' ' + isnull(m.ItemDesc, '') end [Exam], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbMRIRequest R left join build_file..tbCoOtherRevenue on R.Code = OtherRevenueID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID where R.RequestNum = @SearchCriteria end end if @SearchType = '1' -- Search by Name begin if @SearchRevenue = 'MI' begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case when r.RevenueID = 'MI' then OtherRevenue when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ' ' + isnull(d.FirstName, '') when isnull(rev.LocationID, '') <> '' then im.ItemName + ' ' + isnull(im.ItemDesc, '') end [Description], convert(varchar, r.transdate, 101) [Date] from tbMRIRequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherRevenue c on r.code = c.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join INVENTORY..tbInvMaster im on r.Code = im.ItemID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'MI' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case when r.RevenueID = 'MI' then OtherRevenue when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ' ' + isnull(d.FirstName, '') when isnull(rev.LocationID, '') <> '' then im.ItemName + ' ' + isnull(im.ItemDesc, '') end [Exam], convert(varchar, r.transdate, 101) [Date] from tbMRIRequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherRevenue c on r.code = c.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join INVENTORY..tbInvMaster im on r.Code = im.ItemID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SearchRequest] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) AS if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'MI' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], OtherRevenue [Exam], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbMRiRequest R left join build_file..tbCoOtherRevenue on R.Code = OtherRevenueID where R.RequestNum = @SearchCriteria and (NOT R.Code = '263') -- MRI Films end end if @SearchType = '1' -- Search by Name begin if @SearchRevenue = 'MI' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.OtherRevenue [Description], convert(varchar, r.transdate, 101) [Date] from tbMRIrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoOtherRevenue C on r.code = c.OtherRevenueID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' and (NOT R.Code = '263') -- MRI Films order by m.lastname, m.firstname, m.middlename, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'MI' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.OtherRevenue [Description], convert(varchar, r.transdate, 101) [Date] from tbMRIrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbcoOtherRevenue c on r.code = c.OtherRevenueID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' and (NOT R.Code = '263') -- MRI Films order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultMaster] @Type varchar(1), @RevenueID varchar(2), @Criteria varchar(50) AS if @RevenueID = 'XR' begin /* select HospNum [Code], Lastname [Last Name], Firstname [First Name], isnull(middlename, '') [Middle Name], isnull(XRayNum, '') [FileNum] from vwPatientMaster where hospnum in ( select hospnum from tbXRRequest where swfin = 'Y' ) and lastname like @Criteria + '%' order by lastname, firstname, middlename */ select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name], m.xrayNum as [File Num] from vwpatientmaster m inner join tbxrrequest r on m.hospnum = r.hospnum where r.swfin = 'Y' and (m.lastname like @Criteria + '%' OR m.XrayNum = @Criteria or m.HospNum = @Criteria or r.idnum = @Criteria ) order by m.lastname, m.firstname, m.middlename end if @RevenueID = 'CT' begin /* select HospNum [Code], Lastname [Last Name], Firstname [First Name], isnull(middlename, '') [Middle Name], isnull(CTNum, '') [FileNum] from vwPatientMaster where hospnum in ( select hospnum from tbCTRequest where swfin = 'Y' ) and lastname like @Criteria + '%' order by lastname, firstname, middlename */ select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name], m.CTNum as [File Num] from vwpatientmaster m inner join tbctrequest r on m.hospnum = r.hospnum where r.swfin = 'Y' and (m.lastname like @Criteria + '%' or m.CTNum = @Criteria or m.HospNum = @Criteria or r.idnum = @Criteria ) order by m.lastname, m.firstname, m.middlename end if @RevenueID = 'US' begin /* select HospNum [Code], Lastname [Last Name], Firstname [First Name], isnull(middlename, '') [Middle Name], isnull(UltraNum, '') [FileNum] from vwPatientMaster where hospnum in ( select hospnum from tbULRequest where swfin = 'Y' ) and lastname like @Criteria + '%' order by lastname, firstname, middlename */ select distinct m.hospnum [Code], m.lastname [Last Name], m.firstname [First Name], m.middlename [Middle Name], m.ctNum as [File Num] from vwpatientmaster m inner join tbulrequest r on m.hospnum = r.hospnum where r.swfin = 'Y' and (m.lastname like @Criteria + '%' or m.UltraNum = @Criteria or m.HospNum = @Criteria or r.idnum = @Criteria ) order by m.lastname, m.firstname, m.middlename end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetResultWomen] @RequestNum as varchar(10) AS /* declare @RequestNum as varchar(10) set @RequestNum = '11881' */ declare @HospNum as varchar(10) declare @IdNum as varchar(10) declare @RefNum as varchar(10) declare @FileNum as varchar(10) declare @Patientname as varchar(30) declare @Address as varchar(50) declare @Age as varchar(3) declare @Sex as varchar(6) declare @CivilStatus as varchar(10) declare @RoomID as varchar(10) declare @ExamDate as varchar(20) declare @Code as varchar(5) declare @ExamName as varchar(50) declare @FormType as varchar(2) select @HospNum = R.HospNum, @IdNum = R.IdNum, @RefNum = R.RefNum, @FileNum = M.UltraNum, @Patientname = M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName, @Address = HouseStreet + ' ' + Barangay, @Age = dbo.fn_ComputeAge(BirthDate,getdate()), @Sex = M.Sex, @CivilStatus = CivilStatus, @RoomID = R.RoomID, @ExamDate = R.Transdate, @Code = R.Code, @ExamName = E.UltraExam, @FormType = isnull(E.Formtype,'') from tbULrequest R left outer join dbo.vwPatientMaster M on R.HospNum = M.HospNum left outer join BUILD_FILE..tbCoUltraExam E on R.Code = E.ultraExamID left outer join BUILD_FILE..tbCoDoctor D1 on R.RequestDoctorCode = D1.DoctorID where R.requestNum = @RequestNum if @FormType = 'T' begin select R.*, @HospNum as HospNum, @IdNum as IdNum, @RefNum as RefNum, @FileNum as FileNum, @Patientname as Patientname, @Address as Address, @Age as Age, @Sex as Sex, @CivilStatus as CivilStatus, @RoomID as RoomID, @ExamDate as ExamDate, @Code as Code, @ExamName as ExamName, @FormType as FormType, isnull(D.FirstName,'') + ' ' + isnull(D.lastName,'') as DoctorName, isnull(D.Title,'') as DoctoTitle from tbUlWomensResult R left outer join BUILD_FILE..tbCoDoctor D On R.SonologistID = D.DoctorID where RequestNum = @RequestNum; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchRequest] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(200) AS /*set @SearchType = '0' set @SearchRevenue = 'xr' set @SearchCriteria = '14' */ if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'CT' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], CTExam [Exam], CTSectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbCTRequest R left join build_file..tbCoCTExam on R.Code = CTExamID where @SearchCriteria = R.RequestNum end if @SearchRevenue = 'XR' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], XRayExam [Exam], XRaySectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbXRRequest R left join build_file..tbCoXRayExam on R.Code = XRayExamID where @SearchCriteria = R.RequestNum end if @SearchRevenue = 'US' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], --UltraExam [Exam], a.Description [Exam], -- UltraSectionID [SectionID], a.SectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbULRequest R -- left join build_file..tbCoUltraExam -- on R.Code = UltraExamID Left Outer Join Billing..tbBillExamListing a On isnull(R.RevenueID,'US') = a.RevenueID and R.Code = a.ItemID where @SearchCriteria = R.RequestNum end end if @SearchType = '1' -- Search by Name begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.CTExam [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' and DateDiff(day, r.Transdate, getdate()) < 30 order by R.Transdate desc, m.lastname, m.firstname, m.middlename--, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.XRayExam [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' and DateDiff(day, r.Transdate, getdate()) < 30 order by R.Transdate desc, m.lastname, m.firstname, m.middlename--, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, -- c.UltraExam [Description], c.Description [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum -- left join build_file..tbCoUltraExam c -- on r.code = c.Ultraexamid Left Outer Join Billing..tbBillExamListing c On isnull(R.RevenueID,'US') = c.RevenueID and R.Code = c.ItemID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' -- and isnull(c.Classification, 'A') = 'A' and DateDiff(day, r.Transdate, getdate()) < 30 order by R.Transdate desc, m.lastname, m.firstname, m.middlename--, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.CTExam [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' -- and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, c.XRayExam [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, --c.UltraExam [Description], c.Description [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum -- left join build_file..tbCoUltraExam c -- on r.code = c.Ultraexamid Left Outer Join Billing..tbBillExamListing c On isnull(R.RevenueID,'US') = c.RevenueID and R.Code = c.ItemID where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' --and isnull(c.Classification, 'A') = 'A' order by m.lastname, m.firstname, m.middlename, r.transdate end end /* if @SearchType = '0' -- Search by Refnum begin if @SearchRevenue = 'CT' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], CTExam [Exam], CTSectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbCTRequest R left join build_file..tbCoCTExam on R.Code = CTExamID where R.RefNum = @SearchCriteria end if @SearchRevenue = 'XR' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], XRayExam [Exam], XRaySectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbXRRequest R left join build_file..tbCoXRayExam on R.Code = XRayExamID where R.RefNum = @SearchCriteria end if @SearchRevenue = 'US' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], --UltraExam [Exam], a.Description [Exam], -- UltraSectionID [SectionID], a.SectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbULRequest R -- left join build_file..tbCoUltraExam -- on R.Code = UltraExamID Left Outer Join Billing..tbBillExamListing a On isnull(R.RevenueID,'US') = a.RevenueID and R.Code = a.ItemID where R.RefNum = @SearchCriteria end end */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_GetResultWomen_OB] @RequestNum as varchar(10) AS /* declare @RequestNum as varchar(10) set @RequestNum = '11881' */ declare @HospNum as varchar(10) declare @IdNum as varchar(10) declare @RefNum as varchar(10) declare @FileNum as varchar(10) declare @Patientname as varchar(30) declare @Address as varchar(50) declare @Age as varchar(3) declare @Sex as varchar(6) declare @CivilStatus as varchar(10) declare @RoomID as varchar(10) declare @ExamDate as varchar(20) declare @Code as varchar(5) declare @ExamName as varchar(50) declare @FormType as varchar(2) select @HospNum = R.HospNum, @IdNum = R.IdNum, @RefNum = R.RefNum, @FileNum = M.UltraNum, @Patientname = M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName, @Address = HouseStreet + ' ' + Barangay, @Age = dbo.fn_ComputeAge(BirthDate,getdate()), @Sex = M.Sex, @CivilStatus = CivilStatus, @RoomID = R.RoomID, @ExamDate = R.Transdate, @Code = R.Code, @ExamName = E.UltraExam, @FormType = isnull(E.Formtype,'') from tbOBULrequest R left outer join dbo.vwPatientMaster M on R.HospNum = M.HospNum left outer join BUILD_FILE..tbCoUltraExam E on R.Code = E.ultraExamID left outer join BUILD_FILE..tbCoDoctor D1 on R.RequestDoctorCode = D1.DoctorID where R.requestNum = @RequestNum --if @FormType in ( 'P','O','C','B','D') begin select R.*, @HospNum as HospNum, @IdNum as IdNum, @RefNum as RefNum, @FileNum as FileNum, @Patientname as Patientname, @Address as Address, @Age as Age, @Sex as Sex, @CivilStatus as CivilStatus, @RoomID as RoomID, @ExamDate as ExamDate, @Code as Code, @ExamName as ExamName, @FormType as FormType, isnull(D.FirstName,'') + ' ' + isnull(D.lastName,'') as DoctorName, isnull(D.Title,'') as DoctoTitle from tbUlWomensResult R left outer join BUILD_FILE..tbCoDoctor D On R.SonologistID = D.DoctorID where RequestNum = @RequestNum; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchRequestCancel] --declare @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(200) AS /* set @SearchType = '1' set @SearchRevenue ='xr' set @SearchCriteria ='bua' */ if @SearchType = '0' -- Search by RequestNum begin if @SearchRevenue = 'CT' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], case isnull(r.revenueid, 'CT') when 'CT' then c.CTExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Exam], CTSectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbCTRequest R left join build_file..tbCoCTExam C on R.Code = CTExamID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where @SearchCriteria = R.RequestNum --and Not R.Refnum like 'C%I' and not R.RefNum Like 'OR%' end; if @SearchRevenue = 'XR' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], case r.revenueid when 'BM' then E.OtherRevenue when 'XR' then c.XRayExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Exam], XRaySectionID [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbXRRequest R left join build_file..tbCoXRayExam C on R.Code = XRayExamID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid Left Outer JOin Build_File..TbcoOtherRevenue E on R.Code = E.OtherRevenueID and othersectionid = 'XR' where @SearchCriteria = R.RequestNum --and Not R.Refnum like 'C%I' and not R.RefNum Like 'OR%' end if @SearchRevenue = 'US' begin select R.RequestNum, R.RefNum, R.TransDate, R.HospNum, R.IDNum, R.Code [ExamID], case r.revenueid when 'US' then c.UltraExam when 'WC' then w.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Exam], case when r.RevenueID = 'WC' then w.SectionID else UltraSectionID end [SectionID], R.RequestDoctorCode [DoctorID], R.SWFIN [Status] from tbULRequest R left join build_file..tbCoUltraExam C on R.Code = C.UltraExamID left join build_file..tbCoOtherRevenue W on W.OtherSectionID = 'WC' and R.Code = W.OtherRevenueID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where @SearchCriteria = R.RequestNum --and Not R.Refnum like 'C%I' and not R.RefNum Like 'OR%' end end if @SearchType = '1' -- Search by Name begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case isnull(r.revenueid, 'CT') when 'CT' then c.CTExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' and not R.RefNum Like 'OR%' --and Not R.Refnum like 'C%I' and order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'BM' then E.OtherRevenue when 'XR' then c.XRayExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE C.Xrayexam--l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid Left Outer JOin Build_File..TbcoOtherRevenue E on R.Code = E.OtherRevenueID and othersectionid = 'XR' where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' and not R.RefNum Like 'OR%' --and Not R.Refnum like 'C%I' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'US' then c.UltraExam when 'WC' then w.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoUltraExam C on R.Code = C.UltraExamID left join build_file..tbCoOtherRevenue W on W.OtherSectionID = 'WC' and R.Code = W.OtherRevenueID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and m.lastname like @SearchCriteria + '%' and Not R.Refnum like 'C%I' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end end if @SearchType = '2' -- Search by Slip begin if @SearchRevenue = 'CT' -- in ct begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case isnull(r.revenueid, 'CT') when 'CT' then c.CTExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbCTrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoCTExam c on r.code = c.CTexamid left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' and Not R.Refnum like 'C%I' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'XR' -- in xray begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'BM' then E.OtherRevenue when 'XR' THEN C.XRayExam when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbxrrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoXRayExam c on r.code = c.xrayexamid left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid Left Outer JOin Build_File..TbcoOtherRevenue E on R.Code = E.OtherRevenueID and othersectionid = 'XR' where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end if @SearchRevenue = 'US' -- in ultra begin select r.RequestNum [Request #], r.refnum [Slip #], r.idnum [Adm #], m.Lastname [Last Name], m.Firstname [First Name], m.Middlename [Middle Name], r.Code, case r.revenueid when 'US' then c.UltraExam when 'WC' then w.OtherRevenue when 'MD' then '(PF) ' + d.lastname + ' ' + d.firstname ELSE l.ItemName END [Description], convert(varchar, r.transdate, 101) [Date] from tbULrequest r left join vwpatientmaster m on r.hospnum = m.hospnum left join build_file..tbCoUltraExam C on R.Code = C.UltraExamID left join build_file..tbCoOtherRevenue W on W.OtherSectionID = 'WC' and R.Code = W.OtherRevenueID left join INVENTORY..tbInvMaster l on r.Code = l.ItemID left join BUILD_FILE..tbCoDoctor d on r.code = d.doctorid where isnull(r.swfin, '') in ('', 'X') --isnull(r.swfin, '') = '' and r.refnum like @SearchCriteria + '%' and not R.RefNum Like 'OR%' order by m.lastname, m.firstname, m.middlename, r.transdate end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_GetResultWomen] @RequestNum as varchar(10) AS /* declare @RequestNum as varchar(10) set @RequestNum = '11881' */ declare @HospNum as varchar(10) declare @IdNum as varchar(10) declare @RefNum as varchar(10) declare @FileNum as varchar(10) declare @Patientname as varchar(30) declare @Address as varchar(50) declare @Age as varchar(3) declare @Sex as varchar(6) declare @CivilStatus as varchar(10) declare @RoomID as varchar(10) declare @ExamDate as varchar(20) declare @Code as varchar(5) declare @ExamName as varchar(50) declare @FormType as varchar(2) select @HospNum = R.HospNum, @IdNum = R.IdNum, @RefNum = R.RefNum, @FileNum = M.UltraNum, @Patientname = M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName, @Address = HouseStreet + ' ' + Barangay, @Age = dbo.fn_ComputeAge(BirthDate,getdate()), @Sex = M.Sex, @CivilStatus = CivilStatus, @RoomID = R.RoomID, @ExamDate = R.Transdate, @Code = R.Code, @ExamName = E.UltraExam, @FormType = isnull(E.Formtype,'') from tbOBULrequest R left outer join dbo.vwPatientMaster M on R.HospNum = M.HospNum left outer join BUILD_FILE..tbCoUltraExam E on R.Code = E.ultraExamID left outer join BUILD_FILE..tbCoDoctor D1 on R.RequestDoctorCode = D1.DoctorID where R.requestNum = @RequestNum begin select R.*, @HospNum as HospNum, @IdNum as IdNum, @RefNum as RefNum, @FileNum as FileNum, @Patientname as Patientname, @Address as Address, @Age as Age, @Sex as Sex, @CivilStatus as CivilStatus, @RoomID as RoomID, @ExamDate as ExamDate, @Code as Code, @ExamName as ExamName, @FormType as FormType, isnull(D.FirstName,'') + ' ' + isnull(D.lastName,'') as DoctorName, isnull(D.Title,'') as DoctoTitle from tbUlWomensResult R left outer join BUILD_FILE..tbCoDoctor D On R.SonologistID = D.DoctorID where RequestNum = @RequestNum; end; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_BorrowedFilm2] @RevenueID as varchar(10) AS if @RevenueID = 'XR' begin select b.requestnum, r.hospnum, case when m.hospnum is null then '' else m.lastname + ', ' + m.firstname + ' ' + m.middlename end [patient], r.code [examid], e.XrayExam [exam], s.resultdate, b.borrowedby, b.borroweddate, b.location, b.isreturned, b.borrowedbyId, b.returnedbyID, case isnull(b.BorrowedByID,'') when '' then b.BorrowedBy else dA.LastName end as [ReturnedBy], case isnull(b.returnedbyID,'') when '' then b.returnedby else dB.LastName end as [ReturnedBy], b.borroweddate, b.returneddate, b.borrowuserid, b.returnuserid from tbxrborrowedfilm b left join tbxrrequest r on b.requestnum = r.requestnum left join vwpatientmaster m on r.hospnum = m.hospnum left join BUILD_FILE..tbCoXRayExam e on r.code = e.xrayexamid left join tbxrresult s on r.requestnum = s.requestnum left join BUILD_FILE..tbCoDoctor dA on dA.DoctorID = BorrowedByID left join BUILD_FILE..tbCoDoctor dB on dB.DoctorID = ReturnedByID where isreturned = 0 end; if @RevenueID = 'CT' begin select b.requestnum, r.hospnum, case when m.hospnum is null then '' else m.lastname + ', ' + m.firstname + ' ' + m.middlename end [patient], r.code [examid], e.CtExam [exam], s.resultdate, b.borrowedby, b.borroweddate, b.location, b.isreturned, b.borrowedbyId, b.returnedbyID, case isnull(b.BorrowedByID,'') when '' then b.BorrowedBy else dA.LastName end as [ReturnedBy], case isnull(b.returnedbyID,'') when '' then b.returnedby else dB.LastName end as [ReturnedBy], b.borroweddate, b.returneddate, b.borrowuserid, b.returnuserid from tbxrborrowedfilm b left join tbCtrequest r on b.requestnum = r.requestnum left join vwpatientmaster m on r.hospnum = m.hospnum left join BUILD_FILE..tbCoCTExam e on r.code = e.CTexamid left join tbCtresult s on r.requestnum = s.requestnum left join BUILD_FILE..tbCoDoctor dA on dA.DoctorID = BorrowedByID left join BUILD_FILE..tbCoDoctor dB on dB.DoctorID = ReturnedByID where isreturned = 0 end; if @RevenueID = 'UL' begin select b.requestnum, r.hospnum, case when m.hospnum is null then '' else m.lastname + ', ' + m.firstname + ' ' + m.middlename end [patient], r.code [examid], e.UltraExam [exam], s.resultdate, b.borrowedby, b.borroweddate, b.location, b.isreturned, b.borrowedbyId, b.returnedbyID, case isnull(b.BorrowedByID,'') when '' then b.BorrowedBy else dA.LastName end as [ReturnedBy], case isnull(b.returnedbyID,'') when '' then b.returnedby else dB.LastName end as [ReturnedBy], b.borroweddate, b.returneddate, b.borrowuserid, b.returnuserid from tbxrborrowedfilm b left join tbULrequest r on b.requestnum = r.requestnum left join vwpatientmaster m on r.hospnum = m.hospnum left join BUILD_FILE..tbCoUltraExam e on r.code = e.Ultraexamid left join tbCtresult s on r.requestnum = s.requestnum left join BUILD_FILE..tbCoDoctor dA on dA.DoctorID = BorrowedByID left join BUILD_FILE..tbCoDoctor dB on dB.DoctorID = ReturnedByID where isreturned = 0 end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_BorrowedFilmStatus] @RevenueID as varchar(10), @Mode as varchar(10), @strSearch as varchar(30) AS --23 --13 if @RevenueID = '11' -- For Xray begin if @Mode = '1' -- Selects top 50 select top 50 tbXrBorrowedFilm.RequestNum, tbXrRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbXrRequest.Code,'') [Code], isnull(tbCoXrayExam.XrayExam,'') [Exam], CASE isnull(tbXrBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbXrBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbXrBorrowedFilm.Location,'') [Location], CASE isnull(tbXrBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbXrBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbXrBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbXrBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbXrBorrowedFilm.IsReturned, case isnull(tbXrRequest.SwFin,'') when 'Y' then isnull(tbXrResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbXrBorrowedFilm.Byfolder from Radiology..tbXrBorrowedFilm [tbXrBorrowedFilm] LEFT OUTER JOIN Radiology..tbXrRequest [tbXrRequest] ON tbXrBorrowedFilm.RequestNum = tbXrRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXrRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbXrResult [tbXrResult] ON tbXrRequest.RequestNum = tbXrResult.RequestNum LEFT OUTER JOIN Build_File..tbCoXrayExam [tbCoXrayExam] ON tbXrRequest.Code = tbCoXrayExam.XrayExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbXrBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbXrBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbXrBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbXrBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbXrBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbXrRequest.hospNum,'') <> '' else if @Mode = '2' select tbXrBorrowedFilm.RequestNum, tbXrRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbXrRequest.Code,'') [Code], isnull(tbCoXrayExam.XrayExam,'') [Exam], CASE isnull(tbXrBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbXrBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbXrBorrowedFilm.Location,'') [Location], CASE isnull(tbXrBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbXrBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbXrBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbXrBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbXrBorrowedFilm.IsReturned, case isnull(tbXrRequest.SwFin,'') when 'Y' then isnull(tbXrResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbXrBorrowedFilm.Byfolder from Radiology..tbXrBorrowedFilm [tbXrBorrowedFilm] LEFT OUTER JOIN Radiology..tbXrRequest [tbXrRequest] ON tbXrBorrowedFilm.RequestNum = tbXrRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXrRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbXrResult [tbXrResult] ON tbXrRequest.RequestNum = tbXrResult.RequestNum LEFT OUTER JOIN Build_File..tbCoXrayExam [tbCoXrayExam] ON tbXrRequest.Code = tbCoXrayExam.XrayExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbXrBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbXrBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbXrBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbXrBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbXrBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbXrRequest.hospNum,'') <> '' and tbPasswordMaster.LastName like @strSearch + '%' or tbPasswordMasterB.LastName like @strSearch + '%' or tbCoDoctor.LastName like @strSearch + '%' or tbCoDoctorB.LastName like @strSearch + '%' or tbXrBorrowedFilm.BorrowedBy like @strSearch + '%' else if @Mode = '3' select tbXrBorrowedFilm.RequestNum, tbXrRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbXrRequest.Code,'') [Code], isnull(tbCoXrayExam.XrayExam,'') [Exam], CASE isnull(tbXrBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbXrBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbXrBorrowedFilm.Location,'') [Location], CASE isnull(tbXrBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbXrBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbXrBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbXrBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbXrBorrowedFilm.IsReturned, case isnull(tbXrRequest.SwFin,'') when 'Y' then isnull(tbXrResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbXrBorrowedFilm.ByFolder from Radiology..tbXrBorrowedFilm [tbXrBorrowedFilm] LEFT OUTER JOIN Radiology..tbXrRequest [tbXrRequest] ON tbXrBorrowedFilm.RequestNum = tbXrRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXrRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbXrResult [tbXrResult] ON tbXrRequest.RequestNum = tbXrResult.RequestNum LEFT OUTER JOIN Build_File..tbCoXrayExam [tbCoXrayExam] ON tbXrRequest.Code = tbCoXrayExam.XrayExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbXrBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbXrBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbXrBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbXrBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbXrBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbXrRequest.hospNum,'') <> '' and tbMaster.LastName like @strSearch + '%' else if @Mode = '4' select tbXrBorrowedFilm.RequestNum, tbXrRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbXrRequest.Code,'') [Code], isnull(tbCoXrayExam.XrayExam,'') [Exam], CASE isnull(tbXrBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbXrBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbXrBorrowedFilm.Location,'') [Location], CASE isnull(tbXrBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbXrBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbXrBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbXrBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbXrBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbXrBorrowedFilm.IsReturned, case isnull(tbXrRequest.SwFin,'') when 'Y' then isnull(tbXrResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbXrBorrowedFilm.ByFolder from Radiology..tbXrBorrowedFilm [tbXrBorrowedFilm] LEFT OUTER JOIN Radiology..tbXrRequest [tbXrRequest] ON tbXrBorrowedFilm.RequestNum = tbXrRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbXrRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbXrResult [tbXrResult] ON tbXrRequest.RequestNum = tbXrResult.RequestNum LEFT OUTER JOIN Build_File..tbCoXrayExam [tbCoXrayExam] ON tbXrRequest.Code = tbCoXrayExam.XrayExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbXrBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbXrBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbXrBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbXrBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbXrBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbXrRequest.hospNum,'') <> '' and tbXrRequest.RequestNum like @strSearch + '%' end; if @RevenueID = '23' -- For CT Scan begin if @Mode = '1' select top 50 tbCTBorrowedFilm.RequestNum, tbCTRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbCTRequest.Code,'') [Code], isnull(tbCoCtExam.CTExam,'') [Exam], CASE isnull(tbCTBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbCTBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbCTBorrowedFilm.Location,'') [Location], CASE isnull(tbCTBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbCTBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbCTBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbCTBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbCTBorrowedFilm.IsReturned, case isnull(tbCTRequest.SwFin,'') when 'Y' then isnull(tbCTResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbCTBorrowedFilm.ByFolder from Radiology..tbCTBorrowedFilm [tbCTBorrowedFilm] LEFT OUTER JOIN Radiology..tbCTRequest [tbCTRequest] ON tbCTBorrowedFilm.RequestNum = tbCTRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbCTResult [tbCTResult] ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN Build_File..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CtExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbCTBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbCTBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbCTBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbCTBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbCTBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbCTRequest.hospNum,'') <> ''; else if @Mode = '2' select tbCTBorrowedFilm.RequestNum, tbCTRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbCTRequest.Code,'') [Code], isnull(tbCoCTExam.CTExam,'') [Exam], CASE isnull(tbCTBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbCTBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbCTBorrowedFilm.Location,'') [Location], CASE isnull(tbCTBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbCTBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbCTBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbCTBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbCTBorrowedFilm.IsReturned, case isnull(tbCTRequest.SwFin,'') when 'Y' then isnull(tbCTResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbCTBorrowedFilm.ByFolder from Radiology..tbCTBorrowedFilm [tbCTBorrowedFilm] LEFT OUTER JOIN Radiology..tbCTRequest [tbCTRequest] ON tbCTBorrowedFilm.RequestNum = tbCTRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbCTResult [tbCTResult] ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN Build_File..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbCTBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbCTBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbCTBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbCTBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbCTBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbCTRequest.hospNum,'') <> '' and tbPasswordMaster.LastName like @strSearch + '%' or tbPasswordMasterB.LastName like @strSearch + '%' or tbCoDoctor.LastName like @strSearch + '%' or tbCoDoctorB.LastName like @strSearch + '%' or tbCTBorrowedFilm.BorrowedBy like @strSearch + '%' else if @Mode = '3' select tbCTBorrowedFilm.RequestNum, tbCTRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbCTRequest.Code,'') [Code], isnull(tbCoCTExam.CTExam,'') [Exam], CASE isnull(tbCTBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbCTBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbCTBorrowedFilm.Location,'') [Location], CASE isnull(tbCTBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbCTBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbCTBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbCTBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbCTBorrowedFilm.IsReturned, case isnull(tbCTRequest.SwFin,'') when 'Y' then isnull(tbCTResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbCTBorrowedFilm.ByFolder from Radiology..tbCTBorrowedFilm [tbCTBorrowedFilm] LEFT OUTER JOIN Radiology..tbCTRequest [tbCTRequest] ON tbCTBorrowedFilm.RequestNum = tbCTRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbCTResult [tbCTResult] ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN Build_File..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbCTBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbCTBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbCTBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbCTBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbCTBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbCTRequest.hospNum,'') <> '' and tbMaster.LastName like @strSearch + '%' else if @Mode = '4' select tbCTBorrowedFilm.RequestNum, tbCTRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbCTRequest.Code,'') [Code], isnull(tbCoCTExam.CTExam,'') [Exam], CASE isnull(tbCTBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbCTBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbCTBorrowedFilm.Location,'') [Location], CASE isnull(tbCTBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbCTBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbCTBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbCTBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbCTBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbCTBorrowedFilm.IsReturned, case isnull(tbCTRequest.SwFin,'') when 'Y' then isnull(tbCTResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbCTBorrowedFilm.ByFolder from Radiology..tbCTBorrowedFilm [tbCTBorrowedFilm] LEFT OUTER JOIN Radiology..tbCTRequest [tbCTRequest] ON tbCTBorrowedFilm.RequestNum = tbCTRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbCTResult [tbCTResult] ON tbCTRequest.RequestNum = tbCTResult.RequestNum LEFT OUTER JOIN Build_File..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbCTBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbCTBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbCTBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbCTBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbCTBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbCTRequest.hospNum,'') <> '' and tbCTRequest.RequestNum like @strSearch + '%' end; if @RevenueID = '13' -- For UltraScound begin if @Mode = '1' select top 50 tbULBorrowedFilm.RequestNum, tbULRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbULRequest.Code,'') [Code], isnull(tbCoUltraExam.UltraExam,'') [Exam], CASE isnull(tbULBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbULBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbULBorrowedFilm.Location,'') [Location], CASE isnull(tbULBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbULBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbULBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbULBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbULBorrowedFilm.IsReturned, case isnull(tbULRequest.SwFin,'') when 'Y' then isnull(tbULResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbULBorrowedFilm.ByFolder from Radiology..tbULBorrowedFilm [tbULBorrowedFilm] LEFT OUTER JOIN Radiology..tbULRequest [tbULRequest] ON tbULBorrowedFilm.RequestNum = tbULRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbULResult [tbULResult] ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN Build_File..tbCoUltraExam [tbCoUltraExam] ON tbULRequest.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbULBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbULBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbULBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbULBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbULBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbULRequest.hospNum,'') <> ''; else if @Mode = '2' select tbULBorrowedFilm.RequestNum, tbULRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbULRequest.Code,'') [Code], isnull(tbCoUltraExam.UltraExam,'') [Exam], CASE isnull(tbULBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbULBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbULBorrowedFilm.Location,'') [Location], CASE isnull(tbULBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbULBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbULBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbULBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbULBorrowedFilm.IsReturned, case isnull(tbULRequest.SwFin,'') when 'Y' then isnull(tbULResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbULBorrowedFilm.ByFolder from Radiology..tbULBorrowedFilm [tbULBorrowedFilm] LEFT OUTER JOIN Radiology..tbULRequest [tbULRequest] ON tbULBorrowedFilm.RequestNum = tbULRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbULResult [tbULResult] ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN Build_File..tbCoUltraExam [tbCoUltraExam] ON tbULRequest.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbULBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbULBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbULBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbULBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbULBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbULRequest.hospNum,'') <> '' and tbPasswordMaster.LastName like @strSearch + '%' or tbPasswordMasterB.LastName like @strSearch + '%' or tbCoDoctor.LastName like @strSearch + '%' or tbCoDoctorB.LastName like @strSearch + '%' or tbULBorrowedFilm.BorrowedBy like @strSearch + '%' else if @Mode = '3' select tbULBorrowedFilm.RequestNum, tbULRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbULRequest.Code,'') [Code], isnull(tbCoUltraExam.UltraExam,'') [Exam], CASE isnull(tbULBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbULBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbULBorrowedFilm.Location,'') [Location], CASE isnull(tbULBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbULBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbULBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbULBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbULBorrowedFilm.IsReturned, case isnull(tbULRequest.SwFin,'') when 'Y' then isnull(tbULResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbULBorrowedFilm.ByFolder from Radiology..tbULBorrowedFilm [tbULBorrowedFilm] LEFT OUTER JOIN Radiology..tbULRequest [tbULRequest] ON tbULBorrowedFilm.RequestNum = tbULRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbULResult [tbULResult] ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN Build_File..tbCoUltraExam [tbCoUltraExam] ON tbULRequest.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbULBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbULBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbULBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbULBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbULBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbULRequest.hospNum,'') <> '' and tbMaster.LastName like @strSearch + '%' else if @Mode = '4' select tbULBorrowedFilm.RequestNum, tbULRequest.HospNum, tbMaster.LastName + ', ' + tbMaster.FirstName + ' ' + tbMaster.MiddleName [PatientName], isnull(tbULRequest.Code,'') [Code], isnull(tbCoUltraExam.UltraExam,'') [Exam], CASE isnull(tbULBorrowedFilm.BorrowedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.BorrowedBy,'') else case isnull(tbCoDoctor.DoctorID,'') WHEN '' then tbPasswordMasterB.FirstName + ' ' + tbPasswordMasterB.LastName else 'Dr. ' + tbCoDoctor.FirstName + ' ' + tbCoDoctor.LastName end End As [BorrowedBy], isnull(cast(tbULBorrowedFilm.BorrowedDate as varchar(20)),'') [BorrowedDate], isnull(tbULBorrowedFilm.Location,'') [Location], CASE isnull(tbULBorrowedFilm.ReturnedByID,'') WHEN '' THEN isnull(tbULBorrowedFilm.ReturnedBy,'') else case isnull(tbCoDoctorB.DoctorID,'') WHEN '' then tbPasswordMaster.FirstName + ' ' + tbPasswordMaster.LastName else 'Dr. ' + tbCoDoctorB.FirstName + ' ' + tbCoDoctorB.LastName end End As [ReturnedBy], isnull(cast(tbULBorrowedFilm.ReturnedDate as varchar(20)),'') [ReturnedDate], case isnull(tbULBorrowedFilm.IsReturned,'0') when '0' then cast(datediff(day,tbULBorrowedFilm.BorrowedDate,getdate()) as varchar(10)) else 'R' end as [Due], tbULBorrowedFilm.IsReturned, case isnull(tbULRequest.SwFin,'') when 'Y' then isnull(tbULResult.XrayNum,'NoFileNumber') else 'NoResult' end as [Status], tbPasswordMasterC.LastName + ', ' + tbPasswordMasterC.FirstName [User] , tbULBorrowedFilm.ByFolder from Radiology..tbULBorrowedFilm [tbULBorrowedFilm] LEFT OUTER JOIN Radiology..tbULRequest [tbULRequest] ON tbULBorrowedFilm.RequestNum = tbULRequest.RequestNum LEFT OUTER JOIN vwPatientMaster [tbMaster] ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN RADIOLOGY..tbULResult [tbULResult] ON tbULRequest.RequestNum = tbULResult.RequestNum LEFT OUTER JOIN Build_File..tbCoUltraExam [tbCoUltraExam] ON tbULRequest.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctor] ON tbULBorrowedFilm.BorrowedByID = tbCoDoctor.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor[tbCoDoctorB] ON tbULBorrowedFilm.ReturnedByID = tbCoDoctorB.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMaster] ON tbULBorrowedFilm.ReturnedByID = tbPasswordMaster.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterB] ON tbULBorrowedFilm.BorrowedByID = tbPasswordMasterB.EmployeeID LEFT OUTER JOIN PASSWORD..tbPasswordMaster [tbPasswordMasterC] ON tbULBorrowedFilm.BorrowUserID = tbPasswordMasterC.EmployeeID where isnull(tbULRequest.hospNum,'') <> '' and tbULRequest.RequestNum like @strSearch + '%' end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio2_InquiryList] @Type varchar(1), @Name varchar(20) AS IF @TYPE = '1' BEGIN SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, M.LastName, M.Firstname, M.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbCTRequest REQ LEFT JOIN tbCTResult RES ON REQ.RequestNum = RES.RequestNum LEFT JOIN vwPatientMaster M ON REQ.HospNum = M.HospNum WHERE REQ.SwFin = 'Y' AND M.LastName like @Name + '%' ORDER BY M.LastName, M.FirstName, M.MiddleName, RES.ControlNum END IF @TYPE = '2' BEGIN SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, M.LastName, M.Firstname, M.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbXRRequest REQ LEFT JOIN tbXRResult RES ON REQ.RequestNum = RES.RequestNum LEFT JOIN vwPatientMaster M ON REQ.HospNum = M.HospNum WHERE REQ.SwFin = 'Y' AND M.LastName like @Name + '%' ORDER BY M.LastName, M.FirstName, M.MiddleName, RES.ControlNum END IF @TYPE = '3' BEGIN SELECT REQ.RequestNum, REQ.HospNum, REQ.IDNum, M.LastName, M.Firstname, M.Middlename, RES.ControlNum, REQ.TypeDescription [Exam], RES.ResultDate FROM tbULRequest REQ LEFT JOIN tbULResult RES ON REQ.RequestNum = RES.RequestNum LEFT JOIN vwPatientMaster M ON REQ.HospNum = M.HospNum WHERE REQ.SwFin = 'Y' AND M.LastName like @Name + '%' ORDER BY M.LastName, M.FirstName, M.MiddleName, RES.ControlNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetResultWomen_OB] --declare @Requestnum varchar(10) AS --SET @REQUESTNUM = '197' select B.hospnum,F.civilstatus,b.idnum,C.sex,B.roomid, C.lastname +', '+ C.firstname+' '+C.Middlename as [PatienName], D.otherrevenue as [Exam Taken], C.Age, E.Lastname +', '+E.firstname as Doctor, Result1,Result2,Result3,Result4,Result5,Result6,Result7,Result8,Result9,Result10,Result11, Result12, Result13,Result14,Result15,Result16,Result17,Result18,Result19,Result20,Result21, Result22,Result23,Result24,Result25,Result26,Result27,Result28,Result29,Result30, VerifyDate as [Exam Date], A.Sonologist as Reader, B.Transdate as [Transaction Date], Interpretation as Diagnosis /*R.*, @HospNum as HospNum, @IdNum as IdNum, @RefNum as RefNum, @FileNum as FileNum, @Patientname as Patientname, @Address as Address, @Age as Age, @Sex as Sex, @CivilStatus as CivilStatus, @RoomID as RoomID, @ExamDate as ExamDate, @Code as Code, @ExamName as ExamName, @FormType as FormType, isnull(D.FirstName,'') + ' ' + isnull(D.lastName,'') as DoctorName, isnull(D.Title,'') as DoctoTitle*/ from tbUlWomensResult A left outer join radiology..tbOBULrequest B on A.requestnum = B.requestnum left outer join patient_data..tbmaster C on B.hospnum = C.hospnum left outer join Build_file..tbcootherrevenue D on D.otherrevenueid = B.code left outer join build_file..tbcodoctor E on E.doctorid = B.requestdoctorcode left outer join build_file..tbcocivilstatus F on C.civilstatus = F.civilstatusid where A.RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CheckIfWithResult] @RequestNum as varchar(10), @Formtype as varchar(10) AS /* declare @RequestNum as varchar(10) declare @Formtype as varchar(10) set @RequestNum = '11918' set @Formtype = 'O' */ if @Formtype = 'O' begin select * from tbUlWomensResultOB where RequestNum = @RequestNum end; else if @Formtype = 'T' begin select * from tbUlWomensResult where RequestNum = @RequestNum end; else begin select * from tbULResult where RequestNum = @RequestNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveResultWomens] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Result1 as varchar(50) = '', @Result2 as varchar(50) = '', @Result3 as varchar(50) = '', @Result4 as varchar(50) = '', @Result5 as varchar(50) = '', @Result6 as varchar(50) = '', @Result7 as varchar(50) = '', @Result8 as varchar(50) = '', @Result9 as varchar(50) = '', @Result10 as varchar(50) = '', @Result11 as varchar(50) = '', @Result12 as varchar(50) = '', @Result13 as varchar(50) = '', @Result14 as varchar(50) = '', @Result15 as varchar(50) = '', @Result16 as varchar(50) = '', @Result17 as varchar(50) = '', @Result18 as varchar(50) = '', @Result19 as varchar(50) = '', @Result20 as varchar(50) = '', @Result21 as text = '', @Result22 as text = '', @Result23 as text = '', @Result24 as text = '', @Result25 as text = '', @Result26 as text = '', @Result27 as text = '', @Result28 as text = '', @Result29 as text = '', @Result30 as text = '' AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResult Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResult (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11, @Result12, @Result13, @Result14, @Result15, @Result16, @Result17, @Result18, @Result19, @Result20, @Result21, @Result22, @Result23, @Result24, @Result25, @Result26, @Result27, @Result28, @Result29, @Result30); end else begin Update tbUlWomensResult Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30 where RequestNum = @RequestNum; end; UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_CheckIfWithResult] @RequestNum as varchar(10), @Formtype as varchar(10) AS if @Formtype = 'O' begin select * from tbUlWomensResultOB where RequestNum = @RequestNum end; else if @Formtype = 'T' begin select * from tbUlWomensResult where RequestNum = @RequestNum end; else begin select * from tbULResult where RequestNum = @RequestNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveResultWomens] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Result1 as varchar(50) = '', @Result2 as varchar(50) = '', @Result3 as varchar(50) = '', @Result4 as varchar(50) = '', @Result5 as varchar(50) = '', @Result6 as varchar(50) = '', @Result7 as varchar(50) = '', @Result8 as varchar(50) = '', @Result9 as varchar(50) = '', @Result10 as varchar(50) = '', @Result11 as varchar(50) = '', @Result12 as varchar(50) = '', @Result13 as varchar(50) = '', @Result14 as varchar(50) = '', @Result15 as varchar(50) = '', @Result16 as varchar(50) = '', @Result17 as varchar(50) = '', @Result18 as varchar(50) = '', @Result19 as varchar(50) = '', @Result20 as varchar(50) = '', @Result21 as text = '', @Result22 as text = '', @Result23 as text = '', @Result24 as text = '', @Result25 as text = '', @Result26 as text = '', @Result27 as text = '', @Result28 as text = '', @Result29 as text = '', @Result30 as text = '' AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; --SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResult Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResult (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11, @Result12, @Result13, @Result14, @Result15, @Result16, @Result17, @Result18, @Result19, @Result20, @Result21, @Result22, @Result23, @Result24, @Result25, @Result26, @Result27, @Result28, @Result29, @Result30); end else begin Update tbUlWomensResult Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30 where RequestNum = @RequestNum; end; UPDATE tbOBULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode And isnull(RecordStatus,'') = '') BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode And isnull(RecordStatus,'') = ''; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveResultWomens_OB] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Result1 as varchar (50), @Result2 as varchar (50), @Result3 as varchar (50), @Result4 as varchar (50), @Result5 as varchar (50), @Result6 as varchar (50), @Result7 as varchar (50), @Result8 as varchar (50), @Result9 as varchar (50), @Result10 as varchar (50), @Result11 as varchar (50), @Result12 as varchar (50), @Result13 as varchar (50), @Result14 as varchar (50), @Result15 as varchar (50), @Result16 as varchar (50), @Result17 as varchar (50), @Result18 as varchar (50), @Result19 as varchar (50)=NULL, @Result20 as varchar (50)=NULL, @Result21 as varchar (50)=NULL, @Result22 as varchar (50)=NULL, @Result23 as varchar (50)=NULL, @Result24 as varchar (50)=NULL, @Result25 as varchar (50)=NULL, @Result26 as varchar (50)=NULL, @Result27 as varchar (50)=NULL, @Result28 as varchar (50)=NULL, @Result29 as varchar (50) =NULL, @Result30 as varchar (50) = NULL, @Result31 as varchar (50) = NULL , @Result32 as varchar (50) = NULL, @Result33 as varchar (50) = NULL, @Result34 as varchar (50) = NULL, @Result35 as varchar (50)= NULL, @Result36 as varchar (50) = NULL, @Result37 as varchar (50)= NULL, @Result38 as varchar (50) = NULL, @Result39 as varchar (50) = NULL, @Result40 as varchar (50) = NULL, @Result41 as varchar (50) = NULL, @Result42 as varchar (50) = NULL, @Result43 as varchar (50) = NULL, @Result44 as varchar (50) = NULL, @Result45 as varchar (50) = NULL, @Result46 as varchar (50) = NULL, @Result47 as varchar (50) = NULL, @Result48 as varchar (50) = NULL, @Result49 as varchar (50) = NULL, @Result50 as varchar (50) = NULL, @Result51 as varchar (50) = NULL, @Result52 as varchar (50) = NULL, @Result53 as varchar (50) = NULL, @Result54 as varchar (50) = NULL, @Result55 as varchar (50) = NULL, @Result56 as varchar (50) = NULL, @Result57 as varchar (50) = NULL, @Result58 as varchar (50) = NULL, @Result59 as varchar (50) = NULL AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; -- SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResultOB Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResultOB (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30, Result31, Result32, Result33, Result34, Result35, Result36, Result37, Result38, Result39, Result40, Result41, Result42, Result43, Result44, Result45, Result46, Result47, Result48, Result49, Result50, Result51, Result52, Result53, Result54, Result55, Result56, Result57, Result58, Result59) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11, @Result12,@Result13,@Result14,@Result15,@Result16,@Result17,@Result18,@Result19,@Result20, @Result21,@Result22,@Result23,@Result24,@Result25,@Result26,@Result27,@Result28,@Result29,@Result30, @Result31,@Result32,@Result33,@Result34,@Result35,@Result36,@Result37,@Result38,@Result39,@Result40, @Result41,@Result42,@Result43,@Result44,@Result45,@Result46,@Result47,@Result48,@Result49,@Result50, @Result51,@Result52,@Result53,@Result54,@Result55,@Result56,@Result57,@Result58,@Result59) end else begin Update tbUlWomensResultOB Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30, Result31 = @Result31, Result32 = @Result32, Result33 = @Result33, Result34 = @Result34, Result35 = @Result35, Result36 = @Result36, Result37 = @Result37, Result38 = @Result38, Result39 = @Result39, Result40 = @Result40, Result41 = @Result41, Result42 = @Result42, Result43 = @Result43, Result44 = @Result44, Result45 = @Result45, Result46 = @Result46, Result47 = @Result47, Result48 = @Result48, Result49 = @Result49, Result50 = @Result50, Result51 = @Result51, Result52 = @Result52, Result53 = @Result53, Result54 = @Result54, Result55 = @Result55, Result56 = @Result56, Result57 = @Result57, Result58 = @Result58, Result59 = @Result59 where RequestNum = @RequestNum; end; UPDATE tbOBULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode and isnull(RecordStatus,'') = '') BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode and isnull(RecordStatus,'') = '' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_BiophysicalProfile] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Result1 as varchar (50), @Result2 as varchar (50), @Result3 as varchar (50), @Result4 as varchar (50), @Result5 as varchar (50), @Result6 as varchar (50), @Result7 as varchar (50), @Result8 as varchar (50), @Result9 as varchar (50), @Result10 as varchar (50), @Result11 as varchar (50), @Result12 as varchar (50), @Result13 as varchar (50), @Result14 as varchar (50), @Result15 as varchar (50), @Result16 as varchar (50), @Result17 as varchar (50), @Result18 as varchar (50), @Result19 as varchar (50), @Result20 as varchar (50), @Result21 as varchar (50), @Result22 as varchar (50), @Result23 as varchar (50), @Result24 as varchar (50), @Result25 as varchar (50), @Result26 as varchar (50), @Result27 as varchar (50), @Result28 as varchar (50), @Result29 as varchar (50), @Result30 as varchar (50) = NULL, @Result31 as varchar (50) = NULL, @Result32 as varchar (50) = NULL, @Result33 as varchar (50) = NULL, @Result34 as varchar (50) = NULL, @Result35 as varchar (50)= NULL, @Result36 as varchar (50) = NULL, @Result37 as varchar (50)= NULL /*@Result38 as varchar (50) = NULL, @Result39 as varchar (50) = NULL, @Result40 as varchar (50) = NULL, @Result41 as varchar (50) = NULL, @Result42 as varchar (50) = NULL, @Result43 as varchar (50) = NULL, @Result44 as varchar (50) = NULL, @Result45 as varchar (50) = NULL, @Result46 as varchar (50) = NULL, @Result47 as varchar (50) = NULL, @Result48 as varchar (50) = NULL, @Result49 as varchar (50) = NULL, @Result50 as varchar (50) = NULL, @Result51 as varchar (50) = NULL, @Result52 as varchar (50) = NULL, @Result53 as varchar (50) = NULL, @Result54 as varchar (50) = NULL, @Result55 as varchar (50) = NULL, @Result56 as varchar (50) = NULL, @Result57 as varchar (50) = NULL, @Result58 as varchar (50) = NULL, @Result59 as varchar (50) = NULL, @Result60 as varchar (50) = NULL */ AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResultOB Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResultOB (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30, Result31, Result32, Result33, Result34, Result35, Result36, Result37/*, Result38, Result39, Result40, Result41, Result42, Result43, Result44, Result45, Result46, Result47, Result48, Result49, Result50, Result51, Result52, Result53, Result54, Result55, Result56, Result57, Result58, Result59, Result60*/) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11, @Result12,@Result13,@Result14,@Result15,@Result16,@Result17,@Result18,@Result19,@Result20, @Result21,@Result22,@Result23,@Result24,@Result25,@Result26,@Result27,@Result28,@Result29,@Result30, @Result31,@Result32,@Result33,@Result34,@Result35,@Result36,@Result37/*,@Result38,@Result39,@Result40, @Result41,@Result42,@Result43,@Result44,@Result45,@Result46,@Result47,@Result48,@Result49,@Result50, @Result51,@Result52,@Result53,@Result54,@Result55,@Result56,@Result57,@Result58,@Result59, @Result60*/) end else begin Update tbUlWomensResultOB Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30, Result31 = @Result31, Result32 = @Result32, Result33 = @Result33, Result34 = @Result34, Result35 = @Result35, Result36 = @Result36, Result37 = @Result37 /*Result38 = @Result38, Result39 = @Result39, Result40 = @Result40, Result41 = @Result41, Result42 = @Result42, Result43 = @Result43, Result44 = @Result44, Result45 = @Result45, Result46 = @Result46, Result47 = @Result47, Result48 = @Result48, Result49 = @Result49, Result50 = @Result50, Result51 = @Result51, Result52 = @Result52, Result53 = @Result53, Result54 = @Result54, Result55 = @Result55, Result56 = @Result56, Result57 = @Result57, Result58 = @Result58, Result59 = @Result59, Result60 = @Result60*/ where RequestNum = @RequestNum; end; UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveResultWomens_OB] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Result1 as varchar (50), @Result2 as varchar (50), @Result3 as varchar (50), @Result4 as varchar (50), @Result5 as varchar (50), @Result6 as varchar (50), @Result7 as varchar (50), @Result8 as varchar (50), @Result9 as varchar (50), @Result10 as varchar (50), @Result11 as varchar (50), @Result12 as varchar (50), @Result13 as varchar (50), @Result14 as varchar (50), @Result15 as varchar (50), @Result16 as varchar (50), @Result17 as varchar (50), @Result18 as varchar (50), @Result19 as varchar (50), @Result20 as varchar (50), @Result21 as varchar (50), @Result22 as varchar (50), @Result23 as varchar (50), @Result24 as varchar (50), @Result25 as varchar (50), @Result26 as varchar (50), @Result27 as varchar (50), @Result28 as varchar (50), @Result29 as varchar (50), @Result30 as varchar (50) = NULL, @Result31 as varchar (50) = NULL , @Result32 as varchar (50) = NULL, @Result33 as varchar (50) = NULL, @Result34 as varchar (50) = NULL, @Result35 as varchar (50)= NULL, @Result36 as varchar (50) = NULL, @Result37 as varchar (50)= NULL, @Result38 as varchar (50) = NULL, @Result39 as varchar (50) = NULL, @Result40 as varchar (50) = NULL, @Result41 as varchar (50) = NULL, @Result42 as varchar (50) = NULL, @Result43 as varchar (50) = NULL, @Result44 as varchar (50) = NULL, @Result45 as varchar (50) = NULL, @Result46 as varchar (50) = NULL, @Result47 as varchar (50) = NULL, @Result48 as varchar (50) = NULL, @Result49 as varchar (50) = NULL, @Result50 as varchar (50) = NULL, @Result51 as varchar (50) = NULL, @Result52 as varchar (50) = NULL, @Result53 as varchar (50) = NULL, @Result54 as varchar (50) = NULL, @Result55 as varchar (50) = NULL, @Result56 as varchar (50) = NULL, @Result57 as varchar (50) = NULL, @Result58 as varchar (50) = NULL, @Result59 as varchar (50) = NULL AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResultOB Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResultOB (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30, Result31, Result32, Result33, Result34, Result35, Result36, Result37, Result38, Result39, Result40, Result41, Result42, Result43, Result44, Result45, Result46, Result47, Result48, Result49, Result50, Result51, Result52, Result53, Result54, Result55, Result56, Result57, Result58, Result59) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11, @Result12,@Result13,@Result14,@Result15,@Result16,@Result17,@Result18,@Result19,@Result20, @Result21,@Result22,@Result23,@Result24,@Result25,@Result26,@Result27,@Result28,@Result29,@Result30, @Result31,@Result32,@Result33,@Result34,@Result35,@Result36,@Result37,@Result38,@Result39,@Result40, @Result41,@Result42,@Result43,@Result44,@Result45,@Result46,@Result47,@Result48,@Result49,@Result50, @Result51,@Result52,@Result53,@Result54,@Result55,@Result56,@Result57,@Result58,@Result59) end else begin Update tbUlWomensResultOB Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30, Result31 = @Result31, Result32 = @Result32, Result33 = @Result33, Result34 = @Result34, Result35 = @Result35, Result36 = @Result36, Result37 = @Result37, Result38 = @Result38, Result39 = @Result39, Result40 = @Result40, Result41 = @Result41, Result42 = @Result42, Result43 = @Result43, Result44 = @Result44, Result45 = @Result45, Result46 = @Result46, Result47 = @Result47, Result48 = @Result48, Result49 = @Result49, Result50 = @Result50, Result51 = @Result51, Result52 = @Result52, Result53 = @Result53, Result54 = @Result54, Result55 = @Result55, Result56 = @Result56, Result57 = @Result57, Result58 = @Result58, Result59 = @Result59 where RequestNum = @RequestNum; end; UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CongenitalAnomality] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @DoctorID varchar(5), @SonologistID varchar(10), @SonologistID2 varchar(10), @Sonologist varchar(100), @Sonologist2 varchar(100), @ExamTaken varchar(100) , @ExamDate as DateTime, @VerifyDate as DateTime , @ResultDate AS DateTime, @VerifyByID as varchar(20) , @UserID AS varChar(8), @AdmDiagnosis as text , @Remarks as text, @Interpretation as text, @Comments as text, @Result1 as varchar (50), @Result2 as varchar (50), @Result3 as varchar (50), @Result4 as varchar (50), @Result5 as varchar (50), @Result6 as varchar (50), @Result7 as varchar (50), @Result8 as varchar (50), @Result9 as varchar (50), @Result10 as varchar (50), @Result11 as varchar (50), @Result12 as varchar (50), @Result13 as varchar (50), @Result14 as varchar (50), @Result15 as varchar (50), @Result16 as varchar (50), @Result17 as varchar (50), @Result18 as varchar (50), @Result19 as varchar (50), @Result20 as varchar (50), @Result21 as varchar (50), @Result22 as varchar (50), @Result23 as varchar (50), @Result24 as varchar (50), @Result25 as varchar (50), @Result26 as varchar (50), @Result27 as varchar (50), @Result28 as varchar (50), @Result29 as varchar (50), @Result30 as varchar (50) = NULL, @Result31 as varchar (50) = NULL, @Result32 as varchar (50) = NULL, @Result33 as varchar (50) = NULL, @Result34 as varchar (50) = NULL, @Result35 as varchar (50)= NULL, @Result36 as varchar (50) = NULL, @Result37 as varchar (50)= NULL, @Result38 as varchar (50) = NULL, @Result39 as varchar (50) = NULL, @Result40 as varchar (50) = NULL, @Result41 as varchar (50) = NULL, @Result42 as varchar (50) = NULL, @Result43 as varchar (50) = NULL, @Result44 as varchar (50) = NULL, @Result45 as varchar (50) = NULL, @Result46 as varchar (50) = NULL, @Result47 as varchar (50) = NULL, @Result48 as varchar (50) = NULL, @Result49 as varchar (50) = NULL, @Result50 as varchar (50) = NULL, @Result51 as varchar (50) = NULL, @Result52 as varchar (50) = NULL, @Result53 as varchar (50) = NULL, @Result54 as varchar (50) = NULL, @Result55 as varchar (50) = NULL, @Result56 as varchar (50) = NULL, @Result57 as varchar (50) = NULL, @Result58 as varchar (50) = NULL, @Result59 as varchar (50) = NULL, @Result60 as varchar (50) = NULL, @Result61 as varchar (50) = NULL, @Result62 as varchar (50) = NULL, @Result63 as varchar (50) = NULL, @Result64 as varchar (50) = NULL, @Result65 as varchar (50)= NULL, @Result66 as varchar (50) = NULL, @Result67 as varchar (50)= NULL, @Result68 as varchar (50) = NULL, @Result69 as varchar (50) = NULL, @Result70 as varchar (50) = NULL, @Result71 as varchar (50) = NULL, @Result72 as varchar (50) = NULL, @Result73 as varchar (50) = NULL, @Result74 as varchar (50) = NULL, @Result75 as varchar (50) = NULL, @Result76 as varchar (50) = NULL, @Result77 as varchar (50) = NULL, @Result78 as varchar (50) = NULL, @Result79 as varchar (50) = NULL, @Result80 as varchar (50) = NULL, @Result81 as varchar (50) = NULL, @Result82 as varchar (50) = NULL, @Result83 as varchar (50) = NULL, @Result84 as varchar (50) = NULL, @Result85 as varchar (50) = NULL, @Result86 as varchar (50) = NULL, @Result87 as varchar (50) = NULL, @Result88 as varchar (50) = NULL, @Result89 as varchar (50) = NULL, @Result90 as varchar (50) = NULL, @Result91 as varchar (50) = NULL, @Result92 as varchar (50) = NULL, @Result93 as varchar (50) = NULL, @Result94 as varchar (50) = NULL, @Result95 as varchar (50) = NULL, @Result96 as varchar (50) = NULL, @Result97 as varchar (50) = NULL, @Result98 as varchar (50) = NULL, @Result99 as varchar (50) = NULL, @Result100 as varchar (50) = NULL, @Result101 as varchar (50) = NULL, @Result102 as varchar (50) = NULL, @Result103 as varchar (50) = NULL, @Result104 as varchar (50) = NULL, @Result105 as varchar (50) = NULL, @Result106 as varchar (50) = NULL, @Result107 as varchar (50) = NULL, @Result108 as varchar (50) = NULL AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; SET @RevenueID = 'US' if not exists(SELECT RequestNum FROM tbUlWomensResultOB Where RequestNum = @RequestNum) begin INSERT INTO tbUlWomensResultOB (RequestNum, Remarks, Interpretation, AdmDiagnosis, Transdate, ResultDate, UserID, SonologistID, SonologistID2, Sonologist, Sonologist2, VerifyDate, VerifyByID, Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8, Result9, Result10, Result11, Result12, Result13, Result14, Result15, Result16, Result17, Result18, Result19, Result20, Result21, Result22, Result23, Result24, Result25, Result26, Result27, Result28, Result29, Result30, Result31, Result32, Result33, Result34, Result35, Result36, Result37, Result38, Result39, Result40, Result41, Result42, Result43, Result44, Result45, Result46, Result47, Result48, Result49, Result50, Result51, Result52, Result53, Result54, Result55, Result56, Result57, Result58, Result59, Result60, Result61, Result62, Result63, Result64, Result65, Result66, Result67, Result68, Result69, Result70, Result71, Result72, Result73, Result74, Result75, Result76, Result77, Result78, Result79, Result80, Result81, Result82, Result83, Result84, Result85, Result86, Result87, Result88, Result89, Result90, Result91, Result92, Result93, Result94, Result95, Result96, Result97, Result98, Result99, Result100, Result101, Result102, Result103, Result104, Result105, Result106, Result107,Result108, Comments) VALUES (@RequestNum, @Remarks, @Interpretation, @AdmDiagnosis, getdate(), @ResultDate, @UserID, @SonologistID, @SonologistID2, @Sonologist, @Sonologist2, getdate(), @VerifyByID, @Result1, @Result2, @Result3, @Result4, @Result5, @Result6, @Result7, @Result8, @Result9, @Result10, @Result11,@Result12,@Result13,@Result14,@Result15,@Result16,@Result17,@Result18,@Result19,@Result20, @Result21,@Result22,@Result23,@Result24,@Result25,@Result26,@Result27,@Result28,@Result29,@Result30, @Result31,@Result32,@Result33,@Result34,@Result35,@Result36,@Result37,@Result38,@Result39,@Result40, @Result41,@Result42,@Result43,@Result44,@Result45,@Result46,@Result47,@Result48,@Result49,@Result50, @Result51,@Result52,@Result53,@Result54,@Result55,@Result56,@Result57,@Result58,@Result59, @Result60, @Result61,@Result62,@Result63, @Result64, @Result65, @Result66, @Result67, @Result68, @Result69, @Result70, @Result71,@Result72,@Result73, @Result74, @Result75, @Result76, @Result77, @Result78, @Result79, @Result80, @Result81,@Result82,@Result83, @Result84, @Result85, @Result86, @Result87, @Result88, @Result89, @Result90, @Result91,@Result92, @Result93, @Result94, @Result95, @Result96, @Result97, @Result98, @Result99,@Result100, @Result101,@Result102, @Result103, @Result104, @Result105, @Result106, @Result107,@Result108,@Comments) end else begin Update tbUlWomensResultOB Set RequestNum = @RequestNum, Remarks = @Remarks, Interpretation = @Interpretation, AdmDiagnosis = @AdmDiagnosis, Transdate = getdate(), ResultDate = @ResultDate, UserID = @UserID, SonologistID = @SonologistID, SonologistID2 = @SonologistID2, Sonologist = @Sonologist, Sonologist2 = @Sonologist2, VerifyDate = getdate(), VerifyByID = VerifyByID, Result1 = @Result1, Result2 = @Result2, Result3 = @Result3, Result4 = @Result4, Result5 = @Result5, Result6 = @Result6, Result7 = @Result7, Result8 = @Result8, Result9 = @Result9, Result10 = @Result10, Result11 = @Result11, Result12 = @Result12, Result13 = @Result13, Result14 = @Result14, Result15 = @Result15, Result16 = @Result16, Result17 = @Result17, Result18 = @Result18, Result19 = @Result19, Result20 = @Result20, Result21 = @Result21, Result22 = @Result22, Result23 = @Result23, Result24 = @Result24, Result25 = @Result25, Result26 = @Result26, Result27 = @Result27, Result28 = @Result28, Result29 = @Result29, Result30 = @Result30, Result31 = @Result31, Result32 = @Result32, Result33 = @Result33, Result34 = @Result34, Result35 = @Result35, Result36 = @Result36, Result37 = @Result37, Result38 = @Result38, Result39 = @Result39, Result40 = @Result40, Result41 = @Result41, Result42 = @Result42, Result43 = @Result43, Result44 = @Result44, Result45 = @Result45, Result46 = @Result46, Result47 = @Result47, Result48 = @Result48, Result49 = @Result49, Result50 = @Result50, Result51 = @Result51, Result52 = @Result52, Result53 = @Result53, Result54 = @Result54, Result55 = @Result55, Result56 = @Result56, Result57 = @Result57, Result58 = @Result58, Result59 = @Result59, Result60 = @Result60, Result61 = @Result61, Result62 = @Result62, Result63 = @Result63, Result64 = @Result64, Result65 = @Result65, Result66 = @Result66, Result67 = @Result67, Result68 = @Result68, Result69 = @Result69, Result70 = @Result70, Result71 = @Result71, Result72 = @Result72, Result73 = @Result73, Result74 = @Result74, Result75 = @Result75, Result76 = @Result76, Result77 = @Result77, Result78 = @Result78, Result79 = @Result79, Result80 = @Result80, Result81 = @Result81, Result82 = @Result82, Result83 = @Result83, Result84 = @Result84, Result85 = @Result85, Result86 = @Result86, Result87 = @Result87, Result88 = @Result88, Result89 = @Result89, Result90 = @Result90, Result91 = @Result91, Result92 = @Result92, Result93 = @Result93, Result94 = @Result94, Result95 = @Result95, Result96 = @Result96, Result97 = @Result97, Result98 = @Result98, Result99 = @Result99, Result100 = @Result100, Result101 = @Result101, Result102 = @Result102, Result103 = @Result103, Result104 = @Result104, Result105 = @Result105, Result106 = @Result106, Result107 = @Result107, Result108 = @Result108, Comments = @Comments where RequestNum = @RequestNum; end; UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @UserID, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created bt : Jetty P. Omo Date : October 07/2007 To Save/Retrieve ICD10 from Radiology Module */ CREATE PROCEDURE [dbo].[sp_saveICD10] @IDNum As VarChar(10), @Dept As Varchar(3), @ICD1 As VarChar(15), @ICD2 As VarChar(15), @ICD3 As VarChar(15), @ICD4 As VarChar(15), @ICD5 As VarChar(15), @ICD6 As VarChar(15), @ICD7 As VarChar(15), @ICD8 As VarChar(15), @ICD9 As VarChar(15), @ICD10 As VarChar(15), @ICD11 As VarChar(15), @ICD12 As VarChar(15), @ICD13 As VarChar(15), @ICD14 As VarChar(15), @ICD15 As VarChar(15), @ICD16 As VarChar(15), @ICD17 As VarChar(15), @ICD18 As VarChar(15), @ICD19 As VarChar(15), @ICD20 As VarChar(15) AS select * from tbXRICD10 Delete tbXRICD10 Where IDNum = @IDNum and Dept = @Dept; IF Len(@ICD1) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD1,@Dept ) ; end ; IF Len(@ICD2) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD2,@Dept ) ; End ; IF Len(@ICD3) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD3,@Dept ) ; end ; IF Len(@ICD4) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD4,@Dept ) ; End ; IF Len(@ICD5) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD5 ,@Dept ) ; End ; IF Len(@ICD6) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD6,@Dept ) ; End ; IF Len(@ICD7) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD7 ,@Dept ) ; End ; IF Len(@ICD8) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD8,@Dept ) ; End ; IF Len(@ICD9) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD9 ,@Dept ) ; End ; IF Len(@ICD10) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD10,@Dept ) ; End ; IF Len(@ICD11) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD11,@Dept ) ; end ; IF Len(@ICD12) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD12,@Dept ) ; End ; IF Len(@ICD13) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD13 ,@Dept ) ; end ; IF Len(@ICD14) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD14,@Dept ) ; End ; IF Len(@ICD15) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD15,@Dept ) ; End ; IF Len(@ICD16) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD16,@Dept ) ; End ; IF Len(@ICD17) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD17,@Dept ) ; End ; IF Len(@ICD18) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID,Dept ) Values (@IDNum, @ICD18,@Dept ) ; End ; IF Len(@ICD19) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD19,@Dept ) ; End ; IF Len(@ICD20) > 0 Begin Insert tbXRICD10 (IDNum, DiagnosisID ,Dept ) Values (@IDNum, @ICD20 ,@Dept ) ; End ; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ReportRadiologyResult] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Set @StartDate = '09/22/2003'; Set @EndDate = '09/29/2003';*/ IF @RevenueID = 'XR' Begin Select Distinct A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD.' [Request Doctor],cast(D.ReportOrder as int) ReportOrder From tbXRResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoRoom C On B.RoomID = C.RoomID Left Outer Join Build_File..tbCoStation D On C.StationID = D.StationID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 1; End; Else IF @RevenueID = 'CT' Begin Select Distinct A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD.' [Request Doctor], cast(D.ReportOrder as int) ReportOrder From tbCTResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoRoom C On B.RoomID = C.RoomID Left Outer Join Build_File..tbCoStation D On C.StationID = D.StationID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 1; End; Else IF @RevenueID = 'US' Begin Select Distinct A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD.' [Request Doctor],cast(D.ReportOrder as int) ReportOrder From tbULResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoRoom C On B.RoomID = C.RoomID Left Outer Join Build_File..tbCoStation D On C.StationID = D.StationID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 1; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ReportRadiologyResult_OUT] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Set @StartDate = '09/22/2003'; Set @EndDate = '09/29/2003';*/ IF @RevenueID = 'XR' Begin Select A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD. ' + C.DrClinic [Request Doctor] From tbXRResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 0; End; Else IF @RevenueID = 'CT' Begin Select A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD. ' + C.DrClinic [Request Doctor] From tbCTResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 0; End; Else IF @RevenueID = 'US' Begin Select A.Idnum, A.Hospnum,dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) + ' MD. ' + C.DrClinic [Request Doctor] From tbULResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and isnumeric(isnull(A.Idnum,'')) = 0; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ReportRadiologyResult_InOut] @StartDate as varchar(10), @EndDate as varchar(10), @RevenueID as varchar(2) AS /*Set @StartDate = '09/22/2003'; Set @EndDate = '09/29/2003';*/ IF @RevenueID = 'XR' Begin Select A.Idnum, A.Hospnum, dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) [Request Doctor], isnull(C.DrClinic, '') DRClinic From tbXRResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and NOT isnull(A.HospNum,'') = '' --and isnumeric(isnull(A.Idnum,'')) = 1; End; Else IF @RevenueID = 'CT' Begin Select A.Idnum, A.Hospnum, dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) [Request Doctor], isnull(C.DrClinic, '') DRClinic From tbCTResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and NOT isnull(A.HospNum,'') = '' End; Else IF @RevenueID = 'US' Begin Select A.Idnum, A.Hospnum, dbo.fn_GetStation(B.RoomID) Station, Patient_Data.dbo.fn_GetPatientName(A.Hospnum) [Patient Name], A.RoomID, A.ExamTaken Precedure, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) [Request Doctor], isnull(C.DrClinic, '') DRClinic From tbULResult A Left Outer Join Patient_Data..tbPatient B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoDoctor C On A.RequestDoctorCode = C.DoctorID Where A.ResultDate Between @StartDate and @EndDate and NOT isnull(A.HospNum,'') = '' End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Altered By Jetty P. OMo -Change the way in getting the amount of request it is already based on the setup 02/02/2008 -Change the age and Birthdate format 10/10/2007 */ --updated by alejandro 03/22/2007 --for separation of display in Ultrasound and Women Center Exams --updated by gonzalo 01/21/2010 --added colorcode for stat CREATE PROCEDURE [dbo].[spRadio_NurseRequest] @Type As varChar(1) --set @type = '2' as Declare @CompanyMarkup as Float Declare @Company as varchar(1) Declare @Dept as varchar(2) IF @Type = '1' Begin set @Dept = 'CT' End if @Type = '2' Begin set @Dept = 'XR' End if @Type = '3' Begin set @Dept = 'US' End set @CompanyMarkup = (select top 1 CompanyMarkup from radiology..tbradiosetup WHERE DEPARTMENT = @Dept ) set @Company = (select top 1 Company from Radiology..tbRadiosetup WHERE DEPARTMENT = @Dept) IF @Type = '1' /* CT-Scan Request */ BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.CtExamID as [ItemID] , C.CTExam as [ItemDesc], case When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '1' then Case When R.RoomClassID = 'A' then cast((C.RateA * (@CompanyMarkup / 100)) + C.RateA as money) When R.RoomClassId = 'B' then cast((C.RateB * (@CompanyMarkup / 100)) + C.RateB as money) When R.RoomClassId = 'C' then cast((C.RateC * (@CompanyMarkup / 100)) + C.RateC as money) When R.RoomClassId = 'D' then cast((C.RateD * (@CompanyMarkup / 100)) + C.RateD as money) Else cast((C.RateE * (@CompanyMarkup / 100)) + C.RateE as money) End When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '3' then cast(C.RateH as money) Else Case When R.RoomClassID = 'A' then cast(C.RateA as money) When R.RoomClassId = 'B' then cast(C.RateB as money) When R.RoomClassId = 'C' then cast(C.RateC as money) When R.RoomClassId = 'D' then cast(C.RateD as money) Else cast (C.RateE as money) End End as [Amount], A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, D.RoomID , convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbCoCTExam C on A.ItemID = C.CTExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID='CT' and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Union All Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.CtExamID as [ItemID] , C.CTExam as [ItemDesc], cast(isnull(C.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID /* (select Max(isnull(lastname,'')+','+isnull(firstname,'')+' '+isnull(middlename,'')) from password..tbpasswordmain where employeeid = radiology.dbo.fn_GetUserName (A.UserID) as Userid Group by EmployeeID ) as UserID */ , convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID ,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbCoCtExam C on A.ItemID = C.CTExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID = 'CT' -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Order By [Date Request], [LastName], [FirstName] END IF @Type = '2' /* XRay Request */ BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.XRayExamID as [ItemID] , C.XRayExam as [ItemDesc], case When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '1' then Case When R.RoomClassID = 'A' then cast((C.RateA * (@CompanyMarkup / 100)) + C.RateA as money) When R.RoomClassId = 'B' then cast((C.RateB * (@CompanyMarkup / 100)) + C.RateB as money) When R.RoomClassId = 'C' then cast((C.RateC * (@CompanyMarkup / 100)) + C.RateC as money) When R.RoomClassId = 'D' then cast((C.RateD * (@CompanyMarkup / 100)) + C.RateD as money) Else cast((C.RateE * (@CompanyMarkup / 100)) + C.RateE as money) End When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '3' then cast(C.RateH as money) Else Case When R.RoomClassID = 'A' then cast(C.RateA as money) When R.RoomClassId = 'B' then cast(C.RateB as money) When R.RoomClassId = 'C' then cast(C.RateC as money) When R.RoomClassId = 'D' then cast(C.RateD as money) Else cast (C.RateE as money) End End as [Amount], A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, D.RoomID ,convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbCoXrayExam C on A.ItemID = C.XRayExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID='XR' -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Union All Select Distinct D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.XRayExamID as [ItemID] , C.XRayExam as [ItemDesc], cast(isnull(C.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID /* (select Max(isnull(lastname,'')+','+isnull(firstname,'')+' '+isnull(middlename,'')) from password..tbpasswordmain where employeeid = radiology.dbo.fn_GetUserName (A.UserID) as Userid Group by EmployeeID ) as UserID */, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Inner Join Build_File..tbCoXRayExam C on A.ItemID = C.XRayExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 Where (A.RecordStatus is null or A.RecordStatus = '') and A.RevenueID = 'XR' -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Order By [Date Request], [LastName], [FirstName] END IF @Type = '3' /* Ultrasound Request */ BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.UltraExamID as [ItemID] , C.UltraExam as [ItemDesc], case When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '1' then Case When R.RoomClassID = 'A' then cast((C.RateA * (@CompanyMarkup / 100)) + C.RateA as money) When R.RoomClassId = 'B' then cast((C.RateB * (@CompanyMarkup / 100)) + C.RateB as money) When R.RoomClassId = 'C' then cast((C.RateC * (@CompanyMarkup / 100)) + C.RateC as money) When R.RoomClassId = 'D' then cast((C.RateD * (@CompanyMarkup / 100)) + C.RateD as money) Else cast((C.RateE * (@CompanyMarkup / 100)) + C.RateE as money) End When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '3' then cast(C.RateH as money) Else Case When R.RoomClassID = 'A' then cast(C.RateA as money) When R.RoomClassId = 'B' then cast(C.RateB as money) When R.RoomClassId = 'C' then cast(C.RateC as money) When R.RoomClassId = 'D' then cast(C.RateD as money) Else cast (C.RateE as money) End End as [Amount], A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, D.RoomID, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID ,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left outer Join Build_File..tbCoUltraExam C on A.ItemID = C.UltraExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Where (isnull(A.RecordStatus,'')='') and A.RevenueID in ('US') -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Union All Select Distinct D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.UltraExamID as [ItemID] , C.UltraExam as [ItemDesc], cast(isnull(C.RateA,0)as money) as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID, convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID ,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left Outer Join Build_File..tbCoUltraExam C on A.ItemID = C.UltraExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 --Left outer Join Build_file..tbcoOtherRevenue X on X.OtherRevenueID = A.ItemID and X.OthersectionID ='WC' Where (isnull(A.RecordStatus,'')='') and A.RevenueID IN ( 'US') -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Order By [Date Request], [LastName], [FirstName] END IF @Type = '4' /* Woman Center Request */ BEGIN Select D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.UltraExamID as [ItemID] , Case when A.RevenueID ='US' then C.UltraExam else X.OtherRevenue end as [ItemDesc], case when A.RevenueID ='US' then case When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '1' then Case When R.RoomClassID = 'A' then cast((C.RateA * (@CompanyMarkup / 100)) + C.RateA as money) When R.RoomClassId = 'B' then cast((C.RateB * (@CompanyMarkup / 100)) + C.RateB as money) When R.RoomClassId = 'C' then cast((C.RateC * (@CompanyMarkup / 100)) + C.RateC as money) When R.RoomClassId = 'D' then cast((C.RateD * (@CompanyMarkup / 100)) + C.RateD as money) Else cast((C.RateE * (@CompanyMarkup / 100)) + C.RateE as money) End When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '3' then cast(C.RateH as money) Else Case When R.RoomClassID = 'A' then cast(C.RateA as money) When R.RoomClassId = 'B' then cast(C.RateB as money) When R.RoomClassId = 'C' then cast(C.RateC as money) When R.RoomClassId = 'D' then cast(C.RateD as money) Else cast (C.RateE as money) End end else case When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '1' then Case When R.RoomClassID = 'A' then cast((X.RateA * (@CompanyMarkup / 100)) + X.RateA as money) When R.RoomClassId = 'B' then cast((X.RateB * (@CompanyMarkup / 100)) + X.RateB as money) When R.RoomClassId = 'C' then cast((X.RateC * (@CompanyMarkup / 100)) + X.RateC as money) When R.RoomClassId = 'D' then cast((X.RateD * (@CompanyMarkup / 100)) + X.RateD as money) Else cast((X.RateE * (@CompanyMarkup / 100)) + X.RateE as money) End When laboratory.dbo.fn_LabIsHMO(A.IDNum) = 'Y' and @Company = '3' then cast(X.RateH as money) Else Case When R.RoomClassID = 'A' then cast(X.RateA as money) When R.RoomClassId = 'B' then cast(X.RateB as money) When R.RoomClassId = 'C' then cast(X.RateC as money) When R.RoomClassId = 'D' then cast(X.RateD as money) Else cast (X.RateE as money) End end end as Amount, /*case when A.RevenueID ='US' then Case When R.RoomClassID = 'A' then cast(isnull(C.RateA,0)as money) When R.RoomClassID = 'B' then cast(isnull(C.RateB,0)as money) When R.RoomClassID = 'C' then cast(isnull(C.RateC,0)as money) When R.RoomClassID = 'D' then cast(isnull(C.RateD,0)as money) When R.RoomClassID = 'E' then cast(isnull(C.RateE,0)as money) End else Case When R.RoomClassID = 'A' then cast(isnull(x.RateA,0)as money) When R.RoomClassID = 'B' then cast(isnull(x.RateB,0)as money) When R.RoomClassID = 'C' then cast(isnull(x.RateC,0)as money) When R.RoomClassID = 'D' then cast(isnull(x.RateD,0)as money) When R.RoomClassID = 'E' then cast(isnull(x.RateE,0)as money) End end as Amount, */ A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, D.RoomId, D.AttendingDr1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, D.RoomID, convert(varchar(10),RequestDate, 101) [Date Request], isnull(A.StationID,'') as StationID,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left outer Join Build_File..tbCoUltraExam C on A.ItemID = C.UltraExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.AttendingDr1 left outer Join Build_File..tbCoRoom R on D.RoomID = R.RoomID Left outer Join Build_file..tbcoOtherRevenue X on X.OtherRevenueID = A.ItemID and x.othersectionid = 'WC' Where (isnull(A.RecordStatus,'')='') and A.RevenueID in ('WC') -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Union All Select Distinct D.HospNum, A.IDNum as [Admission #], IsNull(MasterIn.LastName,'') [LastName], IsNull(MasterIn.FirstName,'')[FirstName], IsNull(MasterIn.MiddleName,'') [MiddleName], C.UltraExamID as [ItemID] , Case when A.RevenueID ='US' then C.UltraExam else X.OtherRevenue end as [ItemDesc], case when A.RevenueID ='US' then cast(isnull(C.RateA,0)as money) else cast(isnull(X.RateA,0)as money) end as Amount, A.RequestDate as [RequestDate], MasterIn.HouseStreet [HouseStreet], MasterIn.Barangay [Barangay], Address.Town [Town], MasterIn.Sex, MasterIn.CivilStatus, convert(varchar,MasterIn.BirthDate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(MasterIn.BirthDate, getdate()), D.AdmDate, 'OPD' as RoomId, D.DoctorID1 [DoctorID], Doc.LastName + ', ' + Doc.FirstName as DrName, A.Quantity, A.Remarks, A.PatientType, A.RequestNum, radiology.dbo.fn_GetUserName (A.UserID) as Userid, Case When isnull(D.ERnum,'') = '' Then 'OPD' Else 'ER' End as RoomID, convert(varchar(10),RequestDate,101) [Date Request], isnull(A.StationID,'') as StationID,A.ISPortable,A.Stat From station..tbNurseCommunicationFile A Inner Join Patient_Data..tbOutPatient D on A.IdNum = D.IdNum Inner Join Patient_Data..tbMaster MasterIn on D.HospNum = MasterIn.HospNum Left Outer Join Build_File..tbCoUltraExam C on A.ItemID = C.UltraExamID left outer Join Build_File..tbCoAddress Address on MasterIn.ZipCode = Address.ZipCode left outer Join Build_File..tbCoDoctor Doc on Doc.DoctorId = D.DoctorID1 Left outer Join Build_file..tbcoOtherRevenue X on X.OtherRevenueID = A.ItemID and X.OthersectionID ='WC' Where (isnull(A.RecordStatus,'')='') and A.RevenueID IN ('WC') -- and D.BillingDate is Null and ((D.BillingDate is Null) or (datediff(day, D.BillingDate, getdate()) < 4)) Order By [Date Request], [LastName], [FirstName] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetRequestInfo] @IDNum as Varchar(10), @RevenueID as Varchar(10), @ItemID as Varchar(10), @TransDate as Varchar(10) AS /*set @RevenueID = 'XR' set @ItemID = '4' set @IDNum = '119149' set @Transdate = '11/07/2003' */ Select Convert(Varchar(10),RequestDate,101) RequestDate, dbo.fn_GetUserName(A.UserID) as RequestBY From Station..tbNurseLogBook A Where A.RevenueID = 'XR' and A.Idnum = @Idnum and A.ItemID = @ItemID and Convert(Varchar(10),A.ProcessDate,101) = @TransDate; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spCash_SaveMRI] @AssessID int AS declare @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @DepartmentID as varchar(2), @DoctorName as varchar(50) DECLARE @RequestNum AS varChar(8), @RevenueID AS varChar(2), @DrCr AS varChar(1), @SlipNum as varchar(10), @DiscountType as varchar(2), @NetAmount as money DECLARE @ErrorCode int SET @ErrorCode = 0 SELECT @RefNum = RefNum FROM BILLING..tbCashCommunication WHERE AssessID = @AssessID; SELECT @DepartmentID = DepartmentID, @RevenueID = RevenueID, @ItemID = ItemID, @Quantity = Quantity, @Amount = Amount, @HospNum = HospNum, @DoctorID = RequestDocID, @UserID = UserID, @RefNum = ISNULL(@RefNum, ORNumber), @RoomID = 'OPD', @DiscountType = DiscountType, @NetAmount = NetAmount, @IDNum = IDNum, @DoctorName = DoctorName, @SlipNum = RefNum FROM BILLING..tbCashAssessment WHERE AssessID = @AssessID; IF @DepartmentID= 'MI' BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM RADIOLOGY..tbMRIRequestNum UPDATE RADIOLOGY..tbMRIRequestNum SET RequestNum = RequestNum + 1 SET @ErrorCode = @@ERROR IF @ErrorCode <> 0 RETURN @ErrorCode SET @DrCr = 'D' INSERT INTO RADIOLOGY..tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID, DoctorName, SlipNum, DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @Refnum, @Quantity, @RevenueID, @DoctorName, @SlipNum, @DiscountType, @NetAmount) SET @ErrorCode = @@ERROR IF @ErrorCode <> 0 RETURN @ErrorCode END UPDATE TBCASHCOMMUNICATION SET RECORDSTATUS = 'Y' WHERE ASSESSID = @AssessID AND ISNULL(RECORDSTATUS, '') = ''; SET @ErrorCode = @@ERROR IF @ErrorCode <> 0 RETURN @ErrorCode RETURN @ErrorCode GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_OutCancellation] @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10) AS DECLARE @RevenueID AS varChar(2) DECLARE @RoomID as varchar(10) DECLARE @Quantity as float DECLARE @RequestDocID as varchar(10) declare @ErrorCode int DECLARE @HospNum as varchar(10) DECLARE @DiscRevenueID as varchar(5) DECLARE @DiscAmount as float, @strPatientType varchar(1); DECLARE @CancelledTransNum As varchar set @ErrorCode = 0 BEGIN /* Search for the Existing RefNum */ SET @RevenueID = 'MI'; SET @CancelledTransNum=0; SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode, @HospNum = Hospnum FROM tbMRIRequest WHERE RequestNum = @RequestNum; IF NOT RTRIM(LTRIM(@ItemID)) ='263' --MRI FILMS BEGIN SET @CancelledTransNum = Cast(Substring(RTRIM(LTRIM(@RequestNum)),6,LEN(RTRIM(LTRIM(@RequestNum)))-5) As varchar); Update tbMRIRequestNum SET CancelledTransNum = @CancelledTransNum; END INSERT INTO tbMRIRequest_Cancelled Select * from tbMRIRequest Where Requestnum = @RequestNum; DELETE tbMRIRequest Where Requestnum = @RequestNum; /* -- Update the Record Status UPDATE tbMRIRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum; set @HospNum = (Select HospNum from RADIOLOGY..tbMRIRequest Where RequestNum = @RequestNum); */ /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, HospNum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum,@HospNum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID); END; set @ErrorCode = @@ERROR If @ErrorCode <> 0 Return @ErrorCode RETURN @ErrorCode GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveCashRequest] @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(100) = '', @RevenueID as varchar(2) = '', @PatientID As Varchar(10)='' --Transaction # AS DECLARE @RequestNum AS varChar(8), @DrCr AS varChar(1) --IF @Type = '1' /* MRI */ BEGIN IF RTRIM(LTRIM(@ItemID)) ='263' BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(10), RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1; Set @RequestNum='MI'+@RequestNum; END ELSE BEGIN IF RTRIM(LTRIM(@PatientID)) <> '' BEGIN Set @RequestNum = RTRIM(LTRIM(@PatientID)) ; END END SET @RevenueID = 'MI'; SET @DrCr = 'D'; INSERT INTO tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID, NurseRemarks) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @NurseRemarks) ; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveInCharge] @IDNum AS varChar(10), @ItemID AS varChar(8), @TypeDescription as varchar(30), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @RoomID AS varChar(8), @UserID AS varChar(10), @RefNum AS varChar(10), @NurseRemarks as varchar(50), @DoctorName as varchar(50) = null, @PatientID As Varchar(10)='' --Transaction # AS DECLARE @RequestNum AS varChar(10), @RevenueID AS varChar(2), @DrCr AS varChar(1), @TransNum As Varchar(10), @CancelledTransNum As Int If @DoctorID <> '0' Begin set @DoctorName = null; End; /* MRI */ IF RTRIM(LTRIM(@ItemID)) = '263' BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(10),RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1; Set @RequestNum = 'MI' + @RequestNum; END ELSE BEGIN IF RTRIM(LTRIM(@PatientID)) <> '' BEGIN Set @TransNum = RTRIM(LTRIM(@PatientID)) ; Select @CancelledTransNum=CancelledTransNum From tbMRIRequestNum; IF Cast(Substring(RTRIM(LTRIM(@PatientID)),6,LEN(RTRIM(LTRIM(@PatientID)))-5) As Int) = @CancelledTransNum BEGIN UPDATE tbMRIRequestNum SET CancelledTransNum = 0; END END ELSE BEGIN Select @CancelledTransNum=CancelledTransNum From tbMRIRequestNum; IF @CancelledTransNum > 0 BEGIN SET @Transnum = @CancelledTransNum; --SELECT @TransNum = LTRIM(RTRIM(Convert(varChar(5),TransNum))) FROM tbMRIRequestNum; IF len(LTRIM(RTRIM(@TransNum))) = 1 BEGIN SET @TransNum = '00' + LTRIM(RTRIM(@TransNum)); END IF len(LTRIM(RTRIM(@TransNum))) = 2 BEGIN SET @TransNum = '0' + LTRIM(RTRIM(@TransNum)); END SET @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ LTRIM(RTRIM(@TransNum)); UPDATE tbMRIRequestNum SET CancelledTransNum = 0; END ELSE BEGIN NewNumberLoop: UPDATE tbMRIRequestNum SET TransNum = TransNum + 1; SELECT @TransNum = LTRIM(RTRIM(Convert(varChar(5),TransNum))) FROM tbMRIRequestNum; IF len(LTRIM(RTRIM(@TransNum))) = 1 BEGIN SET @TransNum = '00' + LTRIM(RTRIM(@TransNum)); END IF len(LTRIM(RTRIM(@TransNum))) = 2 BEGIN SET @TransNum = '0' + LTRIM(RTRIM(@TransNum)); END SET @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ LTRIM(RTRIM(@TransNum)); /* SELECT @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ RTRIM(Convert(varChar(10),TransNum)) FROM tbMRIRequestNum; */ SELECT Requestnum From tbMRIRequest Where RequestNum = @Transnum; if @@RowCount > 0 Goto NewNumberLoop SELECT PatientID From DICOM..PatientTable Where PatientID = @Transnum; if @@RowCount > 0 Goto NewNumberLoop END END END SET @RevenueID = 'MI'; SET @DrCr = 'D'; INSERT INTO Radiology..tbMRIRequest (RequestNum, TransDate, IDNum, Code , TypeDescription, Quantity, Amount, HospNum, RequestDoctorCode, RoomID, [By], RefNum, SWFIN, NurseRemarks,DoctorName, RevenueID) VALUES (Case RTRIM(LTRIM(@ItemID)) When '263' then @RequestNum Else @TransNum End, GetDate(), @IDNum, @ItemID, @TypeDescription, @Quantity, @Amount, @Hospnum, @DoctorID, @RoomID, @UserID,@RefNum, 'X', @NurseRemarks, @DoctorName, @RevenueID); INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, RequestNum) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@UserID, @DoctorID, Case RTRIM(LTRIM(@ItemID)) When '263' then @RequestNum Else @TransNum End ); IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID) BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE(), ReferenceNum = @RefNum WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID; END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @TypeDescription, @Quantity, @Amount, 'X', @RefNum, @UserID, GETDATE()); END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveOutCharge] @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(100) = '', @RevenueID as varchar(2) = '', @PatientID As Varchar(10)='' --Transaction # AS DECLARE @RequestNum AS varChar(10), --@RevenueID AS varChar(2), @DrCr AS varChar(1), @TransNum As Varchar(10), @CancelledTransNum As varchar --IF @Type = '1' /* MRI */ BEGIN /* SELECT @RequestNum = RTRIM(Convert(varChar(10), RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1 SET @RevenueID = 'MI' SET @DrCr = 'D' */ IF RTRIM(LTRIM(@ItemID)) = '263' BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(10),RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1; Set @RequestNum = 'MI' + @RequestNum; END ELSE BEGIN IF RTRIM(LTRIM(@PatientID)) <> '' BEGIN Set @TransNum = RTRIM(LTRIM(@PatientID)) ; Select @CancelledTransNum=CancelledTransNum From tbMRIRequestNum; IF Cast(Substring(RTRIM(LTRIM(@PatientID)),6,LEN(RTRIM(LTRIM(@PatientID)))-5) As varchar) = @CancelledTransNum BEGIN UPDATE tbMRIRequestNum SET CancelledTransNum = 0; END END ELSE BEGIN Select @CancelledTransNum=CancelledTransNum From tbMRIRequestNum; IF @CancelledTransNum > 0 BEGIN SET @Transnum = @CancelledTransNum; --SELECT @TransNum = LTRIM(RTRIM(Convert(varChar(5),TransNum))) FROM tbMRIRequestNum; IF len(LTRIM(RTRIM(@TransNum))) = 1 BEGIN SET @TransNum = '00' + LTRIM(RTRIM(@TransNum)); END IF len(LTRIM(RTRIM(@TransNum))) = 2 BEGIN SET @TransNum = '0' + LTRIM(RTRIM(@TransNum)); END SET @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ LTRIM(RTRIM(@TransNum)); UPDATE tbMRIRequestNum SET CancelledTransNum = 0; END ELSE BEGIN NewNumberLoop: UPDATE tbMRIRequestNum SET TransNum = TransNum + 1; SELECT @TransNum = LTRIM(RTRIM(Convert(varChar(5),TransNum))) FROM tbMRIRequestNum; IF len(LTRIM(RTRIM(@TransNum))) = 1 BEGIN SET @TransNum = '00' + LTRIM(RTRIM(@TransNum)); END IF len(LTRIM(RTRIM(@TransNum))) = 2 BEGIN SET @TransNum = '0' + LTRIM(RTRIM(@TransNum)); END SET @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ LTRIM(RTRIM(@TransNum)); /* SELECT @TransNum = Substring(convert(varchar(4),year(getdate()),101),3,2) + 'MR-'+ RTRIM(Convert(varChar(10),TransNum)) FROM tbMRIRequestNum; */ SELECT Requestnum From tbMRIRequest Where RequestNum = @Transnum; if @@RowCount > 0 Goto NewNumberLoop SELECT PatientID From DICOM..PatientTable Where PatientID = @Transnum; if @@RowCount > 0 Goto NewNumberLoop END END END SET @RevenueID = 'MI'; SET @DrCr = 'D'; INSERT INTO tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID, NurseRemarks) VALUES (Case RTRIM(LTRIM(@ItemID)) When '263' then @RequestNum Else @TransNum End, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @NurseRemarks) ; END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity, RequestNum) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, @RoomID, @UserID, @DoctorID, @Quantity, Case RTRIM(LTRIM(@ItemID)) When '263' then @RequestNum Else @TransNum End); end /* OLD? ... --IF @Type = '1' /* MRI */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1 SET @RevenueID = 'MI' SET @DrCr = 'D' INSERT INTO tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID, NurseRemarks) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @NurseRemarks) END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity, RequestNum) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, @RoomID, @UserID, @DoctorID, @Quantity, @RequestNum) end */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveOutRequest] @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(100) = '', @RevenueID as varchar(2) = '' AS DECLARE @RequestNum AS varChar(8), @DrCr AS varChar(1) --IF @Type = '1' /* MRI */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1 SET @RevenueID = 'MI' SET @DrCr = 'D' INSERT INTO tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID, NurseRemarks) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @NurseRemarks) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_InCancellation] @RequestNum AS varChar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10) AS DECLARE @RevenueID AS varChar(2) DECLARE @Quantity as float DECLARE @RoomID as varchar(10) DECLARE @RequestDocID as varchar(10) DECLARE @strPatientType AS VARCHAR(10) DECLARE @CancelledTransNum As Int BEGIN SET @RevenueID = 'MI'; SET @CancelledTransNum=0; SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbMRIRequest WHERE RequestNum = @RequestNum; IF NOT RTRIM(LTRIM(@ItemID)) ='263' --MRI FILMS BEGIN SET @CancelledTransNum = Cast(Substring(RTRIM(LTRIM(@RequestNum)),6,LEN(RTRIM(LTRIM(@RequestNum)))-5) As Int); Update tbMRIRequestNum SET CancelledTransNum = @CancelledTransNum; END INSERT INTO tbMRIRequest_Cancelled Select * from tbMRIRequest Where Requestnum = @RequestNum; DELETE tbMRIRequest Where Requestnum = @RequestNum; /* --- Update the Record Status UPDATE tbMRIRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum */ /*Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_DoctorCharge Script Date: 07/01/2000 1:19:32 AM ******/ CREATE PROCEDURE [dbo].[spMRI_DoctorCharge] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10) AS declare @DeptCode as varchar(2) declare @Hospnum as varchar(10), @RoomID as varchar(10) DECLARE @RequestNum AS varChar(8) if isnumeric(@IDNum) = 1 begin Select @Hospnum = HospNum, @RoomID = RoomID From Patient_Data..tbPatient Where IDNum = @IDNum; end else begin Select @Hospnum = HospNum, @RoomID = 'OPD' From Patient_Data..tbOutPatient Where IDNum = @IDNum end IF right(ltrim(@RefNum),1) = 'S' begin set @DeptCode = 'MI' end; SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbMRIRequestNum UPDATE tbMRIRequestNum SET RequestNum = RequestNum + 1 INSERT INTO tbMRIRequest (RequestNum, Transdate, HospNum, IDNum, Code, SWFIN, [By], Amount, RoomID, RefNum, Quantity, RevenueID) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, 'X', @UserID, @Amount, @RoomID, @RefNum, 1, 'MD') IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '', @DeptCode ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @DeptCode) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_InquiryResult] @ReqNum varchar(10) AS begin SELECT r.ControlNum, e.OtherRevenue [Examination], Case Isnull(r.ResultDate,'') when '' then q.TransDate else r.ResultDate End As ResultDate, q.TransDate, q.Code, q.RequestDoctorCode [DoctorID], d1.FirstName + ' ' + d1.MiddleName +' ' + d1.LastName [Doctor], r.RadCode [RadiologistID], d2.FirstName + ' ' + d2.MiddleName + ' ' + d2.LastName [Radiologist], r.XRayNum [FileNum], r.RoomID, r.TranscribedByID, r.VerifyByID, r.RadCode2 [CoRadiologistID], r.Remarks FROM tbMRIRequest q left join tbMRIResult r on q.requestnum = r.requestnum left join build_file..tbcodoctor d1 on q.requestdoctorcode = d1.doctorid left join build_file..tbcodoctor d2 on r.radcode = d2.doctorid LEFT JOIN BUILD_FILE..tbcoOtherRevenue e on q.Code = e.OtherRevenueID where q.requestnum = @ReqNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_InquiryInterpret] @ReqNum varchar(10) AS begin select Interpretation, Remarks from tbMRIResult where RequestNum = @ReqNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveResult2] @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @TransDate AS DateTime, @ResultDate AS DateTime, @RequestDoctorCode AS varChar(4), @RadCode AS varChar(4), @Interpretation AS Text, @RoomID AS varChar(8), @ResultBy AS varChar(8), @Film8 AS Float, @Film10 AS Float, @Film11 AS Float, @Film14 AS Float, @Film17 AS Float, @FileNum AS varChar(10), @ControlNum AS varChar(10), @DoctorID varchar(5), @ExamTaken varchar(100) , @RadCode2 varchar(4), @Remarks text AS DECLARE @RevenueID AS varChar(2) BEGIN SET @RevenueID = 'MI' INSERT INTO tbMRIResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, --VerifyByID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks) --, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, -- @ResultBy, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks) --, getdate()) UPDATE tbMRIRequest SET SwFin = 'Y', RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum END IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @ResultBy, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spMRILogBook] --declare @StartDate as Varchar(10), @EndDate as Varchar(10), @PatientType as varchar(1) = '' /*set @StartDate = '01/01/2008' set @EndDate = '01/31/2008' set @PatientType = 'o'*/ AS if @PatientType = 'I' Begin Select A.idnum, D.LastName+', '+D.FirstName+' '+D.MiddleName as PatientName, D.Birthdate, D.Age, D.Sex, B.RoomID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.VerifyDate From Radiology..TbMriRequest A Left Outer Join Billing..tbBillDailybill B On A.Idnum = B.Idnum and A.refnum = B.Refnum Left Outer Join Patient_Data..tbPatient C On B.Idnum = C.Idnum Left Outer Join Patient_Data..tbMaster D On C.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.Code = E.OtherRevenueID and OtherSectionID = 'MI' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMriResult G On A.Idnum = G.Idnum and A.RequestNum = G.Requestnum Where B.Revenueid ='MI' and A.SwFin = 'Y' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' end else Select A.idnum, D.LastName+', '+D.FirstName+' '+D.MiddleName as PatientName, D.Birthdate, D.Age, D.Sex, B.RoomID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.VerifyDate From radiology..tbMrirequest A Left Outer Join Billing..tbBillOpDailyout B On A.Idnum = B.Idnum and A.refnum = B.Refnum Left Outer Join Patient_Data..tbOutPatient C On B.Idnum = C.Idnum Left Outer Join Patient_Data..tbMaster D On C.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.Code = E.OtherRevenueID and OtherSectionID = 'MI' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMriresult G On A.Idnum = G.Idnum and A.RequestNum = G.Requestnum Where A.Refnum like 'C%V'and B.Revenueid ='MI' and A.SwFin = 'Y' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' UNION ALL select A.Idnum, C.PaymentFrom as PatientName, D.BirthDate, D.Age, D.Sex, B.RoomID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.VerifyDate from radiology..tbMrirequest A Left Outer Join Billing..tbBillOpDailyOut B On a.refnum = b.refnum --and A.hospnum = B.hospnum Left Outer Join Billing..tbCashOrMaster C On B.Refnum = C.Refnum Left Outer Join Patient_Data..tbMaster D On A.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.Code = E.OtherrevenueID and OtherSectionID = 'MI' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMriresult G On A.RequestNum = G.Requestnum Where A.refnum like 'OR%' and B.Revenueid = 'MI' and A.SwfIn = 'Y' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' order by PatientName GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_ResultFile] @HospNum varchar(8), @RevenueID varchar(2) AS if @RevenueID = 'MI' begin select m.requestnum, Case Isnull(r.resultdate,'') when '' then CONVERT(VARCHAR, cast(m.Transdate as datetime), 101) else CONVERT(VARCHAR, cast(r.resultdate as datetime), 101) End As [Result Date], m.Code [Code], z.OtherRevenue [Exam] from tbMRIrequest m left join tbMRIresult r on m.requestnum = r.requestnum and m.Code = r.ItemCode and m.hospnum = r.hospnum LEFT JOIN build_file..tbcoOtherRevenue Z on m.Code = z.OtherRevenueID where m.swfin = 'Y' AND m.HospNum = @HospNum and Isnull(m.Code,'') <> '263' order by cast(r.resultdate as datetime) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created by : FRIGILLANA, Rodney J. Date Updated : 12 August, 2002 */ CREATE PROCEDURE [dbo].[spRadio_ListPreviousResults_old] @RevenueID AS varChar(2), @HospNum AS varchar(10) /* set @RevenueID = 'MI' set @HospNum = '327' */ AS IF @RevenueID = 'XR' --Xray BEGIN SELECT A.*, B.XrayExam AS ExamName, C.XrayNum AS Filenum FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'US' --Ultrasound BEGIN SELECT A.*, B.UltraExam AS ExamName, C.UltraNum AS Filenum FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'CT' --CT- Scan BEGIN SELECT A.*, B.CTExam AS ExamName, C.CTNum AS Filenum FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'MI' --MRI BEGIN SELECT A.*, B.OtherRevenue AS ExamName, C.MRINum AS Filenum FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Transdate DESC ; END IF @RevenueID = 'MM' --MAMMO BEGIN SELECT A.*, B.OtherRevenue AS ExamName, C.MammoNum AS Filenum FROM Radiology..tbMammoResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemID = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMammoFileNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Transdate DESC ; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Radiology..spRadio_ListPreviousResults 'CT','00189816', '','89' /* Created by : FRIGILLANA, Rodney J. Date Updated : 12 August, 2002 updated 03/12/2007 ---alejandro Updated by Jetty P. Omo- 07/16/2007 Checked if it is verified added for comuunication module to see verified results only */ CREATE PROCEDURE [dbo].[spRadio_ListPreviousResults] @RevenueID AS varChar(2), @HospNum AS varchar(10), @Verified AS varchar(2)= 'N', @Requestnum As varchar(20) = '' AS --declare -- @RevenueID AS varChar(2), -- @HospNum AS varchar(10), -- @Verified AS varchar(2), -- @Requestnum As varchar(20) --set @RevenueID = 'xr' --set @HospNum = '270171' --set @Verified = 'n' --set @Requestnum = '' if @Verified = 'Y' Begin IF @RevenueID = 'XR' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation , A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum and A.VerifyById <> null ORDER BY Examdate DESC ; END IF @RevenueID = 'US' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.UltraNum WHERE A.Hospnum = @HospNum and A.VerifyById <> null ORDER BY Examdate DESC ; END IF @RevenueID = 'CT' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.VerifyById <> null ORDER BY Examdate DESC ; END IF @RevenueID = '' BEGIN SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum and A.VerifyById <> null UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.VerifyById <> null UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.VerifyById <> null UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.OtherRevenue AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate as Examdate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.MRINum AS Filenum,A.radcode FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.VerifyById <> null ORDER BY Examdate DESC END End else IF @Requestnum = '' Begin IF @RevenueID = 'XR' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'US' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.UltraNum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'CT' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.CTNum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC ; END IF @RevenueID = 'MI' --MRI BEGIN SELECT A.HospNum, A.IDNum,A.XrayNum,B.OtherRevenue AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.MRINum AS Filenum,A.radcode --A.*, B.OtherRevenue AS ExamName, C.MRINum AS Filenum FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Transdate DESC ; END /*IF @RevenueID = 'MM' --MAMMO BEGIN SELECT A.HospNum, A.IDNum, C.MammoNum AS Filenum, B.OtherRevenue AS ExamName FROM Radiology..tbMammoResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemID = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMammoFileNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Transdate DESC ; END*/ IF @RevenueID = '' BEGIN SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.UltraNum WHERE A.Hospnum = @HospNum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.CTNum WHERE A.Hospnum = @HospNum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.OtherRevenue AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate as Examdate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.MRINum AS Filenum,A.radcode FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum ORDER BY Examdate DESC END end --------------------------------------- else begin IF @RevenueID = 'XR' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Examdate DESC ; END IF @RevenueID = 'US' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.UltraNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Examdate DESC ; END IF @RevenueID = 'CT' BEGIN --SELECT A.*, SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.CTNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Examdate DESC ; END IF @RevenueID = 'MI' --MRI BEGIN SELECT A.HospNum, A.IDNum,A.XrayNum,B.OtherRevenue AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.MRINum AS Filenum,A.radcode --A.*, B.OtherRevenue AS ExamName, C.MRINum AS Filenum FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Transdate DESC ; END IF @RevenueID = 'MM' --MAMMO BEGIN SELECT A.HospNum, A.IDNum, C.MammoNum AS Filenum, B.OtherRevenue AS ExamName FROM Radiology..tbMammoResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemID = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMammoFileNum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Transdate DESC ; END IF @RevenueID = '' BEGIN SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum,A.radcode FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.XrayNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum,A.radcode FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.UltraNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum,A.radcode FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum and A.XrayNum = C.CTNum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum UNION ALL SELECT A.HospNum, A.IDNum,A.XrayNum,B.OtherRevenue AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate as Examdate, A.ResultDate, A.TranscribedByID, A.RequestDoctorCode, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.MRINum AS Filenum,A.radcode FROM Radiology..tbMRIResult A LEFT OUTER JOIN Build_File..tbcoOtherRevenue B ON A.ItemCode = B.OtherRevenueID LEFT OUTER JOIN Radiology..tbMRINum C ON A.Hospnum = C.Hospnum WHERE A.Hospnum = @HospNum and A.Requestnum = @Requestnum ORDER BY Examdate DESC END END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_VerifyResult] @RequestNum AS varChar(8), @VerifyByID AS varChar(8), @VerifyDate AS DateTime AS BEGIN UPDATE tbMRIResult SET VerifyByID = @VerifyByID, VerifyDate = getdate() WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spMRI_PrintResult] --declare @RequestNum as varchar (15) --set @requestNum = '3910' --5726 --3916 AS select A.RequestNum,case when isnull(A.hospnum,'')= ''--isnumeric(A.HospNum) = 1 then Cash.LastName + ', ' + Cash.FirstName + ' ' + Cash.MiddleName else B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName end PatientName, A.HospNum,A.Idnum,D.LastName + ', ' + D.FirstName + ' ' + D.MiddleName Doctor, A.ExamTaken, case when isnumeric(A.HospNum) = 1 then dbo.fn_ComputeAge(B.BirthDate,getdate()) else dbo.fn_ComputeAge(Cash.BirthDate,getdate()) end AGe, case when isnumeric(A.HospNum) = 1 then Case when B.Sex = 'M' then 'Male' else 'Female' end else Case when Cash.Sex = 'M' then 'Male' else 'Female' end end Sex, Case when isnull(C.RoomID,'') = '' then 'CASH' else C.RoomID end RoomID, E.TransDate ExamDate, A.Interpretation, case when isnull(D1.FirstName,'') = '' then '' else D1.FirstName + ' ' + D1.MiddleName + ' ' + D1.LastName + ' M.D., FPCR' end As RAdiologist, case when isnull(D2.FirstName,'') = '' then '' else D2.FirstName + ' ' + D2.MiddleName + ' ' + D2.LastName + ' M.D., FPCR' end As coRAdiologist from Radiology..tbMRIResult A Inner join Radiology..tbMRIRequest E on A.Requestnum= E.RequestNum Left Join Patient_data..tbpatient C on A.IDNum = C.Idnum Left Join Patient_Data..tbMaster B on A.HospNum = B.HospNum Left Join Build_File..tbcoDoctor D on E.requestdoctorcode = D.DoctorID --C.AttendingDr1 = D.DoctorID Left Join Build_File..tbcoDoctor D1 on D1.DoctorID = A.Radcode Left join Patient_data..tbcashpatient Cash on A.HospNum= Cash.Hospnum Left Join Build_File..tbcoDoctor D2 on D2.DoctorID = A.Radcode2 Where A.RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_SaveRetrieve2] @RequestNum AS varChar(10), @RadCode AS varChar(4), @DoctorID as varchar(5), @Interpretation AS Text, @Remarks as Text, @RadCode2 as varchar(4), @ResultDate as varchar(10) AS BEGIN UPDATE tbMRIResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate WHERE RequestNum = @RequestNum; UPDATE tbMRIRequest Set RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_UpdatePatientID] @IDNum As Varchar(10), @ItemCode As Varchar(4), @OldPatientID As Varchar(10), @NewPatientID As Varchar(10) AS /* DECLARE @IDNum As Varchar(10), @ItemCOde As Varcahr(4), @OldPatientID As Varchar(10), @NewPatientID As Varchar(10) */ DECLARE @StudyUID As Varchar(64), @StudyID As Varchar(50), @RefDoc As Varchar(4), @Radiologist As Varchar(4), @ExamResult As Varchar(8000) BEGIN --Update PatientID Update Radiology..tbMRIRequest Set RequestNum = @NewPatientID Where RequestNum = @OldPatientID and Code = @ItemCode and IDnum = @IDnum; Update Radiology..tbMRIResult Set RequestNum = @NewPatientID Where RequestNum = @OldPatientID and ItemCode = @ItemCode and IDnum = @IDnum; Select @StudyUID = A.StudyUID,@StudyID = A.StudyID, @RefDoc = B.RefDoctor_ID,@Radiologist = B.Radiologist_ID, @ExamResult = B.Exam_Result From DICOM..StudyTable A Inner Join DICOM..tblExamresult B On A.StudyId = B.StudyID and A.StudyUId = B.StudyUID and B.Modality = 'MR' Where A.PatientID_FKey = @NewPatientID; --IF EXISTS(Select Top 1 * From RADIOLOGY..tbMRIResult Where RequestNum = @NewPatientID and ItemCode = @ItemCode and IDnum = @IDnum) Select Top 1 * From RADIOLOGY..tbMRIResult Where RequestNum = @NewPatientID and ItemCode = @ItemCode and IDnum = @IDnum; IF @@rowcount > 0 BEGIN UPDATE RADIOLOGY..tbMRIResult Set RequestDoctorCode = @RefDoc, Interpretation = @ExamResult, RadCode = @Radiologist, RequestNum = @NewPatientID, PatientID = @NewPatientID, StudyUID = @StudyUID, StudyID = @StudyID Where RequestNum = @NewPatientID and ItemCode = @ItemCode and IDnum = @IDnum; Update Radiology..tbMRIRequest Set SWFin = 'Y',RequestNum = @NewPatientID Where RequestNum = @NewPatientID and IsNull(SwFin,'')='X' and Code = @ItemCode and IDnum = @IDnum; END ELSE BEGIN Select * from DICOM..StudyTable Where PatientID_FKey = @NewPatientID; IF @@Rowcount > 0 BEGIN INSERT INTO RADIOLOGY..tbMRIResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, --VerifyByID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks,PatientID,StudyID,StudyUID) --, VerifyDate) (Select A.Hospnum,A.IDNum,A.RequestNum,Code,A.TransDate, C.Date_Created,C.RefDoctor_ID,C.Radiologist_ID,C.Exam_Result,A.RoomID, '',A.RequestNum,A.TypeDescription,'','','',B.PatientID_FKey,B.StudyID,B.StudyUID From Radiology..tbMRIRequest A Inner Join DICOM..StudyTable B On A.RequestNum = B.PatientID_FKey Inner Join DICOM..tblExamResult C On B.StudyId = C.StudyID and C.Modality = 'MR' Where A.RequestNum = @NewPatientID and IsNull(A.SwFin,'')='X' and Code = @ItemCode and IDnum = @IDnum); Update Radiology..tbMRIRequest Set SWFin = 'Y' Where RequestNum = @NewPatientID and IsNull(SwFin,'')='X' and Code = @ItemCode and IDnum = @IDnum; END END END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_PatientResultFile] @HospNum varchar(10), @RevenueID varchar(2) AS if @RevenueID = 'MI' begin select m.requestnum PatientID, /*Case Isnull(r.resultdate,'') when '' then CONVERT(VARCHAR, cast(m.Transdate as datetime), 101) else CONVERT(VARCHAR, cast(r.resultdate as datetime), 101) End As [Result Date]*/ Convert(Varchar,m.TransDate,9) [Exam date], m.Code [Code], z.OtherRevenue [Exam], m.IDNum IDNum from tbMRIrequest m LEFT OUTER JOIN tbMRIresult r on m.requestnum = r.requestnum and m.Code = r.ItemCode and m.hospnum = r.hospnum LEFT OUTER JOIN build_file..tbcoOtherRevenue Z on m.Code = z.OtherRevenueID and z.OtherSectionID = @RevenueID where --m.swfin = 'Y' AND m.HospNum = @HospNum and Isnull(m.Code,'') <> '263' order by m.transdate--cast(r.resultdate as datetime) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Created by : Jetty P. Omo --Use to get the interpretation --To see the full interpreation in the RTF file without any other Characters --OCt 22,2007 CREATE procedure [dbo].[sp_GetInterpretationOnly] @Form as varchar(20), @RequestNumber as varchar(20) AS IF @Form = 'XRAY' Begin --Xray Select Interpretation,* from tbXRresult where requestnum = @RequestNumber End IF @Form = 'ULTRA' Begin --Ultrasound Select Interpretation,* from tbULresult where requestnum = @RequestNumber End IF @Form = 'CTSCAN' Begin --CT - Scan Select Interpretation,* from tbCTresult where requestnum = @RequestNumber End IF @Form = 'MRI' Begin --CT - Scan Select Interpretation,* from tbMRIresult where requestnum = @RequestNumber End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --aLTERED bY JETTY p. OMO --aDDED MRI CREATE PROCEDURE [dbo].[spRadio_IsResultVerified] @RequestNum as varchar(10), @Type as varchar(1) AS --set @RequestNum = '170646' if @Type = '1' --CT Scan Begin Select rtrim(isnull(VerifyByID,'')) as VerifyByID From tbCTResult Where RequestNum = @RequestNum End; Else if @Type = '2' --Xray Begin Select rtrim(isnull(VerifyByID,'')) as VerifyByID From tbXRResult Where RequestNum = @RequestNum End; Else if @Type = '3' --Ultrasound Begin Select rtrim(isnull(VerifyByID,'')) as VerifyByID From tbULResult Where RequestNum = @RequestNum End; Else if @Type = '4' --mri Begin Select rtrim(isnull(VerifyByID,'')) as VerifyByID From tbMRIResult Where RequestNum = @RequestNum End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ChargesbySlip] @ChargeSlip varchar(10), @UserID varchar(10) AS delete tbChargeSlip where UserID = @UserID; insert into tbChargeSlip (Code, Description, Price, Quantity, Amount, UserID) select b.itemid, case b.revenueid when 'MM' then r.OtherRevenue when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end as price, b.quantity, b.amount, @UserID from BILLING..tbbilldailybill b left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip union all select b.itemid, case b.revenueid when 'MM' then r.OtherRevenue when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as description, case when isnull(b.quantity, 0) = 0 then 0 else b.amount / b.quantity end as price, b.quantity, b.amount, @UserID from BILLING..tbbillopdailyout b left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on b.itemid = d.doctorid where b.refnum = @ChargeSlip GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spGlobal_DumpChargeSlip Script Date: 07/01/2000 1:20:51 AM ******/ CREATE PROCEDURE [dbo].[spGlobal_DumpChargeSlip] @Code varchar(10), @Description varchar(50), @Quantity float, @Price float, @Amount float, @UserID varchar(10) AS INSERT INTO RADIOLOGY..tbChargeSlip (Code, Description, Quantity, Price, Amount, UserID) VALUES (@Code, @Description, @Quantity, @Price, @Amount, @UserID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ChargeslipProfile] @ChargeslipNo as float AS Update Radiology..tbOBULOPD set CSlip = @ChargeslipNo GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveOutCharge] @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(50), @DoctorName as varchar(50) = null, @Portable as varchar(1), @RevenueID AS varChar(2) = '', @NurseRequestNum as varchar(10) = null AS DECLARE @RequestNum AS varChar(8), @DrCr AS varChar(1), @ItemDesc as varchar(50) If @DoctorID <> '0' Begin set @DoctorName = null; End /* OB Ultrasound */ BEGIN Set @ItemDesc = (Select OtherRevenue from Build_File..tbcoOtherRevenue where OtherRevenueID = @ItemID) SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbOBULOpd UPDATE tbOBULOpd SET RequestNum = RequestNum + 1 SET @DrCr = 'D' INSERT INTO tbOBULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRemarks, DoctorName, RevenueID, portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRemarks, @DoctorName,@Revenueid, @Portable, @NurseRequestNum) END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity, RequestNum, DoctorName) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, @RoomID, @UserID, @DoctorID, @Quantity, @RequestNum, @DoctorName) end IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '') BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE(), ReferenceNum = @RefNum WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '' UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '' END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate, RequestNum, Remarks) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @ItemDesc, @Quantity, @Amount, 'X', @RefNum, @UserID, GETDATE(), @NurseRequestNum, 'Manually Posted') END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveInCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @TypeDescription as varchar(30), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @RoomID AS varChar(8), @UserID AS varChar(10), @RefNum AS varChar(10), @Film1 as int, @Film2 as int, @Film3 as int, @Film4 as int, @Film5 as int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(50), @DoctorName as varchar(50) = null, @ChargeRevenueID as varchar(2) = '', @Portable as varchar(1) = '', @RevenueID AS varChar(2), @MarkupRate as float (8) = 0, @NurseRequestNum as varchar(10) = null AS DECLARE @RequestNum AS varChar(8), @DrCr AS varChar(1) If @DoctorID <> '0' Begin set @DoctorName = null End; IF @Type = '4' /* OB Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbOBULOpd UPDATE tbOBULOpd SET RequestNum = RequestNum + 1 SET @DrCr = 'D' INSERT INTO tbOBULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRemarks, DoctorName, RevenueID, portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRemarks, @DoctorName,@RevenueID, @Portable, @NurseRequestNum) END INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, RequestNum, DoctorName, MarkupRate) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@UserID, @DoctorID, @RequestNum, @DoctorName, @MarkupRate) IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '') BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE(), ReferenceNum = @RefNum WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '' UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X' WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(recordstatus,'')= '' END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate,Remarks) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @TypeDescription, @Quantity, @Amount, 'X', @RefNum, @UserID, GETDATE(),'Manually Posted') END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveRequestOnly] @DepartmentID varchar(2), @HospNum varchar(8), @IDNum varchar(10), @Code varchar(8), @RequestDoctorCode varchar(8), @Quantity float, @Amount float, @RoomID varchar(8), @RefNum varchar(10), @RevenueID varchar(2), @UserID varchar(10) AS declare @RequestNum varchar(10) IF @DepartmentID = 'WC' /* WOMEN Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbOBULOpd SET RequestNum = RequestNum + 1 INSERT INTO tbOBULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By]) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[SP_Radiology_UserLogin] @LogSequence as varchar(5), @EmployeeID as varchar(50), @Remarks as Text, @LogInDate as datetime, @LogOutDate as datetime = null As Declare @strRemarks as varchar(500); if Exists(Select * From tbRadiology_Userlogin Where EmployeeID = @EmployeeID and LogOutDate is null) Begin set @strRemarks = (Select top 1 Cast(Remarks as varchar(1000)) From tbRadiology_Userlogin Where EmployeeID = @EmployeeID and LogOutDate is null) + ' Not Properly Logout' Update tbRadiology_Userlogin set LogOutDate = getdate(), Remarks = @strRemarks Where EmployeeID = @EmployeeID and LogOutDate is null; End; If @LogoutDate = '' Begin Set @LogoutDate = Null End; insert into tbRadiology_Userlogin(LogSequence, EmployeeID, Remarks, LogInDate, LogOutDate) values(@LogSequence, @EmployeeID, @Remarks, GetDate(), @LogoutDate) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Radio_UpdateLogRemarks] @EmployeeID as varchar(10), @Remarks as text AS Update tbRadiology_UserLogin Set Remarks = @Remarks Where EmployeeID = @EmployeeID and LogOutDate is null; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_Radiology_Search_User] (@Type as varchar(1), @UserID as varchar(5), @Date as varchar(10)) AS if @Type = '1' select A.LogSequence, A.EmployeeID, ltrim(rtrim(isnull(B.lastname,''))) + ', ' + ltrim(rtrim(isnull(B.firstname,''))) + ' ' + ltrim(rtrim(isnull(B.middlename,''))) as Name, A.LoginDate, A.LogoutDate, Remarks from tbRadiology_Userlogin A left outer join password..tbpasswordmaster B on A.EmployeeID = B.EmployeeID where A.EmployeeID = @UserID order by A.logsequence desc else if @Type = '2' select A.LogSequence, A.EmployeeID, ltrim(rtrim(isnull(B.lastname,''))) + ', ' + ltrim(rtrim(isnull(B.firstname,''))) + ' ' + ltrim(rtrim(isnull(B.middlename,''))) as Name, A.LoginDate, A.LogoutDate, Remarks from tbRadiology_Userlogin A left outer join password..tbpasswordmaster B on A.EmployeeID = B.EmployeeID where A.LogSequence = @UserID order by A.logsequence desc else if @Type = '3' select A.LogSequence, A.EmployeeID, ltrim(rtrim(isnull(B.lastname,''))) + ', ' + ltrim(rtrim(isnull(B.firstname,''))) + ' ' + ltrim(rtrim(isnull(B.middlename,''))) as Name, A.LoginDate, A.LogoutDate, Remarks from tbRadiology_Userlogin A left outer join password..tbpasswordmaster B on A.EmployeeID = B.EmployeeID order by A.logsequence desc GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[SP_Radiology_UserLogin_Update] @EmployeeID as varchar(50) as Update tbRadiology_Userlogin Set LogoutDate = Getdate() Where EmployeeId= @EmployeeID and LogoutDate = null; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Created by Jetty P. Omo Setup for Radiology - Cash Rate ~ Opd Rate = RateA in the Build_File ~ Cash Rate = RateG in the Build_file ~ Socialized = Rate is according to Room Rate - Included PACS enable/disable - Markup Rate for Exam during Holiday and other special cases - Portable markup rate --02/02/2008 -Added Company setup ~ 1 = Enabled ~ 2 = Disabled ~ 3 = RateH File Altered By Gonzalo Added the following: -Option to disable the client/agents ie bonzi -Option to disable Dictation -Further Markup Specifications -Option to disable if result to be updated/verified only by radiologist; if results to be verified by thumbprint scanner; if exams are to be edited/displayed/printed through application extension; if the report to be used is through client's own requirements. */ alter Procedure [dbo].[Sp_RadioSetup] @Mode as varchar(1), @Department as varchar(2) = '', @CashBasis as varchar(1) = '', @ChargeSlipSetup as bit = '', @UserID as varchar(20) = '', @Markup as varchar(5) = '0', @PortableMrkup as varchar(10) = '0', @PortableOperator as varchar(1) = '*', @PACS as varchar(1) = '', @Company as int = '1', @CompanyMarkup as int = '0', @FileNoSetup as bit = 1, @FileNumber as int = '0', @FileNoPrefix as varchar(10) = '', @Bonzi as varchar(1) = '0', @Merlin as varchar(1) = '0', @Dictation as varchar(1) = '0', @HighestMarkUpLimit as varchar(20) = '0', @HMarkUpLimitOperator as varchar(1) = '', @BeyondRegHrsMarkUp as varchar(20) = '0', @BeyondRegHrsMarkUpOperator as varchar(1) = '', @BeyondRegHrsFrom as varchar(20) = '', @BeyondRegHrsTo as varchar(20) = '', @StatOperator as varchar(1) = '', @ERPatientMarkUp as varchar(20) = '0', @ERPatientOperator as varchar(1) = '', @HolidayMarkUp as varchar(20) = '0', @HolidayOperator as varchar(1) = '', @ResultUpdateOnlyByRadiologist as varchar(1) = '0', @VerifyByFingerPrint as varchar(1) = '0', @ResultDLL as varchar(1) = '0', @ResultFormatted as varchar(1) = '0' AS if @Mode = '1' Begin select isnull(A.Cashbasis,1) as Cashbasis,isnull(A.chargeslipsetup,0)as chargeslipsetup, isnull(A.Userid,'')as Userid,isnull(A.Markup,0)as Markup/*Table A is for Stat Markup*/,isnull(A.MarkupOperator,'')as MarkupOperator, A.Department, isnull(B.Markup,0) as PMArkup/*Table B is for Portable Markup*/,B.Operator,isnull(A.Pacs,0) Pacs, isnull(A.Company,2) Company,isnull(A.CompanyMarkup,0) CompanyMarkup, isnull(A.FileNoSetup,1) as FileNoSetup,isnull(A.FileNumber,0) as FileNumber, isnull(FileNoPrefix,'') as FileNoPrefix, isnull(Bonzi,'0') as Bonzi, isnull(Merlin,'0') as Merlin, isnull(Dictation,'0') as Dictation, isnull(HighestMarkUpLimit,'0') as HighestMarkUpLimit, isnull(HMarkUpLimitOperator,'') as HMarkUpLimitOperator, isnull(BeyondRegHrsMarkUp,'0') as BeyondRegHrsMarkUp, isnull(BeyondRegHrsMarkUpOperator,'') as BeyondRegHrsMarkUpOperator, Convert(varchar(20), isnull(BeyondRegHrsFrom, getdate()), 108) as BeyondRegHrsFrom, Convert(varchar(20), isnull(BeyondRegHrsTo, getdate()), 108) as BeyondRegHrsTo, isnull(ERPatientMarkUp,'0') as ERPatientMarkUp, isnull(ERPatientOperator,'') as ERPatientOperator, isnull(HolidayMarkUp,'0') as HolidayMarkUp, isnull(HolidayOperator,'') as HolidayOperator, isnull(A.ResultUpdateOnlyByRadiologist,'0') as ResultUpdateOnlyByRadiologist, isNull(A.VerifyByFingerPrint,'0') as [VerifyByFingerPrint], isnull(A.ResultDLL,'0') as ResultDLL, isnull(A.ResultFormatted, '0') as ResultFormatted from tbRadiosetup A Left Outer Join tbRadioMarkUpOptions B on A.Department = B.DepartmentID where Department = @Department End if @Mode = '2' Begin delete tbRadiosetup WHERE Department = @Department Insert into tbRadiosetup( Department,CashBasis,ChargeSlipSetup,UserID,Markup, Pacs,Company,CompanyMarkup,FileNoSetup,FileNumber, FileNoPrefix, Bonzi, Merlin, Dictation, MarkUpOperator, ResultUpdateOnlyByRadiologist,VerifyByFingerPrint,ResultDLL, ResultFormatted) Values( @Department,@CashBasis,@ChargeSlipSetup,@UserID,@Markup, @Pacs,@Company,@CompanyMarkup,@FileNoSetup,@FileNumber, @FileNoPrefix, @Bonzi, @Merlin, @Dictation, @StatOperator, @ResultUpdateOnlyByRadiologist,@VerifyByFingerPrint,@ResultDLL, @ResultFormatted) update tbRadioMarkUpOptions set Markup = @PortableMrkup, Operator = @PortableOperator, HighestMarkUpLimit = @HighestMarkUpLimit, HMarkUpLimitOperator = @HMarkUpLimitOperator, BeyondRegHrsMarkUp = @BeyondRegHrsMarkUp, BeyondRegHrsMarkUpOperator = @BeyondRegHrsMarkUpOperator, BeyondRegHrsFrom = @BeyondRegHrsFrom, BeyondRegHrsTo = @BeyondRegHrsTo, ERPatientMarkUp = @ERPatientMarkUp, ERPatientOperator = @ERPatientOperator, HolidayMarkUp = @HolidayMarkUp, HolidayOperator = @HolidayOperator where DepartmentID = @Department if @FileNoSetup = 0 Begin update tbRadiosetup set FileNoSetup = 0 end ELSE Begin update tbRadiosetup set FileNoSetup = 1 end End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadBorrowedFilm] @RevenueID varchar(2), @RequestNum varchar(10) AS if @RevenueID = 'XR' begin select * from tbXRBorrowedFilm where IsReturned = 0 and RequestNum = @RequestNum OR RequestNumbers like '%' + @RequestNum + '%' end; if @RevenueID = 'CT' begin select * from tbCTBorrowedFilm where IsReturned = 0 and RequestNum = @RequestNum OR RequestNumbers like '%' + @RequestNum + '%' end; if @RevenueID = 'US' begin select * from tbULBorrowedFilm where IsReturned = 0 and RequestNum = @RequestNum OR RequestNumbers like '%' + @RequestNum + '%' end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveBorrowedFilm1] @RevenueID varchar(2), @ReturnMode varchar(1), @RequestNum varchar(10), @Name varchar(50), @Location varchar(50), @UserID varchar(10), @ID as varchar(10), @ByFolder as bit = 0, @RequestNumbers as varchar(200) = '' AS if @RevenueID = 'XR' begin if @ReturnMode = '0' --borrow begin insert into tbXRBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned, BorrowedByID, ByFolder, RequestNumbers) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0, @ID, @ByFolder, @RequestNumbers) end else --return begin update tbXRBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID, ReturnedByID = @ID, ByFolder = @ByFolder, RequestNumbers = @RequestNumbers where RequestNum = @RequestNum and IsReturned = 0 end end if @RevenueID = 'CT' begin if @ReturnMode = '0' --borrow begin insert into tbCTBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned,BorrowedByID, ByFolder, RequestNumbers) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0,@ID, @ByFolder, @RequestNumbers) end else --return begin update tbCTBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID, ReturnedByID = @ID, ByFolder = @ByFolder, RequestNumbers = @RequestNumbers where RequestNum = @RequestNum and IsReturned = 0 end end if @RevenueID = 'US' begin if @ReturnMode = '0' --borrow begin insert into tbULBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned,BorrowedByID, ByFolder, RequestNumbers) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0, @ID, @ByFolder, @RequestNumbers) end else --return begin update tbULBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID, ReturnedById = @ID, ByFolder = @ByFolder, RequestNumbers = @RequestNumbers where RequestNum = @RequestNum and IsReturned = 0 end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveBorrowedFilm] @RevenueID varchar(2), @ReturnMode varchar(1), @RequestNum varchar(10), @Name varchar(50), @Location varchar(50), @UserID varchar(10) AS if @RevenueID = 'XR' begin if @ReturnMode = '0' --borrow begin insert into tbXRBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0) end else --return begin update tbXRBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID where RequestNum = @RequestNum and IsReturned = 0 end end if @RevenueID = 'CT' begin if @ReturnMode = '0' --borrow begin insert into tbCTBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0) end else --return begin update tbCTBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID where RequestNum = @RequestNum and IsReturned = 0 end end if @RevenueID = 'US' begin if @ReturnMode = '0' --borrow begin insert into tbULBorrowedFilm (RequestNum, BorrowedBy, Location, BorrowedDate, BorrowUserID, IsReturned) values (@RequestNum, @Name, @Location, GETDATE(), @UserID, 0) end else --return begin update tbULBorrowedFilm set ReturnedBy = @Name, ReturnedDate = GETDATE(), IsReturned = 1, ReturnUserID = @UserID where RequestNum = @RequestNum and IsReturned = 0 end end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultForViewing] @RequestNum varchar(10), @RevenueID varchar(2), @UserID varchar(10) AS declare @HospNum varchar(10), @PatientName varchar(90), @CivilStatus varchar(10), @BirthDate datetime, @Age varchar(3), @cAge varchar(3), @ResultDate datetime, @Sex varchar(6), @AdmNum varchar(10), @Address varchar(100), @TelNo varchar(10), @PatientClass varchar(1), @Classification varchar(10), @TranscribedBy varchar(10) -- added by BSL March 17, 2003 if @RevenueID = 'XR' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbxrrequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbXRResult where requestnum = @RequestNum end if @RevenueID = 'CT' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbCTRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbCTResult where requestnum = @RequestNum end if @RevenueID = 'US' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbULRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbULResult where requestnum = @RequestNum end set @PatientClass = '' /*if ISNUMERIC(@AdmNum) = 1 begin select @PatientClass = ISNULL(PatientClass, '') from PATIENT_DATA..tbPatient2 where IDNum = @Admnum end else begin select @PatientClass = LEFT(ISNULL(PatientType, ''), 1) from PATIENT_DATA..tbOutPatient where IDNum = @AdmNum end if @PatientClass = 'S' set @Classification = 'SERVICE' else if @PatientClass = 'P' set @Classification = 'PAY' else set @Classification = 'SERVICE'*/ set @Classification = (select case isnull(MSSClassification,'') when '' then 'PAY' else 'SERVICE' end as Classification from PATIENT_DATA..tbMaster where hospnum = @HospNum) if isnumeric(@HospNum) = 1 begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = TelNum from PATIENT_DATA..tbMaster m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatus = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end else begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = '' from PATIENT_DATA..tbCashPatient m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatusID = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end IF (@BirthDate is null) or (@BirthDate <= '01/01/1900') BEGIN SET @cAge = @Age END ELSE BEGIN SET @cAge = convert(varchar(3), cast((year(@ResultDate) + (cast(month(@ResultDate) as float)/12) + (cast(day(@ResultDate) as float)/365)) - (year(@BirthDate) + (cast(month(@BirthDate) as float)/12) + (cast(day(@BirthDate) as float)/365)) as int) ) END delete tbRadioResult where UserID = @UserID if @RevenueID = 'XR' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate ) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.XrayExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @USerID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'XR' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate] from tbXRRequest q left join tbXRResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoXrayExam e on q.Code = e.XrayExamID where q.RequestNum = @RequestNum end if @RevenueID = 'CT' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate ) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.CTExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'CT' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate] from tbCTRequest q left join tbCTResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoCTExam e on q.Code = e.CTExamID where q.RequestNum = @RequestNum end if @RevenueID = 'US' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate ) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.UltraExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'US' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate] from tbULRequest q left join tbULResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoUltraExam e on q.Code = e.UltraExamID where q.RequestNum = @RequestNum end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultForViewing2] @RequestNum varchar(10), @RevenueID varchar(2), @UserID varchar(10) AS declare @HospNum varchar(10), @PatientName varchar(90), @CivilStatus varchar(10), @BirthDate datetime, @Age varchar(3), @cAge varchar(3), @ResultDate datetime, @Sex varchar(6), @AdmNum varchar(10), @Address varchar(100), @TelNo varchar(10), @PatientClass varchar(1), @Classification varchar(10), @TranscribedBy varchar(10) -- added by BSL March 17, 2003 if @RevenueID = 'XR' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbxrrequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbXRResult where requestnum = @RequestNum end if @RevenueID = 'CT' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbCTRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbCTResult where requestnum = @RequestNum end if @RevenueID = 'US' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbULRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbULResult where requestnum = @RequestNum end set @PatientClass = '' /*if ISNUMERIC(@AdmNum) = 1 begin select @PatientClass = ISNULL(PatientClass, '') from PATIENT_DATA..tbPatient2 where IDNum = @Admnum end else begin select @PatientClass = LEFT(ISNULL(PatientType, ''), 1) from PATIENT_DATA..tbOutPatient where IDNum = @AdmNum end if @PatientClass = 'S' set @Classification = 'SERVICE' else if @PatientClass = 'P' set @Classification = 'PAY' else set @Classification = 'SERVICE'*/ set @Classification = (select case isnull(MSSClassification,'') when '' then 'PAY' else 'SERVICE' end as Classification from PATIENT_DATA..tbMaster where hospnum = @HospNum) if isnumeric(@HospNum) = 1 begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = TelNum from PATIENT_DATA..tbMaster m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatus = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end else begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = '' from PATIENT_DATA..tbCashPatient m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatusID = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end IF (@BirthDate is null) or (@BirthDate <= '01/01/1900') BEGIN SET @cAge = @Age END ELSE BEGIN SET @cAge = convert(varchar(3), cast((year(@ResultDate) + (cast(month(@ResultDate) as float)/12) + (cast(day(@ResultDate) as float)/365)) - (year(@BirthDate) + (cast(month(@BirthDate) as float)/12) + (cast(day(@BirthDate) as float)/365)) as int) ) END delete tbRadioResult where UserID = @UserID if @RevenueID = 'XR' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate , Encoder) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.XrayExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @USerID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'XR' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder] from tbXRRequest q left join tbXRResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoXrayExam e on q.Code = e.XrayExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID where q.RequestNum = @RequestNum end if @RevenueID = 'CT' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate ,Encoder) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.CTExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'CT' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder] from tbCTRequest q left join tbCTResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoCTExam e on q.Code = e.CTExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID where q.RequestNum = @RequestNum end if @RevenueID = 'US' begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate, Encoder ) select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.UltraExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, case when s.RadCode = '0' then s.RadiologistName when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'US' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder] from tbULRequest q left join tbULResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.ResidentID = d3.DoctorID left join BUILD_FILE..tbCoUltraExam e on q.Code = e.UltraExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID where q.RequestNum = @RequestNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --exec RADIOLOGY..spRadio_RequestStatus '2', '02/07/2008','02/07/2008', '' /* Added the ff . Start date - Start of Date Range on searching End Date - End of Date Range on searching Search Criteria - Lastname of patient AGE,DOctor,Room and Birthdate At the same time it will show if the result is Draft or verified */ /* X - Processed V - Verified Y - Draft C/R - Revoked/Cancelled */ CREATE PROCEDURE [dbo].[spRadio_RequestStatus_Result] @Status as varchar(1), @RevenueType as varchar(1), @StartDate as varchar(20), @EndDate as varchar(20), @SearchCriteria as varchar(20), @DoctorID as varchar(10) = 'ALL' AS --declare --@Status as varchar(1), --@RevenueType as varchar(1), --@StartDate as varchar(20), --@EndDate as varchar(20), --@SearchCriteria as varchar(20), --@DoctorID as varchar(10) -- --set @Status = 'X' --set @RevenueType = '2' --set @StartDate = '01/17/2011' --set AND @EndDate + ' 23:59:59.99' = '01/17/2011' --set @SearchCriteria = '' --set @DoctorID = 'ALL' if @StartDate is null begin set @StartDate = convert(varchar,getdate(),101) end if @EndDate is null Begin set @EndDate = convert(varchar,getdate(),101) End if @DoctorID Not In ('','ALL') Begin if @Status in ('A') --All Exams by Doctor Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate End End --======================================================================================================================== if @Status in ('X','C') -- Cancelled/Processed and Without Results yet. No segragation of doctors yet. Plain processed requests. Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate End End --=============================================================================================================== if @Status in ('Y') --Draft Results. With or Without Doctors. Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate End End --============================================================================================================================ if @Status in ('V') Begin Set @Status = 'Y'; if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate End End End --=========================================================================================================================== --=========================================================================================================================== --=========================================================================================================================== --=========================================================================================================================== --=========================================================================================================================== if @DoctorID In ('','ALL') Begin if @Status in ('A') --Draft Results. With or Without Doctors. Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') -- and IsNull(Res.VerifyByID, '') = '' order by A.TransDate End End if @Status in ('X','C') -- Cancelled/Processed and Without Results yet. No segragation of doctors yet. Plain processed requests. Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status order by A.TransDate End End --=============================================================================================================== if @Status in ('Y') --Draft Results. With or Without Doctors. Begin if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbXRresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status], -- 'X' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') = '' order by A.TransDate End End --============================================================================================================================ if @Status in ('V') Begin Set @Status = 'Y'; if @RevenueType = '1' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' -- and @DoctorID in () union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm. #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN RADIOLOGY..tbCTResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate END; if @RevenueType = '2' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- = convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN RADIOLOGY..tbXRResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate END; if @RevenueType = '3' BEGIN select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' Union all select Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, A.IdNum [Adm #], A.Hospnum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], 'V' as [Request Status], A.RoomID, A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate, Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum, A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN RADIOLOGY..tbULResult Res On A.RequestNum = Res.RequestNum LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' and IsNull(A.SWFin,'') = @Status -- and IsNull(Res.RadCode,'') in (@DoctorID, '') and IsNull(Res.VerifyByID, '') <> '' order by A.TransDate End End End /* ============================================================================== ==============================Previous Script================================= ============================================================================== Gonzalo, 01172011 */ --if @RevenueType = '1' --BEGIN -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm. #], A.Hospnum [Hosp #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.CTExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' -- else 'V' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbCTRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B -- ON A.Code = B.CTExamID -- LEFT OUTER JOIN PATIENT_DATA..tbmaster C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- --union all -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm. #], A.Hospnum [Hosp #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.CTExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'V' -- else 'Y' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbCTRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B -- ON A.Code = B.CTExamID -- LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- order by A.TransDate --END; -- --if @RevenueType = '2' --BEGIN -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.XrayExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbxrresult where requestnum = A.requestnum ) is null then 'V' -- else 'Y' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbXRRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B -- ON A.Code = B.XrayExamID -- LEFT OUTER JOIN PATIENT_DATA..tbmaster C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- -- = convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- --union all -- -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.XrayExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbxrresult where requestnum = A.requestnum ) is null then 'V' -- else 'Y' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbXRRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B -- ON A.Code = B.XrayExamID -- LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- order by A.TransDate --END; -- --if @RevenueType = '3' --BEGIN -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.UltraExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'V' -- else 'Y' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbULRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B -- ON A.Code = B.UltraExamID -- LEFT OUTER JOIN PATIENT_DATA..tbmaster C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' -- --Union all -- -- select -- Case When @StartDate = @EndDate Then Replace(convert(varchar,A.TransDate,100), Replace(Convert(varchar(40), A.TransDate, 107),',',''),'') else Convert(varchar(40), A.TransDate, 100) End As TransDate, -- A.IdNum [Adm #], -- C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], -- A.Code [Item Code], -- B.UltraExam [Item Description], -- convert(varchar,A.TransDate,100) as [Transaction Date], -- case when A.swfin = 'X' then 'X' -- when A.swfin = 'Y' then -- Case when (select max(verifydate) as verifydate from radiology..tbUlresult where requestnum = A.requestnum ) is null then 'V' -- else 'Y' -- end -- when A.swfin is null then 'S' -- else 'R' end as [Request Status], -- A.RoomID, -- A.RequestDoctorCode, -- convert(varchar,C.Birthdate,101) as Birthdate, -- Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), -- C.Sex, -- A.refnum, -- A.requestnum -- from RADIOLOGY..tbULRequest A -- LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B -- ON A.Code = B.UltraExamID -- LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C -- ON A.HospNum = C.HospNum -- where A.transdate between @StartDate AND @EndDate + ' 23:59:59.99' -- --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' -- order by A.TransDate --End -- GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created by : Jetty P. Omo Details : Turn Around Time Report based on Build File Date : June 23,2008 */ CREATE Procedure [dbo].[Radio_TurnAroundTime] @SectionId varchar(10), @StartDate varchar(15), @EndDate varchar(15), @Status varchar(1) /* set @SectionId = 'XR' set @StartDate = '06/26/2008' set @EndDate = '06/26/2008' set @Status = '0' */ as if @SectionId = 'XR' Begin select (Case When IsNumeric(R.HospNum) = 1 Then IsNull(P.LastName,'') + ', ' + IsNull(P.FirstName,'') + ' ' + IsNull(P.MiddleName,'') Else IsNull(C.LastName,'') + ', ' + IsNull(C.FirstName,'') + ' ' + Isnull(C.MiddleName,'') End) as PatientName, XrayExam [Procedure], R.Transdate, Pro.DateandTime [Date procedure done], Result.ResultDate, Result.Verifydate, CASE WHEN isnumeric(R.idnum) = 1 THEN 'In Patient' else 'Out Patient' end as [Patient Type], case when Result.[resultcode] = '1' then case when (convert(varchar(10),Pro.DateandTime,101) <= convert(varchar(10),Result.Verifydate,101)) and CAST(datediff(MINUTE,Pro.DateandTime,Result.Verifydate) AS FLOAT)/ 60 <= cast(isnull(T.Inhours,'0')as float) then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') and Result.Verifydate <= convert(varchar(10),Result.Verifydate,101) + ' 10:00' then 'ON TIME' else 'LATE' end else case when (convert(varchar(10),Pro.DateandTime,101) <= convert(varchar(10),Result.Verifydate,101)) and CAST(datediff(MINUTE,Pro.DateandTime,Result.Verifydate) AS FLOAT)/ 60 <= cast(isnull(T.Outhours,'0')as float) then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') and Result.Verifydate <= convert(varchar(10),Result.Verifydate,101) + ' 10:00' then 'ON TIME' else 'LATE' end end as Status from radiology..tbxrrequest R Left Outer Join radiology..tbBuildTAT T on R.Code = T.Itemid AND T.REVENUEID = @SectionId Left Outer Join Build_file..tbcoxrayexam E on R.Code = E.XrayExamid Left Outer Join Patient_data..tbmaster P on R.Hospnum = P.Hospnum Left Outer Join laboratory..vwPatientResultEntry C on R.Hospnum = C.Hospnum Left Outer Join radiology..tbxrresult Result on R.Requestnum = Result.Requestnum Left Outer Join radiology..tbRadioDateofProcedureDone Pro On R.Requestnum = Pro.Requestnum and Deptid = '2' where R.transdate between @StartDate and @EndDate + ' 23:59:59.99' AND T.REVENUEID = @SectionId and SWfin <> 'C' End else if @SectionId = 'US' Begin select (Case When IsNumeric(R.HospNum) = 1 Then IsNull(P.LastName,'') + ', ' + IsNull(P.FirstName,'') + ' ' + IsNull(P.MiddleName,'') Else IsNull(C.LastName,'') + ', ' + IsNull(C.FirstName,'') + ' ' + Isnull(C.MiddleName,'') End) as PatientName, UltraExam [Procedure], R.Transdate, Pro.DateandTime [Date procedure done], Result.ResultDate, Result.Verifydate, CASE WHEN isnumeric(R.idnum) = 1 THEN 'In Patient' else 'Out Patient' end as [Patient Type], case when (convert(varchar(10),Pro.DateandTime,101) <= convert(varchar(10),Result.Verifydate,101)) and CAST(datediff(MINUTE,Pro.DateandTime,Result.Verifydate) AS FLOAT)/ 60 <= cast(isnull(T.oUThours,'0')as float) then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') then 'ON TIME' when (Pro.DateandTime between convert(varchar(10),Pro.DateandTime,101) + ' 17:00' and convert(varchar(10),Pro.DateandTime,101) + ' 23:59') and Result.Verifydate <= convert(varchar(10),Result.Verifydate,101) + ' 10:00' then 'ON TIME' else 'LATE' end as Status from radiology..tbulrequest R Left Outer Join radiology..tbBuildTAT T on R.Code = T.Itemid AND T.REVENUEID = @SectionId Left Outer Join Build_file..tbcoUltraexam E on R.Code = E.UltraExamid Left Outer Join Patient_data..tbmaster P on R.Hospnum = P.Hospnum Left Outer Join laboratory..vwPatientResultEntry C on R.Hospnum = C.Hospnum Left Outer Join radiology..tbUlresult Result on R.Requestnum = Result.Requestnum Left Outer Join radiology..tbRadioDateofProcedureDone Pro On R.Requestnum = Pro.Requestnum and Deptid = '3' where R.transdate between @StartDate and @EndDate + ' 23:59:59.99' and SWfin <> 'C' End else if @SectionId = 'CT' Begin select (Case When IsNumeric(R.HospNum) = 1 Then IsNull(P.LastName,'') + ', ' + IsNull(P.FirstName,'') + ' ' + IsNull(P.MiddleName,'') Else IsNull(C.LastName,'') + ', ' + IsNull(C.FirstName,'') + ' ' + Isnull(C.MiddleName,'') End) as PatientName, CtExam [Procedure], R.Transdate, Pro.DateandTime [Date procedure done], Result.ResultDate, Result.Verifydate, CASE WHEN isnumeric(R.idnum) = 1 THEN 'In Patient' else 'Out Patient' end as [Patient Type], case when convert(varchar(10),Pro.DateandTime,101) = convert(varchar(10),Result.Verifydate,101) then 'ON TIME' when Result.Verifydate > Pro.DateandTime and Result.Verifydate <= Convert(Varchar(10),Result.Verifydate, 101) + ' 12:00' then 'ON TIME' else 'LATE' end as Status from radiology..tbCTrequest R Left Outer Join radiology..tbBuildTAT T on R.Code = T.Itemid AND T.REVENUEID = @SectionId Left Outer Join Build_file..tbcoCTexam E on R.Code = E.CTExamid Left Outer Join Patient_data..tbmaster P on R.Hospnum = P.Hospnum Left Outer Join laboratory..vwPatientResultEntry C on R.Hospnum = C.Hospnum Left Outer Join radiology..tbCTresult Result on R.Requestnum = Result.Requestnum Left Outer Join radiology..tbRadioDateofProcedureDone Pro On R.Requestnum = Pro.Requestnum and Deptid = '1' where R.transdate between @StartDate and @EndDate + ' 23:59:59.99' and SWfin <> 'C' End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_SaveResult2 Script Date: 07/01/2000 1:20:56 AM ******/ CREATE PROCEDURE [dbo].[spRadio_SaveResult2] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @TransDate AS DateTime, @ResultDate AS DateTime, @RequestDoctorCode AS varChar(4), @RadCode AS varChar(4), @Interpretation AS Text, @RoomID AS varChar(8), @ResultBy AS varChar(8), @Film8 AS Float, @Film10 AS Float, @Film11 AS Float, @Film14 AS Float, @Film17 AS Float, @FileNum AS varChar(10), @ControlNum AS varChar(10), @DoctorID varchar(5), @ExamTaken varchar(100) , @RadCode2 varchar(4), @Remarks text AS DECLARE @RevenueID AS varChar(2) IF @Type = '1' BEGIN SET @RevenueID = 'CT' INSERT INTO tbCTResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, --VerifyByID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks) --, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, -- @ResultBy, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks) --, getdate()) UPDATE tbCTRequest SET SwFin = 'Y', RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum END IF @Type = '2' BEGIN SET @RevenueID = 'XR' INSERT INTO tbXRResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, -- VerifyByID, Film8, Film10, Film11, Film14, Film17, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks) --, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, -- @ResultBy, @Film8, @Film10, @Film11, @Film14, @Film17, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks) --, getDate()) UPDATE tbXRRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum END IF @Type = '3' BEGIN SET @RevenueID = 'US' INSERT INTO tbULResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, --VerifyByID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks) --, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, --@ResultBy, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks) --, getdate()) UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum END IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @ResultBy, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By : Jetty P. Omo Details : Added the result code for Diagnostic Film Status whether complicated or uncomplicated Date : June 28,2008 Altered By : Christian Gonzalo Details : Keeping track for the versions of interpretation for each verification churva. Date : May 06, 2010 */ CREATE PROCEDURE [dbo].[spRadio_SaveResult] @Type varChar(1), @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @TransDate AS DateTime, @ResultDate AS DateTime, @RequestDoctorCode AS varChar(4), @RadCode AS varChar(4), @Interpretation AS Text, @RoomID AS varChar(20), @ResultBy AS varChar(50), @Film8 AS Float, @Film10 AS Float, @Film11 AS Float, @Film14 AS Float, @Film17 AS Float, @FileNum AS varChar(10), @ControlNum AS varChar(50), @DoctorID varchar(5), @ExamTaken varchar(100) , @RadCode2 varchar(4), @Remarks text, @ExamDate as DateTime = null, @VerifyByID as varchar(20) = null, @VerifyDate as DateTime = null, @RadCode3 as varchar(4), @RadCode4 as varchar(4), @Resultcode as varchar(5) = null, @Equipment as varchar(5) = '', @Findings as varchar(20) = null, @RadTech as varchar(20) = '' AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; IF @Type = '1' BEGIN SET @RevenueID = 'CT' INSERT INTO tbCTResult ( HospNum, IDNum, RequestNum, ItemCode, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks, ExamDate, VerifyByID, VerifyDate,RadCode3, RadCode4,Resultcode,RadTech) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks, @ExamDate, @VerifyByID, @VerifyDate, @RadCode3, @RadCode4,@Resultcode,@RadTech); --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin INSERT INTO tbCTResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @ResultBy, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, '1'); End UPDATE tbCTRequest SET SwFin = 'Y', RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; END IF @Type = '2' BEGIN SET @RevenueID = 'XR' INSERT INTO tbXRResult ( HospNum, IDNum, RequestNum, ItemCode, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, Film8, Film10, Film11, Film14, Film17, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks, ExamDate, VerifyByID, VerifyDate, RadCode3, RadCode4,Resultcode,RadTech) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, @Film8, @Film10, @Film11, @Film14, @Film17, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks, @ExamDate, @VerifyByID, @VerifyDate, @RadCode3, @RadCode4,@Resultcode,@RadTech); --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin INSERT INTO tbXRResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @ResultBy, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, '1'); End UPDATE tbXRRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; END IF @Type = '3' BEGIN SET @RevenueID = 'US' INSERT INTO tbULResult ( HospNum, IDNum, RequestNum, ItemCode, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks, ExamDate, VerifyByID, VerifyDate, RadCode3, RadCode4,Resultcode, ResultFindings,RadTech) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks, @ExamDate, @VerifyByID, @VerifyDate, @RadCode3, @RadCode4,@Resultcode, @Findings,@RadTech) ; --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin INSERT INTO tbUltraResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @ResultBy, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, '1'); End UPDATE tbULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; END IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @ResultBy, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_VerifyBy] --declare @RevenueID varchar(2), @DoctorID varchar(20)= '', @PatientType varchar(1) --set @RevenueID = 'XR' --set @DoctorID = 'c006' --set @PatientType = '1' AS if @RevenueID = 'XR' begin If @PatientType = '0' Begin select distinct Hospnum,Idnum,RequestNum,B.LastName+', '+B.FirstName as Radiologist, A.VerifyById as Code --distinct(verifybyid) as Code, B.LastName+', '+B.FirstName as Radiologist from tbxrresult A Left Outer Join PassWord..tbPasswordMain B On A.verifybyid = B.EmployeeID where isnumeric(Idnum) = 1 and verifybyid like 'C0%' and VerifybyiD = @DoctorID --and isnull(B.DoctorId,'') <> '' --order by verifybyid End Else Begin select distinct Hospnum,Idnum,RequestNum,B.LastName+', '+B.FirstName as Radiologist, A.VerifyById as Code --distinct(verifybyid) as Code, B.LastName+', '+B.FirstName as Radiologist from tbxrresult A Left Outer Join PassWord..tbPasswordMain B On A.verifybyid = B.EmployeeID where isnumeric(Idnum) <> 1 and verifybyid like 'C0%' and VerifybyiD = @DoctorID --and isnull(B.DoctorId,'') <> '' --order by verifybyid End End if @RevenueID = 'CT' begin select distinct(verifybyid) as Code, B.LastName+', '+B.FirstName as Radiologist, A.VerifyById as Code from tbCtresult A Left Outer Join PassWord..tbPasswordMain B On A.verifybyid = B.EmployeeID where verifybyid like 'C0%' and VerifybyiD = @DoctorID --and isnull(B.DoctorId,'') <> '' order by verifybyid End if @RevenueID = 'US' begin select distinct(verifybyid) as Code, B.LastName+', '+B.FirstName as Radiologist, A.VerifyById as Code from tbUlResult A Left Outer Join PassWord..tbPasswordMain B On A.verifybyid = B.EmployeeID where verifybyid like 'C0%' and VerifybyiD = @DoctorID --and isnull(B.DoctorId,'') <> '' order by verifybyid End GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_SaveRetrieve2 Script Date: 07/01/2000 1:20:56 AM ******/ CREATE PROCEDURE [dbo].[spRadio_SaveRetrieve3] @Type AS varChar(1), @RequestNum AS varChar(10), @RadCode AS varChar(4), @DoctorID as varchar(5), @Interpretation AS Text, @Encoder as varchar(10) --Added by BSL March 17, 2003 AS IF @Type = '1' /* CT-Scan Department */ BEGIN UPDATE tbCTResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, TranscribedByID = @Encoder WHERE RequestNum = @RequestNum END IF @Type = '2' /* XRay Department */ BEGIN UPDATE tbXRResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, TranscribedByID = @Encoder WHERE RequestNum = @RequestNum END IF @Type = '3' /* Ultrasound Department */ BEGIN UPDATE tbULResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation , TranscribedByID = @Encoder WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_SaveRetrieve2 Script Date: 07/01/2000 1:20:56 AM ******/ CREATE PROCEDURE [dbo].[spRadio_SaveRetrieve2] @Type AS varChar(1), @RequestNum AS varChar(10), @RadCode AS varChar(4), @DoctorID as varchar(5), @Interpretation AS Text, @Remarks as Text, @RadCode2 as varchar(4), @ResultDate as varchar(10) AS IF @Type = '1' /* CT-Scan Department */ BEGIN UPDATE tbCTResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate WHERE RequestNum = @RequestNum END IF @Type = '2' /* XRay Department */ BEGIN UPDATE tbXRResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate WHERE RequestNum = @RequestNum END IF @Type = '3' /* Ultrasound Department */ BEGIN UPDATE tbULResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By : Jetty P. Omo Details : Added the result code for Diagnostic Film Status whether complicated or uncomplicated Date : June 28,2008 */ CREATE PROCEDURE [dbo].[spRadio_SaveRetrieve] @Type AS varChar(1), @RequestNum AS varChar(10), @RadCode AS varChar(4), @DoctorID as varchar(5), @Interpretation AS Text, @Remarks as Text, @RadCode2 as varchar(4), @ResultDate as varchar(10), @ExamDate as DateTime = null, @EditedByID as varchar(20) = null, @VerifyByID as varchar(20) = null, @VerifyDate as DateTime = null, @RadCode3 as varchar(4), @RadCode4 as varchar(4), @PreviousInterpretation as text = null, @Resultcode as varchar(5) = null, @RadTech as varchar(10) = '' AS Declare @EditedDate as DateTime; set @EditedDate = getdate() If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; else Begin set @VerifyDate = getdate(); end; IF @Type = '1' /* CT-Scan Department */ BEGIN UPDATE tbCTResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate, ExamDate = @ExamDate, EditedByID = @EditedByID, EditedDate = @EditedDate, VerifyByID = @VerifyByID, VerifyDate = @VerifyDate, RadCode3 = @RadCode3, RadCode4 = @RadCode4, Resultcode = @Resultcode, RadTech = @RadTech WHERE RequestNum = @RequestNum; UPDATE tbCTRequest SET RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; if (select isnull(convert(varchar(10),Interpretation1),'') from RADIOLOGY..tbCTResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbCTResult set Interpretation1 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation2),'') from RADIOLOGY..tbCTResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbCTResult set Interpretation2 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation3),'') from RADIOLOGY..tbCTResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbCTResult set Interpretation3 = @PreviousInterpretation where RequestNum = @RequestNum; END; END IF @Type = '2' /* XRay Department */ BEGIN UPDATE tbXRResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate, ExamDate = @ExamDate, EditedByID = @EditedByID, EditedDate = @EditedDate, VerifyByID = @VerifyByID, VerifyDate = @VerifyDate, RadCode3 = @RadCode3, RadCode4 = @RadCode4, Resultcode = @Resultcode, RadTech = @RadTech WHERE RequestNum = @RequestNum; UPDATE tbXRRequest SET RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; if (select isnull(convert(varchar(10),Interpretation1),'') from RADIOLOGY..tbXRResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbXRResult set Interpretation1 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation2),'') from RADIOLOGY..tbXRResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbXRResult set Interpretation2 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation3),'') from RADIOLOGY..tbXRResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbXRResult set Interpretation3 = @PreviousInterpretation where RequestNum = @RequestNum; END; END IF @Type = '3' /* Ultrasound Department */ BEGIN UPDATE tbULResult SET RadCode = @RadCode, RequestDoctorCode = @DoctorID, Interpretation = @Interpretation, Remarks = @Remarks, RadCode2 = @RadCode2, ResultDate = @ResultDate, ExamDate = @ExamDate, EditedByID = @EditedByID, EditedDate = @EditedDate, VerifyByID = @VerifyByID, VerifyDate = @VerifyDate, RadCode3 = @RadCode3, RadCode4 = @RadCode4, Resultcode = @Resultcode, RadTech = @RadTech WHERE RequestNum = @RequestNum; UPDATE tbULRequest SET RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; if (select isnull(convert(varchar(10),Interpretation1),'') from RADIOLOGY..tbULResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbULResult set Interpretation1 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation2),'') from RADIOLOGY..tbULResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbULResult set Interpretation2 = @PreviousInterpretation where RequestNum = @RequestNum; END; else if (select isnull(convert(varchar(10),Interpretation3),'') from RADIOLOGY..tbULResult where RequestNum = @RequestNum) = '' BEGIN UPDATE RADIOLOGY..tbULResult set Interpretation3 = @PreviousInterpretation where RequestNum = @RequestNum; END; END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --Added by BSL Interpretation Passed to Grid has limitation --March 14, 2003 CREATE PROCEDURE [dbo].[spRadio_GetInterpretation] @RevenueID as varchar(2), @RequestNum as varchar(10) AS if @RevenueId = 'XR' begin Select Interpretation From RADIOLOGY..tbXrResult Where RequestNum = @RequestNum end; if @RevenueId = 'CT' begin Select Interpretation From RADIOLOGY..tbCTResult Where RequestNum = @RequestNum end; if @RevenueId = 'UL' begin Select Interpretation From RADIOLOGY..tbULResult Where RequestNum = @RequestNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --EXEC RADIOLOGY.dbo.Radiology_logbook '01/28/2008', '01/28/2008', 'xr' /* Created By Jetty P. OMO November 12,2007 Logbook for In Patient and Out Patient Revenueid XR - Xray Department US - Ultrasound Department CT - CT Scan Dapartment */ CREATE Procedure [dbo].[Radiology_logbook] --declare @StartDate as varchar(10), @EndDate as varchar(10), @Revenueid as varchar(10), @PatientType as varchar(1) = 'I' /* set @StartDate = '11/01/2007' set @EndDate = '11/30/2007' set @Revenueid = 'XR' */ as if @PatientType = 'I' Begin --Xray if @Revenueid = 'XR' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex, XrayExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'xr' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum from Radiology..tbxrRequest Req Left Outer Join Radiology..tbXRResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '2' Left Outer Join Build_file..tbcoXrayExam X On X.XrayExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode --Left Outer Join Station..tbNurseLogbook N --On N.Referencenum = Req.Refnum and N.revenueid = 'XR' Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 1 Order by Req.transdate asc End --CtScan If @Revenueid = 'CT' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex,CtExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, --Convert(Varchar(25),Req.Transdate,131) as [Time of Request] (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'CT' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum, D.LastName + ' ' + D.FirstName as Radiologist from Radiology..tbCTRequest Req Left Outer Join Radiology..tbCTResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '1' Left Outer Join Build_file..tbcoCTExam X On X.CTExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 1 end --UltraSound IF @Revenueid = 'US' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex,UltraExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'US' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum, D.LastName + ' ' + D.FirstName as Radiologist from Radiology..tbULRequest Req Left Outer Join Radiology..tbULResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '3' Left Outer Join Build_file..tbcoUltraExam X On X.UltraExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 1 End End Else --Xray if @Revenueid = 'XR' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex, XrayExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'xr' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum, D.LastName + ' ' + D.FirstName as Radiologist from Radiology..tbxrRequest Req Left Outer Join Radiology..tbXRResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '2' Left Outer Join Build_file..tbcoXrayExam X On X.XrayExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode --Left Outer Join Station..tbNurseLogbook N --On N.Referencenum = Req.Refnum and N.revenueid = 'XR' Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 0 Order by Req.transdate asc End --CtScan If @Revenueid = 'CT' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex,CtExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, --Convert(Varchar(25),Req.Transdate,131) as [Time of Request] (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'CT' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum, D.LastName + ' ' + D.FirstName as Radiologist from Radiology..tbCTRequest Req Left Outer Join Radiology..tbCTResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '1' Left Outer Join Build_file..tbcoCTExam X On X.CTExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 0 end --UltraSound IF @Revenueid = 'US' Begin select Req.IDnum,isnull(P.Lastname,'') + ', ' + isnull(P.Firstname,'') + ' ' + isnull(P.MiddleName,'') as [Patient Name], Convert(Varchar(10),P.Birthdate,101) as Birthdate, Laboratory.dbo.fn_LabComputeAge(P.Birthdate, getdate()) as Age,Req.Roomid as Room, P.Sex as Sex,UltraExam as [Procedure], isnull(D.Lastname,'') + ', ' + isnull(D.Firstname,'') + ' ' as Doctor, (select top 1 requestdate from Station..tbNurseLogbook where revenueid = 'US' and referencenum = req.refnum and itemid = Req.Code) as [RequestDate], Req.Transdate as [Processed Date], Res.VerifyDate as [Result Available], DT.DateandTime as [Time Taken],RefNum, D.LastName + ' ' + D.FirstName as Radiologist from Radiology..tbULRequest Req Left Outer Join Radiology..tbULResult Res On Req.Requestnum = Res.Requestnum Left Outer Join Patient_data..tbmaster P On Req.Hospnum = P.hospnum Left Outer Join tbRadioDateofProcedureDone DT On DT.Requestnum = Req.Requestnum and DT.DeptID = '3' Left Outer Join Build_file..tbcoUltraExam X On X.UltraExamID = Req.Code Left Outer Join Build_file..tbCoDoctor D On D.DoctorID = Req.RequestDoctorCode Where Req.transdate between @StartDate and @EndDate + ' 23:59:59.99' and Req.Swfin <> 'R' and isnumeric(Req.Idnum) = 0 End GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_XrayMonthlyReport] @BeginDate varchar(10), @EndDate varchar(10) AS SELECT A.Hospnum, A.IDNum, A.RequestNum, A.RadCode, B.Amount, C.Lastname, C.Firstname, C.Middlename, C.IsResident FROM Radiology..tbXRResult A LEFT OUTER JOIN Radiology..tbXRRequest B ON A.RequestNum = B.RequestNum LEFT OUTER JOIN Build_File..tbCoDoctor C ON A.RadCode = C.DoctorID WHERE (A.transdate >= @BeginDate and A.transdate < @EndDate) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_MammographyReport] --@RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS --set @revenueid='xr' --set @FirstDay= '10/01/2005' --set @LastDay ='10/20/2005' DECLARE @StartDate datetime, @EndDate datetime, @Revenueid as varchar(2) set @Revenueid = 'XR' SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) Select distinct b.refnum, sum(b.amount) Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity , b.itemid, max(Case @RevenueID when 'XR' then e.XrayExam End) as exam, max(b.userid) UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum) as IDNum, max(p.hospnum) HospNum, max(m.lastname + ', ' + m.firstname) patient, max(R.RadCode)RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbilldailybill b Left Join Build_File..tbcoXrayExam E on B.itemID = E.XrayExamID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum inner join (Select distinct Refnum,radcode From radiology..tbxrrequest A Inner Join radiology..tbxrresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoXrayExam C on B.ItemCode = C.XrayexamId where C.xraysectionid ='XMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.xraysectionid ='XMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 union all Select max(b.refnum) as Refnum, sum(b.amount) as Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity, b.itemid, max(Case @RevenueID when 'XR'then e.XrayExam End) as exam, max(b.userid) as UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)Idnum, max(p.hospnum) Hospnum, max(Case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom End) as patient, max(R.RadCode) RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbillopdailyout b left Join build_file..tbcoXrayExam E on B.ItemID = E.XrayExamID left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum inner join (Select distinct Refnum,radcode From radiology..tbxrrequest A Inner Join radiology..tbxrresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoXrayExam C on B.ItemCode = C.XrayexamId where C.xraysectionid ='XMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.xraysectionid ='XMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 Order by b.transdate GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CheckResultStatus] @Type varchar(2), @RequestNum varchar(10) AS If @Type = 'XR' Begin Select VerifyById from tbXRResult Where RequestNum = @RequestNum End If @Type = 'CT' Begin Select VerifyById from tbCTResult Where RequestNum = @RequestNum End If @Type = 'US' Begin Select VerifyById from tbULResult Where RequestNum = @RequestNum End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO -- Created by : Jetty P. Omo -- July 14,2007 -- Retrieving Result Ready for Printing CREATE PROCEDURE [dbo].[spRadio_GetResultToBePrinted] @RevenueID as varchar(2), @RequestNumber as varchar (15) AS IF @RevenueID = 'XR' BEGIN SELECT A.HospNum, A.IDNum, A.XrayNum,B.XrayExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, D.FirstName + ' ' + Substring(D.MiddleName,0,1) + D.Lastname + ' ,' + D.Title as RequestingDoctor, DR.FirstName + ' ' + Substring(DR.MiddleName,0,1) + DR.Lastname + ' ,' + DR.Title as Radiologist, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.XrayNum AS Filenum, P.Lastname + ', ' + P.FirstName + ' ' + Substring(P.MiddleName,0,1) as PatientName, P.Sex,P.Birthdate,dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age, P.HouseStreet + ' ,' + P.Barangay + ' ,' + Ad.Town + ' ,' + Province as Address FROM Radiology..tbXRResult A LEFT OUTER JOIN Build_File..tbCoXrayExam B ON A.ItemCode = B.XrayExamID LEFT OUTER JOIN Radiology..tbXRFileNum C ON A.Hospnum = C.Hospnum LEFT OUTER JOIN Patient_data..tbmaster P ON A.Hospnum = P.Hospnum LEFT OUTER JOIN Build_file..tbcoDoctor D ON A.RequestDoctorCode = D.DoctorID LEFT OUTER JOIN Build_file..tbcoAddress Ad ON P.Zipcode = Ad.ZipCode LEFT OUTER JOIN Build_file..tbcoDoctor DR ON A.RadCode = DR.DoctorID WHERE A.RequestNum = @RequestNumber END IF @RevenueID = 'US' BEGIN SELECT A.HospNum, A.IDNum,A.XrayNum,B.UltraExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, D.FirstName + ' ' + Substring(D.MiddleName,0,1) + D.Lastname + ' ,' + D.Title as RequestingDoctor, DR.FirstName + ' ' + Substring(DR.MiddleName,0,1) + DR.Lastname + ' ,' + DR.Title as Radiologist, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.UltraNum AS Filenum, P.Lastname + ', ' + P.FirstName + ' ' + Substring(P.MiddleName,0,1) as PatientName , P.Sex,P.Birthdate,dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age, P.HouseStreet + ' ,' + P.Barangay + ' ,' + Ad.Town + ' ,' + Province FROM Radiology..tbULResult A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.ItemCode = B.UltraExamID LEFT OUTER JOIN Radiology..tbUltraNum C ON A.Hospnum = C.Hospnum LEFT OUTER JOIN Patient_data..tbmaster P ON A.Hospnum = P.Hospnum LEFT OUTER JOIN Build_file..tbcoDoctor D ON A.RequestDoctorCode = D.DoctorID LEFT OUTER JOIN Build_file..tbcoAddress Ad ON P.Zipcode = Ad.ZipCode LEFT OUTER JOIN Build_file..tbcoDoctor DR ON A.RadCode = DR.DoctorID WHERE A.RequestNum = @RequestNumber END IF @RevenueID = 'CT' BEGIN SELECT A.HospNum, A.IDNum,A.XrayNum,B.CTExam AS ExamName, A.VerifyByID, A. VerifyDate, A.ItemCode, A.TransDate, A.ExamDate, A.ResultDate, A.TranscribedByID, D.FirstName + ' ' + Substring(D.MiddleName,0,1) + D.Lastname + ' ,' + D.Title as RequestingDoctor, DR.FirstName + ' ' + Substring(DR.MiddleName,0,1) + DR.Lastname + ' ,' + DR.Title as Radiologist, A.ResultCode, A.Interpretation, A.RoomID, A.ControlNum, A.Remarks, A.RequestNum, C.CTNum AS Filenum, P.Lastname + ', ' + P.FirstName + ' ' + Substring(P.MiddleName,0,1) as PatientName , P.Sex,P.Birthdate,dbo.fn_ComputeAge(P.BirthDate,getdate()) as Age, P.HouseStreet + ' ,' + P.Barangay + ' ,' + Ad.Town + ' ,' + Province FROM Radiology..tbCTResult A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.ItemCode = B.CTExamID LEFT OUTER JOIN Radiology..tbCTNum C ON A.Hospnum = C.Hospnum LEFT OUTER JOIN Patient_data..tbmaster P ON A.Hospnum = P.Hospnum LEFT OUTER JOIN Build_file..tbcoDoctor D ON A.RequestDoctorCode = D.DoctorID LEFT OUTER JOIN Build_file..tbcoAddress Ad ON P.Zipcode = Ad.ZipCode LEFT OUTER JOIN Build_file..tbcoDoctor DR ON A.RadCode = DR.DoctorID WHERE A.RequestNum = @RequestNumber END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveVerifyPrint] @RevenueID AS varchar(2), @RequestNum AS varchar(8) AS IF @RevenueID = 'CT' /* CT-Scan Table */ BEGIN Update tbCTResult SET DigitallySigned = 'Y' WHERE RequestNum = @RequestNum END IF @RevenueID = 'XR' /* X-ray Table */ BEGIN Update tbXRResult SET DigitallySigned = 'Y' WHERE RequestNum = @RequestNum END IF @RevenueID = 'US' /* Ultrasound Table */ BEGIN Update tbULResult SET DigitallySigned = 'Y' WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_VerifyResult] @Type AS varChar(1), @RequestNum AS varChar(10), @VerifyByID AS varChar(10), @VerifyDate AS DateTime --with encryption AS IF @Type = '1' /* CT-Scan Department */ BEGIN UPDATE tbCTResult SET VerifyByID = @VerifyByID, VerifyDate = getdate() WHERE RequestNum = @RequestNum; /****** Update Station..tbComm_AutoPrint for Automatic Printing of Results *******/ ---By Mike C. 11/24/2005 IF not exists (Select RequestNum from Station..tbComm_AutoPrint where RevenueId = 'CT' and RequestNum = @RequestNum) Begin Insert Into Station..tbComm_AutoPrint (RequestNum, IDNum, HospNum, Room, ItemID, RevenueID, UserID, RequestStatus, StationID, AccessionNum) (Select distinct a.RequestNum, a.IDNum, a.HospNum, a.RoomID, a.Itemcode, 'CT', a.VerifyByID, 'N', c.StationID, null From radiology..tbCTResult a inner join build_file..tbcoroom c on a.roomid = c.roomid where a.RequestNum = @RequestNum); End END IF @Type = '2' /* XRay Department */ BEGIN UPDATE tbXRResult SET VerifyByID = @VerifyByID, VerifyDate = getdate() WHERE RequestNum = @RequestNum; /****** Update Station..tbComm_AutoPrint for Automatic Printing of Results *******/---By Mike C. 11/24/2005 IF not exists (Select RequestNum from Station..tbComm_AutoPrint where RevenueId = 'XR' and RequestNum = @RequestNum) Begin Insert Into Station..tbComm_AutoPrint (RequestNum, IDNum, HospNum, Room, ItemID, RevenueID, UserID, RequestStatus, StationID, AccessionNum) (Select distinct a.RequestNum, a.IDNum, a.HospNum, a.RoomID, a.Itemcode, 'XR', a.VerifyByID, 'N', c.StationID, null From radiology..tbXRResult a inner join build_file..tbcoroom c on a.roomid = c.roomid where a.RequestNum = @RequestNum); End END IF @Type = '3' /* Ultrasound Department */ BEGIN UPDATE tbULResult SET VerifyByID = @VerifyByID, VerifyDate = getdate() WHERE RequestNum = @RequestNum; /****** Update Station..tbComm_AutoPrint for Automatic Printing of Results *******/---By Mike C. 11/24/2005 IF not exists (Select RequestNum from Station..tbComm_AutoPrint where RevenueId = 'US' and RequestNum = @RequestNum) Begin Insert Into Station..tbComm_AutoPrint (RequestNum, IDNum, HospNum, Room, ItemID, RevenueID, UserID, RequestStatus, StationID, AccessionNum) (Select distinct a.RequestNum, a.IDNum, a.HospNum, a.RoomID, a.Itemcode, 'US', a.VerifyByID, 'N', c.StationID, null From radiology..tbULResult a inner join build_file..tbcoroom c on a.roomid = c.roomid where a.RequestNum = @RequestNum); End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_MaintenanceUpdate] @FormName AS varChar(12), @Type AS varChar(1), @RequestNum AS varChar(8), @FilmsUsed AS varChar(30), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float AS DECLARE @RevenueID AS varChar(2), @Transdate AS DateTime, @Quantity AS Integer IF @FormName = 'ADJUSTMENT' BEGIN IF @Type = '1' BEGIN UPDATE tbCTRequest SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum UPDATE tbCTResult SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum END IF @Type = '2' BEGIN UPDATE tbXRRequest SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum UPDATE tbXRResult SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum END IF @Type = '3' BEGIN UPDATE tbULRequest SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum UPDATE tbULResult SET FilmsUsed = @FilmsUsed WHERE RequestNum = @RequestNum END END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created by : Christian Gonzalo Details : Use to retrieve the amount for Radiologists' contribution Date : December 28, 2009 */ CREATE PROCEDURE [dbo].[Radio_Get_RadContributions] @StartDate varchar(30), @EndDate varchar(40) AS /* declare @StartDate varchar(30), @EndDate varchar(40) */ set @StartDate ='12/01/2009' set @EndDate = '12/01/2009' Select RS.HospNum, RS.IDNum, RQ.RefNum, RS.RequestNum, RS.RadCode, D.LastName + ', ' + D.FirstName as DrName, M.LastName + ', ' + M.FirstName as PatientName, RQ.Transdate, RQ.Amount, (select Company from patient_data..tbhospitalinfo) as HospitalName, (select Address1 from patient_data..tbhospitalinfo) as HospitalAddress From RADIOLOGY..tbXRResult RS Left Outer Join RADIOLOGY..tbXRRequest RQ on RS.HospNum = RQ.HospNum and RS.IDNum = RQ.IDNum Left Outer Join PATIENT_DATA..tbMaster M on RS.HospNum = M.HospNum Left Outer Join BUILD_FILE..tbCoDoctor D on RS.RadCode = D.DoctorID where RQ.Transdate between @StartDate and @EndDate + ' 23:59:59.99' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchPreviousExamResult] @Hospnum as varchar(10), @RevenueID as varchar(2), @Lastname as varchar(20), @Firstname as varchar(20) AS If @RevenueID = 'XR' Begin Select A.Hospnum [Hospital #], A.XrayNum [File #], B.XrayExam [Exam], Convert(Varchar(10), A.ResultDate,101) [ResultDate] From tbxrResult A Left Outer Join Build_File..tbCoXrayExam B On A.ItemCode = B.XrayExamID Left Outer Join Patient_Data..tbCashPatient C On A.HospNum = C.Hospnum Left Outer Join Patient_Data ..tbMaster D On A.Hospnum = D.Hospnum Where A.HospNum = @Hospnum Or (C.Lastname like @Lastname + '%' and C.Firstname like Left(@Firstname,4) + '%') Or (D.Lastname like @Lastname + '%' and D.Firstname like Left(@Firstname,4) + '%'); End; If @RevenueID = 'CT' Begin Select A.XrayNum [File #], B.CTExam [Exam], Convert(Varchar(10), A.ResultDate,101) [ResultDate] From tbCTResult A Left Outer Join Build_File..tbCoCTExam B On A.ItemCode = B.CTExamID Where A.HospNum = @Hospnum; End; If @RevenueID = 'US' Begin Select A.XrayNum [File #], B.UltraExam [Exam], Convert(Varchar(10), A.ResultDate,101) [ResultDate] From tbCTResult A Left Outer Join Build_File..tbCoUltraExam B On A.ItemCode = B.UltraExamID Where A.Hospnum = @Hospnum; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --exec RADIOLOGY..spRadio_RequestStatus '2', '02/07/2008','02/07/2008', '' /* Added the ff . Start date - Start of Date Range on searching End Date - End of Date Range on searching Search Criteria - Lastname of patient AGE,DOctor,Room and Birthdate At the same time it will show if the result is Draft or verified */ CREATE PROCEDURE [dbo].[spRadio_RequestStatus] --declare @type as varchar(1), @StartDate as varchar(20), @EndDate as varchar(20), @SearchCriteria as varchar(20) --set @type = '2' --set @StartDate = '02/21/2011' --set @EndDate = '02/21/2011' --set @SearchCriteria = 'narvaez' AS if @StartDate is null begin set @StartDate = convert(varchar,getdate(),101) end if @EndDate is null Begin set @EndDate = convert(varchar,getdate(),101) End if @Type = '1' BEGIN select A.Hospnum [Hosp #], A.IdNum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'Y' else 'V' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' union all select A.Hospnum [Hosp #], A.IdNum [Hosp #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.CTExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select verifydate from radiology..tbCTresult where requestnum = A.requestnum ) is null then 'V' else 'Y' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbCTRequest A LEFT OUTER JOIN BUILD_FILE..tbcoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' order by [Transaction Date] END; if @Type = '2' BEGIN select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbxrresult where requestnum = A.requestnum ) is null then 'V' else 'Y' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101)between @StartDate and @EndDate -- = convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' union all select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.XrayExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select max(verifydate) as verifydate from radiology..tbxrresult where requestnum = A.requestnum ) is null then 'V' else 'Y' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbXRRequest A LEFT OUTER JOIN BUILD_FILE..tbcoXrayExam B ON A.Code = B.XrayExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' order by [Transaction Date] END; if @Type = '3' BEGIN select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select verifydate from radiology..tbULresult where requestnum = A.requestnum ) is null then 'V' else 'Y' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' Union all select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.Code [Item Code], B.UltraExam [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], case when A.swfin = 'X' then 'X' when A.swfin = 'Y' then Case when (select verifydate from radiology..tbUlresult where requestnum = A.requestnum ) is null then 'V' else 'Y' end when A.swfin is null then 'S' else 'R' end as [Request Status],A.RoomID,A.RequestDoctorCode,convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbULRequest A LEFT OUTER JOIN BUILD_FILE..tbcoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN PATIENT_DATA..tbcashpatient C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101)between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' order by [Transaction Date] End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_PrintResult] @RequestNum varchar(10), @RevenueID varchar(2), @UserID varchar(10) AS declare @HospNum varchar(10), @PatientName varchar(90), @CivilStatus varchar(10), @BirthDate datetime, @Age varchar(3), @cAge varchar(3), @ResultDate datetime, @Sex varchar(6), @AdmNum varchar(10), @Address varchar(100), @TelNo varchar(10), @PatientClass varchar(1), @Classification varchar(10), @TranscribedBy varchar(10) -- added by BSL March 17, 2003 if @RevenueID = 'XR' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbxrrequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbXRResult where requestnum = @RequestNum end if @RevenueID = 'CT' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbCTRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbCTResult where requestnum = @RequestNum end if @RevenueID = 'US' begin Select @HospNum = HospNum, @AdmNum = IDNum from tbULRequest where requestnum = @RequestNum Select @ResultDate = ResultDate, @TranscribedBy = TranscribedByID from tbULResult where requestnum = @RequestNum end if isnumeric(@HospNum) = 1 begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = TelNum from PATIENT_DATA..tbMaster m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatus = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end else begin select @PatientName = isnull(LastName, '') + ', ' + isnull(FirstName, '') + ' ' + isnull(MiddleName, ''), @CivilStatus = s.CivilStatus, @BirthDate = BirthDate, @Age = Age, @Sex = case isnull(Sex, '') when 'M' then 'MALE' when 'F' then 'FEMALE' else '' end, @Address = UPPER(m.HouseStreet + ' ' + m.Barangay + isnull(', ' + a.Town + ', ' + a.Province, '')), @TelNo = '' from PATIENT_DATA..tbCashPatient m left join BUILD_FILE..tbCoCivilStatus s on m.CivilStatusID = s.CivilStatusID left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum end IF (@BirthDate is null) or (@BirthDate <= '01/01/1900') BEGIN SET @cAge = @Age END ELSE BEGIN SET @cAge = convert(varchar(3), cast((year(@ResultDate) + (cast(month(@ResultDate) as float)/12) + (cast(day(@ResultDate) as float)/365)) - (year(@BirthDate) + (cast(month(@BirthDate) as float)/12) + (cast(day(@BirthDate) as float)/365)) as int) ) END if @RevenueID = 'XR' begin select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.XrayExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, s.remarks, case when s.RadCode = '0' then '' when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], case when s.RadCode2 = '0' then '' when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName + ', M.D.' end [Radiologist2], d2.title as RadiologistTitle, d3.title as RadiologistTitle2, @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @USerID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'XR' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder], PV.LastName + ', ' + PV.FirstName [VerifiedBy] from tbXRRequest q left join tbXRResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.RadCode2 = d3.DoctorID left join BUILD_FILE..tbCoXrayExam e on q.Code = e.XrayExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID left join PASSWORD..tbPasswordMaster PV on s.VerifyByID = PV.EmployeeID where q.RequestNum = @RequestNum end if @RevenueID = 'CT' begin select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.CTExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, s.remarks, case when s.RadCode = '0' then '' when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], case when s.RadCode2 = '0' then '' when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName + ', M.D.' end [Radiologist2], d2.title as RadiologistTitle, d3.title as RadiologistTitle2, @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'CT' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder], PV.LastName + ', ' + PV.FirstName [VerifiedBy] from tbCTRequest q left join tbCTResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.RadCode2 = d3.DoctorID left join BUILD_FILE..tbCoCTExam e on q.Code = e.CTExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID left join PASSWORD..tbPasswordMaster PV on s.VerifyByID = PV.EmployeeID where q.RequestNum = @RequestNum end if @RevenueID = 'US' begin select @PatientName [PatientName], q.HospNum, case when q.RequestDoctorCode = '0' then q.DoctorName when d1.DoctorID is null then '' else d1.FirstName + ' ' + d1.LastName + ', M.D.' end [Doctor], e.UltraExam [Examination], @CivilStatus [CivilStatus], @cAge [Age], @Sex [Sex], @AdmNum [AdmNum], q.RequestNum [CTNum], q.RoomID, s.ExamDate, s.Interpretation, s.remarks, case when s.RadCode = '0' then '' when d2.DoctorID is null then '' else d2.FirstName + ' ' + d2.LastName + ', M.D.' end [Radiologist], case when s.RadCode2 = '0' then '' when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName + ', M.D.' end [Radiologist2], d2.title as RadiologistTitle, d3.title as RadiologistTitle2, @Address [Address], @TelNo [TelNo], s.XRayNum [FileNum], s.ControlNum, @UserID, @Classification [Classification], q.TransDate [RequestDate], s.ResultDate, 'US' DepartmentNo, case when d3.DoctorID is null then '' else d3.FirstName + ' ' + d3.LastName end [Rasident], @BirthDate [BirthDate], P.LastName + ', ' + P.FirstName [Encoder], PV.LastName + ', ' + PV.FirstName [VerifiedBy] from tbULRequest q left join tbULResult s on q.RequestNum = s.RequestNum left join BUILD_FILE..tbCoDoctor d1 on q.RequestDoctorCode = d1.DoctorID left join BUILD_FILE..tbCoDoctor d2 on s.RadCode = d2.DoctorID left join BUILD_FILE..tbCoDoctor d3 on s.RadCode2 = d3.DoctorID left join BUILD_FILE..tbCoUltraExam e on q.Code = e.UltraExamID left join PASSWORD..tbPasswordMaster P on s.TranscribedByID = P.EmployeeID left join PASSWORD..tbPasswordMaster PV on s.VerifyByID = PV.EmployeeID where q.RequestNum = @RequestNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By : Jetty P. Omo Details : Added the result code for Diagnostic Film Status whether complicated or uncomplicated Date : June 28,2008 */ CREATE PROCEDURE [dbo].[spRadio_InquiryResult] @Type varchar(1), @ReqNum varchar(10) AS --set @Type = '2' --set @ReqNum = '16451' if @type = '1' begin SELECT r.ControlNum, e.CTExam [Examination], q.TransDate, q.Code, q.RequestDoctorCode [DoctorID], d1.FirstName + ' ' + d1.MiddleName +' ' + d1.LastName [Doctor], r.RadCode [RadiologistID], d2.FirstName + ' ' + d2.MiddleName + ' ' + d2.LastName [Radiologist], r.XRayNum [FileNum], r.RoomID, r.TranscribedByID, r.VerifyByID, r.RadCode2 [CoRadiologistID], r.Remarks, E.CTSectionID as SectionID, isnull(q.TransDate, getdate()) ExamDate, q.DoctorName, isnull(convert(varchar(10),VerifyDate,101) + ' ' + convert(varchar(10),VerifyDate,108) , convert(varchar(10),ResultDate,101) + ' ' + convert(varchar(10),ResultDate,108) ) ResultDate, r.RadCode3 [CoRadiologistID3], r.RadCode4 [CoRadiologistID4],Resultcode, IsNull(ResultFindings,'') Findings FROM tbCTRequest q left join tbCTResult r on q.requestnum = r.requestnum left join build_file..tbcodoctor d1 on q.requestdoctorcode = d1.doctorid left join build_file..tbcodoctor d2 on r.radcode = d2.doctorid LEFT JOIN BUILD_FILE..tbCoCTExam e on q.Code = e.CTExamID where q.requestnum = @ReqNum end if @type = '2' begin SELECT r.ControlNum, e.XRayExam [Examination], q.TransDate, q.Code, r.RequestDoctorCode [DoctorID], d1.FirstName + ' ' + d1.MiddleName + ' ' + d1.LastName [Doctor], r.RadCode [RadiologistID], d2.FirstName + ' ' + d2.MiddleName + ' ' + d2.LastName [Radiologist], r.XRayNum [FileNum], r.RoomID, q.Film8, q.Film10, q.Film11, q.Film14, q.Film17, r.TranscribedByID, r.VerifyByID, r.RadCode2 [CoRadiologistID], r.Remarks, E.XRaySectionID as SectionID, isnull(q.TransDate, getdate()) ExamDate,q.DoctorName, isnull(convert(varchar(10),VerifyDate,101) + ' ' + convert(varchar(10),VerifyDate,108) , convert(varchar(10),ResultDate,101) + ' ' + convert(varchar(10),ResultDate,108) ) ResultDate, r.RadCode3 [CoRadiologistID3], r.RadCode4 [CoRadiologistID4],Resultcode, IsNull(ResultFindings,'') Findings FROM tbXRRequest q left join tbXRResult r on q.requestnum = r.requestnum left join build_file..tbcodoctor d1 on r.requestdoctorcode = d1.doctorid left join build_file..tbcodoctor d2 on r.radcode = d2.doctorid LEFT JOIN BUILD_FILE..tbCoXRayExam e on q.Code = e.XRayExamID where q.requestnum = @ReqNum end if @type = '3' begin SELECT r.ControlNum, -- e.UltraExam [Examination], e.Description [Examination], q.TransDate, q.Code, Q.RequestDoctorCode [DoctorID], d1.FirstName + ' ' + d1.MiddleName + ' ' + d1.LastName [Doctor], r.RadCode [RadiologistID], d2.FirstName + ' ' + d2.MiddleName + ' ' + d2.LastName [Radiologist], r.XRayNum [FileNum], r.RoomID, r.TranscribedByID, r.VerifyByID, r.RadCode2 [CoRadiologistID], r.Remarks, E.SectionID as SectionID, isnull(q.TransDate, getdate()) ExamDate, q.DoctorName, isnull(convert(varchar(10),VerifyDate,101) + ' ' + convert(varchar(10),VerifyDate,108) , convert(varchar(10),ResultDate,101) + ' ' + convert(varchar(10),ResultDate,108) ) ResultDate, r.RadCode3 [CoRadiologistID3], r.RadCode4 [CoRadiologistID4],Resultcode, IsNull(ResultFindings,'') Findings FROM tbULRequest q left join tbULResult r on q.requestnum = r.requestnum left join build_file..tbcodoctor d1 on q.requestdoctorcode = d1.doctorid left join build_file..tbcodoctor d2 on r.radcode = d2.doctorid -- LEFT JOIN BUILD_FILE..tbCoUltraExam e -- on q.Code = e.UltraExamID Left Outer Join Billing..tbBillExamListing e On q.Code = e.ItemID and isnull(q.RevenueID,'US') = e.RevenueID where q.requestnum = @ReqNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CheckVerified] @RequestNum as varchar(10), @RevenueID as varchar(2) AS /*Set @RequestNum = '29'; Set @RevenueID = 'CT'; */ If @RevenueID = 'XR' Begin Select isnull(VerifyByID,'') VerifyByID From tbXRResult Where RequestNum = @RequestNum End; Else If @RevenueID = 'CT' Begin Select isnull(VerifyByID,'') VerifyByID From tbCTResult Where RequestNum = @RequestNum End; If @RevenueID = 'US' Begin Select isnull(VerifyByID,'') VerifyByID From tbULResult Where RequestNum = @RequestNum End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InquiryInterpret] @Type varchar(1), @ReqNum varchar(10) AS if @Type = '1' begin select Interpretation, Remarks from tbCTResult where RequestNum = @ReqNum end if @Type = '2' begin select Interpretation, Remarks from tbXRResult where RequestNum = @ReqNum end if @Type = '3' begin select Interpretation, Remarks from tbULResult where RequestNum = @ReqNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CancelResult] @RequestNum as varchar(10), @RevenueId as varchar(2) AS /* declare @RequestNum as varchar(10) declare @RevenueId as varchar(2) set @RequestNum = '' set @RevenueID = '' */ if @RevenueId = 'XR' begin update tbXrRequest set SwFin = 'X' where RequestNum = @RequestNum; delete from tbXrResult where RequestNum = @RequestNum; end; if @RevenueId = 'CT' begin update tbCTRequest set SwFin = 'X' where RequestNum = @RequestNum; delete from tbCTResult where RequestNum = @RequestNum; end; if @RevenueId = 'CT' begin update tbULRequest set SwFin = 'X' where RequestNum = @RequestNum; delete from tbULResult where RequestNum = @RequestNum; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_DumpResultEntry] @RequestNum as varchar(10), @RevenueID as varchar(2), @UserID as varchar(10) AS --Set @RequestNum = '29'; Delete From tbRadioResult Where UserID = @UserID; IF @RevenueID = 'XR' Begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks) Select Patient_Data.dbo.fn_GetPatientName(A.HospNum) Patient, A.HospNum, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) Doctor, A.ExamTaken, Patient_Data.dbo.fn_GetPatientCivilStatus(A.HospNum) CivilStatus, Case When Left(A.HospNum,1) = 'T' Then C.Age Else B.Age End Age, Case When Left(A.HospNum,1) = 'T' Then C.Sex Else B.Sex End Sex, Case When A.Idnum = 'CASH' Then 'OPD' Else A.Idnum End, A.RequestNum, isnull(D.RoomID, 'OPD') Room, ExamDate, Interpretation, Patient_Data.dbo.fn_GetDrName(A.RadCode) Radiologist, Patient_Data.dbo.fn_GetCompleteAddress(A.HospNum) Address, Case When Left(A.HospNum,1) = 'T' Then '' Else B.TelNum End TelNum, A.XrayNum, A.ControlNum, @UserID, Patient_Data.dbo.fn_GetDrName(A.RadCode2) Radio2, A.Remarks From tbXRResult A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.HospNum Left Outer Join Patient_Data..tbCashPatient C On A.HospNum = C.HospNum Left Outer Join Patient_Data..tbPatient D On A.Idnum = D.Idnum Where RequestNum = @RequestNum End; Else IF @RevenueID = 'CT' Begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks) Select Patient_Data.dbo.fn_GetPatientName(A.HospNum) Patient, A.HospNum, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) Doctor, A.ExamTaken, Patient_Data.dbo.fn_GetPatientCivilStatus(A.HospNum) CivilStatus, Case When Left(A.HospNum,1) = 'T' Then C.Age Else B.Age End Age, Case When Left(A.HospNum,1) = 'T' Then C.Sex Else B.Sex End Sex, Case When A.Idnum = 'CASH' Then 'OPD' Else A.Idnum End, A.RequestNum, isnull(D.RoomID, 'OPD') Room, ExamDate, Interpretation, Patient_Data.dbo.fn_GetDrName(A.RadCode) Radiologist, Patient_Data.dbo.fn_GetCompleteAddress(A.HospNum) Address, Case When Left(A.HospNum,1) = 'T' Then '' Else B.TelNum End TelNum, A.XrayNum, A.ControlNum, @UserID, Patient_Data.dbo.fn_GetDrName(A.RadCode2) Radio2, A.Remarks From tbCTResult A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.HospNum Left Outer Join Patient_Data..tbCashPatient C On A.HospNum = C.HospNum Left Outer Join Patient_Data..tbPatient D On A.Idnum = D.Idnum Where RequestNum = @RequestNum End; Else IF @RevenueID = 'US' Begin INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks) Select Patient_Data.dbo.fn_GetPatientName(A.HospNum) Patient, A.HospNum, Patient_Data.dbo.fn_GetDrName(A.RequestDoctorCode) Doctor, A.ExamTaken, Patient_Data.dbo.fn_GetPatientCivilStatus(A.HospNum) CivilStatus, Case When Left(A.HospNum,1) = 'T' Then C.Age Else B.Age End Age, Case When Left(A.HospNum,1) = 'T' Then C.Sex Else B.Sex End Sex, Case When A.Idnum = 'CASH' Then 'OPD' Else A.Idnum End, A.RequestNum, isnull(D.RoomID, 'OPD') Room, ExamDate, Interpretation, Patient_Data.dbo.fn_GetDrName(A.RadCode) Radiologist, Patient_Data.dbo.fn_GetCompleteAddress(A.HospNum) Address, Case When Left(A.HospNum,1) = 'T' Then '' Else B.TelNum End TelNum, A.XrayNum, A.ControlNum, @UserID, Patient_Data.dbo.fn_GetDrName(A.RadCode2) Radio2, A.Remarks From tbULResult A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.HospNum Left Outer Join Patient_Data..tbCashPatient C On A.HospNum = C.HospNum Left Outer Join Patient_Data..tbPatient D On A.Idnum = D.Idnum Where RequestNum = @RequestNum End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created By: Christian Gonzalo Client: Lorma Medical Center Date: 12062010 Modifications: 1.)Altered the parameter @EndDate to getdate() of RADIOLOGY.dbo.fncPatientTotalHospitalbillNet_CutOff */ CREATE PROCEDURE [dbo].[spRadio_RadiologistPatientList_New] @RadCode varchar(10), @StartDate varchar(40), @EndDate varchar(40), @RevenueID varchar(2) = 'XR' AS /* Declare @StartDate VARCHAR(40), @EndDate VARCHAR(40), @RevenueID varchar(2), @RadCode varchar(10) set @StartDate = '05/01/2010' set @EndDate = '05/28/2010' set @RadCode = '213' set @RevenueID = 'xr' */ If @RevenueID = 'XR' Begin Select A.HospNum, A.IDNum, A.PatientName, A.ItemID, A.Exam, A.RefNum, A.Amount Gross, IsNull(A.DiscountPercentage, 0) DiscountPercentage, Case When IsNull(A.DiscountPercentage, 0) = 0 Then A.Amount Else (A.Amount - (A.Amount * A.DiscountPercentage)) End Net, A.Quantity, IsNull(A.RoomID,'OPD') RoomID, A.AccountNum, A.AccountName, A.TransDate, A.VerifyDate, A.HospitalBill, A.PatientType, A.SectionID, Case When A.HospitalBill = 0 and IsNull(A.ORNum,'') Not In ('OR') and IsNull(A.SDeductionAmount,0) <> 0 Then A.SDeductionDate Else IsNull(A.ORNum,A.RefNum) End as ORNum, A.RadCode, A.DoctorsName, A.FileNum--, -- a.sdeductiondate, -- a.sdeductionamount From ( Select Distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.XrayExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'I' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'XR' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillDailyBill B2 Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum),B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbXRRequest Req Left Outer Join Billing..tbBillDailyBill B On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbXRResult Res with (Index(tbXRResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoXRayExam Ex On Ex.XrayExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 1 and B.RevenueID = 'XR' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' Union All Select distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.XrayExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'O' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'XR' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillOPDailyOut B2 with (Index(tbBillOPDailyOut9)) Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum), B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbXRRequest Req Left Outer Join Billing..tbBillOPDailyOut B with (Index(tbBillOPDailyOut9, RefNum)) On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbXRResult Res with (Index(tbXRResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoXRayExam Ex On Ex.XrayExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbOutPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 0 and B.RevenueID = 'XR' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' ) as A --INNER JOIN BILLING..tbbillopdailyout b ON A.IDNum = B.IDNum --Where HospitalBill <= 0 --AND --B.RevenueID IN ('CP','PY','DE','PP','OA') Where A.RadCode = @RadCode Order By A.TransDate --Order By A.PatientName End If @RevenueID = 'CT' Begin --Select A.HospNum, -- A.IDNum, -- A.PatientName, -- A.ItemID, -- A.Exam, -- A.RefNum, -- A.Amount Gross, IsNull(A.DiscountPercentage, 0) DiscountPercentage, -- Case When IsNull(A.DiscountPercentage, 0) < 1 Then A.Amount Else (A.Amount - (A.Amount * A.DiscountPercentage)) End Net, -- A.Quantity, -- IsNull(A.RoomID,'OPD') RoomID, -- A.AccountNum, -- A.AccountName, -- A.TransDate, -- A.VerifyDate, -- A.HospitalBill, -- A.PatientType, -- A.SectionID, A.SeniorDiscount, -- A.ORNum, A.RadCode, A.DoctorsName, A.FileNum Select A.HospNum, A.IDNum, A.PatientName, A.ItemID, A.Exam, A.RefNum, A.Amount Gross, IsNull(A.DiscountPercentage, 0) DiscountPercentage, Case When IsNull(A.DiscountPercentage, 0) = 0 Then A.Amount Else (A.Amount - (A.Amount * A.DiscountPercentage)) End Net, A.Quantity, IsNull(A.RoomID,'OPD') RoomID, A.AccountNum, A.AccountName, A.TransDate, A.VerifyDate, A.HospitalBill, A.PatientType, A.SectionID, Case When A.HospitalBill = 0 and IsNull(A.ORNum,'') Not In ('OR') and IsNull(A.SDeductionAmount,0) <> 0 Then A.SDeductionDate Else IsNull(A.ORNum,A.RefNum) End as ORNum, A.RadCode, A.DoctorsName, A.FileNum From ( Select distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.CTExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'I' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'CT' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillDailyBill B2 Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum), B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbCTRequest Req Left Outer Join Billing..tbBillDailyBill B On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbCTResult Res with (Index(tbCTResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoCTExam Ex On Ex.CTExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 1 and B.RevenueID = 'CT' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' Union All Select distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.CTExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'O' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'CT' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillOPDailyOut B2 with (Index(tbBillOPDailyOut9)) Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum), B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbCTRequest Req Left Outer Join Billing..tbBillOPDailyOut B with (Index(tbBillOPDailyOut9, RefNum)) On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbCTResult Res with (Index(tbCTResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoCTExam Ex On Ex.CTExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbOutPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 0 and B.RevenueID = 'CT' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' ) as A --INNER JOIN BILLING..tbbillopdailyout b ON A.IDNum = B.IDNum --Where HospitalBill <= 0 --AND --B.RevenueID IN ('CP','PY','DE','PP','OA') Where A.RadCode = @RadCode Order By A.TransDate --Order By A.PatientName End If @RevenueID = 'US' Begin --Select A.HospNum, -- A.IDNum, -- A.PatientName, -- A.ItemID, -- A.Exam, -- A.RefNum, -- A.Amount Gross, IsNull(A.DiscountPercentage, 0) DiscountPercentage, -- Case When IsNull(A.DiscountPercentage, 0) = 0 Then A.Amount Else (A.Amount - (A.Amount * A.DiscountPercentage)) End Net, -- A.Quantity, -- IsNull(A.RoomID,'OPD') RoomID, -- A.AccountNum, -- A.AccountName, -- A.TransDate, -- A.VerifyDate, -- A.HospitalBill, -- A.PatientType, -- A.SectionID, A.SeniorDiscount, -- A.ORNum, A.RadCode, A.DoctorsName, A.FileNum Select A.HospNum, A.IDNum, A.PatientName, A.ItemID, A.Exam, A.RefNum, A.Amount Gross, IsNull(A.DiscountPercentage, 0) DiscountPercentage, Case When IsNull(A.DiscountPercentage, 0) = 0 Then A.Amount Else (A.Amount - (A.Amount * A.DiscountPercentage)) End Net, A.Quantity, IsNull(A.RoomID,'OPD') RoomID, A.AccountNum, A.AccountName, A.TransDate, A.VerifyDate, A.HospitalBill, A.PatientType, A.SectionID, Case When A.HospitalBill = 0 and IsNull(A.ORNum,'') Not In ('OR') and IsNull(A.SDeductionAmount,0) <> 0 Then A.SDeductionDate Else IsNull(A.ORNum,A.RefNum) End as ORNum, A.RadCode, A.DoctorsName, A.FileNum From ( Select distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.UltraExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'I' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'US' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillDailyBill B2 Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum), B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillDailyBill B3 Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbULRequest Req Left Outer Join Billing..tbBillDailyBill B On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbULResult Res with (Index(tbULResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoUltraExam Ex On Ex.UltraExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 1 and B.RevenueID = 'US' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' Union All Select distinct Req.HospNum, Req.IDNum, Case when isnull(B.IDNum,'CASH') = 'CASH' then isnull(ORM.[Name],'') else Patient_Data.dbo.fn_GetPatientName(Req.Hospnum) End as PatientName, Req.Code ItemID, Ex.UltraExam Exam, Req.RefNum, B.Amount, B.Quantity, Req.RoomID, IsNull(P.AccountNum, Req.HospNum) AccountNum, radiology.dbo.fn_GetCompanyNameByIDNum(Req.IDNum) AccountName, Req.TransDate, Res.VerifyDate, Res.XrayNum FileNum, Case When CAST(BILLING.dbo.fncPatientTotalHospitalbillNet( B.IDNum, CASE WHEN IsNumeric(B.IDNum) = 1 THEN '1' ELSE '2' End, '') AS decimal(16, 2)) < 1 Or Left(Req.RefNum,2) = 'OR' Then '0' Else '1' End As HospitalBill, 'O' PatientType, Case When G.RevenueID = 'CF' then isnull(G.Discount,'0') else '0' End as SeniorDiscount, 'US' SectionID, IsNull(Res.RadCode,'') RadCode, Radiology.dbo.fn_GetDoctorsName(Res.RadCode) DoctorsName, Case When Left(Req.RefNum, 2) = 'OR' Then Req.RefNum Else IsNull((Select Top 1 IsNull(B2.RefNum,B.RefNum) From Billing..tbBillOPDailyOut B2 with (Index(tbBillOPDailyOut9)) Where B2.RevenueID IN ('CP','PY','DE','PP','OA') and B2.IDNum = Req.IDNum), B.RefNum) End ORNum, cast((G.Discount / G.Gross) as decimal(8, 6)) as DiscountPercentage, IsNull((Select Sum(Amount) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),0) as SDeductionAmount, IsNull((Select convert(varchar(20),Max(TransDate),103) From Billing..tbBillOPDailyOut B3 with (Index(tbBillOPDailyOut9)) Where B3.IDNum = Req.IDNum and B3.RevenueID = 'SD'),'') as SDeductionDate From Radiology..tbULRequest Req Left Outer Join Billing..tbBillOPDailyOut B with (Index(tbBillOPDailyOut9, RefNum)) On Req.Code = B.ItemID and Req.RefNum = B.RefNum and Req.IDNum = B.IDNum Left Outer Join Radiology..tbULResult Res with (Index(tbULResult_PatientList)) On Res.RequestNum = Req.RequestNum Left Outer Join Build_File..tbCoUltraExam Ex On Ex.UltraExamID = Req.Code Left Outer Join Billing..tbCashAssessment ORM with (Index(tbCashAssessment3)) ON ORM.RefNum = Req.SlipNum Left Outer Join Patient_Data..tbOutPatient P On P.IDNum = Req.IDNum Left Outer Join Billing..tbBillSeniorDiscount G with (Index(tbBillSeniorDiscount_IDNum_DeptID)) on G.IDNum = Req.IDnum and G.DepartmentID = @RevenueID Where Req.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' and IsNumeric(B.IDNum) = 0 and B.RevenueID = 'US' -- and IsNull(Res.RadCode,'') = @RadCode and Not IsNull(Res.ResultDate, '') = '' ) as A --INNER JOIN BILLING..tbbillopdailyout b ON A.IDNum = B.IDNum --Where HospitalBill <= 0 --AND --B.RevenueID IN ('CP','PY','DE','PP','OA') Where A.RadCode = @RadCode Order By A.TransDate --Order By A.PatientName End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Radio_ResultReport] @RequestNum varchar(20), @RevenueID varchar(2) AS /* declare @RequestNum varchar(20), @RevenueID varchar(2) set @RevenueID ='XR' set @RequestNum = '150731' */ Declare @Version Varchar(2) declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) declare @ImagingReason as varchar(900) declare @SurgicalReason as varchar(900) declare @Idnum as varchar(20) declare @RefNum as varchar(20) --If @RefNum like 'C%I' -- begin -- set @Idnum = (Select distinct IDnum from Prepaid..tbPrepaidCharges where Chargeslip = @refnum and revenueid = @DepartmentID) -- end --else -- begin -- set @Idnum = (Select distinct IDnum from Station..tbNurseLogbook where ReferenceNum = @refnum and revenueid = @DepartmentID) -- end if @IdNum is null Begin if @RevenueID = 'XR' Begin set @IdNum = (select top 1 IdNum from TBXrrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBXrrequest Where RequestNum = @RequestNum ) End if @RevenueID = 'US' Begin set @IdNum = (select top 1 IdNum from TBULrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBULrequest Where RequestNum = @RequestNum ) End if @RevenueID = 'CT' Begin set @IdNum = (select top 1 IdNum from TBCTrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBCTrequest Where RequestNum = @RequestNum ) End End if isnumeric(@IdNum) = 0 begin if @IDNum = 'CASH' Begin Select top 1 @ImagingReason = ltrim(rtrim(replace(cast(isnull(ImagingReason,'') as varchar(1900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(SurgicalReason,'') as varchar(1900)),char(13),''))) From Billing..tbCashAssessment with (Index(tbCashAssessment_ORNumber)) Where ORNumber = @RefNum End else Begin Select top 1 @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar(1900)),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar(1900)),char(13),''))), -- @BriefHistory = @ChiefComplaints + CHAR(13) + @Diagnosis, @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(1900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum End end; if isnumeric(@IdNum) = 1 begin Select @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar(900)),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar(900)),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar(900)),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar(900)),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar(2000)),char(13),''))), @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMain PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Where L.ReferenceNum = @RefNum end; IF @RevenueID = 'CT' BEGIN Set @Version = (Select Top 1 Version From Radiology..tbCTResultHistory Where RequestNum = @RequestNum Order by VerifyDate Desc); SELECT Top 1 Req.HospNum AS HospNum, Req.RequestNum AS RequestNum, Req.RefNum, Patient_Data.dbo.fn_GetPatientName(tbMaster.HospNum) PatientName, Req.Code AS Code, case isnull(Req.revenueID, 'CT') when 'CT' then tbCoCTExam.CTExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName else I.ItemName end AS Description, tbCoCTExam.CTSectionID AS SectionID, Req.IDNum AS IDNum, Req.TransDate AS TransDate, Req.Film1, Req.Film2, Req.Film3, Req.Film4, Req.Film5, Req.Film6, Req.Film7, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = Req.RequestDoctorCode), 'OPD') END AS RoomID, Req.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate())--tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CTNum ELSE tbCashPatient.CTNum END AS FileNum, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.HouseStreet -- ELSE tbCashPatient.HouseStreet -- END HouseStreet, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.Barangay -- ELSE tbCashPatient.Barangay -- END Barangay, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Town -- ELSE tbCoAddress_C.Town -- END [Town], -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Province -- ELSE tbCoAddress_C.Province -- END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], Req.Amount, Billing.dbo.fn_GetDoctorsName(Req.RequestDoctorCode) ReqDocName, --Req.DoctorName, Req.revenueID, case when isnumeric(Req.IDNum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge, Req.Quantity, Case When Req.RevenueID = 'C3' then PH.LocationID else '' End As LocationID, Interpretation, IsNull(Res.VerifyByID,'') VerifyByID, IsNull(Billing.dbo.fn_GetEmployeeName(Res.VerifyByID),'') VerifyByName, Res.ExamDate as ExamDate, Res.ResultDate as ResultDate, Res.VerifyDate as VerificationDate, IsNull(Res.RadCode,'') as Radiologist, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode),'') RadiologistName, IsNull(Res.RadCode2,'') as Radiologist2, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode2),'') RadiologistName2, IsNull(Res.RadCode3,'') as Radiologist3, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode3),'') RadiologistName3, IsNull(Res.RadCode4,'') as Radiologist4, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode4),'') RadiologistName4, IsNull(Res.ResultFindings,'0|0|0|0|0|0|0') as ResultFindings, CASE WHEN tbMaster.HospNum IS NOT NULL THEN Case When Len(tbMaster.HouseStreet) = 0 Then '' Else tbMaster.HouseStreet End + ', ' + Case When Len(tbMaster.Barangay) = 0 Then '' Else tbMaster.Barangay End + ', ' + Case When Len(tbCoAddress.Town) = 0 Then '' Else tbCoAddress.Town End + ', ' + Case When Len(tbCoAddress.Province) = 0 Then '' Else tbCoAddress.Province End ELSE Case When Len(tbCashPatient.HouseStreet) = 0 Then '' Else tbCashPatient.HouseStreet End + ', ' + Case When Len(tbCashPatient.Barangay) = 0 Then '' Else tbCashPatient.Barangay End + ', ' + Case When Len(tbCoAddress_C.Town) = 0 Then '' Else tbCoAddress_C.Town End + ', ' + Case When Len(tbCoAddress_C.Province) = 0 Then '' Else tbCoAddress_C.Province End END as CompleteAddress, Res.EditedByID as UserID, IsNull(IT.RequestNum,'NoResult') as ITRequestNum, -- IsNull(AdmDiagnosis,'') AdmDiagnosis, IsNull(ChiefComplaint,'') as ChiefComplaint, IsNull(SN.Reason,'') as Remarks, -- IsNull(PHis.ImagingReason,'') ImagingReason, IsNull(PHis.SurgicalReason,'') as SurgicalReason, Case When IsNull(@Findings,'') = '' Then IsNull(@Diagnosis,'') Else @Findings End as AdmDiagnosis, IsNull(@ChiefComplaints,'') as ChiefComplaint, IsNull(@ImagingReason,'') as ImagingReason, IsNull(@SurgicalReason,'') as SurgicalReason, IsNull(Res.Verifier1,'') VerifierCode1, Radiology.dbo.fn_GetEmployeeName(Res.Verifier1) VerifierName1, IsNull(Res.Verifier2,'') VerifierCode2, Radiology.dbo.fn_GetEmployeeName(Res.Verifier2) VerifierName2, -- IsNull(Res.RadTech,Res.TranscribedbyID) TranscribedbyID, RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Res.TranscribedbyID)) TranscribedBy, --RadTech InCharge Case When isNull((Select IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then IsNull(Res.RadTech,Res.TranscribedbyID) --RadTech InCharge Else IsNull(Res.RadTech,Req.[By]) --RadTech InCharge End as TranscribedByID, Case When isNull((Select IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Res.TranscribedbyID)) --RadTech InCharge Else RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Req.[By])) --RadTech InCharge End as TranscribedBy, IsNull(ResultGrid1, '') as ResultGrid1, IsNull(ResultGrid2, '') as ResultGrid2, IsNull(ResultGrid3, '') as ResultGrid3, IsNull(ResultGrid4, '') as ResultGrid4, IsNull(ResultGrid5, '') as ResultGrid5, IsNull(ResultGrid6, '') as ResultGrid6, IsNull(ResultGrid7, '') as ResultGrid7, IsNull(ResultGrid8, '') as ResultGrid8, IsNull(ResultGrid9, '') as ResultGrid9, IsNull(ResultGrid10, '') as ResultGrid10, IsNull(ResultGrid11, '') as ResultGrid11, IsNull(ResultGrid12, '') as ResultGrid12, IsNull(ResultGrid13, '') as ResultGrid13, IsNull(ResultGrid14, '') as ResultGrid14, IsNull(ResultGrid15, '') as ResultGrid15, IsNull(ResultGrid16, '') as ResultGrid16, IsNull(ResultGrid17, '') as ResultGrid17, IsNull(ResultGrid18, '') as ResultGrid18, IsNull(ResultGrid19, '') as ResultGrid19, IsNull(ResultGrid20, '') as ResultGrid20, IsNull(ResultGrid21, '') as ResultGrid21, IsNull(ResultGrid22, '') as ResultGrid22, IsNull(ResultGrid23, '') as ResultGrid23, IsNull(ResultGrid24, '') as ResultGrid24, IsNull(ResultGrid25, '') as ResultGrid25, IsNull(ResultGrid26, '') as ResultGrid26, IsNull(ResultGrid27, '') as ResultGrid27, IsNull(ResultGrid28, '') as ResultGrid28, IsNull(FieldName1, '') FieldName1, IsNull(FieldName2, '') FieldName2, IsNull(FieldName3, '') FieldName3, IsNull(FieldName4, '') FieldName4, IsNull(FieldName5, '') FieldName5, IsNull(FieldName6, '') FieldName6, IsNull(FieldName7, '') FieldName7, IsNull(FieldName8, '') FieldName8, IsNull(FieldName9, '') FieldName9, IsNull(FieldName10, '') FieldName10, IsNull(FieldName11, '') FieldName11, IsNull(FieldName12, '') FieldName12, IsNull(FieldName13, '') FieldName13, IsNull(Cast((Select Top 1 VerifyDate From Radiology..tbCTResultHistory with (Index(tbCTResultHistory_RequestNum_Version)) Where RequestNum = @RequestNum AND Version = IsNull(@Version,1) - 1)as varchar(40)),'') DateLastVerified, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash FROM tbCTRequest Req LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON Req.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON Req.IDNum = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON Req.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON Req.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON Req.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.ZipCode = tbCoAddress.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoCTExam [tbCoCTExam] ON Req.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON Req.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON Req.Code = Doc.DoctorID LEFT OUTER JOIN Inventory..tbInvStockCard PH ON Req.RefNum = PH.RefNum and Req.Code = PH.ItemID and PH.SummaryCode = 'PH' LEFT OUTER JOIN Radiology..tbCTResult Res On Res.RequestNum = Req.RequestNum LEFT OUTER JOIN Radiology..tbRadioResultTable IT With (Index(tbRadioResultTable_RequestNum)) On IT.RequestNum = Req.RequestNum and IT.RevenueID = 'CT' and IT.RequestNum is not Null LEFT OUTER JOIN PATIENT_DATA..tbPatientHistory PHis On Req.IDNum = PHis.IDNum LEFT OUTER JOIN STATION..tbNurseCommunicationFile SN On SN.IDNum = Req.IDNum and SN.RevenueID = 'CT' and SN.ItemID = Req.Code and SN.RecordStatus = 'X' and IsNull(SN.Referencenum,'') in (Req.RefNum,'') Left Outer Join Billing..tbCashAssessment B On Req.RefNum = B.ORNumber and Indicator = 'CT' and B.IDNum = Req.IDNum WHERE @RequestNum = Req.RequestNum Order By Req.TransDate desc END IF @RevenueID = 'XR' BEGIN Set @Version = (Select Top 1 Version From Radiology..tbXRResultHistory Where RequestNum = @RequestNum Order by VerifyDate Desc); SELECT top 1 Req.HospNum AS HospNum, Req.RequestNum AS RequestNum, Req.RefNum, Patient_Data.dbo.fn_GetPatientName(tbMaster.HospNum) PatientName, Req.Code AS Code, case isnull(Req.revenueID,'XR') when 'BM' then E.OtherRevenue when 'XR' then tbCoXrayExam.XRayExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName else I.ItemName end AS Description, tbCoXrayExam.XRaySectionID AS SectionID, Req.IDNum AS IDNum, Req.TransDate AS TransDate, Req.Film1, Req.Film2, Req.Film3, Req.Film4, Req.Film5, Req.Film6, Req.Film7, Req.RoomID as Room, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select top 1 Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = Req.RequestDoctorCode), 'OPD') END AS RoomID, Req.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate())--tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.XRayNum ELSE tbCashPatient.XRayNum END AS FileNum, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.HouseStreet -- ELSE tbCashPatient.HouseStreet -- END HouseStreet, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.Barangay -- ELSE tbCashPatient.Barangay -- END Barangay, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Town -- ELSE tbCoAddress_C.Town -- END [Town], -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Province -- ELSE tbCoAddress_C.Province -- END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], Req.Amount, Billing.dbo.fn_GetDoctorsName(Req.RequestDoctorCode) ReqDocName, --Req.DoctorName, Req.revenueID, case when isnumeric(Req.IDNum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge, Req.Quantity, Case When Req.RevenueID = 'XM' then PH.LocationID else '' End As LocationID, Interpretation, IsNull(Res.VerifyByID,'') VerifyByID, IsNull(Billing.dbo.fn_GetEmployeeName(Res.VerifyByID),'') VerifyByName, Res.ExamDate as ExamDate, Res.ResultDate as ResultDate, Res.VerifyDate as VerificationDate, IsNull(Res.RadCode,'') as Radiologist, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode),'') RadiologistName, IsNull(Res.RadCode2,'') as Radiologist2, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode2),'') RadiologistName2, IsNull(Res.RadCode3,'') as Radiologist3, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode3),'') RadiologistName3, IsNull(Res.RadCode4,'') as Radiologist4, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode4),'') RadiologistName4, IsNull(Res.ResultFindings,'0|0|0|0|0|0|0') as ResultFindings, CASE WHEN tbMaster.HospNum IS NOT NULL THEN Case When Len(tbMaster.HouseStreet) = 0 Then '' Else tbMaster.HouseStreet End + ', ' + Case When Len(tbMaster.Barangay) = 0 Then '' Else tbMaster.Barangay End + ', ' + Case When Len(tbCoAddress.Town) = 0 Then '' Else tbCoAddress.Town End + ', ' + Case When Len(tbCoAddress.Province) = 0 Then '' Else tbCoAddress.Province End ELSE Case When Len(tbCashPatient.HouseStreet) = 0 Then '' Else tbCashPatient.HouseStreet End + ', ' + Case When Len(tbCashPatient.Barangay) = 0 Then '' Else tbCashPatient.Barangay End + ', ' + Case When Len(tbCoAddress_C.Town) = 0 Then '' Else tbCoAddress_C.Town End + ', ' + Case When Len(tbCoAddress_C.Province) = 0 Then '' Else tbCoAddress_C.Province End END as CompleteAddress, Res.EditedByID as UserID, IsNull(IT.RequestNum,'NoResult') as ITRequestNum, -- IsNull(AdmDiagnosis,'') AdmDiagnosis, IsNull(ChiefComplaint,'') as ChiefComplaint, IsNull(SN.Reason,'') as Remarks, -- IsNull(PHis.ImagingReason,'') ImagingReason, IsNull(PHis.SurgicalReason,'') as SurgicalReason, Case When IsNull(@Findings,'') = '' Then IsNull(@Diagnosis,'') Else @Findings End as AdmDiagnosis, IsNull(@ChiefComplaints,'') as ChiefComplaint, IsNull(@ImagingReason,'') as ImagingReason, IsNull(@SurgicalReason,'') as SurgicalReason, IsNull(Res.Verifier1,'') VerifierCode1, Radiology.dbo.fn_GetEmployeeName(Res.Verifier1) VerifierName1, IsNull(Res.Verifier2,'') VerifierCode2, Radiology.dbo.fn_GetEmployeeName(Res.Verifier2) VerifierName2, -- IsNull(Res.RadTech,Res.TranscribedbyID) TranscribedbyID, RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Res.TranscribedbyID)) TranscribedBy, --RadTech InCharge Case When isNull((Select top 1 IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then IsNull(Res.RadTech,Res.TranscribedbyID) --RadTech InCharge Else IsNull(Res.RadTech,Req.[By]) --RadTech InCharge End as TranscribedByID, Case When isNull((Select top 1 IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Res.TranscribedbyID)) --RadTech InCharge Else RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Req.[By])) --RadTech InCharge End as TranscribedBy, IsNull(ResultGrid1, '') as ResultGrid1, IsNull(ResultGrid2, '') as ResultGrid2, IsNull(ResultGrid3, '') as ResultGrid3, IsNull(ResultGrid4, '') as ResultGrid4, IsNull(ResultGrid5, '') as ResultGrid5, IsNull(ResultGrid6, '') as ResultGrid6, IsNull(ResultGrid7, '') as ResultGrid7, IsNull(ResultGrid8, '') as ResultGrid8, IsNull(ResultGrid9, '') as ResultGrid9, IsNull(ResultGrid10, '') as ResultGrid10, IsNull(ResultGrid11, '') as ResultGrid11, IsNull(ResultGrid12, '') as ResultGrid12, IsNull(ResultGrid13, '') as ResultGrid13, IsNull(ResultGrid14, '') as ResultGrid14, IsNull(ResultGrid15, '') as ResultGrid15, IsNull(ResultGrid16, '') as ResultGrid16, IsNull(ResultGrid17, '') as ResultGrid17, IsNull(ResultGrid18, '') as ResultGrid18, IsNull(ResultGrid19, '') as ResultGrid19, IsNull(ResultGrid20, '') as ResultGrid20, IsNull(ResultGrid21, '') as ResultGrid21, IsNull(ResultGrid22, '') as ResultGrid22, IsNull(ResultGrid23, '') as ResultGrid23, IsNull(ResultGrid24, '') as ResultGrid24, IsNull(ResultGrid25, '') as ResultGrid25, IsNull(ResultGrid26, '') as ResultGrid26, IsNull(ResultGrid27, '') as ResultGrid27, IsNull(ResultGrid28, '') as ResultGrid28, IsNull(FieldName1, '') FieldName1, IsNull(FieldName2, '') FieldName2, IsNull(FieldName3, '') FieldName3, IsNull(FieldName4, '') FieldName4, IsNull(FieldName5, '') FieldName5, IsNull(FieldName6, '') FieldName6, IsNull(FieldName7, '') FieldName7, IsNull(FieldName8, '') FieldName8, IsNull(FieldName9, '') FieldName9, IsNull(FieldName10, '') FieldName10, IsNull(FieldName11, '') FieldName11, IsNull(FieldName12, '') FieldName12, IsNull(FieldName13, '') FieldName13, IsNull(Cast((Select Top 1 VerifyDate From Radiology..tbXRResultHistory with (Index(tbXRResultHistory_RequestNum_Version)) Where RequestNum = @RequestNum AND Version = IsNull(@Version,1) - 1)as varchar(40)),'') DateLastVerified, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash FROM tbXRRequest Req LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON Req.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON Req.IDNum = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON Req.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON Req.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON Req.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.ZipCode = tbCoAddress.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam [tbCoXRayExam] ON Req.Code = tbCoXRayExam.XRayExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON Req.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON Req.Code = DOC.DoctorID LEFT OUTER JOIN BUILD_FILE..tbcoOtherRevenue E ON Req.Code = E.OtherRevenueID and E.OtherSectionID = 'XR' LEFT OUTER JOIN Inventory..tbInvStockCard PH ON Req.RefNum = PH.RefNum and Req.Code = PH.ItemID and PH.SummaryCode = 'PH' LEFT OUTER JOIN Radiology..tbXRResult Res On Res.RequestNum = Req.RequestNum LEFT OUTER JOIN Radiology..tbRadioResultTable IT With (Index(tbRadioResultTable_RequestNum)) On IT.RequestNum = Req.RequestNum and IT.RevenueID = 'XR' and IT.RequestNum is not Null LEFT OUTER JOIN PATIENT_DATA..tbPatientHistory PHis On Req.IDNum = PHis.IDNum LEFT OUTER JOIN STATION..tbNurseCommunicationFile SN On SN.IDNum = Req.IDNum and SN.RevenueID = 'XR' and SN.ItemID = Req.Code and SN.RecordStatus = 'X' and IsNull(SN.Referencenum,'') in (Req.RefNum,'') Left Outer Join Billing..tbCashAssessment B On Req.RefNum = B.ORNumber and Indicator = 'XR' and B.IDNum = Req.IDNum WHERE @RequestNum = Req.RequestNum order by Req.TransDate desc END IF @RevenueID = 'US' BEGIN Set @Version = (Select Top 1 Version From Radiology..tbUltraResultHistory Where RequestNum = @RequestNum Order by VerifyDate Desc); SELECT Top 1 Req.HospNum AS HospNum, Req.RequestNum AS RequestNum, Req.RefNum, Patient_Data.dbo.fn_GetPatientName(tbMaster.HospNum) PatientName, Req.Code AS Code, case isnull(Req.revenueID,'US') when 'US' then tbCoUltraExam.UltraExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName when 'WC' then Build.Description else I.ItemName end AS Description, tbCoUltraExam.UltraSectionID AS SectionID, Req.IDNum AS IDNum, Req.TransDate AS TransDate, '' AS [8X10], '' AS [10X12], '' AS [11X14], '' AS [14X14], '' AS [14X17], CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select top 1 Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = Req.RequestDoctorCode), 'OPD') END AS RoomID, Req.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate())--tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, CASE WHEN LEFT(Req.RefNum, 2) = 'OR' THEN 0 ELSE CASE WHEN ISNUMERIC(tbPatient.IDNum) = 1 THEN ISNULL(tbPatient.BillingDate, 0) ELSE ISNULL(tbOutpatient.BillingDate, 0) END END AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.UltraNum ELSE tbCashPatient.UltraNum END AS FileNum, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.HouseStreet -- ELSE tbCashPatient.HouseStreet -- END HouseStreet, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbMaster.Barangay -- ELSE tbCashPatient.Barangay -- END Barangay, -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Town -- ELSE tbCoAddress_C.Town -- END [Town], -- CASE WHEN tbMaster.HospNum IS NOT NULL -- THEN tbCoAddress.Province -- ELSE tbCoAddress_C.Province -- END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], Req.Amount, Billing.dbo.fn_GetDoctorsName(Req.RequestDoctorCode) ReqDocName, --Req.DoctorName, Req.RevenueID , case when isnumeric(Req.IDNum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge, Req.Quantity, '' LocationID, Interpretation, IsNull(Res.VerifyByID,'') VerifyByID, IsNull(Billing.dbo.fn_GetEmployeeName(Res.VerifyByID),'') VerifyByName, Res.ExamDate as ExamDate, Res.ResultDate as ResultDate, Res.VerifyDate as VerificationDate, IsNull(Res.RadCode,'') as Radiologist, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode),'') RadiologistName, IsNull(Res.RadCode2,'') as Radiologist2, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode2),'') RadiologistName2, IsNull(Res.RadCode3,'') as Radiologist3, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode3),'') RadiologistName3, IsNull(Res.RadCode4,'') as Radiologist4, IsNull(Billing.dbo.fn_getDoctorsName(Res.RadCode4),'') RadiologistName4, IsNull(Res.ResultFindings,'0|0|0|0|0|0|0') as ResultFindings, CASE WHEN tbMaster.HospNum IS NOT NULL THEN Case When Len(tbMaster.HouseStreet) = 0 Then '' Else tbMaster.HouseStreet End + ', ' + Case When Len(tbMaster.Barangay) = 0 Then '' Else tbMaster.Barangay End + ', ' + Case When Len(tbCoAddress.Town) = 0 Then '' Else tbCoAddress.Town End + ', ' + Case When Len(tbCoAddress.Province) = 0 Then '' Else tbCoAddress.Province End ELSE Case When Len(tbCashPatient.HouseStreet) = 0 Then '' Else tbCashPatient.HouseStreet End + ', ' + Case When Len(tbCashPatient.Barangay) = 0 Then '' Else tbCashPatient.Barangay End + ', ' + Case When Len(tbCoAddress_C.Town) = 0 Then '' Else tbCoAddress_C.Town End + ', ' + Case When Len(tbCoAddress_C.Province) = 0 Then '' Else tbCoAddress_C.Province End END as CompleteAddress, Res.EditedByID as UserID, IsNull(IT.RequestNum,'NoResult') as ITRequestNum, -- IsNull(AdmDiagnosis,'') AdmDiagnosis, IsNull(ChiefComplaint,'') as ChiefComplaint, IsNull(SN.Reason,'') as Remarks, -- IsNull(PHis.ImagingReason,'') ImagingReason, IsNull(PHis.SurgicalReason,'') as SurgicalReason, Case When IsNull(@Findings,'') = '' Then IsNull(@Diagnosis,'') Else @Findings End as AdmDiagnosis, IsNull(@ChiefComplaints,'') as ChiefComplaint, IsNull(@ImagingReason,'') as ImagingReason, IsNull(@SurgicalReason,'') as SurgicalReason, IsNull(Res.Verifier1,'') VerifierCode1, Radiology.dbo.fn_GetEmployeeName(Res.Verifier1) VerifierName1, IsNull(Res.Verifier2,'') VerifierCode2, Radiology.dbo.fn_GetEmployeeName(Res.Verifier2) VerifierName2, Case When isNull((Select top 1 IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then IsNull(Res.RadTech,Res.TranscribedbyID) --RadTech InCharge Else IsNull(Res.RadTech,Req.[By]) --RadTech InCharge End as TranscribedByID, Case When isNull((Select top 1 IsNull(UserID, '') From Build_File..tbcoDoctor Where UserID = Res.TranscribedbyID),'') <> Res.TranscribedbyID Then RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Res.TranscribedbyID)) --RadTech InCharge Else RADIOLOGY.dbo.fn_GetEmployeeName(IsNull(Res.RadTech,Req.[By])) --RadTech InCharge End as TranscribedBy, IsNull(ResultGrid1, '') as ResultGrid1, IsNull(ResultGrid2, '') as ResultGrid2, IsNull(ResultGrid3, '') as ResultGrid3, IsNull(ResultGrid4, '') as ResultGrid4, IsNull(ResultGrid5, '') as ResultGrid5, IsNull(ResultGrid6, '') as ResultGrid6, IsNull(ResultGrid7, '') as ResultGrid7, IsNull(ResultGrid8, '') as ResultGrid8, IsNull(ResultGrid9, '') as ResultGrid9, IsNull(ResultGrid10, '') as ResultGrid10, IsNull(ResultGrid11, '') as ResultGrid11, IsNull(ResultGrid12, '') as ResultGrid12, IsNull(ResultGrid13, '') as ResultGrid13, IsNull(ResultGrid14, '') as ResultGrid14, IsNull(ResultGrid15, '') as ResultGrid15, IsNull(ResultGrid16, '') as ResultGrid16, IsNull(ResultGrid17, '') as ResultGrid17, IsNull(ResultGrid18, '') as ResultGrid18, IsNull(ResultGrid19, '') as ResultGrid19, IsNull(ResultGrid20, '') as ResultGrid20, IsNull(ResultGrid21, '') as ResultGrid21, IsNull(ResultGrid22, '') as ResultGrid22, IsNull(ResultGrid23, '') as ResultGrid23, IsNull(ResultGrid24, '') as ResultGrid24, IsNull(ResultGrid25, '') as ResultGrid25, IsNull(ResultGrid26, '') as ResultGrid26, IsNull(ResultGrid27, '') as ResultGrid27, IsNull(ResultGrid28, '') as ResultGrid28, IsNull(FieldName1, '') FieldName1, IsNull(FieldName2, '') FieldName2, IsNull(FieldName3, '') FieldName3, IsNull(FieldName4, '') FieldName4, IsNull(FieldName5, '') FieldName5, IsNull(FieldName6, '') FieldName6, IsNull(FieldName7, '') FieldName7, IsNull(FieldName8, '') FieldName8, IsNull(FieldName9, '') FieldName9, IsNull(FieldName10, '') FieldName10, IsNull(FieldName11, '') FieldName11, IsNull(FieldName12, '') FieldName12, IsNull(FieldName13, '') FieldName13, IsNull(Cast((Select Top 1 VerifyDate From Radiology..tbUltraResultHistory with (Index(tbUltraResultHistory_RequestNum_Version)) Where RequestNum = @RequestNum AND Version = IsNull(@Version,1) - 1)as varchar(40)),'') DateLastVerified, IsNull(B.ImagingReason,'') as ImagingReasonCash, IsNull(B.SurgicalReason,'') as SurgicalReasonCash FROM tbULRequest Req LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON Req.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON Req.IDNum = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON Req.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON Req.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON Req.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.ZipCode = tbCoAddress.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoUltraExam [tbCoUltraExam] ON Req.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON Req.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON Req.Code = DOC.DoctorID LEFT OUTER JOIN Billing..tbBillExamListing Build ON Req.RevenueID = Build.RevenueID and Req.Code = Build.ItemID LEFT OUTER JOIN Radiology..tbULResult Res On Res.RequestNum = Req.RequestNum LEFT OUTER JOIN Radiology..tbRadioResultTable IT With (Index(tbRadioResultTable_RequestNum)) On IT.RequestNum = Req.RequestNum and IT.RevenueID = 'US' and IT.RequestNum is not Null LEFT OUTER JOIN PATIENT_DATA..tbPatientHistory PHis On Req.IDNum = PHis.IDNum LEFT OUTER JOIN STATION..tbNurseCommunicationFile SN On SN.IDNum = Req.IDNum and SN.RevenueID = 'US' and SN.ItemID = Req.Code and SN.RecordStatus = 'X' and IsNull(SN.Referencenum,'') in (Req.RefNum,'') Left Outer Join Billing..tbCashAssessment B On Req.RefNum = B.ORNumber and Indicator = 'US' and B.IDNum = Req.IDNum WHERE @RequestNum = Req.RequestNum Order By Req.TransDate desc END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_RequestFile] @HospNum varchar(8), @RevenueID varchar(2) AS if @RevenueID = 'XR' begin select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.TransDate,'') as datetime), 101) [Exam Date], m.Code [Code], z.XRayExam [Exam], case isnull(m.swfin,'') when 'X' then 'No result' when 'R' then convert(varchar, cast(isnull(r.resultDate,'') as datetime), 101) end as [ResultDate] from tbxrrequest m LEFT JOIN tbxrresult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoXRayExam z on m.Code = z.XRayExamID where m.HospNum = @HospNum and isnull(Z.XRayExamID,'') <> '' order by cast(m.transDate as datetime) /* union all select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.requestdate,'') as datetime), 101) [Exam Date], m.ItemID [Code], z.XRayExam [Exam], 'No result'as [ResultDate] from Station..tbNurseCommunicationFile m LEFT JOIN tbxrresult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoXRayExam z on m.itemid = z.XRayExamID where m.HospNum = @HospNum and m.revenueid = 'XR'*/ end; if @RevenueID = 'CT' begin select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.TransDate,'') as datetime), 101) [Exam Date], m.Code [Code], z.CTExam [Exam], case isnull(m.swfin,'') when 'X' then 'No result' when 'R' then convert(varchar, cast(isnull(r.resultDate,'') as datetime), 101) end as [ResultDate] from tbCTRequest m left join tbCTResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoCTExam z on m.Code = z.CTExamID where m.HospNum = @HospNum and isnull(Z.CTExamID,'') <> '' order by cast(r.resultdate as datetime) /* union all select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.requestdate,'') as datetime), 101) [Exam Date], m.ItemID [Code], z.CTExam [Exam], 'No result'as [ResultDate] from Station..tbNurseCommunicationFile m LEFT JOIN tbCTRequest r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoCTExam z on m.itemid = z.CTExamID where m.HospNum = @HospNum and m.revenueid = 'CT' */ end; if @RevenueID = 'US' begin select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.TransDate,'') as datetime), 101) [Exam Date], m.Code [Code], z.UltraExam [Exam], case isnull(m.swfin,'') when 'X' then 'No result' when 'R' then convert(varchar, cast(isnull(r.resultDate,'') as datetime), 101) end as [ResultDate] from tbULRequest m left join tbULResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoUltraExam z on m.Code = z.UltraExamID where m.HospNum = @HospNum and isnull(Z.UltraExamID,'') <> '' order by cast(r.resultdate as datetime) /* union all select m.requestnum, CONVERT(VARCHAR, cast(isnull(m.requestdate,'') as datetime), 101) [Exam Date], m.ItemID [Code], z.UltraExam [Exam], 'No result'as [ResultDate] from Station..tbNurseCommunicationFile m LEFT JOIN tbULResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoUltraExam z on m.itemid = z.UltraExamID where m.HospNum = @HospNum and m.revenueid = 'UL' */ end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ResultFile] @HospNum varchar(8), @RevenueID varchar(2), @RadCode varchar(10) = '' AS if @RadCode = '' Begin if @RevenueID = 'XR' begin select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.XRayExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num] ---by Z3r0 from tbxrrequest m left join tbxrresult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoXRayExam z on m.Code = z.XRayExamID where m.swfin = 'Y' AND m.HospNum = @HospNum order by cast(r.resultdate as datetime) end if @RevenueID = 'CT' begin -- select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], -- m.Code [Code], z.CTExam [Exam], -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, -- Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.CTExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num]---by Z3r0 from tbCTRequest m left join tbCTResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoCTExam z on m.Code = z.CTExamID where m.swfin = 'Y' AND m.HospNum = @HospNum order by cast(r.resultdate as datetime) end if @RevenueID = 'US' begin -- select m.requestnum as [Trans. No] , CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], -- m.Code [Code], -- --z.UltraExam [Exam], -- '(' + m.RevenueID + ') ' + z.Description [Exam], -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, -- Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.UltraExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num]---by Z3r0 from tbULRequest m left join tbULResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoUltraExam z on m.Code = z.UltraExamID Left Outer Join Billing..tbBillExamListing b On isnull(m.RevenueID,'US') = b.RevenueID and m.Code = b.ItemID where m.swfin = 'Y' AND m.HospNum = @HospNum order by cast(r.resultdate as datetime) end End else begin if @RevenueID = 'XR' begin -- select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], -- m.Code [Code], z.XRayExam [Exam], r.ExamDate, r.EditedDate, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, -- Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.XRayExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num]---by Z3r0 from tbxrrequest m left join tbxrresult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoXRayExam z on m.Code = z.XRayExamID where m.swfin = 'Y' AND m.HospNum = @HospNum and Radcode = @Radcode order by cast(r.resultdate as datetime) end if @RevenueID = 'CT' begin -- select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], -- m.Code [Code], z.CTExam [Exam], -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, -- Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.CTExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num]---by Z3r0 from tbCTRequest m left join tbCTResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoCTExam z on m.Code = z.CTExamID where m.swfin = 'Y' AND m.HospNum = @HospNum and Radcode = @Radcode order by cast(r.resultdate as datetime) end if @RevenueID = 'US' begin -- select m.requestnum as [Trans. No] , CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], -- m.Code [Code], -- --z.UltraExam [Exam], -- '(' + m.RevenueID + ') ' + z.Description [Exam], -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, -- Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, -- Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, select m.requestnum as [Trans. No], CONVERT(VARCHAR, cast(r.ExamDate as datetime), 101) [Exam Date], m.Code [Code], z.UltraExam [Exam], isnull(m.FilmsReleased,'') [Films Released], isnull(billing.dbo.fn_getemployeeName(m.FilmsUser),'') [Released by], r.ExamDate, r.EditedDate, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, isnull(r.EditCount,0) as Count, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, r.xraynum [File Num]---by Z3r0 from tbULRequest m left join tbULResult r on m.requestnum = r.requestnum LEFT JOIN build_file..tbCoUltraExam z on m.Code = z.UltraExamID Left Outer Join Billing..tbBillExamListing b On isnull(m.RevenueID,'US') = b.RevenueID and m.Code = b.ItemID where m.swfin = 'Y' AND m.HospNum = @HospNum and Radcode = @Radcode order by cast(r.resultdate as datetime) end end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultCancellation] @RevenueID varchar(2), @RequestNum varchar(10), @UserId varchar(4), @HospNum varchar(10) AS Begin Tran; Declare @Verified varchar(4) Declare @VerifyDate varchar(10) if @RevenueID = 'XR' begin Set @Verified = (Select VerifybyID from tbXRResult where RequestNum = @RequestNum and HospNum = @HospNum) Set @VerifyDate = (Select convert(varchar(10),VerifyDate,101) as VerifyDate from tbXRResult where RequestNum = @RequestNum and HospNum = @HospNum) If isnull(@Verified,'') = '' and isnull(@VerifyDate,'') = '' Begin /*Update tbXRResult Set HospNum = 'C', RequestNum = 'C' + RequestNum, CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; */ Update tbXRRequest Set HospNum = 'C', CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; End end if @RevenueID = 'CT' begin Set @Verified = (Select VerifybyID from tbCTResult where RequestNum = @RequestNum and HospNum = @HospNum) Set @VerifyDate= (Select convert(varchar(10),VerifyDate,101) as VerifyDate from tbCTResult where RequestNum = @RequestNum and HospNum = @HospNum) If isnull(@Verified,'') = '' and isnull(@VerifyDate,'') = '' Begin /* Update tbCTResult Set HospNum = 'C', RequestNum = 'C'+RequestNum, CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; */ Update tbCTRequest Set HospNum = 'C', CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; End end if @RevenueID = 'US' begin Set @Verified = (Select VerifybyID from tbULResult where RequestNum = @RequestNum and HospNum = @HospNum) Set @VerifyDate = (Select convert(varchar(10),VerifyDate,101) as VerifyDate from tbULResult where RequestNum = @RequestNum and HospNum = @HospNum) If isnull(@Verified,'') = '' and isnull(@VerifyDate,'') = '' Begin /* Update tbULResult Set HospNum = 'C', RequestNum = 'C'+RequestNum, CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; */ Update tbULRequest Set HospNum = 'C', CancelInfo = convert(varchar(10),getdate(),101) + ' ' + @HospNum + ' ' + @UserId Where RequestNum = @RequestNum and HospNum = @HospNum; End end If @@Error <> 0 Begin goto SaveError; End Commit Tran; Return 0; SaveError: Rollback Tran; Return @@Error; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ResultForPrinting] @RequestNum As varchar(10), @Department As varchar(2), -- CT / XR / US @Patient AS varChar(90), @HospNum AS varChar(10), @Doctor AS varChar(60), @Examination AS varChar(60), @CivilStatus AS varChar(15), @Age AS varChar(3), @Sex AS varChar(6), @AdmNum AS varChar(10), @CTNum AS varChar(10), @RoomNo AS varChar(15), @ExamDate AS DateTime, @Interpretation AS Text, @Radiologist AS varChar(60), @Address AS varChar(60), @TelNo AS varChar(15), @FileNum AS varChar(10), @ControlNum AS varChar(10), @UserID AS varchar(10) AS DECLARE @cHospNum as varchar(10) DECLARE @PatientClass as varchar(1) DECLARE @Classification as varchar(50) DECLARE @RequestDate as datetime DECLARE @ResultDate as datetime DECLARE @ResidentID as varchar(5) DECLARE @Resident as varchar(60) DECLARE @BirthDate as datetime DECLARE @cAge as varchar(3) DECLARE @Encoder as varchar(50) SET @Encoder = (Select LastName + ', ' + FirstName + ' ' + MiddleName [Encoder] From Password..tbPasswordMaster Where EmployeeID = @USerID) if @Hospnum = 'CASH' begin SET @cHospNum = 'OPD' end else begin SET @cHospNum = @HospNum end if isnumeric(@HospNum) = 1 begin select @BirthDate = BirthDate from PATIENT_DATA..tbMaster where HospNum = @HospNum end else begin select @BirthDate = BirthDate from PATIENT_DATA..tbCashPatient where HospNum = @HospNum end set @PatientClass = '' if ISNUMERIC(@AdmNum) = 1 begin select @PatientClass = ISNULL(PatientClass, '') from PATIENT_DATA..tbPatient2 where IDNum = @Admnum end else begin select @PatientClass = LEFT(ISNULL(PatientType, ''), 1) from PATIENT_DATA..tbOutPatient where IDNum = @AdmNum end /* if @PatientClass = 'S' set @Classification = 'SERVICE' else if @PatientClass = 'P' set @Classification = 'PAY' else set @Classification = 'SERVICE' */ set @Classification = (select case isnull(MSSClassification,'') when '' then 'PAY' else 'SERVICE' end as Classification from PATIENT_DATA..tbMaster where hospnum = @HospNum) if @Department = 'XR' begin select @RequestDate = TransDate from tbXRRequest where RequestNum = @RequestNum select @ResultDate = ResultDate, @ResidentID = ResidentID from tbXRResult where RequestNum = @RequestNum end if @Department = 'US' begin select @RequestDate = TransDate from tbULRequest where RequestNum = @RequestNum select @ResultDate = ResultDate, @ResidentID = ResidentID from tbULResult where RequestNum = @RequestNum end if @Department = 'CT' begin select @RequestDate = TransDate from tbCTRequest where RequestNum = @RequestNum select @ResultDate = ResultDate, @ResidentID = ResidentID from tbCTResult where RequestNum = @RequestNum end if len(isnull(@ResidentID, '')) > 0 begin select @Resident = ( FirstName + ' ' + LastName + case when len(isnull(Title, '')) > 0 then ', ' + Title else ', M.D.' end ) from BUILD_FILE..tbCoDoctor where DoctorID = @ResidentID end DELETE tbRadioResult WHERE UserID = @UserID; IF (@BirthDate is null) or (@BirthDate <= '01/01/1900') BEGIN SET @cAge = @Age END ELSE BEGIN SET @cAge = convert(varchar(3), cast((year(@ResultDate) + (cast(month(@ResultDate) as float)/12) + (cast(day(@ResultDate) as float)/365)) - (year(@BirthDate) + (cast(month(@BirthDate) as float)/12) + (cast(day(@BirthDate) as float)/365)) as int) ) END INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Classification, RequestDate, ResultDate, DepartmentNo, Resident, BirthDate,Encoder ) VALUES (@Patient, @cHospNum, @Doctor, @Examination, @CivilStatus, @cAge, @Sex, @AdmNum, @CTNum, @RoomNo, @ExamDate, @Interpretation, @Radiologist, @Address, @TelNo, @FileNum, @ControlNum, @UserID, @Classification, @RequestDate, @ResultDate, @Department, @Resident, @BirthDate,@Encoder ) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ListFileNum] @Type varchar(1), @DisplayType varchar(1), @Criteria varchar(50) AS if @Type = '1' begin if @DisplayType = '0' begin select top 1000 ctnum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbCTFileNum --order by RecordID desc end if @DisplayType = '1' begin select ctnum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbCTFileNum order by ctNum end if @DisplayType = '2' begin select ctnum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbCTFileNum where ctNum like @Criteria + '%' order by ctNum end if @DisplayType = '3' begin select ctnum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbCTFileNum where LastName like @Criteria + '%' order by Patient end end if @Type = '2' begin if @DisplayType = '0' begin select top 1000 xraynum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbXRFileNum -- order by RecordID desc end if @DisplayType = '1' begin select xraynum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbXRFileNum order by XRayNum end if @DisplayType = '2' begin select xraynum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbXRFileNum where XRayNum like @Criteria + '%' order by XRayNum end if @DisplayType = '3' begin select xraynum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbXRFileNum where Lastname like @Criteria + '%' order by Patient end end if @Type = '3' begin if @DisplayType = '0' begin select top 1000 UltraNum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbULFileNum --order by RecordID desc end if @DisplayType = '1' begin select UltraNum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbULFileNum order by UltraNum end if @DisplayType = '2' begin select UltraNum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbULFileNum where UltraNum like @Criteria + '%' order by UltraNum end if @DisplayType = '3' begin select UltraNum [File #], hospnum [Hosp. #], LastName +', ' + Firstname + ' ' + MiddleName [Patient] from tbULFileNum where LastName like @Criteria + '%' order by Patient end end /* if @Type = '1' begin if @DisplayType = '0' begin select top 1000 ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum order by RecordID desc end if @DisplayType = '1' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum order by ctNum end if @DisplayType = '2' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum where ctNum like @Criteria + '%' order by ctNum end if @DisplayType = '3' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum where Patient like @Criteria + '%' order by Patient end end if @Type = '2' begin if @DisplayType = '0' begin select top 1000 xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum order by RecordID desc end if @DisplayType = '1' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum order by XRayNum end if @DisplayType = '2' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum where XRayNum like @Criteria + '%' order by XRayNum end if @DisplayType = '3' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum where Patient like @Criteria + '%' order by Patient end end if @Type = '3' begin if @DisplayType = '0' begin select top 1000 UltraNum [File #], hospnum [Hosp. #], patient [Patient] from tbUltraNum order by RecordID desc end if @DisplayType = '1' begin select UltraNum [File #], hospnum [Hosp. #], patient [Patient] from tbUltraNum order by UltraNum end if @DisplayType = '2' begin select UltraNum [File #], hospnum [Hosp. #], patient [Patient] from tbUltraNum where UltraNum like @Criteria + '%' order by UltraNum end if @DisplayType = '3' begin select UltraNum [File #], hospnum [Hosp. #], patient [Patient] from tbUltraNum where Patient like @Criteria + '%' order by Patient end end*/ /*if @Type = '1' begin if @DisplayType = '0' begin select top 1000 ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum order by RecordID desc end if @DisplayType = '1' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum order by ctNum end if @DisplayType = '2' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum where ctNum like @Criteria + '%' order by ctNum end if @DisplayType = '3' begin select ctnum [File #], hospnum [Hosp. #], patient [Patient] from tbctnum where Patient like @Criteria + '%' order by Patient end end if @Type = '2' begin if @DisplayType = '0' begin select top 1000 xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum order by RecordID desc end if @DisplayType = '1' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum order by XRayNum end if @DisplayType = '2' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum where XRayNum like @Criteria + '%' order by XRayNum end if @DisplayType = '3' begin select xraynum [File #], hospnum [Hosp. #], patient [Patient] from tbxrnum where Patient like @Criteria + '%' order by Patient end end*/ GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ListFileNumEntry] @Type varchar(1), @DisplayType varchar(1), @Criteria varchar(50) AS If @Type = '1' --CTSCAN Begin If @DisplayType = '0' Begin select B.HospNum, isnull(A.CTNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbCTFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.EntryID desc End If @DisplayType = '1' Begin select B.HospNum, isnull(A.CTNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbCTFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.CTNum End If @DisplayType = '2' Begin select B.HospNum, isnull(A.CTNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbCTFileNum A on A.HospNum = B.HospNum where A.CTNum like @Criteria + '%' order by A.CTNum End If @DisplayType = '3' Begin select B.HospNum, isnull(A.CTNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbCTFileNum A on A.HospNum = B.HospNum where B.LastName like @Criteria + '%' order by B.LastName, B.FirstName, B.MiddleName End End If @Type = '2' --XRAY Begin If @DisplayType = '0' Begin select B.HospNum, isnull(A.XRayNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbXRFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.EntryID desc End If @DisplayType = '1' Begin select B.HospNum, isnull(A.XrayNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbXRFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.XrayNum End If @DisplayType = '2' Begin select B.HospNum, isnull(A.XRayNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbXRFileNum A on A.HospNum = B.HospNum where A.XrayNum like @Criteria + '%' order by A.XrayNum End If @DisplayType = '3' Begin select B.HospNum, isnull(A.XRayNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbXRFileNum A on A.HospNum = B.HospNum where B.LastName like @Criteria + '%' order by B.LastName, B.FirstName, B.MiddleName End End If @Type = '3' --ULTRASOUND Begin If @DisplayType = '0' Begin select B.HospNum, isnull(A.UltraNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbULFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.EntryID desc End If @DisplayType = '1' Begin select B.HospNum, isnull(A.UltraNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbULFileNum A on A.HospNum = B.HospNum where B.lastname is not null order by A.UltraNum End If @DisplayType = '2' Begin select B.HospNum, isnull(A.UltraNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbULFileNum A on A.HospNum = B.HospNum where A.UltraNum like @Criteria + '%' order by A.UltraNum End If @DisplayType = '3' Begin select B.HospNum, isnull(A.UltraNum,'') as FileNum, isnull(B.LastName + ', ' + B.FirstName + ' ' + B.MiddleName,'') as Patient, isnull(A.ControlNum,'') as ControlNum, isnull(A.EntryId,'') as EntryId, isnull(B.LastName,'') as LastName, isnull(B.FirstName,'') as FirstName, isnull(B.MiddleName,'') as MiddleName from Patient_Data..tbMaster B left outer join tbULFileNum A on A.HospNum = B.HospNum where B.LastName like @Criteria + '%' order by B.LastName, B.FirstName, B.MiddleName End End GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ValidateFileNum] @Type varchar(1), @FileNumber varchar(10), @HospNum varchar(10) AS If @Type = '1' --CT-SCAN Begin Select * from tbCTFileNum as FileNum where CtNum = @FileNumber and HospNum <> @HospNum End If @Type = '2' --X-RAY Begin Select * from tbXrFileNum where XRayNum = @FileNumber and HospNum <> @HospNum End If @Type = '3' --ULTRASOUND Begin Select * from tbULFileNum where UltraNum = @FileNumber and HospNum <> @HospNum End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_FileNumUpdate] @RevenueID varchar(2), @FileNum varchar(10), @HospNum varchar(8), @LastName varchar(50), @FirstName varchar(50), @MiddleName varchar(50) AS if @RevenueID = 'XR' begin if exists(select * from tbXRFileNum where XRayNum = @FileNum) begin update tbXRFileNum set HospNum = case when isnumeric(HospNum) = 1 then HospNum else @HospNum end, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where XrayNum = @FileNum end else begin insert into tbXRFileNum (XrayNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set XRayNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set XRayNum = @FileNum where HospNum = @HospNum end end if @RevenueID = 'CT' begin if exists(select * from tbCTFileNum where CTNum = @FileNum) begin update tbCTFileNum set HospNum = case when isnumeric(HospNum) = 1 then HospNum else @HospNum end, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where CTNum = @FileNum end else begin insert into tbCTFileNum (CTNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set CTNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set CTNum = @FileNum where HospNum = @HospNum end end if @RevenueID = 'US' begin if exists(select * from tbULFileNum where UltraNum = @FileNum) begin update tbULFileNum set HospNum = case when isnumeric(HospNum) = 1 then HospNum else @HospNum end, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where UltraNum = @FileNum end else begin insert into tbULFileNum (UltraNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set UltraNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set UltraNum = @FileNum where HospNum = @HospNum end end If @RevenueID = 'MM' --RevenueID for mammogram begin if exists(select * from tbMammoFileNum where MammoNum = @FileNum) begin update tbMammoFileNum set HospNum = case when isnumeric(HospNum) = 1 then HospNum else @HospNum end, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where MammoNum = @FileNum end else begin insert into tbMammoFileNum (MammoNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set MammoNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set MammoNum = @FileNum where HospNum = @HospNum end end If @RevenueID = 'XM' --Dummy RevenueID for mammogram begin if exists(select * from tbMammoFileNum where MammoNum = @FileNum) begin update tbMammoFileNum set HospNum = case when isnumeric(HospNum) = 1 then HospNum else @HospNum end, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where MammoNum = @FileNum end else begin insert into tbMammoFileNum (MammoNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set MammoNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set MammoNum = @FileNum where HospNum = @HospNum end end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_FileNumEntryUpdate] @RevenueID varchar(2), @FileNum varchar(10), @HospNum varchar(8), @LastName varchar(50), @FirstName varchar(50), @MiddleName varchar(50) AS if @RevenueID = 'XR' begin if exists(select * from tbXRFileNum where HospNum = @HospNum) begin update tbXRFileNum Set XRayNum = @FileNum, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where HospNum = @HospNum end else begin insert into tbXRFileNum (XrayNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set XRayNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set XRayNum = @FileNum where HospNum = @HospNum end end if @RevenueID = 'CT' begin if exists(select * from tbCTFileNum where HospNum = @HospNum) begin update tbCTFileNum Set CTNum = @FileNum, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where HospNum = @HospNum end else begin insert into tbCTFileNum (CTNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set CTNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set CTNum = @FileNum where HospNum = @HospNum end end if @RevenueID = 'US' begin if exists(select * from tbULFileNum where HospNum = @HospNum) begin update tbULFileNum Set UltraNum = @FileNum, LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, ControlNum = ControlNum + 1 where HospNum = @HospNum end else begin insert into tbULFileNum (UltraNum, HospNum, LastName, FirstName, MiddleName, ControlNum) values (@FileNum, @HospNum, @LastName, @FirstName, @MiddleName, 1) end if isnumeric(@HospNum) = 1 begin update PATIENT_DATA..tbMaster set UltraNum = @FileNum where HospNum = @HospNum end else begin update PATIENT_DATA..tbCashPatient set UltraNum = @FileNum where HospNum = @HospNum end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchFileNum] @RevenueID varchar(10), @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin if @RevenueID = 'XR' begin select XRayNum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from RADIOLOGY..tbXRFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end if @RevenueID = 'CT' begin select CTNum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from RADIOLOGY..tbCTFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end if @RevenueID = 'US' begin select UltraNum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from RADIOLOGY..tbULFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end if @RevenueID = 'MI' begin select MRINum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from RADIOLOGY..tbMRIFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end if @RevenueID = 'WC' begin select OBUltraNum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from tbOBULFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end end if @SearchType = '1' begin if @RevenueID = 'XR' begin select XRayNum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from RADIOLOGY..tbXRFileNum where XRayNum = @SearchCriteria end if @RevenueID = 'CT' begin select CTNum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from RADIOLOGY..tbCTFileNum where CTNum = @SearchCriteria end if @RevenueID = 'US' begin select UltraNum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from RADIOLOGY..tbULFileNum where UltraNum = @SearchCriteria end if @RevenueID = 'MI' begin select MRINum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from RADIOLOGY..tbMRIFileNum where MRINum = @SearchCriteria end if @RevenueID = 'WC' begin select OBUltraNum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from tbOBULFileNum where OBUltraNum = @SearchCriteria end end if @SearchType = '2' begin if @RevenueID = 'XR' begin select XRayNum [FileNum] from RADIOLOGY..tbXRFileNum where HospNum = @SearchCriteria end if @RevenueID = 'CT' begin select CTNum [FileNum] from RADIOLOGY..tbCTFileNum where HospNum = @SearchCriteria end if @RevenueID = 'US' begin select UltraNum [FileNum] from RADIOLOGY..tbULFileNum where HospNum = @SearchCriteria end if @RevenueID = 'MI' begin select MRINum [FileNum] from RADIOLOGY..tbMRIFileNum where HospNum = @SearchCriteria end if @RevenueID = 'WC' begin select OBUltraNum [FileNum] from tbOBULFileNum where HospNum = @SearchCriteria end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO --Altered by Jetty P. Omo --to View MRI Interpretations --Oct 06,2007 --added Heart Station CREATE PROCEDURE [dbo].[spRadio_SearchInterpretation] @RevenueID varchar(2), @SectionID varchar(3), @SearchType varchar(1), @SearchCriteria varchar(50) /* set @RevenueID = 'XR' set @SectionID = 'MI' set @SearchType = '0' set @SearchCriteria ='' */ AS if @SearchType = '0' begin if @RevenueID = 'CT' begin select Description, Code from tbCTInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' order by Description end if @RevenueID = 'XR' IF @SectionID = 'MI' begin select Description, Code from tbMRIInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' order by Description end else begin select Description, Code from tbXRInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' order by Description end if @RevenueID = 'US' begin select Description, Code from tbULInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' order by Description end if @RevenueID = 'HS' if isnumeric(@SearchCriteria) = 0 begin select Description, Code from build_file..tbcoHSNormalValues where Description like @SearchCriteria + '%' order by Description end else begin select Description, Code from build_file..tbcoHSNormalValues where Code = @SearchCriteria order by Description end end if @SearchType = '1' begin if @RevenueID = 'CT' begin select i.Code, i.Description, i.SectionID, i.Interpretation, i.ExamCode, i.[Normal], s.SectionName from tbCTInterpretation i left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'CT') and (s.SectionID = i.SectionID) where i.Code = @SearchCriteria end if @RevenueID = 'XR' IF @SectionID = 'MI' begin select i.Code, i.Description, i.SectionID, i.Interpretation, i.ExamCode, i.[Normal], s.SectionName from tbMRIInterpretation i left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'XR') and (s.SectionID = i.SectionID) where i.Code = @SearchCriteria end else begin select i.Code, i.Description, i.SectionID, i.Interpretation, i.ExamCode, i.[Normal], s.SectionName from tbXRInterpretation i left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'XR') and (s.SectionID = i.SectionID) where i.Code = @SearchCriteria end if @RevenueID = 'US' begin select i.Code, i.Description, i.SectionID, i.Interpretation, i.ExamCode, i.[Normal], s.SectionName from tbULInterpretation i left join BUILD_FILE..tbCoSection s on (s.RevenueID = 'US') and (s.SectionID = i.SectionID) where i.Code = @SearchCriteria end if @RevenueID = 'HS' begin select i.Code, i.Description,'' as SectionID, i.Interpretation,'' as examcode,'' as [normal], '' as SectionName from build_file..tbcoHSNormalValues i where i.Code = @SearchCriteria end end if @SearchType = '2' begin if @RevenueID = 'CT' begin select Count(*) [RecCount] from tbCTInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' end if @RevenueID = 'XR' begin select Count(*) [RecCount] from tbXRInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' end if @RevenueID = 'US' begin select Count(*) [RecCount] from tbULInterpretation where isnull(SectionID, '') in (@SectionID, '') and Description like @SearchCriteria + '%' end if @RevenueID = 'HS' begin select Count(*) [RecCount] from build_file..tbcoHSNormalValues where Description like @SearchCriteria + '%' end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_AddInterpret] @Type AS varChar(1), @Code AS varChar(8), @Description AS Text, @Interpretation AS Text AS IF @Type = '1' /* CT-Scan Department */ BEGIN INSERT INTO tbCTInterpretation ( code, description, interpretation ) VALUES ( @Code, @Description, @Interpretation ) END IF @Type = '2' /* Xray Department */ BEGIN INSERT INTO tbXRInterpretation ( code, description, interpretation ) VALUES ( @Code, @Description, @Interpretation ) END IF @Type = '3' /* Ultrasound Department */ BEGIN INSERT INTO tbULInterpretation ( code, description, interpretation ) VALUES ( @Code, @Description, @Interpretation ) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* GONZALO 030509 */ CREATE PROCEDURE [dbo].[spRadio_DeleteInterpret] @RevenueID varchar(2), @Code varchar(10) AS if @RevenueID = 'XR' begin delete from radiology..tbxrinterpretation where code = @Code end if @RevenueID = 'CT' begin delete from radiology..tbctinterpretation where code = @Code end if @RevenueID = 'US' begin delete from radiology..tbulinterpretation where code = @Code end if @RevenueID = 'MI' begin delete from radiology..tbmriinterpretation where code = @Code end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ExamList] @Type AS varChar(1) AS IF @Type = '1' /* CT-Scan Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbCTInterpretation ORDER BY CONVERT(VARCHAR(50), Description) END IF @Type = '2' /* Xray Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbXRInterpretation ORDER BY CONVERT(VARCHAR(50), Description) END IF @Type = '3' /* Ultrasound Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbULInterpretation ORDER BY CONVERT(VARCHAR(50), Description) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ExamListSearch] @Type AS varChar(1), @Description AS varChar(30) AS IF @Type = '1' /* CT-Scan Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbCTInterpretation WHERE Description LIKE @Description + '%' ORDER BY code END IF @Type = '2' /* Xray Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbXRInterpretation WHERE Description LIKE @Description + '%' ORDER BY code END IF @Type = '3' /* Ultrasound Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbULInterpretation WHERE Description LIKE @Description + '%' ORDER BY code END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ViewInterpretation] @RevenueID varchar(2), @Criteria varchar(50), @ItemID varchar(8) = Null AS /* declare @RevenueID varchar(2), @Criteria varchar(50), @ItemID varchar(8) set @RevenueID = 'xr' set @Criteria = '' set @ItemID = Null */ if @ItemID is null begin if @RevenueID = 'XR' begin select Code, Description from tbXRInterpretation where Description like @Criteria + '%' --and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'CT' begin select Code, Description from tbCTInterpretation where Description like @Criteria + '%' --and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'US' begin select Code, Description from tbULInterpretation where Description like @Criteria + '%' --and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'MI' begin select Code, Description from tbMRIInterpretation where Description like @Criteria + '%' --and isnull(ExamCode,'') like @ItemID Order by Description end end if @ItemID is not null begin if @RevenueID = 'XR' begin select Code, Description from tbXRInterpretation where Description like @Criteria + '%' and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'CT' begin select Code, Description from tbCTInterpretation where Description like @Criteria + '%' and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'US' begin select Code, Description from tbULInterpretation where Description like @Criteria + '%' and isnull(ExamCode,'') like @ItemID Order by Description end if @RevenueID = 'MI' begin select Code, Description from tbMRIInterpretation where Description like @Criteria + '%' and isnull(ExamCode,'') like @ItemID Order by Description end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CheckExistInterpretation] @RevenueID as varchar(2), @Code as varchar(4) AS /*set @Code = '55' set @RevenueID = 'US' */ If @RevenueID = 'CT' Begin Select * From tbXRInterpretation Where Code = @Code End Else If @RevenueID = 'US' Begin Select * From tbULInterpretation Where Code = @Code End Else If @RevenueID = 'CT' Begin Select * From tbCTInterpretation Where Code = @Code End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Altered By : Jetty P. Omo Details : Added the result code for Diagnostic Film Status whether complicated or uncomplicated Date : June 28,2008 */ CREATE PROCEDURE [dbo].[spRadio_UpdateInterpret] @RevenueID varchar(2), @Code varchar(10), @Description varchar(50), @SectionID varchar(3), @Interpretation text, @Normal varchar(1) = '1', @Equipment varchar(100) = '', @ExamCode varchar(5) = Null, @RadCode varchar(8) = Null, @Gender varchar(3) = '' AS if @RevenueID = 'XR' begin update tbXRInterpretation set Description = @Description, SectionID = @SectionID, Interpretation = @Interpretation, [Normal] = @Normal, Equipment = @Equipment, ExamCode = @ExamCode, RadCode = @RadCode, Gender = @Gender where Code = @Code end if @RevenueID = 'CT' begin update tbCTInterpretation set Description = @Description, SectionID = @SectionID, Interpretation = @Interpretation, [Normal] = @Normal, Equipment = @Equipment, ExamCode = @ExamCode, RadCode = @RadCode, Gender = @Gender where Code = @Code end if @RevenueID = 'US' begin update tbULInterpretation set Description = @Description, SectionID = @SectionID, Interpretation = @Interpretation, [Normal] = @Normal, Equipment = @Equipment, ExamCode = @ExamCode, RadCode = @RadCode, Gender = @Gender where Code = @Code end if @RevenueID = 'MI' begin update tbMRIInterpretation set Code = @code, Description = @Description, SectionID = @SectionID, Interpretation = @Interpretation, [Normal] = @Normal where Code = @Code end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_Interpretation] @Type AS varChar(1), @Code AS varChar(8), @Interpretation AS Text AS IF @Type = '1' /* CT-Scan Department */ BEGIN UPDATE tbCTInterpretation SET Interpretation = @Interpretation WHERE Code = @Code END IF @Type = '2' /* Xray Department */ BEGIN UPDATE tbXRInterpretation SET Interpretation = @Interpretation WHERE Code = @Code END IF @Type = '3' /* Ultrasound Department */ BEGIN UPDATE tbULInterpretation SET Interpretation = @Interpretation WHERE Code = @Code END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_InsertInterpret] @RevenueID varchar(2), @Code varchar(10), @Description varchar(50), @SectionID varchar(3), @Interpretation text, @Normal varchar(1) = '1', @ExamCode varchar(5) = Null, @RadCode varchar(8) = Null, @Gender varchar(3) = '' AS declare @NewCode as varchar(10) if @RevenueID = 'XR' begin select @NewCode = max(cast(Code as int)) + 1 from tbXRInterpretation where isnumeric(Code) = 1 insert into tbXRInterpretation (Code, Description, SectionID, Interpretation,[Normal],RadCode,Gender,ExamCode) values (@NewCode, @Description, @SectionID, @Interpretation,@Normal,@RadCode,@Gender,@ExamCode) end if @RevenueID = 'CT' begin select @NewCode = max(cast(Code as int)) + 1 from tbCTInterpretation where isnumeric(Code) = 1 insert into tbCTInterpretation (Code, Description, SectionID, Interpretation,[Normal],RadCode,Gender,ExamCode) values (@NewCode, @Description, @SectionID, @Interpretation,@Normal,@RadCode,@Gender,@ExamCode) end if @RevenueID = 'US' begin select @NewCode = max(cast(Code as int)) + 1 from tbULInterpretation where isnumeric(Code) = 1 insert into tbULInterpretation (Code, Description, SectionID, Interpretation,[Normal],RadCode,Gender,ExamCode) values (@NewCode, @Description, @SectionID, @Interpretation,@Normal,@RadCode,@Gender,@ExamCode) end if @RevenueID = 'MI' begin select @NewCode = max(cast(Code as int)) + 1 from tbMRIInterpretation where isnumeric(Code) = 1 insert into tbMRIInterpretation (Code, Description, SectionID, Interpretation,[Normal],ExamCode) values (@NewCode, @Description, @SectionID, @Interpretation,@Normal,@ExamCode) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadExam] @Type AS varChar(1), @Code AS varChar(5) AS IF @Type = '1' /* CT-Scan Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbCTInterpretation WHERE Code = @Code END IF @Type = '2' /* Xray Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbXRInterpretation WHERE Code = @Code END IF @Type = '3' /* Ultrasound Listing */ BEGIN SELECT Code, Description, Interpretation FROM tbULInterpretation WHERE Code = @Code END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* ADDED By: Christian Gonzalo DATE: February 03, 2009 DETAILS: ~View by Radiologist's code (or with SearchCriteria) ~Search all interpretations ALTERED By: Gonzalo Date: 12062010 Detail/s: Replaced RadioID in tbXRInterpretation [and the likes] with RadCode. */ CREATE PROCEDURE [dbo].[spRadio_ViewInterpretationByRadio] --@Type varchar(1), @RevenueID varchar(2), @SearchCriteria varchar(50) = '', @ExamID varchar(5) = '', @RadioID varchar(50) = '', --not necessarily employeeid, put a search box in the search interpret window. @Gender varchar(10) = '' AS if @RevenueID = 'XR' Begin Select Description, Code From tbXRInterpretation Where Description like '%' + @SearchCriteria + '%' --and IsNull(ExamCode,'') = @ExamID -- and IsNull(RadCode,'') in (@RadioID,'') and IsNull(Gender,'N') in ('N', @Gender) End if @RevenueID = 'CT' Begin Select Description, Code From tbCTInterpretation Where Description like @SearchCriteria + '%' --and IsNull(ExamCode,'') = @ExamID and IsNull(RadCode,'') in (@RadioID,'') and IsNull(Gender,'N') in ('N', @Gender) End if @RevenueID = 'US' Begin Select Description, Code From tbULInterpretation Where Description like @SearchCriteria + '%' --and IsNull(ExamCode,'') = @ExamID and IsNull(RadCode,'') in (@RadioID,'') and IsNull(Gender,'N') in ('N', @Gender) End ----*****Search by Radiologist's ID (loading of rad's interpretations) --if @Type = '0' --Begin -- if @RevenueID = 'XR' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbXRInterpretation -- Order by Description -- End -- else -- Begin -- select Description, Code, password.* -- from tbXRInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where password.employeeid like @EmployeeID --or RadCode is null -- Order by Description -- End -- end -- -- if @RevenueID = 'CT' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbCTInterpretation -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbCTInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where password.employeeid like @EmployeeID --or RadCode is null -- Order by Description -- End ---- select Code, Description ---- from tbCTInterpretation ---- where Description like @Criteria + '%' ---- Order by Description -- end -- -- if @RevenueID = 'US' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbULInterpretation -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbULInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where password.employeeid like @EmployeeID --or RadCode is null -- Order by Description -- End ---- select Code, Description ---- from tbULInterpretation ---- where Description like @Criteria + '%' ---- Order by Description -- end -- -- if @RevenueID = 'MI' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbMRIInterpretation -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbMRIInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where password.employeeid like @EmployeeID --or RadCode is null -- Order by Description -- End ---- select Code, Description ---- from tbMRIInterpretation ---- where Description like @Criteria + '%' ---- Order by Description -- end -- -- --End -- ----******Search by Criteria (by first letters typed...) --if @Type = '1' --Begin -- if @RevenueID = 'XR' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbXRInterpretation -- where Description like @SearchCriteria + '%' and (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbXRInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where (password.employeeid like @EmployeeID) -- --or RadCode is null) -- and Description like @SearchCriteria + '%' -- Order by Description -- End -- end -- -- if @RevenueID = 'CT' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbCTInterpretation -- where Description like @SearchCriteria + '%' and (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbCTInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where (password.employeeid like @EmployeeID) -- --or RadCode is null) -- and Description like @SearchCriteria + '%' -- Order by Description -- End -- end -- -- if @RevenueID = 'US' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbULInterpretation -- where Description like @SearchCriteria + '%' and (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbULInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where (password.employeeid like @EmployeeID) -- --or RadCode is null) -- and Description like @SearchCriteria + '%' -- Order by Description -- End -- end -- -- if @RevenueID = 'MI' -- begin -- if @EmployeeID = '' -- Begin -- select Description, Code -- from tbMRIInterpretation -- where Description like @SearchCriteria + '%' and (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- End -- else -- Begin -- select Description, Code -- from tbMRIInterpretation interpret -- left outer join build_file..tbcodoctor doctor -- on interpret.RadCode = doctor.doctorid -- left outer join password..tbpasswordmain password -- on password.employeeid = doctor.doctorid -- where (password.employeeid like @EmployeeID) -- --or RadCode is null) -- and Description like @SearchCriteria + '%' -- Order by Description -- End -- end --End -- ----******Search all interpretations.. --if @Type = '2' --Begin -- if @RevenueID = 'XR' -- begin -- select Description, Code -- from tbXRInterpretation -- where (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- end -- -- if @RevenueID = 'CT' -- begin -- select Description, Code -- from tbCTInterpretation -- where (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- end -- -- if @RevenueID = 'US' -- begin -- select Description, Code -- from tbULInterpretation -- where (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- end -- -- if @RevenueID = 'MI' -- begin -- select Description, Code -- from tbMRIInterpretation -- where (Gender = @Gender or IsNull(Gender,'') = '') -- Order by Description -- end --End -- -- -- -- -- -- -- GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ReportResultInterpretation] @RevenueID as varchar(2), @Code as varchar(10) AS If @RevenueID = 'XR' Begin Select * From Radiology..tbXRInterpretation where code = @Code; End; Else If @RevenueID = 'US' Begin Select * From Radiology..tbULInterpretation where code = @Code; End; Else If @RevenueID = 'CT' Begin Select * From Radiology..tbCTInterpretation where code = @Code; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Mammo_SaveInterpretation] @Code as varchar(5), @description as varchar(200), @interpretation as text AS BEGIN SET NOCOUNT ON; if exists(select * from radiology..tbmminterpretation where code=@code) begin update radiology..tbmminterpretation set description=@description, interpretation=@interpretation where code=@code end else begin insert into radiology..tbmminterpretation (description,interpretation) values (@description,@interpretation) end END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Mammo_GetInterpretation] @strCriteria as varchar(200) AS BEGIN SET NOCOUNT ON; select isnull(Code,'') as [Code], isnull(Description,'') as [Description], isnull(interpretation,'') as [interpretation] from radiology..tbMMinterpretation where description like '%'+ @strCriteria +'%' order by Description asc END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LastFileNum] @RevenueID varchar(2) AS IF @RevenueID = 'CT' BEGIN select ctnum [FileNum] from tbctnum where recordid = (select max(isnull(recordid, 0)) from tbctnum) END; IF @RevenueID = 'XR' BEGIN select xraynum [FileNum] from tbxrnum where recordid = (select max(isnull(recordid, 0)) from tbxrnum) END; IF @RevenueID = 'US' BEGIN select ultranum [FileNum] from tbUltraNum where recordid = (select max(isnull(recordid, 0)) from tbUltraNum) END; /* if @RevenueID = 'XR' begin if exists(select * from tbXRFileNum) begin select top 1 XRayNum [FileNum] from tbxrnum where recordid = (select max(isnull(recordid, 0)) from tbxrnum) end else begin select '' [FileNum] end end if @RevenueID = 'CT' begin if exists(select * from tbCTFileNum) begin select top 1 CTNum [FileNum] from tbctnum where recordid = (select max(isnull(recordid, 0)) from tbctnum) end else begin select '' [FileNum] end end if @RevenueID = 'US' begin if exists(select * from tbULFileNum) begin select top 1 UltraNum [FileNum] from tbultranum where recordid = (select max(isnull(recordid, 0)) from tbultranum) end else begin select '' [FileNum] end end */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_UpdateFileNum] @Type varchar(1), @HospNum varchar(8), @FileNum varchar(10), @PatientName varchar(50) AS declare @NewRecordID float IF @Type = '1' BEGIN IF EXISTS ( SELECT * FROM tbCTNum WHERE CTNum = @FileNum ) BEGIN UPDATE tbCTNum SET HospNum = @HospNum, Patient = @PatientName WHERE CTNum = @FileNum END ELSE BEGIN SELECT @NewRecordID = MAX(ISNULL(RecordID, 0)) FROM tbXRNum INSERT INTO tbCTNum (CTNum, HospNum, Patient, RecordID) VALUES (@FileNum, @HospNum, @PatientName, @NewRecordID) END END IF @Type = '2' BEGIN IF EXISTS ( SELECT * FROM tbXRNum WHERE XRayNum = @FileNum ) BEGIN UPDATE tbXRNum SET HospNum = @HospNum, Patient = @PatientName WHERE XRayNum = @FileNum END ELSE BEGIN SELECT @NewRecordID = MAX(ISNULL(RecordID, 0)) FROM tbXRNum INSERT INTO tbXRNum (XRayNum, HospNum, Patient, RecordID) VALUES (@FileNum, @HospNum, @PatientName, @NewRecordID) END END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveInCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @TypeDescription as varchar(30), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @RoomID AS varChar(8), @UserID AS varChar(10), @RefNum AS varChar(10), @Film1 as int, @Film2 as int, @Film3 as int, @Film4 as int, @Film5 as int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(50), @DoctorName as varchar(50) = null, @ChargeRevenueID as varchar(2) = '', @Portable as varchar(1) = '', @RevenueID AS varChar(2), @NurseRequestNum as varchar(10) = null, @Media varchar(150) = '', @Creatinine varchar(100) = '', @EKG varchar(50) = '', @Oximeter varchar(50) = '', @Particular varchar(200) = '', @Relevant varchar (200) = '', @Precaution varchar(200) = '' AS DECLARE @RequestNum AS varChar(8), -- @RevenueID AS varChar(2), @DrCr AS varChar(1), @UltrarevenueID as Varchar(2) If @Revenueid= 'US' begin set @Ultrarevenueid = 'US' end else begin set @ultrarevenueid='WC' end If @DoctorID <> '0' Begin set @DoctorName = null End; IF @Type = '1' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 -- SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, TransDate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRemarks, DoctorName, revenueID, Portable, NurseRequest, Media,Creatinine, EKG, Oximeter,Particular, Relevant,Precaution) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRemarks, @DoctorName, 'CT', @Portable, @NurseRequestNum, @Media,@Creatinine, @EKG, @Oximeter, @Particular, @Relevant,@Precaution ) END IF @Type = '2' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 -- SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], Film1, Film2, Film3, Film4, Film5, Film6, Film7, NurseRemarks, DoctorName, RevenueID, Portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @Film1, @Film2, @Film3, @Film4, @Film5, @Film6, @Film7, @NurseRemarks, @DoctorName, 'XR', @Portable, @NurseRequestNum) END IF @Type = '3' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 -- SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRemarks, DoctorName, RevenueID, portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRemarks, @DoctorName,@Ultrarevenueid, @Portable, @NurseRequestNum) END INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, RequestNum, DoctorName) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@UserID, @DoctorID, @RequestNum, @DoctorName ) IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(RecordStatus,'') = '') -- RequestNum = @NurseRequestNum) BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE(), ReferenceNum = @RefNum WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(RecordStatus,'') = '' --RequestNum = @NurseRequestNum END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate,Remarks) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @TypeDescription, @Quantity, @Amount, 'X', @RefNum, @UserID, GETDATE(),'Manualy Posted') END IF EXISTS(SELECT * FROM station..tbNurseCommunicationFile WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(RecordStatus,'') = '') -- RequestNum = @NurseRequestNum) BEGIN UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X', ReferenceNum = @RefNum WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and isnull(RecordStatus,'') = '' --RequestNum = @NurseRequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveOutCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @NurseRemarks as varchar(50), @DoctorName as varchar(50) = null, @Portable as varchar(1), @RevenueID AS varChar(2) = '', @NurseRequestNum as varchar(10) = null, @Media varchar(150) = '', @Creatinine varchar(100) = '', @EKG varchar(50) = '', @Oximeter varchar(50) = '', @Particular varchar(200) = '', @Relevant varchar (200) = '', @Precaution varchar(200) = '' AS DECLARE @RequestNum AS varChar(8), @DrCr AS varChar(1), @ItemDesc as varchar(50) If @DoctorID <> '0' Begin set @DoctorName = null; End IF @Type = '1' /* CT-Scan */ BEGIN Set @ItemDesc = (Select CTExam from Build_File..tbCoCTExam where CtExamID = @ItemID) SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 --SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, NurseRemarks, DoctorName, RevenueID, Portable, NurseRequest, Media,Creatinine, EKG, Oximeter,Particular, Relevant,Precaution) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @NurseRemarks, @DoctorName, @RevenueID, @Portable, @NurseRequestNum, @Media,@Creatinine, @EKG, @Oximeter, @Particular, @Relevant,@Precaution ) END IF @Type = '2' /* XRay */ BEGIN if @RevenueID = 'XR' Begin Set @ItemDesc = (Select XrayExam from Build_File..tbCoXrayExam where XrayExamID = @ItemID) End; else Begin Set @ItemDesc = (Select OtherRevenue from Build_File..tbCoOtherRevenue where OtherRevenueID = @ItemID) End; SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 -- SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, SWFIN, [By], Film1, Film2, Film3, Film4, Film5, Film6, Film7, RoomID, Refnum, Quantity, NurseRemarks, DoctorName, RevenueID, Portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, 'X', @UserID, @Film1, @Film2, @Film3, @Film4, @Film5, @Film6, @Film7, @RoomID, @RefNum, @Quantity, @NurseRemarks, @DoctorName, @RevenueID, @Portable, @NurseRequestNum) END IF @Type = '3' /* Ultrasound */ BEGIN Set @ItemDesc = (Select UltraExam from Build_File..tbCoUltraExam where UltraExamID = @ItemID) SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 -- SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, NurseRemarks, DoctorName, RevenueID, Portable, NurseRequest) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @Refnum, @Quantity, @NurseRemarks, @DoctorName, @RevenueID, @Portable, @NurseRequestNum) END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity, RequestNum, DoctorName) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, @RoomID, @UserID, @DoctorID, @Quantity, @RequestNum, @DoctorName) end IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and RequestNum = @NurseRequestNum) BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE(), ReferenceNum = @RefNum WHERE IDNum = @IDNum --HospNum = @HospNum AND AND RevenueID = @RevenueID AND ItemID = @ItemID and RequestNum= @NurseRequestNum END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate, RequestNum, Remarks) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @ItemDesc, @Quantity, @Amount, 'X', @RefNum, @UserID, GETDATE(), @NurseRequestNum, 'Manually Posted') END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveRequestOnly] @DepartmentID varchar(2), @HospNum varchar(8), @IDNum varchar(10), @Code varchar(8), @RequestDoctorCode varchar(8), @Quantity float, @Amount float, @RoomID varchar(8), @RefNum varchar(10), @RevenueID varchar(2), @UserID varchar(10), @Media varchar(150) = '', @Creatinine varchar(100) = '', @EKG varchar(50) = '', @Oximeter varchar(50) = '', @Particular varchar(200) = '', @Relevant varchar (200) = '', @Precaution varchar(200) = '' AS declare @RequestNum varchar(10) IF @DepartmentID = 'CT' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 INSERT INTO tbCTRequest (RequestNum, TransDate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By], Media,Creatinine, EKG, Oximeter, Particular, Relevant,Precaution) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID, @Media,@Creatinine, @EKG, @Oximeter, @Particular, @Relevant,@Precaution) END IF @DepartmentID = 'XR' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By]) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID) END IF @DepartmentID = 'US' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By]) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID) END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --Modified by BSL for the saving of Discount CREATE PROCEDURE [dbo].[spRadio_SaveOutCharge1] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @DoctorID AS varChar(4), @UserID AS varChar(8), @RefNum AS varChar(10), @RoomID as varchar(10), @Film1 AS Int, @Film2 AS Int, @Film3 AS Int, @Film4 AS Int, @Film5 AS Int, @Film6 as int, @Film7 as int, @DiscountType as varchar(2), @NetAmount as float AS DECLARE @RequestNum AS varChar(8), @RevenueID AS varChar(2), @DrCr AS varChar(1) IF @Type = '1' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @DiscountType, @NetAmount) END IF @Type = '2' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, SWFIN, [By], Film1, Film2, Film3, Film4, Film5, Film6, Film7, RoomID, Refnum, Quantity, DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, 'X', @UserID, @Film1, @Film2, @Film3, @Film4, @Film5, @Film6, @Film7, @RoomID, @RefNum, @Quantity, @DiscountType, @NetAmount) END IF @Type = '3' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, SWFIN, [By], Amount, RoomID, RefNum, Quantity, DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'X', @UserID, @Amount, @RoomID, @Refnum, @Quantity, @DiscountType, @NetAmount) END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity, RequestNum, DiscountType, NetAmount) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, @RoomID, @UserID, @DoctorID, @Quantity, @RequestNum, @DiscountType, @NetAmount) end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @TypeDescription as varchar(30), @Quantity as float, @cAmount as varchar(50), @HospNum AS varChar(8), @DoctorID AS varChar(4), @RoomID AS varChar(8), @UserID AS varChar(10), @RefNum AS varChar(10), @NurseRequestNum as varchar(10), @Film1 as int, @Film2 as int, @Film3 as int, @Film4 as int, @Film5 as int, @Film6 as int, @Film7 as int AS DECLARE @RequestNum AS varChar(8), @RevenueID AS varChar(2), @DrCr AS varChar(1), @Amount as float, @NurseID varchar(10), @NurseRequestDate datetime set @NurseID = null set @NurseRequestDate = null if len(@NurseRequestNum) > 0 begin select @NurseID = UserID, @NurseRequestDate = RequestDate from STATION..tbNurseCommunicationFile where RequestNum = @NurseRequestNum end set @Amount = cast(cast(@cAmount as money) as float) IF @Type = '1' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, TransDate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRequest, NurseID, NurseRequestDate ) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRequestNum, @NurseID, @NurseRequestDate) END IF @Type = '2' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], Film1, Film2, Film3, Film4, Film5, Film6, Film7, NurseRequest, NurseID, NurseRequestDate) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @Film1, @Film2, @Film3, @Film4, @Film5, @Film6, @Film7, @NurseRequestNum, @NurseID, @NurseRequestDate) END IF @Type = '3' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, SWFIN, [By], NurseRequest, NurseID, NurseRequestDate ) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, @Amount, @RoomID, @RefNum, @Quantity, 'X', @UserID, @NurseRequestNum, @NurseID, @NurseRequestDate ) END IF ISNUMERIC(@IDNum) = 1 BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, RequestNum) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@UserID, @DoctorID, @RequestNum ) END IF ISNUMERIC(@IDNum) = 0 BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, RequestNum) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@UserID, @DoctorID, @RequestNum ) END UPDATE station..tbNurseCommunicationFile SET RecordStatus = 'X', ReferenceNum = @RefNum WHERE RequestNum = @NurseRequestNum UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @UserID, ProcessDate = GETDATE() WHERE RequestNum = @NurseRequestNum GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --Modified by BSL March 13, 2003 for the saving of discounts CREATE PROCEDURE [dbo].[spRadio_SaveRequestOnly1] @DepartmentID varchar(2), @HospNum varchar(8), @IDNum varchar(10), @Code varchar(8), @RequestDoctorCode varchar(8), @Quantity float, @Amount float, @RoomID varchar(8), @RefNum varchar(10), @RevenueID varchar(2), @UserID varchar(10), @DiscountType as varchar(2), @NetAmount as float AS declare @RequestNum varchar(10) IF @DepartmentID = 'CT' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 INSERT INTO tbCTRequest (RequestNum, TransDate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By], DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID, @DiscountType, @NetAmount) END IF @DepartmentID = 'XR' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By], DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID, @DiscountType, @NetAmount) END IF @DepartmentID = 'US' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, RequestDoctorCode, Amount, RoomID, RefNum, Quantity, RevenueID, [By], DiscountType, NetAmount) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @UserID, @DiscountType, @NetAmount) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InpatientCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @Code AS varChar(4), @TypeDescription AS varChar(30), @RequestDoctorCode AS varChar(4), @Lastname AS varChar(30), @Firstname AS varChar(30), @Middlename AS varChar(30), @RoomID AS varChar(8), @ProcessBy AS varChar(8), @RefNum AS varChar(10), @Film8 AS Int, @Film10 AS Int, @Film11 AS Int, @Film14 AS Int, @Film17 AS Int AS DECLARE @RequestNum AS varChar(8), @RevenueID AS varChar(2), @DrCr AS varChar(1) IF @Type = '1' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, TransDate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, RoomID, RefNum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity) END IF @Type = '2' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, RoomID, Film8, Film10, Film11, Film14, Film17, RefNum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, @RoomID, @Film8, @Film10, @Film11, @Film14, @Film17,@RefNum, @Quantity) END IF @Type = '3' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8),RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, RoomID, RefNum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, @RoomID, @RefNum, @Quantity) END INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Quantity, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Quantity, @Amount, @DrCr, @RevenueID, @RoomID,@ProcessBy, @RequestDoctorCode ) IF EXISTS(SELECT * FROM station..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID) BEGIN UPDATE station..tbNurseLogBook SET RecordStatus = 'X', ProcessBy = @ProcessBy, ProcessDate = GETDATE() WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID END ELSE BEGIN INSERT INTO station..tbNurseLogBook (HospNum, IDNum, PatientType, RevenueID, RequestDate, ItemID, Description, Quantity, Amount, RecordStatus, ReferenceNum, ProcessBy, ProcessDate) VALUES (@HospNum, @IDNum, 'I', @RevenueID, GETDATE(), @ItemID, @TypeDescription, @Quantity, @Amount, 'X', @RefNum, @ProcessBy, GETDATE()) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_OutpatientCharge] @Type AS varChar(1), @IDNum AS varChar(10), @ItemID AS varChar(8), @Quantity as float, @Amount AS Float, @HospNum AS varChar(8), @Code AS varChar(4), @TypeDescription AS varChar(30), @RequestDoctorCode AS varChar(4), @Lastname AS varChar(30), @Firstname AS varChar(30), @Middlename AS varChar(30), @ProcessBy AS varChar(8), @RefNum AS varChar(10), @Film8 AS Int, @Film10 AS Int, @Film11 AS Int, @Film14 AS Int, @Film17 AS Int AS DECLARE @RequestNum AS varChar(8), @RevenueID AS varChar(2), @DrCr AS varChar(1) IF @Type = '1' /* CT-Scan */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbCTOpd UPDATE tbCTOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'CT' SET @DrCr = 'D' INSERT INTO tbCTRequest (RequestNum, Transdate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, RoomID, RefNum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, 'OPD', @RefNum, @Quantity) END IF @Type = '2' /* XRay */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbXROpd UPDATE tbXROpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'XR' SET @DrCr = 'D' INSERT INTO tbXRRequest (RequestNum, Transdate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, Film8, Film10, Film11, Film14, Film17, RoomID, Refnum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, @Film8, @Film10, @Film11, @Film14, @Film17,'OPD', @RefNum, @Quantity) END IF @Type = '3' /* Ultrasound */ BEGIN SELECT @RequestNum = RTRIM(Convert(varChar(8), RequestNum)) FROM tbULOpd UPDATE tbULOpd SET RequestNum = RequestNum + 1 SET @RevenueID = 'US' SET @DrCr = 'D' INSERT INTO tbULRequest (RequestNum, Transdate, HospNum, IDNum, Code, TypeDescription, RequestDoctorCode, Amount, RoomID, RefNum, Quantity) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @Code, @TypeDescription, @RequestDoctorCode, @Amount, 'OPD', @Refnum, @Quantity) END IF LEFT(@RefNum,2) <> 'OR' begin INSERT INTO billing..tbBillOPDailyOut (HospNum, Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, Quantity) VALUES (@Hospnum, @Refnum, @IDNum, Getdate(), @ItemID, @Amount, @DrCr, @RevenueID, 'OPD', @ProcessBy, @RequestDoctorCode, @Quantity) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_OutCancellation2] @Type AS varChar(1), @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10), @RevenueID AS varChar(2) AS --DECLARE @RevenueID AS varChar(2) DECLARE @RoomID as varchar(10) DECLARE @Quantity as float DECLARE @RequestDocID as varchar(10) IF @Type = '1' BEGIN /* Search for the Existing RefNum */ --SET @RevenueID = 'CT' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbCTRequest WHERE RequestNum = @RequestNum /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END IF @Type = '2' BEGIN /* Search for existing RefNum*/ --SET @RevenueID = 'XR' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbXRRequest WHERE RequestNum = @RequestNum /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END IF @Type = '3' BEGIN /* Search for existing RefNum */ -- SET @RevenueID = 'US' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbULRequest WHERE RequestNum = @RequestNum /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_OutCancellation] @Type AS varChar(1), @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserId As varChar(4) AS DECLARE @RevenueID AS varChar(2), @Transdate AS DateTime, @Quantity AS Integer IF @Type = '1' BEGIN /* Search for the Existing RefNum */ SET @RevenueID = 'CT' /* SELECT @TransDate = TransDate, @Quantity = Quantity FROM tbBillOPDailyOut WHERE RefNum = @RefNum AND RevenueID = @RevenueID AND ItemID = @ItemID */ /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID) END IF @Type = '2' BEGIN /* Search for existing RefNum*/ SET @RevenueID = 'XR' /* SELECT @TransDate = TransDate, @Quantity = Quantity FROM tbBillOPDailyOut WHERE RefNum = @RefNum AND RevenueID = @RevenueID AND ItemID = @ItemID */ /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID) END IF @Type = '3' BEGIN /* Search for existing RefNum */ SET @RevenueID = 'US' SELECT @TransDate = TransDate, @Quantity = Quantity FROM billing..tbBillOPDailyOut WHERE RefNum = @RefNum AND RevenueID = @RevenueID AND ItemID = @ItemID /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID) END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_PrintRequestListing] @RevenueID varchar(2), @SearchStr varchar(50) AS IF @RevenueID = 'XR' BEGIN SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.XRayExam, cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbXRRequest x LEFT JOIN PATIENT_DATA..tbMaster m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoXRayExam e on x.Code = e.XrayExamID WHERE RevenueID = 'XR' AND SWFIN in ('X','Y') AND ISNUMERIC(x.HospNum) = 1 AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) UNION ALL SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.XRayExam [Exam], cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbXRRequest x LEFT JOIN PATIENT_DATA..tbCashPatient m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoXRayExam e on x.Code = e.XrayExamID WHERE RevenueID = 'XR' AND SWFIN in ('X','Y') AND LEFT(x.HospNum, 1) = 'T' AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) ORDER BY LastName, FirstName, MiddleName, TransDate desc END IF @RevenueID = 'US' BEGIN SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.UltraExam, cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbULRequest x LEFT JOIN PATIENT_DATA..tbMaster m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoUltraExam e on x.Code = e.UltraExamID WHERE RevenueID = 'US' AND SWFIN in ('X','Y') AND ISNUMERIC(x.HospNum) = 1 AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) UNION ALL SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.UltraExam [Exam], cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbULRequest x LEFT JOIN PATIENT_DATA..tbCashPatient m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoUltraExam e on x.Code = e.UltraExamID WHERE RevenueID = 'US' AND SWFIN in ('X','Y') AND LEFT(x.HospNum, 1) = 'T' AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) ORDER BY LastName, FirstName, MiddleName, TransDate desc END IF @RevenueID = 'CT' BEGIN SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.CTExam, cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbCTRequest x LEFT JOIN PATIENT_DATA..tbMaster m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoCTExam e on x.Code = e.CTExamID WHERE RevenueID = 'CT' AND SWFIN in ('X','Y') AND ISNUMERIC(x.HospNum) = 1 AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) UNION ALL SELECT RefNum, x.HospNum, m.LastName, m.FirstName, m.MiddleName, Code, e.CTExam [Exam], cast(CONVERT(VARCHAR(10), x.TransDate, 101) as datetime) [TransDate] FROM tbXRRequest x LEFT JOIN PATIENT_DATA..tbCashPatient m ON x.HospNum = m.HospNum LEFT JOIN BUILD_FILE..tbCoCTExam e on x.Code = e.CTExamID WHERE RevenueID = 'CT' AND SWFIN in ('X','Y') AND LEFT(x.HospNum, 1) = 'T' AND ((m.LastName like @SearchStr + '%') OR (x.RefNum = @SearchStr)) ORDER BY LastName, FirstName, MiddleName, TransDate desc END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_PrintConsultation] @RequestNum varchar(10) AS declare @RevenueID varchar(2) declare @ItemID varchar(10) declare @IDNum varchar(10) declare @HospNum varchar(8) declare @RoomID varchar(10) declare @TransDate datetime declare @PreviousExam varchar(50) declare @PreviousDate datetime declare @Exam varchar(50) declare @FileNum varchar(10) declare @LastName varchar(50) declare @FirstName varchar(50) declare @MiddleName varchar(50) declare @Age varchar(5) declare @Sex varchar(6) declare @BirthDate datetime declare @HouseStreet varchar(50) declare @Barangay varchar(50) declare @TownProvince varchar(100) declare @TelNum varchar(20) declare @Diagnosis varchar(255) declare @PatientClass varchar(1) declare @AcceptDate datetime declare @DoctorID varchar(10) declare @DoctorName varchar(50) declare @NurseID varchar(10) declare @NurseName varchar(50) declare @EncoderID varchar(10) declare @EncoderName varchar(50) declare @NurseRequestDate datetime declare @Remarks varchar(50) -- added March06,2003 3:18PM /BSL select @RevenueID = RevenueID, @IDNum = IDNum, @TransDate = n.RequestDate, @AcceptDate = NULL, @Exam = NULL, @DoctorID = n.DoctorID, @DoctorName = 'DR. ' + d.LastName + ', ' + d.FirstName, @NurseID = n.UserID, @EncoderID = NULL, @NurseRequestDate = RequestDate, @ItemID = ItemID, @Remarks = Remarks from STATION..tbNurseCommunicationFile n left join BUILD_FILE..tbCoDoctor d on n.DoctorID = d.DoctorID where n.RequestNum = @RequestNum SET @PatientClass = '' IF ISNUMERIC(@IDNum) = 1 BEGIN select @HospNum = p.HospNum, @RoomID = p.RoomID, @PatientClass = isnull(p2.PatientClass, '') from PATIENT_DATA..tbPatient p left join PATIENT_DATA..tbPatient2 p2 on p.IDNum = p2.IDNum where p.IDNum = @IDNum END IF ISNUMERIC(@IDNum) = 0 BEGIN select @HospNum = HospNum, @RoomID = (Select Case isnull((select ErNum from Patient_Data..tbOutPatient where IdNum = @IdNum ),'') when '' then 'OPD' Else 'ER' end as [RoomID]), --BSL March 20, 2003 @PatientClass = LEFT(isnull(PatientType, ''), 1) from PATIENT_DATA..tbOutpatient where IDNum = @IDNum END IF ISNUMERIC(@HospNum) = 1 BEGIN select @FileNum = case when @RevenueID = 'XR' then XRayNum when @RevenueID = 'US' then UltraNum when @RevenueID = 'CT' then CTNum end, @LastName = LastName, @FirstName = FirstName, @MiddleName = MiddleName, @Age = Age, @Sex = Sex, @BirthDate = BirthDate, @HouseStreet = UPPER(HouseStreet), @Barangay = UPPER(Barangay), @TownProvince = UPPER(Town) + ', ' + UPPER(Province), @TelNum = TelNum from PATIENT_DATA..tbMaster m left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum END IF ISNUMERIC(@HospNum) = 0 BEGIN select @FileNum = case when @RevenueID = 'XR' then XRayNum when @RevenueID = 'US' then UltraNum when @RevenueID = 'CT' then CTNum end, @LastName = LastName, @FirstName = FirstName, @MiddleName = MiddleName, @Age = Age, @Sex = Sex, @BirthDate = BirthDate, @HouseStreet = UPPER(HouseStreet), @Barangay = UPPER(Barangay), @TownProvince = UPPER(Town) + ', ' + UPPER(Province), @TelNum = '' from PATIENT_DATA..tbcashPatient m left join BUILD_FILE..tbCoAddress a on m.ZipCode = a.ZipCode where HospNum = @HospNum END set @Diagnosis = '' IF ISNUMERIC(@IDNum) = 1 BEGIN select @Diagnosis = REPLACE(REPLACE(CAST(AdmDiagnosis AS VARCHAR(255)), CHAR(13), ''), CHAR(10), ' ') from PATIENT_DATA..tbPatientHistory where IDNum = @IDNum END IF @RevenueID = 'XR' BEGIN select @Exam = XRayExam from BUILD_FILE..tbCoXrayExam where XrayExamID = @ItemID; select top 1 @PreviousExam = e.XRayExam, @PreviousDate = convert(varchar(10), x.TransDate, 101) from tbxrrequest x left join BUILD_FILE..tbCoXRayExam e on x.Code = e.XRayExamID where HospNum = @HospNum and RevenueID = 'XR' and SWFIN not in ('C','R') and x.TransDate < @TransDate order by x.TransDate desc if left(@IdNum,1) = 'T' begin select @EncoderID = (Select A.userID From BILLING..tbCashAssessment A left outer join RADIOLOGY..tbXrrequest B on A.OrNumber = B.RefNum Where B.RequestNum = @RequestNum) end; END IF @RevenueID = 'US' BEGIN select @Exam = UltraExam from BUILD_FILE..tbCoUltraExam where UltraExamID = @ItemID; select top 1 @PreviousExam = e.UltraExam, @PreviousDate = convert(varchar(10), x.TransDate, 101) from tbULRequest x left join BUILD_FILE..tbCoUltraExam e on x.Code = e.UltraExamID where HospNum = @HospNum and RevenueID = 'US' and SWFIN not in ('C','R') and x.TransDate < @TransDate order by x.TransDate desc if left(@IdNum,1) = 'T' begin select @EncoderID = (Select A.userID From BILLING..tbCashAssessment A left outer join RADIOLOGY..tbULrequest B on A.OrNumber = B.RefNum Where B.RequestNum = @RequestNum) end; END IF @RevenueID = 'CT' BEGIN select @Exam = CTExam from BUILD_FILE..tbCoCTExam where CTExamID = @ItemID; select top 1 @PreviousExam = e.CTExam, @PreviousDate = convert(varchar(10), x.TransDate, 101) from tbCTRequest x left join BUILD_FILE..tbCoCTExam e on x.Code = e.CTExamID where HospNum = @HospNum and RevenueID = 'CT' and SWFIN not in ('C','R') and x.TransDate < @TransDate order by x.TransDate desc if left(@IdNum,1) = 'T' begin select @EncoderID = (Select A.userID From BILLING..tbCashAssessment A left outer join RADIOLOGY..tbCTrequest B on A.OrNumber = B.RefNum Where B.RequestNum = @RequestNum) end; END if @BirthDate is not null begin SET @Age = RADIOLOGY.dbo.fn_ComputeAge(@BirthDate, @TransDate) end if @Sex = 'M' SET @Sex = 'MALE' if @Sex = 'F' SET @Sex = 'FEMALE' if @DoctorID <> '0' begin SELECT @DoctorName = 'DR. ' + LastName + ', ' + FirstName FROM BUILD_FILE..tbCoDoctor WHERE DoctorID = @DoctorID end SELECT TOP 1 @NurseName = LastName + ', ' + FirstName + ' ' + MiddleName FROM PASSWORD..tbPasswordMaster WHERE EmployeeID = @NurseID SELECT TOP 1 @EncoderName = LastName + ', ' + FirstName + ' ' + MiddleName FROM PASSWORD..tbPasswordMaster WHERE EmployeeID = @EncoderID select @IDNum [IDNum], @FileNum [FileNum], @PatientClass [PatientClass], @LastName [LastName], @FirstName [FirstName], @MiddleName [MiddleName], @HospNum [HospNum], @Age [Age], @Sex [Sex], @BirthDate [BirthDate], @HouseStreet [HouseStreet], @Barangay [Barangay], @TownProvince [TownProvince], @TelNum [TelNum], @RoomID [RoomID], @Exam [Exam], @Diagnosis [Diagnosis], @PreviousExam [PreviousExam], @PreviousDate [PreviousDate], @AcceptDate [TransDate], @DoctorName [DoctorName], ISNULL(@NurseName, '') [NurseName], @NurseRequestDate [NurseRequestDate], @EncoderName [EncoderName], @RevenueID [RevenueID], @Remarks [Remarks] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReportGrossIncome1] @StartDate AS VARCHAR(10), @EndDate AS VARCHAR(10) AS SELECT A.Amount, CASE LEFT(ISNULL(D.PatientClass, ''),1) WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' ELSE isnull(R.RoomClass,'SERVICE') END AS Classification, 'XR' AS RevenueID, 'IN-PATIENT' AS PatientType /*CASE ISNULL(E.RoomClassID,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType*/ FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'XR' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'XR' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'XR' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'XR' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'XR' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) IN ('OR', 'CC') AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(D.PatientClass, ''),1) WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' ELSE isnull(R.RoomClass,'SERVICE') END AS Classification, 'CT' AS RevenueID, 'IN-PATIENT' AS PatientType /*CASE ISNULL(R.RoomClass,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType*/ FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'CT' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'CT' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'CT' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'CT' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'CT' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) IN ('OR', 'CC') AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(D.PatientClass, ''),1) WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' ELSE isnull(R.RoomClass,'SERVICE') END AS Classification, 'US' AS RevenueID, 'IN-PATIENT' AS PatientType /*CASE ISNULL(R.RoomClass,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType*/ FROM Radiology..tbULRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'US' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'US' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbULRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'US' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE LEFT(ISNULL(C.PatientType, ''),1) WHEN '' THEN 'PAY' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END AS Classification, 'US' AS RevenueID, 'OUT-PATIENT' AS PatientType FROM Radiology..tbUlRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'US' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) IN ('OR', 'CC') AND SwFin = 'Y' /* SELECT A.Amount, CASE ISNULL(D.RoomClass,'') WHEN '' THEN CASE ISNULL(B.PatientClass, '') WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END ELSE D.RoomClass END AS Classification, 'XR' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType FROM Radiology..tbXRRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE ISNULL(D.RoomClass,'') WHEN '' THEN CASE ISNULL(B.PatientClass, '') WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END ELSE D.RoomClass END AS Classification, 'CT' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType FROM Radiology..tbCTRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Amount, CASE ISNULL(D.RoomClass,'') WHEN '' THEN CASE ISNULL(B.PatientClass, '') WHEN '' THEN 'SERVICE' WHEN 'S' THEN 'SERVICE' WHEN 'P' THEN 'PAY' END ELSE D.RoomClass END AS Classification, 'US' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OUT-PATIENT' WHEN 'OPD' THEN 'OUT-PATIENT' ELSE 'IN-PATIENT' END AS PatientType FROM Radiology..tbUlRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' ORDER BY RevenueID, PatientType, Classification */ GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReportGrossIncome] @StartDate As varchar(10), @EndDate As varchar(10) AS select revenueid,iclass As IClass,sum(iproc) AS ITotalProcedures,sum(iamount) AS ITotalAmount, oclass AS OClass,sum(oproc) AS OTotalProcedures,sum(oamount) AS OTotalAmount from ( select revenueid, case isnull(patienttype,'') when 'I' then roomclass when '' then '' END AS IClass, case isnull(patienttype,'') when 'I' then 1 when '' then 0 END AS IProc, case isnull(patienttype,'') when 'I' then amount when '' then 0 END AS IAmount, case isnull(patienttype,'') when 'O' then roomclass when '' then '' END AS OClass, case isnull(patienttype,'') when 'O' then 1 when '' then 0 END AS OProc, case isnull(patienttype,'') when 'O' then amount when '' then 0 END AS OAmount from ( SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'XR' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbXRRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'UL' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbULRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'CT' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbCTRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' ) as Summary ) as Summary Group by revenueid,iclass,oclass; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveResultLog] @Rank int, @RevenueID varchar (3), @RequestNum varchar (10), @RefNum varchar (10), @HospNum varchar (10), @ChargeDate datetime, @Remarks varchar (200), @Status varchar (1), @UserID varchar (15), @VerifyID varchar (15), @resultDate datetime , @ItemID as varchar(5) AS if exists (Select RequestNum From tbradioResultLog Where Requestnum = @RequestNum) begin update tbradioResultLog set Rank = @Rank, RevenueID = @RevenueID, RequestNum = @RequestNum, RefNum = @RefNum, HospNum = @HospNum, Transdate = getdate(), ChargeDate = @ChargeDate, Remarks = @Remarks, Status = @Status, UserID = @UserID, VerifyID = @VerifyID, ResultDate = @resultDate, ItemID = @ItemID where Requestnum = @RequestNum; end; else begin insert into tbradioResultLog ( Rank, RevenueID, RequestNum, RefNum, HospNum, Transdate, ChargeDate, resultDate, Remarks, Status, UserID, VerifyID, ItemID) values (@Rank, @RevenueID, @RequestNum, @RefNum, @HospNum, getdate(), @ChargeDate, @resultDate, @Remarks, @Status, @UserID, @VerifyID, @ItemID); end; if @RevenueID = 'XR' begin Update tbXrRequest set LogBook = 'L' Where RequestNum = @RequestNum; end; if @RevenueID = 'US' begin Update tbULRequest set LogBook = 'L' Where RequestNum = @RequestNum; end; if @RevenueID = 'CT' begin Update tbCTRequest set LogBook = 'L' Where RequestNum = @RequestNum; end; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ProfessionalServices] @StartDate as varchar(10), @EndDate as varchar(10) AS SELECT count(A.IdNum) AS IPDCount, 0 as OPDCount, 'XR' as RevenueID FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'XR' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT 0 as IPDCount, Count(A.IdNum) as OPDCount, 'XR' AS RevenueID FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'XR' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' UNION ALL SELECT count(A.IdNum) AS IPDCount, 0 as OPDCount, 'CT' as RevenueID FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'CT' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT 0 as IPDCount, Count(A.IdNum) as OPDCount, 'CT' AS RevenueID FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'CT' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' UNION ALL SELECT count(A.IdNum) AS IPDCount, 0 as OPDCount, 'US' as RevenueID FROM Radiology..tbULRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass R ON E.RoomClassID = R.RoomClassID WHERE A.RevenueID = 'US' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 UNION ALL SELECT 0 as IPDCount, Count(A.IdNum) as OPDCount, 'US' AS RevenueID FROM Radiology..tbULRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'US' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetExamsPerFolder] @RequestNum as varchar(10), @RevenueID AS VARCHAR(2) AS declare @HospNum as varchar(10) if @RevenueID = 'XR' begin Set @HospNum = (select top 1 HospNum FROM tbXrRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbXrRequest WHERE HOSPNUM = @HospNum; end; if @RevenueID = 'US' begin Set @HospNum = (select top 1 HospNum FROM tbULRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbULRequest WHERE HOSPNUM = @HospNum; end; if @RevenueID = 'CT' begin Set @HospNum = (select top 1 HospNum FROM tbCTRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbCTRequest WHERE HOSPNUM = @HospNum; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReportMonthlyIncome1] @StartDate AS VARCHAR(10), @EndDate AS VARCHAR(10), @RevenueID AS VARCHAR(3) AS IF @RevenueID = 'XR' BEGIN SELECT A.Code, MAX(B.XRayExam) AS [XRayExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], 0 AS [InService], 0 AS [InServiceAmount], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN 1 ELSE 0 END) AS [OPDService], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN A.Amount ELSE 0 END) AS OPDServiceAmount, SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 1 WHEN 'P' THEN 1 ELSE 0 END) AS [OPDPay], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN A.Amount WHEN 'P' THEN A.Amount ELSE 0 END) AS [OPDPayAmount] FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'XR' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' GROUP BY A.Code UNION ALL SELECT A.Code, MAX(B.XRayExam) AS [XRayExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], 0 AS [InService], 0 AS [InServiceAmount], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN 1 ELSE 0 END) AS [OPDService], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN A.Amount ELSE 0 END) AS OPDServiceAmount, SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 1 WHEN 'P' THEN 1 ELSE 0 END) AS [OPDPay], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN A.Amount WHEN 'P' THEN A.Amount ELSE 0 END) AS [OPDPayAmount] FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'XR' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) IN ('OR', 'CC') AND SwFin = 'Y' GROUP BY A.Code UNION ALL -- InPatient SELECT A.Code, MAX(B.XRayExam) AS [XRayExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN 1 ELSE 0 END) AS [InPay], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN A.Amount ELSE 0 END) AS [InPayAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN 1 ELSE 0 END) AS [InPrivate], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN A.Amount ELSE 0 END) AS [InPrivateAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN 1 ELSE 0 END) AS [InSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN A.Amount ELSE 0 END) AS [InSuiteAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 1 ELSE 0 END) AS [InService], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID WHERE A.RevenueID = 'XR' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 AND LEFT(ISNULL(D.PatientClass, ''), 1) <> 'S' --AND SwFin = 'Y' GROUP BY A.Code UNION ALL SELECT A.Code, MAX(B.XRayExam) AS [XRayExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN 1 ELSE 0 END) AS [InService], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbXRRequest A LEFT OUTER JOIN Build_File..tbCoXRayExam B ON A.Code = B.XRayExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON A.RoomID = E.RoomID WHERE A.RevenueID = 'XR' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 AND LEFT(ISNULL(D.PatientClass, ''), 1) = 'S' --AND SwFin = 'Y' GROUP BY A.Code ORDER BY A.Code END IF @RevenueID = 'CT' BEGIN -- OutPatient SELECT A.Code, MAX(B.CTExam) AS [CTExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], 0 AS [InService], 0 AS [InServiceAmount], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN 1 ELSE 0 END) AS [OPDService], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN A.Amount ELSE 0 END) AS OPDServiceAmount, SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 1 WHEN 'P' THEN 1 ELSE 0 END) AS [OPDPay], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN A.Amount WHEN 'P' THEN A.Amount ELSE 0 END) AS [OPDPayAmount] FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'CT' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' GROUP BY A.Code UNION -- InPatient SELECT A.Code, MAX(B.CTExam) AS [CTExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN 1 ELSE 0 END) AS [InPay], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN A.Amount ELSE 0 END) AS [InPayAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN 1 ELSE 0 END) AS [InPrivate], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN A.Amount ELSE 0 END) AS [InPrivateAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN 1 ELSE 0 END) AS [InSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN A.Amount ELSE 0 END) AS [InSuiteAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 1 ELSE 0 END) AS [InService], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON C.RoomID = E.RoomID WHERE A.RevenueID = 'CT' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 AND LEFT(ISNULL(D.PatientClass, ''), 1) <> 'S' --AND SwFin = 'Y' GROUP BY A.Code UNION ALL -- InPatient SELECT A.Code, MAX(B.CTExam) AS [CTExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN 1 ELSE 0 END) AS [InService], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbCTRequest A LEFT OUTER JOIN Build_File..tbCoCTExam B ON A.Code = B.CTExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON C.RoomID = E.RoomID WHERE A.RevenueID = 'CT' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 AND LEFT(ISNULL(D.PatientClass, ''), 1) = 'S' --AND SwFin = 'Y' GROUP BY A.Code ORDER BY A.Code END; IF @RevenueID = 'US' BEGIN -- OutPatient SELECT A.Code, MAX(B.UltraExam) AS [UltraExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], 0 AS [InService], 0 AS [InServiceAmount], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN 1 ELSE 0 END) AS [OPDService], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 0 WHEN 'S' THEN A.Amount ELSE 0 END) AS OPDServiceAmount, SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN 1 WHEN 'P' THEN 1 ELSE 0 END) AS [OPDPay], SUM(CASE LEFT(ISNULL(C.PatientType, ''), 1) WHEN '' THEN A.Amount WHEN 'P' THEN A.Amount ELSE 0 END) AS [OPDPayAmount] FROM Radiology..tbUlRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbOutPatient C ON A.IDNum = C.IDNum WHERE A.RevenueID = 'US' AND A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND LEFT(A.RefNum, 2) NOT IN ('OR', 'CC') AND ISNUMERIC(A.IDNum) = 0 AND SwFin = 'Y' GROUP BY A.Code UNION -- InPatient SELECT A.Code, MAX(B.UltraExam) AS [UltraExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN 1 ELSE 0 END) AS [InPay], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'B' THEN 1 ELSE 0 END) AS [InAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN A.Amount ELSE 0 END) AS [InPrivate], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'C' THEN A.Amount ELSE 0 END) AS [InPrivateAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN 1 ELSE 0 END) AS [InSuite], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 0 WHEN 'D' THEN A.Amount ELSE 0 END) AS [InSuiteAmount], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN 1 ELSE 0 END) AS [InService], SUM(CASE ISNULL(E.RoomClassID, '') WHEN '' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbUlRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON C.RoomID = E.RoomID WHERE A.RevenueID = 'US' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 --AND SwFin = 'Y' GROUP BY A.Code UNION ALL -- InPatient SELECT A.Code, MAX(B.UltraExam) AS [UltraExam], MAX(B.RateA) AS [RateOPD], MAX(B.RateB) AS [RateInPatientPay], MAX(B.RateC) AS [RateInPatientPrivate], MAX(B.RateD) AS [RateSuite], 0 AS [InPay], 0 AS [InPayAmount], 0 AS [InPrivate], 0 AS [InPrivateAmount], 0 AS [InSuite], 0 AS [InSuiteAmount], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN 1 ELSE 0 END) AS [InService], SUM(CASE LEFT(ISNULL(D.PatientClass, ''), 1) WHEN 'S' THEN A.Amount ELSE 0 END) AS [InServiceAmount], 0 AS [OPDService], 0 AS [OPSServiceAmount], 0 AS [OPDPay], 0 AS [ODPPayAmount] FROM Radiology..tbUlRequest A LEFT OUTER JOIN Build_File..tbCoUltraExam B ON A.Code = B.UltraExamID LEFT OUTER JOIN Patient_Data..tbPatient C ON A.IDNum = C.IDNum LEFT OUTER JOIN Patient_Data..tbPatient2 D On A.IDNum = D.IDNum LEFT OUTER JOIN Build_File..tbCoRoom E ON C.RoomID = E.RoomID WHERE A.RevenueID = 'US' AND C.BillingDate BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' AND ISNUMERIC(A.IDNum) = 1 --AND SwFin = 'Y' GROUP BY A.Code ORDER BY A.Code END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --BJSL CREATE PROCEDURE [dbo].[spRadio_RequestingDoctorReport] @RevenueID as varchar(5), @StartDate as varchar(10), @EndDate as varchar(10) AS if @RevenueID = 'XR' select isnull(A.RequestDocID,'A') [requestdoctorcode], CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], sum (case left(isnull(P.PatientClass,''),1) when 'S' then 1 else 0 end) as [IPDService], sum (case left(isnull(P.PatientClass,''),1) when 'P' then 1 else 0 end) as [IPDPay], 0 [OPDService], 0 [OPDPay] from Billing..tbBillDailyBill A left outer join Patient_Data..tbPatient2 P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'XR' group by requestDocID union all select ISNULL(A.RequestDocID,'A') [requestdoctorcode] , CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], sum (case left(isnull(P.PatientType,''),1) when 'S' then 1 else 0 end) as [OPDService], sum (case left(isnull(P.PatientType,''),1) when 'P' then 1 else 0 end) as [OPDPay] from Billing..tbBillOPDailyOut A left outer join Patient_Data..tbOutPatient P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'XR' group by requestDocID union all select ISNULL(A.requestdoctorcode,'') [requestdoctorcode], CASE isnull(A.Requestdoctorcode,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], 0 [OPDService], sum(1) as [OPDPay] from tbXRRequest A left outer join Build_File..tbCoDoctor B on A.requestdoctorcode = B.DoctorID where isnumeric(A.IdNum) = 0 and left(A.RefNum,2) in ('OR','CC') and TransDate between @StartDate and @EndDate + ' 23:59:59.99' group by requestdoctorcode order by [DoctorName]; else if @RevenueID = 'CT' select ISNULL(A.RequestDocID,'') [requestdoctorcode], CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], sum (case left(isnull(P.PatientClass,''),1) when 'S' then 1 else 0 end) as [IPDService], sum (case left(isnull(P.PatientClass,''),1) when 'P' then 1 else 0 end) as [IPDPay], 0 [OPDService], 0 [OPDPay] from Billing..tbBillDailyBill A left outer join Patient_Data..tbPatient2 P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'CT' group by requestDocID union all select ISNULL(A.RequestDocID,'') [requestdoctorcode] , CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], sum (case left(isnull(P.PatientType,''),1) when 'S' then 1 else 0 end) as [OPDService], sum (case left(isnull(P.PatientType,''),1) when 'P' then 1 else 0 end) as [OPDPay] from Billing..tbBillOPDailyOut A left outer join Patient_Data..tbOutPatient P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'CT' group by requestDocID union all select ISNULL(A.requestdoctorcode,'') [requestdoctorcode], CASE isnull(A.RequestDoctorcode,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], 0 [OPDService], sum(1) as [OPDPay] from tbCTRequest A left outer join Build_File..tbCoDoctor B on A.requestdoctorcode = B.DoctorID where isnumeric(A.IdNum) = 0 and left(A.RefNum,2) in ('OR','CC') and TransDate between @StartDate and @EndDate + ' 23:59:59.99' group by requestdoctorcode order by [DoctorName]; else if @RevenueID = 'US' select ISNULL(A.RequestDocID,'') [requestdoctorcode], CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], sum (case left(isnull(P.PatientClass,''),1) when 'S' then 1 else 0 end) as [IPDService], sum (case left(isnull(P.PatientClass,''),1) when 'P' then 1 else 0 end) as [IPDPay], 0 [OPDService], 0 [OPDPay] from Billing..tbBillDailyBill A left outer join Patient_Data..tbPatient2 P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'US' group by requestDocID union all select ISNULL(A.RequestDocID,'') [requestdoctorcode] , CASE isnull(A.RequestDocID,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], sum (case left(isnull(P.PatientType,''),1) when 'S' then 1 else 0 end) as [OPDService], sum (case left(isnull(P.PatientType,''),1) when 'P' then 1 else 0 end) as [OPDPay] from Billing..tbBillOPDailyOut A left outer join Patient_Data..tbOutPatient P on A.IdNum = P.IdNum left outer join Build_File..tbCoDoctor B on A.RequestDocID = B.DoctorID where TransDate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = 'US' group by requestDocID union all select ISNULL(A.requestdoctorcode,'') [requestdoctorcode], CASE isnull(A.RequestDoctorcode,'') WHEN '' THEN ' NO REQUESTING DOCTOR' WHEN '0' THEN ' OUTSIDE DOCTOR' ELSE max(isnull(B.LastName,'')) + ', ' + max(isnull(B.FirstName,'')) + ' ' + max(isnull(B.MiddleName,'')) END AS [DoctorName], 0 [IPDService], 0 [IPDPay], 0 [OPDService], sum(1) as [OPDPay] from tbUSRequest A left outer join Build_File..tbCoDoctor B on A.requestdoctorcode = B.DoctorID where isnumeric(A.IdNum) = 0 and left(A.RefNum,2) in ('OR','CC') and TransDate between @StartDate and @EndDate + ' 23:59:59.99' group by requestdoctorcode order by [DoctorName]; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetExamsPerFolderTag] @RequestNum as varchar(10), @RevenueID AS VARCHAR(2) AS declare @HospNum as varchar(10) if @RevenueID = 'XR' begin Set @HospNum = (select top 1 HospNum FROM tbXrRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbXrRequest X WHERE HOSPNUM = @HospNum; end; if @RevenueID = 'US' begin Set @HospNum = (select top 1 HospNum FROM tbULRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbULRequest WHERE HOSPNUM = @HospNum; end; if @RevenueID = 'CT' begin Set @HospNum = (select top 1 HospNum FROM tbCTRequest WHERE RequestNum = @RequestNum); SELECT Requestnum, Code, TypeDescription, Refnum, Transdate, 'Y' AS Tag FROM tbCTRequest WHERE HOSPNUM = @HospNum; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /* altered by : Jetty P. Omo Date : 02/05/2008 */ CREATE PROCEDURE [dbo].[spRadio_IncomeReport] @RevenueID varchar(2), @StartDate varchar(10), @EndDate varchar(10) AS select s.itemid, max(case @RevenueID when 'XR' then xray.xrayexam when 'CT' then ct.ctexam when 'US' then ultra.ultraexam end) as exam, sum(case when s.type = 'I' then s.quantity else 0 end) as InQuantity, sum(case when s.type = 'I' then s.amount else 0 end) as InAmount, sum(case when s.type = 'O' then s.quantity else 0 end) as OutQuantity, sum(case when s.type = 'O' then s.amount else 0 end) as OutAmount, sum(quantity) as TotalQty, sum(amount) as TotalAmt from ( select b.refnum, b.itemid, sum( case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end /*case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end*/) quantity, sum(b.amount) amount, 'I' type from BILLING..tbbilldailybill b where transdate between @StartDate and @EndDate + ' 23:59:59.99' and revenueid = @RevenueID group by refnum, itemid having sum(amount) <> 0 union all select b.refnum, b.itemid, sum( case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end --else 0 END /*case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end*/) quantity, sum(b.amount) amount, case @RevenueID when 'XR' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(req.idnum, '')) = '' then 'O' when isnumeric(max(isnull(req.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(req.idnum, ''))) = 1 then 'I' end else 'O' end when 'CT' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(reqct.idnum, '')) = '' then 'O' when isnumeric(max(isnull(reqct.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(reqct.idnum, ''))) = 1 then 'I' end else 'O' end when 'US' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(requs.idnum, '')) = '' then 'O' when isnumeric(max(isnull(requs.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(requs.idnum, ''))) = 1 then 'I' end else 'O' end end as type from BILLING..tbbillopdailyout b left join ( select refnum, max(idnum) idnum from tbxrrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as req on b.refnum = req.refnum left join ( select refnum, max(idnum) idnum from tbctrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as reqct on b.refnum = reqct.refnum left join ( select refnum, max(idnum) idnum from tbulrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as requs on b.refnum = requs.refnum where b.transdate between @StartDate and @EndDate + ' 23:59:59.99' and b.revenueid = @RevenueID group by b.refnum, b.itemid having sum(b.amount) <> 0 ) as s left join BUILD_FILE..tbcoxrayexam xray on s.itemid = xray.xrayexamid left join BUILD_FILE..tbcoctexam ct on s.itemid = ct.ctexamid left join BUILD_FILE..tbcoultraexam ultra on s.itemid = ultra.ultraexamid /* WHERE (Case When @RevenueID = 'XR' Then Case When Not xray.XraySectionID in ('EQT', 'IXM', 'PXM', 'SOP', 'SUP') Then 1 Else 0 End When @RevenueID = 'CT' Then Case When Not ct.CTSectionID in ('SUP', 'MED', 'MEI', 'EQT') Then 1 Else 0 End Else 1 End) = 1 */ group by s.itemid GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_OPDRequestPrinting] @SearchType as varchar(1), @RevenueID as varchar(3), @SearchCriteria as varchar(100) /** set @SearchType = ''3'' set @RevenueID = ''XR'' set @SearchCriteria = ''26'' */ AS if @SearchType = '0' --Default Search BEGIN IF @RevenueID = 'XR' BEGIN select distinct A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum Left OUTER JOIN Radiology..tbxrrequest R ON R.Idnum = A.IDNum where A.RevenueID = @RevenueID and (R.SWfin <> 'C' or R.SWfin <> 'Y') order by [Patient Name] END IF @RevenueID = 'US' BEGIN select distinct A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum Left OUTER JOIN Radiology..tbULrequest R ON R.Idnum = A.idnum where A.RevenueID = @RevenueID and R.SWfin not in ('C','Y') order by [Patient Name] END IF @RevenueID = 'CT' BEGIN select distinct A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum Left OUTER JOIN Radiology..tbCTrequest R ON R.Idnum = A.idnum where A.RevenueID = @RevenueID and R.SWfin not in ('C','Y') order by [Patient Name] END END; if @SearchType = '1' -- Search by Last Name BEGIN select A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum where A.RevenueID = @RevenueID and B.LastName like @SearchCriteria + '%' END; if @SearchType = '2' -- Search by Adm. Num. BEGIN select A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum where A.RevenueID = @RevenueID and A.IdNum like @SearchCriteria + '%' END; if @SearchType = '3' -- Search by Hosp. Num. BEGIN select A.HospNum [Hosp. No.], A.IdNum [Adm. No.], B.LastName + ', ' + B.FirstName + ' ' + left(B.MiddleName,1) + '.' as [Patient Name], A.RevenueID, A.ItemID [Item Code], A.Description [Description], A.Quantity, convert(money,A.Amount) [Amount], isnull(A.Printed,'') [Printed], isnull(A.RequestNum,'') [Request Num] from PATIENT_DATA..tbOPDCommunicationfile A LEFT OUTER JOIN PATIENT_DATA..tbmaster B ON A.HospNum = B.HospNum where A.RevenueID = @RevenueID and A.HospNum like @SearchCriteria + '%' END; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Created by Jetty P. Omo --December 01, 2006 --Created to save cancellation with valid reason CREATE PROCEDURE [dbo].[spRadio_SaveRevokeCharges] @Revenueid varchar(5), @RequestNum varchar(10), @UserId varchar(10), @Reason text AS Declare @ErrNum as Int; Begin tran; Declare @ItemID varchar(10) if @RevenueID = 'XR' Begin set @ItemID =(Select code From tbXRrequest where RequestNum = @RequestNum) End else if @RevenueID = 'US' Begin set @ItemID =(Select code From tbULrequest where RequestNum = @RequestNum) End else if @RevenueID = 'CT' Begin set @ItemID =(Select code From tbCTrequest where RequestNum = @RequestNum) End Begin Insert Into Radiology..tbRadioCancelRequest(Revenueid,RequestNum, ItemID, UserID,Reason, TransDate) Values(@Revenueid,@RequestNum,@ItemID,@UserId,@Reason,getDate()); End; if @@Error <> 0 Begin Set @ErrNum = @@Error goto ErrTrap End Commit Tran; Return 0; ErrTrap: Rollback tran; Return @ErrNum; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ListFilms] @Type AS varChar(1), @RequestNum AS varChar(8), @Code AS varChar(4) AS IF @Type = '1' BEGIN SELECT Code, TypeDescription AS Description, Amount FROM tbCTRequest WHERE RequestNum = @RequestNum AND Code = @Code END IF @Type = '2' BEGIN SELECT Code, TypeDescription AS Description, Amount, Film8 AS [8X10], Film10 AS [10X12], Film11 AS [11X14], Film14 AS [14X14], Film17 AS [14X17] FROM tbXRRequest WHERE RequestNum = @RequestNum AND Code = @Code END IF @Type = '3' BEGIN SELECT Code, TypeDescription AS Description, Amount FROM tbULRequest WHERE RequestNum = @RequestNum AND Code = @Code END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_LastCharge] @IDNUm varchar(10), @RevenueID varchar(2), @ItemID varchar(10) AS declare @Today datetime set @Today = dateadd(day, -1, getdate()) if @RevenueID = 'XR' begin select top 1 TransDate from tbXRRequest where idnum = @IDNum and code = @ItemID and swfin not in ('C','R') and RevenueID = @RevenueID and TransDate > @Today order by TransDate desc end if @RevenueID = 'CT' begin select top 1 TransDate from tbCTRequest where idnum = @IDNum and code = @ItemID and swfin not in ('C','R') and RevenueID = @RevenueID and TransDate > @Today order by TransDate desc end if @RevenueID = 'US' begin select top 1 TransDate from tbULRequest where idnum = @IDNum and code = @ItemID and swfin not in ('C','R') and RevenueID = @RevenueID and TransDate > @Today order by TransDate desc end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadRequest] --declare @TYPE varchar(1), @RequestNum varchar(200) --set @Type ='2' --set @Requestnum = '21016' AS IF @TYPE = '1' BEGIN SELECT tbCTRequest.HospNum AS HospNum, tbCTRequest.RequestNum AS RequestNum, tbCTRequest.RefNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbCTRequest.Code AS Code, case isnull(tbCTRequest.revenueID, 'CT') when 'CT' then tbCoCTExam.CTExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName else I.ItemName end AS Description, tbCoCTExam.CTSectionId AS SectionId, tbCTRequest.IdNum AS IDNum, tbCTRequest.TransDate AS TransDate, tbCTRequest.Film1, tbCTRequest.Film2, tbCTRequest.Film3, tbCTRequest.Film4, tbCTRequest.Film5, tbCTRequest.Film6, tbCTRequest.Film7, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = RequestDoctorCode), 'OPD') END AS RoomID, tbCTRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate()) ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CTNum ELSE tbCashPatient.CTNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbCTRequest.Amount, tbCTRequest.DoctorName, tbCTRequest.revenueID, case when isnumeric(tbCTRequest.idnum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge FROM tbCTRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbCTRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbCTRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbCTRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbCTRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbCTRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoCTExam [tbCoCTExam] ON tbCTRequest.Code = tbCoCTExam.CTExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON tbCTRequest.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON tbCTRequest.Code = Doc.DoctorID WHERE @RequestNum = tbCTRequest.RequestNum END IF @TYPE = '2' BEGIN SELECT tbXRRequest.HospNum AS HospNum, tbXRRequest.RequestNum AS RequestNum, tbXRRequest.RefNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbXRRequest.Code AS Code, case isnull(tbXRRequest.revenueID,'XR') when 'BM' then E.OtherRevenue when 'XR' then tbCoXrayExam.XRayExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName else I.ItemName end AS Description, tbCoXrayExam.XRaySectionID AS SectionId, tbXRRequest.IdNum AS IDNum, tbXRRequest.TransDate AS TransDate, tbXRRequest.Film1, tbXRRequest.Film2, tbXRRequest.Film3, tbXRRequest.Film4, tbXRRequest.Film5, tbXRRequest.Film6, tbXRRequest.Film7, tbXRRequest.RoomID as Room, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = RequestDoctorCode), 'OPD') END AS RoomID, tbXRRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate()) ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.XRayNum ELSE tbCashPatient.XRayNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbXRRequest.Amount, tbXRRequest.DoctorName, tbXRRequest.revenueID, case when isnumeric(tbXRRequest.idnum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge FROM tbXRRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbXRRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbXRRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbXRRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbXRRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam [tbCoXRayExam] ON tbXRRequest.Code = tbCoXRayExam.XRayExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON tbXRRequest.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON tbXRRequest.Code = DOC.DoctorID LEFT OUTER JOIN BUILD_FILE..tbcoOtherRevenue E ON tbXRRequest.Code = E.OtherRevenueID and E.Othersectionid = 'XR' WHERE @RequestNum = tbXRRequest.RequestNum order by tbXRRequest.TransDate desc END IF @TYPE = '3' BEGIN SELECT tbULRequest.HospNum AS HospNum, tbULRequest.RequestNum AS RequestNum, tbULRequest.RefNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbULRequest.Code AS Code, case isnull(tbULRequest.revenueID,'US') when 'US' then tbCoUltraExam.UltraExam when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName when 'WC' then Build.Description else I.ItemName end AS Description, tbCoUltraExam.UltraSectionID AS SectionID, tbULRequest.IdNum AS IDNum, tbULRequest.TransDate AS TransDate, '' AS [8X10], '' AS [10X12], '' AS [11X14], '' AS [14X14], '' AS [14X17], CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = RequestDoctorCode), 'OPD') END AS RoomID, tbULRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN radiology.dbo.fn_ComputeAge(tbMaster.Birthdate,getdate()) ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate,/* ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate,*/ CASE WHEN LEFT(tbULRequest.RefNum, 2) = 'OR' THEN 0 ELSE CASE WHEN ISNUMERIC(tbPatient.IDNum) = 1 THEN ISNULL(tbPatient.BillingDate, 0) ELSE ISNULL(tbOutpatient.BillingDate, 0) END END AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.UltraNum ELSE tbCashPatient.UltraNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbULRequest.Amount, tbULRequest.DoctorName, tbULRequest.RevenueID , case when isnumeric(tbULRequest.idnum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge FROM tbULRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbULRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbULRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbULRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbULRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbULRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoUltraExam [tbCoUltraExam] ON tbULRequest.Code = tbCoUltraExam.UltraExamID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON tbULRequest.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON tbULRequest.Code = DOC.DoctorID LEFT OUTER JOIN Billing..tbBillExamListing Build ON tbULRequest.RevenueID = Build.RevenueID and tbULRequest.Code = Build.ItemID WHERE @RequestNum = tbULRequest.RequestNum END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_LoadChargeSlip] @DepartmentID varchar(2), @RefNum varchar(10) AS if @DepartmentID = 'XR' begin select r.RequestNum, r.Code, case when r.RevenueID = 'XR' then e.XrayExam when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') when len( isnull(rev.LocationID, '') ) > 0 then m.ItemName + ' ' + isnull(m.ItemDesc, '') else rev.ItemName end ItemDesc, r.Quantity, r.Amount, r.RevenueID, rev.LocationID, b.RevenueID [InventoryCode] from tbXRRequest r left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID left join BUILD_FILE..tbCoXRayExam e on r.Code = e.XRayExamID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID where r.RefNum = @RefNum order by r.TransDate end if @DepartmentID = 'US' begin select r.RequestNum, r.Code, case when r.RevenueID = 'US' then e.UltraExam when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') when len( isnull(rev.LocationID, '') ) > 0 then m.ItemName + ' ' + isnull(m.ItemDesc, '') else rev.ItemName end ItemDesc, r.Quantity, r.Amount, r.RevenueID, rev.LocationID, b.RevenueID [InventoryCode] from tbULRequest r left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID left join BUILD_FILE..tbCoUltraExam e on r.Code = e.UltraExamID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID where r.RefNum = @RefNum order by r.TransDate end if @DepartmentID = 'CT' begin select r.RequestNum, r.Code, case when r.RevenueID = 'CT' then e.CTExam when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') when len( isnull(rev.LocationID, '') ) > 0 then m.ItemName + ' ' + isnull(m.ItemDesc, '') else rev.ItemName end ItemDesc, r.Quantity, r.Amount, r.RevenueID, rev.LocationID, b.RevenueID [InventoryCode] from tbCTRequest r left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID left join BUILD_FILE..tbCoCTExam e on r.Code = e.CTExamID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID where r.RefNum = @RefNum order by r.TransDate end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DailyOut Script Date: 07/01/2000 1:20:53 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DailyOut_Backup] @Type varchar(1), @ReportDate varchar(10), @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = @reportdate -- CAST(@ReportDate as datetime) set @enddate = dateadd(day, 1, @begindate) delete tbRadioReportDaily where UserID = @UserID; if @type = '1' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.ctexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbctrequest q left join BUILD_FILE..tbcoctexam e on q.code = e.ctexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum left join PATIENT_DATA..tbcashpatient c on q.hospnum = c.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end if @type = '2' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.xrayexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbxrrequest q left join BUILD_FILE..tbcoxrayexam e on q.code = e.xrayexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum left join PATIENT_DATA..tbcashpatient c on q.hospnum = c.hospnum where (q.transdate >= @begindate and q.transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end if @type = '3' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) /* select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.ultraexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbulrequest q left join tbcoultraexam e on q.code = e.ultraexamid left join tbpatient p on q.idnum = p.idnum left join tbcodoctor d on q.requestdoctorcode = d.doctorid left join tbmaster m on q.hospnum = m.hospnum left join tbcashpatient c on q.hospnum = c.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null */ select @UserID, q.idnum, case when isnumeric(m.hospnum) = 1 then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.ultraexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbulrequest q left join BUILD_FILE..tbCoUltraExam e on q.code = e.ultraexamid left join BUILD_FILE..tbCoDoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbMaster m on q.hospnum = m.hospnum left join PATIENT_DATA..tbCashPatient c on q.hospnum = c.hospnum where isnumeric(q.idnum) = 0 -- and (q.transdate >= @begindate and q.transdate < @enddate) and (q.transdate between @ReportDate and @ReportDate + ' 23:59:59.999') and isnull(q.swfin, '') <> 'C' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Created by Jetty P. OMo --December 04,2006 --For cancellation report with reason --CancellationReport '11/29/2007','11/29/2007','CT' CREATE PROCEDURE [dbo].[CancellationReport] @StartDate varchar(30), @EndDate varchar (30), @Revenueid varchar (5) AS /* set @StartDate = '11/25/2006' set @EndDate = '12/04/2006' set @Revenueid = 'US' */ if @Revenueid = 'XR' Begin --X-Ray Exam select isNull(Master.Firstname,'') + ' ' + Left(IsNull(Master.MiddleName,''),1) + ' ' + isnull(Master.LastName,'') as [PatientName], XR.RefNum, XrayExam.XrayExam, (Select top 1 isnull(FirstName,'') + ' ' + Left(IsNull(MiddleName,''),1) + ' ' + isnull(LastName,'') from Password..tbpasswordmain where EmployeeID = tbRequest.userid) as EmployeeName, Tbrequest.Reason,TbRequest.Transdate from tbRadioCancelRequest TbRequest Left Outer Join build_file..TbCoXrayExam XrayExam on XrayExam.XrayExamid = TbRequest.ItemId Left Outer Join tbxrrequest XR on XR.requestnum = TbRequest.Requestnum Left Outer Join Patient_data..tbmaster Master on Master.Hospnum = XR.Hospnum Where TbRequest.transdate between @StartDate and @EndDate + ' 23:59:59.99' and TbRequest.revenueid = 'XR' end if @Revenueid = 'US' Begin --Ultrasound Exam select isNull(Master.Firstname,'') + ' ' + Left(IsNull(Master.MiddleName,''),1) + ' ' + isnull(Master.LastName,'') as [PatientName], US.RefNum, UltraExam.UltraExam, (Select top 1 isnull(FirstName,'') + ' ' + Left(IsNull(MiddleName,''),1) + ' ' + isnull(LastName,'') from Password..tbpasswordmain where EmployeeID = tbRequest.userid) as EmployeeName, Tbrequest.Reason,TbRequest.Transdate from tbRadioCancelRequest TbRequest Left Outer Join build_file..TbCoUltraExam UltraExam on UltraExam.UltraExamid = TbRequest.ItemId Left Outer Join tbULrequest US on US.requestnum = TbRequest.Requestnum Left Outer Join Patient_data..tbmaster Master on Master.Hospnum = US.Hospnum Where TbRequest.transdate between @StartDate and @EndDate + ' 23:59:59.99' and TbRequest.revenueid = 'US' end if @Revenueid = 'CT' Begin --CT Scan Exam select isNull(Master.Firstname,'')+ ' ' + Left(IsNull(Master.MiddleName,''),1) + ' ' + isnull(Master.LastName,'') as [PatientName], CT.RefNum, CTExam.CTExam, (Select top 1 isnull(FirstName,'')+ ' ' + Left(IsNull(MiddleName,''),1) + ' ' + isnull(LastName,'') from Password..tbpasswordmain where EmployeeID = tbRequest.userid) as EmployeeName, Tbrequest.Reason,TbRequest.Transdate from tbRadioCancelRequest TbRequest Left Outer Join build_file..TbCoCTExam CTExam on CTExam.CTExamid = TbRequest.ItemId Left Outer Join tbCTrequest CT on CT.requestnum = TbRequest.Requestnum Left Outer Join Patient_data..tbmaster Master on Master.Hospnum = CT.Hospnum Where TbRequest.transdate between @StartDate and @EndDate + ' 23:59:59.99' and TbRequest.revenueid = 'CT' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CancelRequestOnly] @DepartmentID AS varChar(2), @RequestNum AS varChar(8) AS IF @DepartmentID = 'CT' BEGIN /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END IF @DepartmentID = 'XR' BEGIN /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END IF @DepartmentID = 'US' BEGIN /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END IF @DepartmentID = 'WC' BEGIN /* Update Record Status */ UPDATE tbOBULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetResultFormat] @RevenueId as varchar(2), @RequestNum as varchar(10) AS if @RevenueId = 'XR' begin select R.requestnum, R.Code, E.XrayExam as Exam, isnull(E.FormType,'') as FormType from tbXrRequest R left outer join BUILD_FILE..tbCoXrayExam E on R.Code = E.XrayExamID Where RequestNum = @RequestNum end; if @RevenueId = 'CT' begin select R.requestnum, R.Code, E.CTExam as Exam, isnull(E.FormType,'') as FormType from tbCTRequest R left outer join BUILD_FILE..tbCoCTExam E on R.Code = E.CTExamID Where RequestNum = @RequestNum end; if @RevenueId = 'US' begin select R.requestnum, R.Code, E.UltraExam as Exam, isnull(E.FormType,'') as FormType from tbULRequest R left outer join BUILD_FILE..tbCoUltraExam E on R.Code = E.UltraExamID Where RequestNum = @RequestNum end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --created by Jetty P. Omo --october 18, 2006 CREATE PROCEDURE [dbo].[Rad_print_Diagnosis] @RequestNum as varchar(30), @RevenueID as varchar(20) = 'XR' AS declare @ChiefComplaints as varchar(2000) declare @Diagnosis as varchar(2000) declare @Findings as varchar(2000) declare @BriefHistory as varchar(2000) declare @ImagingReason as varchar(2000) declare @SurgicalReason as varchar(2000) declare @Idnum as varchar(20) declare @RefNum as varchar(20) --If @RefNum like 'C%I' -- begin -- set @Idnum = (Select distinct IDnum from Prepaid..tbPrepaidCharges where Chargeslip = @refnum and revenueid = @DepartmentID) -- end --else -- begin -- set @Idnum = (Select distinct IDnum from Station..tbNurseLogbook where ReferenceNum = @refnum and revenueid = @DepartmentID) -- end if IsNull(@IdNum,'') in ('', 'CASH') Begin if @RevenueID = 'XR' Begin set @IdNum = (select top 1 IdNum from TBXrrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBXrrequest Where RequestNum = @RequestNum ) End if @RevenueID = 'US' Begin set @IdNum = (select top 1 IdNum from TBULrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBULrequest Where RequestNum = @RequestNum ) End if @RevenueID = 'CT' Begin set @IdNum = (select top 1 IdNum from TBCTrequest Where RequestNum = @RequestNum ) set @RefNum = (select top 1 RefNum from TBCTrequest Where RequestNum = @RequestNum ) End End if isnumeric(@IdNum) = 0 begin if @IDNum = 'CASH' Begin Select @ImagingReason = ltrim(rtrim(replace(cast(isnull(ImagingReason,'') as varchar(1900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(SurgicalReason,'') as varchar(1900)),char(13),''))) From Billing..tbCashAssessment with (Index(tbCashAssessment_ORNumber)) Where ORNumber = @RefNum End else Begin Select @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaints,'') as varchar(1900)),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.Findings,'') as varchar(1900)),char(13),''))), -- @BriefHistory = @ChiefComplaints + CHAR(13) + @Diagnosis, @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(1900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbOutPatient P left outer join PATIENT_DATA..tbOUTPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum Where P.IdNum = @IdNum End end; if isnumeric(@IdNum) = 1 begin Select @ChiefComplaints = ltrim(rtrim(replace(cast(isnull(PH.ChiefComplaint,'') as varchar(900)),char(13),''))), @Findings = ltrim(rtrim(replace(cast(isnull(PH.FinalDiagnosis,'') as varchar(900)),char(13),''))), @Diagnosis = ltrim(rtrim(replace(cast(isnull(PH.AdmDiagnosis,'') as varchar(900)),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(PH.AdmImpression,'') as varchar(900)),char(13),''))), @BriefHistory = ltrim(rtrim(replace(cast(isnull(NP.BriefHistory,'') as varchar(2000)),char(13),''))), @ImagingReason = ltrim(rtrim(replace(cast(isnull(PH.ImagingReason,'') as varchar(900)),char(13),''))) + ' ' + ltrim(rtrim(replace(cast(isnull(S.Reason,'') as varchar(900)),char(13),''))), @SurgicalReason = ltrim(rtrim(replace(cast(isnull(PH.SurgicalReason,'') as varchar(900)),char(13),''))) From PATIENT_DATA..tbPatient P left outer join STATION..tbNurseLogbook L ON L.IdNum = P.IdNum left outer join PATIENT_DATA..tbPatientHistory PH ON P.IdNum = PH.IdNum left outer join BUILD_FILE..tbCoCompany C ON P.AccountNum = C.AccountNum left outer join PASSWORD..tbPasswordMain PWORD ON L.UserID = PWORD.EmployeeID left outer join STATION..tbNurseProfile NP ON P.IdNum = NP.IdNum Left Outer Join Station..tbNurseCommunicationFile S On L.Idnum = S.Idnum and L.Hospnum = S.Hospnum and L.ReferenceNum = S.Referencenum Where L.ReferenceNum = @RefNum end; SELECT IsNull(@ChiefComplaints,'') as ChiefComplaint, IsNull(@Findings,'') as Finding, IsNull(@Diagnosis,'') as Diagnosis, IsNull(@BriefHistory,'') as BriefHistory, IsNull(@ImagingReason,'') as ImagingReason, IsNull(@SurgicalReason,'') as SurgicalReason ----Comment by Gonzalo, Previous Code, 01142010 --if isnumeric(@IdNum) = 0 -- begin -- -- Select top 1 cast(isnull(PH.ChiefComplaints,'')as text)as ChiefComplaint, -- '' as AdmDiagnosis -- From PATIENT_DATA..tbOutPatient P -- left outer join PATIENT_DATA..tbOUTPatientHistory PH -- ON P.IdNum = PH.IdNum -- left outer join BUILD_FILE..tbCoCompany C -- ON P.AccountNum = C.AccountNum -- Where P.IdNum = @IdNum -- end; -- --if isnumeric(@IdNum) = 1 -- begin -- -- Select top 1 cast(isnull(PH.ChiefComplaint,'')as text) as ChiefComplaint, -- cast(isnull(PH.AdmDiagnosis,'')as text) as AdmDiagnosis -- From PATIENT_DATA..tbPatient P -- left outer join STATION..tbNurseLogbook L -- ON L.IdNum = P.IdNum -- left outer join PATIENT_DATA..tbPatientHistory PH -- ON P.IdNum = PH.IdNum ---- left outer join BUILD_FILE..tbCoCompany C ---- ON P.AccountNum = C.AccountNum -- left outer join PASSWORD..tbPasswordMaster PWORD -- ON L.UserID = PWORD.EmployeeID -- left outer join STATION..tbNurseProfile NP -- ON P.IdNum = NP.IdNum -- Where L.IdNum = @IdNum -- end; ----End of Comment GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --EXEC RADIOLOGY.dbo.spRadio_IncomeReport 'XR', '01/01/2008', '01/31/2008' CREATE PROCEDURE [dbo].[spRadio_IncomeReport_bak] @RevenueID varchar(2), @StartDate varchar(10), @EndDate varchar(10) AS select s.itemid, max(case @RevenueID when 'XR' then xray.xrayexam when 'CT' then ct.ctexam when 'US' then ultra.ultraexam end) as exam, sum(case when s.type = 'I' then s.quantity else 0 end) as InQuantity, sum(case when s.type = 'I' then s.amount else 0 end) as InAmount, sum(case when s.type = 'O' then s.quantity else 0 end) as OutQuantity, sum(case when s.type = 'O' then s.amount else 0 end) as OutAmount, sum(quantity) as TotalQty, sum(amount) as TotalAmt from ( select b.refnum, b.itemid, sum(case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end) quantity, sum(b.amount) amount, 'I' type from BILLING..tbbilldailybill b where transdate between @StartDate and @EndDate + ' 23:59:59' and (revenueid = @RevenueID or SummaryCode = @RevenueID) group by refnum, itemid having sum(amount) <> 0 union all select b.refnum, b.itemid, sum(case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end) quantity, sum(b.amount) amount, case @RevenueID when 'XR' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(req.idnum, '')) = '' then 'O' when isnumeric(max(isnull(req.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(req.idnum, ''))) = 1 then 'I' end else 'O' end when 'CT' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(reqct.idnum, '')) = '' then 'O' when isnumeric(max(isnull(reqct.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(reqct.idnum, ''))) = 1 then 'I' end else 'O' end when 'US' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(requs.idnum, '')) = '' then 'O' when isnumeric(max(isnull(requs.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(requs.idnum, ''))) = 1 then 'I' end else 'O' end end as type from BILLING..tbbillopdailyout b left join ( select refnum, max(idnum) idnum from tbxrrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as req on b.refnum = req.refnum left join ( select refnum, max(idnum) idnum from tbctrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as reqct on b.refnum = reqct.refnum left join ( select refnum, max(idnum) idnum from tbulrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as requs on b.refnum = requs.refnum where b.transdate between @StartDate and @EndDate + ' 23:59:59' and (b.revenueid = @RevenueID or SummaryCode = @RevenueID) group by b.refnum, b.itemid having sum(b.amount) <> 0 ) as s left join BUILD_FILE..tbcoxrayexam xray on s.itemid = xray.xrayexamid left join BUILD_FILE..tbcoctexam ct on s.itemid = ct.ctexamid left join BUILD_FILE..tbcoultraexam ultra on s.itemid = ultra.ultraexamid group by s.itemid GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CashCancellation] @Type AS varChar(1), @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8) AS IF @Type = '1' BEGIN /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END IF @Type = '2' BEGIN /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END IF @Type = '3' BEGIN /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum END if exists(select * from BILLING..tbCashCommunication where RefNum = @RefNum AND ItemID = @ItemID) begin UPDATE billing..tbCashCommunication SET RecordStatus = NULL WHERE RefNum = @RefNum AND ItemID = @ItemID end else begin INSERT INTO BILLING..tbCashCommunication (idnum, paymentfrom, transdate, revenueid, drcr, recordstatus, lgrp, itemid, quantity, refnum, amount, userid, reportdate, roomid, requestdocid, departmentid) select b.idnum, m.paymentfrom, b.transdate, b.revenueid, b.drcr, '' [recordstatus], b.groupcode [lgrp], b.itemid, b.quantity, b.refnum, b.amount, b.userid, b.reportdate, b.roomid, b.requestdocid, '' [departmentid] from billing..tbbillopdailyout b left join billing..tbcashormaster m on b.refnum = m.refnum where b.refnum = @RefNum and b.ItemID = @ItemID end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ReportDoctorsContribution_INandOUT] @Type varchar(1), @StartDate varchar(10), @EndDate varchar(10), @Option as bit As If @Type = '1' Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN from tbCTRequest A left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' and isnumeric(A.Idnum) = @Option Group by A.RequestDoctorCode Order by [Doctor] asc End If @Type = '2' Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN from tbXRRequest A left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' and isnumeric(A.Idnum) = @Option Group by A.RequestDoctorCode Order by [Doctor] asc End If @Type = 3 Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(IDNum) = 0 and IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(IDNum) = 0 and not IDNum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN from tbULRequest A left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' and isnumeric(A.Idnum) = @Option Group by A.RequestDoctorCode Order by [Doctor] asc End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_LoadPatientsLogBook] @CSNum varchar(10), @ORNum varchar(10), @LastName varchar(90), @HospNum varchar(8), @IDNum varchar(10), @Mode varchar(1), @RevenueID varchar(2) AS /* declare @CSNum varchar(10) declare @ORNum varchar(10) declare @LastName varchar(90) declare @HospNum varchar(8) declare @IDNum varchar(10) declare @Mode varchar(1) set @CSNum = '' set @ORNum = '' set @LastName = 'lo' set @HospNum = '' set @IDNum = '' set @Mode = 0*/ Declare @FirstName varchar(30), @MiddleName varchar(30) Set @FirstName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@LastName,',') where code = 2); Set @MiddleName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@LastName,',') where code = 3); Set @LastName = (select ltrim(rtrim(strName)) from Laboratory.dbo.fn_LabSplit(@LastName,',') where code = 1); if @RevenueID = 'XR' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbXrRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbXrRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbXrRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbXrRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End end; if @RevenueID = 'CT' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbCTRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbCTRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbCTRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbCTRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End; end; if @RevenueID = 'US' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbULRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbULRequest RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbULRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(RoomID,'')))) when 'OPD' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From tbULRequest RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End; end; if @RevenueID = 'HS' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbHrtMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbHrtMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbHrtMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbHrtMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End; end; if @RevenueID = 'MM' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From RADIOLOGY..tbMammoMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From RADIOLOGY..tbMammoMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From RADIOLOGY..tbMammoMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From RADIOLOGY..tbMammoMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End; end; --ECG if @RevenueID = 'EL' begin If @Mode = '0' --IN-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbECGMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND --(RadioMaster.IDNum = @IDNum or @IDNum = '') AND isnumeric(RadioMaster.IDNum ) = 1 Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '1' --OUT-PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(Out.LastName,'')) as [Last Name], Max(IsNull(Out.FirstName,'')) as [First Name], Max(IsNull(Out.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbECGMaster RadioMaster Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum --Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = tbLabLogbook.HospNum Where Out.LastName like IsNull(@LastName,'') + '%' AND Out.FirstName like IsNull(@FirstName,'') + '%' AND Out.MiddleName like IsNull(@MiddleName,'') + '%' AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (not RadioMaster.HospNum like '%B') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND --isnumeric(RadioMaster.IDNum ) = 0 AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '2' --CASH PATIENT Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], 'O' as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbECGMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND IsNull(RadioMaster.RefNum,'') <> '' Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End If @Mode = '3' --LRA LOGBOOK Begin Select Max(IsNull(ltrim(RadioMaster.HospNum), '')) as [Hosp. #], Max(IsNull(ltrim(RadioMaster.IDNum), '')) as [Adm. #], Max(IsNull(vw.LastName,'')) as [Last Name], Max(IsNull(vw.FirstName,'')) as [First Name], Max(IsNull(vw.MiddleName,'')) as [Middle Name], case rtrim(ltrim(Max(IsNull(P.RoomID,'')))) when '' then 'O' else 'I' end as PatientType, '' as Transplant, '' as Dialysis From CARDIO..tbECGMaster RadioMaster --Left Outer Join Patient_Data..tbMaster Out on Out.HospNum = RadioMaster.HospNum Left Outer Join LABORATORY..vwPatientResultEntry vw on vw.HospNum = RadioMaster.HospNum Left Outer Join Patient_Data..tbPatient P on RadioMaster.IdNum = P.IdNum Where (vw.LastName like IsNull(@LastName,'') + '%') AND (vw.FirstName like IsNull(@FirstName,'') + '%') AND (vw.MiddleName like IsNull(@MiddleName,'') + '%') AND (RadioMaster.HospNum = @HospNum or @HospNum = '') AND (RadioMaster.IDNum = @IDNum or @IDNum = '') AND (RadioMaster.RefNum = @CSNum or @CSNum = '') AND (RadioMaster.RefNum = @ORNum or @ORNum = '') Group by RadioMaster.HospNum Order by [Last Name], [First Name], [Middle Name] End; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_FilmUsed] @RequestNum as varchar(10), @RevenueID as varchar(3) = 'XR' AS if @RevenueID = 'XR' Begin Select Film1, Film2, Film3, Film4, Film5, Film6, Film7, Film8 from Radiology..tbXrRequest where RequestNum = @RequestNum End if @RevenueID = 'CT' Begin Select Film1, Film2, Film3, Film4, Film5, Film6, Film7--, Film8 from Radiology..tbCTRequest where RequestNum = @RequestNum End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InCancellation2] @Type AS varChar(1), @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10), @RevenueID AS varChar(2) AS --DECLARE @RevenueID AS varChar(2) DECLARE @Quantity as float DECLARE @RoomID as varchar(10) DECLARE @RequestDocID as varchar(10) IF @Type = '1' BEGIN SET @RevenueID = 'CT' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbCTRequest WHERE RequestNum = @RequestNum /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /*Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END IF @Type = '2' BEGIN /* Search for existing RefNum*/ SET @RevenueID = 'XR' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbXRRequest WHERE RequestNum = @RequestNum /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END IF @Type = '3' BEGIN /* Search for existing RefNum */ SET @RevenueID = 'US' SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbULRequest WHERE RequestNum = @RequestNum /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, Getdate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_InCancellation] @Type AS varChar(1), @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserId As varChar(4) AS DECLARE @RevenueID AS varChar(2), @RoomID varchar(10) Set @RoomID=(Select RoomID From Patient_Data..tbPatient Where IdNum = @IDNum) IF @Type = '1' BEGIN /* Search for the Existing RefNum */ SET @RevenueID = 'CT' /* SELECT @TransDate = TransDate, @Quantity = Quantity FROM tbBillDailyBill WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID */ /* Update the Record Status */ UPDATE tbCTRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /*Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @RoomID, @UserID) END IF @Type = '2' BEGIN /* Search for existing RefNum*/ SET @RevenueID = 'XR' /* SELECT @TransDate = TransDate, @Quantity = Quantity FROM tbBillDailyBill WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID */ /* Update the Record Status */ UPDATE tbXRRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @RoomID, @UserID) END IF @Type = '3' BEGIN /* Search for existing RefNum */ SET @RevenueID = 'US' /* SELECT @TransDate = TransDate, @Quantity = Quantity FROM tbBillDailyBill WHERE IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID */ /* Update Record Status */ UPDATE tbULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomId, UserID) VALUES (@Refnum, @IDNum, Getdate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @RoomID, @UserID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ReportDoctorsContribution] @Type varchar(1), @StartDate varchar(10), @EndDate varchar(10) As If @Type = '1' Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(a.IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(a.IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN, max(case isnumeric(A.IdNum) when 1 then isnull(CP.Company,'Personal') when 0 then isnull(COP.Company,'Personal') else 'CASH' end) as Company from tbCTRequest A left outer join PATIENT_DATA..tbpatient P on A.IdNum = P.IdNum left outer join PATIENT_DATA..tbOutPatient OP on A.IdNum = OP.IdNum left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) left outer join BUILD_FILE..tbCoCompany CP on P.AccountNum = CP.AccountNum left outer join BUILD_FILE..tbCoCompany COP on OP.AccountNum = COP.AccountNum where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' Group by A.RequestDoctorCode Order by [Doctor] asc End If @Type = '2' Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(a.IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(a.IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN, max(case isnumeric(A.IdNum) when 1 then isnull(CP.Company,'Personal') when 0 then isnull(COP.Company,'Personal') else 'CASH' end) as Company from tbXRRequest A left outer join PATIENT_DATA..tbpatient P on A.IdNum = P.IdNum left outer join PATIENT_DATA..tbOutPatient OP on A.IdNum = OP.IdNum left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) left outer join BUILD_FILE..tbCoCompany CP on P.AccountNum = CP.AccountNum left outer join BUILD_FILE..tbCoCompany COP on OP.AccountNum = COP.AccountNum where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' Group by A.RequestDoctorCode Order by [Doctor] asc End If @Type = 3 Begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else 'Various' end as Doctor, Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then 1 else 0 end) as OUT, Sum(Case When isnumeric(a.IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(a.IDNum) = 0 and a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(a.IDNum) = 0 and not a.idnum like 'T%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(a.IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN, max(case isnumeric(A.IdNum) when 1 then isnull(CP.Company,'Personal') when 0 then isnull(COP.Company,'Personal') else 'CASH' end) as Company from tbULRequest A left outer join PATIENT_DATA..tbpatient P on A.IdNum = P.IdNum left outer join PATIENT_DATA..tbOutPatient OP on A.IdNum = OP.IdNum left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) left outer join BUILD_FILE..tbCoCompany CP on P.AccountNum = CP.AccountNum left outer join BUILD_FILE..tbCoCompany COP on OP.AccountNum = COP.AccountNum where A.SwFin <> 'C' and Transdate between @startDate and @EndDate + ' 23:59:59.99' Group by A.RequestDoctorCode Order by [Doctor] asc End GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_GrossIncomeReport] @StartDate AS varChar(10), @EndDate AS varChar(10) AS SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'XR' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbXRRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'UL' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbULRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' UNION ALL SELECT A.Hospnum, A.Code, A.Amount, A.RoomID, CASE ISNULL(B.PatientClass,'') WHEN '' THEN 'S' ELSE B.PatientClass END AS PatientClass, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'OPD' ELSE D.RoomClass END AS RoomClass, 'CT' AS RevenueID, CASE ISNULL(D.RoomClass,'') WHEN '' THEN 'O' WHEN 'OPD' THEN 'O' ELSE 'I' END AS PatientType FROM Radiology..tbCTRequest A LEFT OUTER JOIN Patient_Data..tbPatient2 B ON A.IDNum = B.IDNum LEFT OUTER JOIN Build_File..tbCoRoom C ON A.RoomID = C.RoomID LEFT OUTER JOIN Build_File..tbCoRoomClass D ON C.RoomClassID = D.RoomClassID WHERE A.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND SwFin = 'Y' ; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --BJSL CREATE PROCEDURE [dbo].[spRadio_GetOutsideRequestingDoctor] @StartDate as varchar(10), @EndDate as varchar(10) AS select A.RequestDocID, isnull(R.DoctorName,'') [DoctorName] from Billing..tbBillDailyBill A left outer join Radiology..tbXrRequest R on A.refNum = R.RefNUm where A.RequestDocID = '0' and A.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and A.revenueid = 'XR' union all select A.RequestDocID, isnull(R.DoctorName,'') [DoctorName] from Billing..tbBillOPDailyOut A left outer join Radiology..tbXrRequest R on A.refNum = R.RefNUm where A.RequestDocID = '0' and A.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and A.revenueid = 'XR' union all select A.requestdoctorcode, A.DoctorName from tbXRRequest A left outer join Build_File..tbCoDoctor B on A.requestdoctorcode = B.DoctorID where A.requestdoctorcode = '0' and isnumeric(A.IdNum) = 0 and left(A.RefNum,2) in ('OR','CC') and TransDate between @StartDate and @EndDate + ' 23:59:59.99' order by [DoctorName] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_XRMonthlyReport] @BeginDate varchar(10), @EndDate varchar(10) AS declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = @BeginDate set @ReportDate2 = dateadd(day, 1, @EndDate) SELECT '1' as Type, B.ItemID as Code, max(E.[Description]) as [Description], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as Quantity, sum(B.Amount) as Amount, max(isnull(X.Film1,0)) as Film1, max(isnull(X.Film2,0)) as Film2, max(isnull(X.Film3,0)) as Film3, max(isnull(X.Film4,0)) as Film4, max(isnull(X.Film5,0)) as Film5, max(isnull(X.Film6,0)) as Film6, max(isnull(X.Film7,0)) as Film7 FROM BILLING..tbBillDailyBill B left outer join RADIOLOGY..tbXrRequest X on B.RefNum = X.refNum and B.ItemId = X.Code left outer join BILLING..tbBillExamListing E on B.ItemId = E.ItemID and b.RevenueiD = E.RevenueID where B.RevenueId = 'XR' and B.Transdate between @BeginDate and @EndDate + ' 23:59:59.99' group by B.RefNum, B.ItemID having sum(b.amount) <> 0 union all SELECT '0' as Type, B.ItemID as Code, max(E.[Description]) as [Description], sum(case when isnull(B.Quantity, 0) = 0 then case when isnull(B.Amount,0) > 0 then 1 when isnull(B.Amount,0) = 0 then 0 when isnull(B.Amount,0) < 0 then -1 end Else case when isnull(B.Amount,0) < 0 then ABS(IsNull(B.Quantity,1)) * -1 when isnull(B.Amount,0) = 0 then 0 else ABS(IsNull(B.Quantity,1)) end end) as Quantity, sum(b.amount) as Amount, max(isnull(X.Film1,0)) as Film1, max(isnull(X.Film2,0)) as Film2, max(isnull(X.Film3,0)) as Film3, max(isnull(X.Film4,0)) as Film4, max(isnull(X.Film5,0)) as Film5, max(isnull(X.Film6,0)) as Film6, max(isnull(X.Film7,0)) as Film7 FROM BILLING..tbBillOPDailyOut B left outer join RADIOLOGY..tbXrRequest X on B.RefNum = X.refNum and B.ItemId = X.Code left outer join BILLING..tbBillExamListing E on B.ItemId = E.ItemID and b.RevenueiD = E.RevenueID where B.RevenueId = 'XR' and B.Transdate between @BeginDate and @EndDate + ' 23:59:59.99' group by B.RefNum, B.ItemID having sum(b.amount) <> 0 /* select r.Code, e.xrayexam [Description], case when isnull(r.Quantity, 0) = 0 then 1 else r.Quantity end [Quantity], r.Amount, r.Film1, r.Film2, r.Film3, r.Film4, r.Film5, r.Film6, r.Film7, isnumeric(r.idnum) [Type] from tbxrrequest r left join build_file..tbcoxrayexam e on r.code = e.xrayexamid where (r.transdate >= @ReportDate1 and r.transdate < @ReportDate2) and r.swfin in ('X','Y') AND ( Exists(Select top 1 * from Billing..tbBillDailyBill Where Refnum = r.Refnum) OR Exists(Select top 1 * from Billing..tbBillOpDailyOut Where Refnum = r.Refnum) ) */ GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_UpdateFilmsUsed] @Type as varchar(1), @RequestNum as varchar(10), @Film1 as int, @Film2 as int, @Film3 as int, @Film4 as int, @Film5 as int, @Film6 as int, @Film7 as int, @Film8 as int = null AS IF @Type = '2' BEGIN UPDATE tbXRRequest SET Film1 = @Film1, Film2 = @Film2, Film3 = @Film3, Film4 = @Film4, Film5 = @Film5, Film6 = @Film6, Film7 = @Film7, Film8 = @Film8 WHERE RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_InDailyRep Script Date: 07/01/2000 1:20:54 AM ******/ CREATE PROCEDURE [dbo].[spRadio_InOutDailyRep_Waste] @Date AS varChar(10), @UserID as varchar(10) AS Declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = cast(@Date as datetime) set @ReportDate2 = dateadd(day, 1, @ReportDate1) DELETE tbXRDailyRep WHERE UserID = @UserID; INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XRayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, ISNULL(FilmWaste1,0), ISNULL(FilmWaste2,0), ISNULL(FilmWaste3,0), ISNULL(FilmWaste4,0), ISNULL(FilmWaste5,0), ISNULL(FilmWaste6,0), ISNULL(FilmWaste7,0) FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE isnumeric(tbXRRequest.IDNUm) = 1 --tbXRRequest.RoomId <> 'OPD' -- AND CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date AND (tbXRRequest.TransDate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') ; INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XrayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, ISNULL(FilmWaste1,0), ISNULL(FilmWaste2,0), ISNULL(FilmWaste3,0), ISNULL(FilmWaste4,0), ISNULL(FilmWaste5,0), ISNULL(FilmWaste6,0), ISNULL(FilmWaste7,0) FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE --tbXRRequest.RoomId = 'OPD' AND /*CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date */ ISNUMERIC(tbXRRequest.IDNum) = 0 AND (tbXRRequest.Transdate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') ; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchReceipt] @SearchType varchar(1), @SearchRevenue varchar(2), @SearchCriteria varchar(20) AS if @SearchType = '0' -- Search by Receipt No. begin select distinct RefNum, SlipNum, r.HospNum, m.LastName + ', ' + m.FirstName [PatientName], r.TransDate from radiology..tbxrrequest r left join patient_data..tbmaster m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 1 and r.RefNum = @SearchCriteria union all select distinct RefNum, SlipNum, r.HospNum, m.LastName + ', ' + m.FirstName [PatientName], r.TransDate from radiology..tbxrrequest r left join patient_data..tbcashpatient m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 0 and r.RefNum = @SearchCriteria end if @SearchType = '1' -- Search by Name begin select distinct RefNum [Receipt No.], SlipNum [Charge Slip], r.HospNum [Hosp. No.], m.LastName [Last Name], m.FirstName [First Name], CONVERT(VARCHAR(10), r.TransDate, 101) [Date Encoded] from radiology..tbxrrequest r left join patient_data..tbmaster m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 1 and m.LastName like @SearchCriteria + '%' union all select distinct [RefNum] Receipt, SlipNum, r.HospNum, m.LastName [Last Name], m.FirstName [First Name], CONVERT(VARCHAR(10), r.TransDate, 101) TransDate from radiology..tbxrrequest r left join patient_data..tbcashpatient m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 0 and m.LastName like @SearchCriteria + '%' order by m.LastName, m.FirstName, r.RefNum end if @SearchType = '2' -- Search by Slip begin select distinct RefNum [Receipt No.], SlipNum [Charge Slip], r.HospNum [Hosp. No.], m.LastName [Last Name], m.FirstName [First Name], CONVERT(VARCHAR(10), r.TransDate, 101) [Date Encoded] from radiology..tbxrrequest r left join patient_data..tbmaster m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 1 and r.SlipNum = @SearchCriteria union all select distinct [RefNum] Receipt, SlipNum, r.HospNum, m.LastName [Last Name], m.FirstName [First Name], CONVERT(VARCHAR(10), r.TransDate, 101) TransDate from radiology..tbxrrequest r left join patient_data..tbcashpatient m on r.HospNum = m.HospNum where ((refnum like 'OR%') or (refnum like 'CC%')) and swfin = 'X' and transdate >= '01/16/2003' and isnumeric(r.HospNum) = 0 and r.SlipNum = @SearchCriteria order by m.LastName, m.FirstName, r.RefNum end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SearchReceiptDetails] @SearchType varchar(1), @RefNum varchar(10), @RequestNum varchar(10) AS if @SearchType = '0' begin select c.RequestNum, case when c.RevenueID = 'XR' then c.Code else c.RevenueID + '-' + c.Code end [Code], case when c.RevenueID = 'XR' then v.XRayExam else m.ItemName + isnull(' ' + m.ItemDesc, '') end [Particulars], cast(c.Amount as money) Amount, cast(c.Amount as money) - isnull(c.NetAmount, cast(c.Amount as money)) Discount, isnull(c.NetAmount, cast(c.Amount as money)) Net from tbXRRequest c left join BUILD_FILE..tbCoXRayExam v on c.Code = v.XRayExamID left join INVENTORY..tbInvMaster m on c.Code = m.ItemID where c.RefNum = @RefNum end if @SearchType = '1' begin select c.RequestNum, c.SlipNum [ChargeSlip], c.RevenueID, c.Code [ItemID], isnull(v.ExamName, r.ItemName) ExamName, cast(c.Amount as money) Amount, c.DiscountType, cast(c.Amount as money) - isnull(c.NetAmount, cast(c.Amount as money)) DiscountAmount, isnull(c.NetAmount, cast(c.Amount as money)) NetAmount, case when left(c.IDNum, 1) = 'T' then 'CASH' when c.IDNum = 'ASSESS' then 'CASH' when isnull(c.IDNum, '') = '' then 'CASH' else c.IDNum end IDNum, isnull(c.Quantity, 0) Quantity, 'XR' [SourceID], c.RequestDoctorCode [RequestDocID], '1' [ReferenceCode], isnull(r.LocationID, '') [LocationID] from tbXRRequest c left join BUILD_FILE..vwBuildFile v on c.RevenueID = v.RevenueID and c.Code = v.ExamID left join BUILD_FILE..tbCoRevenueCode r on c.RevenueID = r.RevenueID where c.RefNum = @RefNum and c.RequestNum = @RequestNum end if @SearchType = '2' begin select count(*) [RecCount] from tbXRRequest c where c.RefNum = @RefNum end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DailyIn Script Date: 07/01/2000 1:20:53 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DailyIn_backup] @Type varchar(1), @ReportDate varchar(10), /* format mm/dd/yyyy */ @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) delete tbRadioReportDaily where UserID = @UserID; if @type = '1' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician) /*select @UserID, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ctexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbctrequest q left join BUILD_FILE..tbcoctexam e on q.code = e.ctexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null */ select @UserID, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ctexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from Billing..tbBillDailyBill q left join BUILD_FILE..tbcoctexam e on q.ItemId = e.ctexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on P.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) -- and isnull(swfin, '') <> 'C' and p.idnum is not null and q.RevenueID = 'CT' order by q.TransDate; end if @type = '2' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician) select @userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.xrayexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbxrrequest q left join BUILD_FILE..tbcoxrayexam e on q.code = e.xrayexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (q.transdate >= @begindate and q.transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null end if @type = '3' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician) select @userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ultraexam [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbulrequest q left join BUILD_FILE..tbcoultraexam e on q.code = e.ultraexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_MonthRep] @Start AS DateTime, @End AS DateTime, @UserID varchar(10) AS DELETE tbXRMonthlyRep WHERE UserID = @UserID; INSERT tbXRMonthlyRep SELECT TypeDescription, Film8, Film10, Film11, Film14, Film17, (SELECT CASE RoomID WHEN 'OPD' THEN CONVERT(varChar(10),Amount) ELSE '' END) AS OutCharge, (SELECT CASE RoomID WHEN 'OPD' THEN '' ELSE CONVERT(varChar(10),Amount) END) AS InCharge, (SELECT CASE RoomID WHEN 'OPD' THEN 1 ELSE '' END) AS OutNo, (SELECT CASE RoomID WHEN 'OPD' THEN '' ELSE 1 END) AS InNo, @UserID FROM tbXRRequest WHERE CONVERT(varChar(10),TransDate,101) BETWEEN @Start AND @End GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --BSL 02/18/2003 CREATE PROCEDURE [dbo].[spRadio_ReportMonthlyIncome] AS declare @StartDate as varchar(10) declare @EndDate as varchar(10) set @StartDate = '01/01/2003' set @EndDate = '01/31/2003' /* select A.Code, max(E.XrayExam) [XrayExam], Sum(case IsNull(R.RoomClassID,'') when 'B' then A.Amount else 0 end) as [PayWardAmount], Sum(case IsNull(R.RoomClassID,'') when 'C' then A.Amount else 0 end) as [PrivateAmount], Sum(case IsNull(R.RoomClassID,'') when 'D' then A.Amount else 0 end) as [SuiteAmount], Sum(case IsNull(R.RoomClassID,'') when 'B' then 1 else 0 end) as [PayWard], Sum(case IsNull(R.RoomClassID,'') when 'C' then 1 else 0 end) as [Private], Sum(case IsNull(R.RoomClassID,'') when 'D' then 1 else 0 end) as [Suite], sum(Case left(isnull(D.PatientClass,''),1) when 'S' then 1 else 0 end) as [IPDService], sum(Case left(isnull(D.PatientClass,''),1) when '' then 1 when 'P' then 1 else 0 end) as [IPDPay] from Radiology..tbXRRequest A left outer join Build_File..tbCoXrayExam E on A.Code = E.XrayExamID left outer join Patient_Data..tbPatient P on A.IdNum = P.IdNum left outer join Patient_Data..tbPatient2 D on A.IdNum = D.IdNum left outer join Build_File..tbCoRoom R on P.RoomID = R.RoomID where revenueid = 'XR' and A.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and isnumeric(A.IdNum) = 1 group by A.Code */ select A.Code, max(E.XrayExam) [XrayExam], sum(A.Amount) [OPDAmount], 0 [PayWardAmount], 0 [PrivateAmount], 0 [SuiteAmount], 0 [PayWard], 0 [Private], 0 [Suite], 0 [IPDService], 0 [IPDPay], sum (Case left(isnull(P.PatientType,''),1) when '' then 1 when 'S' then 1 else 0 end) as [OPDService], sum (Case left(isnull(P.PatientType,''),1) when '' then 1 when 'P' then 1 else 0 end) as [OPDPay] from Radiology..tbXRRequest A left outer join Build_File..tbCoXrayExam E on A.Code = E.XrayExamID left outer join Patient_Data..tbOutPatient P on A.IdNum = P.IdNum where revenueid = 'XR' and A.TransDate between @StartDate and @EndDate + ' 23:59:59.99' and isnumeric(A.IdNum) = 0 and LEFT(A.RefNum, 2) not in ('OR','CC') group by A.Code GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ResultPrint] @UserID varchar(10), @PatientName varchar(50), @Age varchar(3), @Sex varchar(10), @HospNum varchar(10), @ExamDate varchar(10), @Physician varchar(50), @RequestDate varchar(10), @RefNum varchar(10), @Exam varchar(50), @Interpretation text, @IncludeDensity int, @Density text, @IncludeFindings int, @Findings text, @Radiologist varchar(50), @RadiologistID varchar(10) AS DELETE tbMammoResult_Print WHERE UserID = @UserID INSERT INTO tbMammoResult_Print (UserID, PatientName, Age, Sex, HospNum, ExamDate, Physician, RequestDate, RefNum, Examination, Interpretation, IncludeDensity, Density, IncludeFindings, Findings, Radiologist, RadiologistID) VALUES (@UserID, @PatientName, @Age, @Sex, @HospNum, @ExamDate, @Physician, @RequestDate, @RefNum, @Exam, @Interpretation, @IncludeDensity, @Density, @IncludeFindings, @Findings, @Radiologist, @RadiologistID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_SaveRequest] @IDNum varchar(10), @HospNum varchar(8), @RefNum varchar(10), @ItemID varchar(10), @Amount float, @DoctorID varchar(4), @PatientType varchar(1), @RoomID varchar(10), @DrCr varchar(1), @UserID varchar(10) AS DECLARE @nRequest float DECLARE @cRequest varchar(10) SELECT @nRequest = RequestNum + 1 FROM tbMammoSlip UPDATE tbMammoSlip SET RequestNum = @nRequest SET @cRequest = CONVERT(varchar(10), @nRequest) INSERT INTO tbMammoMaster (TransDate, RequestNum, IDNum, HospNum, RefNum, ItemID, Amount, DoctorID, PatientType, UserID, SWMRK, Rush, ResultStatus, Quantity) VALUES (GETDATE(), @cRequest, @IDNum, @HospNum, @RefNum, @ItemID, @Amount, @DoctorID, @PatientType, @UserID, 'R', 'N', 'N',1) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[spCash_SaveMammoMaster] @AssessID int AS DECLARE @RequestNum varchar(12), @Rush varchar(1), @Hospnum As Varchar(8), @IDNum As Varchar(10), @ItemID As Varchar(4), @Amount As Float, @UserID As Varchar(8), @DoctorID As Varchar(4), @RefNum varchar(12), @Quantity float, @Counter int, @FormType varchar(1), @RoomId varchar(8), @PatientType varchar(1), @Revenueid varchar(4), @DoctorName varchar(60), @ReaderID varchar(5), @ReaderName varchar(50) DECLARE @ErrorCode int SET @ErrorCode = 0; Select @Rush = Rush, @RefNum = RefNum, @IDNum = IDNum, @Revenueid = Revenueid, @ReaderID = ReaderID, @ReaderName = ReaderName, @DoctorName = DoctorName From tbCashAssessment Where AssessID = @AssessID; Select @RefNum = RefNum, @Hospnum = HospNum, -- @IDNum = HospNum, @ItemID = ItemID, @Amount = Amount, @UserID = UserID, @DoctorID = RequestDocID, @Quantity = Quantity From tbCashCommunication Where AssessID = @AssessID; Select @FormType = isnull(FormType,'') From Build_File..tbCoNucExam Where @ItemID = NucExamID; If isnumeric(@IdNum) = 1 Begin Select @RoomId = RoomId, @PatientType = 'I' From Patient_Data..tbPatient where IdNum = @IdNum End; Else Begin Set @RoomId = 'OPD' Set @PatientType = 'O' End; SET @counter = 1 WHILE @Counter <= @Quantity BEGIN Update RADIOLOGY..tbMammoSlip Set RequestNum=RequestNum+1; /* ===> Update RequestNum(aka LabNumber) on Each Saving Loop */ SET @ErrorCode = @@ERROR; IF @ErrorCode <> 0 RETURN @ErrorCode; /* **************** Assign RequestNum to Variables ****************** */ Set @RequestNum=(Select RTrim(Cast(RequestNum as varchar(12))) From RADIOLOGY..tbMammoSlip); /* ************ Append to Nuclear Master File ****************************** */ If @revenueid <> 'MD' Begin set @RevenueID = 'MM' INSERT INTO RADIOLOGY..tbMammoMaster (RequestNum, Transdate, HospNum, IDNum, ItemID, RequestDoctorCode, ResultStatus, UserID, Amount, RoomID, RefNum, Quantity, RevenueID, DoctorName) VALUES (@RequestNum, GetDate(), @Hospnum, @IDNum, @ItemID, @DoctorID, 'N', @UserID, @Amount, @RoomID, @RefNum, @Quantity, @RevenueID, @DoctorName) SET @ErrorCode = @@ERROR; IF @ErrorCode <> 0 RETURN @ErrorCode; End; SET @Counter = @Counter + 1 CONTINUE END UPDATE TBCASHCOMMUNICATION SET RECORDSTATUS = 'Y' WHERE ASSESSID = @AssessID AND ISNULL(RECORDSTATUS, '') = ''; SET @ErrorCode = @@ERROR; IF @ErrorCode <> 0 RETURN @ErrorCode; RETURN @ErrorCode; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Lab_SaveChargeSlip Script Date: 07/01/2000 1:19:47 AM ******/ CREATE PROCEDURE [dbo].[sp_NucSaveChargeSlip] @ItemCode varchar(5), @ItemDesc varchar(50), @Quantity float, @Price float AS insert into tbNucChargeSlip(itemcode,itemdesc,quantity,price) values(@ItemCode,@ItemDesc,@Quantity,@Price) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_NucListInterpretation] AS Select * From tbNucInterpretation GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_NucSearchInterpretation] @Code varchar(10) AS Select * From tbNucInterpretation Where code = @code GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --exec RADIOLOGY..spRadio_RequestStatus '2', '02/07/2008','02/07/2008', '' /* Added the ff . Start date - Start of Date Range on searching End Date - End of Date Range on searching Search Criteria - Lastname of patient AGE,DOctor,Room and Birthdate At the same time it will show if the result is Draft or verified */ CREATE PROCEDURE [dbo].[spMammo_RequestStatus] --declare @StartDate as varchar(20), @EndDate as varchar(20), @SearchCriteria as varchar(20) --set @type = '2' --set @StartDate = '02/07/2008' --set @EndDate = '02/07/2008' --set @SearchCriteria = '' AS BEGIN select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.ITEMID [Item Code], B.OTHERREVENUE [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], A.RESULTSTATUS [Request Status], case when isnumeric(A.IdNum)=1 THEN A.RoomID else 'OPD' END AS [ROOMID], A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()), C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbmammomaster A LEFT OUTER JOIN build_file..tbcootherrevenue B ON A.ITEMID = B.OTHERREVENUEID LEFT OUTER JOIN PATIENT_DATA..tbmaster C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) -- and isnumeric (A.Hospnum) = 1 and C.LastName like @SearchCriteria + '%' AND othersectionid='MM' union all select A.Hospnum [Hosp #], A.IdNum [Adm #], C.LastName + ', ' + C.FirstName + ' ' + left(isnull(C.MiddleName,''),1) + '.' as [Patient Name], A.ITEMID [Item Code], B.OTHERREVENUE [Item Description], convert(varchar,A.TransDate,101) as [Transaction Date], A.RESULTSTATUS [Request Status], case when isnumeric(A.IdNum)=1 THEN A.RoomID else 'OPD' END AS [ROOMID] ,A.RequestDoctorCode, convert(varchar,C.Birthdate,101) as Birthdate,Age =Laboratory.dbo.fn_LabComputeAge(C.BirthDate, getdate()),C.Sex, A.refnum,A.requestnum from RADIOLOGY..tbmammomaster A LEFT OUTER JOIN build_file..tbcootherrevenue B ON A.ITEMID = B.OTHERREVENUEID LEFT OUTER JOIN PATIENT_DATA..tbCashPatient C ON A.HospNum = C.HospNum where convert(varchar,A.transdate,101) between @StartDate and @EndDate --= convert(varchar,getdate(),101) and isnumeric (A.Hospnum) = 0 and C.LastName like @SearchCriteria + '%' AND othersectionid='MM' order by [Transaction Date] END; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ResultRetrieve] --declare @RequestNum varchar(10) AS --set @RequestNum = '2' select isNull(m.requestnum,'') as requestnum, IsNull(m.idnum,'') as idnum, IsNull(m.hospnum,'') as hospnum, case when isnumeric(m.hospnum) = 1 then IsNull(z.lastname,'') else IsNull(c.lastname,'') end [lastname], case when isnumeric(m.hospnum) = 1 then IsNull(z.firstname,'') else IsNull(c.firstname,'') end [firstname], case when isnumeric(m.hospnum) = 1 then IsNull(z.middlename,'') else IsNull(c.middlename,'') end [middlename], case when isnumeric(m.hospnum) = 1 then IsNull(z.civilstatus,'') else IsNull(c.civilstatusid,'') end [civilstatus], case when isnumeric(m.hospnum) = 1 then IsNull(z.sex,'') else IsNull(c.sex,'') end [sex], case when isnumeric(m.hospnum) = 1 then isnull(convert(varchar, z.birthdate, 101), '') else isnull(convert(varchar, c.birthdate, 101), '') end [birthdate], case when isnumeric(m.hospnum) = 1 then IsNull(z.age,'') else cast(isnull(c.age,'') as varchar) end [age], case when isnumeric(m.hospnum) = 1 then isnull(z.housestreet, '') else isnull(c.housestreet, '') end [housestreet], case when isnumeric(m.hospnum) = 1 then isnull(z.barangay, '') else isnull(c.barangay, '') end [barangay], case when isnumeric(m.hospnum) = 1 then isnull(am.town + ', ' + am.province, '') else isnull(ac.town + ', ' + ac.province, '') end [town], m.resultdate, m.requestdate, a.itemid, IsNull(b.otherrevenue,'') [exam], IsNull(m.interpretation,'') Interpretation , isnull(m.doctorid, '') [doctorid], isnull(dd.firstname + ' ' + dd.lastname, '') [doctor], IsNull(m.radiologistid,'') as radiologistid, IsNull(dr.firstname,'') + ' ' + IsNull(dr.lastname,'') [radiologist], isnull(m.densitycode, '') [densitycode], isnull(m.findingscode, '') [findingscode], IsNull(case when isnumeric(IsNull(m.idnum,'')) = 1 then IsNull(p.roomid,'') else 'OP' end,'') [roomid], case when isnumeric(m.idnum) = 1 then convert(varchar, p.admdate, 101) else '' end [admdate], IsNull(a.refnum,'') as refnum, M.BiRad --IsNull(m.interpretation,'') [interpretation] from tbmammoresult m left join tbmammomaster a on m.requestnum = a.requestnum -- left join PATIENT_DATA..tbmaster z left Outer Join laboratory..vwPatientResultEntry z on m.hospnum = z.hospnum left join PATIENT_DATA..tbcashpatient c on m.hospnum = c.hospnum left join BUILD_FILE..tbcoaddress am on z.zipcode = am.zipcode left join BUILD_FILE..tbcoaddress ac on c.zipcode = ac.zipcode left join BUILD_FILE..tbCoOtherRevenue b on a.itemid = b.otherrevenueid and b.othersectionid ='MM' left join BUILD_FILE..tbCoDoctor dd on m.doctorid = dd.doctorid left join BUILD_FILE..tbCoDoctor dr on m.radiologistid = dr.doctorid left join PATIENT_DATA..tbpatient p on m.idnum = p.idnum where m.requestnum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ---- /*Modified by: Stephanie Mae Bravo Date: December 01,2007 Time: 4:56 PM*/ CREATE PROCEDURE [dbo].[spMammo_ResultSave] @RequestNum varchar(10), @IDnum varchar(10), @HospNum varchar(8), @ResultDate datetime, @RequestDate datetime, @ItemID varchar(4), @DoctorID varchar(4), @RadiologistID varchar(4), @Interpretation text, @UserID varchar(10), @DensityCode varchar(1), @FindingsCode varchar(10), @Revenueid varchar(2), @BiRad varchar(5) --@ItemCode varchar(5) AS INSERT INTO tbMammoResult (RequestNum, IDNum, HospNum, ResultDate, RequestDate, ItemID, DoctorID, RadiologistID, Interpretation, UserID, SWFIN, DensityCode, FindingsCode,Birad) VALUES (@RequestNum, @IDNum, @HospNum, @ResultDate, @RequestDate, @ItemID, @DoctorID, @RadiologistID, @Interpretation, @UserID, 'Z', @DensityCode, @FindingsCode,@BiRad) UPDATE tbMammoMaster SET ResultStatus = 'Z' WHERE RequestNum = @RequestNum IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W' ---ResultBy = @UserID, --ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemID; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_SaveResult] @RequestNum varchar(10), @IDnum varchar(10), @HospNum varchar(8), @ResultDate datetime, @RequestDate datetime, @ItemID varchar(4), @DoctorID varchar(4), @RadiologistID varchar(4), @Interpretation text, @UserID varchar(10) --@RadiologistID2 varchar(10) AS INSERT INTO tbMammoResult (RequestNum, IDNum, HospNum, ResultDate, RequestDate, ItemID, DoctorID, RadiologistID, Interpretation, UserID, SWFIN)-- RadiologistID2) VALUES (@RequestNum, @IDNum, @HospNum, @ResultDate, @RequestDate, @ItemID, @DoctorID, @RadiologistID, @Interpretation, @UserID, 'Z') --@RadiologistID2) UPDATE tbMammoMaster SET ResultStatus = 'Z' WHERE RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_TransReport] @BeginDate varchar(10), @EndDate varchar(10) AS /*select case when b.idnum = 'CASH' then 'B' else 'A' end type, b.transdate, b.idnum, p.hospnum, case when b.idnum = 'CASH' then c.paymentfrom else m.lastname + ', ' + m.firstname end as patient, b.revenueid, b.itemid, r.otherrevenue examination, case when b.idnum = 'CASH' then b.refnum else '' end receiptnum, case when b.idnum <> 'CASH' then b.refnum else '' end slipnum, b.amount, case when b.idnum = 'CASH' then '' else isnull(com.company, p.accountnum) end company from BILLING..tbbillopdailyout b left join PATIENT_DATA..tbOutPatient p on b.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BILLING..tbcashormaster c on b.refnum = c.refnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoCompany com on p.accountnum = com.accountnum where (b.transdate between @BeginDate and @EndDate + ' 23:59:59') and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') union all select 'A' as type, b.transdate, b.idnum, p.hospnum, m.lastname + ', ' + m.firstname as patient, b.revenueid, b.itemid, r.otherrevenue examination, '' as receiptnum, b.refnum as slipnum, b.amount, isnull(com.company, p.accountnum) as company from BILLING..tbbilldailybill b left join PATIENT_DATA..tbpatient p on b.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoCompany com on p.accountnum = com.accountnum where (b.transdate between @BeginDate and @EndDate + ' 23:59:59') and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') GO*/ select case when b.idnum = 'CASH' then 'B' else 'A' end type, b.transdate, b.idnum, p.hospnum, case when b.idnum = 'CASH' then c.paymentfrom else m.lastname + ', ' + m.firstname end as patient, b.revenueid, b.itemid, r.otherrevenue examination, case when b.idnum = 'CASH' then b.refnum else '' end receiptnum, case when b.idnum <> 'CASH' then b.refnum else '' end slipnum, b.amount, case when b.idnum = 'CASH' then '' else isnull(com.company, p.accountnum) end company, isNULL(j.LastName, '') + ', ' + ISNULL(j.FirstName, '') + ' ' + ISNULL(j.MiddleName, '') [DOCTOR] from BILLING..tbbillopdailyout b left join PATIENT_DATA..tbOutPatient p on b.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BILLING..tbcashormaster c on b.refnum = c.refnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoCompany com on p.accountnum = com.accountnum left join tbmammomaster x on c.refnum = x.refnum left join tbmammoresult y on x.requestnum = y.requestnum left join BUILD_FILE..tbCoDoctor j on y.doctorid = j.doctorid where (b.transdate between @BeginDate and @EndDate + ' 23:59:59') and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') union all select 'A' as type, b.transdate, b.idnum, p.hospnum, m.lastname + ', ' + m.firstname as patient, b.revenueid, b.itemid, r.otherrevenue examination, '' as receiptnum, b.refnum as slipnum, b.amount, isnull(com.company, p.accountnum) as company, isNULL(j.LastName, '') + ', ' + ISNULL(j.FirstName, '') + ' ' + ISNULL(j.MiddleName, '') [DOCTOR] from BILLING..tbbilldailybill b left join PATIENT_DATA..tbpatient p on b.idnum = p.idnum left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join BUILD_FILE..tbCoOtherRevenue r on b.itemid = r.otherrevenueid left join BUILD_FILE..tbCoCompany com on p.accountnum = com.accountnum left join tbmammomaster x on b.refnum = x.refnum left join tbmammoresult y on x.requestnum = y.requestnum and b.itemid = y.itemid left join BUILD_FILE..tbCoDoctor j on y.doctorid = j.doctorid where (b.transdate between @BeginDate and @EndDate + ' 23:59:59') and (b.revenueid = 'MM' or isnull(b.summarycode, '') = 'MM') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_RequestList] /*EDITED BY: STEPHANIE MAE BRAVO DATE: 01/30/2008 4:16PM @SearchCriteria varchar(50) AS --INPATIENT select max(isnull(a.requestnum,'')), max(isnull(a.refnum,''))as [Charge Slip #], max(isnull(b.lastname+', '+b.firstname,'')) as Patient, max(isnull(c.otherrevenue,'')), max(convert(varchar, a.transdate, 101)) [Date] from radiology..tbmammomaster a inner join patient_Data..tbmaster b on a.hospnum = b.hospnum inner join BUILD_FILE..tbCoOtherRevenue c on a.itemid = c.OtherRevenueID and c.OtherSectionID = 'MM' inner join billing..tbbilldailybill d on a.refnum = d.refnum where a.resultstatus in ('N','') and --(d.refnum like @SearchCriteria + '%') or (b.lastname like @SearchCriteria + '%') group by d.refnum--,d.amount having sum(d.amount) <> 0 union all --OUTPATIENT select max(isnull(a.requestnum,'')), max(isnull(a.refnum,''))as [Charge Slip #], max(case when b.lastname is null then isnull(e.paymentfrom,'') else isnull(b.lastname,'') + ', ' + isnull(b.firstname,'') end) as Patient, max(isnull(c.otherrevenue,'')), max(convert(varchar, a.transdate, 101)) [Date] from radiology..tbmammomaster a inner join patient_Data..tbmaster b on a.hospnum = b.hospnum inner join BUILD_FILE..tbCoOtherRevenue c on a.itemid = c.OtherRevenueID and c.OtherSectionID = 'MM' inner join billing..tbbillopdailyout d on a.refnum = d.refnum left outer join billing..tbcashormaster e on d.refnum = e.refnum where d.revenueid = 'MM' and a.resultstatus in ('N','') and a.refnum like @SearchCriteria + '%' group by d.refnum,d.itemid having sum(d.amount) <> 0 order by [Patient] */ --declare @SearchCriteria varchar(50) --set @SearchCriteria = 'ba' AS --INPATIENT select max(isnull(a.requestnum,'')), max(isnull(a.refnum,''))as [Charge Slip #], max(isnull(b.lastname+', '+b.firstname,'')) as Patient, max(isnull(c.otherrevenue,'')), max(convert(varchar, a.transdate, 101)) [Date] from radiology..tbmammomaster a left outer join laboratory..vwPatientResultEntry b on a.hospnum = b.hospnum left outer join BUILD_FILE..tbCoOtherRevenue c on a.itemid = c.OtherRevenueID and c.OtherSectionID = 'MM' left outer join billing..tbbilldailybill d on a.refnum = d.refnum where a.resultstatus in ('N','') and --(d.refnum like @SearchCriteria + '%') or (b.lastname like @SearchCriteria + '%') group by d.refnum--,d.amount having sum(d.amount) <> 0 union all --OUTPATIENT select max(isnull(a.requestnum,'')), max(isnull(a.refnum,''))as [Charge Slip #], max(case when b.lastname is null then isnull(e.paymentfrom,'') else isnull(b.lastname,'') + ', ' + isnull(b.firstname,'') end) as Patient, max(isnull(c.otherrevenue,'')), max(convert(varchar, a.transdate, 101)) [Date] from radiology..tbmammomaster a left outer join laboratory..vwPatientResultEntry b on a.hospnum = b.hospnum left outer join BUILD_FILE..tbCoOtherRevenue c on a.itemid = c.OtherRevenueID and c.OtherSectionID = 'MM' inner join billing..tbbillopdailyout d on a.refnum = d.refnum left outer join billing..tbcashormaster e on d.refnum = e.refnum Where D.revenueid ='MM' --and a.swmrk in ('R','') and a.resultstatus in ('N','') and (b.lastname like @SearchCriteria + '%') /*where d.revenueid = 'MM' and a.resultstatus in ('N','') and (b.lastname like @SearchCriteria + '%') -- and a.refnum like @SearchCriteria + '%' --or (b.lastname like @SearchCriteria + '%') and A.Resultstatus <> 'Z'*/ group by d.refnum,d.itemid having sum(d.amount) <> 0 order by [Patient] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ResultMaster] @Type varchar(1), @Criteria varchar(50) AS select HospNum, Lastname, Firstname, isnull(middlename, '') Middlename from PATIENT_DATA..tbmaster where hospnum in ( select hospnum from tbMammoMaster where resultstatus = 'Z' ) and lastname like @Criteria + '%' union all select Hospnum, Lastname, Firstname, isnull(Middlename, '') Middlename from PATIENT_DATA..tbcashpatient where hospnum in ( select hospnum from tbMammoMaster where resultstatus = 'Z' ) and lastname like @Criteria + '%' order by lastname, firstname, middlename GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ResultFile] @HospNum varchar(8) AS select m.requestnum, CONVERT(VARCHAR, r.resultdate, 101) [Result Date], m.itemid [Code], z.OtherRevenue [Exam] from tbmammomaster m left join tbmammoresult r on m.requestnum = r.requestnum LEFT JOIN BUILD_FILE..tbCoOtherRevenue z on m.itemid = z.OtherRevenueID and z.OtherSectionID = 'MM' where m.resultstatus = 'Z' AND m.HospNum = @HospNum order by r.resultdate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_LoadRequest] --declare @RequestNum varchar(10), @Hospnum varchar (10) = null AS --set @RequestNum = '1383' --set @Hospnum = '2480c' select m.requestnum, m.hospnum, m.idnum, m.refnum, m.itemid, case when isnull(m.drcr, '') = 'P' then 'DR. ' + d.FirstName + ' ' + d.LastName else ISNULL(e.OtherRevenue, 'MM ' + m.itemid) end [exam], m.quantity, m.amount, case when isnumeric(m.Idnum) = 1 then 'I' when left(m.Idnum,1) = 'T' then 'C' when right(m.idnum,1) = 'B' then 'O' when m.IdNum ='CASH' and isnumeric(m.hospnum) = 1 then 'O' --when m.IdNum ='CASH' and isnumeric(m.hospnum) = 0 then 'O' end patienttype, m.TransDate, m.DoctorID, doc.FirstName + ' ' + doc.LastName [doctor], Num.MammoNum as FileNum from tbMammoMaster m left join BUILD_FILE..tbCoOtherRevenue e on m.itemid = e.OtherRevenueID and e.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on m.itemid = d.DoctorID left join BUILD_FILE..tbCoDoctor doc on m.DoctorID = doc.DoctorID Left Outer Join patient_data..tbMaster Num on M.hospnum = Num.hospnum left outer join laboratory..vwPatientResultEntry A on M.hospnum = A.hospnum where m.requestnum = @RequestNum --and m.hospnum = @Hospnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_CancelList] @SearchType varchar(1), @SearchCriteria varchar(50) AS IF @SearchType = '0' BEGIN select m.requestnum, m.refnum, case when z.lastname is null then c.lastname + ', ' + c.firstname else z.lastname + ', ' + z.firstname end as patient, case isnull(m.drcr, '') when '' then isnull(e.OtherRevenue, 'MM ' + m.itemid) when 'P' then 'DR. ' + d.FirstName + ' ' + d.LastName end as [exam], m.transdate from tbMammoMaster m left join PATIENT_DATA..tbmaster z on m.hospnum = z.hospnum left join PATIENT_DATA..tbcashpatient c on m.hospnum = c.hospnum left join BUILD_FILE..tbCoOtherRevenue e on m.itemid = e.OtherRevenueID and e.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on m.itemid = d.DoctorID where m.ResultStatus = 'N' and ((c.lastname like @SearchCriteria + '%') or (z.lastname like @SearchCriteria + '%')) order by patient END IF @SearchType = '1' BEGIN select m.requestnum, m.refnum, case when z.lastname is null then c.lastname + ', ' + c.firstname else z.lastname + ', ' + z.firstname end as patient, case isnull(m.drcr, '') when '' then isnull(e.OtherRevenue, 'MM ' + m.itemid) when 'P' then 'DR. ' + d.FirstName + ' ' + d.LastName end as [exam], m.transdate from tbMammoMaster m left join PATIENT_DATA..tbmaster z on m.hospnum = z.hospnum left join PATIENT_DATA..tbcashpatient c on m.hospnum = c.hospnum left join BUILD_FILE..tbCoOtherRevenue e on m.itemid = e.OtherRevenueID and e.OtherSectionID = 'MM' left join BUILD_FILE..tbCoDoctor d on m.itemid = d.DoctorID where m.ResultStatus = 'N' and m.refnum = @SearchCriteria order by patient END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_CancelRequest] @RequestNum varchar(10) AS UPDATE tbMammoMaster SET ResultStatus = 'R' WHERE RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[sp_Get_MammoLogBook] --declare @StartDate as Varchar(10), @EndDate as Varchar(10), @PatientType as varchar(1) = '' /*set @StartDate = '01/01/2008' set @EndDate = '01/31/2008' set @PatientType = 'O' */ AS if @PatientType = 'I' Begin Select A.idnum, D.LastName+', '+D.FirstName+' '+D.MIddleName as PatientName, D.Birthdate, D.Age, D.Sex, B.RooMID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.ResultDate From Radiology..TBMAMMOMASTER A Left Outer Join Billing..tbBillDailybill B On A.Idnum = B.Idnum and A.refnum = B.Refnum Left Outer Join Patient_Data..tbPatient C On B.Idnum = C.Idnum Left Outer Join Patient_Data..tbMaster D On C.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.ItemID = E.OtherRevenueID and OtherSectionID = 'MM' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMAMMOResult G On A.Idnum = G.Idnum and A.RequestNum = G.Requestnum Where B.Revenueid ='MM' and A.RESULTSTATUS = 'z' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' end else Select A.idnum, D.LastName+', '+D.FirstName+' '+D.MIddleName as PatientName, D.Birthdate, D.Age, D.Sex, B.RooMID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.ResultDate From radiology..TBMAMMOMASTER A Left Outer Join Billing..tbBillOpDailyout B On A.Idnum = B.Idnum and A.refnum = B.Refnum Left Outer Join Patient_Data..tbOutPatient C On B.Idnum = C.Idnum Left Outer Join Patient_Data..tbMaster D On C.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.ItemID = E.OtherRevenueID and OtherSectionID = 'MM' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMAMMOResult G On A.Idnum = G.Idnum and A.RequestNum = G.Requestnum Where A.Refnum like 'C%V'and B.Revenueid ='MM' and A.RESULTSTATUS = 'z' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' UNION ALL select A.Idnum, C.PaymentFrom as PatientName, D.BirthDate, D.Age, D.Sex, B.RooMID, F.Lastname+', '+F.Firstname as Physician, E.OtherRevenue as [Procedure], A.Transdate, G.ResultDate from radiology..TBMAMMOMASTER A Left Outer Join Billing..tbBillOpDailyOut B On a.refnum = b.refnum --and A.hospnum = B.hospnum Left Outer Join Billing..tbCashOrMaster C On B.Refnum = C.Refnum Left Outer Join Patient_Data..tbMaster D On A.Hospnum = D.Hospnum Left Outer Join Build_File..tbCoOtherRevenue E On A.ItemID = E.OtherrevenueID and OtherSectionID = 'MM' Left Outer Join Build_File..tbCoDoctor F On A.RequestDoctorCode = F.DoctorID Left Outer Join radiology..tbMAMMOResult G On A.RequestNum = G.Requestnum Where A.refnum like 'OR%' and B.Revenueid = 'MM' and A.RESULTSTATUS = 'z' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59' order by PatientName --select * from TBMAMMOMASTER -- select * from tbMAMMOResult GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.sp_NucGetPatResult Script Date: 07/01/2000 1:20:34 AM ******/ /*for Nuclear ; By: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatResult] @strCashPatient Varchar(1), @strHospNum Varchar(8) AS select tbNucLogBook.hospnum ,'Last Name' = case isnull(@strCashPatient,'') when 'N' then a.lastname when 'Y' then b.lastname end,'First Name' = case isnull(@strCashPatient,'') when 'N' then a.firstname when 'Y' then b.firstname end,'Middle Name' = case isnull(@strCashPatient,'') when 'N' then a.middlename when 'Y' then b.middlename end,requestnum as [Trans. No.], doctorid as [Doctor], build_file..tbCoNucExam.nucexam as [Exam], tbNucLogBook.Transdate as [Trans. Date], tbNucLogBook.userid as [User ID] from tbNucLogBook left outer join patient_data..tbMaster a on tbNucLogBook.hospnum=a.hospnum left outer join patient_data..tbCashPatient b on tbNucLogBook.hospnum=b.hospnum left outer join build_file..tbCoNucExam on tbNucLogBook.itemid = build_file..tbCoNucexam.Nucexamid where tbNucLogBook.hospnum = @strHospNum order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucSearchResult] @requestnum varchar(10) AS Select * From radiology..tbNucLogBook Where requestnum = @requestnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_NucSaveResult] @Switch integer, @Hospnum varchar(10), @IdNum varchar(10), @RequestNum varchar(10), @ItemID varchar(5), @TransDate datetime, @ResultDate datetime, @PatientType varchar(1), @UserID varchar(10), @DoctorID varchar(5), @Result text AS if @Switch = 0 begin INSERT INTO tbNucLogBook(hospnum,idnum,requestnum,itemid, transdate,resultdate,patienttype,userid, doctorid,result) VALUES(@hospnum,@idnum,@requestnum,@itemid,@transdate, @resultdate,@patienttype,@userid,@doctorid, @result) end else begin UPDATE tbNucLogBook SET hospnum = @hospnum, idnum = @idnum, requestnum = @requestnum, itemid = @itemid, transdate = @transdate, resultdate = @resultdate, patienttype = @patienttype, userid = @userid, doctorid = @doctorid, result = @result WHERE requestnum = @requestnum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Code By : Christian Gonzalo Details : Keeping track of the interpretation versions for each verification churva. Date : May 06, 2010 */ CREATE PROCEDURE [dbo].[spRadio_SaveVersion] @Type AS varChar(1), @RequestNum AS varChar(10), @RadCode AS varChar(4), @DoctorID as varchar(5), @Interpretation AS Text, @Remarks as Text, @RadCode2 as varchar(4), @ResultDate as varchar(10), @ExamDate as DateTime = null, @EditedByID as varchar(20) = null, @VerifyByID as varchar(20) = null, @VerifyDate as DateTime = null, @Resultcode as varchar(5) = null, --@Findings as varchar(20) = Null, @VerifyByID1 as varchar(20) = Null, @VerifyByID2 as varchar(20) = Null AS Declare @EditedDate as DateTime, @VersionNum as int, @HospNum as varchar(10), @IDNum as Varchar(10), @ItemCode as varchar(5), @FileNum as varchar(10); set @EditedDate = getdate() If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; else Begin set @VerifyDate = getdate(); end; IF @Type = '1' /* CT-Scan Department */ BEGIN --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin if exists(Select top 1 * From tbCTResultHistory Where RequestNum = @RequestNum) Begin Set @VersionNum = (Select top 1 max(isnull(Version,0)) + 1 From tbCTResultHistory Where RequestNum = @RequestNum); End else Begin Set @VersionNum = 1; End Set @HospNum = (Select top 1 isnull(HospNum,'') From tbCTResultHistory Where RequestNum = @RequestNum); Set @IDNum = (Select top 1 isnull(IDNum,'') From tbCTResultHistory Where RequestNum = @RequestNum); Set @ItemCode = (Select top 1 isnull(ItemCode,'') From tbCTResultHistory Where RequestNum = @RequestNum); Set @FileNum = (Select top 1 isnull(XrayNum,'') From tbCTResultHistory Where RequestNum = @RequestNum); INSERT INTO tbCTResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version, Verifier1, Verifier2) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @EditedByID, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, @VersionNum, @VerifyByID1, @VerifyByID2); End END IF @Type = '2' /* XRay Department */ BEGIN --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin if exists(Select top 1 * From tbXRResultHistory Where RequestNum = @RequestNum) Begin Set @VersionNum = (Select top 1 max(isnull(Version,0)) + 1 From tbXRResultHistory Where RequestNum = @RequestNum); End else Begin Set @VersionNum = 1; End Set @HospNum = (Select top 1 isnull(HospNum,'') From tbXRResultHistory Where RequestNum = @RequestNum); Set @IDNum = (Select top 1 isnull(IDNum,'') From tbXRResultHistory Where RequestNum = @RequestNum); Set @ItemCode = (Select top 1 isnull(ItemCode,'') From tbXRResultHistory Where RequestNum = @RequestNum); Set @FileNum = (Select top 1 isnull(XrayNum,'') From tbXRResultHistory Where RequestNum = @RequestNum); INSERT INTO tbXRResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version, Verifier1, Verifier2) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @EditedByID, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, @VersionNum, @VerifyByID1, @VerifyByID2); End END IF @Type = '3' /* Ultrasound Department */ BEGIN --Keep Interpretation to represent which version has been provided if the result is verified if @VerifyByID is not null Begin if exists(Select top 1 * From tbUltraResultHistory Where RequestNum = @RequestNum) Begin Set @VersionNum = (Select top 1 max(isnull(Version,0)) + 1 From tbUltraResultHistory Where RequestNum = @RequestNum); End else Begin Set @VersionNum = 1; End Set @HospNum = (Select top 1 isnull(HospNum,'') From tbUltraResultHistory Where RequestNum = @RequestNum); Set @IDNum = (Select top 1 isnull(IDNum,'') From tbUltraResultHistory Where RequestNum = @RequestNum); Set @ItemCode = (Select top 1 isnull(ItemCode,'') From tbUltraResultHistory Where RequestNum = @RequestNum); Set @FileNum = (Select top 1 isnull(XrayNum,'') From tbUltraResultHistory Where RequestNum = @RequestNum); INSERT INTO tbUltraResultHistory ( HospNum, IDNum, RequestNum, ItemCode, RadCode, Interpretation, XrayNum, TranscribedByID, RadCode2, Remarks, VerifyByID, VerifyDate,Version, Verifier1, Verifier2) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @RadCode, @Interpretation, @FileNum, @EditedByID, @RadCode2, @Remarks, @VerifyByID, @VerifyDate, @VersionNum, @VerifyByID1, @VerifyByID2); End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucCheckMasterFile Script Date: 07/01/2000 1:20:23 AM ******/ /* for heart station;by: mary ann gungon*/ CREATE PROCEDURE [dbo].[sp_NucCheckMasterFile] @strIdNum Varchar(10), @strItemID Varchar(4) AS select * from tbNucMaster where idnum = @strIdNum and itemid = @strItemID and requeststatus <> 'R' and convert(varchar(10),transdate,101) = convert(varchar(10),getdate(),101) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCancelByLastName Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCancelByLastName] @strLastName Varchar(50) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucexam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and ((select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) like @strLastName+'%' or (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) like @strLastName+'%') order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCancelRequest Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCancelRequest] AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' order by [Last Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCancelByIdNum Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCancelByIdNum] @strIdNum Varchar(10) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and tbNucMaster.idnum= @strIdNum order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetCancelByHospNum Script Date: 07/01/2000 1:20:23 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetCancelByHospNum] @strHospNum Varchar(10) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNUcMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and tbNucMaster.hospnum= @strHospNum order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucAddRequest Script Date: 07/01/2000 1:20:23 AM ******/ /* heart station By: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucAddRequest] @strHospNum Varchar(8), @strIdNum Varchar(10), @strRequestNum Varchar(8), @strExamCode Varchar(4), @numAmount Numeric, @strDoctorID Varchar(4), @strPatientType Varchar(1), @strRefNum Varchar(10), @strUserID Varchar(8), @strNurseRequestNum Varchar(8), @strFormType Varchar(1), @Quantity float, @ReaderFee varchar(1) AS declare @strTransDate datetime set @strTransDate = getdate() insert into tbNucMaster (HospNum,IdNum,RequestNum,ItemID,Amount,TransDate,DoctorID, PatientType,RequestStatus,RefNum,UserId,NurseRequestNum,FormType,Quantity,ReaderFee) values(@strHospNum,@strIdNum,@strRequestNum,@strExamCode,@numAmount,@strTransDate, @strDoctorID,@strPatientType,'X',@strRefNum,@strUserID,@strNurseRequestNum,@strFormType,@Quantity,@ReaderFee) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucSearchRefnum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucSearchRefnum] @strRefNum Varchar(10) AS select doctorid,itemid,amount,getdate() as [server date] from tbNucMaster where refnum = @strRefNum and requeststatus <> 'R' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_Nuc_GetChargeSlip] @IDNum varchar(8) AS select tbNucMaster.TransDate as [Trans. Date],tbNucMaster.refnum as [Charge Slip No.],tbNucMaster.itemid as Code, (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.NucExam end) as Examination, tbNucMaster.Quantity as Quantity,tbNucMaster.Amount as Amount from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.NucExamID Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.IDNum = @IDNum and tbNucMaster.RequestStatus <> 'R' order by tbNucMaster.Refnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_Nuc_GetChargeSlipByRefNum] @RefNum varchar(10) AS select tbNucMaster.TransDate as [Trans. Date],tbNucMaster.refnum as [Charge Slip No.],tbNucMaster.itemid as Code, (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName + ', ' + build_file..tbCoDoctor.FirstName else build_file..tbCoNucExam.NucExam end) as Examination, tbNucMaster.Quantity as Quantity,tbNucMaster.Amount as Amount from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.NucExamID Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.RefNum = @RefNum and tbNucMaster.RequestStatus <> 'R' order by tbNucMaster.Refnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetPatientByFirstName Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatientByFirstName] @strLastName Varchar(50), @strFirstName Varchar(50) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and ((select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) = @strLastName or (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) = @strLastName) and ((select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) like @strFirstName+'%' or (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) like @strFirstName+'%') and tbNucMaster.ReaderFee = 0 order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetPatientByIdNum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatientByIdNum] @strIdNum Varchar(10) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and tbNucMaster.idnum= @strIdNum and tbNucMaster.ReaderFee = 0 order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetPatientByHospNum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatientByHospNum] @strHospNum Varchar(10) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and tbNucMaster.hospnum= @strHospNum and tbNucMaster.ReaderFee = 0 order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetPatientByLastName Script Date: 07/01/2000 1:20:24 AM ******/ /* for: heart station, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetPatientByLastName] @strLastName Varchar(50) AS select 'Last Name' = (select tmp = case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe = case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'First Name' = (select tmp2 = case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe2 = case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), 'Middle Name' = (select tmp3 = case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then (select tmpe3 = case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end ) end ), (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucExam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucExam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbnucMaster.requeststatus='X' and ((select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) like @strLastName+'%' or (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) like @strLastName+'%') and tbNucMaster.ReaderFee = 0 order by 'Last Name' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetResultsEntry Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetResultsEntry] AS select (case patienttype when 'I' then (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then case when not exists(select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select lastname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select lastname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end end) as [Last Name], (case patienttype when 'I' then (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then case when not exists(select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select firstname from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select firstname from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end end ) as [First Name], (case patienttype when 'I' then (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) when 'O' then case when not exists(select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) then (select middlename from patient_data..tbCashPatient where tbNucMaster.hospnum = patient_data..tbCashPatient.hospnum) else (select middlename from patient_data..tbMaster where tbNucMaster.hospnum = patient_data..tbMaster.hospnum) end end ) as [Middle Name], (case tbNucMaster.ReaderFee when 1 then build_file..tbCoDoctor.LastName+', ' + build_file..tbCoDoctor.Firstname else build_file..tbCoNucexam.nucexam end) as Exam, tbNucMaster.transdate as [Trans. Date], tbNucMaster.requestnum as [Trans. No.], tbNucMaster.userid as [User ID], tbNucMaster.hospnum as [Hosp. No.], tbNucMaster.idnum as [Adm. No.] from tbNucMaster Left Outer Join build_file..tbCoNucExam on tbNucMaster.ItemID = build_file..tbCoNucexam.nucexamid Left Outer Join build_file..tbCoDoctor on tbNucMaster.ItemID = build_file..tbCoDoctor.DoctorID where tbNucMaster.requeststatus='X' and tbNucMaster.ReaderFee = 0 order by [Last Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucIncRefNum Script Date: 07/01/2000 1:20:24 AM ******/ CREATE PROCEDURE [dbo].[sp_NucIncRefNum] AS update tbNucSlip set chargeslip=chargeslip+1 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucIncRequestNum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucIncRequestNum] AS update tbNucSlip set requestnum=requestnum+1 GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_NucGetRequestNum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetRequestNum] AS select requestnum from tbNucSlip GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.sp_EndoGetRefNum Script Date: 07/01/2000 1:20:24 AM ******/ /* for: nuclear, by: Mary Ann Gungon */ CREATE PROCEDURE [dbo].[sp_NucGetRefNum] AS select chargeslip from tbNucSlip GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_CSlip] @Patient AS varChar(90), @AccountNum AS varChar(60), @HospNum AS varChar(10), @CSlip AS varChar(10), @RoomNo AS varChar(5), @Doctor AS varChar(50), @Age AS varChar(3), @AdmNum AS varChar(10), @Code AS varChar(5), @Description AS varChar(60), @Quantity AS varChar(3), @Price AS Float, @Charges AS Float AS DECLARE @cHospNum as varchar(8) IF @HospNum = 'CASH' BEGIN SET @cHospNum = 'OPD' END ELSE BEGIN SET @cHospNum = @HospNum END INSERT INTO tbRadioCSlip (PatientName, AccountNum, HospNum, CSlipNum, RoomNo, Doctor, Age, AdmNum, Code, Description, Quantity, Price, Charges) VALUES (@Patient, @AccountNum, @cHospNum, @CSlip, @RoomNo, @Doctor, @Age, @AdmNum, @Code, @Description, @Quantity, @Price, @Charges) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ClearCslip] AS DELETE tbRadioCSlip GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMammo_ResultUpdate] @RequestNum varchar(10), @ResultDate varchar(10), @DoctorID varchar(10), @RadiologistID varchar(10), @Interpretation text, @DensityCode varchar(1), @FindingsCode varchar(10) AS UPDATE tbMammoResult SET ResultDate = @ResultDate, DoctorID = @DoctorID, RadiologistID = @RadiologistID, Interpretation = @Interpretation, DensityCode = @DensityCode, FindingsCode = @FindingsCode WHERE RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[sp_Rad_UpdateHistory] @Hospnum varchar(10), @Idnum varchar(10), @Requestnum varchar(20), @PatientName varchar(500), @Remarks text = NULL, @ExamName varchar(50) = NULL, @VersionNumber int = NULL, @Birad varchar(5) = NULL, @RunDate datetime = NULL, @UserID varchar(10) = NULL AS Set @VersionNumber = (Select Isnull(Count(Requestnum),0) + 1 From Radiology..tbHistory where Requestnum = @Requestnum) insert into Radiology..tbMammoHistory(Hospnum,Idnum,Requestnum,PatientName,Remarks,ExamName,VersionNumber,Birad,RunDate,UserID) select hospnum,idnum,Requestnum,@PatientName,@Remarks,@ExamName,@VersionNumber,@Birad,@RunDate,@UserID from radiology..tbmammoresult Where Idnum = @Idnum and Requestnum = @Requestnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dbo].[sp_Viewing] @Requestnum as varchar(10) AS select requestnum,interpretation,birad from radiology..tbmammoresult where requestnum = @Requestnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Created by : Jetty P. Omo Date : 02/08/2008 Details : Setup for Radiology File number ~If FileNoSetup is 0(False) then file number is applicable for all section else it is per section ~If mode = 0 then centralized file number update else by section */ --Sp_RadioFileNoSetup 'xr' CREATE Procedure [dbo].[Sp_RadioFileNoSetup] @Department as varchar(2), @Mode as varchar(1) = '0' --SET @Department = 'XR' AS Declare @ALLSection as varchar(1) set @ALLSection = (select isnull(FileNoSetup,1)from tbRadiosetup where Department = @Department) if @Mode = 0 Begin if @ALLSection = 0 Begin select isnull(FileNoSetup,1) as FileNoSetup, isnull(FileNumber,0) as FileNumber, isnull(FileNoPrefix,'') as FileNoPrefix from tbRadiosetup where Department = 'XR' End if @ALLSection = 1 Begin select isnull(FileNoSetup,1) as FileNoSetup, isnull(FileNumber,0) as FileNumber, isnull(FileNoPrefix,'') as FileNoPrefix from tbRadiosetup where Department = @Department End end if @Mode = 1 Begin if @ALLSection = 0 Begin update tbRadiosetup set FileNumber = FileNumber + 1 where Department = 'XR' End if @ALLSection = 1 Begin update tbRadiosetup set FileNumber = FileNumber + 1 where Department = @Department End end GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_SaveXrRadTech] @Mode as varchar(1), @strCode as varchar(10) AS declare @strLastName as varchar(30) declare @strFirstName as varchar(30) declare @strMiddleName as varchar(30) set @strLastName = (select LastName from Password..tbPasswordMaster where EmployeeID = @strCode) set @strFirstName = (select FirstName from Password..tbPasswordMaster where EmployeeID = @strCode) set @strMiddleName = (select MiddleName from Password..tbPasswordMaster where EmployeeID = @strCode) if @Mode = '1' --Saving begin insert Radiology..tbRadioRadTech (EmployeeID, LastName, FirstName, MiddleName) values (@strCode,@strLastName,@strFirstName,@strMiddleName) end; else if @Mode = '2' begin delete from Radiology..tbRadioRadTech where EmployeeID = @strCode; end ; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO -- For Searching of Rad Techs to be tagged. March 06, 2003 09:45AM /bsl CREATE PROCEDURE [dbo].[spRadio_SelectEmployee] @strSearch as varchar(10) AS select A.EmployeeID, A.LastName + ', ' + A.FirstName + ' ' + A.MiddleName [EmployeeName] From Password..tbPasswordMain A left outer join Radiology..tbRadioRadTech B on A.EmployeeID = B.EmployeeID where A.departmentid = '11' and isnull(B.EmployeeID,'') = '' and (A.EmployeeID like @strSearch + '%' or A.LastName like @strSearch + '%') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SelectRadTech] @SearchCriteria varchar(50) as select distinct A.EmployeeID, A.LastName + ', ' + A.FirstName + ' ' + A.MiddleName [EmployeeName] From Password..tbPasswordMain A left outer join Radiology..tbRadioRadTech B on A.EmployeeID = B.EmployeeID where A.departmentid in ('11','13','23','MR','27') --and isnull(B.EmployeeID,'') = '' and (A.EmployeeID like @SearchCriteria + '%' or A.LastName like @SearchCriteria + '%') order by [EmployeeName] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE Procedure [dbo].[ViewingVersions] --Declare @Requestnum varchar(10) AS --set @Requestnum = '8' Select VersionNumber as Version#,Remarks as Description,Requestnum From Radiology..tbMammoHistory Where requestnum = @requestnum Order By Cast(VersionNumber as Integer) desc GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchProgramAccess] @strSearch as varchar(10) AS if len(ltrim(rtrim(@strSearch))) = 0 begin select * from tbRadioUserSettings order by itemid end; else begin select * from tbRadioUserSettings Where str(Itemid) = @strSearch or Description like @strSearch order by itemid; end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveProgramSettings] @strMode as varchar(1), @strCode as int, @strDescription as varchar(100), @strStatus as varchar(1) AS if @strMode = 'A' begin insert into tbRadioUserSettings ([Description], Status) values (@strDescription, @strStatus); end; if @strMode = 'B' begin update tbRadioUserSettings set [description] = @strDescription, Status = @strStatus where ItemID = @strCode end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetSavedUserRights] @EmployeeId as varchar(15) AS /* declare @EmployeeId as varchar(15) set @EmployeeId = '1105' */ declare @Text varchar(300) declare @Delimiter char(1) declare @I as integer declare @Start as integer declare @End as integer declare @C as char(1) declare @Count as integer declare @Table table(Code int, RightsID varchar(50)) declare @Table2 table(strName varchar(50), quantity integer) declare @UserRights as varchar(300) declare @intCtr as integer declare PatientC cursor for (Select EmployeeRights from RADIOLOGY..tbRadioUserRights where EmployeeID = @EmployeeID) open PatientC fetch next from PatientC into @UserRights WHILE @@FETCH_STATUS = 0 begin set @I = 1 set @Start = 1 set @End = 0 set @Count = 1 set @text = @UserRights set @Delimiter = '|' while @I < len(@Text) begin set @C = substring(@Text, @I, 1) if @C = @Delimiter begin set @End = @I end if @End > 0 begin insert into @Table values(@Count, Replace(substring(@Text, @Start, @I - @Start),@Delimiter,'')) set @Start = @I + 1 set @End = 0 set @Count = @Count + 1 end set @I = @I + 1 end if substring(@Text,len(@text),1) = @Delimiter begin insert into @Table values(@Count, substring(@Text, @Start, @I - @Start )) insert into @Table values(@Count+1, '') end else begin insert into @Table values(@Count, substring(@Text, @Start, @I - @Start + 1)) end fetch next from PatientC into @UserRights end close PatientC deallocate PatientC insert into tbRadioDumpUserRights select @EmployeeId, A.RightsID, S.Description from RADIOLOGY..tbRadioUserSettings S left outer join @table A on A.RightsID = S.ItemID where isnull(A.RightsID,'') <> '' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DailyIn Script Date: 07/01/2000 1:20:53 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DailyIn] @Type varchar(1), @ReportDate varchar(10), /* format mm/dd/yyyy */ @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) delete tbRadioReportDaily where UserID = @UserID; if @type = '1' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician, Station) select @UserID, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ctexam [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity , q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station from Billing..tbBillDailyBill q left join BUILD_FILE..tbcoctexam e on q.ItemId = e.ctexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on P.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) -- and isnull(swfin, '') <> 'C' and p.idnum is not null and q.RevenueID = 'CT' and (Select sum(Amount) From Billing..tbBillDailyBill Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'CT') > 0 order by q.TransDate; end if @type = '2' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician, Station) select @userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.xrayexam [exam], Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station from Billing..tbBillDailyBill q left join BUILD_FILE..tbcoxrayexam e on q.ItemID = e.xrayexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum where (q.transdate >= @begindate and q.transdate < @enddate) -- and isnull(swfin, '') <> 'C' and p.idnum is not null and q.RevenueID = 'XR' and (Select sum(Amount) From Billing..tbBillDailyBill Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'XR') > 0 end if @type = '3' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician, Station) select @userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.ultraexam [exam],Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station from Billing..tbBillDailyBill q left join BUILD_FILE..tbcoultraexam e on q.ItemID = e.ultraexamid left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocID = d.doctorid left join PATIENT_DATA..tbmaster m on P.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) -- and isnull(swfin, '') <> 'C' and p.idnum is not null and q.RevenueID = 'US' and (Select sum(Amount) From Billing..tbBillDailyBill Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'US') > 0 end if @type = '4' begin insert into tbRadioReportDaily (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician, Station) select @userid, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.OtherRevenue [exam],Case When q.quantity = 0 then 1 else q.quantity end quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician, (Select Top 1 Y.Station From Build_file..tbCoRoom X Left Outer Join Build_File..tbCoStation Y On X.StationID = Y.StationID Where X.RoomID = P.RoomID) Station from Billing..tbBillDailyBill q left join BUILD_FILE..tbcoOtherRevenue e on q.ItemID = e.OtherRevenueID left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocID = d.doctorid left join PATIENT_DATA..tbmaster m on P.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and p.idnum is not null and q.RevenueID = 'WC' and (Select sum(Amount) From Billing..tbBillDailyBill Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'WC') > 0 end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_DailyOut Script Date: 07/01/2000 1:20:53 AM ******/ CREATE PROCEDURE [dbo].[spRadio_DailyOut] @Type varchar(1), @ReportDate varchar(10), @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = @reportdate -- CAST(@ReportDate as datetime) set @enddate = dateadd(day, 1, @begindate) delete tbRadioReportDaily where UserID = @UserID; if @type = '1' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician, Clinic) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.PaymentFrom end [patient], 'OPD' [roomid], q.refnum, e.ctexam [exam], q.quantity, q.amount, case when isnull(q.requestdocid, '0') = '0' Then isnull(q.DoctorName,'') else d.lastname + ', ' + d.firstname end as physician, D.drClinic from Billing..tbbillOpdailyOut q left join BUILD_FILE..tbcoctexam e on q.itemID = e.ctexamid left join PATIENT_DATA..tbOutpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on P.hospnum = m.hospnum left join Billing..tbcashOrmaster c on q.Refnum = c.Refnum where (q.transdate >= @begindate and q.transdate < @enddate) -- and isnull(swfin, '') <> 'C' --and p.idnum is null and q.Revenueid = 'CT' and (Select sum(Amount) From Billing..tbBillOpDailyOut Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'CT') > 0 end if @type = '2' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.PaymentFrom end [patient], 'OPD' [roomid], q.refnum, e.Xrayexam [exam], q.quantity, q.amount, case when isnull(q.requestdocid, '0') = '0' Then isnull(q.DoctorName,'') else d.lastname + ', ' + d.firstname end as physician from Billing..tbbillOpdailyOut q left join BUILD_FILE..tbcoXrayexam e on q.itemID = e.Xrayexamid left join PATIENT_DATA..tbOutpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join Billing..tbcashOrmaster c on q.Refnum = c.Refnum where (q.transdate >= @begindate and q.transdate < @enddate) -- and isnull(swfin, '') <> 'C' --and p.idnum is null and q.Revenueid = 'XR' and (Select sum(Amount) From Billing..tbBillOpDailyOut Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'XR') > 0 end if @type = '3' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.PaymentFrom end [patient], 'OPD' [roomid], q.refnum, e.Ultraexam [exam], q.quantity, q.amount, case when isnull(q.requestdocid, '0') = '0' Then isnull(q.DoctorName,'') else d.lastname + ', ' + d.firstname end as physician from Billing..tbbillOpdailyOut q left join BUILD_FILE..tbcoUltraexam e on q.itemID = e.Ultraexamid left join PATIENT_DATA..tbOutpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join Billing..tbcashOrmaster c on q.Refnum = c.Refnum where (q.transdate >= @begindate and q.transdate < @enddate) -- and isnull(swfin, '') <> 'C' --and p.idnum is null and q.Revenueid = 'US' and (Select sum(Amount) From Billing..tbBillOpDailyOut Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'US') > 0 end if @type = '4' begin insert into tbRadioReportDaily (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.PaymentFrom end [patient], 'OPD' [roomid], q.refnum, e.OtherRevenue [exam], q.quantity, q.amount, case when isnull(q.requestdocid, '0') = '0' Then isnull(q.DoctorName,'') else d.lastname + ', ' + d.firstname end as physician from Billing..tbbillOpdailyOut q left join BUILD_FILE..tbcoOtherRevenue e on q.itemID = e.OtherRevenueID left join PATIENT_DATA..tbOutpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdocId = d.doctorid left join PATIENT_DATA..tbmaster m on p.hospnum = m.hospnum left join Billing..tbcashOrmaster c on q.Refnum = c.Refnum where (q.transdate >= @begindate and q.transdate < @enddate) and q.Revenueid = 'WC' and (Select sum(Amount) From Billing..tbBillOpDailyOut Where Refnum = Q.Refnum and ItemID = Q.ItemID and RevenueID = 'WC') > 0 end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_Ledger Script Date: 07/01/2000 1:20:55 AM ******/ CREATE PROCEDURE [dbo].[spRadio_Ledger] @PatientType varchar(1), @IDNum varchar(10), @RevenueID varchar(10), @UserID varchar(10) AS Declare @OpdIdnum as varchar(10); delete tbRadioReportLedger where Userid = @UserID; if @PatientType = 'I' begin Set @OpdIdnum = (Select OpdIdnum from Patient_Data..tbPatient where idnum = @Idnum); If Len(isnull(@OpdIdnum,'')) > 0 Begin insert into tbRadioReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @userid, --b.transdate, convert(varchar(10), b.transdate, 101) + substring(convert(varchar, b.transdate, 100), 12, 8), b.refnum, b.itemid, case b.RevenueID when 'XR' then x.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from billing..tbbilldailybill b left join build_file..tbcoxrayexam x on b.itemid = x.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum order by b.transdate; insert into tbRadioReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @userid, b.transdate, b.refnum, b.itemid, case b.RevenueID when 'XR' then x.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from Billing..tbbillopdailyout b left join build_file..tbcoxrayexam x on b.itemid = x.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @OpdIdnum order by b.transdate End; Else Begin insert into tbRadioReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @userid, --b.transdate, convert(varchar(10), b.transdate, 101) + substring(convert(varchar, b.transdate, 100), 12, 8), b.refnum, b.itemid, case b.RevenueID when 'XR' then x.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from billing..tbbilldailybill b left join build_file..tbcoxrayexam x on b.itemid = x.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum order by b.transdate End; end if @PatientType = 'O' begin insert into tbRadioReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @userid, b.transdate, b.refnum, b.itemid, case b.RevenueID when 'XR' then x.xrayexam when 'CT' then c.ctexam when 'US' then u.ultraexam when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from Billing..tbbillopdailyout b left join build_file..tbcoxrayexam x on b.itemid = x.xrayexamid left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @RevenueID or isnull(b.summarycode, '') = @RevenueID) and b.idnum = @IDNum order by b.transdate end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spUltra_AppointmentStatus] @Option as varchar(1), @PatientNo as varchar(50) AS if @Option = 'R' ---Revoke begin update Radiology..tbUltraAppointment set Status = 'R' where PatientNo = @PatientNo end; if @option = 'P' --- Preset begin update Radiology..tbUltraAppointment set Status = 'P' where PatientNo = @PatientNo end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spUltra_Appointment] @PatientName as varchar(100), @Procedure as varchar(100), @Doctor as varchar(100), @Date as datetime, @Time as varchar(10), @ContactNo as varchar(50), @UserID as varchar(10), @RevenueID as varchar(2) AS if exists(Select * from Radiology..tbUltraAppointment where PatientName = @PatientName) begin update Radiology..tbUltraAppointment set PatientName = @PatientName, [Procedure]= @Procedure, Doctor =@Doctor, AppointmentDate = @Date, [time] = @Time, ContactNo = @ContactNo, UserID = @UserID, RevenueID = @RevenueID where PatientName = @PatientName end; else begin Insert into Radiology..tbUltraAppointment (PatientName,[Procedure],Doctor,AppointmentDate,[time],ContactNo,UserID, RevenueID) Values (@PatientName,@Procedure,@Doctor,@Date,@Time,@ContactNo,@UserID, @RevenueID) end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spUltra_GetAppointment] @RevenueID as varchar(2) AS declare @Date as varchar(10) set @Date = convert(varchar(10),getdate(),101) select PatientNo,PatientName,[Procedure],Doctor, Convert(varchar(10),AppointmentDate,101)AppDate,[Time],ContactNo from Radiology..tbultraAppointment where convert(varchar(10), Appointmentdate,101) = @Date and isnull(Status,'') not in ('R','P') and RevenueID = @RevenueID GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spUltra_SearchAppointment] @PatientName as varchar(10), @RevenueID as varchar(2) AS --set @PatientName = 'A' Select A.PatientNo, A.PatientName, A.[Procedure], A.Doctor,A.AppointmentDate,A.[Time], A.ContactNo, B.LastName + ', '+ B.FirstName + ' '+ B.MiddleName as Recordedby From Radiology..tbUltraAppointment A Left Outer join password..tbPasswordMaster B on A.UserID = B.EmployeeID where A.PatientName like @PatientName +'%' and A.RevenueID = @RevenueID and isnull(A.Status,'') <> 'R' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_ResultPrint Script Date: 07/01/2000 1:20:56 AM ******/ CREATE PROCEDURE [dbo].[spRadio_ResultPrint] @Patient AS varChar(90), @HospNum AS varChar(10), @Doctor AS varChar(60), @Examination AS varChar(60), @CivilStatus AS varChar(15), @Age AS varChar(3), @Sex AS varChar(6), @AdmNum AS varChar(10), @CTNum AS varChar(10), @RoomNo AS varChar(25), @ExamDate AS DateTime, @Interpretation AS Text, @Radiologist AS varChar(60), @Address AS varChar(60), @TelNo AS varChar(15), @FileNum AS varChar(10), @ControlNum AS varChar(10), @UserID AS varchar(10), @Radiologist2 AS varchar(60), @Remarks AS text , @Tracing as varchar(1) = '', @RadiologyID as varchar(10) = '', @Radiologist3 as varchar(60) = null, @Radiologist4 as varchar(60) = null, @RevenueID as Varchar(3) = '', @ExamDate1 as datetime = null, @Equipment as varchar(100) = '', @ResultFindings As varchar(50) = '0|0|0|0|0|0|0' AS DECLARE @cHospNum as varchar(10) DECLARE @ChiefComplaint as varchar(200), @AdmDiagnosis as varchar(200), @Verifier as varchar(100), @Company as varchar(250) set @Doctor = Replace(@Doctor,', M.D.','') if @Hospnum = 'CASH' begin SET @cHospNum = 'OPD' end else begin SET @cHospNum = @HospNum end --DELETE tbRadioResult --WHERE UserID = @UserID and AdmNum = @AdmNum; select @chiefcomplaint = ISNULL(chiefcomplaint,'') from patient_data..tbpatienthistory where idnum = @AdMnum select @AdmDiagnosis = ISNULL(AdmDiagnosis,'') from patient_data..tbpatienthistory where idnum = @AdMnum select @Verifier = ISNULL(LastName,'') + ', ' + ISNULL(FirstName,'') + ' ' + ISNULL(MiddleName,'') + ', ' + ISNULL(nameaffix,'') from password..tbpasswordmain where employeeid = @UserID--@VerifyByID if IsNumeric(@AdmNum) = 1 Begin select @Company = IsNull(Company,'') from Build_file..tbCoCompany C Left Outer Join Patient_data..tbPatient P On P.AccountNum = C.AccountNum where P.IDNum = @AdmNum End else Begin select @Company = IsNull(Company,'') from Build_file..tbCoCompany C Left Outer Join Patient_data..tbOutPatient P On P.AccountNum = C.AccountNum where P.IDNum = @AdmNum End INSERT INTO tbRadioResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks, Tracing, RadiologyID, Radiologist3, Radiologist4, CHIEFCOMPLAINT, ADMDIAGNOSIS, REVENUEID, VERIFIER, Equipment,TransDate,ResultFindings) VALUES( @Patient, @cHospNum, Replace(@Doctor,'',', M.D.'), @Examination, @CivilStatus, @Age, @Sex, @AdmNum, @CTNum, ltrim(rtrim(@RoomNo)), @ExamDate,replace(cast(@Interpretation as varchar(5000)),'`',''''), @Radiologist, @Address, @TelNo, @FileNum, @ControlNum, @UserID, @Radiologist2, @Remarks, @Tracing, @RadiologyID, @Radiologist3, @Radiologist4, @ChiefComplaint, @AdmDiagnosis, @RevenueID, @Verifier, @Equipment, @ExamDate1,@ResultFindings) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveUserRights] @strEmployeeID as varchar(15), @strEmployeeRights as varchar(100), @strRadioSectionID as varchar(20), @strUserid as varchar(15) AS if exists (select employeeid from tbRadioUserRights where employeeid = @strEmployeeID) begin update tbRadioUserRights set EmployeeRights = @strEmployeeRights, RadioSectionID = @strRadioSectionID, TransDate = getdate(), UserID = @strUserid where employeeid = @strEmployeeID; end; else begin insert into tbRadioUserRights (EmployeeID, EmployeeRights, TransDate, USerID, RadioSectionID) values (@strEmployeeID, @strEmployeeRights, getdate(), @strUserid, @strRadioSectionID) end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_CheckIfCanVerify] @DepartmentID as varchar(2), @EmployeeID as varchar(15), @Password as varchar(50) AS select P.EmployeeID, P.[Password], [Name] as VerifyName From Password..tbpasswordMain P left outer join radiology..tbRadioUserRights R on P.EmployeeID = R.EmployeeID where P.EmployeeID = @EmployeeID and P.DepartmentId in (@DepartmentID,'00') and P.Password = @Password and R.EmployeeRights like '%20%' GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_TransReport Script Date: 07/01/2000 1:20:57 AM ******/ CREATE PROCEDURE [dbo].[spRadio_TransReport] @RevenueID AS varChar(2), @StartDate AS DateTime, @EndDate AS DateTime, @UserID as varchar(10) AS DELETE tbRadioTransReport WHERE UserID = @UserID; IF @RevenueID = 'CT' BEGIN INSERT tbRadioTransReport Select B.PatientName, isnull(C.CtExam,'') as Description, A.RefNum as CSlip, '' as Cash, Cast(A.Amount as Varchar) as Charge, @UserID From Billing..tbBillDailybill A Left Outer Join (Select X.Idnum, X.HospNum, isnull(LastName,'') + ', ' + isnull(FirstName,'') as PatientName From Patient_Data..tbPatient X Left Outer Join Patient_Data..tbMaster Y On X.HospNum = Y.HospNum) B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoCtExam C On A.ItemID = C.CTExamID Where A.RevenueID = 'CT' and TransDate Between @StartDate and @EndDate + ' 23:59:59.99' union all Select Case When Not B.PatientName = '' Then B.PatientName Else D.PaymentFrom End as PatientName, isnull(C.CtExam,'') as Description, A.RefNum as CSlip, Case When LEFT(A.RefNum, 2) = 'OR' Then Cast(A.Amount as Varchar) Else '' End as Cash, Case When LEFT(A.RefNum, 2) <> 'OR' Then Cast(A.Amount as Varchar) Else '' End as Charge, @UserID From Billing..tbBillOpDailyOut A Left Outer Join (Select X.Idnum, X.HospNum, isnull(LastName,'') + ', ' + isnull(FirstName,'') as PatientName From Patient_Data..tbOutPatient X Left Outer Join Patient_Data..tbMaster Y On X.HospNum = Y.HospNum) B On A.Idnum = B.Idnum Left Outer Join Billing..tbCashOrMaster D On A.Refnum = D.Refnum Left Outer Join Build_File..tbCoCtExam C On A.ItemID = C.CTExamID Where A.RevenueID = 'CT' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' END IF @RevenueID = 'US' BEGIN INSERT tbRadioTransReport Select B.PatientName, isnull(C.UltraExam,'') as Description, A.RefNum as CSlip, '' as Cash, Cast(A.Amount as Varchar) as Charge, @UserID From Billing..tbBillDailybill A Left Outer Join (Select X.Idnum, X.HospNum, isnull(LastName,'') + ', ' + isnull(FirstName,'') as PatientName From Patient_Data..tbPatient X Left Outer Join Patient_Data..tbMaster Y On X.HospNum = Y.HospNum) B On A.Idnum = B.Idnum Left Outer Join Build_File..tbCoUltraExam C On A.ItemID = C.UltraExamID Where A.RevenueID = 'US' and TransDate Between @StartDate and @EndDate + ' 23:59:59.99' ; INSERT tbRadioTransReport Select Case When Not B.PatientName = '' Then B.PatientName Else D.PaymentFrom End as PatientName, isnull(C.UltraExam,'') as Description, A.RefNum as CSlip, Case When LEFT(A.RefNum, 2) = 'OR' Then Cast(A.Amount as Varchar) Else '' End as Cash, Case When LEFT(A.RefNum, 2) <> 'OR' Then Cast(A.Amount as Varchar) Else '' End as Charge, @UserID From Billing..tbBillOpDailyOut A Left Outer Join (Select X.Idnum, X.HospNum, isnull(LastName,'') + ', ' + isnull(FirstName,'') as PatientName From Patient_Data..tbOutPatient X Left Outer Join Patient_Data..tbMaster Y On X.HospNum = Y.HospNum) B On A.Idnum = B.Idnum Left Outer Join Billing..tbCashOrMaster D On A.Refnum = D.Refnum Left Outer Join Build_File..tbCoUltraExam C On A.ItemID = C.UltraExamID Where A.RevenueID = 'US' and A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_GetTransReport] @UserId varchar(10) AS select PatientName, Examination, ORNo, cast(cash as money) as Cash, Cast(Charge as money) as Charge from tbRadioTransReport where userid = @UserID; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_PARS_RepStatementOfAccountDepartmental] @IDNum as Varchar(10) AS /* declare @IDNum as Varchar(10) set @IDNum = '539661' */ Declare @Billingdate as varchar(10) IF isnumeric(@IDNum) = 1 BEGIN Set @BillingDate = (Select convert(varchar(10),BillingDate,101) from Patient_Data..tbPatient where IDNum = @IDNum) select X.RevenueID,TransDate, HospNum, IDNum, RefNum, Quantity, Description, Charges, Credit, ItemID, X.RevenueID, X.RoomAccomodation, Department, EmployeeName,AccountNum, Patient_Data.dbo.fn_getCompleteAddress(HospNum) Address, billing.dbo.fn_getpatientsname(Hospnum) PatientName, isnull(Radiology.dbo.fn_GetCompanyName(AccountNum),'NON-MEMBER') CompanyName, ReportOrder = (Case When C.DRCR = 'D' and C.RevenueID not in ('RA', 'MJ') then '1 - HB CHARGES' When C.DRCR = 'D' and C.RevenueID = 'RA' then '2 - ROOM AND BOARD' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID not in ('SS', 'DE', 'PP', 'PY') then '3 - HB CREDIT' When C.DRCR = 'P' and C.RevenueID = 'MD' then '4 - DOCTOR CHARGES' When C.DRCR = 'P' and C.RevenueID <> 'MD' then '5 - DOCTOR CREDITS' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID = 'SS' then '6 - MEDICARE' When C.DRCR = 'C' and C.RevenueID in ('DE', 'PP','PY') then '7 - PAYMENTS' End), OrderName = (Case When C.DRCR = 'D' and C.RevenueID not in ('RA', 'MJ') then 'HB CHARGES' When C.DRCR = 'D' and C.RevenueID = 'RA' then 'ROOM AND BOARD' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID not in ('SS', 'DE', 'PP', 'PY') then 'HB CREDIT' When C.DRCR = 'P' and C.RevenueID = 'MD' then 'DOCTOR CHARGES' When C.DRCR = 'P' and C.RevenueID <> 'MD' then 'DOCTOR CREDITS' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID = 'SS' then 'MEDICARE' When C.DRCR = 'C' and C.RevenueID in ('DE', 'PP','PY') then 'PAYMENTS' End) from ( Select convert(varchar(10),TransDate,101) as TransDate, HospNum, IDNum, RefNum, Case when Quantity = 0 then '' else Quantity end as Quantity, Description, Cast(isnull(Charges,0) as Money) as Charges, Cast(isnull(Credit,0) as Money) as Credit, ItemID, RevenueID, 0 as RoomAccomodation, Department, Billing.dbo.fn_getemployeename(UserID) as EmployeeName, AccountNum from Billing..BillingDrugsSOA Where RevenueID in ('PH', 'PC', 'CS', 'CC') and IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) UNION ALL Select convert(varchar(10),TransDate,101) as TransDate, HospNum, IDNum, RefNum, Case when Quantity = 0 then '' else Quantity end as Quantity, Case When RevenueID in ('CP','PP','DE','PY') Then Description + ' (' + RefNum + ')' Else Description End as Description, Cast(isnull(Charges,0) as Money) as Charges, Cast(isnull(Credit,0) as Money) as Credit, ItemID, RevenueID, RoomAccomodation, Department, billing.dbo.fn_getemployeename(UserID) as EmployeeName, AccountNum from Billing..BillingOthersSOA Where IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) --and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC', 'BB', 'TB') )X left Outer Join Build_File..tbCoRevenueCode C on X.RevenueID = C.RevenueID --where not(Charges = 0.00 and Credit = 0.00) --order by ReportOrder END ELSE BEGIN Set @BillingDate = (Select convert(varchar(10),BillingDate,101) from Patient_Data..tbOutPatient where IDNum = @IDNum) select TransDate, HospNum, IDNum, RefNum, Quantity, Description, Charges, Credit, ItemID, X.RevenueID, X.RoomAccomodation, Department, EmployeeName, AccountNum, Patient_Data.dbo.fn_getCompleteAddress(HospNum) Address, billing.dbo.fn_getpatientsname(Hospnum) PatientName, isnull(Radiology.dbo.fn_GetCompanyName(AccountNum),'NON-MEMBER') CompanyName, ReportOrder = (Case When C.DRCR = 'D' and C.RevenueID not in ('RA', 'MJ') then '1 - HB CHARGES' When C.DRCR = 'D' and C.RevenueID = 'RA' then '2 - ROOM AND BOARD' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID not in ('SS', 'DE', 'PP', 'PY') then '3 - HB CREDIT' When C.DRCR = 'P' and C.RevenueID = 'MD' then '4 - DOCTOR CHARGES' When C.DRCR = 'P' and C.RevenueID <> 'MD' then '5 - DOCTOR CREDITS' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID = 'SS' then '6 - MEDICARE' When C.DRCR = 'C' and C.RevenueID in ('DE', 'PP','PY') then '7 - PAYMENTS' End), OrderName = (Case When C.DRCR = 'D' and C.RevenueID not in ('RA', 'MJ') then 'HB CHARGES' When C.DRCR = 'D' and C.RevenueID = 'RA' then 'ROOM AND BOARD' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID not in ('SS', 'DE', 'PP', 'PY') then 'HB CREDIT' When C.DRCR = 'P' and C.RevenueID = 'MD' then 'DOCTOR CHARGES' When C.DRCR = 'P' and C.RevenueID <> 'MD' then 'DOCTOR CREDITS' When C.DRCR = 'C' and C.LGRP = 'L' and C.RevenueID = 'SS' then 'MEDICARE' When C.DRCR = 'C' and C.RevenueID in ('DE', 'PP','PY') then 'PAYMENTS' End) from ( Select convert(varchar(10),TransDate,101) as TransDate, HospNum, IDNum, RefNum, Quantity, Description, Cast(isnull(Charges,0) as Money) as Charges, Cast(isnull(Credit,0) as Money) as Credit, ItemID, RevenueID, 0 as RoomAccomodation, Department, Billing.dbo.fn_getemployeename(UserID) as EmployeeName, AccountNum from Billing..OPBillingDrugsSOA Where RevenueID in ('PH', 'PC', 'CS', 'CC') and IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) UNION ALL Select convert(varchar(10),TransDate,101) as TransDate, HospNum, IDNum, RefNum, Quantity, Case When RevenueID in ('CP','PP','DE','PY') Then Description + ' (' + RefNum + ')' Else Description End as Description, Cast(isnull(Charges,0) as Money) as Charges, Cast(isnull(Credit,0) as Money) as Credit, ItemID, RevenueID, 0 as RoomAccomodation, Department, Billing.dbo.fn_getemployeename(UserID) as EmployeeName, AccountNum from Billing..OPBillingOthersSOA Where IDNum = @IDNum and (TransDate < = @Billingdate + ' 23:59:59.99' or BillingDate is null) --and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC', 'BB', 'TB') )X left Outer Join Build_File..tbCoRevenueCode C on X.RevenueID = C.RevenueID --where not(Charges = 0.00 and Credit = 0.00) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Radio_CashAssessmentInfo] --declare @Option as varchar(1), --1.Cash Patient, 2.RegularPatient, 3. ConfinedPatient @Option2 as varchar(1), --1. Search by Lastname, 2. Search by ID @Search as varchar(30) -- Search String AS /*Declare @Option as varchar(1); --Cash Patient Declare @Option2 as varchar(1); Declare @Search as varchar(30); set @Option = '1'; set @Option2 = '2'; set @Search = 'T82'; */ If @Option = '1' Begin If @Option2 = '1' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, Convert(varchar(10),BirthDate, 101) BirthDate, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbCashPatient A Where Lastname Like @Search + '%' Order By LastName, FirstName; End; If @Option2 = '2' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age From Patient_Data..tbCashPatient A Where HospNum = @Search; End; End; If @Option = '2' Begin If @Option2 = '1' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address] From Patient_Data..tbMaster A Where Lastname Like @Search + '%' Order By LastName, FirstName; End; If @Option2 = '2' Begin Select 'CASH'[IDNum], HospNum, LastName, FirstName, MiddleName, ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = A.ZipCode),'') [Address], HouseStreet, Barangay, Sex, BirthDate, CivilStatus as CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age From Patient_Data..tbMaster A Where HospNum = @Search; End; End; If @Option = '3' Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And DcrDate is null Order By LastName, FirstName; End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where A.IDnum = @Search And DcrDate is null; End; End; If @Option = '4' ---- Out Patient Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress isnull Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) And BillingDate is null And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101) AND A.PatientType <> 'C' --January 26'06 Order By LastName, FirstName; End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where A.IDnum = @Search And BillingDate is null -- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; End; If @Option = '5' ---- Out Patient Billed Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) --And BillingDate is null --And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101) Order By LastName, FirstName; End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age, A.Expirationdate From Patient_Data..tbOutPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where A.IDnum = @Search --And BillingDate is null -- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; End; If @Option = '6' ---- inpatient Begin If @Option2 = '1' Begin Select A.Idnum [IDNum], A.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address] From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where (B.Lastname Like @Search + '%' Or B.HospNum = @Search) --And BillingDate is null --- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101) Order By LastName, FirstName; End; If @Option2 = '2' Begin Select A.IDNum [IDNum], B.HospNum, B.LastName, B.FirstName, B.MiddleName, B.ZipCode, Isnull((Select Top 1 Town + ' ,' + Province From Build_File..tbCoAddress Where ZipCode = B.ZipCode),'') [Address], B.HouseStreet, B.Barangay, B.Sex, B.BirthDate, B.CivilStatus as CivilStatusID, dbo.fn_ComputeAge(BirthDate,getdate()) as Age From Patient_Data..tbPatient A Left Outer Join Patient_Data..tbMaster B On A.HospNum = B.Hospnum Where a.idnum = @Search --And BillingDate is null -- And Convert(Varchar(10),A.AdmDate, 101) = Convert(Varchar(10),getdate(), 101); End; End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* Created by : Jetty P. OMo Details : Use to save turn around time Date : June 17,2008 */ CREATE PROCEDURE [dbo].[Radio_Save_TAT] @Revenueid varchar(5), @Itemid varchar(10), @InHours int = 0, @InMinutes int = 0, @OutHours int = 0, @OutMinutes int = 0, @Active bit, @UserID varchar(10) AS Begin Tran; if exists(select top 1 * from Radiology..tbBuildTAT where ItemID = @ItemID and Revenueid = @Revenueid) begin update Radiology..tbBuildTAT set InHours = @InHours,InMinutes = @InMinutes,OutHours = @OutHours,OutMinutes = @OutMinutes, Active = @Active,UserID = @UserID where ItemID = @ItemID and Revenueid = @Revenueid end else begin insert into Radiology..tbBuildTAT (ItemID, InHours, InMinutes,OutHours, OutMinutes,Active,UserID,Revenueid) values (@ItemID, @InHours, @InMinutes,@OutHours, @OutMinutes,@Active,@UserID,@Revenueid) end --SELECT * FROM tbBuildTAT If @@Error <> 0 Begin goto SaveError; End Commit Tran; Return 0; SaveError: Rollback Tran; Return @@Error; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO --BSJ March 13, 2003 5:59PM For Discount Computation --updated March 28, 2003 CREATE PROCEDURE [dbo].[spRadio_GetDiscount] @RevenueID as varchar(2), @ItemID as varchar(10), @DiscountType as varchar(2), @MSSCode as varchar(2), @WithMarkUp as bit = 0 AS declare @Senior as bit declare @MSS as bit declare @Price as float declare @NetAmount as float declare @Discount as Float declare @Location as varchar(2) declare @RevenueType as varchar(1) set @Senior = (SELECT RADIOLOGY.dbo.fn_SeniorDiscounted(@RevenueID,@ItemID)) --Determines if item is senior discounted set @MSS = (SELECT RADIOLOGY.dbo.fn_MSSDiscounted(@RevenueID,@ItemID)) --Determines if item is MSS discounted accdg. to patient mss class /*@RevenueType is used to determine if the revenue is a procedure, supply or medicine. This is necessary in the computation for the MSS Discount*/ /* @RevenueType values: A = Procedures; B=Medicines; C=Supplies */ if @RevenueID = 'XR' -- X-Ray Procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoXrayExam WHERE XrayExamID = @ItemID) end; if @RevenueID = 'CT' -- CT Scan Procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoCTExam WHERE CTExamID = @ItemID) end; if @RevenueID = 'UL' --UltraSound procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoUltraExam WHERE UltraExamID = @ItemID) end; if @RevenueID = 'NU' --Nuclear procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoNucExam WHERE NucExamID = @ItemID) end; if @RevenueID = 'HS' --Cardiovascular procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoHSExam WHERE HsExamID = @ItemID) end; if @RevenueID = 'PT' --Physical Therapy procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoPTExam WHERE PTExamID = @ItemID) end; if @RevenueID = 'LB' -- Laboratory procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoLabExam WHERE LabExamID = @ItemID) end; if @RevenueID = 'PA' --Pulmonary procedures begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoRtsExam WHERE RtsExamID = @ItemID) end; if @RevenueID in ('OR' ,'DI','NE','ER','IC') begin set @RevenueType = 'A' set @Price = (SELECT RateA FROM BUILD_FILE..tbCoOtherRevenue WHERE OtherRevenueID = @ItemID and OtherSectionID = @RevenueID) end; if @RevenueID in ('RU','HP','CS','HU','KS','OS','XS','CU','UU','RS','SO','IO','CA') -- Supplies begin set @RevenueType = 'C' set @Price = (SELECT SellingPriceOut FROM INVENTORY..tbInvent A left outer join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID WHERE ItemID = @ItemID and B.RevenueID = @RevenueID) end; if @RevenueID in ('RN','PH','RM','HM','XN','CN','UN','OM','RM','CQ') -- Medicine begin set @RevenueType = 'B' set @Price = (SELECT SellingPriceOut FROM INVENTORY..tbInvent A left outer join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID WHERE ItemID = @ItemID and B.RevenueID = @RevenueID) end; If @WithMarkUp=1 Set @Price = @Price * 1.25; /**** Computation of Discount *****/ if @DiscountType = 'SM' begin if @Senior = 1 begin set @Discount = @Price * 0.20 set @NetAmount = @Price - @Discount end; else begin set @Discount = 0 set @NetAmount = @Price end; end; --Is QFS / Med.Social Service Discount if @DiscountType = 'QF' begin if @MSS = 1 begin set @Discount = (SELECT RADIOLOGY.dbo.fn_MSSDiscount(@Price,@MSSCode,@RevenueType)) set @NetAmount = @Price - @Discount end; else begin set @Discount = @Price * 0.20 set @NetAmount = @Price - @Discount end; end; -- Government Employee Discount if @DiscountType = 'GE' begin set @Discount = @Price * 0.20 set @NetAmount = @Price - @Discount end; -- Government Employee Dependent Discount if @DiscountType = 'GD' begin set @Discount = @Price * 0.10 set @NetAmount = @Price - @Discount end; -- NKTI Employee Discount if @DiscountType = 'KE' begin if @RevenueType = 'A' --Procedures begin set @Discount = @Price * 0.50 set @NetAmount = @Price - @Discount end; if @RevenueType in ('B','C') --Medicines & Supplies begin set @Discount = @Price * 0.20 set @NetAmount = @Price - @Discount end; end; -- NKTI Employee Dependent Discount if @DiscountType = 'KD' begin if @RevenueType = 'A' --Procedures begin set @Discount = @Price * 0.25 set @NetAmount = @Price - @Discount end; else if @RevenueType in ('B','C') --Medicines & Supplies begin set @Discount = @Price * 0.10 set @NetAmount = @Price - @Discount end; end; if @DiscountType = '' begin set @Discount = 0 set @NetAmount = @Price end; select cast(isnull(@Price,0) as money) as Price, cast(Isnull(@Discount,0) as money) as Discount, cast(Isnull(@NetAmount,0) as money) as NetAmount GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveResultCalcium] @Idnum varchar(10), @Hospnum varchar(10), @RequestNum varchar(10), @Lession1 varchar(15), @Lession2 varchar(15), @Lession3 varchar(15), @Lession4 varchar(15), @Lession5 varchar(15), @Volume1 varchar(15), @Volume2 varchar(15), @Volume3 varchar(15), @Volume4 varchar(15), @Volume5 varchar(15), @Mass1 varchar(15), @Mass2 varchar(15), @Mass3 varchar(15), @Mass4 varchar(15), @Mass5 varchar(15), @Score1 varchar(15), @Score2 varchar(15), @Score3 varchar(15), @Score4 varchar(15), @Score5 varchar(15), @Reference1 varchar(15), @Reference2 varchar(15), @Reference3 varchar(15), @Reference4 varchar(15), @Reference5 varchar(15), @Commentary text AS If Exists(Select * from tbCtResultCalcium Where RequestNum = @RequestNum) Begin Update tbCtResultCalcium Set Idnum = @Idnum, Hospnum = @Hospnum, RequestNum = @RequestNum, Lession1 = @Lession1, Lession2 = @Lession2, Lession3 = @Lession3, Lession4 = @Lession4, Lession5 = @Lession5, Volume1 = @Volume1, Volume2 = @Volume2, Volume3 = @Volume3, Volume4 = @Volume4, Volume5 = @Volume5, Mass1 = @Mass1, Mass2 = @Mass2, Mass3 = @Mass3, Mass4 = @Mass4, Mass5 = @Mass5, Score1 = @Score1, Score2 = @Score2, Score3 = @Score3, Score4 = @Score4, Score5 = @Score5, Reference1 = @Reference1, Reference2 = @Reference2, Reference3 = @Reference3, Reference4 = @Reference4, Reference5 = @Reference5, Commentary = @Commentary Where RequestNum = @RequestNum; End; Else Begin Insert Into tbCtResultCalcium(Idnum,Hospnum,RequestNum,Lession1,Lession2,Lession3,Lession4,Lession5, Volume1,Volume2,Volume3,Volume4,Volume5, Mass1,Mass2,Mass3,Mass4,Mass5, Score1,Score2,Score3,Score4,Score5, Reference1,Reference2,Reference3,Reference4,Reference5,Commentary) Values(@Idnum,@Hospnum,@RequestNum,@Lession1,@Lession2,@Lession3,@Lession4,@Lession5, @Volume1,@Volume2,@Volume3,@Volume4,@Volume5, @Mass1,@Mass2,@Mass3,@Mass4,@Mass5, @Score1,@Score2,@Score3,@Score4,@Score5, @Reference1,@Reference2,@Reference3,@Reference4,@Reference5, @Commentary); End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_MammographyReport_WC] --@RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS --set @revenueid='xr' --set @FirstDay= '10/01/2005' --set @LastDay ='10/20/2005' DECLARE @StartDate datetime, @EndDate datetime, @Revenueid as varchar(2) set @Revenueid = 'WC' SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) Select distinct b.refnum, sum(b.amount) Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity , b.itemid, max(Case @RevenueID when 'WC' then e.OtherRevenue End) as exam, max(b.userid) UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum) as IDNum, max(p.hospnum) HospNum, max(m.lastname + ', ' + m.firstname) patient, max(R.RadCode)RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbilldailybill b Left Join Build_File..tbCoOtherRevenue E on B.itemID = E.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum inner join (Select distinct Refnum,radcode From radiology..tbUlrequest A Inner Join radiology..tbUlresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoOtherRevenue C on B.ItemCode = C.OtherRevenueid where C.sectionid ='MMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.sectionid ='MMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 union all Select max(b.refnum) as Refnum, sum(b.amount) as Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity, b.itemid, max(Case @RevenueID when 'WC' then e.OtherRevenue End) as exam, max(b.userid) as UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)Idnum, max(p.hospnum) Hospnum, max(Case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom End) as patient, max(R.RadCode) RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbillopdailyout b left Join build_file..tbCoOtherRevenue E on B.ItemID = E.OtherRevenueId left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum inner join (Select distinct Refnum,radcode From radiology..tbUlrequest A Inner Join radiology..tbUlresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoOtherRevenue C on B.ItemCode = C.OtherRevenueID where C.sectionid ='MMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.sectionid ='MMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 Order by b.transdate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_MammographyReport_WC_thanex] --@RevenueID varchar(2), @FirstDay varchar(10), @LastDay varchar(10) AS --set @revenueid='xr' --set @FirstDay= '10/01/2005' --set @LastDay ='10/20/2005' DECLARE @StartDate datetime, @EndDate datetime, @Revenueid as varchar(2) set @Revenueid = 'WC' SET @StartDate = CONVERT(datetime, @FirstDay, 101) SET @EndDate = DATEADD(day, 1, CONVERT(datetime, @LastDay, 101)) Select distinct b.refnum, sum(b.amount) Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity , b.itemid, max(Case @RevenueID when 'WC' then e.OtherRevenue End) as exam, max(b.userid) UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum) as IDNum, max(p.hospnum) HospNum, max(m.lastname + ', ' + m.firstname) patient, max(R.RadCode)RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbilldailybill b Left Join Build_File..tbCoOtherRevenue E on B.itemID = E.OtherRevenueID left join patient_data..tbpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum inner join (Select distinct Refnum,radcode From radiology..tbUlrequest A Inner Join radiology..tbUlresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoOtherRevenue C on B.ItemCode = C.OtherRevenueid where C.sectionid ='MMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.sectionid ='MMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 union all Select max(b.refnum) as Refnum, sum(b.amount) as Amount, max(Case When isnull(b.quantity, 1) = 0 Then 1 Else b.Quantity End) as Quantity, b.itemid, max(Case @RevenueID when 'WC' then e.OtherRevenue End) as exam, max(b.userid) as UserID, max(Convert(varchar(10), b.transdate, 101)) transdate, max(b.idnum)Idnum, max(p.hospnum) Hospnum, max(Case when p.idnum is not null then m.lastname + ', ' + m.firstname else z.paymentfrom End) as patient, max(R.RadCode) RadCode, max(D.lastName + ', ' + D.FirstName + ' ' + D.MIddleName) Reader From billing..tbbillopdailyout b left Join build_file..tbCoOtherRevenue E on B.ItemID = E.OtherRevenueId left join patient_data..tboutpatient p on b.idnum = p.idnum left join patient_data..tbmaster m on p.hospnum = m.hospnum left join billing..tbcashormaster z on b.refnum = z.refnum inner join (Select distinct Refnum,radcode From radiology..tbUlrequest A Inner Join radiology..tbUlresult B on A.RequestNum = B.RequestNum Left Join build_file..tbcoOtherRevenue C on B.ItemCode = C.OtherRevenueID where C.sectionid ='MMM' ) R on b.refnum = R.Refnum Left Join Build_File..tbcoDoctor D on D.DoctorID = R.RadCode Where b.transdate >= @StartDate and b.transdate < @EndDate and b.revenueid = @RevenueID and E.sectionid ='MMM' group by B.Refnum, B.ItemID having sum(b.amount) > 0 Order by b.transdate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_UpdateInterpret] @RevenueID varchar(2), @Code varchar(10), @Description varchar(50), @SectionID varchar(3), @Interpretation text AS if @RevenueID = 'WC' begin update tbOBInterpretation set Code = @code, Description = @Description, SectionID = @SectionID, Interpretation = @Interpretation where Code = @Code end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ViewInterpretation] @RevenueID varchar(2), @Criteria varchar(50) AS if @RevenueID = 'WC' begin select Code, Description from tbOBInterpretation where Description like @Criteria + '%' Order by Description end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_InsertInterpret] @RevenueID varchar(2), @Code varchar(10), @Description varchar(50), @SectionID varchar(3), @Interpretation text AS declare @NewCode as varchar(10) if @RevenueID = 'WC' begin select @NewCode = max(cast(Code as int)) + 1 from tbOBInterpretation where isnumeric(Code) = 1 insert into tbOBInterpretation (Code, Description, SectionID, Interpretation) values (@NewCode, @Description, @SectionID, @Interpretation) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ResultPrint] @Patient AS varChar(90), @HospNum AS varChar(10), @Doctor AS varChar(60), @Examination AS varChar(60), @CivilStatus AS varChar(15), @Age AS varChar(3), @Sex AS varChar(6), @AdmNum AS varChar(10), @CTNum AS varChar(10), @RoomNo AS varChar(25), @ExamDate AS DateTime, @Interpretation AS Text, @Radiologist AS varChar(60), @Address AS varChar(60), @TelNo AS varChar(15), @FileNum AS varChar(10), @ControlNum AS varChar(10), @UserID AS varchar(10), @Radiologist2 AS varchar(60), @Remarks AS text , @Tracing as varchar(1) = '', @RadiologyID as varchar(10) = '' AS DECLARE @cHospNum as varchar(10) if @Hospnum = 'CASH' begin SET @cHospNum = 'OPD' end else begin SET @cHospNum = @HospNum end DELETE tbOBPrintResult WHERE UserID = @UserID and AdmNum = @AdmNum INSERT INTO tbOBPrintResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks, Tracing, RadiologyID) VALUES (@Patient, @cHospNum, @Doctor, @Examination, @CivilStatus, @Age, @Sex, @AdmNum, @CTNum, ltrim(rtrim(@RoomNo)), @ExamDate,replace(cast(@Interpretation as varchar(5000)),'`',''''), @Radiologist, @Address, @TelNo, @FileNum, @ControlNum, @UserID, @Radiologist2, @Remarks, @Tracing, @RadiologyID) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SearchFileNum] @RevenueID varchar(10), @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin if @RevenueID = 'WC' begin select OBUltraNum [File No.], LastName [Last Name], FirstName [First Name], MiddleName [Middle Name], ControlNum [Control] from tbOBULFileNum where LastName like @SearchCriteria + '%' order by LastName, FirstName, MiddleName end end if @SearchType = '1' begin if @RevenueID = 'WC' begin select OBUltraNum [FileNum], LastName, FirstName, MiddleName, ControlNum, HospNum from tbOBULFileNum where OBUltraNum = @SearchCriteria end end if @SearchType = '2' begin if @RevenueID = 'WC' begin select OBUltraNum [FileNum] from tbOBULFileNum where HospNum = @SearchCriteria end end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_InDailyRep Script Date: 07/01/2000 1:20:54 AM ******/ CREATE PROCEDURE [dbo].[spRadio_InDailyRep] @Date AS varChar(10), @UserID as varchar(10) AS Declare @ReportDate1 datetime declare @ReportDate2 datetime set @ReportDate1 = cast(@Date as datetime) set @ReportDate2 = dateadd(day, 1, @ReportDate1) DELETE tbXRDailyRep WHERE UserID = @UserID; INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XRayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE isnumeric(tbXRRequest.IDNUm) = 1 --tbXRRequest.RoomId <> 'OPD' -- AND CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date AND (tbXRRequest.TransDate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.spRadio_OutDailyRep Script Date: 07/01/2000 1:20:56 AM ******/ CREATE PROCEDURE [dbo].[spRadio_OutDailyRep] @Date AS varChar(10), @UserID as varchar(10) AS DECLARE @ReportDate1 datetime, @ReportDate2 datetime SET @ReportDate1 = @Date SET @ReportDate2 = DATEADD(day, 1, @ReportDate1) DELETE tbXRDailyRep WHERE UserID = @UserID; INSERT tbXRDailyRep SELECT RTRIM(m.LastName) + ', ' + RTRIM(m.FirstName) AS PatientName, tbXRRequest.RoomID, -- tbXRRequest.TypeDescription AS Description, E.XrayExam as Description, tbXRRequest.Refnum AS CSlip, CONVERT(varChar(12),tbXRRequest.Amount) AS Amount, (Film8 + Film10 + Film11 + Film14 + Film17) AS FilmUsed, Film8, Film10, Film11, Film14, Film17, LEFT(tbCoDoctor.Firstname, 1) + '. ' + tbCoDoctor.Lastname AS Physician, @UserID, Film1, Film2, Film3, Film4, Film5, Film6, Film7 FROM tbXRRequest LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbXRRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN vwPatientMaster m ON tbXRRequest.HospNum = m.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoXRayExam E ON tbXRRequest.Code = E.XRayExamID WHERE --tbXRRequest.RoomId = 'OPD' AND /*CONVERT(varChar(10), tbXRRequest.Transdate, 101) = @Date */ ISNUMERIC(tbXRRequest.IDNum) = 0 AND (tbXRRequest.Transdate >= @ReportDate1 AND tbXRRequest.TransDate < @ReportDate2) AND (tbXRRequest.SwFin ='Y' OR tbXRRequest.SwFin = 'X') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBULI_DoctorChargeCancel] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10) AS declare @DeptCode as varchar(2) declare @Hospnum as varchar(10), @RoomID as varchar(10) DECLARE @RequestNum AS varChar(8) if isnumeric(@IDNum) = 1 begin Select @Hospnum = HospNum, @RoomID = RoomID From Patient_Data..tbPatient Where IDNum = @IDNum; end else begin Select @Hospnum = HospNum, @RoomID = 'OPD' From Patient_Data..tbOutPatient Where IDNum = @IDNum end Update tbOBULRequest set SWFIN = 'C' Where IDNum = @IDNum and RefNum = @RefNum and Code = @ItemID; IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '', @DeptCode ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @DeptCode) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_LoadChargeSlip] @DepartmentID varchar(2), @RefNum varchar(10) --SET @DepartmentID = 'WC' --SET @RefNum = 'C24650W' AS if @DepartmentID = 'WC' begin select r.RequestNum, r.Code, case when r.RevenueID = 'WC' then e.OtherRevenue when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') when len( isnull(rev.LocationID, '') ) > 0 then m.ItemName + ' ' + isnull(m.ItemDesc, '') else rev.ItemName end ItemDesc, r.Quantity, r.Amount, r.RevenueID, rev.LocationID, b.RevenueID [InventoryCode] from tbOBULRequest r left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID left join BUILD_FILE..tbcoOtherRevenue e on r.Code = e.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID WHere r.RefNum = @RefNum and isnull(R.SWFIN,'X') = 'X' order by r.TransDate end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_DailyCensus] @ReportDate varchar(10) AS declare @begindate as datetime declare @enddate as datetime --set @ReportDate ='07/04/2007' set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) Begin select q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], Case Isnumeric(q.idnum) when 0 then 'OPD' else p.roomid end room, q.refnum as Refnum, Case isnull(Q.RevenueID, 'WC') when 'MD' Then 'DR. ' + g.lastname + ', ' + g.firstname + ' ' + isnull(g.middlename,'') when 'WC' then e.OtherRevenue Else inv.ItemName End [exam], q.quantity as Quantity, q.amount as Amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as RequestDoc from tbOBULRequest q left join BUILD_FILE..tbcoOtherRevenue e on q.code = e.OtherRevenueID left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum left join BUILD_FILE..tbcodoctor g on q.code = g.doctorid left Join Inventory..tbInvmaster Inv on q.code = Inv.itemid where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and Right(q.Idnum,1) <> 'B' end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_OutCancellation2] @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10), @RevenueID AS varChar(2) AS DECLARE @RoomID as varchar(10) DECLARE @Quantity as float DECLARE @RequestDocID as varchar(10) BEGIN /* Search for existing RefNum */ SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbobULRequest WHERE RequestNum = @RequestNum /* Update Record Status */ UPDATE tbOBULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_RequestTransaction] @RevenueID as varchar(2) As DECLARE @StartDate as varchar(10) set @StartDate = convert(varchar(10),getdate(),101) SELECT A.TransDate as [Transaction Date], A.HospNum as [Hosp. No.], A.IdNum as [Adm. No.], A.[Name] as PatientName, A.ItemID, case isnull(A.revenueID,'') when 'MD' then D.Lastname + ', ' + D.FirstName + ' ' + D.MiddleName else case isnull(R.LocationID,'') when '' then E.Description else I.ItemName end end as ExamName, A.Quantity as Qty, convert(varchar,cast(A.Amount as Money)) as Amount, A.ORNumber as Refnum , isnull(A.printed,'N') as Printed FROM BILLING..tbCashAssessment A LEFT OUTER JOIN BUILD_fILE..tbCoRevenueCode R on A.RevenueID = R.RevenueID LEFT OUTER JOIN BILLING..tbBillExamListing E on A.ItemID = E.ItemID and A.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster I on A.ItemID = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on A.ItemID = D.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on A.UserID = PW.EmployeeID LEFT OUTER JOIN PATIENT_DATA..tbPatient P on A.IdNum = P.IdNum WHERE (A.RevenueID = @RevenueID OR A.DepartmentID = @RevenueID) and A.RecordStatus = '1' and A.TransDate between @StartDate and Getdate() Union All select TransDate, A.HospNum as [Hosp. No.], A.IdNum as [Adm. No.], M.LastName + ', ' + M.FirstName + ' ' + M.MiddlEName as PatientName, A.Code, case isnull(A.revenueID,'') when 'MD' then D.Lastname + ', ' + D.FirstName + ' ' + D.MiddleName else case isnull(R.LocationID,'') when '' then E.Description else I.ItemName end end as ExamName, A.Quantity as Qty, convert(varchar,cast(A.Amount as Money)) as Amount, A.Refnum as Refnum, isnull(A.printed,'') as Printed from Radiology..tbOBULRequest A LEFT OUTER JOIN BUILD_fILE..tbCoRevenueCode R on A.RevenueID = R.RevenueID Left Outer Join Patient_data..tbMaster M On A.HospNum = M.HospNum LEFT OUTER JOIN BILLING..tbBillExamListing E on A.Code = E.ItemID and A.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster I on A.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on A.Code = D.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on A.[BY] = PW.EmployeeID where A.RevenueID = @RevenueID and A.SWFin <> 'C' and A.TransDate between @StartDate and Getdate() GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --- By Jerome D. Otanes 08/09/2007 CREATE PROCEDURE [dbo].[spOB_PrintRequestTransaction] @RevenueID as varchar(2), @HospNum as varchar(10), @Refnum as varchar(10) /*set @revenueID = 'wc' set @HospNum = '263427' set @REfnum = 'C70W'*/ As DECLARE @StartDate as varchar(10) set @StartDate = convert(varchar(10),getdate(),101) SELECT A.TransDate as [Transaction Date], A.HospNum as [Hosp. No.], A.IdNum as [Adm. No.], A.[Name] as PatientName, A.ItemID, case isnull(A.revenueID,'') when 'MD' then D.Lastname + ', ' + D.FirstName + ' ' + D.MiddleName else case isnull(R.LocationID,'') when '' then E.Description else I.ItemName end end as ExamName, A.Quantity as Qty, convert(varchar,cast(A.Amount as Money)) as Amount, A.ORNumber as Refnum, isnull(A.printed,'') as Printed, RD.LastName + ', '+ RD.FirstName + ' ' + RD.MiddleName as DoctorName, CASE when isnull(P.RoomID,'') = '' then 'OPD' else p.Roomid end as RoomID, PW.LastName + ', ' + Pw.FirstName + ' ' + Pw.MiddleName as Requestby FROM BILLING..tbCashAssessment A LEFT OUTER JOIN BUILD_fILE..tbCoRevenueCode R on A.RevenueID = R.RevenueID LEFT OUTER JOIN BILLING..tbBillExamListing E on A.ItemID = E.ItemID and A.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster I on A.ItemID = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on A.ItemID = D.DoctorID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor RD on A.RequestDocID = RD.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on A.UserID = PW.EmployeeID LEFT OUTER JOIN PATIENT_DATA..tbPatient P on A.IdNum = P.IdNum WHERE (A.RevenueID = @RevenueID OR A.DepartmentID = @RevenueID) and A.RecordStatus = '1' and A.TransDate between @StartDate and Getdate() and A.Hospnum = @HospNum --and (A.[Name] like @SearchText + '%' OR A.ChargeSlip = @SearchText or A.RefNum = @SearchText or A.OrNumber= @SearchText) Union All select TransDate, A.HospNum as [Hosp. No.], A.IdNum as [Adm. No.], M.LastName + ', ' + M.FirstName + ' ' + M.MiddlEName as PatientName, A.Code, case isnull(A.revenueID,'') when 'MD' then D.Lastname + ', ' + D.FirstName + ' ' + D.MiddleName else case isnull(R.LocationID,'') when '' then E.Description else I.ItemName end end as ExamName, A.Quantity as Qty, convert(varchar,cast(A.Amount as Money)) as Amount, A.Refnum as Refnum, isnull(A.printed,'') as Printed, D.Lastname + ', ' + D.FirstName + ' ' + D.MiddleName as DoctorName, CASE when isnull(A.RoomID,'') = '' then 'OPD' else A.Roomid end as RoomID, PW.LastName + ', ' + Pw.FirstName + ' ' + Pw.MiddleName as Requestby from Radiology..tbOBULRequest A LEFT OUTER JOIN BUILD_fILE..tbCoRevenueCode R on A.RevenueID = R.RevenueID Left Outer Join Patient_data..tbMaster M On A.HospNum = M.HospNum LEFT OUTER JOIN BILLING..tbBillExamListing E on A.Code = E.ItemID and A.RevenueID = E.RevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster I on A.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor D on A.RequestDoctorCode = D.DoctorID LEFT OUTER JOIN PASSWORD..tbPasswordMaster PW on A.[by] = PW.EmployeeID where A.RevenueID = @RevenueID and A.SWFin <> 'C' and A.TransDate between @StartDate and Getdate() and A.HospNUm = @HospNum and A.Refnum = @Refnum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_TransReport] @StartDate AS varchar(10), @EndDate AS varchar(10) --set @StartDate ='11/13/2007' --set @EndDate = '11/13/2007' AS SELECT C.TransDate, C.Idnum, CASE WHEN ISNUMERIC(C.HospNum) = 1 THEN isnull(tbMaster.LastName, '') + ', ' + isnull(tbMaster.FirstName, '') ELSE tbCashPatient.LastName + ', ' + tbCashPatient.FirstName END AS PatientName, CASE Revenueid when 'MD' then 'DR. ' + Doc.LastName + ', ' + Doc.FirstName + ' ' + Doc.MiddleName when 'WC' then mri.OtherRevenue else Inv.ItemName end AS Description, C.RefNum as CSlip, CASE WHEN LEFT(C.RefNum, 2) <> 'OR' THEN C.Amount ELSE 0 END As Amount FROM tbOBULRequest C LEFT JOIN PATIENT_DATA..tbMaster tbMaster ON C.HospNum = tbMaster.HospNum LEFT JOIN PATIENT_DATA..tbCashPatient tbCashPatient ON C.HospNum = tbCashPatient.HospNum LEFT JOIN BUILD_FILE..tbcoOtherRevenue mri ON C.Code = mri.OtherRevenueID Left join Build_File..tbcoDoctor Doc on C.Code = Doc.DoctorID Left Join Inventory..tbinvMaster Inv on C.code = Inv.Itemid WHERE C.TransDate BETWEEN @StartDate AND @EndDate + ' 23:59:59' AND ISNULL(C.SwFin,'') <> 'C' ORDER BY C.TransDate GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_InquiryResult] @ReqNum varchar(10) AS SELECT r.ControlNum, e.Description [Examination], r.ResultDate, q.TransDate, q.Code, Q.RequestDoctorCode [DoctorID], d1.FirstName + ' ' + d1.MiddleName + ' ' + d1.LastName [Doctor], r.RadCode [RadiologistID], d2.FirstName + ' ' + d2.MiddleName + ' ' + d2.LastName [Radiologist], r.XRayNum [FileNum], r.RoomID, r.TranscribedByID, r.VerifyByID, r.RadCode2 [CoRadiologistID], r.Remarks, E.SectionID as SectionID, isnull(r.ExamDate, getdate()) ExamDate, q.DoctorName, isnull(r.ResultDate, getdate()) ResultDate fROM tbOBULRequest q left join tbOBULResult r on q.requestnum = r.requestnum left join build_file..tbcodoctor d1 on q.requestdoctorcode = d1.doctorid left join build_file..tbcodoctor d2 on r.radcode = d2.doctorid Left Outer Join Billing..tbBillExamListing e On q.Code = e.ItemID and isnull(q.RevenueID,'WC') = e.RevenueID where q.requestnum = @ReqNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_SaveResult] @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @TransDate AS DateTime, @ResultDate AS DateTime, @RequestDoctorCode AS varChar(4), @RadCode AS varChar(4), @Interpretation AS Text, @RoomID AS varChar(20), @ResultBy AS varChar(8), @Film8 AS Float, @Film10 AS Float, @Film11 AS Float, @Film14 AS Float, @Film17 AS Float, @FileNum AS varChar(10), @ControlNum AS varChar(10), @DoctorID varchar(5), @ExamTaken varchar(100) , @RadCode2 varchar(4), @Remarks text, @ExamDate as DateTime = null, @VerifyByID as varchar(20) = null, @VerifyDate as DateTime = null AS DECLARE @RevenueID AS varChar(2) If isnull(@VerifyByID,'') = '' Begin set @VerifyByID = null; set @VerifyDate = null; End; BEGIN SET @RevenueID = 'WC' INSERT INTO tbOBULResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks, ExamDate, VerifyByID, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks, @ExamDate, @VerifyByID, @VerifyDate) ; UPDATE tbOBULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum; END IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode and isnull(RecordStatus,'')='') BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @ResultBy, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode and isnull(RecordStatus,'')=''; END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_LoadRequest] @RequestNum varchar(10) AS SELECT OB.HospNum AS HospNum, OB.RequestNum AS RequestNum, OB.RefNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, OB.Code AS Code, case isnull(OB.revenueID,'WC') when 'MD' then '(PF) ' + Doc.LastName + ', ' + Doc.FirstName when 'WC' then Build.Description else I.ItemName end AS Description, OBOtherExam.SectionID AS SectionID, OB.IdNum AS IDNum, OB.TransDate AS TransDate, '' AS [8X10], '' AS [10X12], '' AS [11X14], '' AS [14X14], '' AS [14X17], CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE isnull((Select Case When isnull(DrClinic, '') = '' Then 'OPD' Else DRClinic End From Build_File..tbCoDoctor Where DoctorID = RequestDoctorCode), 'OPD') END AS RoomID, OB.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, CASE WHEN LEFT(OB.RefNum, 2) = 'OR' THEN 0 ELSE CASE WHEN ISNUMERIC(tbPatient.IDNum) = 1 THEN ISNULL(tbPatient.BillingDate, 0) ELSE ISNULL(tbOutpatient.BillingDate, 0) END END AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.UltraNum ELSE tbCashPatient.UltraNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], OB.Amount, OB.DoctorName, OB.RevenueID , case when isnumeric(OB.idnum) = 1 then tbPatient.LateCharges else tbOutPatient.LateCharges end as OpenLateCharge FROM tbOBULRequest OB LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON OB.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON OB.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON OB.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON OB.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON OB.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbcoOtherRevenue OBOtherExam ON OB.Code = OBOtherExam.OtherRevenueID LEFT OUTER JOIN INVENTORY..tbInvMaster I ON OB.Code = I.ItemID LEFT OUTER JOIN BUILD_FILE..tbCoDoctor Doc ON OB.Code = DOC.DoctorID LEFT OUTER JOIN Billing..tbBillExamListing Build ON OB.RevenueID = Build.RevenueID and OB.Code = Build.ItemID WHERE OB.RequestNum = @RequestNum GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_ResultFile] @HospNum varchar(8), @RevenueID varchar(2) AS if @RevenueID = 'WC' begin select m.requestnum as [Trans. No] , CONVERT(VARCHAR, cast(m.transdate as datetime), 101) [Exam Date], m.Code [Code], '(' + m.RevenueID + ') ' + z.Description [Exam], Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.TranscribedById)) Technician, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.EditedByID)) EditedBy, Convert(Varchar(30),Cardio.dbo.fn_GetDoctorsName(r.RadCode)) Radiologist, Convert(Varchar(30),Cardio.dbo.fn_GetUserName(r.VerifyById)) VerifyBy, M.formtype from tbOBULRequest m left join tbOBULResult r on m.requestnum = r.requestnum Left Outer Join Billing..tbBillExamListing z On isnull(m.RevenueID,'WC') = z.RevenueID and m.Code = z.ItemID where m.swfin = 'Y' AND m.HospNum = @HospNum order by cast(r.resultdate as datetime) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SaveOBResult] @HospNum AS varChar(8), @IDNum AS varChar(10), @RequestNum AS varChar(10), @ItemCode AS varChar(4), @TransDate AS DateTime, @ResultDate AS DateTime, @RequestDoctorCode AS varChar(4), @RadCode AS varChar(4), @Interpretation AS Text, @RoomID AS varChar(8), @ResultBy AS varChar(8), @Film8 AS Float, @Film10 AS Float, @Film11 AS Float, @Film14 AS Float, @Film17 AS Float, @FileNum AS varChar(10), @ControlNum AS varChar(10), @DoctorID varchar(5), @ExamTaken varchar(100) , @RadCode2 varchar(4), @Remarks text AS DECLARE @RevenueID AS varChar(2) BEGIN SET @RevenueID = 'WC' INSERT INTO tbOBULResult ( HospNum, IDNum, RequestNum, ItemCode, TransDate, ResultDate, RequestDoctorCode, RadCode, Interpretation, RoomID, --VerifyByID, XrayNum, ControlNum, ExamTaken, TranscribedByID, RadCode2, Remarks) --, VerifyDate) VALUES ( @HospNum, @IDNum, @RequestNum, @ItemCode, @TransDate, @ResultDate, @RequestDoctorCode, @RadCode, @Interpretation, @RoomID, --@ResultBy, @FileNum, @ControlNum, @ExamTaken, @ResultBy, @RadCode2, @Remarks) --, getdate()) UPDATE tbOBULRequest SET SwFin = 'Y' , RequestDoctorCode = @DoctorID WHERE RequestNum = @RequestNum END IF EXISTS(SELECT * FROM STATION..tbNurseLogBook WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode) BEGIN UPDATE STATION..tbNurseLogBook SET RecordStatus = 'W', ResultBy = @ResultBy, ResultDate = @ResultDate WHERE HospNum = @HospNum AND IDNum = @IDNum AND RevenueID = @RevenueID AND ItemID = @ItemCode and isnull(RecordStatus,'') = '' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_InCancellation2] @RequestNum AS varChar(8), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @RefNum As varChar(8), @UserID as varchar(10), @RevenueID AS varChar(2) AS DECLARE @Quantity as float DECLARE @RoomID as varchar(10) DECLARE @RequestDocID as varchar(10) BEGIN /* Search for existing RefNum */ SELECT @Quantity = Quantity * (-1), @RoomID = RoomID, @RequestDocID = RequestDoctorCode FROM tbOBULRequest WHERE RequestNum = @RequestNum /* Update Record Status */ UPDATE tbOBULRequest SET SwFin = 'C' WHERE RequestNum = @RequestNum /* Append cancelled RefNum */ INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, UserID, RequestNum, Quantity, RoomID, RequestDocID) VALUES (@Refnum, @IDNum, Getdate(), @ItemID, (@Amount * -1), 'D', @RevenueID, @UserID, @RequestNum, @Quantity, @RoomID, @RequestDocID) END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_DailyOut Script Date: 07/01/2000 1:20:53 AM ******/ CREATE PROCEDURE [dbo].[spMRI_DailyOut] @ReportDate varchar(10), @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime set @begindate = @reportdate -- CAST(@ReportDate as datetime) set @enddate = dateadd(day, 1, @begindate) delete tbMRIDailyReport --where UserID = @UserID; begin insert into tbMRIDailyReport (userid, idnum, patient, roomid, refnum, exam, quantity, amount, physician) select @userid, q.idnum, case when m.hospnum is not null then m.lastname + ', ' + m.firstname + ' ' + m.middlename else c.lastname + ', ' + c.firstname + ' ' + c.middlename end [patient], 'OPD' [roomid], q.refnum, e.OtherRevenue [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbMRIrequest q left join BUILD_FILE..tbcoOtherRevenue e on q.code = e.OtherRevenueID left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum left join PATIENT_DATA..tbcashpatient c on q.hospnum = c.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is null end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_DailyIn] @ReportDate varchar(10), @UserID varchar(10) AS declare @begindate as datetime declare @enddate as datetime --set @ReportDate ='04/21/2005' set @begindate = CONVERT(datetime, @ReportDate, 101) set @enddate = dateadd(day, 1, @begindate) delete tbMRIDailyReport --where UserID = @UserID; insert into tbMRIDailyReport (UserID, IDNum, Patient, RoomID, RefNum, Exam, Quantity, Amount, Physician) select @UserID, q.idnum, m.lastname + ', ' + m.firstname + ' ' + m.middlename [patient], p.roomid, q.refnum, e.OtherRevenue [exam], q.quantity, q.amount, case when d.doctorid is not null then d.lastname + ', ' + d.firstname else '' end as physician from tbMRIRequest q left join BUILD_FILE..tbcoOtherRevenue e on q.code = e.OtherRevenueID left join PATIENT_DATA..tbpatient p on q.idnum = p.idnum left join BUILD_FILE..tbcodoctor d on q.requestdoctorcode = d.doctorid left join PATIENT_DATA..tbmaster m on q.hospnum = m.hospnum where (transdate >= @begindate and transdate < @enddate) and isnull(swfin, '') <> 'C' and p.idnum is not null GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOB_VerifyResult] @RequestNum AS varChar(10), @VerifyByID AS varChar(10), @VerifyDate AS DateTime --with encryption AS BEGIN UPDATE tbOBULResult SET VerifyByID = @VerifyByID, VerifyDate = getdate() WHERE RequestNum = @RequestNum; IF not exists (Select RequestNum from Station..tbComm_AutoPrint where RevenueId = 'WC' and RequestNum = @RequestNum) Begin Insert Into Station..tbComm_AutoPrint (RequestNum, IDNum, HospNum, Room, ItemID, RevenueID, UserID, RequestStatus, StationID, AccessionNum) (Select distinct a.RequestNum, a.IDNum, a.HospNum, a.RoomID, a.Itemcode, 'WC', a.VerifyByID, 'N', c.StationID, null From radiology..tbOBULResult a inner join build_file..tbcoroom c on a.roomid = c.roomid where a.RequestNum = @RequestNum); End END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spOBUL_InquiryInterpret] @ReqNum varchar(10) AS begin select Interpretation, Remarks from tbOBULResult where RequestNum = @ReqNum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_InitCodes] @strResultCode as varchar(2) AS select ResultValue, SortOrder - 1 as SortOrder from tbRadio_DefaultObtetrics where resultcode = @strResultCode order by SortOrder GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO -- 02/27/2003 5:13PM -bsl CREATE PROCEDURE [dbo].[spRadio_DefaultFilm] @strItemId as varchar(10) AS Select XrayExamID, B.Description, FilmCode, FilmQuantity from Build_File..tbCoXrayExam A left outer join Radiology..tbXrFilm B on A.FilmCode = B.Code where XrayExamID = @strItemId GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_ListFileNum] @Criteria varchar(50) AS begin Select MRINum [File #], hospnum [Hosp. #], LastName, Firstname, MiddleName From tbMRIFilenum Where LastName like @Criteria + '%' Order by MRINum end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[Radio_ResultTable] @Mode as varchar(2), @RequestNum as varchar(10), @RevenueID as varchar(2), @FieldName1 as varchar(100) = '', @FieldName2 as varchar(100) = '', @FieldName3 as varchar(100) = '', @FieldName4 as varchar(100) = '', @FieldName5 as varchar(100) = '', @FieldName6 as varchar(100) = '', @FieldName7 as varchar(100) = '', @FieldName8 as varchar(100) = '', @FieldName9 as varchar(100) = '', @FieldName10 as varchar(100) = '', @FieldName11 as varchar(100) = '', @FieldName12 as varchar(100) = '', @FieldName13 as varchar(100) = '', @ResultGrid1 as varchar(100) = '', @ResultGrid2 as varchar(100) = '', @ResultGrid3 as varchar(100) = '', @ResultGrid4 as varchar(100) = '', @ResultGrid5 as varchar(100) = '', @ResultGrid6 as varchar(100) = '', @ResultGrid7 as varchar(100) = '', @ResultGrid8 as varchar(100) = '', @ResultGrid9 as varchar(100) = '', @ResultGrid10 as varchar(100) = '', @ResultGrid11 as varchar(100) = '', @ResultGrid12 as varchar(100) = '', @ResultGrid13 as varchar(100) = '', @ResultGrid14 as varchar(100) = '', @ResultGrid15 as varchar(100) = '', @ResultGrid16 as varchar(100) = '', @ResultGrid17 as varchar(100) = '', @ResultGrid18 as varchar(100) = '', @ResultGrid19 as varchar(100) = '', @ResultGrid20 as varchar(100) = '', @ResultGrid21 as varchar(100) = '', @ResultGrid22 as varchar(100) = '', @ResultGrid23 as varchar(100) = '', @ResultGrid24 as varchar(100) = '', @ResultGrid25 as varchar(100) = '', @ResultGrid26 as varchar(100) = '', @ResultGrid27 as varchar(100) = '', @ResultGrid28 as varchar(100) = '' AS if @Mode = '0' Begin if exists(Select Top 1 * from Radiology..tbRadioResultTable Where RevenueID = @RevenueID and RequestNum = @RequestNum) Begin Update Radiology..tbRadioResultTable Set ResultGrid1 = @ResultGrid1, ResultGrid2 = @ResultGrid2, ResultGrid3 = @ResultGrid3, ResultGrid4 = @ResultGrid4, ResultGrid5 = @ResultGrid5, ResultGrid6 = @ResultGrid6, ResultGrid7 = @ResultGrid7, ResultGrid8 = @ResultGrid8, ResultGrid9 = @ResultGrid9, ResultGrid10 = @ResultGrid10, ResultGrid11 = @ResultGrid11, ResultGrid12 = @ResultGrid12, ResultGrid13 = @ResultGrid13, ResultGrid14 = @ResultGrid14, ResultGrid15 = @ResultGrid15, ResultGrid16 = @ResultGrid16, ResultGrid17 = @ResultGrid17, ResultGrid18 = @ResultGrid18, ResultGrid19 = @ResultGrid19, ResultGrid20 = @ResultGrid20, ResultGrid21 = @ResultGrid21, ResultGrid22 = @ResultGrid22, ResultGrid23 = @ResultGrid23, ResultGrid24 = @ResultGrid24, ResultGrid25 = @ResultGrid25, ResultGrid26 = @ResultGrid26, ResultGrid27 = @ResultGrid27, ResultGrid28 = @ResultGrid28, FieldName1 = @FieldName1, FieldName2 = @FieldName2, FieldName3 = @FieldName3, FieldName4 = @FieldName4, FieldName5 = @FieldName5, FieldName6 = @FieldName6, FieldName7 = @FieldName7, FieldName8 = @FieldName8, FieldName9 = @FieldName9, FieldName10 = @FieldName10, FieldName11 = @FieldName11, FieldName12 = @FieldName12, FieldName13 = @FieldName13 Where RevenueID = @RevenueID and RequestNum = @RequestNum End else Begin Insert into Radiology..tbRadioResultTable( RequestNum, RevenueID, ResultGrid1, ResultGrid2, ResultGrid3, ResultGrid4, ResultGrid5, ResultGrid6, ResultGrid7, ResultGrid8, ResultGrid9, ResultGrid10, ResultGrid11, ResultGrid12, ResultGrid13, ResultGrid14, ResultGrid15, ResultGrid16, ResultGrid17, ResultGrid18, ResultGrid19, ResultGrid20, ResultGrid21, ResultGrid22, ResultGrid23, ResultGrid24, ResultGrid25, ResultGrid26, ResultGrid27, ResultGrid28, FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, FieldName6, FieldName7, FieldName8, FieldName9, FieldName10, FieldName11, FieldName12, FieldName13) Values( @RequestNum, @RevenueID, @ResultGrid1, @ResultGrid2, @ResultGrid3, @ResultGrid4, @ResultGrid5, @ResultGrid6, @ResultGrid7, @ResultGrid8, @ResultGrid9, @ResultGrid10, @ResultGrid11, @ResultGrid12, @ResultGrid13, @ResultGrid14, @ResultGrid15, @ResultGrid16, @ResultGrid17, @ResultGrid18, @ResultGrid19, @ResultGrid20, @ResultGrid21, @ResultGrid22, @ResultGrid23, @ResultGrid24, @ResultGrid25, @ResultGrid26, @ResultGrid27, @ResultGrid28, @FieldName1, @FieldName2, @FieldName3, @FieldName4, @FieldName5, @FieldName6, @FieldName7, @FieldName8, @FieldName9, @FieldName10, @FieldName11, @FieldName12, @FieldName13) End End if @Mode = '1' Begin Select * From Radiology..tbRadioResultTable Where RequestNum = @RequestNum and RevenueID = @RevenueID End --if @Mode = '2' --Begin -- --if exists(Select Top 1 * from Radiology..tbRadioResultTable Where RequestNum = @RequestNum) -- Begin -- Update Radiology..tbRadioResultTable -- Set FieldName1 = @FieldName1, FieldName2 = @FieldName2, FieldName3 = @FieldName3, FieldName4 = @FieldName4, -- FieldName5 = @FieldName5, FieldName6 = @FieldName6, FieldName7 = @FieldName7, FieldName8 = @FieldName8, -- FieldName9 = @FieldName9, FieldName10 = @FieldName10, FieldName11 = @FieldName11, FieldName12 = @FieldName12, -- FieldName13 = @FieldName13, FieldName14 = @FieldName14, FieldName15 = @FieldName15 -- Where RequestNum = @RequestNum and RevenueID = @RevenueID -- End --else -- Begin -- Insert into Radiology..tbRadioResultTable( -- RequestNum, RevenueID, -- FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, -- FieldName6, FieldName7, FieldName8, FieldName9, FieldName10, -- FieldName11, FieldName12, FieldName13, FieldName14, FieldName15) -- Values( -- @RequestNum, @RevenueID, -- @FieldName1, @FieldName2, @FieldName3, @FieldName4, @FieldName5, -- @FieldName6, @FieldName7, @FieldName8, @FieldName9, @FieldName10, -- @FieldName11, @FieldName12, @FieldName13, @FieldName14, @FieldName15) -- End --End -- -- -- --if @Mode = '3' --Begin -- Select * From Radiology..tbRadioResultTable -- Where RequestNum = @RequestNum and RevenueID = @RevenueID --End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_InsertInterpret] @RevenueID varchar(2), @Code varchar(10), @Description varchar(50), @Interpretation text AS declare @NewCode as varchar(10) if @RevenueID = 'MI' begin select @NewCode = max(cast(Code as int)) + 1 from tbMRIInterpretation where isnumeric(Code) = 1 insert into tbMRIInterpretation (Code, Description, Interpretation) values (@NewCode, @Description, @Interpretation) end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /*Created by Jetty P. Omo Nov 11,2007 To save/update the time of procedure done in the department DeptID Legend : 1 - Ct Scan 2 - Xray 3 - Ultrasound */ CREATE Procedure [dbo].[sp_saveDateandtimeofProcedure] @RequestNum as varchar(50), @DeptID as varchar(2), @Hospnum as varchar(50), @EndDate as varchar(50), @StartDate as varchar(50) = Null AS IF (Exists(Select RequestNum From tbRadioDateofProcedureDone Where RequestNum=@RequestNum and deptid = @DeptID)) Begin Update tbRadioDateofProcedureDone set DateandTime = @EndDate, StartDate = @StartDate Where RequestNum=@RequestNum and deptid = @DeptID End Else Begin Insert into tbRadioDateofProcedureDone(RequestNum,DeptID,Hospnum,DateandTime, StartDAte) values (@RequestNum,@DeptID,@Hospnum,cast(@EndDate as datetime), cast(@StartDate as datetime)) End GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_UpdateFileNum] @HospNum varchar(8), @FileNum varchar(10), @PatientName varchar(50) AS declare @NewRecordID float BEGIN IF EXISTS ( SELECT * FROM tbMRINum WHERE MRINum = @FileNum ) BEGIN UPDATE tbMRINum SET HospNum = @HospNum, Patient = @PatientName WHERE MRINum = @FileNum END ELSE BEGIN SELECT @NewRecordID = MAX(ISNULL(RecordID, 0)) FROM tbMRINum INSERT INTO tbMRINum (MRINum, HospNum, Patient, RecordID) VALUES (@FileNum, @HospNum, @PatientName, @NewRecordID) END END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_ResultPrint] @Patient AS varChar(90), @HospNum AS varChar(10), @Doctor AS varChar(60), @Examination AS varChar(60), @CivilStatus AS varChar(15), @Age AS varChar(3), @Sex AS varChar(6), @AdmNum AS varChar(10), @CTNum AS varChar(10), @RoomNo AS varChar(15), @ExamDate AS DateTime, @Interpretation AS Text, @Radiologist AS varChar(60), @Address AS varChar(60), @TelNo AS varChar(15), @FileNum AS varChar(10), @ControlNum AS varChar(10), @UserID AS varchar(10), @Radiologist2 AS varchar(60), @Remarks AS text AS DECLARE @cHospNum as varchar(10) if @Hospnum = 'CASH' begin SET @cHospNum = 'OPD' end else begin SET @cHospNum = @HospNum end DELETE tbMRIPrintResult INSERT INTO tbMRIPrintResult (PatientName, HospNum, Doctor, Examination, CivilStatus, Age, Sex, AdmNum, CTNum, RoomNo, ExamDate, Interpretation, Radiologist, Address, TelNo, FileNum, ControlNum, UserID, Radiologist2, Remarks) VALUES (@Patient, @cHospNum, @Doctor, @Examination, @CivilStatus, @Age, @Sex, @AdmNum, @CTNum, @RoomNo, @ExamDate, @Interpretation, @Radiologist, @Address, @TelNo, @FileNum, @ControlNum, @UserID, @Radiologist2, @Remarks) GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_SearchFormFormats] @DepartmentID as varchar(2), @strSearch as varchar(10) AS select * from RADIOLOGY..tbRadioFormFormats WHERE (FormType = @strSearch or FormDescription like '%' + @strSearch + '%') and DepartmentID = @DepartmentID and Active = 1 ; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_BuildExamFormat] @FormType as varchar(2), @FormDescription as varchar(100), @DepartmentID as varchar(2), @Active as varchar(1) AS IF NOT EXISTS (SELECT Formtype FROM tbRadioFormFormats WHERE Formtype = @Formtype and DepartmentID = @DepartmentID) begin INSERT INTO tbRadioFormFormats (FormType, FormDescription, DepartmentID, Active) VALUES (@FormType, @FormDescription, @DepartmentID, @Active) end ELSE begin UPDATE tbRadioFormFormats SET FormType = @FormType, FormDescription = @FormDescription, DepartmentID = @DepartmentID, Active = @Active WHERE FormType = @FormType; end; GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_Ledger Script Date: 07/01/2000 1:20:55 AM ******/ CREATE PROCEDURE [dbo].[spMRI_Ledger] @PatientType varchar(1), @IDNum varchar(10), @RevenueID varchar(10), @UserID varchar(10) AS delete tbMRIReportLedger where Userid = @UserID; if @PatientType = 'I' begin insert into tbMRIReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @UserID, convert(varchar(10), b.transdate, 101) + substring(convert(varchar, b.transdate, 100), 12, 8), b.refnum, b.itemid, case b.RevenueID when 'MI' then M.OtherRevenue when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from billing..tbbilldailybill b left join build_file..tbcoOtherRevenue M on b.itemid = M.OtherRevenueID left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @revenueid or isnull(b.summarycode, '') = @revenueid) and b.idnum = @idnum order by b.transdate end if @PatientType = 'O' begin insert into tbMRIReportLedger (UserID, TransDate, Reference, Code, Description, Quantity, Amount, Encoder) select @UserID, convert(varchar(10), b.transdate, 101) + substring(convert(varchar, b.transdate, 100), 12, 8), b.refnum, b.itemid, case b.RevenueID when 'MI' then M.OtherRevenue when 'MD' then 'DR. ' + d.firstname + ' ' + d.lastname end as exam, isnull(b.quantity, 0), b.amount, b.userid from billing..tbBillOpDailyout b left join build_file..tbcoOtherRevenue M on b.itemid = M.OtherRevenueID left join build_file..tbcoctexam c on b.itemid = c.ctexamid left join build_file..tbcoultraexam u on b.itemid = u.ultraexamid left join build_file..tbcodoctor d on b.itemid = d.doctorid where (b.revenueid = @revenueid or isnull(b.summarycode, '') = @revenueid) and b.idnum = @idnum order by b.transdate end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_LoadChargeSlip] @DepartmentID varchar(2), @RefNum varchar(10) AS if @DepartmentID = 'MI' begin select r.RequestNum, r.Code, case when r.RevenueID = 'MI' then e.OtherRevenue when r.RevenueID = 'MD' then 'DR. ' + isnull(d.LastName, '') + ', ' + isnull(d.FirstName, '') when len( isnull(rev.LocationID, '') ) > 0 then m.ItemName + ' ' + isnull(m.ItemDesc, '') else rev.ItemName end ItemDesc, r.Quantity, r.Amount, r.RevenueID, rev.LocationID, b.RevenueID [InventoryCode] from tbMRIRequest r left join BUILD_FILE..tbCoRevenueCode rev on r.RevenueID = rev.RevenueID left join BILLING..tbBillInvCode b on r.RevenueID = b.ServiceID left join BUILD_FILE..tbcoOtherRevenue e on r.Code = e.OtherRevenueID left join BUILD_FILE..tbCoDoctor d on r.Code = d.DoctorID left join INVENTORY..tbInvMaster m on r.Code = m.ItemID where r.RefNum = @RefNum order by r.TransDate end GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_IncomeReport] @RevenueID varchar(2), @StartDate varchar(10), @EndDate varchar(10) AS /*set @RevenueID= 'MS' set @StartDate= '01/01/2005' set @EndDate ='04/22/2005'*/ --AS select s.itemid, max(case @RevenueID when 'MI' then mri.OtherRevenue end) as exam, sum(case when s.type = 'I' then s.quantity else 0 end) as InQuantity, sum(case when s.type = 'I' then s.amount else 0 end) as InAmount, sum(case when s.type = 'O' then s.quantity else 0 end) as OutQuantity, sum(case when s.type = 'O' then s.amount else 0 end) as OutAmount, sum(quantity) as TotalQty, sum(amount) as TotalAmt from ( select b.refnum, b.itemid, sum(case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end) quantity, sum(b.amount) amount, 'I' type from BILLING..tbbilldailybill b where transdate between @StartDate and @EndDate + ' 23:59:59' and revenueid = @RevenueID group by refnum, itemid having sum(amount) <> 0 union all select b.refnum, b.itemid, sum(case when b.amount < 0 then isnull(b.quantity, 1) * (-1) else isnull(b.quantity, 1) end) quantity, sum(b.amount) amount, case @RevenueID when 'MI' then case when left(b.refnum, 2) = 'OR' then case when max(isnull(reqMRI.idnum, '')) = '' then 'O' when isnumeric(max(isnull(reqMRI.idnum, ''))) = 0 then 'O' when isnumeric(max(isnull(reqMRI.idnum, ''))) = 1 then 'I' end else 'O' end end as type from BILLING..tbbillopdailyout b left join ( select refnum, max(idnum) idnum from tbMRIrequest where refnum like 'OR%' and isnull(swfin, '') not in ('C','R') group by refnum ) as reqMRI on b.refnum = reqMRI.refnum where b.transdate between @StartDate and @EndDate + ' 23:59:59' and b.revenueid = @RevenueID group by b.refnum, b.itemid having sum(b.amount) <> 0 ) as s left join BUILD_FILE..tbcoOtherRevenue mri on s.itemid = mri.otherrevenueid group by s.itemid GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_DoctorContribution] @RevenueID varchar(2), @StartDate varchar(10), @EndDate varchar(10) AS /* declare @RevenueID varchar(2) declare @StartDate varchar(10) declare @EndDate varchar(10) set @RevenueID = 'MS' set @StartDate = '04/01/2005' set @EndDate = '04/30/2005' */ if @RevenueID = 'MI' begin Select case when not ltrim(rtrim(Max(isnull(D.LastName,'') + ' ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')))) = '' then Max(isnull(D.LastName,'') + ', ' + isNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'')) + ' ' + max(IsNull(D.clnic,'')) else ' VARIOUS' end as Doctor, Sum(Case When isnumeric(IDNum) = 0 and Refnum like 'OR%' then 1 else 0 end) as CASH, Sum(Case When isnumeric(IDNum) = 0 and not RefNum like '%X' then 1 else 0 end) as OUT, Sum(Case When isnumeric(IDNum) = 1 then 1 else 0 end) as [IN], Sum(Case When isnumeric(IDNum) = 0 and Refnum like 'OR%' then Cast(isnull(Amount,0) as money) else 0 end) as AmountCASH, Sum(Case When isnumeric(IDNum) = 0 and not RefNum like '%X' then Cast(isnull(Amount,0) as money) else 0 end) as AmountOUT, Sum(Case When isnumeric(IDNum) = 1 then Cast(isnull(Amount,0) as money) else 0 end) as AmountIN from RADIOLOGY..tbMRIRequest A left outer join Build_File..tbCoDoctor D on D.DoctorID = rtrim(ltrim(A.RequestDoctorCode)) where SwFin <> 'R' and convert(varchar(10),Transdate,101) between @startDate and @EndDate + ' 23:59:59.99' -- and D.LastName like 'Torre%' Group by A.RequestDoctorCode--, A.IDNum Order by [Doctor] asc end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spMRI_LoadRequest] @RequestNum varchar(10) AS --set @RequestNum ='2318' BEGIN SELECT tbMRIRequest.HospNum AS HospNum, tbMRIRequest.RequestNum AS RequestNum, tbMRIRequest.RefNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.LastName ELSE tbCashPatient.LastName END AS Lastname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.FirstName ELSE tbCashPatient.FirstName END AS Firstname, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.MiddleName ELSE tbCashPatient.MiddleName END AS Middlename, tbMRIRequest.Code AS Code, tbCoMRIExam.OtherRevenue AS Description, tbMRIRequest.IdNum AS IDNum, tbMRIRequest.TransDate AS TransDate, tbMRIRequest.Film1, tbMRIRequest.Film2, tbMRIRequest.Film3, tbMRIRequest.Film4, tbMRIRequest.Film5, tbMRIRequest.Film6, tbMRIRequest.Film7, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.RoomID ELSE 'OPD' END AS RoomID, tbMRIRequest.RequestDoctorCode [DoctorID], ISNULL(tbCoDoctor.LastName, '') [DrLastName], ISNULL(tbCoDoctor.FirstName, '') [DrFirstName], ISNULL(tbCoDoctor.MiddleName, '') [DrMiddleName], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Sex ELSE tbCashPatient.Sex END AS Sex, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.BirthDate ELSE tbCashPatient.BirthDate END AS BirthDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CivilStatus ELSE tbCashPatient.CivilStatusID END AS CivilStatus, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Age ELSE CAST(tbCashPatient.Age AS VARCHAR) END AS Age, CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.AdmDate ELSE tbOutPatient.AdmDate END AS AdmDate, ISNULL(CASE WHEN tbPatient.IDNum IS NOT NULL THEN tbPatient.BillingDate ELSE tbOutPatient.BillingDate END, 0) AS BillingDate, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.CTNum ELSE tbCashPatient.CTNum END AS FileNum, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.HouseStreet ELSE tbCashPatient.HouseStreet END HouseStreet, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.Barangay ELSE tbCashPatient.Barangay END Barangay, CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Town ELSE tbCoAddress_C.Town END [Town], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbCoAddress.Province ELSE tbCoAddress_C.Province END [Province], CASE WHEN tbMaster.HospNum IS NOT NULL THEN tbMaster.TelNum ELSE '' END [TelNum], CASE WHEN tbMaster.HospNum IS NOT NULL THEN ISNULL(tbMaster.ControlNum, 0) ELSE ISNULL(tbCashPatient.ControlNum, 0) END [ControlNum], tbMRIRequest.Amount FROM tbMRIRequest tbMRIRequest LEFT OUTER JOIN PATIENT_DATA..tbPatient [tbPatient] ON tbMRIRequest.IDNum = tbPatient.IDNum LEFT OUTER JOIN PATIENT_DATA..tbOutPatient [tbOutPatient] ON tbMRIRequest.IDNUm = tbOutPatient.IDNum LEFT OUTER JOIN BUILD_FILE..tbCoDoctor [tbCoDoctor] ON tbMRIRequest.RequestDoctorCode = tbCoDoctor.DoctorID LEFT OUTER JOIN PATIENT_DATA..tbMaster [tbMaster] ON tbMRIRequest.HospNum = tbMaster.HospNum LEFT OUTER JOIN PATIENT_DATA..tbCashPatient [tbCashPatient] ON tbMRIRequest.HospNum = tbCashPatient.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoAddress [tbCoAddress] ON tbMaster.Zipcode = tbCoAddress.Zipcode LEFT OUTER JOIN BUILD_FILE..tbCoAddress AS tbCoAddress_C ON tbCashPatient.ZipCode = tbCoAddress_C.ZipCode LEFT OUTER JOIN BUILD_FILE..tbCoOtherREvenue [tbCoMRIExam] ON tbMRIRequest.Code = tbCoMRIExam.OtherRevenueID WHERE tbMRIRequest.RequestNum = @RequestNum END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.spRadio_DoctorCharge Script Date: 07/01/2000 1:19:32 AM ******/ CREATE PROCEDURE [dbo].[spMRI_DoctorChargeCancel] @PatientType AS varChar(1), @RefNum as varchar(10), @IDNum AS varChar(10), @ItemID AS varChar(8), @Amount AS Float, @UserID as varchar(10) AS declare @DeptCode as varchar(2) declare @Hospnum as varchar(10), @RoomID as varchar(10) DECLARE @RequestNum AS varChar(8) if isnumeric(@IDNum) = 1 begin Select @Hospnum = HospNum, @RoomID = RoomID From Patient_Data..tbPatient Where IDNum = @IDNum; end else begin Select @Hospnum = HospNum, @RoomID = 'OPD' From Patient_Data..tbOutPatient Where IDNum = @IDNum end Update tbMRIRequest set SWFIN = 'C' Where IDNum = @IDNum and RefNum = @RefNum and Code = @ItemID; IF @PatientType = 'I' BEGIN INSERT INTO billing..tbBillDailyBill (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '', @DeptCode ) END IF @PatientType = 'O' BEGIN INSERT INTO billing..tbBillOPDailyOut (Refnum, IDNum, Transdate, ItemID, Amount, DrCr, RevenueID, RoomID, UserID, RequestDocID, SummaryCode) VALUES (@Refnum, @IDNum, GetDate(), @ItemID, @Amount, 'P', 'MD', '', @UserID, '' , @DeptCode) END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[sp_MRI_Get_Charges_By_ChargeSlip] @Refnum As Varchar(20) AS BEGIN select Code,TypeDescription As Description,Quantity,Amount/Quantity As Price,Amount,[By] As UserID, 0 As NetAmount,'' As DiscountType,RequestNum from tbmrirequest Where Refnum=@Refnum Order By TransDate END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_GetResultSquenceNum] @RevenueID as varchar(3) AS Select isnull(Max(Rank) ,'') + 1 as Rank from tbradioResultLog Where revenueiD = @RevenueID and ResultDate between convert(varchar(10),getdate(),101) and getdate(); GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_ReportSchedule] @RevenueID as varchar(2), @StartDate as varchar(10), @EndDate as varchar(10) AS /* declare @SchedDate as varchar(10) set @SchedDate = '3/22/2005' */ SELECT S.SchedDate, S.SchedTime, S.HospNum, S.IdNum, M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName as PatientName, S.ExamId, E.Description, S.UserId, S.SequenceNum, isnull(M.Housestreet,'') + ' ' + isnull(M.Barangay,'') + ', ' + A.Town + ', ' + A.Province + ' ' + A.ZipCode as Address, case isnull(M.BirthDate,'') when '' then M.Age + '/' + M.Sex else case isdate(M.Birthdate) when 1 then patient_data.dbo.fn_ComputeAge (M.birthdate,getdate()) + '/' + M.Sex else M.Age + '/' + M.Sex end end as Age, M.LastName, M.FirstName , M.MiddleName FROM tbMRISchedule S left outer join PATIENT_DATA..tbMaster M on S.HospNum = M.HospNum left outer join BILLING..tbBillExamListing E on S.ExamID = E.ItemID and S.RevenueID = E.RevenueID left outer join BUILD_FILE..tbCoAddress A on M.ZipCode = A.ZipCode WHERE S.RevenueID = @RevenueID AND CAST(schedDate AS DATETIME) BETWEEN @StartDate AND @EndDate + ' 23:59:59.99' order by SchedDate, SchedTime GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_GetSchedule] @RevenueID as varchar(2), @SchedDate as varchar(10) AS /* declare @SchedDate as varchar(10) set @SchedDate = '3/22/2005' */ SELECT S.SchedDate, S.SchedTime, S.HospNum, S.IdNum, M.LastName + ', ' + M.FirstName + ' ' + M.MiddleName as PatientName, S.ExamId, E.Description, S.UserId, S.SequenceNum, isnull(M.Housestreet,'') + ' ' + isnull(M.Barangay,'') + ', ' + A.Town + ', ' + A.Province + ' ' + A.ZipCode as Address, case isnull(M.BirthDate,'') when '' then M.Age + '/' + M.Sex else case isdate(M.Birthdate) when 1 then patient_data.dbo.fn_ComputeAge (M.birthdate,getdate()) + '/' + M.Sex else M.Age + '/' + M.Sex end end as Age, M.LastName, M.FirstName , M.MiddleName FROM tbMRISchedule S left outer join PATIENT_DATA..tbMaster M on S.HospNum = M.HospNum left outer join BILLING..tbBillExamListing E on S.ExamID = E.ItemID and S.RevenueID = E.RevenueID left outer join BUILD_FILE..tbCoAddress A on M.ZipCode = A.ZipCode WHERE SchedDate = @SchedDate and S.RevenueID = @RevenueID order by SchedDate, SchedTime GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spMRI_SaveSchedule] @SequenceNum as int, @SchedDate as varchar(10), @SchedTime as varchar(10), @HospNum as varchar(10), @IdNum as varchar(10), @RefNum as varchar(10), @ExamID as varchar(10), @UserID as varchar(10), @RevenueID as varchar(2) AS if exists (SELECT * FROM tbMRISchedule WHERE SequenceNum = @SequenceNum) and @SequenceNum > 0 begin update tbMRISchedule set SchedDate = @SchedDate, SchedTime = @SchedTime, HospNum = @HospNum, IdNum = @IdNum, RefNum = @RefNum, ExamID = @ExamID, UserID = @UserID, Transdate = getdate(), RevenueID = @RevenueID where SequenceNum = @SequenceNum; end; else begin insert into tbMRISchedule (SchedDate, SchedTime, HospNum, IdNum, RefNum, ExamID, UserID, Transdate, RevenueID) values (@SchedDate, @SchedTime, @HospNum, @IdNum, @RefNum, @ExamID, @UserID, getdate(), @RevenueID); end; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spRadio_ExamStatistics_New] @RevenueID varchar(2), @StartDate varchar(10), @LastDate varchar(10) AS Declare @BeginDate datetime, @EndDate datetime Set @BeginDate = cast(@StartDate as datetime) Set @EndDate = dateadd(day, 1, cast(@LastDate as datetime)) If @RevenueID = 'CT' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.ctexam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwctrequestmaster v on b.refnum = v.refnum Left join patient_data..tbpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'CT' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwctrequestmaster v on b.refnum = v.refnum Left join patient_data..tboutpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'CT' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbcoctexam e on a.itemid = e.ctexamid End; If @RevenueID = 'XR' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.XRayExam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwxrrequestmaster v on b.refnum = v.refnum Left join patient_data..tbpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) and b.revenueid = 'XR' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwxrrequestmaster v on b.refnum = v.refnum Left join patient_data..tboutpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'XR' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbCoXrayExam e on a.itemid = e.XRayExamid End; If @RevenueID = 'US' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.UltraExam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwulrequestmaster v On b.refnum = v.refnum Left join patient_data..tbpatient p On b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'US' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwulrequestmaster v On b.refnum = v.refnum Left join patient_data..tboutpatient p On b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'US' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbCoUltraExam e on a.itemid = e.UltraExamID End; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[spRadio_ExamStatistics] @RevenueID varchar(2), @StartDate varchar(10), @LastDate varchar(10) AS Declare @BeginDate datetime, @EndDate datetime Set @BeginDate = cast(@StartDate as datetime) Set @EndDate = dateadd(day, 1, cast(@LastDate as datetime)) If @RevenueID = 'CT' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.ctexam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwctrequestmaster v on b.refnum = v.refnum Left join patient_data..tbpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'CT' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwctrequestmaster v on b.refnum = v.refnum Left join patient_data..tboutpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'CT' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbcoctexam e on a.itemid = e.ctexamid End; If @RevenueID = 'XR' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.XRayExam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwxrrequestmaster v on b.refnum = v.refnum Left join patient_data..tbpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) and b.revenueid = 'XR' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwxrrequestmaster v on b.refnum = v.refnum Left join patient_data..tboutpatient p on b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'XR' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbCoXrayExam e on a.itemid = e.XRayExamid End; If @RevenueID = 'US' Begin Select isnull(a.doctorid, '') DoctorID, isnull(d.lastname, '') LastName, isnull(d.firstname, '') FirstName, isnull(d.middlename, '') MiddleName, a.itemid, e.UltraExam [ExamName], a.amount, Case when a.patienttype = 1 and a.amount < 0 then -1 when a.patienttype = 1 and a.amount > 0 then 1 else 0 End InpatientCount, Case when a.patienttype = 0 and a.amount < 0 then -1 when a.patienttype = 0 and a.amount > 0 then 1 else 0 End OutpatientCount From (Select isnumeric(isnull(b.idnum, v.idnum)) patienttype, b.itemid, b.amount, isnull(v.requestdoctorcode, p.attendingdr1) doctorid From billing..tbbilldailybill b Left join vwulrequestmaster v On b.refnum = v.refnum Left join patient_data..tbpatient p On b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'US' Union all Select isnumeric(isnull(v.idnum, b.idnum)), b.itemid, b.amount, isnull(v.requestdoctorcode, p.DoctorID1) doctorid From billing..tbbillopdailyout b Left join vwulrequestmaster v On b.refnum = v.refnum Left join patient_data..tboutpatient p On b.idnum = p.idnum Where (b.transdate >= @BeginDate and b.transdate < @EndDate) --b.transdate >= '01/01/2001' and b.revenueid = 'US' ) as a Left join build_file..tbcodoctor d on a.doctorid = d.doctorid Left join build_file..tbCoUltraExam e on a.itemid = e.UltraExamID End;