use patient_data SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_AOPD_Rep_CensusReport] @StartDate as varchar(10), @EndDate as varchar(10), @Type as varchar(1) /* set @StartDate = '06/15/2008' set @EndDate = '06/18/2008' set @Type = '3' */ as if @Type = '1' begin Select B.Hospnum, A.IDNum, LastName, FirstName, MiddleName, AdmDate, case when isnumeric(A.AccountNum) = 1 then 'PERSONAL' else C.Company end Account, A.AccountNum from Patient_Data..tbOutpatient A Left Outer Join Patient_Data..tbMaster B on A.Hospnum = B.Hospnum Left Outer Join Build_File..tbcoCompany C on A.AccountNum = C.AccountNum where IDNum in (Select IDNum from Medicare..tbMedActual where cast(MedRoomBoard + MedDrug + MedOthers + MedOR as Decimal(12,2)) > 0) and AdmDate between @StartDate and @EndDate + ' 23:59:59.99' order by AdmDate end else if @Type = '2' begin Select B.Hospnum, A.IDNum, LastName, FirstName, MiddleName, AdmDate, C.Company as Account, A.AccountNum from Patient_Data..tbOuCREATE TABLE [dbo].[tblrequester](tpatient A Left Outer Join Patient_Data..tbMaster B on A.Hospnum = B.Hospnum Left Outer Join Build_File..tbcoCompany C on A.AccountNum = C.AccountNum where isnumeric(A.AccountNum) = 0 and AdmDate between @StartDate and @EndDate + ' 23:59:59.99' order by AdmDate end else if @Type = '3' begin Select B.Hospnum, A.IDNum, LastName, FirstName, MiddleName, AdmDate, 'PERSONAL' as Account, A.AccountNum from Patient_Data..tbOutpatient A Left Outer Join Patient_Data..tbMaster B on A.Hospnum = B.Hospnum where isnumeric(A.AccountNum) = 1 and AdmDate between @StartDate and @EndDate + ' 23:59:59.99' and A.IDNum in (Select IDNum from Billing..tbBillOPDailyOut where DRCR = 'D' group by IDNum) order by AdmDate end GO USE [clinical_area] GO /****** Object: StoredProcedure [dbo].[spGeneric_GetPatient] Script Date: 05/11/2011 13:15:05 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGeneric_GetPatient] @Status As Varchar (1), @Lastname As Varchar(20), @HospNum As Varchar(10), @IDNum As Varchar(10) AS Declare @DateToDay as varchar(10); Set @DateToDay = Convert(varchar(10),getdate(),101); IF @Status='O' Begin SELECT tbOutPatient.HospNum AS [Hospital #],tbOutPatient.IDNum AS [Admission #],RTRIM(isnull(tbMaster.LastName,'')) + ' ,' + RTRIM(isnull(tbMaster.FirstName,'')) + ' ' + RTRIM(isnull(tbMaster.MiddleName,'')) AS [Patient Name],convert(varchar(10),tbOutPatient.AdmDate,101) + substring(convert(varchar(19),tbOutPatient.AdmDate,100),12,8) AS [Admission Date], tboutpatient.billingdate as [Billing Date] FROM PATIENT_DATA..tbOutPatient AS tbOutPatient LEFT OUTER JOIN PATIENT_DATA..tbMaster AS tbMaster ON tbOutPatient.Hospnum = tbMaster.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany tbCoCompany ON tbOutPatient.AccountNum = tbCoCompany.AccountNum where ((tbOutPatient.AdmDate Between @DateToDay and @DateToDay + ' 23:59:59' and DcrDate is null) and (tbMaster.LastName like rtrim(@Lastname) + '%' ) and tboutpatient.HospNum like @Hospnum +'%' and tbOutPatient.IDNum like @IDNum +'%') and tbOutPatient.opdstatus <> 'R' order by tbmaster.lastname, tbmaster.firstname, tbmaster.middlename End; IF @Status = 'I' Begin SELECT tbPatient.HospNum AS [Hospital #],tbPatient.IDNum AS [Admission #],RTRIM(isnull(tbMaster.LastName,'')) + ' ,' + RTRIM(isnull(tbMaster.FirstName,'')) + ' ' + RTRIM(isnull(tbMaster.MiddleName,'')) AS [Patient Name],convert(varchar(10),tbPatient.AdmDate,101) + substring(convert(varchar(19),tbPatient.AdmDate,100),12,8) AS [Admission Date], tbpatient.billingdate as [Billing Date] FROM PATIENT_DATA..tbPatient AS tbPatient LEFT OUTER JOIN PATIENT_DATA..tbMaster AS tbMaster ON tbPatient.Hospnum = tbMaster.HospNum where (tbPatient.BillingDate Is Null) and ((tbMaster.LastName like @Lastname + '%' or @Lastname ='') and (tbPatient.HospNum = @HospNum or @Hospnum='') and (tbPatient.IDNum = @IDNum or @IDNum='') ) ORDER BY [Patient Name] End; IF @Status = 'C' Begin SELECT tbPatient.HospNum AS [Hospital #],tbPatient.IDNum AS [Admission #],RTRIM(isnull(tbMaster.LastName,'')) + ' ,' + RTRIM(isnull(tbMaster.FirstName,'')) + ' ' + RTRIM(isnull(tbMaster.MiddleName,'')) AS [Patient Name],convert(varchar(10),tbPatient.AdmDate,101) + substring(convert(varchar(19),tbPatient.AdmDate,100),12,8) AS [Admission Date], tbpatient.billingdate as [Billing Date] FROM PATIENT_DATA..tbPatient AS tbPatient LEFT OUTER JOIN PATIENT_DATA..tbMaster AS tbMaster ON tbPatient.Hospnum = tbMaster.HospNum where (tbpatient.dcrdate <= billingdate or tbpatient.dcrdate is null) and ((tbMaster.LastName like @Lastname + '%' ) and (tbPatient.HospNum = @HospNum or @Hospnum='') and (tbPatient.IDNum = @IDNum or @IDNum='') ) ORDER BY [Patient Name] End; IF @Status = 'D' begin --OPD Previous Registration SELECT tbOutPatient.HospNum AS [Hospital #],tbOutPatient.IDNum AS [Admission #],RTRIM(isnull(tbMaster.LastName,'')) + ' ,' + RTRIM(isnull(tbMaster.FirstName,'')) + ' ' + RTRIM(isnull(tbMaster.MiddleName,'')) AS [Patient Name],convert(varchar(10),tbOutPatient.AdmDate,101) + substring(convert(varchar(19),tbOutPatient.AdmDate,100),12,8) AS [Admission Date], tboutpatient.billingdate as [Billing Date] FROM PATIENT_DATA..tbOutPatient AS tbOutPatient LEFT OUTER JOIN PATIENT_DATA..tbMaster AS tbMaster ON tbOutPatient.Hospnum = tbMaster.HospNum LEFT OUTER JOIN BUILD_FILE..tbCoCompany tbCoCompany ON tbOutPatient.AccountNum = tbCoCompany.AccountNum where (tbOutPatient.OpdStatus <>'R' and (tbMaster.LastName like rtrim(@Lastname) + '%' ) and tboutpatient.HospNum like @Hospnum +'%' and tbOutPatient.IDNum like @IDNum +'%') and isnull(tbCoCompany.Class,'') <> 'S' order by tbmaster.lastname, tbmaster.firstname, tbmaster.middlename, tbOutPatient.AdmDate end; IF @Status = 'T' begin SELECT tbPatient.HospNum AS [Hospital #],tbPatient.IDNum AS [Admission #],RTRIM(isnull(tbMaster.LastName,'')) + ' ,' + RTRIM(isnull(tbMaster.FirstName,'')) + ' ' + RTRIM(isnull(tbMaster.MiddleName,'')) AS [Patient Name],convert(varchar(10),tbPatient.AdmDate,101) + substring(convert(varchar(19),tbPatient.AdmDate,100),12,8) AS [Admission Date], tbpatient.billingdate as [Billing Date] FROM PATIENT_DATA..tbPatient AS tbPatient LEFT OUTER JOIN PATIENT_DATA..tbMaster AS tbMaster ON tbPatient.Hospnum = tbMaster.HospNum where ((tbMaster.LastName like @Lastname + '%' or @Lastname ='') and (tbPatient.HospNum = @HospNum or @Hospnum='') and (tbPatient.IDNum = @IDNum or @IDNum='') ) ORDER BY [Patient Name], [Admission Date] end; ---------------------------------------------------------------------------- USE [clinical_area] GO /****** Object: StoredProcedure [dbo].[spGeneric_CheckPending] Script Date: 05/11/2011 13:16:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[spGeneric_CheckPending] @userid varchar(10) AS select count(*) TotalPending from Station..tbNurseCommunicationFile where (recordstatus IS NULL or recordstatus='') and RevenueID in (Select revenueid from tbGenericAccess where userid = @userid) ---------------------------------------------------------------------------- USE [Clinical_area] set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ----->>Created by oski for Generic Charging --patient_data..spGeneric_GetPatient 'I', '131844', '176666' CREATE Procedure [dbo].[spGeneric_GetPatientInfo] @strPatientType as varchar(1), @HospNum as varchar(10), @Idnum as varchar(11) as if @strpatientType = 'O' begin Select isnull(A.LastName,'') LastName, isnull(A.FirstName,'') FirstName, isnull(A.MiddleName,'') MiddleName, isnull(A.birthDate,'')BirthDate, isnull(A.Sex,'') Sex, isnull(A.Age,'') Age, isnull(A.Barangay,'')Barangay, Case A.CivilStatus When '0' Then 'Child' When '1' Then 'Single' When '2' then 'Married' When '3' Then 'Widow' when '4' Then 'Separated' When '5' Then 'Divorced' Else '' End AS CivilStatus, B.Idnum, B.HospNum, B.DoctorID1 as DoctorID, 'Dr. '+ D.LastName + ', ' + D.FirstName as Doctor, 'OPD' as Room, 'A' as RoomClassID, B.AdmDate, case when (B.AccountNum = B.Hospnum or isnull(B.AccountNum,'') = '') then 'PERSONAL' else C.Company end as Account, B.AccountNum from patient_Data..tboutpatient B left outer join patient_data..tbmaster A on a.hospnum = b.hospnum left outer join build_file..tbcocompany C on b.accountnum = c.accountnum left outer join build_file..tbcodoctor D on b.doctorid1 = d.doctorid where B.Hospnum = @hospnum and b.idnum = @idnum end if @strpatientType = 'I' begin Select isnull(A.LastName,'') LastName, isnull(A.FirstName,'') FirstName, isnull(A.MiddleName,'') MiddleName, isnull(A.birthDate,'')BirthDate, isnull(A.Sex,'') Sex, isnull(A.Age,'') Age, isnull(A.Barangay,'')Barangay, Case A.CivilStatus When '0' Then 'Child' When '1' Then 'Single' When '2' then 'Married' When '3' Then 'Widow' when '4' Then 'Separated' When '5' Then 'Divorced' Else '' End AS CivilStatus, B.Idnum, B.HospNum, B.AttendingDr1 as Doctorid, 'Dr. '+ D.LastName + ', ' + D.FirstName as Doctor, B.RoomiD as Room, R.RoomClassID, B.AdmDate, case when (B.AccountNum = B.Hospnum or isnull(B.AccountNum,'') = '') then 'PERSONAL' else C.Company end as Account, B.AccountNum from patient_Data..tbpatient B left outer join patient_data..tbmaster A on a.hospnum = b.hospnum left outer join build_file..tbcocompany C on b.accountnum = c.accountnum left outer join build_file..tbcodoctor D on d.doctorid = b.attendingdr1 left outer join build_File..tbcoroom R on b.roomid = r.roomid where B.Hospnum = @hospnum and b.idnum = @idnum end ---------------------------------------------------------------------------- Alter table Patient_Data..tbhospitalinfo add isAllowSpecializedCompanyRate bit null ---------------------------------------------------------------------------- USE [build_file] GO /****** Object: Table [dbo].[tbcoBuildFileSetting] Script Date: 05/11/2011 14:40:44 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbcoBuildFileSetting]( [isAllowCompanyItems] [bit] NOT NULL DEFAULT(0), [AllowAutoDoctorCode] [bit] NOT NULL DEFAULT(0), [AllowAutoCompanyCode] [bit] NOT NULL DEFAULT(0), [AllowMoAonCompany] [bit] NULL ) ON [PRIMARY] ---------------------------------------------------------------------------- ALTER TABLE [dbo].[tbCoCompany] ADD [moaStartDate] [varchar](11) NULL, [moaEndDate] [varchar](11) NULL, [moNumber] [varchar](20) NULL, [compPassword] [varchar](20) NULL, [moaNumber] [varchar](30) NULL, [isEmployee] [bit] NULL ---------------------------------------------------------------------------- USE [Build_File] set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Bui_Search_Company](@SearchCriteria as varchar(60), @type as varchar(1)) AS If (@Type = '1') Select '' as dumm, isnull(a.company,'') as Company, isnull(a.accountnum,'')as AccountNum, isnull(b. description,'') as Description, isnull(a.cardcode,'') as CardCode, (case when a.status = 'A' then 'Active' else 'Inactive' End) as status from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code order by a.company else If (@Type = '2') Select isnull(a.accountnum,'') as AccountNum, isnull(a.company,'') as Company, isnull(a.housestreet,'') as HouseStreet, isnull(a.barangay,'') as Barangay, isnull(a.zipcode,'') as Zipcode, isnull(a.status,'') as Status,isnull(a.cardcode,'') as CardCode, isnull(a.tin,'') as TIN, isnull(a.vat,'') as VAT, isnull(a.fax,'') as FAX, isnull(a.status,'') as Status, isnull(a.phone,'') as Phone, (case when ltrim(rtrim(isnull(b.description,''))) = '' then '(NONE)' else b.description End) as description, (case when ltrim(rtrim(isnull(c.town,'') + ', ' + isnull(c.province,''))) = ',' then '(NONE)' else isnull(c.town,'') + ', ' + isnull(c.province,'') End) as province, IsNull( a.Class, '' ) as Class , IsNull( a.ContactPerson, '' ) as ContactPerson, IsNull( a.Position, '' ) as Position, IsNull( a.Officer, '' ) as Officer, isnull(CardCode, '') as CardCode, isnull(EmployeeID,'') as EmployeeID, isnull(a.CreditLimit, 0) as CreditLimit, CompanyDiscount, moaStartDate, moaEndDate , moaNumber, comppassword, isnull(a.isEmployee,0) as isEmployee from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code left outer join tbcoaddress c on a.zipcode = c.zipcode where a.accountnum = @searchcriteria else If (@type = '3') Select * from tbcoCompany where ltriM(rtrim(isnull(company,''))) = @SearchCriteria else If (@Type = '4') Select '' as dumm, isnull(a.companyid,'') as CompanyID,isnull(a.company,'') as Company, isnull(a.accountnum,'') as AccountNum, isnull(b.code,'') + ' - ' + isnull(b.description,'') as description, b.code,a.cardcode, (case when a.status = 'A' then 'Active' else 'Inactive' End) as status from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code order by b.description,a.company else If (@Type = '5') Select '' as dumm, isnull(a.companyid,'') as CompanyID,isnull(a.company,'') as Company, isnull(a.accountnum,'') as AccountNum, isnull(b.code,'') + ' - ' + isnull(b.description,'') as description, isnull(b.code,'') as Code,isnull(a.cardcode,'') as Cardcode, (case when a.status = 'A' then 'Active' else 'Inactive' End) as status from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code order by a.accountnum else If (@Type = '6') Select '' as dumm, isnull(a.companyid,'') as CompanyID,isnull(a.company,'') as Company, isnull(a.accountnum,'') as AccountNum, isnull(b.code,'') + ' - ' + isnull(b.description,'') as description, isnull(b.code,'') as Code,isnull(a.cardcode,'') as Cardcode, (case when a.status = 'A' then 'Active' else 'Inactive' End) as status from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code order by a.company else If (@Type = '7') Select '' as dumm, isnull(a.companyid,'') as CompanyID,isnull(a.company,'') as Company, isnull(a.accountnum,'') as Accountnum, isnull(b.code,'') + ' - ' + isnull(b.description,'') as description, isnull(b.code,'') as Code, isnull(a.cardcode,'') as CardCode, (case when a.status = 'A' then 'Active' else 'Inactive' End) as status from tbcocompany a left outer join tbcobusinessclass b on a.class = b.code where b.description not like '%advance%' order by a.company set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter table Patient_data..tbhospitalinfo add isSOAColumnar bit not null default(0) ----------------------------------------------------------------- USE [billing] GO /****** Object: StoredProcedure [dbo].[Billing_CheckOPPendingRequests] Script Date: 05/12/2011 14:09:52 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create Procedure [dbo].[Billing_CheckOPPendingRequests] @IDNum as varchar(10) as --set @IDNum = '319572B' Select distinct isnull(A.RevenueID,'') as RevenueID, max(isnull(B.ItemName,'')) as RevenueName, count(ItemID) as RequestsNumber from Station..tbNurseCommunicationFile A Left Outer Join Build_File..tbCoRevenueCode B On A.RevenueID = B.RevenueID where A.IDNum = @IDNum and A.StationID = 'OR' and isnull(A.RecordStatus,'') = '' Group by A.IDNum, A.RevenueID GO USE [build_file] GO /****** Object: StoredProcedure [dbo].[spBuild_CanAddItems] Script Date: 05/13/2011 12:19:10 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -->>To enable the BuildFile option in adding items to -->>the company, the class should be in the where condition CREATE Procedure [dbo].[spBuild_CanAddItems] @AccountNum varchar(10) as select Class from tbcocompany where AccountNum = @AccountNum and Class in('HM') go Alter table Build_File..tbcorevenuecode add GenericActive varchar(1) go USE [Clinical_area] /****** Object: Table [dbo].[tbOPDUserSetting] Script Date: 02/18/2011 11:56:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbGenericUserSetting]( [EmployeeID] [varchar](15) NULL, [MenuID] [varchar](5) NULL, [Status] [bit] NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF go USE [Build_File] GO /****** Object: Table [dbo].[tbGenericMenu] Script Date: 05/13/2011 14:36:03 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbGenericMenu]( [MenuID] [varchar](5) NULL, [Menu] [varchar](100) NULL, [Status] [bit] NOT NULL, [MenuGroup] [varchar](1) NULL, [MainMenu] [varchar](1) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF go USE [Clinical_Area] GO /****** Object: Table [dbo].[tbGenericAccess] Script Date: 05/13/2011 14:57:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING OFF GO CREATE TABLE [dbo].[tbGenericAccess]( [UserID] [varchar](5) NULL, [RevenueID] [varchar](4) NULL, [RevenueName] [varchar](50) NULL, [Status] [bit] NOT NULL, [RevTransSetting] [varchar](1) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF go Alter table tbcolabexam add GSISPercentageRate varchar(4) go Alter table inventory..tbInvRentalItemsPrice add RateI float null go Alter table patient_data..tbhospitalinfo add isallowspecializedcompanyrate bit null go USE [billing] GO /****** Object: StoredProcedure [dbo].[Cashier_LoadDiscount] Script Date: 05/16/2011 11:52:39 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create Procedure [dbo].[Cashier_LoadDiscount] as select * from Build_File..tbCoRevenuecode where lgrp = 'D' and cashieractive = 'Y' and RevenueID not in ('VR','DL') order by itemname GO USE [billing] GO /****** Object: StoredProcedure [dbo].[spCash_ReportCreditCard_Daily] Script Date: 05/16/2011 13:21:42 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[spCash_ReportCreditCard_Daily] @ReportDate varchar(10), @EndDate as varchar(10) = @ReportDate, @RangeType as int = 1, @Card as varchar(20) = '' AS declare @ComputerID varchar(10) set @ComputerID = LEFT(HOST_ID(), 10) delete tbCashReportCreditCard where ComputerID = @ComputerID if @RangeType = 1 Begin insert into tbCashReportCreditCard select c.TransDate, SUBSTRING(c.TransNum, 3, 10) TransNum, c.PaymentFrom, s.Particulars, s.NetAmount [Amount], c.Card, convert(varchar(10), c. Cutoffdate, 101) as ReportDate, '', @ComputerID from tbcashcardmaster c left join tbcashchargeslips s on c.transnum = s.refnum where c.cutoffdate between @ReportDate and @EndDate + ' 23:59:59.99' and c.status = '' and (isnull(C.Card,'') = @Card or @Card = '') End else Begin insert into tbCashReportCreditCard select c.TransDate, SUBSTRING(c.TransNum, 3, 10) TransNum, c.PaymentFrom, s.Particulars, s.NetAmount [Amount], c.Card, convert(varchar(10), c.TransDate, 101) as ReportDate, '', @ComputerID from tbcashcardmaster c left join tbcashchargeslips s on c.transnum = s.refnum where c.transdate between @ReportDate and @EndDate + ' 23:59:59.99' and c.status = '' and (isnull(C.Card,'') = @Card or @Card = '') End GO ALTER table Patient_Data..tboutpatient add [BadDebt] [bit] NULL GO ALTER table Patient_Data..tbpatient add [BadDebt] [bit] NULL GO use inventory GO alter table tbHospitalinfo add IsUpdateWDPostingDate bit not null default(0) GO alter table tbinvusersettings add isViewMarkup bit not null default(0) GO alter table tbinvmaster add Indication varchar(100), Dosage varchar(100), SpecPrec varchar(100), AdvReac varchar(100), Interaction varchar(100), Preg varchar(100), PrePostAdv varchar(100), Reconstitution varchar(100), Stability varchar(100), Storage varchar(100), PrescriptionID varchar(100) GO alter table tbInvWithdrawHeader add PostingDate datetime GO Alter table tbInvLocation add WDPrefix varchar(20) GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Inv_UpdateUserProfile] @EmployeeID as varchar(10), @intOption as int, @bitValue as bit AS If not Exists( Select * from tbInvUserSettings Where UserID = @EmployeeID) Begin Insert into tbInvUserSettings Select @EmployeeID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0,0,0,0,0,0,0,0,0,0,0,0,0,0; End; If @intOption = 1 Begin Update tbInvUserSettings Set isPOTransaction = @bitValue Where UserID = @EmployeeID; End; If @intOption = 2 Begin Update tbInvUserSettings Set isPODelete = @bitValue Where UserID = @EmployeeID; End; If @intOption = 3 Begin Update tbInvUserSettings Set isPU = @bitValue Where UserID = @EmployeeID; End; If @intOption = 4 Begin Update tbInvUserSettings Set isWD = @bitValue Where UserID = @EmployeeID; End; If @intOption = 5 Begin Update tbInvUserSettings Set isRT = @bitValue Where UserID = @EmployeeID; End; If @intOption = 6 Begin Update tbInvUserSettings Set isAD = @bitValue Where UserID = @EmployeeID; End; If @intOption = 7 Begin Update tbInvUserSettings Set isMaster = @bitValue Where UserID = @EmployeeID; End; If @intOption = 8 Begin Update tbInvUserSettings Set isMasterIPM = @bitValue Where UserID = @EmployeeID; End; If @intOption = 9 Begin Update tbInvUserSettings Set isMasterOPM = @bitValue Where UserID = @EmployeeID; End; If @intOption = 10 Begin Update tbInvUserSettings Set isMasterLC = @bitValue Where UserID = @EmployeeID; End; If @intOption = 11 Begin Update tbInvUserSettings Set isMasterAC = @bitValue Where UserID = @EmployeeID; End; If @intOption = 12 Begin Update tbInvUserSettings Set isMasterPacking = @bitValue Where UserID = @EmployeeID; End; If @intOption = 13 Begin Update tbInvUserSettings Set isLocation = @bitValue Where UserID = @EmployeeID; End; If @intOption = 14 Begin Update tbInvUserSettings Set isLocationIPM = @bitValue Where UserID = @EmployeeID; End; If @intOption = 15 Begin Update tbInvUserSettings Set isLocationOPM = @bitValue Where UserID = @EmployeeID; End; If @intOption = 16 Begin Update tbInvUserSettings Set isLocationIPP = @bitValue Where UserID = @EmployeeID; End; If @intOption = 17 Begin Update tbInvUserSettings Set isLocationOPP = @bitValue Where UserID = @EmployeeID; End; If @intOption = 18 Begin Update tbInvUserSettings Set isLocationTable = @bitValue Where UserID = @EmployeeID; End; If @intOption = 19 Begin Update tbInvUserSettings Set isSupplierTable = @bitValue Where UserID = @EmployeeID; End; If @intOption = 20 Begin Update tbInvUserSettings Set isProdClassTable = @bitValue Where UserID = @EmployeeID; End; If @intOption = 21 Begin Update tbInvUserSettings Set isTermsTable = @bitValue Where UserID = @EmployeeID; End; If @intOption = 22 Begin Update tbInvUserSettings Set isUOMTable = @bitValue Where UserID = @EmployeeID; End; If @intOption = 23 Begin Update tbInvUserSettings Set isUpdateIPP = @bitValue Where UserID = @EmployeeID; End; If @intOption = 24 Begin Update tbInvUserSettings Set isUpdateOPP = @bitValue Where UserID = @EmployeeID; End; If @intOption = 25 Begin Update tbInvUserSettings Set isRecomputeInvBalance = @bitValue Where UserID = @EmployeeID; End; If @intOption = 26 Begin Update tbInvUserSettings Set isUpdateStockCardBalance = @bitValue Where UserID = @EmployeeID; End; If @intOption = 27 Begin Update tbInvUserSettings Set isSystemSettings = @bitValue Where UserID = @EmployeeID; End; If @intOption = 28 Begin Update tbInvUserSettings Set isRIV = @bitValue Where UserID = @EmployeeID; End; If @intOption = 29 Begin Update tbInvUserSettings Set isRIVDelete = @bitValue Where UserID = @EmployeeID; End; If @intOption = 30 Begin Update tbInvUserSettings Set isUpdateLocationTable =@bitValue Where UserID = @EmployeeID; End; If @intOption = 31 Begin Update tbinvUserSettings Set isViewCompanyPrice = @bitValue where UserID = @EmployeeID; End; If @intOption = 32 Begin Update tbinvUserSettings Set isVerifyInventoryRequest = @bitValue where UserID = @EmployeeID; End; If @intOption = 33 Begin Update tbinvUserSettings Set isViewMarkUp = @bitValue where UserID = @EmployeeID; End; If @intOption = 34 Begin Update tbinvUserSettings Set isViewMarkUp = @bitValue where UserID = @EmployeeID; End; if @intOption = 35 Begin Update tbinvUserSettings Set isPOCreate = @bitValue where UserID = @EmployeeID; End; if @intOption = 36 Begin Update tbinvUserSettings Set isPOEdit = @bitValue where UserID = @EmployeeID; End; if @intOption = 37 Begin Update tbinvUserSettings Set isRIVCreate = @bitValue where UserID = @EmployeeID; End; if @intOption = 38 Begin Update tbinvUserSettings Set isRIVEdit = @bitValue where UserID = @EmployeeID; End; if @intOption = 39 Begin Update tbinvUserSettings Set isRRCreate = @bitValue where UserID = @EmployeeID; End; if @intOption = 40 Begin Update tbinvUserSettings Set isRREdit = @bitValue where UserID = @EmployeeID; End; if @intOption = 41 Begin Update tbinvUserSettings Set isRRDelete = @bitValue where UserID = @EmployeeID; End; if @intOption = 42 Begin Update tbinvUserSettings Set isApproveRRCorrection = @bitValue where UserID = @EmployeeID; End; if @intOption = 43 Begin Update tbinvUserSettings Set isApproveWDCorrection = @bitValue where UserID = @EmployeeID; End; go CREATE Procedure [dbo].[sp_Update_tbinvMaster_RR_New] @Recordnumber as integer, @LocationID as varchar(4) as Update tbInvMaster Set ListCost = A.ListCost, Packing = A.Packing, NetCost = A.NetCost, AverageCost = Case When B.OnHand <= 0 Then (A.TotalNetCost/A.Qty) Else (( B.OnHand * C.AverageCost ) + A.TotalNetCost ) / (B.OnHand + A.Qty ) End from tbInvMaster C, tbInvent B, (Select ItemID, ListCost, NetCost, Quantity * Packing As Qty, Packing, TotalNetCost from tbInvRRDetails Where RecordNumber = @Recordnumber ) as A Where C.ItemID = B.ItemID and B.ItemID = A.ItemID and B.LocationID = @LocationID GO CREATE procedure [dbo].[sp_Inv_SaveWDHeader] @RecordNumber int, @LocationID int, @TargetLocationID int, @TransDate datetime, @TransNum varchar(20), @CorrectionEntry bit, @PostingDate datetime as Insert Inventory..tbInvWithdrawHeader (RecordNumber, LocationID, TargetLocationID, TransDate, Transnum, CorrectionEntry, PostingDate ) Values (@RecordNumber, @LocationID, @TargetLocationID, @TransDate, @TransNum, @CorrectionEntry, @PostingDate) GO CREATE procedure [dbo].[sp_Inv_SaveWDHeader_New] @RecordNumber float, @LocationID int, @TargetLocationID int, @TransDate datetime, @CorrectionEntry bit, @PostingDate datetime, @tempWDNumber varchar(50) as Declare @intWDNumber as varchar(50); Declare @intWDYear as varchar(50); Declare @WDNumber as varchar(20); Declare @intWDMonth as varchar(10); Declare @LocationPrex as varchar(5); if @CorrectionEntry = 1 Insert Inventory..tbInvWithdrawHeader (RecordNumber, LocationID, TargetLocationID, TransDate, Transnum, CorrectionEntry, PostingDate ) Values (@RecordNumber, @LocationID, @TargetLocationID, @TransDate, @tempWDNumber, @CorrectionEntry, @PostingDate ) else Set @intWDNumber = IsNull( ( Select IsNull(WDCounter,0) from tbInvLocation Where LocationID = @LocationID ), 0) + 1; Set @intWDYear = IsNull( ( select Year(getdate()) ), 0); set @intWDMonth = IsNull( ( select Month(getdate()) ), 0); Set @LocationPrex = IsNull( ( Select WDPrefix from tbInvLocation where LocationId = @LocationID),0); Set @WDNumber = Right(Cast(@intWDYear as varchar(4)),2) + Right(cast(@intWDMonth as varchar(4)),2) + Replicate('0',7-Len(Cast(@intWDNumber as varchar(7))))+Cast(@intWDNumber as varchar(7)) + '-' + @LocationPrex; Insert Inventory..tbInvWithdrawHeader (RecordNumber, LocationID, TargetLocationID, TransDate, Transnum, CorrectionEntry, PostingDate ) Values (@RecordNumber, @LocationID, @TargetLocationID, @TransDate, @WDNumber, @CorrectionEntry, @PostingDate ) Update tbInvLocation Set WDCounter = Cast(IsNull(WDCounter,0) as int) + 1 Where LocationID = @LocationID; select isWDNumberEntered, ispoentered,iswdentered, * from update tbhospitalinfo set isWDNumberEntered = 0 GO USE [Patient_Data] GO /****** Object: Table [dbo].[tbPatientImage] Script Date: 7/9/2015 6:50:09 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbPatientImage]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [HospNum] [varchar](15) NULL, [IDNum] [varchar](15) NULL, [DoctorID] [varchar](15) NULL, [PatImage] [image] NULL, [FileType] [varchar](15) NULL, [FileName] [varchar](30) NULL, [FileSize] [int] NULL, [ImgNote] [text] NULL, [Confidential] [varchar](1) NULL, [TransDATE] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO create index byPatientID on Patient_Data.dbo.tbPatientImage(IDNum) GO create index byPatientHospNum on Patient_Data.dbo.tbPatientImage(HospNum) GO USE [build_file] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbDBImage]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [TableName] [varchar](50) NULL, [FieldName] [varchar](50) NULL, [IDKEY] [varchar](15) NULL, [DBImage] [image] NULL, [FileType] [varchar](15) NULL, [FileName] [varchar](30) NULL, [FileSize] [int] NULL, [ImgNote] [text] NULL, [Confidential] [varchar](1) NULL, [TransDATE] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO create index byTableFieldID on build_file.dbo.tbDBImage(TableName,FieldName,IDKEY) GO create index byIDKey on build_file.dbo.tbDBImage(IDKEY) GO Alter table Patient_data..tbhospitalinfo Add isAllowAssessmentDiscount bit GO Alter table Patient_data..tbopd_settings Add isAssesmentMarkup bit, IsPostChargeMarkup bit GO USE INVENTORY alter table tbinvpoheader add POUserID varchar(15) GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Inv_SaveEditedPOHeader] @intRecordNumber as int OutPut, @PONumber as varchar(20) OutPut, @SupplierID as varchar(12), @OrderDate smalldatetime, @LocationID as varchar(10), @Requisitioner as varchar(10), @RIVNumber as varchar(20), @RIVDate as smalldatetime, @TotalCost as float, @Remarks as varchar(50), @TermsID as int, @CancelDate as smalldatetime, @Footer as varchar(254), @bitVAT as bit, @bitAccredited as bit, @bitDelivered as bit, @intProcurement as int, @intCurrencyID as int, @Discount as int, @bitEP as bit = 0, @InvoiceNumber as varchar(20) = null, @FixedDiscount as int, @UserID as varchar(15) AS Declare @fltVIP as float; Set @fltVIP = ( Select IsNull(ValueInPeso,0) from tbInvCurrency Where CurrencyID = @intCurrencyID ); Update tbInvPOHeader Set SupplierID = @SupplierID, OrderDate = @OrderDate, LocationID = @LocationID, Requisitioner = @Requisitioner, RIVNumber = @RIVNumber, RIVDate = @RIVDate, TotalCost = @TotalCost, Remarks = @Remarks, TermsID = @TermsID, CancelDate = @CancelDate, Footer = @Footer, isVAT = @bitVAT, isAccredited = @bitAccredited, isDelivered = @bitDelivered, ProcurementID = @intProcurement, CurrencyID = @intCurrencyID, ValueInPeso = @fltVIP, Discount = @Discount, InvoiceNumber = @InvoiceNumber, isEP = @bitEP, FixedDiscount = @FixedDiscount, POUserID = @UserID Where RecordNumber = @intRecordNumber; go ALTER PROCEDURE [dbo].[sp_Inv_SavePOHeader] @intRecordNumber as int OutPut, @PONumber as varchar(20) OutPut, @SupplierID as varchar(12), @OrderDate smalldatetime, @LocationID as varchar(10), @Requisitioner as varchar(10), @RIVNumber as varchar(20), @RIVDate as datetime, @TotalCost as float, @Remarks as varchar(50), @TermsID as int, @CancelDate as smalldatetime, @Footer as varchar(254), @bitVAT as bit, @bitAccredited as bit, @bitDelivered as bit, @intProcurement as int, @intCurrencyID as int, @Discount as int, @isEP as bit = 0, @InvoiceNumber as varchar(10) = null, @EmployeeID as varchar(15) = null, @FixedDiscount as float, @UserID as varchar(15) AS set @IntRecordNumber = '' set @FixedDiscount = '' Declare @intTempRecordNumber as int; Declare @fltVIP as int; Set @fltVIP = ( Select IsNull(ValueInPeso,0) from tbInvCurrency Where CurrencyID = @intCurrencyID ); set @intTempRecordNumber = @intRecordNumber; Set @intRecordNumber = IsNull(( Select Max(IsNull(RecordNumber,0)) + 1 [MaxNumber] from tbInvPOHeader),1); If @intRecordNumber = 0 Begin Set @intRecordNumber = 1; End; if @LocationID = '69' Begin Set @PONumber = IsNull( ( Select Cast(Max(Cast(IsNull(Case When isNumeric(PONumber) = 1 Then PONumber Else Left(PONumber, len(PONumber) - 1) End,0) as int))+1 as varchar(15)) from tbInvPOHeader), 1); Set @PONumber = @PONumber + 'A'; End; else Begin Set @PONumber = IsNull( ( Select Cast(Max(Cast(IsNull(Case When isNumeric(PONumber) = 1 Then PONumber Else Left(PONumber, len(PONumber) - 1) End,0) as int))+1 as varchar(15)) from tbInvPOHeader), 1); Set @PONumber = @PONumber + isnull((Select isnull(POSuffix,'') From tbInvUserSettings Where UserId = @EmployeeID),'') End; Insert into tbInvPOHeader( PONumber, SupplierID, OrderDate, LocationID, Requisitioner, RIVNumber, RIVDate, RecordNumber, TotalCost, Remarks, OrderStatus, TermsID, CancelDate, Footer, isVAT, isAccredited, isDelivered, ProcurementID, CurrencyID, ValueInPeso, Discount, isEP, InvoiceNumber, FixedDiscount, POUserID ) Values( @PONumber, @SupplierID, GetDate(), @LocationID, @Requisitioner, @RIVNumber, @RIVDate, @intRecordNumber, @TotalCost, @Remarks, 'U', @TermsID, @CancelDate, @Footer, @bitVAT, @bitAccredited, @bitDelivered, @intProcurement, @intCurrencyID, @fltVIP, @Discount, @isEP, @InvoiceNumber, @FixedDiscount, @UserID ); Update tbInvPOFree Set PORecordNumber = @intRecordNumber, PONumber = @PONumber Where PORecordNumber = 0 and PONumber = 'New'; go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Inv_SavePOHeader_POEntered] @intRecordNumber as int OutPut, @PONumber as varchar(20) OutPut, @SupplierID as varchar(12), @OrderDate smalldatetime, @LocationID as varchar(10), @Requisitioner as varchar(20), @RIVNumber as varchar(20), @RIVDate as datetime, @TotalCost as float, @Remarks as varchar(50), @TermsID as int, @CancelDate as smalldatetime, @Footer as varchar(254), @bitVAT as bit, @bitAccredited as bit, @bitDelivered as bit, @intProcurement as int, @intCurrencyID as int, @Discount as int, @isEP as bit = 0, @InvoiceNumber as varchar(10) = null, @FixedDiscount as int, @UserID as varchar(15) AS Declare @intTempRecordNumber as int; Declare @fltVIP as float; Set @fltVIP = ( Select IsNull(ValueInPeso,0) from tbInvCurrency Where CurrencyID = @intCurrencyID ); set @intTempRecordNumber = @intRecordNumber; Set @intRecordNumber = IsNull(( Select Max(IsNull(RecordNumber,0)) + 1 [MaxNumber] from tbInvPOHeader),1); If @intRecordNumber = 0 Begin Set @intRecordNumber = 1; End; Insert into tbInvPOHeader( PONumber, SupplierID, OrderDate, LocationID, Requisitioner, RIVNumber, RIVDate, RecordNumber, TotalCost, Remarks, OrderStatus, TermsID, CancelDate, Footer, isVAT, isAccredited, isDelivered, ProcurementID, CurrencyID, ValueInPeso, Discount, isEP, InvoiceNumber, FixedDiscount, POUserID ) Values( @PONumber, @SupplierID, GetDate(), @LocationID, @Requisitioner, @RIVNumber, @RIVDate, @intRecordNumber, @TotalCost, @Remarks, 'U', @TermsID, @CancelDate, @Footer, @bitVAT, @bitAccredited, @bitDelivered, @intProcurement, @intCurrencyID, @fltVIP, @Discount, @isEP, @InvoiceNumber, @FixedDiscount, @UserID ); Update tbInvPOFree Set PORecordNumber = @intRecordNumber Where PONumber = @PONumber and PORecordNumber = 0; go ALTER PROCEDURE [dbo].[sp_Inv_StockCardList] @LocationID as varchar(10), @ItemID as varchar(10), @StartDate as varchar(10), @EndDate as varchar(10) AS --set @locationid = '21' --set @itemid = '5467' --set @startdate = '10/01/2007' --set @enddate = '02/11/2008' Select A.TransDate As "Date", A.SummaryCode + Case When isnull(A.isADS,0) = 1 Then '-ADS' else '' End as "Account", A.HospNum as "Hosp.#", A.IDNum as "Adm #", A.RefNum as "Ref. #", Case A.SummaryCode When 'AD' then 'Adjustment' When 'RS' then 'Return to ' + C.SupplierName When 'WD' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'To - ' + B.Location When 'RT' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'From - ' + B.Location When 'PU' then C.SupplierName When 'CM' then 'Credit Memo' Else '' End as [Trans.Description], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('WD','RS','PH','CS') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then A.Quantity Else '' End End as Decimal(12)) [IN], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('WD','RS','PH','CS') Then A.Quantity Else '' End End as Decimal(12)) [OUT], Cast(A.Balance as Decimal(12)) [Balance], Case When SummaryCode in ('PU','RS','WS','RT') Then convert(VarChar(15),isnull(A.NetCost,0)) Else '' End AS [Net Cost], Convert(VarChar(10), A.Consumption_Date,101) As Expiration, A.LotNumber, A.Packing, Case when left(A.RefNum, 2) = 'OR' then IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = D.UserID ), '') Else IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = A.UserID ), '') End as [User], (Select top 1 RRNumber from tbInvRRheader Where transnum = A.RefNum) [RR #], (Select top 1 PostingDate from tbInvWithdrawHeader Where TransNum = A.RefNum) [Posting Date] from tbInvStockCard A Left Outer Join tbInvLocation B ON A.TargetLocationID = B.LocationID Left Outer Join tbinvSupplier C ON A.TargetLocationID = C.SupplierID left outer join billing..tbcashassessment D on A.RefNum = D.ORNumber and A.ItemID = D.ItemID WHERE A.LocationID = @LocationID and A.ItemID = @ItemID And A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' --ORDER BY A.Transdate Desc Union All Select A.TransDate As "Date", A.SummaryCode + Case When isnull(A.isADS,0) = 1 Then '-ADS' else '' End as "Account", A.HospNum as "Hosp.#", A.IDNum as "Adm #", A.RefNum as "Ref. #", Case A.SummaryCode When 'AD' then 'Adjustment' When 'RS' then 'Return to ' + C.SupplierName When 'WD' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'To - ' + B.Location When 'RT' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'From - ' + B.Location When 'PU' then C.SupplierName When 'CM' then 'Credit Memo' Else '' End as [Trans.Description], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('WD','RS','PH','CS') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then A.Quantity Else '' End End as Decimal(12)) [IN], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('WD','RS','PH','CS') Then A.Quantity Else '' End End as Decimal(12)) [OUT], Cast(A.Balance as Decimal(12)) [Balance], Case When SummaryCode in ('PU','RS','WS','RT') Then convert(VarChar(15),isnull(A.NetCost,0)) Else '' End AS [Net Cost], Convert(VarChar(10), A.Consumption_Date,101) As Expiration, A.LotNumber, A.Packing, IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = A.UserID ), '') [User], (Select top 1 RRNumber from tbInvRRheader Where transnum = A.RefNum) [RR #], (Select top 1 PostingDate from tbInvWithdrawHeader Where TransNum = A.RefNum) [Posting Date] from History..tbPassInvStock A Left Outer Join tbInvLocation B ON A.TargetLocationID = B.LocationID Left Outer Join tbinvSupplier C ON A.TargetLocationID = C.SupplierID WHERE A.LocationID = @LocationID and A.ItemID = @ItemID And A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' ORDER BY A.Transdate Desc go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Inv_StockCardList_ASC] @LocationID as varchar(10), @ItemID as varchar(10), @StartDate as varchar(10), @EndDate as varchar(10) AS --set @locationid = '20' --set @itemid = '5411' --set @startdate = '10/01/2007' --set @enddate = '02/11/2008' Select A.TransDate As "Date", A.SummaryCode + Case When isnull(A.isADS,0) = 1 Then '-ADS' else '' End as "Account", A.HospNum as "Hosp.#", A.IDNum as "Adm #", A.RefNum as "Ref. #", Case A.SummaryCode When 'AD' then 'Adjustment' When 'RS' then 'Return to ' + C.SupplierName When 'WD' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'To - ' + B.Location When 'RT' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'From - ' + B.Location When 'PU' then C.SupplierName When 'CM' then 'Credit Memo' Else '' End as [Trans.Description], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('WD','RS','PH','CS') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then A.Quantity Else '' End End as Decimal(12)) [IN], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('WD','RS','PH','CS') Then A.Quantity Else '' End End as Decimal(12)) [OUT], Cast(A.Balance as Decimal(12)) [Balance], Case When SummaryCode in ('PU','RS','WS','RT') Then convert(VarChar(15),isnull(A.NetCost,0)) Else '' End AS [Net Cost], Convert(VarChar(10), A.Consumption_Date,101) As Expiration, A.LotNumber, A.Packing, Case when left(A.RefNum, 2) = 'OR' then IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = D.UserID ), '') Else IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = A.UserID ), '') End as [User], (Select top 1 RRNumber from tbInvRRheader Where transnum = A.RefNum) [RR #], (Select top 1 PostingDate from tbInvWithdrawHeader Where TransNum = A.RefNum) [Posting Date] from tbInvStockCard A Left Outer Join tbInvLocation B ON A.TargetLocationID = B.LocationID Left Outer Join tbinvSupplier C ON A.TargetLocationID = C.SupplierID left outer join billing..tbcashassessment D on A.RefNum = D.ORNumber and A.ItemID = D.ItemID WHERE A.LocationID = @LocationID and A.ItemID = @ItemID And A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' --ORDER BY A.Transdate Desc Union All Select A.TransDate As "Date", A.SummaryCode + Case When isnull(A.isADS,0) = 1 Then '-ADS' else '' End as "Account", A.HospNum as "Hosp.#", A.IDNum as "Adm #", A.RefNum as "Ref. #", Case A.SummaryCode When 'AD' then 'Adjustment' When 'RS' then 'Return to ' + C.SupplierName When 'WD' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'To - ' + B.Location When 'RT' then Case When A.Quantity < 0 then '*Adjustment*' Else '' End + 'From - ' + B.Location When 'PU' then C.SupplierName When 'CM' then 'Credit Memo' Else '' End as [Trans.Description], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('WD','RS','PH','CS') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then A.Quantity Else '' End End as Decimal(12)) [IN], Cast(Case When A.Quantity < 0 Then Case When A.SummaryCode in ('PU','RT','PC','CC', 'CM') Then Abs(A.Quantity) Else '' End Else Case When A.SummaryCode in ('WD','RS','PH','CS') Then A.Quantity Else '' End End as Decimal(12)) [OUT], Cast(A.Balance as Decimal(12)) [Balance], Case When SummaryCode in ('PU','RS','WS','RT') Then convert(VarChar(15),isnull(A.NetCost,0)) Else '' End AS [Net Cost], Convert(VarChar(10), A.Consumption_Date,101) As Expiration, A.LotNumber, A.Packing, IsNull( ( Select Top 1 IsNull(LastName,'') + ', ' + IsNull(FirstName,'') + ' ' + IsNull(MiddleName,'') from Password..tbPasswordMain Where EmployeeID = A.UserID ), '') [User], (Select top 1 RRNumber from tbInvRRheader Where transnum = A.RefNum) [RR #], (Select top 1 PostingDate from tbInvWithdrawHeader Where TransNum = A.RefNum) [Posting Date] from History..tbPassInvStock A Left Outer Join tbInvLocation B ON A.TargetLocationID = B.LocationID Left Outer Join tbinvSupplier C ON A.TargetLocationID = C.SupplierID WHERE A.LocationID = @LocationID and A.ItemID = @ItemID And A.TransDate Between @StartDate and @EndDate + ' 23:59:59.99' ORDER BY A.Transdate go ALTER PROCEDURE [dbo].[sp_Inv_SavePOHeader] @intRecordNumber as int OutPut, @PONumber as varchar(20) OutPut, @SupplierID as varchar(12), @OrderDate smalldatetime, @LocationID as varchar(10), @Requisitioner as varchar(10), @RIVNumber as varchar(20), @RIVDate as datetime, @TotalCost as float, @Remarks as varchar(50), @TermsID as int, @CancelDate as smalldatetime, @Footer as varchar(254), @bitVAT as bit, @bitAccredited as bit, @bitDelivered as bit, @intProcurement as int, @intCurrencyID as int, @Discount as int, @isEP as bit = 0, @InvoiceNumber as varchar(10) = null, @EmployeeID as varchar(15) = null, @FixedDiscount as float, @UserID as varchar(15) AS set @IntRecordNumber = '' set @FixedDiscount = '' Declare @intTempRecordNumber as int; Declare @fltVIP as int; Set @fltVIP = ( Select IsNull(ValueInPeso,0) from tbInvCurrency Where CurrencyID = @intCurrencyID ); set @intTempRecordNumber = @intRecordNumber; Set @intRecordNumber = IsNull(( Select Max(IsNull(RecordNumber,0)) + 1 [MaxNumber] from tbInvPOHeader),1); If @intRecordNumber = 0 Begin Set @intRecordNumber = 1; End; if @LocationID = '69' Begin Set @PONumber = IsNull( ( Select Cast(Max(Cast(IsNull(Case When isNumeric(PONumber) = 1 Then PONumber Else Left(PONumber, len(PONumber) - 1) End,0) as int))+1 as varchar(15)) from tbInvPOHeader), 1); Set @PONumber = @PONumber + 'A'; End; else Begin Set @PONumber = IsNull( ( Select Cast(Max(Cast(IsNull(Case When isNumeric(PONumber) = 1 Then PONumber Else Left(PONumber, len(PONumber) - 1) End,0) as int))+1 as varchar(15)) from tbInvPOHeader), 1); Set @PONumber = @PONumber + isnull((Select isnull(POSuffix,'') From tbInvUserSettings Where UserId = @EmployeeID),'') End; Insert into tbInvPOHeader( PONumber, SupplierID, OrderDate, LocationID, Requisitioner, RIVNumber, RIVDate, RecordNumber, TotalCost, Remarks, OrderStatus, TermsID, CancelDate, Footer, isVAT, isAccredited, isDelivered, ProcurementID, CurrencyID, ValueInPeso, Discount, isEP, InvoiceNumber, FixedDiscount, POUserID ) Values( @PONumber, @SupplierID, GetDate(), @LocationID, @Requisitioner, @RIVNumber, @RIVDate, @intRecordNumber, @TotalCost, @Remarks, 'U', @TermsID, @CancelDate, @Footer, @bitVAT, @bitAccredited, @bitDelivered, @intProcurement, @intCurrencyID, @fltVIP, @Discount, @isEP, @InvoiceNumber, @FixedDiscount, @UserID ); Update tbInvPOFree Set PORecordNumber = @intRecordNumber, PONumber = @PONumber Where PORecordNumber = 0 and PONumber = 'New'; GO USE [Billing] GO /****** Object: StoredProcedure [dbo].[sp_Billing_LoadDiscountRates] Script Date: 10/04/2011 17:09:42 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_Billing_LoadDiscountRates] @DiscountType varchar(2), @AccountNum varchar(10), @SubType varchar(1) = '', @IdNum varchar(12) = '1' AS if @DiscountType = 'BH' begin select RevenueID, Rate, case when NetPHIC = 1 then 'Y' else 'N' end NetPHIC from BUILD_FILE..tbCoDiscountRates where DiscountType = @DiscountType and SubType = @SubType end else if exists (select top 1 RevenueID from BUILD_FILE..tbCoDiscountRates where DiscountType = @DiscountType and AccountNum = @AccountNum ) begin select RevenueID, Rate, case when NetPHIC = 1 then 'Y' else 'N' end NetPHIC from BUILD_FILE..tbCoDiscountRates where DiscountType = @DiscountType and AccountNum = @AccountNum end else begin -- select RevenueID, Rate, -- case when NetPHIC = 1 -- then 'Y' -- else 'N' -- end NetPHIC -- from BUILD_FILE..tbCoDiscountRates -- where DiscountType = @DiscountType -- and AccountNum = '' If IsNumeric(@IDNUM) = 1 OR @IDNUM = '' begin select RevenueID, Rate, case when NetPHIC = 1 then 'Y' else 'N' end NetPHIC from BUILD_FILE..tbCoDiscountRates where DiscountType = @DiscountType and AccountNum = '' end Else begin select RevenueID, isNull(OPRAte,0) as Rate, case when NetPHIC = 1 then 'Y' else 'N' end NetPHIC from BUILD_FILE..tbCoDiscountRates where DiscountType = @DiscountType and AccountNum = '' End end GO USE [RADIOLOGY] GO if not exists (SELECT 1 FROM [tbOBUserSettings]) begin insert into tbOBUserSettings values(1, 'Assessment', 'A') insert into tbOBUserSettings values(2, 'Out Patient Request Entry', 'A') insert into tbOBUserSettings values(3, 'InPatient Request Entry', 'A') insert into tbOBUserSettings values(4, 'Result Entry', 'A') insert into tbOBUserSettings values(5, 'Result Inquiry', 'A') insert into tbOBUserSettings values(6, 'Result Verification', 'A') insert into tbOBUserSettings values(7, 'Monthly Transaction Report', 'A') insert into tbOBUserSettings values(8, 'Default Radiologist', 'A') insert into tbOBUserSettings values(9, 'Request Cancellation', 'A') insert into tbOBUserSettings values(10, 'Walk-In Master File Update', 'A') insert into tbOBUserSettings values(11, 'ChargeSlip Duplicate', 'A') insert into tbOBUserSettings values(12, 'Slip Verification', 'A') insert into tbOBUserSettings values(13, 'Patient Ledger', 'A') insert into tbOBUserSettings values(14, 'In Patient Census', 'A') insert into tbOBUserSettings values(15, 'Communication', 'A') insert into tbOBUserSettings values(16, 'Request Status', 'A') insert into tbOBUserSettings values(17, 'Scheduling', 'A') insert into tbOBUserSettings values(18, 'Chargeslip Settings', 'A') insert into tbOBUserSettings values(19, 'Assessment Status', 'A') insert into tbOBUserSettings values(20, 'Audit Report', 'A') insert into tbOBUserSettings values(21, 'Statistical Report', 'A') insert into tbOBUserSettings values(22, 'Form Formats', 'A') insert into tbOBUserSettings values(23, 'Womens Ultrasound Reports', 'A') insert into tbOBUserSettings values(24, 'Daily Census Report', 'A') insert into tbOBUserSettings values(25, 'Interpretation', 'A') end GO USE [PATIENT_DATA] GO Alter table patient_data..tbadmittingsetup add isAllowDischargeBlocklisted bit not null default(0) GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Adm_MasterPatientSubSearch] @LastName as VarChar(50), @Sex As VarChar(1), @BirthDate As VarChar(10) AS Declare @BirthMonth as varchar(2), @BirthDay as varchar(2), @BirthYear as varchar(4), @LastNameF as varchar(50) set @BirthMonth = month(@BirthDate) set @BirthDay = day(@BirthDate) set @Birthyear = year(@BirthDate) set @LastNameF = left(@LastName,3) BEGIN SELECT Distinct Master.LastName AS [Last Name], Master.FirstName AS [First Name], Master.MiddleName AS [Middle Name], Master.HospNum AS [Hospital #], convert(varchar(10),Master.BirthDate,101) AS [Birth Date], Master.Age, RTRIM( ISNULL( Master.HouseStreet ,'' ) ) + ' ' + RTRIM( ISNULL( Master.Barangay,'' ) ) + ', ' + RTRIM( ISNULL(Address.Town,'' ) ) + ' ' + RTRIM( ISNULL( Address.Province,'') ) AS Address, Master.AccountNum AS [Account #] FROM tbMaster AS Master LEFT OUTER JOIN Build_File..tbCoAddress AS Address ON Master.ZipCode = Address.ZipCode WHERE Master.LastName Like '%' + @LastNameF + '%' AND -- Master.Sex Like @Sex + '%' AND (month(Master.Birthdate) = @BirthMonth and day(Master.Birthdate) = @BirthDay) -- ORDER BY Master.LastName, Master.FirstName, Master.MiddleName UNION ALL SELECT Distinct Master.LastName AS [Last Name], Master.FirstName AS [First Name], Master.MiddleName AS [Middle Name], Master.HospNum AS [Hospital #], convert(varchar(10),Master.BirthDate,101) AS [Birth Date], Master.Age, RTRIM( ISNULL( Master.HouseStreet ,'' ) ) + ' ' + RTRIM( ISNULL( Master.Barangay,'' ) ) + ', ' + RTRIM( ISNULL(Address.Town,'' ) ) + ' ' + RTRIM( ISNULL( Address.Province,'') ) AS Address, Master.AccountNum AS [Account #] FROM tbMaster AS Master LEFT OUTER JOIN Build_File..tbCoAddress AS Address ON Master.ZipCode = Address.ZipCode WHERE Master.LastName Like '%' + @LastNameF + '%' AND -- Master.Sex Like @Sex + '%' AND (month(Master.Birthdate) = @BirthMonth and year(Master.Birthdate) = @BirthYear) UNION ALL SELECT Distinct Master.LastName AS [Last Name], Master.FirstName AS [First Name], Master.MiddleName AS [Middle Name], Master.HospNum AS [Hospital #], convert(varchar(10),Master.BirthDate,101) AS [Birth Date], Master.Age, RTRIM( ISNULL( Master.HouseStreet ,'' ) ) + ' ' + RTRIM( ISNULL( Master.Barangay,'' ) ) + ', ' + RTRIM( ISNULL(Address.Town,'' ) ) + ' ' + RTRIM( ISNULL( Address.Province,'') ) AS Address, Master.AccountNum AS [Account #] FROM tbMaster AS Master LEFT OUTER JOIN Build_File..tbCoAddress AS Address ON Master.ZipCode = Address.ZipCode WHERE Master.LastName Like '%' + @LastNameF + '%' AND -- Master.Sex Like @Sex + '%' AND (day(Master.Birthdate) = @BirthDay and year(Master.Birthdate) = @BirthYear) ORDER BY Master.LastName, Master.FirstName, Master.MiddleName END GO Alter table Patient_data..tbDOHSetup add [IsAllowYearly] [bit] NOT NULL DEFAULT ((0)), [IsAllowQuarterly] [bit] NOT NULL DEFAULT ((0)) GO use clinical_area go ALTER PROCEDURE [dbo].[spGeneric_SaveAccessRights] @UserID as varchar(15), @RevenueID as varchar(5), @RevenueName as varchar(100), @RevTransSetting as varchar(1), @Status as varchar(1) AS if exists(Select * from Clinical_Area..tbGenericAccess where UserID = @UserID and revenueID = @RevenueID) begin Update Clinical_Area..tbGenericAccess set Status = @Status, RevTransSetting = @RevTransSetting where UserID = @UserID and RevenueID = @RevenueID end else begin Insert into Clinical_Area..tbGenericAccess (UserID, RevenueID, RevenueName, RevTransSetting, Status) values(@UserID, @RevenueID, @RevenueName, @RevTransSetting, @Status) end go ALTER Procedure [dbo].[spGeneric_GetRevenueAccess] --declare @userID as varchar(10) --set @userid = '28' as select '', revenueid as MenuID, RevenueName as Menu, case when RevTransSetting = 'D' then 'Default' when RevTransSetting = 'I' then 'Immediate' when RevTransSetting = 'Y' then 'Can Access' when RevTransSetting = 'N' then 'No Access' end as Setting, case when RevTransSetting = 'N' then '0' else '1' End as Status from Clinical_Area..tbGenericAccess where userid = @userid union all select '', revenueid as MenuID, ItemName as Menu, 'No Access' as Setting, '0' as Status from build_file..tbcorevenuecode where GenericActive = 'Y' --and rwith = 'Y' and locationid = '' and revenueid not in(Select revenueid from tbGenericAccess where userid = @userid) go USE [Clinical_Area] GO -- Add Default Constraint DF__tbHospita__IsMar__76818E95 to tbHospitalInfo Print 'Add Default Constraint DF__tbHospita__IsMar__76818E95 to tbHospitalInfo' GO ALTER TABLE [dbo].[tbHospitalInfo] ADD CONSTRAINT [DF__tbHospita__IsMar__76818E95] DEFAULT ((0)) FOR [IsMarkup] GO -- Create Index IX_tbLinacMaster on tbLinacMaster Print 'Create Index IX_tbLinacMaster on tbLinacMaster' GO CREATE INDEX [IX_tbLinacMaster] ON [dbo].[tbLinacMaster] ([HospNum], [IdNum]) GO -- Create Index IX_tbLinacMaster_1 on tbLinacMaster Print 'Create Index IX_tbLinacMaster_1 on tbLinacMaster' GO CREATE CLUSTERED INDEX [IX_tbLinacMaster_1] ON [dbo].[tbLinacMaster] ([RequestNum]) GO -- Add Column IsPrinted to tbEyeCareMaster Print 'Add Column IsPrinted to tbEyeCareMaster' GO ALTER TABLE [dbo].[tbEyeCareMaster] ADD [IsPrinted] bit NOT NULL CONSTRAINT [DF_tbEyeCareMaster_IsPrinted] DEFAULT (0) GO -- Add Column Doctor to tbPulmoChargeSlip Print 'Add Column Doctor to tbPulmoChargeSlip' GO ALTER TABLE [dbo].[tbPulmoChargeSlip] ADD [Doctor] varchar(50) NULL GO -- Add Column Tag to tbPulmoChargeSlip Print 'Add Column Tag to tbPulmoChargeSlip' GO ALTER TABLE [dbo].[tbPulmoChargeSlip] ADD [Tag] varchar(1) NULL GO -- Add Primary Key PK_tbPTResult to tbPTResult Print 'Add Primary Key PK_tbPTResult to tbPTResult' GO ALTER TABLE [dbo].[tbPTResult] ADD CONSTRAINT [PK_tbPTResult] PRIMARY KEY NONCLUSTERED ([IDNum]) GO -- Add Default Constraint DF_tbEndoMaster_ReaderFee to tbEndoMaster Print 'Add Default Constraint DF_tbEndoMaster_ReaderFee to tbEndoMaster' GO ALTER TABLE [dbo].[tbEndoMaster] ADD CONSTRAINT [DF_tbEndoMaster_ReaderFee] DEFAULT ('') FOR [ReaderFee] GO USE FIXEDASSET /** **/ GO INSERT INTO FixedAsset..ACCESSTYPES (AccessID,Description,Sequence) VALUES ('DI','DELETE ITEM','15') PRINT 'ACCESS TO DELETE MANAGED ASSET (FROM ASSET MANAGER)' GO INSERT INTO FixedAsset..ACCESSTYPES (AccessID,Description,Sequence) VALUES ('DA','DELETE MASSET','16') PRINT 'ACCESS TO DELETE BUILT MASTER ITEM' GO insert into FixedAsset..ACCESSTYPES(AccessID,Description,Sequence) values('UT','UPDATE ASSET TYPE','18') PRINT 'ACCESS TO UPDATE ASSET CATEGORY--LINK TO ACCOUNTING' GO insert into FixedAsset..ACCESSTYPES(AccessID,Description,Sequence) values('UA','UPDATE ASSET NAME','17') PRINT 'ACCESS TO UPDATE ASSET CODE' GO alter table fixedasset..tbfasys add getFAfromInventory bit default('0') GO alter table fixedasset..tbfasys add isFixedAcctCode bit default('1') GO alter table fixedasset..tbfasys add enablePO bit default('0') GO alter table fixedasset..tbfasys add enablePR bit default('0') GO alter table fixedasset..tbfasys add enableCA bit default('1') GO alter table patient_data..tbhospitalinfo add [AllowViewLabVerifiedResult] bit NOT NULL Default((0)), [AllowToViewDischargePatients] bit NOT NULL Default((0)) GO USE Radiology GO create PROCEDURE [dbo].[spRadio_CheckPending_AllSecs] AS ------ modified by cynthia (to ensure that all requested items exist in build_file------- select count(*) as TotalPending from STATION..tbNurseCommunicationFile A inner join Radiology..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 and isnull(P.OPDStatus,'') <> 'R') P on A.IdNum = P.IdNum where A.Revenueid in ('XR','CT','US','MI','MS','MM','MG','NU','PG','WC','O1') and isnull(A.RecordStatus,'') = '' GO USE [Password] GO CREATE TABLE [dbo].[tbChangeLog]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [UpdateDate] [datetime] NULL, [UpdatedBy] [nchar](10) NULL, [ActionDone] [varchar](100) NULL ) ON [PRIMARY] GO use Patient_Data go Alter TABLE tbAdmittingSetUp add [IsAllowByPeriodReport] [bit] NOT NULL DEFAULT ('1'), [isAllowDischargewithoutBillingDate] [bit] NOT NULL DEFAULT ('1'), [isAllowDischargeBlockListed] [bit] NOT NULL DEFAULT ((0)), [isAllowAdmitBlockListed] [bit] NOT NULL DEFAULT ((0)) go USE [PATIENT_DATA] go Alter TABLE tbAdmReportSetup add [DoctorsPatientLoad] [bit] NOT NULL DEFAULT ((0)) GO use password go alter table tbpasswordmaster add UpdateDate Datetime GO USE [build_file] GO /****** Object: Table [dbo].[tbcoBarangay] Script Date: 03/27/2012 17:34:09 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbcoBarangay]( [BarangayID] [varchar](6) NULL, [Barangay] [varchar](100) NULL, [Status] [bit] NOT NULL DEFAULT ((1)) ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO USE [patient_data] GO /****** Object: StoredProcedure [dbo].[sp_adm_RoomStatus] Script Date: 03/27/2012 17:33:07 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_adm_RoomStatus] @Search as varchar(20) = '', @StationID As VarChar(4) = '' AS Select Room, max([Patient Name]) [Patient Name], max(NoticeDate) NoticeDate, max([Billed Date]) [Billed Date], max([BillUpTo Date]) [BillUpTo Date], max([Discharge Date]) [Discharge Date], max([Paid Date]) [Paid Date], max([Room Remarks]) [Room Remarks] from ( select ltrim(rtrim(R.Roomid)) as Room, case when NoticeDate is not null then N.patientname when P.RoomId is not null then M.FirstName + ' ' + isnull(left(M.MiddleName, 1) + '. ','') + M.LastName else '' end as [Patient Name], isnull(convert(varchar,NoticeDate,100),'') as NoticeDate, isnull(convert(varchar,BilledDate,100),'') as [Billed Date], isnull(convert(varchar,BillUpTo,100),'') as [BillUpTo Date], isnull(convert(varchar,DcrDate,100),'') as [Discharge Date], isnull(convert(varchar,PaidDate,100),'') as [Paid Date], isnull(r.Remarks,'') as [Room Remarks], IsNull(R.StationID,'') As StationID from Build_File..tbcoRoom R left outer join Patient_Data..tbpatient P on R.roomid = P.roomid left outer join Patient_Data..tbMaster M on P.Hospnum = M.HospNum left outer join Station..tbNurseDischargeNotice N on P.Idnum = N.Idnum where convert(varchar,noticedate, 101) = convert(varchar(10), getdate(), 101) or p.dcrdate is null union all select ltrim(rtrim(R.Roomid)) as Room, case when NoticeDate is not null then '(Watcher) ' + N.patientname when P.RoomId is not null then '(Watcher) ' + Patient_Data.dbo.fn_GetCompleteName(P.Hospnum) else '' end as [Patient Name], isnull(convert(varchar,NoticeDate,100),'') as NoticeDate, isnull(convert(varchar,BilledDate,100),'') as [Billed Date], isnull(convert(varchar,BillUpTo,100),'') as [BillUpTo Date], isnull(convert(varchar,DcrDate,100),'') as [Discharge Date], isnull(convert(varchar,PaidDate,100),'') as [Paid Date], isnull(r.Remarks,'') as [Room Remarks], IsNull(R.StationID,'') As StationID from Build_File..tbcoRoom R left outer join Patient_Data..tbAdmWatcherMaster P on R.roomid = P.roomid left outer join Station..tbNurseDischargeNotice N on P.Idnum = N.Idnum where convert(varchar,noticedate, 101) = convert(varchar(10), getdate(), 101) or p.dcrdate is null ) A where A.Room like @Search + '%' AND (A.StationID = @StationID or @StationID = '') group by Room order by Room GO USE [PATIENT_DATA] GO alter TABLE [dbo].[tbpatientGuarantor] alter column [IDNum] [varchar](15) NOT NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [GuarantorName] [varchar](100) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [GuarantorAddress] [varchar](200) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [GuarantorEmployer] [varchar](100) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [GuarantorTelNum] [varchar](20) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [EmployerAddress] [varchar](100) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [PatientRelationship] [varchar](50) NULL GO alter TABLE [dbo].[tbpatientGuarantor] alter column [GuarantorRelation] [varchar](50) NULL GO alter TABLE [dbo].[tbpatientGuarantor_Revoke] alter column [GuarantorName] [varchar](50) NULL GO alter TABLE [dbo].[tbpatientGuarantor_Revoke] alter column [GuarantorAddress] [varchar](100) NULL GO alter TABLE [dbo].[tbpatientGuarantor_Revoke] alter column [GuarantorEmployer] [varchar](50) NULL GO alter TABLE [dbo].[tbpatientGuarantor_Revoke] alter column [EmployerAddress] [varchar](100) NULL GO alter TABLE [dbo].[tbMaster2] alter column FatherOccupation [varchar](40) NULL GO alter TABLE [dbo].[tbMaster2] alter column MotherOccupation [varchar](40) NULL GO alter TABLE [dbo].[tbMaster2] alter column SpouseAddress [varchar](80) NULL Go alter table Patient_Data..tbMaster2 add SpousePosition varchar(40), Employerposition varchar(40) Go alter table Patient_Data..tbPatientInformant add InformantOccupation varchar(40) GO alter table Build_File..tbCoAdmPackage add AdmActive bit not null default('1') GO alter TABLE Patient_Data..tbMaster add AccountNumII varchar(12) GO USe Patient_Data GO create table patient_Data..tbAdmNicuCommunication( SequenceNumber int PRIMARY KEY IDENTITY, HospNum varchar(15), IDNum varchar(15), PatientName varchar(50), Modification varchar(100), DateModified datetime, NicuUser varchar(80), DateConfirmed datetime, ConfirmingUser varchar(80), Status varchar(1) ) GO -----Create copies with different IDNum as much as you need --insert into tbAdmNicuCommunication(HospNum,IDNum,PatientName,Modification,DateModified,NicuUser) --values('12345','67891','Cruz, BabyBoy M.','Room Transfer: room NICU1 to room 415',getdate(),'Kristy Anne Aban') --insert into tbAdmNicuCommunication(HospNum,IDNum,PatientName,Modification,DateModified,NicuUser) --values('12346','67892','Bruce, BabyBoy A.','Room Transfer: room 234 to room 234',getdate(),'Kristy Anne Aban') USE BUILD_FILE GO create table build_file..tbcoRelationship( RelationshipID varchar(2), Relationship varchar(30), RelationshipStatus bit not null default('1') ) /* insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('1','Mother','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('2','Father','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('3','Son','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('4','Daughter','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('5','Nephew','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('6','Niece','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('7','Brother','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('8','Sister','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('9','Friend','1') insert into build_file..tbcoRelationship(RelationshipID,Relationship,RelationshipStatus) values('10','Others','1') */ Go USE PATIENT_DATA GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Adm_LoadAddedAdmissionInfo] @IDNum as varchar(10) AS Select * from tbPatient2 where IDNum = @IDNum GO ALTER PROCEDURE [dbo].[sp_Adm_SearchPackage] @SearchCriteria varchar(50) AS select isnull(Package,'') as Description, isnull(PackageID,'') as Code from Build_File..tbCoAdmPackage where AdmActive ='1' And (Package like @SearchCriteria + '%' or PackageID = @SearchCriteria or @SearchCriteria = '') order by Package GO ALTER PROCEDURE [dbo].[sp_Adm_UpdateAddedInfo] @IDNum as varchar(12), @PackageID as varchar(5), @AdmissionTypeID as varchar(2), @UserID as varchar(10) , @SeniorCitizen as bit = 0, @WithAdmissionKit as bit = 0, @SeniorCitizenID as varchar(20)= Null, @isOutborn as varchar(1) = null, @isWellBaby as varchar(1) = null, @MotherIDNum as varchar(15) = Null, @WithTransferFee as bit = 0, @isCaesarianDelivery as varchar(1) = null, @NoticeOfAdmID as varchar(1) =null, @CellNumber as varchar(12)=null, @EmailAdd as varchar(40), @SpouseEmp as varchar(30), @GuarantorRelation as varchar(30), @GSISNum as varchar(20), @SSSNum as varchar(20), @HospPlan as varchar(1), @SpousePosition as varchar(40) = null, @SpouseAddress as varchar(80)= null, @SpouseTelNum as varchar(15)= null, @FatherOccupation as varchar(40) = null, @MotherOccupation as varchar(40) = null, @Employerposition as varchar(40)= null, @InformantOccupation as varchar(40)= null, @GuarantorPosition as varchar(40)= null, @AccountNumII as varchar(15)= null AS Declare @Hospnum as varchar(15) Update tbPatient2 Set PackageID = @PackageID, AdmissionTypeID = @AdmissionTypeID, SeniorCitizen = @SeniorCitizen, NoticeOfAdmID = @NoticeOfAdmID Where IDNum = @IDNum; Update tbPatient Set UserID = @UserID, WithAdmissionKit = @WithAdmissionKit, isOutborn = case when @isOutborn = '' then null else @isOutborn end, isWellBaby = case when @isWellBaby = '' then null else @isWellBaby end, MotherIDNum = @MotherIDNum, WithTransferFee = @WithTransferFee, isCaesarianDelivery = case when @isCaesarianDelivery = '' then null else @isCaesarianDelivery end Where IDNum = @IDNum; set @Hospnum = (Select Hospnum from tbPatient where IDNum = @IDNum); Update tbMaster Set SeniorCitizen = @SeniorCitizen, SeniorCitizenID = @SeniorCitizenID, Cellnum = @CellNumber, EmailAddress = @EmailAdd, SpouseEmployer = @SpouseEmp, GSISNum = @GSISNum, SSSNum = @SSSNum, HospPlan = @HospPlan, AccountNumII = @AccountNumII Where Hospnum = @Hospnum; Update tbPatientGuarantor set GuarantorRelation = @GuarantorRelation, GuarantorOccupation = @GuarantorPosition where IDNum = @IDNum; Update tbMaster2 set SpousePosition = @SpousePosition, SpouseAddress = @SpouseAddress, SpouseTelNum = @SpouseTelNum, FatherOccupation = @FatherOccupation, MotherOccupation = @MotherOccupation, Employerposition = @EmployerPosition Where Hospnum = @Hospnum; Update tbPatientInformant set InformantOccupation = @InformantOccupation where IDNum = @IDNum; GO ALTER PROCEDURE [dbo].[sp_Adm_LoadAddedInfo] @IDNum as varchar(10) AS Select P2.PackageID, P2.AdmissionTypeID, P.Package, A.AdmissionType, P2.SeniorCitizen, M.Title, P2.NoticeOfAdmID, N.NoticeOfAdm, M.Cellnum, M.EmailAddress, M.SpouseEmployer, G.GuarantorRelation, M.GSISNum, M.SSSNum, M.HospPlan, M2.SpousePosition, M2.SpouseAddress, M2.SpouseTelNum, M2.FatherOccupation, M2.MotherOccupation, M2.EmployerPosition, G.GuarantorOccupation, I.InformantOccupation, C.AccountNum, C.Company From Patient_Data..tbPatient2 P2 Left Outer Join Build_File..tbCoAdmPackage P on P2.PackageID = P.PackageID Left Outer Join Build_File..tbCoAdmissionType A on A.AdmissionTypeID = p2.AdmissionTypeID Left Outer Join Patient_Data..tbPatient P1 on P2.IdNum = P1.IDNum left Outer Join Patient_Data..tbMaster M on P1.HospNum = M.HospNum left Outer Join Build_File..tbCoNoticeOfAdm N on P2.NoticeOfAdmID = N.NoticeOfAdmID left Outer Join Patient_Data..tbPatientGuarantor G on P1.IdNum = G.IdNum left Outer Join Patient_Data..tbMaster2 M2 on P1.HospNum = M2.HospNum Left Outer Join Patient_Data..tbPatientInformant I on P1.Idnum = I.IdNum Left Outer Join Build_file..tbcoCompany C on M.AccountNumII = C.AccountNum Where P2.IDNum = @IDNum; GO Create Procedure Check_Nicu_Admitting_Communication AS Select '', HospNum, IDNum, PatientName, Modification, left(DateModified,11) as DateModified, NicuUser, SequenceNumber From tbAdmNicuCommunication Where status is null or status ='' GO use patient_data go Alter Table Patient_data..tboutpatient add OPClassification varchar(1) null go Alter table patient_data..tboutPatient add ReasonOfReferral varchar(200) null, ReferredFrom varchar(150) null go Insert into tbOPDmenu values('78','Discharge Entry','1','E','2') go Insert into tbOPDmenu values('79','Discharge Entry','1','F','3') go Delete from tbOPDmenu where menuid in(12,11) go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go USE [Patient_DATA] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'OPD_GetPatientInfo') EXEC ('CREATE PROC dbo.OPD_GetPatientInfo AS SELECT 1') GO ALTER Procedure [OPD_GetPatientInfo] @Idnum as varchar(11), @HospNum as varchar(10) as Select isnull(A.LastName,'') LastName, isnull(A.FirstName,'') FirstName, isnull(A.MiddleName,'') MiddleName, isnull(A.birthDate,'')BirthDate, isnull(A.Sex,'') Sex, dbo.fn_ComputeAge(A.BirthDate, getdate()) Age, isnull(A.Barangay,'')Barangay, Case A.CivilStatus When '0' Then 'Child' When '1' Then 'Single' When '2' then 'Married' When '3' Then 'Widow' when '4' Then 'Separated' When '5' Then 'Divorced' Else '' End AS CivilStatus, B.Idnum, B.HospNum, isnull(B.DoctorID1,'')DoctorID1, isnull(D1.FirstName,'') + ' ' + isnull(D1.LastName,'') as Doctor1, isnull(B.DoctorID2,'')DoctorID2, isnull(D2.FirstName,'') + ' ' + isnull(D2.LastName,'') as Doctor2, isnull(B.DoctorID3,'')DoctorID3, isnull(D3.FirstName,'') + ' ' + isnull(D3.LastName,'') as Doctor3, isnull(B.DoctorID4,'')DoctorID4, isnull(D4.FirstName,'') + ' ' + isnull(D4.LastName,'') as Doctor4, isnull(B.DoctorID5,'')DoctorID5, isnull(D5.firstname,'') + ' ' + isnull(D5.LastName,'') as Doctor5, B.AdmDate, case when (B.AccountNum = B.Hospnum or isnull(B.AccountNum,'') = '') then 'PERSONAL' else C.Company end as Account, B.AccountNum, isnull(B.ServiceID1,'')ServiceID1, isnull(S1.Service,'') as Service1, isnull(B.ServiceID2,'')ServiceID2, isnull(S2.Service,'') as Service2, isnull(B.ServiceID3,'') as ServiceID3, isnull(S3.Service,'') as Service3, isnull(B.ServiceID4,'')ServiceID4, isnull(S4.Service,'') as Service4, isnull(B.ServiceID5,'')ServiceID5, isnull(S5.Service,'') as Service5, isnull(H.chiefcomplaints,'')ChiefComplaints from patient_Data..tboutpatient B left outer join patient_data..tbmaster A on a.hospnum = b.hospnum left outer join build_file..tbcocompany C on b.accountnum = c.accountnum left outer join build_file..tbcodoctor D1 on b.doctorid1 = d1.doctorid left outer join build_file..tbcodoctor D2 on b.doctorid2 = d2.doctorid left outer join build_file..tbcodoctor D3 on b.doctorid3 = d3.doctorid left outer join build_file..tbcodoctor D4 on b.doctorid4 = d4.doctorid left outer join build_file..tbcodoctor D5 on b.doctorid5 = d5.doctorid left outer join build_file..tbcoService S1 on S1.ServiceID = B.serviceid1 left outer join build_file..tbcoService S2 on S2.ServiceID = B.serviceid2 left outer join build_file..tbcoService S3 on S3.ServiceID = B.serviceid3 left outer join build_file..tbcoService S4 on S4.ServiceID = B.serviceid4 left outer join build_file..tbcoService S5 on S5.ServiceID = B.serviceid5 left outer join patient_data..tboutpatienthistory H on B.idnum = H.Idnum where B.Hospnum = @hospnum and b.idnum = @idnum go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go USE [Patient_DATA] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'OPD_UpdateOPDHistory') EXEC ('CREATE PROC dbo.OPD_UpdateOPDHistory AS SELECT 1') GO ALTER PROCEDURE [OPD_UpdateOPDHistory] @HospNum As Varchar(10), @IDNum As Varchar(10), @OPDStatus As Varchar(1), @Service1 As Varchar(4), @Service2 As Varchar(4), @Service3 As Varchar(4), @Service4 As Varchar(4), @Service5 As Varchar(4), @Doctor1 As Varchar(4), @Doctor2 As Varchar(4), @Doctor3 As Varchar(4), @Doctor4 As Varchar(4), @Doctor5 As Varchar(4), @Findings As Text, @Medications As Text, @Chief As Text, @AdmDate As Datetime, @DcrDate As Datetime, @ERClassification As Varchar, @Reason As Varchar(500), @ReferredFrom As Varchar(500), @UserID As Varchar(10)=NULL AS DECLARE @BillingDate As Datetime, @BillingClerk As Varchar(10) Set @BillingDate = Null; Set @BillingClerk = Null; Begin Select @BillingDate = (Case Isnull(BillingDate,'') When '' then (Case When Isnull(@DcrDate,'') ='' then NULL When Convert(Varchar(10),@DcrDate,101) = Convert(Varchar(10),Getdate(),101) then GETDATE() When @DcrDate < Getdate() then GetDate() --Else BillingDate End) Else Billingdate End), @BillingClerk = (Case Isnull(BillingClerk,'') When '' then (Case When Isnull(@DcrDate,'') ='' then NULL When Convert(Varchar(10),@DcrDate,101) = Convert(Varchar(10),Getdate(),101) then @UserID When @DcrDate < Getdate() then @UserID --Else BillingDate End) Else BillingClerk End) From PATIENT_DATA..tbOutPatient Where HospNum=@HospNum and IDNum=@IDNum; Update PATIENT_DATA..tbOutpatient Set Admdate=@AdmDate, DcrDate=@DcrDate, ServiceID1=@Service1, ServiceID2=@Service2, ServiceID3=@Service3, ServiceID4=@Service4, ServiceID5=@Service5, DoctorID1=@Doctor1, DoctorID2=@Doctor2, DoctorID3=@Doctor3, DoctorID4=@Doctor4, DoctorID5=@Doctor5, OPDStatus=@OPDStatus, OPClassification=@ERClassification, ReasonOfReferral=@Reason, ReferredFrom=@ReferredFrom, BillingDate = @Billingdate, BillingClerk = @BillingClerk Where HospNum=@HospNum and IDNum=@IDNum; Update PATIENT_DATA..tbOutPatientHistory Set Findings=@Findings, Medications=@Medications, ChiefComplaints=@Chief Where IDNum=@IDNum; End go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go USE [Patient_DATA] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'OPD_PerDepartmentLogbook') EXEC ('CREATE PROC dbo.OPD_PerDepartmentLogbook AS SELECT 1') GO ALTER Procedure [OPD_PerDepartmentLogbook] @StartDate varchar(10), @EndDate varchar(10), @RevenueID as varchar(3) as if @Revenueid = '' begin select max(Z.Hospnum)HospNum, max(Z.Idnum)IdNum, max(Z.PxName)PxName, Z.RevenueID, count(Z.Revenueid) Ctr, 'Cash' PType, R.ItemName, Z.AdmDate from ( Select A.Hospnum, A.Idnum, isnull(M.LastName, '') + ', ' + isnull(M.FirstName,'') as PxName, C.Revenueid, case when C.Revenueid in ('PH','CS') then Inv.ItemName else L.Description end as Description, A.AdmDate from Patient_data..tbOutPatient A left outer join Patient_data..tbMaster M on M.Hospnum = A.Hospnum left outer join Billing..tbCashAssessment C on C.Hospnum = A.Hospnum left outer Join Billing..tbBillExamListing L on (L.itemid = C.Itemid and C.Revenueid = L.Revenueid) left outer join Inventory..tbInvMaster Inv on C.Itemid = Inv.Itemid where A.AdmDate between @StartDate and @EndDate + ' 23:59:59.99' and C.TransDate between @StartDate and @EndDate + ' 23:59:59.99' -- And c.idnum is not null )Z left outer join Build_file..tbCoRevenueCode R on Z.Revenueid = R.RevenueID where z.revenueid not in ('MD') group by Z.Idnum, Z.Hospnum , Z.Pxname, Z.Revenueid, R.ItemName, Z.AdmDate --order by z.pxname Union All select max(Z.Hospnum)HospNum, max(Z.Idnum)IdNum, max(Z.PxName)PxName, Z.RevenueID, count(Z.Revenueid) Ctr, 'Post Charges' PType, R.ItemName, Z.AdmDate from ( Select A.Hospnum, A.Idnum, isnull(M.LastName, '') + ', ' + isnull(M.FirstName,'') as PxName, C.Revenueid, case when C.Revenueid in ('PH','CS') then Inv.ItemName else L.Description end as Description, A.AdmDate from Patient_data..tbOutPatient A left outer join Patient_data..tbMaster M on M.Hospnum = A.Hospnum left outer join Billing..tbBillOpdailyout C on C.Hospnum = A.Hospnum and C.Idnum = A.IDnum left outer Join Billing..tbBillExamListing L on L.itemid = C.Itemid and C.Revenueid = L.Revenueid left outer join Inventory..tbInvMaster Inv on C.Itemid = Inv.Itemid where A.AdmDate between @StartDate and @EndDate + ' 23:59:59.99' and C.TransDate between @StartDate and @EndDate + ' 23:59:59.99' And c.idnum <> 'CASH' )Z left outer join Build_file..tbCoRevenueCode R on Z.Revenueid = R.RevenueID where z.revenueid not in ('MD', 'ER') group by Z.Idnum, Z.Hospnum , Z.Pxname, Z.Revenueid, R.ItemName, Z.AdmDate order by z.pxname, z.ptype end else begin select max(Z.Hospnum)HospNum, max(Z.Idnum)IdNum, max(Z.PxName)PxName, Z.RevenueID, count(Z.Revenueid) Ctr, 'Cash' PType, R.ItemName, Z.AdmDate from ( Select A.Hospnum, A.Idnum, isnull(M.LastName, '') + ', ' + isnull(M.FirstName,'') as PxName, C.Revenueid, case when C.Revenueid in ('PH','CS') then Inv.ItemName else L.Description end as Description, A.AdmDate from Patient_data..tbOutPatient A left outer join Patient_data..tbMaster M on M.Hospnum = A.Hospnum left outer join Billing..tbCashAssessment C on C.Hospnum = A.Hospnum left outer Join Billing..tbBillExamListing L on (L.itemid = C.Itemid and C.Revenueid = L.Revenueid) left outer join Inventory..tbInvMaster Inv on C.Itemid = Inv.Itemid where A.AdmDate between @StartDate and @EndDate + ' 23:59:59.99' and C.TransDate between @StartDate and @EndDate + ' 23:59:59.99' And c.Revenueid = @RevenueID )Z left outer join Build_file..tbCoRevenueCode R on Z.Revenueid = R.RevenueID where z.revenueid not in ('MD') and z.revenueid = @Revenueid group by Z.Idnum, Z.Hospnum , Z.Pxname, Z.Revenueid, R.ItemName, Z.AdmDate --order by z.pxname Union All select max(Z.Hospnum)HospNum, max(Z.Idnum)IdNum, max(Z.PxName)PxName, Z.RevenueID, count(Z.Revenueid) Ctr, 'Post Charges' PType, R.ItemName, z.AdmDate from ( Select A.Hospnum, A.Idnum, isnull(M.LastName, '') + ', ' + isnull(M.FirstName,'') as PxName, C.Revenueid, case when C.Revenueid in ('PH','CS') then Inv.ItemName else L.Description end as Description, A.AdmDate from Patient_data..tbOutPatient A left outer join Patient_data..tbMaster M on M.Hospnum = A.Hospnum left outer join Billing..tbBillOpdailyout C on C.Hospnum = A.Hospnum and C.Idnum = A.IDnum left outer Join Billing..tbBillExamListing L on (L.itemid = C.Itemid and C.Revenueid = L.Revenueid) left outer join Inventory..tbInvMaster Inv on C.Itemid = Inv.Itemid where A.AdmDate between @StartDate and @EndDate + ' 23:59:59.99' and C.TransDate between @StartDate and @EndDate + ' 23:59:59.99' And c.idnum <> 'CASH' and c.revenueid = @revenueid )Z left outer join Build_file..tbCoRevenueCode R on Z.Revenueid = R.RevenueID where z.revenueid not in ('MD', 'ER') and z.revenueid = @revenueid group by Z.Idnum, Z.Hospnum , Z.Pxname, Z.Revenueid, R.ItemName, Z.AdmDate order by z.pxname, z.ptype end go use billing go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_PARS_RepSOACompleteSummarized') EXEC ('CREATE PROC dbo.sp_PARS_RepSOACompleteSummarized AS SELECT 1') GO ALTER PROCEDURE [dbo].[sp_PARS_RepSOACompleteSummarized] @IDNum as varchar(10), @AccountNum as varchar(12) AS IF @AccountNum = '' BEGIN -----------------------------ALL------------------------------ ----------------------OUT PATIENT----------------------------- IF isNumeric(@IDNum) = 0 BEGIN SELECT Max(RevenueID) AS RevenueID, Max(Type) AS Type, Max(DrCr) AS DrCr, Description, Sum(Charges) AS Charges, Sum(Credit) AS Credit, Max(PaymentType) AS PaymentType, Sum(Discount) AS Discount FROM (Select Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from OPBillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum Group by L.Department UNION ALL Select Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from OPBillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select max( RevenueID ) as RevenueID , Max( Type ) as Type, Max( DrCr ) as DrCr, Max( Description ) as Description , Sum( Cast(Charges as money)) as Charges , Sum( Cast(Credit as money)) as Credit , Max( PaymentType ) as PaymentType , Sum( Cast(Discount as money)) as Discount From ( Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, -- L.Description as Description , testing lang case when L.Revenueid = 'MD' then L.Description end as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from OPBillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') UNION ALL Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, L.Description as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from Billing..vwHistoryOut L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') ) A Group by ItemID UNION ALL Select Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( SP.Specification, L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from Billing..vwHistoryOut L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from vwHistoryOutDrugs L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum Group by L.Department) Detail Group By Description Order by Description END; ELSE ----------------------IN PATIENT----------------------------- BEGIN SELECT Max(RevenueID) AS RevenueID, Max(Type) AS Type, Max(DrCr) AS DrCr, Description, Sum(Charges) AS Charges, Sum(Credit) AS Credit, Max(PaymentType) AS PaymentType, Sum(Discount) AS Discount FROM (Select --Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from BillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum Group by L.Department UNION ALL Select --Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from BillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select max( RevenueID ) as RevenueID , Max( Type ) as Type, Max( DrCr ) as DrCr, Max( Description ) as Description , Sum( Cast(Charges as MOney)) as Charges , Sum( Cast(Credit as money)) as Credit , Max( PaymentType ) as PaymentType , Sum( Cast( Discount as money)) as Discount From ( Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, -- L.Description as Description , case when L.Revenueid = 'MD' then L.Description end as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from BillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') UNION ALL Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, L.Description as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from Billing..vwHistoryIn L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') ) A Group by ItemID UNION ALL Select --Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull(LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from Billing..vwHistoryIn L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select --Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from vwHistoryInDrugs L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum Group by L.Department) Details Group By Description Order By Description END; END Else BEGIN -------------PER ACCOUNT NUMBER FOR MULTIPLE------------------ ----------------------OUT PATIENT----------------------------- -- select B.AccountNum from billing..tbparsmultiplecompany A -- left join Build_File..tbCoCompany B on B.AccountNum = A.AccountNum -- where A.IDNum = '15174B' and B.Company like '%'+@AccountNum+'%' Select @AccountNum = A.AccountNum from Build_File..tbCoCompany A Left Join Billing..tbParsMultipleCompany B on B.AccountNum = A.AccountNum Where A.Company Like '%'+@AccountNum+'%' and B.IDNum = @IDNum -- ~ Added By JonRoss Viewing Per Company IF isNumeric(@IDNum) = 0 BEGIN SELECT Max(RevenueID) AS RevenueID, Max(Type) AS Type, Max(DrCr) AS DrCr, Description, Sum(Charges) AS Charges, Sum(Credit) AS Credit, Max(PaymentType) AS PaymentType, Sum(Discount) AS Discount FROM (Select Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from OPBillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum AND AccountNum = @AccountNum Group by L.Department UNION ALL Select Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from OPBillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') and L.AccountNum = @AccountNum Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select max( RevenueID ) as RevenueID , Max( Type ) as Type, Max( DrCr ) as DrCr, Max( Description ) as Description , Sum( Cast(Charges as money)) as Charges , Sum( Cast(Credit as money)) as Credit , Max( PaymentType ) as PaymentType , Sum( Cast(Discount as money)) as Discount From ( Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, -- L.Description as Description , testing lang case when L.Revenueid = 'MD' then L.Description end as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from OPBillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') and AccountNum = @AccountNum UNION ALL Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, L.Description as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from Billing..vwHistoryOut L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') and AccountNum = @AccountNum ) A Group by ItemID UNION ALL Select Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( SP.Specification, L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from Billing..vwHistoryOut L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') and AccountNum = @AccountNum Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from vwHistoryOutDrugs L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum and AccountNum = @AccountNum Group by L.Department) Detail Group By Description Order by Description END; ELSE ----------------------IN PATIENT----------------------------- BEGIN SELECT Max(RevenueID) AS RevenueID, Max(Type) AS Type, Max(DrCr) AS DrCr, Description, Sum(Charges) AS Charges, Sum(Credit) AS Credit, Max(PaymentType) AS PaymentType, Sum(Discount) AS Discount FROM (Select --Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from BillingDrugsSOA L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum and AccountNum = @AccountNum Group by L.Department UNION ALL Select --Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull( LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from BillingOthersSOA L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') and AccountNum = @AccountNum Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select max( RevenueID ) as RevenueID , Max( Type ) as Type, Max( DrCr ) as DrCr, Max( Description ) as Description , Sum( Cast(Charges as MOney)) as Charges , Sum( Cast(Credit as money)) as Credit , Max( PaymentType ) as PaymentType , Sum( Cast( Discount as money)) as Discount From ( Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, -- L.Description as Description , case when L.Revenueid = 'MD' then L.Description end as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from BillingOthersSOA L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') and AccountNum = @AccountNum UNION ALL Select isnull(RevenueID,'') as RevenueID, L.ItemID , isnull(LGRP,'') as Type, isnull(DrCr,'D') as DrCr, L.Description as Description , Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Charges,0) End as Money) as Charges, Cast( Case When L.Lgrp = 'D' Then 0 Else isnull(Credit,0) End as Money) as Credit, D.Description as PaymentType , Cast( Case When L.Lgrp = 'D' Then isnull(Credit,0) Else 0 End as Money) as Discount from Billing..vwHistoryIn L Left Outer Join Build_File..tbCoDoctorsCode D on D.DoctorCode = L.RefNum Where IDNum = @IDNum and DrCr = 'P' and RevenueID not in ('PH','PC','CS','CC') and AccountNum = @AccountNum ) A Group by ItemID UNION ALL Select --Distinct isnull(max(L.RevenueID),'') as RevenueID, isnull(max(R.LGRP),'') as Type, max(isnull(R.DrCr,'D')) as DrCr, Case when max(L.RevenueID) = 'GS' or max(L.RevenueID) = 'SS' then Case IsNull(L.RevenueID,'') When 'SS' Then ' ' + max(A.ItemName) When 'GS' Then ' ' + max(A.ItemName) Else max(A.ItemName) End else max( IsNull(LEFT(SP.Specification, 40), L.Department)) end as Description, Sum(Charges) as Charges, Sum(Credit) as Credit, '' as PaymentType , 0 as Discount from Billing..vwHistoryIn L LEFT OUTER JOIN Build_File..tbCoRevenueCode R on L.RevenueID = R.RevenueID 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.RevenueID not in ('PH','PC','CS','CC', 'TB', 'BB') and AccountNum = @AccountNum Group by L.RevenueID, A.RevenueID, SP.Specification UNION ALL Select --Distinct isnull(max(R.RevenueID),'') as RevenueID, isnull(max(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 from vwHistoryInDrugs L LEFT OUTER JOIN BUILD_FILE..tbCoRevenueCode R on R.LocationID = L.LocationID Where IDNum = @IDNum and AccountNum = @AccountNum Group by L.Department) Details Group By Description Order By Description END; END set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_BILLING_LoadPatientForConsolidation] AS SELECT max(D.HospNum) as [Hosp. No.], max(D.OPDNum) as [OPD. No.], max(D.AdmNum) as [ADM. No.], max(isnull(C.LastName,'') + ', ' + isnull(C.FirstName,'') + ' ' + isnull(C.MiddleName,'')) as [Patient Name] , CONVERT( VARCHAR(10), max(D.AdmDate), 101 ) AS [Adm. Date], CONVERT( VARCHAR(10), max(D.AdmDate), 108 ) AS [Adm. Time], CONVERT( VARCHAR(10), max(D.DcrDate), 101 ) AS [Dcr. Date], CONVERT( VARCHAR(10), max(D.DcrDate), 108 ) AS [Dcr. Time] FROM (SELECT A.IDNum as OPDNum, A.AdmDate, A.DcrDate, B.IDNum as AdmNum, A.HospNum, CASE WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'D' THEN Cast(isnull(L.Amount, 0) AS Money) WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'C' THEN Cast(Abs(isnull(L.Amount, 0)) AS money) WHEN R.LGRP = 'F' AND R.DrCr = 'P' THEN Cast(isnull(L.Amount, 0) AS Money) WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'C' THEN Cast(isnull(L.Amount, 0) AS Money) * - 1 WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'D' THEN Cast(Abs(isnull(L.Amount, 0)) AS money) * - 1 WHEN R.LGRP <> 'F' AND R.DrCr = 'P' THEN Cast(isnull(L.Amount, 0) AS Money) * - 1 ELSE 0 END AS Amount FROM tbBillOpDailyOut L INNER JOIN PATIENT_DATA..tbOutPatient A ON A.IDNum = L.IDNum INNER JOIN PATIENT_DATA..tbPatient B ON A.HOSPNUM = B.HOSPNUM LEFT OUTER JOIN Build_File..tbCoRevenueCode R ON R.RevenueID = L.RevenueID WHERE B.DcrDate IS NULL AND DAY( B.AdmDate ) - 2 <= DAY( A.AdmDate ) and Year( B.AdmDate ) = Year( A.AdmDate ) AND ISNULL( B.OPDIDNum , '' ) = '' AND LEFT( A.IDNum, 1 ) <> 'P' UNION ALL SELECT A.IDNum as OPDNum, A.AdmDate, A.DcrDate, B.IDNum as AdmNum, A.HospNum, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(isnull(L.Amount, 0) AS Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Abs(isnull(L.Amount, 0)) AS money) WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(isnull(L.Amount, 0) AS Money) * -1 WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Abs(isnull(L.Amount, 0)) AS money) * -1 ELSE 0 END AS Amount FROM Inventory..tbInvStockCard L INNER JOIN PATIENT_DATA..tbOutPatient A ON A.IDNum = L.IDNum INNER JOIN PATIENT_DATA..tbPatient B ON A.HOSPNUM = B.HOSPNUM WHERE B.DcrDate IS NULL AND DAY( B.AdmDate ) - 2 <= DAY( A.AdmDate ) and Year( B.AdmDate ) = Year( A.AdmDate ) AND ISNULL( B.OPDIDNum , '' ) = '' AND LEFT( A.IDNum, 1 ) <> 'P' ) D INNER JOIN PATIENT_DATA..tbMaster C ON D.HOSPNUM = C.HOSPNUM GROUP BY D.OPDNum HAVING SUM(D.Amount) > 0 ORDER BY [Patient Name] GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go use billing go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Cashier_LoadDiscount') EXEC ('CREATE PROC dbo.Cashier_LoadDiscount AS SELECT 1') GO alter Procedure [dbo].[Cashier_LoadDiscount] as select * from Build_File..tbCoRevenuecode where lgrp = 'D' and cashieractive = 'Y' and RevenueID not in ('VR','DL') order by itemname GO USE [Station] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Nurse_GetPatient_LabResult_NormalValues') EXEC ('CREATE PROC dbo.sp_Nurse_GetPatient_LabResult_NormalValues AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[sp_Nurse_GetPatient_LabResult_NormalValues] Script Date: 04/18/2012 17:42:26 ******/ SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[sp_Nurse_GetPatient_LabResult_NormalValues] @IDNum as Varchar(10) AS DECLARE @OpdIDNum as Varchar(10); Select @OpdIDNum = Isnull(OPDIDNum,'') from Patient_data..tbPatient Where IDNum = @IDnum; select case when a.labexamID IN (Select LabExamID from Build_File..tbCoLabExam where Form='P') then c.ItemID else a.labexamID end as labexamid, a.labsectionid , case a.labexamid when '1' then d.labsection + ' (CBC)' else d.labsection end as section , case when a.labexamid = '1' then ltrim(convert(varchar(30),e.shortname) + ' ' + convert(varchar(35),e.resultname)) when a.labexamID IN (Select LabExamID from Build_File..tbCoLabExam where Form='P' and labexamID <> '1') then g.labexam else b.labexam end as Exam , case a.formtype when '1' then convert(varchar(10),cast(c.minvalue as decimal(10,2))) + ' - ' + convert(varchar(10),cast(c.maxvalue as decimal(10,2))) + ' ' + c.unit when '7' then isnull(c.StrNValues,'') --+ ' ' + isnull(c.Unit,'') when '0' then isnull(c.StrNValues,'') --+ ' ' + isnull(c.Unit,'') when 'U' then isnull(c.StrNValues,'') --+ ' ' + isnull(c.Unit,'') when 'P' then isnull(c.StrNValues,'') --+ ' ' + isnull(c.Unit,'') else 'No Normal Value' END as NormalValue, case a.formtype when '1' then convert(varchar(10),cast(c.result as decimal(10,2))) when '7' then isnull(c.Strresult,'') when '0' then isnull(c.Strresult,'') when 'U' then isnull(c.Strresult,c.result) when 'P' then isnull(c.Strresult,c.result) else 'No Result' END as Result , --convert(varchar(10),Isnull(a.Verifydate,a.ResultDate),101) + substring(convert(varchar(19),Isnull(a.Verifydate,a.ResultDate),100),12,8) as ResultDate, Isnull(a.Verifydate,a.ResultDate) as ResultDate, a.formtype as FormType from laboratory..tblablogbook a left outer join build_file..tbcolabsection d on a.labsectionid = d.labsectionid left outer join build_file..tbcolabexam b on a.labexamid = b.labexamid left outer join laboratory..tblabresultnvalues c on a.requestnum = c.requestnum --and a.labexamid = c.itemid left outer join build_file..tbcolabvalues e on e.code = c.itemid left outer join build_file..tbcolabexam g on c.Itemid = g.labexamid where (a.IDnum=@IDNum or a.IDNum = @OPDIDNum) and (a.labsectionid='H' or a.labexamID IN (Select LabExamID from Build_File..tbCoLabExam where Form='P')) and (a.formtype IN ('1','0','7','U','P')) and(isnumeric(c.Strresult) = 1 ) order by section,Exam,Isnull(a.Verifydate,a.ResultDate); GO USE Build_file GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Bui_Update_Doctor_Details') EXEC ('CREATE PROC dbo.sp_Bui_Update_Doctor_Details AS SELECT 1') GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[sp_Bui_Update_Doctor_Details] --UPDATE TBCODOCTOR-- @DoctorId as int, @CommonCode as varchar(4), @LastName as varchar(40), @FirstName as varchar(30), @MiddleName as varchar(30), @Sex as varchar(1), @Address as varchar(200), @Telephone as varchar(20), @PMCC as varchar(20), @TaxNumber as varchar(20), @status as varchar(1), @title as varchar(20), @Visiting varchar(1), @isForOpdCheckup as varchar(1), @HouseCase as varchar(1), @License as varchar(12), @BankAccount as varchar(20), @SpecializationID as varchar(2), @SpecializationID2 as varchar(2), @SpecializationID3 as varchar(2), @DeptCode as varchar(2), @Department as varchar(50), @DrClinic as varchar(70) = null, @CategoryID as varchar(1) = null, @ClinicInfo as varchar(250) = null, @BirthDay as varchar(11) = null, @EmailAdd as varchar(40) = null, @PhilHealthNum as varchar(20) = null, @PMANum as varchar(35) = null, @TinNum as varchar(30) = null, @CellNum as varchar(15) = null, @SchedDay1 as varchar(20) = null, @SchedDay2 as varchar(20) = null, @SchedDay3 as varchar(20) = null, @SchedDay4 as varchar(20) = null, @SchedDay5 as varchar(20) = null, @SchedDay6 as varchar(20) = null, @SchedDay7 as varchar(20) = null, @WithHoldingTax as float = null, @CardCode as varchar(15) = null, @DoctorInfo as varchar(50) = null, @RateA as float = null, @RateB as float = null, @RateC as float = null, @RateD as float = null, @RateE as float = null, @RateF as float = null, @RateG as float = null, @RateH as float = null, @RateI as float = null, @RateJ as float = null, @CapitalStock as money = null, @Vat as float = null, @ShareofStock as money = null, @GrossRental as float = null, @MonthlyDues as float = null, @CCTV as float = null, @TelBill as float = null, @LightBill as float = null, @WaterBill as float = null, @Cable as float = null AS UPDATE tbCoDoctor SET CommonCode=@CommonCode, LastName=@LastName, FirstName=@FirstName, MiddleName=@MiddleName, Sex=@Sex, DoctorAddress=@Address, TelNo=@Telephone, PMCC=@PMCC, TaxNumber=@TaxNumber, status=@status, title=@title, Visiting=@visiting, isForOpdCheckup=@isForOpdCheckup, HouseCase=@HouseCase, License=@License, BankAccount=@BankAccount, SpecializationID=@SpecializationID, SpecializationID2=@SpecializationID2, SpecializationID3=@SpecializationID3, DeptCode=@DeptCode, Department=@Department, DrClinic=@DrClinic, Birthday=@Birthday, EmailAdd=@EmailAdd, PhilHealthNum=@PhilHealthNum, PMANum=@PMANuM, TinNum=@TinNum, CellNum=@CellNum, CategoryID=@CategoryID, ClinicInfo=@ClinicInfo, SchedDay1=@SchedDay1, SchedDay2=@SchedDay2, SchedDay3=@SchedDay3, SchedDay4=@SchedDay4, SchedDay5=@SchedDay5, SchedDay6=@SchedDay6, SchedDay7=@SchedDay7, TaxWithHeld=@WithHoldingTax, CardCode=@CardCode, DoctorInfo=@DoctorInfo, WithHoldingTax=@WithHoldingTax, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateI=@RateI, RateJ=@RateJ, CapitalStock=@CapitalStock, Vat=@Vat, SharesofStock=@ShareofStock, GrossRental=@GrossRental, MonthlyDues=@MonthlyDues, CCTV=@CCTV, TelBill=@TelBill, LightBill=@LightBill, WaterBill=@WaterBill, Cable=@Cable WHERE DoctorID=@DoctorID GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO use Patient_Data go alter table tbmaster alter column CardNumber varchar(25) GO USE [Patient_Data] GO CREATE NONCLUSTERED INDEX [byCardNumber] ON [dbo].[tbmaster] ( [CardNumber] ASC )WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO USE [Billing] GO /****** Object: View [dbo].[vwHistoryOutDrugs] Script Date: 04/30/2012 16:00:21 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER VIEW [dbo].[vwHistoryOutDrugs] AS SELECT TransDate, M.HospNum, L.IDNum, isnull(L.RefNum, '') AS RefNum, L.Quantity, isnull(TbInvMaster.ItemName, '') + ' ' + isnull(TbInvmaster.ItemDesc, '') AS Description, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) ELSE 0 END AS Charges, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) ELSE 0 END AS Credit, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) * - 1 WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) * - 1 ELSE 0 END AS Amount, L.ItemID AS ItemID, L.RevenueID AS RevenueID, P.BillingDate AS BillingDate, L.ItemType AS DrCr, L.locationID, L.UserID, '' as RoomID, Case When L.RevenueID in ('PC', 'CC') then R2.ItemName Else R.ItemName End as Department, L.CutOffDate , isnull(L.Amount,0) as ActualAmount, isnull(tbInvMaster.isSeniorDiscounted, 0) as Senior , isnull(P.AccountNum,'') as AccountNum , ISNULL( P.InvoiceNumber, '' ) as Invoicenumber , P.AdmDate , P.DcrDate, isnull(DosageID,'') as DosageID, isnull(tbInvMaster.MedicareType,'N') as MedicareType, isnull(tbInvMaster.MedicareCategory,'A') as MedicareCategory, R.LGRP, Case When L.TransDate < P.BillingDate then P.BillingDate Else L.TransDate End as PARSDate FROM HISTORY..tbPassInvStock L INNER JOIN Patient_Data..tbOutPatient P ON L.IDnum = P.IDNum LEFT OUTER JOIN Patient_Data..tbMaster M ON M.HospNum = P.HospNum LEFT OUTER JOIN Inventory..tbInvMaster tbInvMaster ON tbInvMaster.ItemID = L.ItemID LEFT OUTER JOIN Build_File..tbCoRevenueCode R on R.LocationID = L.LocationID LEFT OUTER JOIN Build_File..tbCoRevenueCode R2 on R2.RevenueID = L.RevenueID GO ------------------------------------------ USE [Billing] GO /****** Object: View [dbo].[vwHistoryOut] Script Date: 04/30/2012 16:00:54 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER VIEW [dbo].[vwHistoryOut] AS SELECT L.TransDate, M.HospNum, L.IDNum, isnull(L.RefNum, '') AS RefNum, L.Quantity, CASE WHEN (L.RevenueID = 'PT' or L.RevenueID = 'US' or L.RevenueID = 'AU' or L.RevenueID = 'NU' or L.RevenueID = 'HS' or L.RevenueID = 'LB' or L.RevenueID = 'CT' or L.RevenueID = 'XR' or L.RevenueID = 'PA' or L.RevenueID = 'CT' or L.RevenueID = 'EL' or L.RevenueID = 'SS' or L.RevenueID = 'BA' or L.RevenueID = 'BB' or L.RevenueID = 'GS' or L.RevenueID = 'BD' or L.RevenueID = 'HI' OR L.RevenueID = 'OS') THEN D .Description WHEN R.DrCr = 'P' THEN 'Dr. ' + isnull(Doctor.LastName, '') + ', ' + isnull(Doctor.FirstName, '') + ' ' + isnull(Doctor.MiddleName, '') WHEN R.Rwith = 'Y' then D.Description ELSE R.ItemName END AS Description, CASE WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'D' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'C' THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) WHEN R.LGRP = 'F' and R.DrCr = 'P' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) ELSE 0 END AS Charges, CASE WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'C' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'D' THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) WHEN R.LGRP <> 'F' and R.DrCr = 'P' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) ELSE 0 END AS Credit, CASE WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'D' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'C' THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) WHEN R.LGRP = 'F' and R.DrCr = 'P' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) WHEN isnull(L.Amount, 0) > 0 AND R.DrCr = 'C' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) AS Money) * -1 WHEN isnull(L.Amount, 0) < 0 AND R.DrCr = 'D' THEN Cast(Abs(Cast(isnull(L.Amount,0) as Decimal(12,2))) AS money) * -1 WHEN R.LGRP <> 'F' and R.DrCr = 'P' THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) * -1 ELSE 0 END AS Amount, L.ItemID AS ItemID, Case When L.RevenueID = 'LB' then isnull(S.RevenueID,'LB') Else L.RevenueID End AS RevenueID, P.BillingDate AS BillingDate, R.DrCr AS DrCr, R.LGRP, L.UserID, '' as RoomID, CASE WHEN L.RevenueID = 'MJ' THEN 'TOTAL DEDUCTION' ELSE R.ItemName END as Department, L.CutOffDate , isnull(L.Amount,0) as ActualAmount, L.RequestDocID, D.Senior, D.SeniorDiscount, D.RateA , (Case When isnull(L.AccountNum,'') = '' then P.AccountNum else L.AccountNum end) as AccountNum , P.InvoiceNumber as InvoiceNumber , IsNull( L.RequestNum, '' ) as RequestNum , P.AdmDate , P.DcrDate, isnull(L.RevenueID,'') as LocationID, isnull(Doctor.RentalWTax,0) as RentalWTax, isnull((CASE WHEN (L.RevenueID = 'PT' OR L.RevenueID = 'US' OR L.RevenueID = 'AU' OR L.RevenueID = 'NU' OR L.RevenueID = 'HS' OR L.RevenueID = 'LB' OR L.RevenueID = 'CT' OR L.RevenueID = 'XR' OR L.RevenueID = 'PA' OR L.RevenueID = 'EL' OR L.RevenueID = 'SS' OR L.RevenueID = 'BA' OR L.RevenueID = 'GS' OR L.RevenueID = 'HS') THEN D.MedicareType WHEN R.Rwith = 'Y' THEN isnull(D.MedicareType,'N') ELSE isnull(R.MedicareType,'N') END), isnull(R.MedicareType,'N')) AS MedicareType, isnull((CASE WHEN (L.RevenueID = 'PT' OR L.RevenueID = 'US' OR L.RevenueID = 'AU' OR L.RevenueID = 'NU' OR L.RevenueID = 'HS' OR L.RevenueID = 'LB' OR L.RevenueID = 'CT' OR L.RevenueID = 'XR' OR L.RevenueID = 'PA' OR L.RevenueID = 'EL' OR L.RevenueID = 'SS' OR L.RevenueID = 'BA' OR L.RevenueID = 'GS' OR L.RevenueID = 'HS') THEN D.MedicareCategory WHEN R.Rwith = 'Y' THEN isnull(D.MedicareCategory,'A') ELSE isnull(R.MedicareCategory,'A') END), isnull(R.MedicareCategory,'A') ) AS MedicareCategory, Case When L.TransDate < P.BillingDate then P.BillingDate Else L.TransDate End as PARSDate FROM History..tbPassDailyOut L INNER JOIN Patient_Data..tbOutPatient P ON L.IDnum = P.IDNum LEFT OUTER JOIN Patient_Data..tbMaster M ON M.HospNum = P.HospNum LEFT OUTER JOIN Billing..tbBillExamListing D ON L.ItemID = D .ItemID AND L.RevenueID = D .RevenueID LEFT OUTER JOIN Build_File..tbCoDoctor Doctor ON Doctor.DoctorID = L.ItemID LEFT OUTER JOIN Build_File..tbCoLabExam Lab on Lab.LabExamID = L.ItemID and L.RevenueID = 'LB' LEFT OUTER JOIN Build_File..tbCoLabSection S on Lab.LabSectionID = S.LabSectionID LEFT OUTER JOIN Build_File..tbCoRevenueCode R ON R.RevenueID = (Case L.RevenueID When 'LB' then isnull(S.RevenueID,'LB') Else L.RevenueID End) GO ---------------------------------------- USE [Billing] GO /****** Object: View [dbo].[OPBillingDrugsSOA] Script Date: 04/30/2012 16:01:22 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER VIEW [dbo].[OPBillingDrugsSOA] AS SELECT TransDate, M.HospNum, L.IDNum, isnull(L.RefNum, '') AS RefNum, case when isnull(L.Quantity, 0) = 0 then case when isnull(L.Amount,0) > 0 then 1 when isnull(L.Amount,0) = 0 then 0 when isnull(L.Amount,0) < 0 then -1 end Else case when isnull(L.Amount,0) < 0 then ABS(IsNull(L.Quantity,1)) * -1 when isnull(L.Amount,0) = 0 then 0 else ABS(IsNull(L.Quantity,1)) end end as Quantity, Case When isnumeric(L.ItemID) = 1 Then isnull(TbInvMaster.ItemName, '') + ' ' + isnull(TbInvmaster.ItemDesc, '') Else isnull(I.PackageName,'') + ' (Set/Package)' End AS Description, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Abs(Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money)) ELSE 0 END AS Charges, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Abs(Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money)) ELSE 0 END AS Credit, CASE WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Abs(Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money)) WHEN isnull(L.Amount, 0) > 0 AND (L.RevenueID = 'PC' OR L.RevenueID = 'CC') THEN Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money) * -1 WHEN isnull(L.Amount, 0) < 0 AND (L.RevenueID = 'PH' OR L.RevenueID = 'CS') THEN Abs(Cast(Cast(isnull(L.Amount,0) as Decimal(12,2)) as Money)) * -1 ELSE 0 END AS Amount, ISNULL( L.ItemID, '' ) AS ItemID, L.RevenueID AS RevenueID, P.BillingDate AS BillingDate, L.ItemType AS DrCr, Case When L.locationID = '186' Then '20' Else L.LocationID End as LocationID , isnull(tbInvMaster.MedicareType,'N') as MedicareType, isnull(tbInvMaster.MedicareCategory,'A') as MedicareCategory, isnull(R.GroupRevenueID,'') as GroupRevenueID, L.UserID, 'OPD' as RoomID, R.ItemName as Department, L.CutOffDate, isnull(L.Amount,0) as ActualAmount , isnull(tbInvMaster.isSeniorDiscounted, 0) as Senior , ISNULL( L.SummaryCode, '' ) as SummaryCode , P.AccountNum as AccountNum , IsNull( P.InvoiceNumber, '' ) as InvoiceNumber , P.AdmDate , P.DcrDate, isnull(DosageID,'') as DosageID, tbInvMaster.NM_MedicareType, tbInvMaster.ItemClassificationID, ISNULL(tbInvMaster.GroupCode, '') AS GroupType, isnull(TargetLocationID,'') as TargetLocationID, isnull(L.QuantityRec,'') QuantityRec, isnull(L.RequestByID,'') as RequestByID, isnull(X.isSenior,0) as SeniorLocation, R.LGRP FROM INVENTORY..tbInvStockCard L INNER JOIN Patient_Data..tbOutPatient P ON L.IDnum = P.IDNum LEFT OUTER JOIN Patient_Data..tbMaster M ON M.HospNum = P.HospNum LEFT OUTER JOIN Inventory..tbInvMaster tbInvMaster ON tbInvMaster.ItemID = L.ItemID LEFT OUTER JOIN Build_File..tbCoRevenueCode R on R.LocationID = L.LocationID and not isnull(L.LocationID,'') = '' LEFT OUTER JOIN Build_File..tbCoRevenueCode R2 on R2.RevenueID = L.RevenueID LEFT OUTER JOIN Inventory..tbInvPackage I on I.PackageID = L.ItemID Left Outer Join Inventory..tbInvent X on L.ItemID = X.ItemID and L.LocationID = X.LocationID --Where L.PackageID is null -- as per Maya 2007.06.28 to include Package Items GO ----------------------------- USE [Medicare] GO /****** Object: StoredProcedure [dbo].[MedicRep_GetListOfDeniedClaims] Script Date: 04/30/2012 15:34:27 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.MedicRep_GetListOfDeniedClaims Script Date: 07/01/2000 1:19:55 AM ******/ ALTER PROCEDURE [dbo].[MedicRep_GetListOfDeniedClaims] As Begin Tran Select [Patient Name],[Confinement], DcrDate, MemberNumber,[AdmNum],[Hospital Claim], Payments,Balance, [RA], [Drug], [XLO], [OR],PostDate from ( Select IsNull(B.LastName,'') + ', ' + IsNull(B.FirstName,'') + ' ' + IsNull(B.MiddleName,'') [Patient Name], B.MemberNumber as MemberNumber, B.DcrDate as DcrDate, [Confinement] = Convert(varchar(10),B.AdmDate,101) + ' - ' + Convert(varchar(10),B.DcrDate,101), IsNull(B.IdNum,'') [AdmNum], [Hospital Claim] = Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = B.IdNum ), 0 ) End, [Payments] = Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Sum(Cast( IsNull(Amount,0) as Decimal( 12, 2 ) )) from Medicare..tbMedPayment Where IdNum = B.IdNum ), 0 ) End, ( Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = B.IdNum ), 0 ) End ) - ( Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( IsNull(Amount,0) + IsNull(Tax,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = B.IdNum ), 0 ) End ) [Balance], [RA] = isnull((Select sum(RoomboardAmt) from Medicare..tbMedPayment where IdNum = B.idnum),0), [Drug] = isnull((Select sum(isnull(DrugAmt,0)) from Medicare..tbMedPayment where IdNum = B.idnum),0), [XLO] = isnull((Select sum(isnull(OthersAmt,0)) from Medicare..tbMedPayment where IdNum = B.idnum),0), [OR] = isnull((Select sum(isnull(ORAmt,0)) from Medicare..tbMedPayment where IdNum = B.idnum),0), Convert(Varchar(10), B.PostDate, 101) as PostDate from Medicare..tbMedPatient B -- Left Outer Join Medicare..tbMedPayment B on B.idnum = A.idnum Where ( ( Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = B.IdNum ), 0 ) End ) - ( Case IsNull(B.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( IsNull(Amount,0) + IsNull(Tax,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = B.IdNum ), 0 ) End ) ) > 0 and B.PaymentDenied = 0 --UNDERPAID UNION ALL --UNPAID CLAIMS Select IsNull(E.LastName,'') + ', ' + IsNull(E.FirstName,'') + ' ' + IsNull(E.MiddleName,'') [Patient Name], E.MemberNumber as MemberNumber, E.DcrDate as DcrDate, [Confinement] = Convert(varchar(10),E.AdmDate,101) + ' - ' + Convert(varchar(10),E.DcrDate,101), IsNull(A.IdNum,'') [AdmNum], [Hospital Claim] = Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = A.IdNum ), 0 ) End, [Payments] = Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Sum(Cast( IsNull(Amount,0) as Decimal( 12, 2 ) )) from Medicare..tbMedPayment Where IdNum = A.IdNum ), 0 ) End, ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = A.IdNum ), 0 ) End ) - ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( IsNull(Amount,0) + IsNull(Tax,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IdNum ), 0 ) End ) [Balance], [RA] = isnull((Select sum(isnull(RoomboardAmt,0)) from Medicare..tbMedPayment where IdNum = A.idnum),0), [Drug] = isnull((Select sum(isnull(DrugAmt,0)) from Medicare..tbMedPayment where IdNum = A.idnum),0), [XLO] = isnull((Select sum(isnull(OthersAmt,0)) from Medicare..tbMedPayment where IdNum = A.idnum),0), [OR] = isnull((Select sum(isnull(ORAmt,0)) from Medicare..tbMedPayment where IdNum = A.idnum),0), Convert(Varchar(10), E.PostDate, 101) as PostDate from Medicare..tbMedActual A left outer join Medicare..tbMedPatient E on A.idnum = e.idnum Where IsNull( ( Select Cast( Sum( IsNull( MedRoomBoard, 0 ) + IsNull( MedDrug, 0 ) + IsNull( MedOthers, 0 ) + IsNull( MedOR, 0 ) ) as money ) from Medicare..tbMedActual Where IdNum = A.IdNum ),0) > 0 and IsNull( ( Select Cast( Sum( IsNull(Amount,0) + IsNull(Tax,0) ) as money ) from tbMedPayment Where IdNum = A.IdNum ), 0 ) = 0 and E.PaymentDenied = 0 --UNPAID INPATIENT )a where [Payments] > 0 and datediff(y, year(DcrDate),year(getdate())) > 1 Order by DcrDate desc If @@error<>0 Begin goto abort_save End Commit Tran Return 0 abort_save: Rollback Tran Return -10001 ---------------------- GO /****** Object: StoredProcedure [dbo].[Medic_UpdatePaymentDenied] Script Date: 04/30/2012 15:36:54 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Medic_UpdatePaymentDenied Script Date: 07/01/2000 1:19:23 AM ******/ ALTER PROCEDURE [dbo].[Medic_UpdatePaymentDenied] --'534358','0', '', 'jem' @strIdNum as varchar(10), @bitDenied as bit, @strReason as varchar(250), @strUserid as varchar(10) = '' AS declare @PRoomBoardAmt as money declare @PDrugAmt as money declare @POthersAmt as money declare @PORAmt as money declare @BRoomBoardAmt as money declare @BDrugAmt as money declare @BOthersAmt as money declare @BORAmt as money declare @PAmt as money Begin Tran /***** NOT TO DELETE THE PAYMENT BUT TO TRANSFER IT TO PARS*****/ --if exists(Select * from Medicare..tbMedPayment where IdNum = @strIdNum) -- begin --FOR DENIED UNDERPAID CLAIMS set @PRoomBoardAmt = isnull((Select sum(cast(RoomBoardAmt as money)) from Medicare..tbMedPayment where IdNum = @strIdNum),0) set @PDrugAmt = isnull((Select sum(cast(DrugAmt as money)) from Medicare..tbMedPayment where IdNum = @strIdNum),0) set @POthersAmt = isnull((Select sum(cast(OthersAmt as money)) from Medicare..tbMedPayment where IdNum = @strIdNum),0) set @PORAmt = isnull((Select sum(cast(ORAmt as money)) from Medicare..tbMedPayment where IdNum = @strIdNum),0) set @PAmt = isnull((Select sum(cast(Amount as money)) from Medicare..tbMedPayment where IdNum = @strIdNum),0) --end --else -- begin -- --FOR DENIED UNPAID CLAIMS set @BRoomBoardAmt = isnull((select sum(cast(Amount as money)) from Billing..tbBillDailyBill where IdNum = @strIdNum and ItemID ='SS1' and RevenueID = 'SS' and Amount > 0),0) set @BDrugAmt = isnull((select sum(cast(Amount as money)) from Billing..tbBillDailyBill where IdNum = @strIdNum and ItemID ='SS2' and RevenueID = 'SS' and Amount > 0),0) set @BOthersAmt = isnull((select sum(cast(Amount as money)) from Billing..tbBillDailyBill where IdNum = @strIdNum and ItemID ='SS3' and RevenueID = 'SS' and Amount > 0),0) set @BORAmt = isnull((select sum(cast(Amount as money)) from Billing..tbBillDailyBill where IdNum = @strIdNum and ItemID ='SS4' and RevenueID = 'SS' and Amount > 0),0) --end Update Medicare..tbMedPatient Set PaymentDenied = @bitDenied Where IdNum = @stridNum; If @@error <> 0 Begin goto Abort_Save; End; If @bitDenied = 1 Begin If Exists( Select * from Medicare..tbMedReasonsForPaymentDenial Where IdNum = @strIdNum ) Begin Update Medicare..tbMedReasonsForPaymentDenial Set Reason = @strReason Where IdNum = @strIdNum; End Else Begin Insert into Medicare..tbMedReasonsForPaymentDenial( IdNum, Reason ) Values( @strIdNum, @strReason ); End; If isnumeric(@strIDNum) = 1 Begin Insert into Billing..tbBillDailyBill( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS1', (@BRoomBoardAmt - @PRoomBoardAmt) * - 1, @strUserID ); Insert into Billing..tbBillDailyBill( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS2', (@BDrugAmt - @PDrugAmt) * - 1, @strUserID ); Insert into Billing..tbBillDailyBill( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS3', (@BOthersAmt - @POthersAmt) * - 1, @strUserID ); Insert into Billing..tbBillDailyBill( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS4', (@BORAmt - @PORAmt) * - 1, @strUserID ); End Else Begin Insert into Billing..tbBillOPDailyOut( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS2', (@BDrugAmt - @PDrugAmt) * - 1, @strUserID ); Insert into Billing..tbBillOPDailyOut( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS3', (@BOthersAmt - @POthersAmt ) * - 1, @strUserID ); Insert into Billing..tbBillOPDailyOut( IdNum, TransDate, RevenueID, DrCr, ItemID, Amount, UserID ) Values( @strIDNum, GetDate(), 'SS', 'C', 'SS4', (@BORAmt - @PORAmt ) * - 1, @strUserID ); End --FOR MEDICARE COMPUTATION update Medicare..tbMedActual set PatRoomBoard = (Select cast(ActualRoomboard as money)from Medicare..tbMedActual where IdNum = @strIDNum), PatDrug = (Select cast(ActualDrug as money) from Medicare..tbMedActual where IdNum = @strIDNum), PatOthers = (Select cast(ActualOthers as money) from Medicare..tbMedActual where IdNum = @strIDNum), PatOR = (Select cast(ActualOR as money) from Medicare..tbMedActual where IdNum = @strIDNum), MedRoomBoard = 0, MedDrug = 0, MedOthers =0 , MedOR = 0 where IdNum = @strIDNum --FOR TBMEDSOA Insert into tbMedSOA select E.RevenueID, Case when E.Position = '2' then cast((cast(PHICAmount as float)/ cast(@BDrugAmt as float))*(cast(@BDrugAmt as float) - cast(@PDrugAmt as float)) as float) * -1 when E.Position = '3' then cast((cast(PHICAmount as float)/ cast(@BOthersAmt as float) )*(cast(@BOthersAmt as float) - cast(@POthersAmt as float)) as float) * -1 when E.Position = '4' then cast((cast(PHICAmount as float)/ cast(@BORAmt as float))*(cast(@BORAmt as float) - cast(@PORAmt as float)) as float) * -1 end [PHICAmount], E.IDNum, E.ItemID, E.TransactionDate, E.LocationID from ( Select distinct B.RevenueID,B.IDNum,B.ItemID,B.TransactionDate, B.LocationID, isnull(B.PHICAmount,0) [PHICAmount], G.Position from Medicare..tbMedSOA B left outer join Medicare..Medic_DumpCompensable G on G.Code = B.ItemID and G.IDNum = B.idnum where B.IDNum = @strIDNum ) E --to consider it not as denied but underpaid but many years ago so they will no longer pay it -- Delete Medicare..tbMedPayment Where IdNum = @strIdNum; End Else Begin Delete Medicare..tbMedReasonsForPaymentDenial Where IdNum = @strIdNum; --FOR MEDICARE COMPUTATION update Medicare..tbMedActual set PatRoomBoard = (Select cast(ActualRoomboard as money)from Medicare..tbMedActual where IdNum = @strIDNum) - @BRoomBoardAmt, PatDrug = (Select cast(ActualDrug as money) from Medicare..tbMedActual where IdNum = @strIDNum) - @BDrugAmt, PatOthers = (Select cast(ActualOthers as money) from Medicare..tbMedActual where IdNum = @strIDNum) - @BOthersAmt, PatOR = (Select cast(ActualOR as money) from Medicare..tbMedActual where IdNum = @strIDNum) - @BORAmt, MedRoomBoard = @BRoomBoardAmt, MedDrug = @BDrugAmt, MedOthers =@BOthersAmt , MedOR = @BORAmt where IdNum = @strIDNum Delete from Billing..tbBillDailyBill where RevenueID = 'SS' and ItemID in ('SS1','SS2','SS3','SS4') and Amount <= 0 and IdNum = @strIdNum Delete from Medicare..tbMedSOA where IDNum = @strIdNum and PHICAmount <= 0 End; If @@error <> 0 Begin goto Abort_Save; End; Commit Tran; Return 0; Abort_Save: Rollback Tran; Return -10001 ----------------------------------------------- GO /****** Object: StoredProcedure [dbo].[Medic_UpdateINFODenied] Script Date: 04/22/2012 19:27:33 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER Procedure [dbo].[Medic_UpdateINFODenied] @IDNum as varchar(8), @Denied as varchar(10), @Reason as varchar(100), @Appeal as Varchar(10), @Approved as varchar(10), @DeniedMain as varchar(10), @ReasonMain as varchar(100) AS if Exists(select * from Medicare..tbMedPatient where IDNum = @IDNum) BEGIN Update Medicare..tbMedPatient set ReasonDenied = @Reason, DateDenied = @Denied, DateDeniedMain = @DeniedMain, ReasonDeniedMain = @ReasonMain, DateAppealMain = @Appeal, DateApproved = @Approved where IDNum = @IDNum END -- If @@error<>0 -- Begin -- Goto Abort_saving; -- End; -- End; -- Abort_saving: --RollBack Tran --Return -10001 ------------------------ GO /****** Object: StoredProcedure [dbo].[Medic_SavePHICSOA] Script Date: 04/25/2012 14:46:46 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Medic_SavePHICSOA] --'559394' ,'jem' @strIdNum as varchar(15), @strUserID as varchar(10) as --set @strIDNum = '4613' --set @strUserID = '214' Delete tbMedSOA where IDNum = @StrIdnum If (Select IsNull(PackageID,'1') From Medicare..tbMedActual where IDNum = @strIdNum) = '1' Begin Insert into tbMedSOA select E.RevenueID, Case when E.Position = '2' then case when cast(TotalAmount as float) < cast(MedDrug as float) then cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(TotalAmount as float)) as float) else cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(MedDrug as float)) as float) end when E.Position = '4' then case when cast(TotalAmount as float) < cast(MedOR as float) then cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(TotalAmount as float)) as float) else cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(MedOR as float)) as float) end else case when cast(TotalAmount as float) < cast(MedOthers as float) then cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(TotalAmount as float)) as float) else cast((cast(Amount as float)/ cast(TotalAmount as float))*(cast(MedOthers as float)) as float) end End [Phic Amount], E.IDNum, E.Code as ItemID, getdate() as TransactionDate, E.LocationID from ( Select distinct IsNull(A.Code,'') [Code], [Description] = Case Len(IsNull(A.Code,'')) When 0 Then (Select IsNull(ItemName,'') from Build_File..tbCoRevenueCode Where RevenueID = A.RevenueID ) Else IsNull(A.Description,'') End, IsNull(A.Quantity,0) [Quantity], IsNull(A.Amount,0) [Amount], IsNull(A.RevenueID,'') [RevenueID], IsNull(A.Position,'') [Position], IsNull(A.IdNum,'') [IdNum], IsNull(A.UserID,'') [UserID], case when IsNull(B.MedDrug,0) > D.[TOTALAmount] then D.[TOTALAmount] else IsNull(B.MedDrug,0) end [MedDrug], IsNull(B.MedOthers,0) [MedOthers], IsNull(B.MedOR, 0) [MedOR], D.[TOTALAmount], isnull(A.LocationID,'') as LocationID from Medic_DumpCompensable A Left Outer Join tbMedActual B On A.IdNum = B.IdNum Left Outer Join tbMedClaim C On A.IdNum = C.IdNum Left Outer Join ( select distinct sum(IsNull(A.Amount,0)) [TOTALAmount], IsNull(A.Position,'') [Position], A.IdNum from Medic_DumpCompensable A Where A.IdNum = @strIdNum and (A.Position = '2' or A.Position = '3' or A.Position = '4') and A.Quantity > 0 and A.isCompensable = '0' group by A.Position, A.IDNum )D on A.IDnum = D.Idnum AND D.Position = A.Position Where A.IdNum = @strIdNum and (A.Position = '2' or A.Position = '3' or A.Position = '4') and A.Quantity > 0 and A.isCompensable = '0' ) E Order by E.Position, E.RevenueID End Else Begin Insert into tbMedSOA select E.RevenueID, Case When (E.Position = '2' and ActualDrug > 0) then Case When Cast(ActualDrug As Float) < Cast(MedDrug As Float) Then Cast((Cast(Amount As Float)/ cast(ActualDrug As Float))*(cast(ActualDrug as Float)) As Float) Else Cast((Cast(Amount As Float)/ Cast(ActualDrug As Float))*(Cast(MedDrug as Float)) As Float) End when (E.Position = '4' and ActualOR > 0) then Case When Cast(ActualOR As Float) < Cast(MedOR As Float) Then Cast((Cast(Amount As Float)/ cast(ActualOR As Float))*(cast(ActualOR as Float)) As Float) Else Cast((Cast(Amount As Float)/ Cast(ActualOR As Float))*(Cast(MedOR as Float)) As Float) End when (E.Position = '3' and ActualOthers > 0) then Case When Cast(ActualOthers As Float) < Cast(MedOthers As Float) Then Cast((Cast(Amount As Float)/ cast(ActualOthers As Float))*(cast(ActualOthers as Float)) As Float) Else Cast((Cast(Amount As Float)/ Cast(ActualOthers As Float))*(Cast(MedOthers as Float)) As Float) End else 0 End [Phic Amount], E.IDNum, E.Code as ItemID, getdate() as TransactionDate, E.LocationID from ( Select distinct IsNull(A.Code,'') [Code], [Description] = Case Len(IsNull(A.Code,'')) When 0 Then (Select IsNull(ItemName,'') from Build_File..tbCoRevenueCode Where RevenueID = A.RevenueID ) Else IsNull(A.Description,'') End, IsNull(A.Quantity,0) [Quantity], ISNULL(A.Amount,0) [Amount], IsNull(A.RevenueID,'') [RevenueID], case when (A.Position = 'N') then Case When IsNull(A.Position, 'N') = 'N' And A.RevenueID in ('PH', 'CS') then Case When (Select IsNull(ClassificationType,'') from Inventory..tbInvMaster M Left Outer Join Inventory..tbInvClassification N On M.ItemClassificationID = N.ItemClassificationID Where M.ItemID = A.Code) = 'D' Then '2' else '3' end when A.RevenueID not in ('PH', 'CS', 'AA', 'BB', 'TB') and A.Code not in (Select ItemID from Billing..tbBillExamListing B where NM_MedicareType In ('1', '2', '4') and B.RevenueID = A.RevenueID) Then '3' else (Select Case When IsNull(NM_MedicareType,'') = '' Then '3' Else NM_MedicareType End from Billing..tbBillExamListing Where RevenueID = A.RevenueID And ItemID = A.Code) End else IsNull(A.Position,'') end [Position], IsNull(A.IdNum,'') [IdNum], IsNull(A.UserID,'') [UserID], IsNull(B.MedRoomBoard,0) [MedRoomBoard], IsNull(B.MedDrug,0) [MedDrug], IsNull(B.MedOthers,0) [MedOthers], IsNull(B.MedOR, 0) [MedOR], IsNull(B.ActualRoomBoard,0) ActualRoomBoard, IsNull(B.ActualDrug,0) ActualDrug, IsNull(B.ActualOthers,0) ActualOthers, IsNull(B.ActualOR, 0) ActualOR, isnull(A.LocationID,'') as LocationID, D.[TOTALAmount] From Medic_DumpTable A Left Outer Join tbMedActual B On A.IdNum = B.IdNum Left Outer Join tbMedClaim C On A.IdNum = C.IdNum left outer join ( select distinct sum(IsNull(A.Amount,0)) [TOTALAmount], IsNull(A.Position,'') [Position], A.IdNum from Medic_DumpTable A Where A.IdNum = @strIdNum and ( A.Position = '2' or A.Position = '3' or A.Position = '4' or A.Position = 'N') and A.Quantity > 0 and A.Amount > 0 group by A.Position, A.IDNum )D on A.IDnum = D.Idnum AND D.Position = A.Position Where A.IdNum = @strIdNum And A.UserID = @strUserID And ( A.Position = '2' or A.Position = '3' or A.Position = '4' or A.Position = 'N') and A.Quantity > 0 And A.RevenueID IN (Select RevenueID from Build_file..tbCoRevenueCode where LGRP not in ('D', 'S', 'L', 'F')) ) E Order by E.Position, E.RevenueID End --------------------- alter table medicare..medic_dumptable add LocationID varchar(5) null ----------------- GO /****** Object: StoredProcedure [dbo].[Medic_AutoComputeCharges] Script Date: 04/25/2012 14:40:17 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.Medic_AutoComputeCharges Script Date: 07/01/2000 1:19:49 AM ******/ ALTER PROCEDURE [dbo].[Medic_AutoComputeCharges] @IdNum as varchar(10), @strUserID as varchar(10) AS /******/ Declare Patient_Charges CURSOR FOR Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..BillingDrugsSOA Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..vwHistoryInDrugs Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..BillingOthersSOA Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC') UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..vwHistoryIn Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC') Order by TransDate; /* SELECT (CASE WHEN tbinvstockcard.amount is NULL then 0 WHEN tbinvstockcard.revenueid = 'PC' or tbinvstockcard.revenueid = 'CC' then amount * -1 ELSE TBINVSTOCKCARD.AMOUNT END) as AMOUNT, ltrim(rtrim(isnull(TBcoRevenueCode.ServiceId,''))) as RevenueID, isnull(TBINVSTOCKCARD.itemid,'') as ItemId, tbinvstockcard.quantity, ltrim(rtrim(isnull(tbinvmaster.itemname,'') + ' ' + isnull(tbinvmaster.itemdesc,''))) as ItemDesc, TBINVSTOCKCARD.TransDate FROM Inventory..TBINVSTOCKCARD tbinvstockcard LEFT OUTER JOIN Patient_Data..tbPatient tbPatient ON TBINVSTOCKCARD.IdNum = tbPatient.IdNum LEFT OUTER JOIN Inventory..TBINVMASTER tbInvMaster ON tbinvstockcard.itemid = tbinvmaster.itemid LEFT OUTER JOIN Billing..tbbillInvCode tbcoRevenueCode on tbinvstockcard.revenueid = tbcorevenuecode.revenueid and tbinvstockcard.locationID = tbcorevenuecode.locationID WHERE TBINVSTOCKCARD.IDNUM= @IDNUM Union All SELECT (CASE WHEN tbbilldailybill.drcr = NULL then 0 WHEN tbbilldailybill.drcr = 'D' then tbbilldailybill.amount WHEN tbbilldailybill.drcr = 'C' then (tbbilldailybill.amount * -1) WHEN TBbilldailybill.drcr = 'P' and TBbilldailybill.revenueid = 'MD' then TBbilldailybill.amount WHEN tbbilldailybill.drcr = 'P' and tbbilldailybill.revenueid <> 'MD' then (tbbilldailybill.amount * -1) END) as AMOUNT, isnull(tbbilldailybill.RevenueId,'') as RevenueID, isnull(tbbilldailybill.itemid,'') as ItemId, tbbilldailybill.quantity, (CASE WHEN rtrim(ltrim(isnull(tbbilldailybill.ItemID,''))) = '' then tbcorevenuecode.itemname WHEN TbBillDailyBill.drcr = 'P' then Tbcorevenuecode.ItemName + ' - ' + 'DR. ' + isnull(TbcoDoctor.LastName,'') + ', ' + isnull(TbcoDoctor.Firstname,'') +' ' + isnull(TbcoDoctor.MiddleName,'') WHEN tbBillDailyBill.RevenueID = 'CP' then 'COMPANY PAYMENT - ' + tbCoCompany.Company Else tbBillExamListing.Description End) as ItemDesc, Tbbilldailybill.TransDate FROM billing..tbBillDailyBill tbBillDailyBill LEFT OUTER JOIN Patient_Data..tbPatient tbPatient ON tbBillDailyBill.IdNum = tbPatient.IdNum LEFT OUTER JOIN Billing..tbBillExamListing tbBillExamListing ON tbBillDailyBill.RevenueId = tbBillExamListing.RevenueId and tbBillDailyBill.ItemId = tbBillExamListing.ItemId LEFT OUTER JOIN Billing..tbCoCompany tbCoCompany ON tbBillDailyBill.ItemID = tbCoCompany.CompanyId LEFT OUTER JOIN Billing..tbCoDoctor tbcoDoctor ON tbBillDailyBill.ItemID = tbCoDoctor.DoctorID LEFT OUTER JOIN Billing..tbCoRevenueCode tbCoRevenueCode ON tbBillDailyBill.RevenueID = tbCoRevenueCode.RevenueID WHERE TBBILLDAILYBILL.IDNUM= @IDNUM Order by Transdate, RevenueId, ItemDesc;*/ /******/ declare @strCode as varchar(10) declare @strDescription as varchar(100) declare @fltQuantity as float declare @fltAmount as float declare @strRevenueID as varchar(2) declare @strIdNum as varchar(10) declare @datTransDate as datetime declare @Position as varchar(2) declare @Category as varchar(2) declare @LocationID as varchar(5) declare @strPosition as varchar(1) declare @fltTempQty as float declare @intRecordCount as int declare @intCtr as int Set @strIdNum = @IdNum Open Patient_Charges Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @datTransDate, @Position, @Category, @LocationID Set @intRecordCount = @@Cursor_Rows Set @intCtr = 1 Exec Medicare.dbo.Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @LocationID Begin Tran While @intCtr < @intRecordCount Begin Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @datTransDate, @Position, @Category, @LocationID Exec Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @LocationID Set @intCtr = @intCtr + 1 End Commit Tran CLOSE Patient_Charges DEALLOCATE Patient_Charges Return 0 Abort_Insert: Rollback Tran Return -100001 ----------------------- GO /****** Object: StoredProcedure [dbo].[Medic_InsertTempTable] Script Date: 04/25/2012 14:42:11 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Medic_InsertTempTable Script Date: 07/01/2000 1:19:50 AM ******/ ALTER PROCEDURE [dbo].[Medic_InsertTempTable] @strCode as varchar(10), @strDescription as varchar(100), @fltQuantity as float, @fltAmount as float, @strRevenueID as varchar(2), @strIdNum as varchar(10), @strUserId as varchar(10), @Position as varchar(2), @Category as varchar(2), @LocationID as varchar(5) AS Declare @strRWith as varchar(1); declare @strPosition as varchar(1); declare @strCategory as varchar(1); declare @fltTempQty as float; -- Set @strCode = IsNull(@strCode,''); If @strRevenueID = 'RA' Begin Set @strCode = null; End; Else Begin Set @strCode = IsNull(@strCode,''); End; Set @strDescription = IsNull(@strDescription,''); Set @fltQuantity = IsNull(@fltQuantity,0); Set @fltAmount = IsNull(@fltAmount,0); Set @strRevenueID = IsNull(@strRevenueID,''); Set @strIdNum = IsNull(@strIdNum,''); Set @strUserId = IsNull(@strUserID,''); Begin Tran set @fltTempQty = @fltQuantity; If @fltQuantity <= 0 Begin If not (@strRevenueID = 'PC' or @strRevenueID = 'PH' or @strRevenueID = 'CC' or @strRevenueID = 'CS') Begin set @fltTempQty = 1; End End; Set @strRwith = IsNull((Select Max(IsNull(Rwith,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID Group by RevenueID),''); /* Get MedicareType of Item */ Set @strPosition = ( Case @strRevenueID When 'SS' Then 'N' When 'RT' Then '1' When 'RA' Then '1' When 'PT' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoPTExam Where PTExamID = @strCode ), '' ) When 'CT' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoCTExam Where CTExamID = @strCode ), '' ) When 'AU' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoAudExam Where AudExamID = @strCode ), '' ) When 'HS' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'CV' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'NU' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoNucExam Where NucExamID = @strCode ), '' ) When 'PA' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoRTSExam Where RTSExamID = @strCode ), '' ) When 'XR' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoXrayExam Where XrayExamID = @strCode ), '' ) When 'LB' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'HI' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BB' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BA' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'US' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoUltraExam Where UltraExamID = @strCode ), '' ) When 'PH' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'PC' Then '2' /* Returned Medicine */ When 'CS' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'HC' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'CC' Then '3' /* Returned Supplies */ When 'MD' then 'N' When 'FP' then 'N' Else Case @strRWith When 'Y' then IsNull( ( Select Max(IsNull(MedicareType,'')) from Build_File..tbCoOtherRevenue Where OtherRevenueID = @strCode Group by OtherRevenueID ), '' ) Else IsNull( ( Select Max(IsNull(MedicareType,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID Group by RevenueID ), '' ) End End ); Set @strCategory = 'A'; /* Get MedicareCategory of Item */ Set @strCategory = ( Case @strRevenueID When 'PT' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoPTExam Where PTExamID = @strCode ), '' ) When 'CT' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoCTExam Where CTExamID = @strCode ), '' ) When 'AU' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoAudExam Where AudExamID = @strCode ), '' ) When 'HS' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'CV' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'NU' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoNucExam Where NucExamID = @strCode ), '' ) When 'PA' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoRTSExam Where RTSExamID = @strCode ), '' ) When 'XR' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoXrayExam Where XrayExamID = @strCode ), '' ) When 'LB' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'HI' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BB' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BA' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'US' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoUltraExam Where UltraExamID = @strCode ), '' ) When 'PH' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'CS' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'HC' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) Else Case @strRWith When 'Y' Then IsNull( ( Select Max(IsNull(MedicareCategory,'')) from Build_File..tbCoOtherRevenue Where OtherRevenueID = @strCode Group by OtherRevenueID ), '' ) Else IsNull( ( Select Max(IsNull(MedicareCategory,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strCode Group by RevenueID ), '' ) End End ); /* Default Position When code not found */ If Len(@strPosition) = 0 Begin Select @strPosition = ( Select MedicareType from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID ); End; /* If Code is blank get Position from tbCoRevenueCode */ If Len(@strCode) = 0 and (not @strRevenueID = 'RA' or not @strRevenueID = 'RT') Begin Set @strPosition = ( Select MedicareType from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID ); End; If @fltTempQty = 0 Begin Set @fltTempQty = 1; End; -- If not @strPosition = 'N' /* Do not include non-medicare items */ Begin If Exists( Select * from Medicare..Medic_DumpTable Where Code = @strCode and RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID ) Begin If @fltAmount < 0 Begin Set @fltTempQty = Abs(@fltTempQty) * -1; End; If Len(@strCode) = 0 Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity + @fltTempQty, Amount = Amount + @fltAmount Where RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID; End Else Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity + @fltTempQty, Amount = Amount + @fltAmount Where Code = @strCode and RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID; End; End; Else Begin If @strRevenueID = 'PC' /* Returned Medicines */ Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity - Abs(@fltTempQty), Amount = Amount - Abs(@fltAmount) Where Code = @strCode and RevenueID = 'PH' and IdNum = @strIdNum and UserID = @strUserID; End; Else If @strRevenueID = 'CC' /* Returned Supplies */ Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity - (Abs(@fltTempQty) ), Amount = Amount - (Abs(@fltAmount) ) Where Code = @strCode and RevenueID = 'CS' and IdNum = @strIdNum and UserID = @strUserID; End; Else Begin If @strRevenueID = 'PH' or @strRevenueID = 'HC' Begin Set @strDescription = ( Select IsNull(B.GenericName,'') + ' ' + IsNull(A.ItemDesc,'') + ' (' + A.ItemName + ')' from Inventory..tbInvMaster A Left Outer Join Inventory..tbForGeneric B On A.GenericID = B.GenericID Where A.ItemID = @strCode ); End; Insert Medicare..Medic_DumpTable( Code, Description, Quantity, Amount, RevenueID, Position, IdNum, UserID, MedicareCategory, LocationID ) Values( @strCode, @strDescription, @fltTempQty, @fltAmount, @strRevenueID, @Position, --@strPosition, @strIdNum, @strUserID, @Category, @LocationID) --@strCategory ); End; End; If @@error<>0 Begin goto Abort_Insert; End; End; /* If not @strPosition = 'N' */ Commit Tran; Return 0; Abort_Insert: Rollback Tran; Return -100001; -------------------------------- GO /****** Object: StoredProcedure [dbo].[Medic_AutoComputeChargesOP] Script Date: 04/25/2012 17:45:02 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO /****** Object: Stored Procedure dbo.Medic_AutoComputeCharges Script Date: 07/01/2000 1:19:49 AM ******/ /*** 02/14/2002 : Convert condition transdate to ***/ ALTER PROCEDURE [dbo].[Medic_AutoComputeChargesOP] --'498376B' , 'jem' @IdNum as varchar(10), @strUserID as varchar(10) AS /******/ Declare Patient_Charges CURSOR FOR Select Amount, RevenueID, ItemID, Quantity, Description, MedicareType, MedicareCategory, LocationID--, TransDate from Billing..OPBillingDrugsSOA Where IDNum = @IDNum --and (convert(varchar(10),TransDate,101) < = convert(varchar(10),BillingDate,101) or BillingDate is null) --Where IDNum = @IDNum and (TransDate < = ,BillingDate or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, MedicareType, MedicareCategory, LocationID--, TransDate from Billing..vwHistoryOutDrugs Where IDNum = @IDNum --and (convert(varchar(10),TransDate,101) < = convert(varchar(10),BillingDate,101) or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, MedicareType, MedicareCategory, LocationID--, TransDate--, TransDate from Billing..OPBillingOthersSOA Where IDNum = @IDNum --and (convert(varchar(10),TransDate,101) < = convert(varchar(10),BillingDate,101) or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC') UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, MedicareType, MedicareCategory, LocationID--, TransDate--, TransDate from Billing..vwHistoryOut Where IDNum = @IDNum --and (convert(varchar(10),TransDate,101) < = convert(varchar(10),BillingDate,101) or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC');-- --Order By Transdate; /* SELECT (CASE WHEN TBINVSTOCKCARD.amount is NULL then 0 WHEN tbinvstockcard.revenueid = 'PC' or tbinvstockcard.revenueid = 'CC' then amount * -1 ELSE TBINVSTOCKCARD.AMOUNT END) as AMOUNT, isnull(TBcoRevenueCode.ServiceId,'') as RevenueID, isnull(TBINVSTOCKCARD.itemid,'') as ItemId, tbinvstockcard.quantity, ltrim(rtrim(isnull(tbinvmaster.itemname,'') + ' ' + isnull(tbinvmaster.itemdesc,''))) as ItemDesc FROM Inventory..TBINVSTOCKCARD tbInvStockCard LEFT OUTER JOIN Patient_Data..tbOutPatient tbOutPatient ON TBINVSTOCKCARD.IdNum = tbOutPatient.IdNum LEFT OUTER JOIN Inventory..TBINVMASTER tbInvmaster ON TBINVSTOCKCARD.ItemID = TBINVMASTER.ItemID LEFT OUTER JOIN Billing..tbbillInvCode tbcoRevenueCode on tbinvstockcard.revenueid = tbcorevenuecode.revenueid and tbinvstockcard.locationID = tbcorevenuecode.locationID WHERE TBINVSTOCKCARD.IDNUM= @IDNUM Union All SELECT (CASE WHEN TBBILLOPDAILYOUT.drcr = NULL then 0 WHEN TBBILLOPDAILYOUT.drcr = 'D' then TBBILLOPDAILYOUT.amount WHEN TBBILLOPDAILYOUT.drcr = 'C' then (TBBILLOPDAILYOUT.amount * -1) WHEN TBBILLOPDAILYOUT.drcr = 'P' and TBBILLOPDAILYOUT.revenueid = 'MD' then TBBILLOPDAILYOUT.amount WHEN TBBILLOPDAILYOUT.drcr = 'P' and TBBILLOPDAILYOUT.revenueid <> 'MD' then (TBBILLOPDAILYOUT.amount * -1) END) as AMOUNT, isnull(TBBILLOPDAILYOUT.RevenueId,'') as RevenueID, isnull(TBBILLOPDAILYOUT.itemid,'') as ItemId, TBBILLOPDAILYOUT.quantity, (CASE WHEN rtrim(ltrim(TBBILLOPDAILYOUT.ItemID)) = '' then tbcorevenuecode.itemname WHEN TBBILLOPDAILYOUT.drcr = 'P' then Tbcorevenuecode.ItemName + ' - ' + 'DR. ' + isnull(TbcoDoctor.LastName,'') + ', ' + isnull(TbcoDoctor.Firstname,'') +' ' + isnull(TbcoDoctor.MiddleName,'') WHEN TBBILLOPDAILYOUT.RevenueID = 'CP' then 'COMPANY PAYMENT - ' + tbCoCompany.Company ELSE tbBillExamListing.Description End) as ItemDesc FROM Billing..TBBILLOPDAILYOUT TBBILLOPDAILYOUT LEFT OUTER JOIN Patient_Data..tbOutPatient tbOutpatient ON TBBILLOPDAILYOUT.IdNum = tbOutPatient.IdNum LEFT OUTER JOIN Billing..TbBillExamListing tbBillExamListing ON tbBillOPDailyOut.RevenueId = tbBillExamListing.RevenueId and tbBillOPDailyOut.ItemId = tbBillExamListing.ItemId LEFT OUTER JOIN Billing..tbcoCompany tbcoCompany On tbBillOPDailyOut.ItemID = TbCoCompany.CompanyId LEFT OUTER Join Billing..tbCoDoctor tbcoDoctor ON TBBILLOPDAILYOUT.ItemID = tbCoDoctor.DoctorID LEFT OUTER JOIN Billing..tbCoRevenueCode tbCoRevenueCode ON TBBILLOPDAILYOUT.RevenueID = tbCoRevenueCode.RevenueID WHERE TBBILLOPDAILYOUT.IDNUM= @IDNUM;*/ /******/ declare @strCode as varchar(10) declare @strDescription as varchar(100) declare @fltQuantity as float declare @fltAmount as float declare @strRevenueID as varchar(2) declare @strIdNum as varchar(10) declare @strPosition as varchar(1) declare @fltTempQty as float declare @intRecordCount as int declare @intCtr as int declare @Position as varchar(2) declare @Category as varchar(2) declare @strLocationID as varchar(5) Set @strIdNum = @IdNum Open Patient_Charges Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @Position, @Category, @strLocationID Set @intRecordCount = @@Cursor_Rows Set @intCtr = 1 Exec Medicare..Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @strLocationID Begin Tran While @intCtr < @intRecordCount Begin Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @Position, @Category, @strLocationID Exec Medicare..Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @strLocationID Set @intCtr = @intCtr + 1 End Commit Tran CLOSE Patient_Charges DEALLOCATE Patient_Charges Return 0 Abort_Insert: Rollback Tran Return -100001 GO USE [Build_File] GO /****** Object: StoredProcedure [dbo].[sp_Bui_Search_Doctor] Script Date: 05/02/2012 18:33:48 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_Bui_Search_Doctor] (@SearchCriterion1 as varchar(30), @SearchCriterion2 as varchar(30), @SearchCriterion3 as varchar(30), @Type as varchar(1)) AS If (@Type = '1') Select A.*, B.Specialization, B2.Specialization as Specialization2, B3.Specialization as Specialization3, C.Category, -- V.Company [Vendor] '' [Vendor] from tbcoDoctor A Left Outer Join tbcoSpecialization B On A.SpecializationID = B.SpecializationID Left Outer Join tbcoSpecialization B2 On A.SpecializationID2 = B2.SpecializationID Left Outer Join tbcoSpecialization B3 On A.SpecializationID3 = B3.SpecializationID Left Outer Join tbCoDocCategory C On A.CategoryID = C.CategoryID --Left Outer Join Accounting..Vend V --On A.VendorID = V.VendorID where ltrim(rtrim(doctorid)) = @SearchCriterion1 else If (@Type = '2') Select distinct ltrim(rtrim(isnull(lastname,''))) + ', ' + ltrim(rtrim(isnull(firstname,''))) + ' ' + ltrim(rtrim(isnull(middlename,''))) as DoctorName, DoctorID from tbcoDoctor where ltrim(rtrim(isnull(LastName,''))) = @SearchCriterion1 and ltrim(rtrim(isnull(FirstName,''))) = @SearchCriterion2 and ltrim(rtrim(isnull(MiddleName,''))) = @SearchCriterion3 else If (@Type = '3') Select '' as dumm, ltrim(rtrim(isnull(lastname,''))) + ', ' + ltrim(rtrim(isnull(firstname,''))) + ' ' + ltrim(rtrim(isnull(middlename,''))) as DoctorName, DoctorID, License, taxnumber, PMCC from tbcoDoctor order by Doctorname else If (@Type = '4') Select distinct '' as dumm, ltrim(rtrim(isnull(A.lastname,''))) + ', ' + ltrim(rtrim(isnull(A.firstname,''))) + ' ' + ltrim(rtrim(isnull(A.middlename,''))) as DoctorName, A.DoctorID, A.License, A.taxnumber, (case when A.status = 'I' then 'Inactive' else 'Active' End) as status, A.pmcc,B.Specialization,C.Category, A.SchedDay1 as Monday, A.SchedDay2 as Tuesday, A.SchedDay3 as Wednesday, A.SchedDay4 as Thursday, A.SchedDay5 as Friday, A.SchedDay6 as Saturday, A.SchedDay7 as Sunday from tbcoDoctor A Left Outer Join tbcoSpecialization B On A.SpecializationID = B.SpecializationID Left Outer Join tbCoDocCategory C On A.CategoryID = C.CategoryID order by Doctorname GO USE PATIENT_DATA Go Alter Table tbmedrecsetup Add RevenueCode varchar(3) Go Update tbMedrecsetup set RevenueCode = 'MC' GO Insert into Patient_Data..tbMedRecMenu(MenuID,Menu,Status,MenuGroup,MainMenu) values('107','Assessment Patient List','1','C','2') GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Sp_MedRec_IncomeStatement') EXEC ('CREATE PROC dbo.Sp_MedRec_IncomeStatement AS SELECT 1') GO ALTER Procedure Sp_MedRec_IncomeStatement @StartDate varchar(12), @EndDate varchar(12) As --Declare --@StartDate varchar(12), --@EndDate varchar(12) -- --Set @StartDate ='04/01/2012' --Set @EndDate ='04/09/2012' Declare @RevenueID as varchar(3) Select @RevenueID = RevenueCode from Patient_Data..tbMedRecSetup Select A.RevenueID, A.IDNum, A.HospNum, A.Name, A.Transdate, A.AssessNum, A.Quantity, A.Amount, A.ItemID,A.RecordStatus, B.OtherRevenue, Case when right(A.IDNum,1)= 'B' then 'OUTPATIENT' Else 'INPATIENT' End as PatientType From Billing..tbCashAssessment A Left Outer Join Build_File..tbcoOtherRevenue B on A.ItemID = B.OtherRevenueID Where RevenueID = @RevenueID And A.TransDate between @StartDate and @EndDate + ' 23:59:59:99' And (A.RecordStatus <> 'R' or A.RecordStatus is null) Order By B.OtherRevenue GO Insert into Patient_Data..tbMedRecMenu(MenuID,Menu,Status,MenuGroup,MainMenu) values('106','Assessment Income Report','1','C','2') GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Sp_MedRec_AssesstmentReport') EXEC ('CREATE PROC dbo.Sp_MedRec_AssesstmentReport AS SELECT 1') GO ALTER Procedure [dbo].[Sp_MedRec_AssesstmentReport] @StartDate varchar(12), @EndDate varchar(12) As --Declare --@StartDate varchar(12), --@EndDate varchar(12) -- --Set @StartDate ='04/01/2012' --Set @EndDate ='04/09/2012' Declare @RevenueID as varchar(3) Select @RevenueID = RevenueCode from Patient_Data..tbMedRecSetup Select A.RevenueID, A.IDNum, A.HospNum, A.Name, A.Transdate, A.AssessNum, A.Quantity, A.Amount, A.ItemID,A.RecordStatus, B.OtherRevenue, Case when right(A.IDNum,1)= 'B' then 'OUTPATIENT' Else 'INPATIENT' End as PatientType, C.Lastname+', '+C.FirstName+' '+Left(C.MiddleName,1)as [User] From Billing..tbCashAssessment A Left Outer Join Build_File..tbcoOtherRevenue B on A.ItemID = B.OtherRevenueID Left Outer Join Password..tbPasswordMaster C on A.UserID = C.employeeID Where RevenueID = @RevenueID And A.TransDate between @StartDate and @EndDate + ' 23:59:59:99' And (A.RecordStatus <> 'R' or A.RecordStatus is null) Order By B.OtherRevenue ------------------ GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_MedRec_PrintAssesstment') EXEC ('CREATE PROC dbo.sp_MedRec_PrintAssesstment AS SELECT 1') GO ALTER Procedure [dbo].[sp_MedRec_PrintAssesstment] @AssestmentNum varchar(15) as select a.HospNum, a.IdNum, a.[Name]as PxName, a.TransDate, a.AssessNum, a.ItemID, a.Quantity, a.Amount, b.LastName+', '+ b.FirstName +' '+left(b.MiddleName,1)as Employee, c.OtherRevenue From Billing..tbCashAssessment a left outer join Password..tbpasswordmaster b on a.UserID = b.EmployeeID left outer join Build_File..tbcoOtherRevenue c on a.ItemID = c.OtherRevenueID --Where AssessNum = 'MR' + + RTRIM(@AssestmentNum) Where AssessNum = RTrim(@AssestmentNum) ------------------- go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_MedRec_AssessmentEntry') EXEC ('CREATE PROC dbo.sp_MedRec_AssessmentEntry AS SELECT 1') GO ALTER PROCEDURE [dbo].[sp_MedRec_AssessmentEntry] @strType as varchar(5), @Name AS varChar(60), @RevenueID as varchar(2), @ItemID AS varChar(8), @Quantity AS Float, @Amount AS Float, @UserID AS varChar(10), @IdNum as varchar(10), @Hospnum as varchar(10), @AssessNum AS varChar(10) AS DECLARE @AssessmentNum AS varChar(10), @DrCr AS varChar(1) --IF @RevenueID = 'MD' -- BEGIN SET @DrCr = 'D' -- END SET @AssessmentNum = @strType + RTRIM(@AssessNum) INSERT INTO Billing..tbCashAssessment (IDNum, [Name], Transdate, AssessNum, [Indicator], DrCr, ItemID, Quantity, Amount, RevenueID, UserID, DepartmentId, Hospnum, RefNum) VALUES (@IdNum, @Name, GETDATE(), @AssessmentNum, @RevenueID, @DrCr, @ItemID, @Quantity, @Amount, @RevenueID, @UserID, @strType, @Hospnum, @AssessmentNum) GO ------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Adm_ConsolidationList') EXEC ('CREATE PROC dbo.sp_Adm_ConsolidationList AS SELECT 1') GO GO ALTER PROCEDURE [dbo].[sp_Adm_ConsolidationList] @LastName as varchar(40) = null as if @LastName = '' or @LastName = null begin Select distinct '', Hospnum, NewHospnum, dbo.Fn_GetCompleteName(NewHospnum) PatientName, dbo.fn_GetCompleteAddress(NewHospnum) Address from Patient_Data..tbPatient P left Outer Join Patient_Data..tbMergedHistory M on P.Hospnum = M.OldHospnum where hospnum in ( Select oldhospnum from Patient_Data..tbmergedhistory) and Newhospnum in (Select hospnum from Patient_Data..tbmaster) union all Select distinct '', Hospnum, NewHospnum, dbo.Fn_GetCompleteName(NewHospnum), dbo.fn_GetCompleteAddress(NewHospnum) from Patient_Data..tbOutPatient P left Outer Join Patient_Data..tbMergedHistory M on P.Hospnum = M.OldHospnum where hospnum in ( Select oldhospnum from Patient_Data..tbmergedhistory) and Newhospnum in (Select hospnum from Patient_Data..tbmaster) End Else begin Select distinct '', P.Hospnum, M.NewHospnum, dbo.Fn_GetCompleteName(M.NewHospnum) PatientName, dbo.fn_GetCompleteAddress(M.NewHospnum) Address from Patient_Data..tbPatient P left Outer Join Patient_Data..tbMergedHistory M on P.Hospnum = M.OldHospnum left Outer Join Patient_Data..tbMaster Master on M.NewHospnum = Master.Hospnum where P.hospnum in (Select oldhospnum from Patient_Data..tbmergedhistory) And M.Newhospnum in (Select hospnum from Patient_Data..tbmaster) and Master.LastName like '%'+ @LastName +'%' Union All Select distinct '', P.Hospnum, M.NewHospnum, dbo.Fn_GetCompleteName(M.NewHospnum) PatientName, dbo.fn_GetCompleteAddress(M.NewHospnum) Address from Patient_Data..tbOutPatient P left Outer Join Patient_Data..tbMergedHistory M on P.Hospnum = M.OldHospnum left Outer Join Patient_Data..tbMaster Master on M.NewHospnum = Master.Hospnum where P.hospnum in (Select oldhospnum from Patient_Data..tbmergedhistory) And M.Newhospnum in (Select hospnum from Patient_Data..tbmaster) and Master.LastName = @LastName And Master.LastName = @LastName End GO use MEDICARE go alter table medicare..tbmedhospital add ActivatePhase1 bit null go alter table medicare..tbmedhospital add ActivatePhase2 bit null go alter table medicare..tbmedhospital add ActivatePhase1_2 bit null go update medicare..tbmedhospital set ActivatePhase1 = 1 update medicare..tbmedhospital set ActivatePhase1_2 = 0 update medicare..tbmedhospital set ActivatePhase2 = 0 go alter table build_file..tbcoBuildFileSetting add isAllowUserVerification bit go update build_file..tbcoBuildFileSetting set isAllowUserVerification = 0 go USE [Medicare] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Medic_AutoComputeCharges') EXEC ('CREATE PROC dbo.Medic_AutoComputeCharges AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[Medic_AutoComputeCharges] Script Date: 05/21/2012 15:26:03 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.Medic_AutoComputeCharges Script Date: 07/01/2000 1:19:49 AM ******/ ALTER PROCEDURE [dbo].[Medic_AutoComputeCharges] @IdNum as varchar(10), @strUserID as varchar(10) AS /******/ Declare Patient_Charges CURSOR FOR Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..BillingDrugsSOA Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..vwHistoryInDrugs Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..BillingOthersSOA Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC') UNION ALL Select Amount, RevenueID, ItemID, Quantity, Description, TransDate, MedicareType, MedicareCategory, LocationID from Billing..vwHistoryIn Where IDNum = @IDNum --and (TransDate < = BillingDate or BillingDate is null) and DrCr <> 'P' and RevenueID not in ('PH','PC','CS','CC') Order by TransDate; /* SELECT (CASE WHEN tbinvstockcard.amount is NULL then 0 WHEN tbinvstockcard.revenueid = 'PC' or tbinvstockcard.revenueid = 'CC' then amount * -1 ELSE TBINVSTOCKCARD.AMOUNT END) as AMOUNT, ltrim(rtrim(isnull(TBcoRevenueCode.ServiceId,''))) as RevenueID, isnull(TBINVSTOCKCARD.itemid,'') as ItemId, tbinvstockcard.quantity, ltrim(rtrim(isnull(tbinvmaster.itemname,'') + ' ' + isnull(tbinvmaster.itemdesc,''))) as ItemDesc, TBINVSTOCKCARD.TransDate FROM Inventory..TBINVSTOCKCARD tbinvstockcard LEFT OUTER JOIN Patient_Data..tbPatient tbPatient ON TBINVSTOCKCARD.IdNum = tbPatient.IdNum LEFT OUTER JOIN Inventory..TBINVMASTER tbInvMaster ON tbinvstockcard.itemid = tbinvmaster.itemid LEFT OUTER JOIN Billing..tbbillInvCode tbcoRevenueCode on tbinvstockcard.revenueid = tbcorevenuecode.revenueid and tbinvstockcard.locationID = tbcorevenuecode.locationID WHERE TBINVSTOCKCARD.IDNUM= @IDNUM Union All SELECT (CASE WHEN tbbilldailybill.drcr = NULL then 0 WHEN tbbilldailybill.drcr = 'D' then tbbilldailybill.amount WHEN tbbilldailybill.drcr = 'C' then (tbbilldailybill.amount * -1) WHEN TBbilldailybill.drcr = 'P' and TBbilldailybill.revenueid = 'MD' then TBbilldailybill.amount WHEN tbbilldailybill.drcr = 'P' and tbbilldailybill.revenueid <> 'MD' then (tbbilldailybill.amount * -1) END) as AMOUNT, isnull(tbbilldailybill.RevenueId,'') as RevenueID, isnull(tbbilldailybill.itemid,'') as ItemId, tbbilldailybill.quantity, (CASE WHEN rtrim(ltrim(isnull(tbbilldailybill.ItemID,''))) = '' then tbcorevenuecode.itemname WHEN TbBillDailyBill.drcr = 'P' then Tbcorevenuecode.ItemName + ' - ' + 'DR. ' + isnull(TbcoDoctor.LastName,'') + ', ' + isnull(TbcoDoctor.Firstname,'') +' ' + isnull(TbcoDoctor.MiddleName,'') WHEN tbBillDailyBill.RevenueID = 'CP' then 'COMPANY PAYMENT - ' + tbCoCompany.Company Else tbBillExamListing.Description End) as ItemDesc, Tbbilldailybill.TransDate FROM billing..tbBillDailyBill tbBillDailyBill LEFT OUTER JOIN Patient_Data..tbPatient tbPatient ON tbBillDailyBill.IdNum = tbPatient.IdNum LEFT OUTER JOIN Billing..tbBillExamListing tbBillExamListing ON tbBillDailyBill.RevenueId = tbBillExamListing.RevenueId and tbBillDailyBill.ItemId = tbBillExamListing.ItemId LEFT OUTER JOIN Billing..tbCoCompany tbCoCompany ON tbBillDailyBill.ItemID = tbCoCompany.CompanyId LEFT OUTER JOIN Billing..tbCoDoctor tbcoDoctor ON tbBillDailyBill.ItemID = tbCoDoctor.DoctorID LEFT OUTER JOIN Billing..tbCoRevenueCode tbCoRevenueCode ON tbBillDailyBill.RevenueID = tbCoRevenueCode.RevenueID WHERE TBBILLDAILYBILL.IDNUM= @IDNUM Order by Transdate, RevenueId, ItemDesc;*/ /******/ declare @strCode as varchar(10) declare @strDescription as varchar(100) declare @fltQuantity as float declare @fltAmount as float declare @strRevenueID as varchar(2) declare @strIdNum as varchar(10) declare @datTransDate as datetime declare @Position as varchar(2) declare @Category as varchar(2) declare @LocationID as varchar(5) declare @strPosition as varchar(1) declare @fltTempQty as float declare @intRecordCount as int declare @intCtr as int Set @strIdNum = @IdNum Open Patient_Charges Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @datTransDate, @Position, @Category, @LocationID Set @intRecordCount = @@Cursor_Rows Set @intCtr = 1 Exec Medicare.dbo.Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @LocationID Begin Tran While @intCtr < @intRecordCount Begin Fetch Next from Patient_Charges Into @fltAmount, @strRevenueID, @strCode, @fltQuantity, @strDescription, @datTransDate, @Position, @Category, @LocationID Exec Medic_InsertTempTable @strCode, @strDescription, @fltQuantity, @fltAmount, @strRevenueID, @strIdNum, @strUserID, @Position, @Category, @LocationID Set @intCtr = @intCtr + 1 End Commit Tran CLOSE Patient_Charges DEALLOCATE Patient_Charges Return 0 Abort_Insert: Rollback Tran Return -100001 go ----------------------- USE [Medicare] GO /****** Object: StoredProcedure [dbo].[Medic_InsertTempTable] Script Date: 05/21/2012 15:29:22 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO alter table Medicare..Medic_DumpTable add [LocationID] [varchar](5) NULL GO ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Medic_InsertTempTable') EXEC ('CREATE PROC dbo.Medic_InsertTempTable AS SELECT 1') GO /****** Object: Stored Procedure dbo.Medic_InsertTempTable Script Date: 07/01/2000 1:19:50 AM ******/ ALTER PROCEDURE [dbo].[Medic_InsertTempTable] @strCode as varchar(10), @strDescription as varchar(100), @fltQuantity as float, @fltAmount as float, @strRevenueID as varchar(2), @strIdNum as varchar(10), @strUserId as varchar(10), @Position as varchar(2), @Category as varchar(2), @LocationID as varchar(5) AS Declare @strRWith as varchar(1); declare @strPosition as varchar(1); declare @strCategory as varchar(1); declare @fltTempQty as float; -- Set @strCode = IsNull(@strCode,''); If @strRevenueID = 'RA' Begin Set @strCode = null; End; Else Begin Set @strCode = IsNull(@strCode,''); End; Set @strDescription = IsNull(@strDescription,''); Set @fltQuantity = IsNull(@fltQuantity,0); Set @fltAmount = IsNull(@fltAmount,0); Set @strRevenueID = IsNull(@strRevenueID,''); Set @strIdNum = IsNull(@strIdNum,''); Set @strUserId = IsNull(@strUserID,''); Begin Tran set @fltTempQty = @fltQuantity; If @fltQuantity <= 0 Begin If not (@strRevenueID = 'PC' or @strRevenueID = 'PH' or @strRevenueID = 'CC' or @strRevenueID = 'CS') Begin set @fltTempQty = 1; End End; Set @strRwith = IsNull((Select Max(IsNull(Rwith,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID Group by RevenueID),''); /* Get MedicareType of Item */ Set @strPosition = ( Case @strRevenueID When 'SS' Then 'N' When 'RT' Then '1' When 'RA' Then '1' When 'PT' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoPTExam Where PTExamID = @strCode ), '' ) When 'CT' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoCTExam Where CTExamID = @strCode ), '' ) When 'AU' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoAudExam Where AudExamID = @strCode ), '' ) When 'HS' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'CV' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'NU' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoNucExam Where NucExamID = @strCode ), '' ) When 'PA' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoRTSExam Where RTSExamID = @strCode ), '' ) When 'XR' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoXrayExam Where XrayExamID = @strCode ), '' ) When 'LB' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'HI' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BB' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BA' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'US' Then IsNull( ( Select IsNull(MedicareType,'') from Build_File..tbCoUltraExam Where UltraExamID = @strCode ), '' ) When 'PH' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'PC' Then '2' /* Returned Medicine */ When 'CS' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'HC' Then IsNull( ( Select IsNull(MedicareType,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'CC' Then '3' /* Returned Supplies */ When 'MD' then 'N' When 'FP' then 'N' Else Case @strRWith When 'Y' then IsNull( ( Select Max(IsNull(MedicareType,'')) from Build_File..tbCoOtherRevenue Where OtherRevenueID = @strCode Group by OtherRevenueID ), '' ) Else IsNull( ( Select Max(IsNull(MedicareType,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID Group by RevenueID ), '' ) End End ); Set @strCategory = 'A'; /* Get MedicareCategory of Item */ Set @strCategory = ( Case @strRevenueID When 'PT' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoPTExam Where PTExamID = @strCode ), '' ) When 'CT' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoCTExam Where CTExamID = @strCode ), '' ) When 'AU' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoAudExam Where AudExamID = @strCode ), '' ) When 'HS' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'CV' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoHSExam Where HSExamID = @strCode ), '' ) When 'NU' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoNucExam Where NucExamID = @strCode ), '' ) When 'PA' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoRTSExam Where RTSExamID = @strCode ), '' ) When 'XR' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoXrayExam Where XrayExamID = @strCode ), '' ) When 'LB' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'HI' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BB' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'BA' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoLabExam Where LabExamID = @strCode ), '' ) When 'US' Then IsNull( ( Select IsNull(MedicareCategory,'') from Build_File..tbCoUltraExam Where UltraExamID = @strCode ), '' ) When 'PH' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'CS' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) When 'HC' Then IsNull( ( Select IsNull(MedicareCategory,'') from Inventory..tbInvMaster Where ItemID = @strCode ), '' ) Else Case @strRWith When 'Y' Then IsNull( ( Select Max(IsNull(MedicareCategory,'')) from Build_File..tbCoOtherRevenue Where OtherRevenueID = @strCode Group by OtherRevenueID ), '' ) Else IsNull( ( Select Max(IsNull(MedicareCategory,'')) from Build_File..tbCoRevenueCode Where RevenueID = @strCode Group by RevenueID ), '' ) End End ); /* Default Position When code not found */ If Len(@strPosition) = 0 Begin Select @strPosition = ( Select MedicareType from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID ); End; /* If Code is blank get Position from tbCoRevenueCode */ If Len(@strCode) = 0 and (not @strRevenueID = 'RA' or not @strRevenueID = 'RT') Begin Set @strPosition = ( Select MedicareType from Build_File..tbCoRevenueCode Where RevenueID = @strRevenueID ); End; If @fltTempQty = 0 Begin Set @fltTempQty = 1; End; -- If not @strPosition = 'N' /* Do not include non-medicare items */ Begin If Exists( Select * from Medicare..Medic_DumpTable Where Code = @strCode and RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID ) Begin If @fltAmount < 0 Begin Set @fltTempQty = Abs(@fltTempQty) * -1; End; If Len(@strCode) = 0 Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity + @fltTempQty, Amount = Amount + @fltAmount Where RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID; End Else Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity + @fltTempQty, Amount = Amount + @fltAmount Where Code = @strCode and RevenueID = @strRevenueID and IdNum = @strIdNum and UserID = @strUserID; End; End; Else Begin If @strRevenueID = 'PC' /* Returned Medicines */ Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity - Abs(@fltTempQty), Amount = Amount - Abs(@fltAmount) Where Code = @strCode and RevenueID = 'PH' and IdNum = @strIdNum and UserID = @strUserID; End; Else If @strRevenueID = 'CC' /* Returned Supplies */ Begin Update Medicare..Medic_DumpTable Set Quantity = Quantity - (Abs(@fltTempQty) ), Amount = Amount - (Abs(@fltAmount) ) Where Code = @strCode and RevenueID = 'CS' and IdNum = @strIdNum and UserID = @strUserID; End; Else Begin If @strRevenueID = 'PH' or @strRevenueID = 'HC' Begin Set @strDescription = ( Select IsNull(B.GenericName,'') + ' ' + IsNull(A.ItemDesc,'') + ' (' + A.ItemName + ')' from Inventory..tbInvMaster A Left Outer Join Inventory..tbForGeneric B On A.GenericID = B.GenericID Where A.ItemID = @strCode ); End; Insert Medicare..Medic_DumpTable( Code, Description, Quantity, Amount, RevenueID, Position, IdNum, UserID, MedicareCategory, LocationID ) Values( @strCode, @strDescription, @fltTempQty, @fltAmount, @strRevenueID, @Position, --@strPosition, @strIdNum, @strUserID, @Category, @LocationID) --@strCategory ); End; End; If @@error<>0 Begin goto Abort_Insert; End; End; /* If not @strPosition = 'N' */ Commit Tran; Return 0; Abort_Insert: Rollback Tran; Return -100001; go USE [Patient_data] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbDBImage]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [TableName] [varchar](50) NULL, [FieldName] [varchar](50) NULL, [IDKEY] [varchar](15) NULL, [DBImage] [image] NULL, [FileType] [varchar](15) NULL, [FileName] [varchar](30) NULL, [FileSize] [int] NULL, [ImgNote] [text] NULL, [Confidential] [varchar](1) NULL, [TransDATE] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO create index byTableFieldID on Patient_data.dbo.tbDBImage(TableName,FieldName,IDKEY) GO create index byIDKey on Patient_data.dbo.tbDBImage(IDKEY) GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'SP_Bui_UpdateItem') EXEC ('CREATE PROC dbo.SP_Bui_UpdateItem AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[SP_Bui_UpdateItem] (@RevenueID as varchar(2), @ItemID as varchar(5), @SectionID as varchar(3), @ExamName as varchar(45), @RateA as float, @RateB as Float, @RateC as float, @RateD as float, @RateE as float, @RateF as Float, @RateG as Float, @RateH as Float, @Fixrate as varchar(1), @Status as varchar(1), @MedicareType as varchar(1), @common as varchar(1), @RateSD as float=0.00, @IsSenior as bit, @IsSpecial as bit, @AccountCode as varchar(12), @KidneyActive as varchar(1), @DRActive as varchar(1), @HSActive as varchar(1), @ERActive as varchar(1), @ICUActive as varchar(1), @PICUActive as varchar(1), @ORActive as varchar(1), @NurseryActive as varchar(1), @NurseActive as varchar(1), @OPDActive as varchar(1), @PulmoActive as varchar(1), @PTActive as varchar(1), @MedRecActive as varchar(1), @NuclearActive as varchar(1), @SICUActive as varchar(1), @CCUActive as varchar(1), @WCActive as varchar(1), @EndoActive as varchar(1), @EyeActive as varchar(1), @CathLabActive as varchar(1), @rateI as float = 0) as If (@RevenueID = 'AU') update build_file..tbcoaudexam set AudSectionID=@SectionID, AudExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where audexamid = @itemid else If (@RevenueID = 'CT') update build_file..tbcoctexam set CTSectionID=@SectionID, CTExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where ctexamid = @itemid else If (@RevenueID = 'HS') update build_file..tbcohsexam set HSSectionID=@SectionID, HSExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where hsexamid = @itemid If (@RevenueID = 'LB') update build_file..tbcolabexam set LABSectionID=@SectionID, LABExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where LABexamid = @itemid else If (@RevenueID = 'NU') update build_file..tbconucexam set NUCSectionID=@SectionID, NUCExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where NUCexamid = @itemid else If (@RevenueID = 'PT') update build_file..tbcoptexam set PTSectionID=@SectionID, PTExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where PTexamid = @itemid else If (@RevenueID = 'PA') update build_file..tbcortsexam set RTSSectionID=@SectionID, RTSExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where RTSexamid = @itemid else If (@RevenueID = 'US') update build_file..tbcoultraexam set ULTRASectionID=@SectionID, ULTRAExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where ULTRAexamid = @itemid else If (@RevenueID = 'XR') update build_file..tbcoxrayexam set XRAYSectionID=@SectionID, XRAYExam=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, rateI=@rateI where XRAYexamid = @itemid else Update tbcootherrevenue set OtherRevenue=@ExamName, RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, Fixrate=@Fixrate, Status=@Status, MedicareType=@MedicareType, common=@common, RateSD=@RateSD, IsSenior=@IsSenior, IsSpecial=@IsSpecial, AccountCode=@AccountCode, KidneyActive=@KidneyActive, DRActive=@DRActive, HSActive=@HSActive, ERActive=@ERActive, ICUActive=@ICUActive, PICUActive=@PICUActive, ORActive=@ORActive, NurseryActive=@NurseryActive, NurseActive=@NurseActive, OPDActive=@OPDActive, PulmoActive=@PulmoActive, PTActive=@PTActive, MedRecActive=@MedRecActive, NuclearActive=@NuclearActive, SICUActive=@SICUActive, CCUActive=@CCUActive, WCActive=@WCActive, EndoActive=@EndoActive, EyeActive=@EyeActive, CathLabActive=@CathLabActive, rateI=@rateI where otherrevenueid = @itemid and othersectionid = @revenueid alter table build_file..tbcoroomamenities add Quantity int null go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Bui_RoomAmenities') EXEC ('CREATE PROC dbo.sp_Bui_RoomAmenities AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER procedure [dbo].[sp_Bui_RoomAmenities] @RoomID as varchar(10), @AmenityID as varchar(10), @Status as bit, @Quantity as int as IF (Exists(Select AmenityID from Build_file..tbCoRoomAmenities Where AmenityID=@AmenityID and RoomID=@RoomID)) begin update build_file..tbcoRoomAmenities set RoomID=@RoomID, AmenityID=@AmenityID, Status=@Status, Quantity=@Quantity where AmenityID=@AmenityID and RoomID=@RoomID end; else begin insert into build_file..tbcoroomAmenities (RoomID,AmenityID,Status,Quantity) values (@RoomID,@AmenityID,@Status,@Quantity) end; go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Bui_BatchUpdate') EXEC ('CREATE PROC dbo.sp_Bui_BatchUpdate AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER procedure [dbo].[sp_Bui_BatchUpdate] @RevenueID as varchar(2), @ItemID as varchar(5), @RateA as float, @RateB as Float, @RateC as float, @RateD as float, @RateE as float, @RateF as float, @RateG as float, @RateH as float, @RateI as float, @RateSD as float = 0.00 AS If (@RevenueID = 'AU') Update tbcoaudexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH where audexamid = @itemid else If (@RevenueID = 'CT') Update tbcoctexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateSD = @RateSD where ctexamid = @itemid else If (@RevenueID = 'HS') Update tbcohsexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH where hsexamid = @itemid else If (@RevenueID = 'LB') Update tbcolabexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH where labexamid = @itemid else If (@RevenueID = 'NU') Update tbconucexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH where nucexamid = @itemid else If (@RevenueID = 'PT') Update tbcoptexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateSD = @RateSD where ptexamid = @itemid else If (@RevenueID = 'PA') Update tbcortsexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateI=@RateI where rtsexamid = @itemid else If (@RevenueID = 'US') Update tbcoultraexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateI=@RateI, RateSD = @RateSD where ultraexamid = @itemid else If (@RevenueID = 'XR') Update tbcoxrayexam set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateI=@RateI, RateSD = @RateSD where xrayexamid = @itemid else Update tbcootherrevenue set RateA=@RateA, RateB=@RateB, RateC=@RateC, RateD=@RateD, RateE=@RateE, RateF=@RateF, RateG=@RateG, RateH=@RateH, RateI=@RateI where otherrevenueid = @itemid and othersectionid = @revenueid alter table TbBuildUserSettings add sShowUserValidation bit null GO alter table TbBuildUserSettings add sRoomStatus bit null GO alter table TbBuildUserSettings add sDeposittype bit null GO alter table TbBuildUserSettings add sHospitalList bit null GO alter table TbBuildUserSettings add sICDCode bit null GO alter table TbBuildUserSettings add sCreditMemo bit null GO alter table TbBuildUserSettings add sCausesofConsultation bit null GO alter table TbBuildUserSettings add sHoliday bit null GO alter table TbBuildUserSettings add sShowUserValidation bit null go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'spBuild_UserSettingsNew') EXEC ('CREATE PROC dbo.spBuild_UserSettingsNew AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER Procedure [dbo].[spBuild_UserSettingsNew] @Employeeid as varchar(10) as SELECT isnull(EmployeeID, 0)EmployeeIDisnull, isnull(sCompany, 0)sCompany, isnull(sBussinessClass, 0) sBussinessClass, isnull(sDepartment, 0) sDepartment, isnull(sNationality, 0) sNationality, isnull(sAddress, 0) sAddress, isnull(sBarangay, 0) sBarangay, isnull(sReligion, 0)sReligion, isnull(sDoctor, 0)sDoctor, isnull(sRoom, 0)sRoom, isnull(sStation, 0)sStation, isnull(sRoomClass, 0)sRoomClass, isnull(sAccomodation, 0)sAccomodation, isnull(sDosage, 0)sDosage, isnull(sItemPackage, 0)sItemPackage, isnull(sRevenue, 0)sRevenue, isnull(sCharging, 0)sCharging, isnull(sAccounting, 0)sAccounting, isnull(sLabCode, 0)sLabCode, isnull(sLabSpecimen, 0)sLabSpecimen, isnull(sSection, 0)sSection, isnull(sService, 0)sService, isnull(sAddressRPT, 0)sAddressRPT, isnull(sDoctorsRPT, 0)sDoctorsRPT, isnull(sCompanyRPT, 0)sCompanyRPT, isnull(sRoomCodesRPT, 0)sRoomCodesRPT, isnull(sDepartmentsRPT, 0)sDepartmentsRPT, isnull(sBarangaysRPT, 0)sBarangaysRPT, isnull(sRvcRPT, 0)sRvcRPT, isnull(sRevExamRPT, 0)sRevExamRPT, isnull(sARCodesRPT, 0)sARCodesRPT, isnull(sGLChartCodesRPT, 0)sGLChartCodesRPT, isnull(sAccountingRPT, 0)sAccountingRPT, isnull(sDeptARCodeRPT, 0)sDeptARCodeRPT, isnull(sInterpretRPT, 0)sInterpretRPT, isnull(sRCCodesRPT, 0)sRCCodesRPT, isnull(sTelephoneRPT, 0)sTelephoneRPT, isnull(sMedicalSpecializationRPT, 0)sMedicalSpecializationRPT, isnull(sSurgicalCodeRPT, 0)sSurgicalCodeRPT, isnull(sDoctorProfFee, 0)sDoctorProfFee, isnull(sDiscountRate, 0)sDiscountRate, isnull(sCompanyRate, 0)sCompanyRate, isnull(sDocSpecialization, 0)sDocSpecialization, isnull(sSOP, 0)sSOP, isnull(sExePackage, 0)sExePackage, isnull(sUserLog, 0)sUserLog, isnull(sUserSetting, 0)sUserSetting, isnull(sForInfo, 0)sForInfo, isnull(sRoomStatus,0)sRoomStatus, isnull(sDeposittype, 0)sDepositType, isnull(sHospitalList,0)sHospitalList, isnull(sICDCode,0)sICDcode, isnull(sCreditMemo,0)sCreditMemo, isnull(sCausesofConsultation,0)sCausesofConsultation, isnull(sHoliday,0)sHoliday, isnull(sShowUserValidation , 0) sShowUserValidation FROM BUILD_FILE.dbo.TbBuildUserSettings where employeeid = @Employeeid go alter table build_file..tbcoroom add WithAmenities varchar(1) GO create table tbCoRoomAmenities ( RoomID varchar(10), AmenityID varchar(10), Status bit , Quantity int null ) GO create table tbCoAmenities ( AmenityID varchar(10), Amenity varchar (50) ) GO alter table register..tbupdatenumber alter column hospnum varchar(8) go use Patient_Data GO alter table tbmaster2 add PHICNum varchar(50) GO alter table tbmaster alter column CardNumber varchar(50) GO /****** changed b.cardnum to a.cardnum ******/ ALTER PROCEDURE [dbo].[sp_AOPD_LoadOutPatient] @IDNum as varchar(8) AS Select '' as dumm, isnull(a.lastname,'') + ', ' + isnull(a.firstname,'') + ' ' + isnull(a.middlename,'') as patientname, isnull(a.lastname,'') as LastName, isnull(a.firstname,'') as FirstName, isnull(a.middlename,'') as middlename, b.idnum, a.hospnum, (SELECT CASE WHEN b.ADMDATE IS NULL THEN '' ELSE b.ADMDATE END) AS ADMDATE, (SELECT CASE WHEN b.DCRDATE IS NULL THEN '' ELSE b.DCRDATE END) AS DCRDATE, b.OPDStatus, isnull(H.Weight,'') as Weight, isnull(h.Temperature,'') as Temperature, isnull(h.BloodPressure,'') as BloodPressure, isnull(a.bloodtype,'') as bloodtype, isnull(h.DiagnosisID1,'') as DiagnosisID1, isnull(h.DiagnosisID2,'') as DiagnosisID2, isnull(h.DiagnosisID3,'') as DiagnosisID3, isnull(h.findings,'') as Findings, isnull(h.medications,'') as medications, isnull(b.AccountNum,'') as AccountNum, isnull(b.Remarks,'') as Remarks, isnull(b.ServiceID2,'') as ServiceID2, isnull(b.ServiceID3,'') as ServiceID3, isnull(b.ServiceID4,'') as ServiceID4, isnull(b.ServiceID5,'') as ServiceID5, isnull(b.ServiceID1,'') as ServiceID1, isnull(b.DoctorID1,'') as DoctorID1, isnull(b.DoctorID2,'') as DoctorID2, isNull(b.hosPlan,'') as HospPlan, isnull(c.Company,'') as Company, isnull(b.ConsultationType,'') as ConsultationType, isnull(G.GuarantorName,'') as GuarantorName, isnull(G.GuarantorAddress,'') as GuarantorAddress, isnull(G.GuarantorEmployer,'') as GuarantorEmployer, isnull(G.GuarantorTelNum,'') as GuarantorTelNum, isnull(I.InformantName,'') as InformantName, isnull(I.InformantAddress,'') as InformantAddress, isnull(I.InformantRelation,'') as InformantRelation, isnull(I.InformantTelNum,'') as InformantTelNum, isnull(EmployerAddress,'') as GuarantorEmployerAddress, a.bloodtype as bloodtype, b.ADMDATE as AdmissionDate, b.PatientType as PatientType, b.ConType as ConType, cc.ChiefComplaintID as ChiefComplaintID1, CC.ChiefComplaint as ChiefComplaint1, cc2.ChiefComplaintID as ChiefComplaintID2, CC2.ChiefComplaint as ChiefComplaint2, cc3.ChiefComplaintID as ChiefComplaintID3, CC3.ChiefComplaint as ChiefComplaint3, isnull(b.paycode,'') as Paycode, isnull(a.CardNumber,'') as CardNumber, isnull(B.SeniorCitizen,'') as SeniorCitizenID, isnull(A.SeniorCitizenID,'') as SeniorCitizenIDNo, (b.pharmaSeniorDiscounted) as SeniorCitizen, isnull(b.PerUnit,'') PerUnit, isnull(b.CauseofConsultationID,'') as CauseofConsultationID, a.Age, dbo.fn_GetPatientCivilStatus(a.Hospnum) as CivilStatus, H.ChiefComplaints, isnull(H.Procedures,'') Procedures, isnull(H.Condition, '') Condition, isnull(H.RespiratoryRate, '') RespiratoryRate, isnull(H.AnesthesiaType, '') AnesthesiaType, isnull(B.DoctorID3, '') DoctorID3, isnull(B.OperationDate, getdate()) OperationDate, isnull(isWalkIn,0) isWalkIn, isnull(B.HMOApprovalNum,'') HMOApprovalNum, isnull(Jonelta,0) Jonelta, isnull(B.chiefcomplaintid1,'') as CauseofConsultationid1, isnull(CC.ChiefComplaint,'') as CauseofConsultation1, isnull(B.chiefcomplaintid2,'') as CauseofConsultationid2, isnull(CC2.ChiefComplaint,'') as CauseofConsultation2, isnull(B.chiefcomplaintid3,'') as CauseofConsultationid3, isnull(CC3.ChiefComplaint,'') as CauseofConsultation3, isnull(H.Height, '') as Height, isnull(H.PulseRate,'') as PulseRate, ----additional isnull(b.DoctorID3,'') as DoctorID3, isnull(b.DoctorID4,'') as DoctorID4, isnull(b.DoctorID5,'') as DoctorID5, ---isnull(b.Ismabrate,0) as isMabrate, isnull(B.HomeService,'N')as HomeService from tboutpatient b left outer join tbmaster a on b.hospnum = a.hospnum left outer join Build_File..tbCoCompany C on b.AccountNum = c.AccountNum left outer join tbOutPatientHistory H on b.IDNum=H.IDnum Left Outer Join tbPatientInformant I on b.IDNum = I.IDNum left Outer Join tbPatientGuarantor G on b.IDNum = G.IDNum left outer join BUILD_FILE..tbCoChiefComplaint CC on b.ChiefComplaintID1 = CC.ChiefComplaintID left outer join BUILD_FILE..tbCoChiefComplaint CC2 on b.ChiefComplaintID2 = CC2.ChiefComplaintID left outer join BUILD_FILE..tbCoChiefComplaint CC3 on b.ChiefComplaintID3 = CC3.ChiefComplaintID where b.IDNum = @IDNum GO ALTER PROCEDURE [dbo].[sp_AOPD_Load_TbMaster] @Hospnum as varchar(10) AS Select m.hospnum, isnull(m.lastname,'') as Lastname, isnull(m.firstname,'') as FirstName, isnull(m.middlename,'') as MiddleName, isnull(m.housestreet,'')as HouseStreet, isnull(m.barangay,'') as Barangay, m.Zipcode, (case when isnull(c.town,'') + ', ' + isnull(c.province,'') = ', ' then '' else isnull(c.town,'') + ', ' + isnull(c.province,'') End) as province, isnull(m.telnum,'') as TelNum, m.birthdate as BirthDate, isnull(m.sex,'') as Sex, isnull(m.age,0) as Age, isnull(m2.Employer,'') as Employer, isnull(m2.EmployerAddress,'') as EmployerAddress, isNull(m2.EmployerTelNum,'') as EmployerTelNum, M.CivilStatus , isnull(convert(varchar(10),m.GovDiscountExpiry,101),'') as GovDiscountExpiry, isNull(M.BloodType,'') [BloodType] , isNull(M2.BirthPlace,'') [BirthPlace], isNull(M.Occupation,'') [Occupation] , isNull(N.Nationality,'') [Nationality] , isNull(R.Religion,'') [Religion], isnull(M2.NationalityID,'') AS NationalityID, isnull(M2.ReligionID,'') AS ReligionID, isnull(M.Title,'') AS Title, SSSGSISNum, m2.phicnum from tbmaster m left outer join Build_File..tbcoaddress c on m.zipcode = c.zipcode left outer join tbMaster2 m2 on m.hospNum=m2.HospNum left outer join tbPatient P on m.HospNum=p.HospNum left outer join build_file..tbcoNationality N on N.NationalityID = M2.NationalityID left outer join build_file..tbcoReligion R on R.ReligionID = M2.ReligionID where m.hospnum = @HospNum GO create table tbOPD_UserLogin ( EmployeeID varchar(20) null, Remarks text null, LoginDate datetime null, LogOutDate datetime null, LogSequence float null ) set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_OPD_Search_User') EXEC ('CREATE PROC dbo.sp_OPD_Search_User AS SELECT 1') GO ALTER procedure [dbo].[sp_OPD_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 TbOPD_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 TbOPD_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 TbOPD_userlogin A left outer join password..tbpasswordmaster B on A.EmployeeID = B.EmployeeID set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'SP_OPD_UserLogin') EXEC ('CREATE PROC dbo.SP_OPD_UserLogin AS SELECT 1') GO ALTER procedure [dbo].[SP_OPD_UserLogin] @LogSequence as varchar(5), @EmployeeID as varchar(50), @Remarks as Text, @LogInDate as datetime, @LogOutDate as datetime As Declare @strRemarks as varchar(500); if Exists(Select * From patient_data..TbOPD_UserLogin Where EmployeeID = @EmployeeID and LogOutDate is null) Begin set @strRemarks = (Select top 1 Cast(Remarks as varchar(1000)) From TbOPD_UserLogin Where EmployeeID = @EmployeeID and LogOutDate is null) + ' Not Properly Logout' Update TbOPD_UserLogin set LogOutDate = getdate(), Remarks = @strRemarks Where EmployeeID = @EmployeeID and LogOutDate is null; End; If @LogoutDate = '' Begin Set @LogoutDate = Null End; insert into patient_data..TbOPD_UserLogin(LogSequence, EmployeeID, Remarks, LogInDate, LogOutDate) values(@LogSequence, @EmployeeID, @Remarks, GetDate(), @LogoutDate) set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_OPD_UpdateLogRemarks') EXEC ('CREATE PROC dbo.sp_OPD_UpdateLogRemarks AS SELECT 1') GO ALTER procedure [dbo].[sp_OPD_UpdateLogRemarks] @EmployeeID as varchar(10), @Remarks as text AS Update TbOPD_UserLogin Set Remarks = @Remarks Where EmployeeID = @EmployeeID and LogOutDate is null; set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'SP_OPD_UserLogin_Update') EXEC ('CREATE PROC dbo.SP_OPD_UserLogin_Update AS SELECT 1') GO ALTER procedure [dbo].[SP_OPD_UserLogin_Update] @EmployeeID as varchar(50) as Update patient_data..TbOPD_UserLogin Set LogoutDate = Getdate() Where EmployeeId= @EmployeeID and LogoutDate = null; go ------------------------------------------------------------- alter table patient_data..tbmaster2 add PHICNum varchar(50) null GO ------------------------------------------------------------- USE [Patient_Data] GO /****** Object: StoredProcedure [dbo].[sp_AOPD_Load_TbMaster] Script Date: 05/21/2012 12:55:59 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_AOPD_Load_TbMaster') EXEC ('CREATE PROC dbo.sp_sp_AOPD_Load_TbMaster AS SELECT 1') GO ALTER PROCEDURE [dbo].[sp_AOPD_Load_TbMaster] @Hospnum as varchar(10) AS Select m.hospnum, isnull(m.lastname,'') as Lastname, isnull(m.firstname,'') as FirstName, isnull(m.middlename,'') as MiddleName, isnull(m.housestreet,'')as HouseStreet, isnull(m.barangay,'') as Barangay, m.Zipcode, (case when isnull(c.town,'') + ', ' + isnull(c.province,'') = ', ' then '' else isnull(c.town,'') + ', ' + isnull(c.province,'') End) as province, isnull(m.telnum,'') as TelNum, m.birthdate as BirthDate, isnull(m.sex,'') as Sex, isnull(m.age,0) as Age, isnull(m2.Employer,'') as Employer, isnull(m2.EmployerAddress,'') as EmployerAddress, isNull(m2.EmployerTelNum,'') as EmployerTelNum, M.CivilStatus , isnull(convert(varchar(10),m.GovDiscountExpiry,101),'') as GovDiscountExpiry, isNull(M.BloodType,'') [BloodType] , isNull(M2.BirthPlace,'') [BirthPlace], isNull(M.Occupation,'') [Occupation] , isNull(N.Nationality,'') [Nationality] , isNull(R.Religion,'') [Religion], isnull(M2.NationalityID,'') AS NationalityID, isnull(M2.ReligionID,'') AS ReligionID, isnull(M.Title,'') AS Title, SSSGSISNum, m2.phicnum from tbmaster m left outer join Build_File..tbcoaddress c on m.zipcode = c.zipcode left outer join tbMaster2 m2 on m.hospNum=m2.HospNum left outer join tbPatient P on m.HospNum=p.HospNum left outer join build_file..tbcoNationality N on N.NationalityID = M2.NationalityID left outer join build_file..tbcoReligion R on R.ReligionID = M2.ReligionID where m.hospnum = @HospNum insert into patient_data..tbopdmenu (MenuID,Menu,Status,MenuGroup,MainMenu)values('81','User Logs','1','A','2') alter table Patient_data..tbHospitalInfo add OtherInfo text insert into patient_data..tbopdmenu (MenuID,Menu,Status,MenuGroup,MainMenu)values('82','User Validation','1','A','2') set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go alter table Patient_data..tbopd_settings add MarkUp bit go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'OPD_SaveOPDSettings') EXEC ('CREATE PROC dbo.OPD_SaveOPDSettings AS SELECT 1') GO ALTER Procedure [dbo].[OPD_SaveOPDSettings] @isAllowNewOPSTatRate varchar(1), @isAllowHolidayRate varchar(1), @isAllowAfterFivePMRate varchar(1), @isAllowWeekendRate varchar(1), @isAllowAfterFiveLabChemOnly varchar(1), @isAllowAfterFiveAllRevenues varchar(1), @OPDStatRate float, @HolidayRate float, @AfterFivePmRate float, @WeekendRate float, @MaxMarkUpRate float, @StatAndAfterFivePMRate float, @StatAndWeekendRate float, @HolidayAndWeekend float, @HolidayAndAfterFivePMRate float, @WeekendAfterFive float, @dtWeekendStartMarkUp smalldatetime, @dtWeekendEndMarkUp smalldatetime, @isAssessmentMarkUp as varchar(1), @isPostChargeMarkup as varchar(1), @dtWeekendStartMarkUp2 smalldatetime, @dtWeekendEndMarkUp2 smalldatetime, @MarkUp as bit as Select top 1 * from Patient_data..tbopd_settings; if @@rowcount > 0 begin Update Patient_data..tbOPd_settings set isAllowNewOPSTatRate = @isAllowNewOPSTatRate, isAllowHolidayRate = @isAllowHolidayRate, isAllowAfterFivePMRate = @isAllowAfterFivePMRate, isAllowWeekendRate = @isAllowWeekendRate, isAllowAfterFiveLabChemOnly = @isAllowAfterFiveLabChemOnly, isAllowAfterFiveAllRevenues = @isAllowAfterFiveAllRevenues, OPDStatRate = @OPDStatRate, HolidayRate = @HolidayRate, AfterFivePmRate = @AfterFivePmRate, WeekendRate = @WeekendRate, MaxMarkUpRate = @MaxMarkUpRate, StatAndAfterFivePMRate = @StatAndAfterFivePMRate, StatAndWeekendRate = @StatAndWeekendRate, HolidayAndWeekend = @HolidayAndWeekend, HolidayAndAfterFivePMRate = @HolidayAndAfterFivePMRate, WeekendAfterFive = @WeekendAfterFive, dtWeekendStartMarkUp = @dtWeekendStartMarkUp, dtWeekendEndMarkUp = @dtWeekendEndMarkUp, isAssesmentMarkup = @isAssessmentMarkUp, isPostChargeMarkUp = @isPostChargeMarkup, dtWeekendStartMarkUp2 = @dtWeekendStartMarkUp2, dtWeekendEndMarkUp2 = @dtWeekendEndMarkUp2, MarkUp = @MarkUp end else begin insert into patient_data..tbopd_settings( isAllowNewOPSTatRate, isAllowHolidayRate, isAllowAfterFivePMRate, isAllowWeekendRate, isAllowAfterFiveLabChemOnly, isAllowAfterFiveAllRevenues,OPDStatRate, HolidayRate, AfterFivePmRate, WeekendRate, MaxMarkUpRate, StatAndAfterFivePMRate, StatAndWeekendRate, HolidayAndWeekend, HolidayAndAfterFivePMRate, WeekendAfterFive, dtWeekendStartMarkUp, dtWeekendEndMarkUp, isAssesmentMarkup, isPostChargeMarkUp, dtWeekendStartMarkUp2,dtWeekendEndMarkUp2,MarkUp) values (@isAllowNewOPSTatRate, @isAllowHolidayRate, @isAllowAfterFivePMRate, @isAllowWeekendRate, @isAllowAfterFiveLabChemOnly, @isAllowAfterFiveAllRevenues,@OPDStatRate, @HolidayRate, @AfterFivePmRate, @WeekendRate, @MaxMarkUpRate, @StatAndAfterFivePMRate, @StatAndWeekendRate, @HolidayAndWeekend, @HolidayAndAfterFivePMRate, @WeekendAfterFive, @dtWeekendStartMarkUp, @dtWeekendEndMarkUp, @isAssessmentMarkUp,@isPostChargeMarkup,@dtWeekendStartMarkUp2,@dtWeekendEndMarkUp2,@MarkUp) end GO 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; GO Alter table Patient_data..tbAdmReportSetup add OtherNursingStatistics bit not null default(0) GO USE [Patient_Data] GO /****** Object: StoredProcedure [dbo].[sp_med_Certificate2] Script Date: 08/29/2012 17:35:13 ******/ SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[sp_med_Certificate2] @IDNum As VarChar(10), @RecordsID as Varchar(10) AS --DELETE tbMedrecCertificate; truncate table tbMedrecCertificate; --Delete tbMedRecCertificateDx; truncate table tbMedRecCertificateDx; INSERT tbMedrecCertificate(idnum,lastname,firstname,middlename,age,sex,civilstatus,nationality,housestreet, barangay,town,province,telnum,employer,admdate,dcrdate,drname,finaldiagnosis,procedures,occupation, remarks,PTR,License,[Service],RecordsOfficer,Disposition,DoctorTitle) Select Top 1 Patient.IDNum, Upper(isnull(Master.LastName,'')), Upper(isnull(Master.FirstName,'')), Upper(isnull(Master.MiddleName,'')), isnull(Patient.Age,0), Upper(Case isnull(Master.Sex,'') When 'F' Then 'female' Else 'male' End) AS Sex, Upper(Case isnull(Master.CivilStatus,'') When '0' Then 'child' When '1' Then 'single' When '2' Then 'married' When '3' Then 'widow' When '4' Then 'separated' When '5' Then 'divorced' Else '' End) AS CivilStatus, Upper(isnull(Nation.Nationality,'')), Upper(isnull(Master.HouseStreet,'')), Upper(isnull(Master.Barangay,'')), Upper(isnull(Town.Town,'')), Upper(isnull(Town.Province,'')), Upper(isnull(Master.TelNum,'')), Upper(isnull(Master2.Employer,'')), convert(varchar(25),Patient.AdmDate,107), Convert(varchar(25),Patient.DcrDate,107), Upper(RTrim(IsNull(Doctor.FirstName,'')) + ' ' + Case When RTrim(IsNull(Doctor.MiddleName,'')) = '' then '' Else Left(RTrim(IsNull(Doctor.MiddleName,'')),1) + '.' End + ' ' + RTrim(IsNull(Doctor.LastName,'')) + Replace(isnull(Doctor.Title,''), 'MD', '') ) As DrName,/* Convert(Varchar(8000),isnull(History.FinalDiagnosis,'')), Convert(Varchar(8000),isnull(History.Procedures,'')),*/ isnull(History.FinalDiagnosis,''), isnull(History.Procedures,''), Upper(isnull(Master.Occupation,'')), Upper(isnull(P2.Remarks,'')), Upper(isnull(Doctor.PTR,'')), Upper(isnull(Doctor.License,'')), Upper(isnull(Service.Service,'')), Upper(isnull(pass.LastName,'') + ', ' + isnull(pass.FirstName,'')) as recordOfficer, --Upper(Disposition.Disposition), Upper(Case Isnull(Patient.ResultID,'') When '1' then 'Recovered' When '2' then 'Improved' When '3' then 'Unimproved' When '4' then 'Died' When '5' then 'Check-up' End) Disposition, Upper(RTrim(IsNull(Doctor.FirstName,'')) + ' ' + Case When RTrim(IsNull(Doctor.MiddleName,'')) = '' then '' Else Left(RTrim(IsNull(Doctor.MiddleName,'')),1) + '.' End + ' ' + RTrim(IsNull(Doctor.LastName,'')) + Case when isnull(Doctor.Title,'') = '' then ', M.D.' Else ', ' + isnull(Doctor.Title,'') End ) As DrName FROM Patient_Data..tbPatient Patient Left Outer Join Patient_Data..tbMaster Master On Patient.HospNum = Master.HospNum Left Outer Join Patient_Data..tbPatient2 P2 On Patient.IdNum=P2.IdNum Left Outer Join Patient_Data..tbMaster2 Master2 on Patient.HospNum = Master2.HospNum Left Outer Join Build_File..tbCoNationality Nation On Master2.NationalityID = Nation.NationalityID Left Outer Join Build_File..tbCoAddress Town On Master.ZipCode = Town.ZipCode Left Outer Join Build_File..tbCoDoctor Doctor On Patient.AttendingDr1 = Doctor.DoctorID Left Outer Join Patient_Data..tbPatientHistory History On Patient.IDNum = History.IDNum Left Outer Join Build_File..tbCoService Service on Patient.ServiceID= Service.ServiceID Left Outer Join Password..tbPasswordMaster Pass on Pass.EmployeeID = @RecordsID Left Outer Join Build_File..tbCoDisposition Disposition On Patient.DispositionID = Disposition.DispositionID Where Patient.IDNum = @IDNum; If Exists(Select IdNum from tbPatientHistory Where IdNum = @IDNum and not Procedures is null) Begin Insert into tbMedRecCertificateDx Select @IDNum, 'B', Procedures from tbPatientHistory Where IdNum = @IDNum; End Else Begin Insert into tbMedRecCertificateDx Values(@IDNum, 'B', 'No operation done.'); End; If Exists(Select IdNum from tbPatientHistory Where IdNum = @IDNum and not FinalDiagnosis is null) Begin Insert into tbMedRecCertificateDx Select @IDNum, 'A', FinalDiagnosis from tbPatientHistory Where IdNum = @IDNum; End Else Begin Insert into tbMedRecCertificateDx Values(@IDNum, 'A', 'No Final Diagnosis'); End; If Exists(Select IdNum from tbPatientHistory Where IdNum = @IDNum and not Remarks is null) Begin Insert into tbMedRecCertificateDx Select @IDNum, 'C', Remarks from tbPatientHistory Where IdNum = @IDNum; End Else Begin Insert into tbMedRecCertificateDx Values(@IDNum, 'C', 'No Remarks'); End; GO USE SCHEDULE SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORSchedules]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORSchedules]( [Name] [varchar](100) NULL, [ORRoomID] [int] NULL, [Surgeon] [varchar](10) NULL, [Anesthesiologist] [varchar](4) NULL, [ScheduleDate] [datetime] NULL, [IDNum] [varchar](10) NULL, [HospNum] [varchar](10) NULL, [RecordStatus] [varchar](1) NULL CONSTRAINT [DF__tbORSched__Recor__7E02B4CC] DEFAULT (''), [RequestBy] [varchar](30) NULL, [RequestDate] [datetime] NULL, [Remarks] [text] NULL, [TransNum] [int] IDENTITY(1,1) NOT NULL, [CNurse] [varchar](50) NULL, [SNurse1] [varchar](50) NULL, [SNurse2] [varchar](50) NULL, [AsstSurgeon1] [varchar](50) NULL, [AsstSurgeon2] [varchar](50) NULL, [AsstAnesth1] [varchar](50) NULL, [ProcedureName] [varchar](500) NULL, [RoomID] [varchar](10) NULL, [ProcessBy] [varchar](50) NULL, [ProcessDate] [datetime] NULL, [RevokeBy] [varchar](50) NULL, [RevokeDate] [datetime] NULL, [AsstDoctorID] [varchar](50) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORApplication]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORApplication]( [StartTime] [datetime] NULL, [DayLength] [int] NULL, [ScheduleIncrement] [int] NULL, [RoomID] [int] NULL ) ON [PRIMARY] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORCategory]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORCategory]( [CategoryId] [int] NOT NULL, [CategoryName] [varchar](20) NULL, [Color] [int] NULL, [SortOrder] [int] NULL ) ON [PRIMARY] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORRoom]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORRoom]( [RoomId] [int] NOT NULL, [RoomName] [varchar](20) NULL, [SortOrder] [int] NULL, [RevenueID] [varchar](4) NULL ) ON [PRIMARY] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORSchedule]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORSchedule]( [ScheduleId] [int] NOT NULL, [ScheduleDate] [datetime] NULL ) ON [PRIMARY] END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbORScheduleDetails]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[tbORScheduleDetails]( [ScheduleId] [int] NULL, [RowId] [int] NULL, [RoomId] [int] NULL, [StartTime] [datetime] NULL, [Length] [int] NULL, [Description] [varchar](500) NULL, [ProcedureID] [varchar](8) NULL, [DoctorID1] [varchar](10) NULL, [DoctorID2] [varchar](10) NULL, [CategoryId] [int] NULL, [ScheduleDate] [datetime] NULL, [IDNum] [varchar](10) NULL, [HospNum] [varchar](10) NULL, [RecordStatus] [varchar](1) NULL CONSTRAINT [DF_tbORScheduleDetails_RecordStatus] DEFAULT (''), [RequestBy] [varchar](50) NULL, [RequestDate] [datetime] NULL, [ProcessBy] [varchar](50) NULL, [ProcessDate] [datetime] NULL, [StationID] [varchar](10) NULL, [ResidentDoctor] [varchar](100) NULL, [Remarks] [text] NULL, [TransNum] [int] IDENTITY(1,1) NOT NULL, [CNurse] [varchar](10) NULL, [SNurse1] [varchar](100) NULL, [SNurse2] [varchar](100) NULL, [AsstSurgeon1] [varchar](100) NULL, [AsstSurgeon2] [varchar](100) NULL, [AsstAnesth1] [varchar](100) NULL, [ProcedureName] [varchar](500) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] END GO USE STATION SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchORStaff]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE Procedure [dbo].[SearchORStaff] --declare @SearchCriteria varchar(15) --set @SearchCriteria = ''sar'' AS SElect DISTINCT employeeid AS CODE,isnull(lastname,'''') + '' ,'' +isnull(firstname,'''') + '' '' + isnull(middlename,'''') AS [OR STAFF] from PASSWORD..tbpasswordmain AS tbpasswordmain where originaldepartment = ''29'' and lastname like @SearchCriteria +''%'' order by [OR STAFF] -- or employeeid = ''SA'') order by [OR STAFF] ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_TransactionDate]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Get_TransactionDate] AS Select GETDATE() AS TDATE ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Reindex_DBase]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Reindex_DBase] AS Declare All_Tables cursor for select name from sysobjects where objectproperty(id, ''IsTable'') = 1 AND name LIKE ''tb%''; Declare @strTable as varchar(100); Open All_Tables; Fetch Next from All_Tables Into @strTable; Dbcc dbreindex(@strTable); Begin Transaction While @@Fetch_Status = 0 Begin Fetch Next from All_Tables Into @strTable; Dbcc dbreindex(@strTable); end; If @@error <> 0 Begin goto Abort_Save; End; Commit Transaction; Close All_Tables; Deallocate All_Tables; Return 0; Abort_Save: Rollback Transaction; Return -10001; ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_UpdateSchedules]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE Procedure [dbo].[sp_UpdateSchedules] @Status as varchar(1), @ProcessID as varchar(10), @TransNum as varchar(5) As If @Status = ''C'' Begin Update Schedule..tbOrSchedules Set RecordStatus = @Status, ProcessBy = @ProcessID, ProcessDate = getdate() Where TransNum = @TransNum End Else Begin Update Schedule..tbOrSchedules Set RecordStatus = @Status, RevokeBy = @ProcessID, RevokeDate = getdate() Where TransNum = @TransNum End ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_List_Of_ConfirmedSchedules_New]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE Procedure [dbo].[sp_List_Of_ConfirmedSchedules_New] -- AS declare @DateToday as varchar(10) Set @DateToday = (Select convert(varchar(10),getdate(),101)) Select Distinct [TIME], case when Surgeon = ''DR. '' then '''' else surgeon end SURGEON, case when Anesthesiologist = ''DR. '' then '''' else Anesthesiologist end ANESTHESIOLOGIST, PATIENTNAME,ROOM,PROCEDURENAME, case when ASSTDOCTOR = ''DR. '' then '''' else ASSTDOCTOR end ASSTDOCTOR, case when ltrim(rtrim(CNurse)) = '''' then '''' else CNurse end CNURSE, case when ltrim(rtrim(SNurse)) = '''' then '''' else SNurse end SNURSE, ORROOM,[Status],[Transnum],TransNum,ScheduleDate From ( Select Distinct Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(Isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' + Max(Isnull(tbCoDoctor2.LastName,'''')) as Anesthesiologist, Max(Isnull([Name],'''')) as PatientName, -- Convert(varchar(20),Details.Scheduledate,0) as [SCHEDULEDATE/TIME], Max(Isnull(Details.RoomID,'''')) as Room, Max(Isnull(Details.Procedurename,'''')) as ProcedureName, Max(Isnull(tbPasswordMaster.lastname,''''))+'', ''+ Max(Isnull(Upper(Substring(tbPasswordMaster.FirstName,1,1)),'''')) as CNurse, Max(Isnull(tbPasswordMaster2.lastname,''''))+'', ''+ Max(Isnull(Upper(Substring(tbPasswordMaster2.FirstName,1,1)),'''')) as SNurse, Max(Isnull(Details.OrRoomID,'''')) as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Max(Isnull(ScheduleDate,'''')) as ScheduleDate, ''DR. '' + Max(Isnull(tbCoDoctorAsst.LastName,'''')) as AsstDoctor From Schedule..tbOrSchedules Details -- Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum -- Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum -- Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Password..tbPasswordMaster tbPasswordMaster On Details.CNurse = tbPasswordMaster.EmployeeID Left Outer Join Password..tbPasswordMaster tbPasswordMaster2 On Details.SNurse1 = tbPasswordMaster2.EmployeeID Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.Surgeon = tbCoDoctor.DoctorID --SURGEON(MAIN) Left Outer Join Build_File..tbCoDoctor tbCoDoctor2 On Details.Anesthesiologist = tbCoDoctor2.DoctorID --ANEST(MAIN) Left Outer Join Build_File..tbCoDoctor tbCoDoctorAsst On Details.AsstDoctorID = tbCoDoctorAsst.DoctorID --ANEST(MAIN) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.Transnum--,Details.RoomID,Details.ORRoomID UNION ALL Select Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' + Max(isnull(tbCoDoctor2.LastName,'''')) as Anesthesiologist, Max(isnull([Name],'''')) as PatientName, -- Convert(varchar(20),Details.Scheduledate,0) as [SCHEDULEDATE/TIME], Max(Isnull(Details.RoomID,'''')) as Room, Max(isnull(Details.Procedurename,'''')) as ProcedureName, '''' as CNurse, Max(isnull(tbPasswordMaster2.lastname,''''))+'', ''+ Max(isnull(Upper(Substring(tbPasswordMaster2.FirstName,1,1)),'''')) as SNurse, Max(Isnull(Details.ORRoomID,'''')) as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Max(Isnull(ScheduleDate,'''')) as ScheduleDate, '''' as AsstDoctor From Schedule..tbOrSchedules Details -- Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum -- Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum -- Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Password..tbPasswordMaster tbPasswordMaster2 On Details.SNurse2 = tbPasswordMaster2.EmployeeID Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.AsstSurgeon1 = tbCoDoctor.DoctorID --SURGEON(ASST1) Left Outer Join Build_File..tbCoDoctor tbCoDoctor2 On Details.AsstAnesth1 = tbCoDoctor2.DoctorID --ANEST(ASST1) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.TransNum--,Details.RoomID,Details.ORRoomID UNION ALL --Surgeon3,'''' Select Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(Isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' as Anesthesiologist, Max(isnull([Name],'''')) as PatientName, Max(Isnull(Details.RoomID,'''')) as Room, Max(isnull(Details.Procedurename,'''')) as ProcedureName, '''' as CNurse, '''' as SNurse, Max(Isnull(Details.ORRoomID,'''')) as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Max(Isnull(ScheduleDate,'''')) as ScheduleDate, '''' as AsstDoctor From Schedule..tbOrSchedules Details -- Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum -- Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum --Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.AsstSurgeon2 = tbCoDoctor.DoctorID --SURGEON(ASST2) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.TransNum--,Details.RoomID,Details.ORRoomID )z where surgeon <> ''dr. '' --and anesthesiologist <> ''dr. '' --and SNurse <> '''' Order by ScheduleDate,PatientName,Transnum ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE Procedure [dbo].[sp_GetORSchedule] AS declare @DateToday as varchar(10) Set @DateToday = (Select convert(varchar(10),getdate(),101)) Select [Name], ProcedureName, -- ORRoom.RoomName as Room, OrSchedules.RoomID as RoomID, OrSchedules.ORRoomID as Room, OrSchedules.Surgeon as SurgeonID, DoctorS.LastName+'', ''+ DoctorS.FirstName as Surgeon, OrSchedules.Anesthesiologist as AnesthesiologistID, DoctorA.LastName+'', ''+ DoctorA.FirstName as Anesthesiologist, -- ScheduleDate, convert(varchar(20),scheduledate,0) as ScheduleDate, Remarks, TransNum, CNurse as CNurseID, CNurse.LastName+'', ''+CNurse.FirstName as CNurse, SNurse1 as SNurseID1, SNurse1.LastName+'', ''+SNurse1.FirstName as SNurse1, SNurse2 as SNurseID2, SNurse2.LastName+'', ''+SNurse2.FirstName as SNurse2, AsstSurgeon1 as AsstSurgeonID1, DoctorS1.LastName+'', ''+DoctorS1.FirstName as AsstSurgeon1, AsstSurgeon2 as AsstSurgeonID2, DoctorS2.LastName+'', ''+DoctorS2.FirstName as AsstSurgeon2, AsstAnesth1 as AsstAnesthID1, DoctorA1.LastName+'', ''+DoctorA1.FirstName as AsstAnesthesiologist, AsstDoctorID as AsstDoctorID, DoctorAsst.LastName+'', ''+DoctorAsst.FirstName as AssistantDoctor, OrRoom.RoomName as Room, OrSchedules.RecordStatus as Status From Schedule..tbOrSchedules OrSchedules -- Left Outer Join Schedule..tbORRoom ORRoom on OrSchedules.RoomID = ORRoom.RoomID --SURGEON Left Outer join BUILD_FILE..tbcoDoctor as DoctorS on OrSchedules.Surgeon = DoctorS.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorS1 on OrSchedules.AsstSurgeon1 = DoctorS1.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorS2 on OrSchedules.AsstSurgeon2 = DoctorS1.doctorid --ANESTHESIOLOGIST Left Outer join BUILD_FILE..tbcoDoctor as DoctorA on OrSchedules.Anesthesiologist = DoctorA.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorA1 on OrSchedules.AsstAnesth1 = DoctorA1.doctorid --SCRUB NURSE Left Outer join PASSWORD..tbPasswordMaster as SNurse1 on OrSchedules.SNurse1 = SNurse1.EmployeeID Left Outer join PASSWORD..tbPasswordMaster as SNurse2 on OrSchedules.SNurse2 = SNurse2.EmployeeID --CIRCULATING NURSE Left Outer join PASSWORD..tbPasswordMaster as CNurse on OrSchedules.CNurse = CNurse.EmployeeID --ASSISTANT DOCTOR Left Outer join BUILD_FILE..tbcoDoctor as DoctorAsst on OrSchedules.AsstDoctorID = DoctorAsst.DoctorID LEft Outer Join Schedule..tbOrROom as OrRoom On OrSchedules.OrRoomID = OrRoom.RoomID Where OrSchedules.Scheduledate > = @DateToday --between @DateToday and @DateToday + '' 23:59:59.99'' Order by [Name] ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_ORSchedule_List]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE Procedure [dbo].[sp_Get_ORSchedule_List] --Declare @TransNum varchar(10) --set @Transnum = 1 AS Select [Name], ProcedureName, OrSchedules.RoomID, ORRoom.RoomName, OrSchedules.Surgeon as SurgeonID, DoctorS.LastName+'', ''+ DoctorS.FirstName as Surgeon, OrSchedules.Anesthesiologist as AnesthesiologistID, DoctorA.LastName+'', ''+ DoctorA.FirstName as Anesthesiologist, ScheduleDate, Remarks, TransNum, CNurse as CNurseID, CNurse.LastName+'', ''+CNurse.FirstName as CNurse, SNurse1 as SNurseID1, SNurse1.LastName+'', ''+SNurse1.FirstName as SNurse1, SNurse2 as SNurseID2, SNurse2.LastName+'', ''+SNurse2.FirstName as SNurse2, AsstSurgeon1 as AsstSurgeonID1, DoctorS1.LastName+'', ''+DoctorS1.FirstName as AsstSurgeon1, AsstSurgeon2 as AsstSurgeonID2, DoctorS2.LastName+'', ''+DoctorS2.FirstName as AsstSurgeon2, AsstAnesth1 as AsstAnesthID1, DoctorA1.LastName+'', ''+DoctorA1.FirstName as AsstAnesthesiologist From Schedule..tbOrSchedules OrSchedules Left Outer Join Schedule..tbORRoom ORRoom on OrSchedules.RoomID = ORRoom.RoomID --SURGEON Left Outer join BUILD_FILE..tbcoDoctor as DoctorS on OrSchedules.Surgeon = DoctorS.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorS1 on OrSchedules.AsstSurgeon1 = DoctorS1.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorS2 on OrSchedules.AsstSurgeon2 = DoctorS1.doctorid --ANESTHESIOLOGIST Left Outer join BUILD_FILE..tbcoDoctor as DoctorA on OrSchedules.Anesthesiologist = DoctorA.doctorid Left Outer join BUILD_FILE..tbcoDoctor as DoctorA1 on OrSchedules.AsstAnesth1 = DoctorA1.doctorid --SCRUB NURSE Left Outer join PASSWORD..tbPasswordMaster as SNurse1 on OrSchedules.SNurse1 = SNurse1.EmployeeID Left Outer join PASSWORD..tbPasswordMaster as SNurse2 on OrSchedules.SNurse2 = SNurse2.EmployeeID --CIRCULATING NURSE Left Outer join PASSWORD..tbPasswordMaster as CNurse on OrSchedules.CNurse = CNurse.EmployeeID Where TransNum = @Transnum ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Save_OR_Schedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE Procedure [dbo].[Save_OR_Schedule] @Name as varchar(100), @ORRoomID as varchar(1), @Surgeon as varchar(10), @Anesthesiologist as varchar(10), @ScheduleDate as datetime, @RequestBy as varchar(10) = NULL, @Remarks as varchar(100) = NULL, @CNurse as varchar(10) = NULL, @SNurse1 as varchar(10) = NULL, @SNurse2 as varchar(10) = NULL, @AsstSurgeon1 as varchar(10) = NULL, @AsstSurgeon2 as varchar(10) = NULL, @AsstAnesth1 as varchar(10) = NULL, @ProcedureName as varchar(100) = NULL, @RoomID as varchar(50) = NULL, @RequestDate datetime, @TransNum as varchar(5) = NULL, @AsstDocID as varchar(8) = NULL, @RecordStatus as varchar(1) = NULL AS if not exists (Select TransNum From Schedule..tbOrSchedules where Transnum = @Transnum) Insert into Schedule..tbOrSchedules([Name], ORRoomID,Surgeon,Anesthesiologist,ScheduleDate,RequestBy,Remarks,CNurse,SNurse1,SNurse2,AsstSurgeon1,AsstSurgeon2,AsstAnesth1,ProcedureName,RoomID,RequestDate,AsstDoctorID) Values(@Name, @ORRoomID, @Surgeon, @Anesthesiologist, @ScheduleDate,@RequestBy,@Remarks,@CNurse,@SNurse1,@SNurse2,@AsstSurgeon1,@AsstSurgeon2,@AsstAnesth1,@ProcedureName,@RoomID,@RequestDate,@AsstDocID) else Update Schedule..tbOrSchedules set --[Name], ORRoomID = @ORRoomID, Surgeon = @Surgeon, Anesthesiologist = @Anesthesiologist, ScheduleDate = @ScheduleDate, Remarks = @Remarks, CNurse = @CNurse, SNurse1 = @SNurse1, SNurse2 = @SNurse2, AsstSurgeon1 = @AsstSurgeon1, AsstSurgeon2 = @AsstSurgeon2, AsstAnesth1 = @AsstAnesth1, ProcedureName = @ProcedureName, RoomID = @RoomID, AsstDoctorID = @AsstDocID Where TransNum = @TransNum ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Update_ScheduleParameters]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_Update_ScheduleParameters] @Daylength as integer, @ScheduleIncrement as integer AS BEGIN Update tbORApplication Set Daylength = @Daylength, ScheduleIncrement = @ScheduleIncrement ; END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_AddORRoom]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_AddORRoom] @RoomName AS Varchar(20) AS Declare @RoomID AS INT BEGIN Select @RoomID = RoomID from tbORApplication ; Update tbORApplication Set RoomID = RoomID +1 ; Insert tbORRoom (RoomID,RoomName,RevenueID) Values (@RoomID,@RoomName,''OR''); END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_ORCategory]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Get_ORCategory] @CategoryName AS Varchar(20) AS Select * from tbORCategory where CategoryName = @CategoryName ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GET_ORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_GET_ORSchedule] @Report AS Varchar(10) AS /*SELECT tbORSchedule.ScheduleId, tbORSchedule.ScheduleDate, tbORScheduleDetails.RowId, tbORScheduleDetails.StartTime, tbORScheduleDetails.Length, tbORScheduleDetails.Description, tbORRoom.RoomName AS RoomName, tbORCategory.CategoryName AS CategoryName FROM tbORCategory RIGHT JOIN (tbORSchedule INNER JOIN (tbORScheduleDetails INNER JOIN tbORRoom ON tbORScheduleDetails.RoomId = tbORRoom.RoomId) ON tbORSchedule.ScheduleId = tbORScheduleDetails.ScheduleId) ON tbORCategory.CategoryId = tbORScheduleDetails.CategoryId Where tbORSchedule.ScheduleDate >= @Report and tbORSchedule.ScheduleDate <= @Report +'' 11:59:59 PM''*/ SELECT tbORScheduleDetails.ScheduleId, tbORScheduleDetails.ScheduleDate, tbORScheduleDetails.RowId, tbORScheduleDetails.StartTime, tbORScheduleDetails.Length, tbORScheduleDetails.Description, tbORRoom.RoomName AS RoomName, tbORCategory.CategoryName AS CategoryName FROM tbORScheduleDetails LEFT OUTER JOIN tbORRoom ON tbORScheduleDetails.RoomId = tbORRoom.RoomId LEFT OUTER JOIN tbORCategory ON tbORCategory.CategoryId = tbORScheduleDetails.CategoryId Where (tbORScheduleDetails.ScheduleDate >= @Report and tbORScheduleDetails.ScheduleDate <= @Report +'' 11:59:59 PM'') and tbORScheduleDetails.RecordStatus = ''C'' or tbORScheduleDetails.RecordStatus = ''X'' ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_ORRoom]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Get_ORRoom] @RoomName AS Varchar(20) AS Select * from tbORRoom where Roomname = @RoomName ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_UpdateORRoom]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_UpdateORRoom] @RoomName AS Varchar(20), @RoomID AS int AS BEGIN Update SCHEDULE..tbORRoom Set Roomname = @RoomName Where roomid = @RoomID END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_List_ORRooms]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_List_ORRooms] AS SELECT distinct ROOMID AS [ROOMID],ROOMNAME AS [ROOM NAME] FROM TBORROOM WHERE RevenueID =''OR'' ORDER BY [ROOMID],[ROOM NAME] ' END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Revoke_Confirmed_ORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Revoke_Confirmed_ORSchedule] @IDNum as varchar(10), @ProcedureID as varchar(4), @UserID as varchar(10) AS BEGIN Update tbORScheduleDetails Set RecordStatus ='''', ProcessBy = @UserID, ProcessDate = Getdate() Where IDNum = @IDNum and ProcedureId = @ProcedureId and RecordStatus =''C'' END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Revoke_ORSchedule_Request]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Revoke_ORSchedule_Request] @IDNum as varchar(10), @ProcedureID as varchar(5), @UserID as varchar(10), @TransNum As Int =0 AS BEGIN Update tbORScheduleDetails Set RecordStatus =''R'', ProcessBy = @UserID, ProcessDate = Getdate() Where TransNum = @Transnum and Isnull(RecordStatus,'''') =''''; --IDNum = @IDNum and ProcedureId = @ProcedureId and RecordStatus ='''' END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Save_ORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Save_ORSchedule] @RoomID as integer, @StartTime as datetime, @Length as integer, @Description as varchar(250), @ScheduleDate as datetime, @IDNum as varchar(10), @RequestBy as varchar(8) AS BEGIN Insert tbORScheduleDetails (RoomID,StartTime,Length,Description,ScheduleDate,IDNum,RequestBy,RequestDate) Values (@RoomID,@StartTime,@Length,@Description,@ScheduleDate,@IDNum,@RequestBy,Getdate()) END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Save_RequestORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Save_RequestORSchedule] @StartTime as datetime, @Description as varchar(250), @ScheduleDate as datetime, @IDNum as varchar(10), @RequestBy as varchar(8), @ProcedureID as varchar(8), @DoctorID1 as varchar(4), @DoctorID2 as varchar(4), @HospNum as varchar(10), @StationID As varchar(10), @Remarks As Text = NULL, @CNurse As varchar(10)= NULL, @SNurse1 As varchar(10)= NULL, @SNurse2 As varchar(10)= NULL, @AsstSurgeon1 As varchar(10)= NULL, @AsstSurgeon2 As varchar(10)= NULL, @AsstAnesth1 As varchar(10)= NULL, @ProcedureName As Varchar(100) = NULL AS BEGIN Insert tbORScheduleDetails (StartTime,Description,ScheduleDate,IDNum,RequestBy,RequestDate,ProcedureID,DoctorID1,DoctorID2,HospNum,StationId,Remarks,CNurse,SNurse1,SNurse2,AsstSurgeon1,AsstSurgeon2,AsstAnesth1,ProcedureName) Values (@StartTime,@Description,@ScheduleDate,@IDNum,@RequestBy,Getdate(),@ProcedureID,@DoctorID1,@DoctorID2,@HospNum,@StationID,@Remarks,@CNurse,@SNurse1,@SNurse2,@AsstSurgeon1,@AsstSurgeon2,@AsstAnesth1,@Procedurename) END ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Update_ORSchedule_Request]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Update_ORSchedule_Request] @RoomID as integer, @Length as integer, @Description as varchar(250)/*, @ScheduleDate as datetime*/, @IDNum as varchar(10), @ProcedureID as varchar(5), @UserID as varchar(10), @SurgeonID As Varchar(10)=NULL, @AnestheID As Varchar(10)=NULL, @Transnum As Int=0 AS BEGIN Update tbORScheduleDetails Set RoomID = @RoomID, Length = @Length, Description = @Description, ProcessBy = @UserID, ProcessDate = GETDATE(), RecordStatus =''C'', DoctorID1 = Case Isnull(@SurgeonID,'''') When '''' then DoctorID1 Else @SurgeonID End, DoctorID2 = Case Isnull(@AnestheID,'''') When '''' then DoctorID1 Else @AnestheID End Where TransNum = @Transnum; --IDNum = @IDNum and ProcedureId = @ProcedureId and RecordStatus ='''' END' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Update_Schedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Update_Schedule] @RoomID as integer, @StartTime as datetime, @Length as integer, @Description as varchar(500), @ScheduleDate as datetime, @RecordStatus as varchar(1), @UserID as varchar(8) AS BEGIN Update tbORScheduleDetails Set RoomID = @RoomID, StartTime = @StartTime, Length = @Length, ScheduleDate = @ScheduleDate, RecordStatus = @RecordStatus, ProcessBy = @UserID, ProcessDate = Getdate() Where ltrim(rtrim(Description)) = ltrim(rtrim(@Description)) ; END' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_List_Of_ConfirmedSchedules]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE Procedure [dbo].[sp_List_Of_ConfirmedSchedules] -- AS declare @DateToday as varchar(10) Set @DateToday = (Select convert(varchar(10),getdate(),101)) Select Distinct [TIME], case when Surgeon = ''DR. '' then '''' else surgeon end SURGEON, case when Anesthesiologist = ''DR. '' then '''' else Anesthesiologist end ANESTHESIOLOGIST, PATIENTNAME,ROOMID,PROCEDURENAME, case when ltrim(rtrim(CNurse)) = '''' then '''' else CNurse end CNURSE, case when ltrim(rtrim(SNurse)) = '''' then '''' else SNurse end SNURSE, ORROOM,[Status],[Transnum],IDnum,ScheduleDate From ( Select Distinct Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(Isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' + Max(Isnull(tbCoDoctor2.LastName,'''')) as Anesthesiologist, Max(Isnull(tbMaster.LastName+'', ''+ tbMaster.FirstName,'''')) as PatientName, -- Convert(varchar(20),Details.Scheduledate,0) as [SCHEDULEDATE/TIME], tbPatient.RoomID as RoomID, Max(Isnull(Details.Procedurename,'''')) as ProcedureName, Max(Isnull(tbPasswordMaster.lastname,''''))+'', ''+ Max(Isnull(Upper(Substring(tbPasswordMaster.FirstName,1,1)),'''')) as CNurse, Max(Isnull(tbPasswordMaster2.lastname,''''))+'', ''+ Max(Isnull(Upper(Substring(tbPasswordMaster2.FirstName,1,1)),'''')) as SNurse, Details.RoomID as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Details.Idnum,Max(Isnull(ScheduleDate,'''')) as ScheduleDate From Schedule..tbOrScheduledetails Details Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum --Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Password..tbPasswordMaster tbPasswordMaster On Details.CNurse = tbPasswordMaster.EmployeeID Left Outer Join Password..tbPasswordMaster tbPasswordMaster2 On Details.SNurse1 = tbPasswordMaster2.EmployeeID Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.DoctorID1 = tbCoDoctor.DoctorID --SURGEON(MAIN) Left Outer Join Build_File..tbCoDoctor tbCoDoctor2 On Details.DoctorID2 = tbCoDoctor2.DoctorID --ANEST(MAIN) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.Idnum,Details.RoomID, tbPatient.RoomID,Details.TransNum UNION ALL Select Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' + Max(isnull(tbCoDoctor2.LastName,'''')) as Anesthesiologist, Max(isnull(tbMaster.LastName,''''))+'', ''+ Max(isnull(tbMaster.FirstName,'''')) as PatientName, -- Convert(varchar(20),Details.Scheduledate,0) as [SCHEDULEDATE/TIME], tbPatient.RoomID as RoomID, Max(isnull(Details.Procedurename,'''')) as ProcedureName, '''' as CNurse, Max(isnull(tbPasswordMaster2.lastname,''''))+'', ''+ Max(isnull(Upper(Substring(tbPasswordMaster2.FirstName,1,1)),'''')) as SNurse, Details.RoomID as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Details.Idnum,Max(Isnull(ScheduleDate,'''')) as ScheduleDate From Schedule..tbOrScheduledetails Details Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum --Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Password..tbPasswordMaster tbPasswordMaster2 On Details.SNurse2 = tbPasswordMaster2.EmployeeID Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.AsstSurgeon1 = tbCoDoctor.DoctorID --SURGEON(ASST1) Left Outer Join Build_File..tbCoDoctor tbCoDoctor2 On Details.AsstAnesth1 = tbCoDoctor2.DoctorID --ANEST(ASST1) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.Idnum,Details.RoomID, tbPatient.RoomID,Details.TransNum UNION ALL --Surgeon3,'''' Select Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)) as [Time], ''DR. '' + Max(Isnull(tbCoDoctor.LastName,'''')) as Surgeon, ''DR. '' as Anesthesiologist, -- Case when Max(isnull(AsstSurgeon2,'''')) = '''' then '''' -- else ''DR. '' + Max(isnull(tbCoDoctor.LastName,'''')) end as Surgeon, -- '''' as Anesthesiologist, Max(isnull(tbMaster.LastName,''''))+'', ''+ Max(isnull(tbMaster.FirstName,'''')) as PatientName, -- Convert(varchar(20),Details.Scheduledate,0) as [SCHEDULEDATE/TIME], tbPatient.RoomID as RoomID, Max(isnull(Details.Procedurename,'''')) as ProcedureName, '''' as CNurse, '''' as SNurse, Details.RoomID as ORRoom, case Max(isnull(Details.Recordstatus,'''')) when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, Details.TransNum, Details.Idnum,Max(Isnull(ScheduleDate,'''')) as ScheduleDate From Schedule..tbOrScheduledetails Details Left Outer Join Patient_Data..tbPatient tbPatient On Details.Idnum = tbPatient.Idnum Left Outer Join Patient_Data..tbMaster tbMaster On Details.Hospnum = tbMaster.Hospnum --Left Outer Join Build_File..tbCoOtherRevenue tbCoOtherRevenue On Details.ProcedureID = tbCoOtherRevenue.OtherRevenueID and tbCoOtherRevenue.OtherSectionID = ''OL'' Left Outer Join Build_File..tbCoDoctor tbCoDoctor On Details.AsstSurgeon2 = tbCoDoctor.DoctorID --SURGEON(ASST2) Where Details.Scheduledate between @DateToday and @DateToday + '' 23:59:59.99'' and Details.RecordStatus =''C'' Group by Ltrim(Substring(Convert(Varchar(20),Details.scheduledate,100),12,9)),Details.Idnum,Details.RoomID, tbPatient.RoomID,Details.TransNum )z where surgeon <> ''dr. '' and anesthesiologist <> ''dr. '' --and SNurse <> '''' Order by ScheduleDate,PatientName,Idnum --group by z.Idnum ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_ORScheduleDetails]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_Get_ORScheduleDetails] @Description as varchar(250) AS BEGIN Select * from tbORScheduleDetails Where ltrim(rtrim(Description)) = ltrim(rtrim(@Description)) ; END' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_ListORSchedule_Request]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_ListORSchedule_Request] @StationID As varchar(10) AS select isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName,e.otherrevenue as [OR Procedure], isnull(c.lastname,'''') + '' ,'' + isnull(c.firstname,'''') + '' '' + isnull(c.middlename,'''') as Surgeon, isnull(d.lastname,'''') + '' ,'' + isnull(d.firstname,'''') + '' '' + isnull(d.middlename,'''') as Anesthesiologist, convert(varchar(20),a.scheduledate,0) as [Schedule Date/Time],a.IDNum as [ADM. #], a.ProcedureID as ProcID, case isnull(a.recordstatus,'''') when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status, A.Transnum from tborscheduledetails as a /* left outer join (select a.idnum,isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName from PATIENT_DATA..tbpatient as a left outer join PATIENT_DATA..tbmaster as b on a.hospnum = b.hospnum ) as b on a.idnum = b.idnum*/ left outer join patient_data..tbMaster as b on a.hospnum=b.hospnum left outer join BUILD_FILE..tbcoDoctor as c on a.doctorid1 = c.doctorid left outer join BUILD_FILE..tbcoDoctor as d on a.doctorid2 = d.doctorid left outer join BUILD_FILE..tbcoOtherrevenue as e on a.procedureID = e.otherrevenueid left outer join PATIENT_DATA..tbpatient as f on a.idnum = f.idnum where isnull(f.dcrdate,'''') ='''' and a.StationID = @StationID --isnull(recordstatus,'''') ='''' order by PatientName,Status ' END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_List_ConfirmedORSchedule]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_List_ConfirmedORSchedule] AS select isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName,e.otherrevenue as [OR Procedure], isnull(c.lastname,'''') + '' ,'' + isnull(c.firstname,'''') + '' '' + isnull(c.middlename,'''') as Surgeon, isnull(d.lastname,'''') + '' ,'' + isnull(d.firstname,'''') + '' '' + isnull(d.middlename,'''') as Anesthesiologist, convert(varchar(20),a.scheduledate,0) as [Schedule Date/Time],a.IDNum as [ADM. #], a.ProcedureID as ProcID, case isnull(a.recordstatus,'''') when '''' then ''Pending'' when ''C'' then ''Confirmed'' when ''R'' then ''Revoked'' else '''' END As Status from tborscheduledetails as a /* left outer join (select a.idnum,isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName from PATIENT_DATA..tbpatient as a left outer join PATIENT_DATA..tbmaster as b on a.hospnum = b.hospnum ) as b on a.idnum = b.idnum*/ left outer join patient_data..tbMaster as b on a.hospnum=b.hospnum left outer join BUILD_FILE..tbcoDoctor as c on a.doctorid1 = c.doctorid left outer join BUILD_FILE..tbcoDoctor as d on a.doctorid2 = d.doctorid left outer join BUILD_FILE..tbcoOtherrevenue as e on a.procedureID = e.otherrevenueid left outer join PATIENT_DATA..tbpatient as f on a.idnum = f.idnum where isnull(f.dcrdate,'''') ='''' and isnull(a.recordstatus,'''') IN (''C'') --isnull(recordstatus,'''') ='''' order by PatientName,Status ' END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetORSchedule_Request]') AND type in (N'P', N'PC')) BEGIN EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [dbo].[sp_GetORSchedule_Request] AS select isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName,A.ProcedureName as [OR Procedure], isnull(c.lastname,'''') + '' ,'' + isnull(c.firstname,'''') + '' '' + isnull(c.middlename,'''') as Surgeon, isnull(d.lastname,'''') + '' ,'' + isnull(d.firstname,'''') + '' '' + isnull(d.middlename,'''') as Anesthesiologist, convert(varchar(20),a.scheduledate,0) as [Schedule Date/Time],a.IDNum as [ADM. #],a.ProcedureID as ProcID,'''', a.Transnum As TransNum, a.DoctorID1 As Doc1, a.DoctorID2 As Doc2 from tborscheduledetails as a /* left outer join (select a.idnum,isnull(b.lastname,'''') + '' ,'' + isnull(b.firstname,'''') + '' '' + isnull(b.middlename,'''') as PatientName from PATIENT_DATA..tbpatient as a left outer join PATIENT_DATA..tbmaster as b on a.hospnum = b.hospnum ) as b on a.idnum = b.idnum*/ left outer join patient_data..tbMaster as b on a.hospnum=b.hospnum left outer join BUILD_FILE..tbcoDoctor as c on a.doctorid1 = c.doctorid left outer join BUILD_FILE..tbcoDoctor as d on a.doctorid2 = d.doctorid left outer join BUILD_FILE..tbcoOtherrevenue as e on a.procedureID = e.otherrevenueid where isnull(recordstatus,'''') ='''' ' END GO USE [FixedAsset] GO /****** Object: Table [dbo].[tblrequester] Script Date: 09/05/2012 17:13:12 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tblrequester]( [fld_TicketNumber] [int] NOT NULL, [fld_DateTimeRequest] [varchar](50) NULL, [fld_Department] [varchar](50) NULL, [fld_RequestNeeded] [text] NULL, [fld_RequestedBy] [varchar](50) NULL, [fld_AssignedTo] [varchar](255) NULL, [fld_PriorityLevel] [varchar](50) NULL, [fld_DateTimeStart] [varchar](50) NULL, [fld_DateTimeEnd] [varchar](50) NULL, [fld_RepairStatus] [varchar](50) NULL, [fld_Cost] [float] NULL, [fld_RequestTo] [varchar](50) NULL, [fld_BudgetingHead] [varchar](50) NULL, [fld_Repairman] [varchar](50) NULL, [fld_NotedBy] [varchar](50) NULL, [fld_CheckedBy] [varchar](50) NULL, [fld_WorkDone] [text] NULL, [fld_RushReason] [text] NULL, CONSTRAINT [PK_tblrequester] PRIMARY KEY CLUSTERED ( [fld_TicketNumber] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO USE [FixedAsset] GO /****** Object: Table [dbo].[tblcomments] Script Date: 09/05/2012 17:14:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tblcomments]( [fld_TicketNumber] [int] NULL, [fld_User] [varchar](50) NULL, [fld_Comments] [text] NULL, [fld_Date] [varchar](50) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO USE [Password] GO /****** Object: Table [dbo].[tbPasswordWoms] Script Date: 09/05/2012 17:14:33 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[tbPasswordWoms]( [EmployeeID] [varchar](50) NULL, [Department] [varchar](50) NULL, [UserRights] [varchar](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO USE FIXEDASSET --alter table tbfacadetail --add ManualItemName varchar(25) GO --alter table tbfacadetail --add TempLaborCost money GO ALTER procedure [dbo].[spFA_LoadCADetails]--'PAE-12-10-77595' @CANum varchar(30), @CASequence varchar(30) ='' as --declare @CANum varchar(30), --@CASequence varchar(30) --set @CANum ='PAE-09-3-1' --set @CASequence ='' select a.CANum, a.CASequence, a.POSequence, a.RIVSequence, a.RIVNum, a.ItemID, a.UomID, a.EmpID, a.DeptID, b.UnitofMeasure, a.Quantity, a.UnitCost, a.BackOrder, a.IsBackOrder, a.IsFree, isnull(a.RRtype,'1') RRtype, isnull(a.caClass,0) caClass, a.IsManual, a.Specs, a.manualItemname, a.rrtype, A.propnum, A.TempLaborcost from tbFACADetail a left join tbfaunitofmeasure b on a.UomID = b.UnitofMeasureID where CANum = @CAnum --and not rtrim(a.CASequence) = rtrim(@CASequence) GO ALTER PROCEDURE [dbo].[spFA_LoadCAHeader]--'1'--,'04/01/2009','01/01/2012' --FixedAsset..spFA_LoadCAHeader '3','04/06/2009','04/06/2012' @Mode varchar(1), @CADate1 varchar(10) = NULL, @CADate2 varchar(10) = NULL AS IF @Mode = '1' BEGIN SELECT A.CANum, isnull(A.CADate, getdate()) CADate, --A.IVNum, isnull(A.IVDate, getdate()) IVDate, A.DRNum, isnull(A.DRDate, getdate()) DRDate, A.PONum, isnull(H.PODate, getdate()) PODate, A.TotalCost, isnull(A.Discount,0) Discount, A.NetCost, A.DeliveryStatusID, isnull(D.Delivery,'') Delivery, isnull(A.Remarks,'') Remarks, isnull(A.WarrantyBDate, getdate()) WarrantyBDate, isnull(A.WarrantyEDate, getdate()) WarrantyEDate, A.DateReceived, isnull(H.SupplierID,'') SupplierID, isnull(I.company,'') SupplierName, --A.IsWithBackOrder, A.CAStatus --,isForPARPrint = case when not AM.EmpID is null then 'Y' else 'N' end ,CD.ManualItemName as requestedItem, CD.RRtype FROM tbFACAHeader A Left Outer Join tbFADeliveryStatus D on A.DeliveryStatusID = D.DeliveryID Left Outer Join tbFAPOHeader H on A.POnum = H.PONUm Left Outer Join accounting..vend I on A.SupplierID = I.vendorid --Left outer join tbFAAssetManager AM on AM.CANum = A.CANum left outer join tbFACADetail CD on A.CANum = CD.CANum WHERE A.CAStatus in ('0','1') ORDER by A.CADate DESC, A.CANum DESC END; ELSE IF @Mode = '3' BEGIN SELECT A.CANum, A.CADate, --A.IVNum, A.IVDate, isnull(A.DRNum,'') DRNum, isnull(A.DRDate,'') DRDate, isnull(A.PONum,'') PONum, H.PODate, A.TotalCost, A.Discount, A.NetCost, isnull(A.DeliveryStatusID,'') DeliveryStatusID, isnull(D.Delivery,'') Delivery, isnull(A.Remarks,'') Remarks, A.WarrantyBDate, A.WarrantyEDate, A.DateReceived, isnull(H.SupplierID,'') SupplierID, isnull(I.SupplierName,'') SupplierName, --A.IsWithBackOrder, A.CAStatus --,isForPARPrint = case when not AM.EmpID is null then 'Y' else 'N' end ,CD.ManualItemName as requestedItem, CD.RRtype FROM tbFACAHeader A Left Outer Join tbFADeliveryStatus D on A.DeliveryStatusID = D.DeliveryID Left Outer Join tbFAPOHeader H on A.POnum = H.PONUm Left Outer Join tbfasupplier I on A.SupplierID = I.SupplierID --Left outer join tbFAAssetManager AM on AM.CANum = A.CANum left outer join tbFACADetail CD on A.CANum = CD.CANum WHERE A.CAStatus in ('3') and A.Transdate between @CADate1 and @CADate2 + ' 23:59:59.99' ORDER by A.CADate DESC, A.CANum DESC END; GO ALTER PROCEDURE [dbo].[spFA_ReportCA]--'08/01/2012','08/17/2012' @date1 varchar(10), @date2 varchar(10) AS Declare @TotalDiscount float, @TotalNetCost float Set @TotalDiscount = (select sum(discount) from tbfacaheader where cadate between @date1 and @date2 + ' 23:59:59.99') Set @TotalNetCost = (select sum(netcost) from tbfacaheader where cadate between @date1 and @date2 + ' 23:59:59.99') SELECT 'RR: ' + ch.canum + space(5) + 'RR Date: ' + convert(varchar(10),ch.cadate,101) CAnum, ch.ponum PONum, pd.rivnum RIVNum, -- case when cd.IsFree = 0 then -- case when isnull(m.specification,'') <> '' then m.item + '(' + isnull(m.specification,'') + ')' + ' ' + '"' + pd.specification + '"' -- else m.item + ' ' + '"' + pd.specification + '"' -- end -- else -- case when isnull(m.specification,'') <> '' then '"FREE" ' + m.item + '(' + isnull(m.specification,'') + ')' -- else '"FREE" ' + m.item -- end -- end Item, --m.item, cd.manualitemname as item, /*RECEIVED ITEM*/ ch.cadate, case when ch.castatus in ('0','1') then 'Pending' when ch.castatus = '2' then 'Cancelled' when ch.castatus = '3' then 'Posted' end status, cd.quantity, IsNull(cd.UnitCost,0) unitcost, case when cd.IsFree = 0 then Isnull (cd.UnitCost,0) * Isnull(cd.Quantity,0) else 0 end totalcost, ch.discount, ch.netcost, @totaldiscount totaldiscount, @totalnetcost totalnetcost, ph.pesovalue, isnull(s.company,'') supplier FROM tbfacaheader ch left outer join tbfacadetail cd on ch.canum = cd.canum left outer join tbfapodetail pd on cd.posequence = pd.posequence left outer join tbfapoheader ph on ch.ponum = ph.ponum left outer join accounting..vend s on ch.supplierid = s.vendorid left outer join tbfamaster m on cd.itemid = m.itemcode WHERE ch.cadate between @date1 and @date2 + ' 23:59:59.99' ORDER BY m.item GO ALTER PROCEDURE [dbo].[spFA_ReportCAForm]--'PAE-12-9-77509' @CANum varchar(20) AS SELECT CH.CANum, CH.CADate, S.Company, CH.PONum,--PH.PONum(isSepPO) PH.PODate, CH.DRNum, CH.DRDate, dbo.fnFA_IVSeries(cd.canum) IVNum, CH.IVDate, CD.ItemID, dbo.fnFA_RIVSeries(cd.canum,'2') RIVNum, dbo.fnFA_RIVDateSeries(cd.canum) RIVDate, CD.ManualItemName, -- case when isnull(m.itemname,'') = '' then CD.ManualItemName -- else -- CASE WHEN CD.IsFree = 0 then -- CASE WHEN isnull(M.itemdesc,'') <> '' then M.itemname + '(' + isnull(M.itemdesc,'') + ')' + ' ' + '"' + pd.specification + '"' -- Else M.itemname + ' ' + '"' + pd.specification + '"' -- End -- --ELSE -- -- CASE WHEN isnull(M.itemdesc,'') <> '' then '"FREE" ' + M.itemname + '(' + isnull(M.itemdesc,'') + ')' -- -- Else '"FREE" ' + M.itemname -- -- End -- END -- end as Item, CD.Quantity, U.UnitofMeasure, CD.UnitCost, isnull(CH.Discount,0) Discount, Case When CD.IsFree = 0 then CD.Quantity * CD.UnitCost Else 0 End [Amount], D.Delivery, isnull(CH.Remarks,'') Remark, dbo.[fnFA_GetAssignatories]('3') as RECEIVINGOFFICER, dbo.[fnFA_GetAssignatories]('2') as ValidatingOfficer, dbo.fnFA_RequisitionerSeries(cd.canum) Requisitioner, --dbo.fnFA_GetRequisitionerFromInventory(CH.PONum) Requisitioner, CD.IsFree, dbo.[fnFA_GetAssignatories]('1') as PropertyCustodian, dbo.[fnFA_GetAssignatories]('4') as NotedBy, S.company as Supplier, isnull(CH.VatPerc,0) VatPerc, isnull(CH.VAT,0) VAT, CH.WarrantyBDate as WarrantyStartDate, CH.WarrantyEDate as WarrantyEndDate FROM tbfacadetail CD left outer join tbfacaheader CH on CD.CAnum = CH.CANum left outer join tbfapoheader PH on CH.PONum = PH.PONum left outer join tbfapodetail PD on CD.POSequence = PD.POSequence left outer join tbfadeliverystatus D on CH.DeliveryStatusID = D.DeliveryID left outer join accounting..vend S on CH.SupplierID = S.vendorid left outer join inventory..tbinvmaster M on M.ItemID = CD.itemid left outer join tbfaunitofmeasure U on CD.UomID = U.UnitofMeasureID left outer join Payroll..tbcmaster pm on CH.ReceivingUserID = PM.Empnum left outer join Payroll..tbcmaster PM1 on CH.ValidatingUserID = PM1.Empnum WHERE CD.CANum = @CANum ORDER BY CD.IsFree--, M.Item /*Declare @RIVNum varchar(20), @RIVDate varchar(10), @Requisitioner varchar(30), @IVNum varchar(10), @RIVNum_All varchar(50), @IVNum_All varchar(50), @RIVDate_All varchar(50), @Requisitioner_All varchar(254)*/ /*--~~@Requisitioner_All~~-- DECLARE authors_cursor CURSOR FOR Select Case IsNull(max(pm.MiddleName),'') When '' Then IsNull(max(PM.FirstName),'') + ' ' + IsNull(max(PM.LastName),'') Else IsNull(max(PM.FirstName),'') + ' ' + Left(IsNull(max(PM.MiddleName),''),1) + '. ' + IsNull(max(PM.LastName),'') End Requisitioner From tbfarivdetail rd left outer join tbfacadetail cd on rd.rivsequence = cd.rivsequence left outer join tbfarivheader rh on rd.rivnum = rh.rivnum left outer join Payroll..tbcmaster pm on rh.requisitionerid = pm.empnum Where cd.canum = @canum and cd.isfree = 0 Group by rd.rivnum Order by max(pm.LastName) OPEN authors_cursor Set @Requisitioner_All = '' FETCH NEXT FROM authors_cursor Into @Requisitioner WHILE @@FETCH_STATUS = 0 BEGIN Set @Requisitioner_All = @Requisitioner_All + @Requisitioner + char(13) + char(13) + char(13) FETCH NEXT FROM authors_cursor Into @Requisitioner END CLOSE authors_cursor DEALLOCATE authors_cursor --~~@Requisitioner_All~~--*/ --~~@RIVNum_All~~-- /*DECLARE authors_cursor CURSOR FOR Select isnull(PD.RIVNum,'') From tbFAPODetail PD Left Outer Join tbFACADetail CD on PD.POSequence = CD.POSequence Where CD.CANum = @CANum and PD.IsFree = 0 Group By PD.RIVNum OPEN authors_cursor Set @RIVNum_All = '' FETCH NEXT FROM authors_cursor Into @RIVNum WHILE @@FETCH_STATUS = 0 BEGIN Set @RIVNum_All = @RIVNum_All + @RIVNum + ' - ' FETCH NEXT FROM authors_cursor Into @RIVNum END CLOSE authors_cursor DEALLOCATE authors_cursor*/ --~~@RIVNum_All~~-- /*--~~@RIVDate_All~~-- DECLARE authors_cursor CURSOR FOR Select max(convert(varchar(10),rh.rivdate,101)) From tbfarivdetail rd left outer join tbfacadetail cd on rd.rivsequence = cd.rivsequence left outer join tbfarivheader rh on rd.rivnum = rh.rivnum Where cd.canum = @CANum and cd.isfree = 0 Group by rd.rivnum OPEN authors_cursor Set @RIVDate_All = '' FETCH NEXT FROM authors_cursor Into @RIVDate WHILE @@FETCH_STATUS = 0 BEGIN Set @RIVDate_All = @RIVDate_All + @RIVDate + ' - ' FETCH NEXT FROM authors_cursor Into @RIVDate END CLOSE authors_cursor DEALLOCATE authors_cursor --~~@RIVDate_All~~--*/ --~~@IVNum_All~~-- /*DECLARE authors_cursor CURSOR FOR Select isnull(IVNum,'') From tbFAIVNum Where CANum = @CANum OPEN authors_cursor Set @IVNum_All = '' FETCH NEXT FROM authors_cursor Into @IVNum WHILE @@FETCH_STATUS = 0 BEGIN Set @IVNum_All = @IVNum_All + @IVNum + ' - ' FETCH NEXT FROM authors_cursor Into @IVNum END CLOSE authors_cursor DEALLOCATE authors_cursor*/ --~~@IVNum_All~~-- GO ALTER PROCEDURE [dbo].[spFA_SaveCADetail] @CANum varchar(20), @CASequence varchar(10), @POSequence varchar(10), @RIVSequence varchar(10), @ItemID varchar(20), @UomID varchar(10), @Quantity float, @UnitCost float, --@IsPosted varchar(1), @IsFree varchar(1), @BackOrder float, @IsBackOrder varchar(1), @RRType varchar(1) = '', @IsManual varchar(1)= '', @Specs varchar(150)='', @PropNum varchar(30) = '', @PoNum varchar(30) = '', @Requisitioner varchar(15) = '', @Department varchar(15)='', @CAClass varchar(5)='', @ManualItemName varchar(25)='', @TempLaborCost money = 0 AS DECLARE @ErrorCode int SET @ErrorCode = 0 INSERT INTO tbFACADetail (CANum, CASequence, POSequence, RIVSequence, ItemID, UomID, Quantity, UnitCost, IsFree, BackOrder, IsBackOrder, RRType, IsManual, Specs, PropNum, PONum, EmpID, DeptID, CAClass, ManualItemName, TempLaborCost) VALUES (@CANum, @CASequence, @POSequence, @RIVSequence, @ItemID, @UomID, @Quantity, @UnitCost, --@IsPosted, @IsFree, @BackOrder, @IsBackOrder, @RRType, @IsManual, @Specs, @PropNum, @PONum, @Requisitioner, @Department, @CAClass, @ManualItemName, @TempLaborCost); SET @ErrorCode = @@ERROR IF @ErrorCode <> 0 RETURN @ErrorCode RETURN @ErrorCode GO USE [Patient_Data] GO ALTER TABLE tbHospitalInfo add ReportFooter varchar(250) null GO USE [Billing] GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ALTER FUNCTION [dbo].[fn_RevenueForLoyaltyPoints] (@RevenueID as varchar(2)) RETURNS varchar(1) AS BEGIN declare @DrCr as varchar(1) select @DrCr = DrCr from BUILD_FILE..tbCoRevenueCode where RevenueID = @RevenueID; RETURN case when @DrCr = 'P' then 'N' when @RevenueID in ('CT','DI','AB','EN') then 'N' else 'Y' end END GO USE [Medicare] GO /****** Object: StoredProcedure [dbo].[Medic_PatientPostedIPList] Script Date: 10/22/2012 13:30:01 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[Medic_PatientPostedIPList] @strSearch as varchar(20), @intOption as int, @strType as varchar(1), @intPatientType as int, @WithPayments as bit = 0 AS if @WithPayments = 0 BEGIN /* All Patients */ If @intOption = 1 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) and Right(A.IdNum,1) = 'D' Order by A.AdmDate desc End End /* By Type 1 -- SSS 2 -- GSIS 3 -- OWWA 4 -- ECC */ If @intOption = 2 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and Right(A.IdNum,1) = 'D' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by A.AdmDate desc End End END ELSE BEGIN /* All Patients */ If @intOption = 1 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and Right(A.IdNum,1) = 'D' and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by A.AdmDate desc End End /* By Type 1 -- SSS 2 -- GSIS 3 -- OWWA 4 -- ECC */ If @intOption = 2 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where (IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) like @strSearch+'%' and Right(A.IdNum,1) = 'D' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where idnum = a.idnum ) Order by A.AdmDate desc End End END GO USE [Medicare] GO /****** Object: StoredProcedure [dbo].[Medic_PatientPostedListIPByID] Script Date: 10/22/2012 13:30:29 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[Medic_PatientPostedListIPByID] @strSearch as varchar(20), @intOption as int, @strType as varchar(1), @intPatientType as int, @WithPayments as bit = 0 AS if @WithPayments = 0 BEGIN /* All Patients */ If @intOption = 1 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where A.IdNum like @strSearch+'%' and Right(A.IdNum,1) = 'D' and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by A.AdmDate desc End End /* By Type 1 -- SSS 2 -- GSIS 3 -- OWWA 4 -- ECC */ If @intOption = 2 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where A.IdNum like @strSearch+'%' and Right(A.IdNum,1) = 'D' and MemberType = @strType and not exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by A.AdmDate desc End End END ELSE BEGIN /* All Patients */ If @intOption = 1 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where A.IdNum like @strSearch+'%' and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) and Right(A.IdNum,1) = 'D' Order by A.AdmDate desc End End /* By Type 1 -- SSS 2 -- GSIS 3 -- OWWA 4 -- ECC */ If @intOption = 2 Begin If @intPatientType = 1 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), B.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 2 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(B.AdmDate,'') When '' Then '' Else Convert( varchar(10), B.AdmDate, 101 ) End, [Discharged] = Case IsNull(B.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Inner Join Patient_Data..tbOutPatient B On A.IdNum = B.IdNum Where A.IdNum like @strSearch+'%' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by B.AdmDate desc End If @intPatientType = 3 Begin Select [Patient Name] = Case A.ForPurging When 1 Then '* '+Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) Else Ltrim(IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'')) End, IsNull(A.MemberNumber,'') [Member Number], [Admitted] = Case IsNull(A.AdmDate,'') When '' Then '' Else Convert( varchar(10), A.AdmDate, 101 ) End, [Discharged] = Case IsNull(A.DcrDate,'') When '' Then '' Else Convert( varchar(10), A.DcrDate, 101 ) End, IsNull(A.IdNum,'') [Admission #], [Transmittal Date] = Case IsNull(A.TransDate,'') When '' Then '' Else Convert( varchar(10), A.TransDate, 101 ) End from Medicare..tbMedPatient A Where A.IdNum like @strSearch+'%' and Right(A.IdNum,1) = 'D' and MemberType = @strType and exists(select idnum from medicare..tbmedpayment where IdNum like @strSearch+'%' ) Order by A.AdmDate desc End End END GO USE BILLING GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'spBilling_ReportDailyRoomCharges_Gross') EXEC ('CREATE PROC dbo.spBilling_ReportDailyRoomCharges_Gross AS SELECT 1') GO ALTER PROCEDURE [dbo].[spBilling_ReportDailyRoomCharges_Gross] @ReportDate VARCHAR(10) , @RevenueID VARCHAR(3) , @PatientType VARCHAR(1), @EndDate varchar(10), @ItemId varchar(10) AS --SET @ReportDate = '10/22/2012' --set @EndDate = '10/22/2012' --set @RevenueID = 'ALL' --set @PatientType = 'I' --set @ItemID = '' Declare @Date as varchar(22) set @Date = @EndDate + ' 23:59:59.99' IF @PatientType = 'I' BEGIN SELECT Z.RefNum, Z.RevenueID , Z.IDNum, ISNULL( B.LastName, '' ) + ', ' + ISNULL( B.FirstName, '' ) as PatientName, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome when isnull(Z.RevenueID,'') in ('PC','PH') then 'MEDICINES' when isnull(Z.RevenueID,'') in ('CC','CS') then 'SUPPLIES' else Case when (Z.RevenueID = 'MD' and Z.Amount < 0) then C.ItemName + '- CREDIT MEMO' else C.ItemName End End as [Description], ISNULL( Z.Quantity, 0 ) AS Quantity , CAST( Z.Amount AS Money ) as Amount , CASE WHEN C.Lgrp = 'D' THEN 'B' ELSE 'A' END AS ReportGroup, Z.TransDate, Z.UserID, Z.ItemID, B.AccountNum, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome else Case when Z.RevenueID = 'RA' then isnull(G.Station, Z.Location) else Z.Location End End as Location, Z.DrCr, Z.MainGroup, Charges, Credit FROM ( SELECT A.RefNum, A.RevenueID , A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Location = B.ItemName, DRCR = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' Else Case When B.DrCr = 'D' and Credit = 0 then 'CHARGES' When (B.DrCr = 'C' or (A.Credit <> 0 and B.DrCr <> 'P')) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DrCr = 'P' then 'PROFESSIONAL SERVICES' End End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA', 'TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, isnull(A.PrepaidPackage, '') as PrepaidPackage, D.ItemName as DepartmentIncome, isnull(A.RoomID, '') as RoomID, isnull(A.Description, '') as Description FROM BillingOthersSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.RevenueID = B.RevenueID Left Outer Join Build_File..tbCoAdmPackage C on A.PrepaidPackage = C.PackageID Left Outer Join Build_File..tbCoRevenueCode D on C.DepartmentIncome = D.RevenueID WHERE (A.Transdate BETWEEN @ReportDate and @Date) AND (A.RevenueID = @RevenueID OR @RevenueID = 'ALL') AND A.RevenueID NOT IN ('PH', 'CS', 'PC', 'CC') AND isnull(A.Adjust,'') <> 'X' AND isnull(A.OPDIDNum,'') = '' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID as RevenueID, A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Case When B.DrCr = 'C' Then B.ItemName + ' - ' + B.ItemName else E.Location End as Location, DRCR = Case When (B.DrCr = 'D' and Credit = 0) then 'CHARGES' When (B.DrCr = 'C' or Credit <> 0) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DRCR = 'P' then 'PROFESSIONAL SERVICES' End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, '' as PrepaidPackage, '' as DepartmentIncome, '' as RoomID, isnull(A.Description, '') as Description FROM BillingDrugsSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID Left Outer Join Inventory..tbInvLocation E on A.LocationID = E.LocationID WHERE ( B.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND (A.Transdate BETWEEN @ReportDate and @Date) and isnull(A.OPDIDNum,'') = '' AND (A.ItemID = @Itemid OR @Itemid = '') ) Z Left Outer Join PATIENT_DATA..tbPatient P ON Z.IdNum = P.IDNum Left Outer Join PATIENT_DATA..tbMaster B ON P.HospNum = B.HospNum Left Outer Join BUILD_FILE..tbCoRevenueCode C ON Z.RevenueID = C.RevenueID Left Outer Join Build_File..tbCoRoom F on Z.RoomID = F.RoomID Left Outer Join Build_File..tbCoStation G on F.StationID = G.StationID where Z.Amount <> 0 END ELSE IF @PatientType = 'O' BEGIN SELECT Z.RefNum, Z.RevenueID , Z.IDNum, Case when isnull(Z.IDNum,'CASH') = 'CASH' then isnull(D.PaymentFrom,'') else ISNULL( B.LastName, '' ) + ', ' + ISNULL( B.FirstName, '' ) End as PatientName, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome when isnull(Z.RevenueID,'') in ('PC','PH') then 'MEDICINES' when isnull(Z.RevenueID,'') in ('CC','CS') then 'SUPPLIES' else Case when (Z.RevenueID = 'MD' and Z.Amount < 0) then C.ItemName + '- CREDIT MEMO' else C.ItemName End End as [Description], ISNULL( Z.Quantity, 0 ) AS Quantity , CAST( Z.Amount AS Money ) as Amount , CASE WHEN C.Lgrp = 'D' THEN 'B' ELSE 'A' END AS ReportGroup, Z.TransDate, Z.UserID, Z.ItemID, B.AccountNum, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome else Case when Z.RevenueID = 'RA' then isnull(G.Station, Z.Location) when Z.RevenueID = 'LB' then isnull(I.LabSection, Z.Location) when Z.RevenueID = 'MH' then isnull(Z.Description, Z.Location) else Z.Location End End as Location, Z.DrCr, Z.MainGroup, Charges, Credit FROM ( SELECT A.RefNum, A.RevenueID , A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Location = B.ItemName, DRCR = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' Else Case When B.DrCr = 'D' and Credit = 0 then 'CHARGES' When (B.DrCr = 'C' or (A.Credit <> 0 and B.DrCr <> 'P')) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DrCr = 'P' then 'PROFESSIONAL SERVICES' End End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA', 'TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, isnull(A.PrepaidPackage, '') as PrepaidPackage, D.ItemName as DepartmentIncome, isnull(A.RoomID, '') as RoomID, isnull(A.Description, '') as Description FROM OPBillingOthersSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.RevenueID = B.RevenueID Left Outer Join Build_File..tbCoAdmPackage C on A.PrepaidPackage = C.PackageID Left Outer Join Build_File..tbCoRevenueCode D on C.DepartmentIncome = D.RevenueID WHERE ( A.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.RevenueID NOT IN ('PH', 'CS', 'PC', 'CC', 'OA') AND A.Transdate BETWEEN @ReportDate and @Date and isnull(A.IDNum,'CASH') <> 'CASH' and A.Adjust <> 'X' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID as RevenueID, A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Case When C.DrCr = 'C' Then C.ItemName + ' - ' + B.ItemName else Case when isnull(A.TargetLocationID,'') <> '' then D.Location else E.Location End End as Location, DRCR = Case When (C.DrCr = 'D' and Credit = 0) then 'CHARGES' When (C.DrCr = 'C' or Credit <> 0) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When C.DrCr = 'P' then 'PROFESSIONAL SERVICES' End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, '' as PrepaidPackage, '' as DepartmentIncome, '' as RoomID, isnull(A.Description, '') as Description FROM OPBillingDrugsSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID Left Outer Join Build_File..tbCoRevenueCode C on A.SummaryCode = C.RevenueID Left Outer Join Inventory..tbInvLocation D on A.TargetLocationID = D.LocationID Left Outer Join Inventory..tbInvLocation E on A.LocationID = E.LocationID WHERE ( B.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.Transdate BETWEEN @ReportDate and @Date AND ISNUMERIC( A.IDNum ) = 0 and isnull(A.IDNum,'CASH') <> 'CASH' AND (A.ItemID = @Itemid OR @Itemid = '') ) Z left Outer Join PATIENT_DATA..tbOutPatient P ON Z.IdNum = P.IDNum Left Outer Join PATIENT_DATA..tbMaster B ON P.HospNum = B.HospNum Left Outer Join BUILD_FILE..tbCoRevenueCode C ON Z.RevenueID = C.RevenueID Left Outer Join Billing..tbCashORMaster D on Z.RefNum = D.RefNum Left Outer Join Build_File..tbCoRoom F on Z.RoomID = F.RoomID Left Outer Join Build_File..tbCoStation G on F.StationID = G.StationID Left Outer Join Build_File..tbCoLabExam H on Z.ItemID = H.LabExamID Left Outer Join Build_File..tbCoLabSection I on H.LabSectionID = I.LabSectionID where Z.Amount <> 0 END ELSE IF @PatientType = 'A' BEGIN SELECT Z.RefNum, Z.RevenueID , Z.IDNum, Case when isnull(Z.IDNum,'CASH') = 'CASH' then isnull(D.PaymentFrom,'') else ISNULL( B.LastName, '' ) + ', ' + ISNULL( B.FirstName, '' ) End as PatientName, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome when isnull(Z.RevenueID,'') in ('PC','PH') then 'MEDICINES' when isnull(Z.RevenueID,'') in ('CC','CS') then 'SUPPLIES' else Case when (Z.RevenueID = 'MD' and Z.Amount < 0) then C.ItemName + '- CREDIT MEMO' else C.ItemName End End as [Description], ISNULL( Z.Quantity, 0 ) AS Quantity , CAST( Z.Amount AS Money ) as Amount , CASE WHEN C.Lgrp = 'D' THEN 'B' ELSE 'A' END AS ReportGroup, Z.TransDate, Z.UserID, Z.ItemID, B.Accountnum, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome else Case when Z.RevenueID = 'RA' then isnull(G.Station, Z.Location) when Z.RevenueID = 'LB' then isnull(I.LabSection, Z.Location) when Z.RevenueID = 'MH' then isnull(Z.Description, Z.Location) else Z.Location End End as Location, Z.DrCr, Z.MainGroup, Charges, Credit FROM ( SELECT A.RefNum, A.RevenueID , A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Location = B.ItemName, DRCR = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' Else Case When B.DrCr = 'D' and Credit = 0 then 'CHARGES' When (B.DrCr = 'C' or (A.Credit <> 0 and B.DrCr <> 'P')) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DrCr = 'P' then 'PROFESSIONAL SERVICES' End End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA', 'TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, isnull(A.PrepaidPackage, '') as PrepaidPackage, D.ItemName as DepartmentIncome, isnull(A.RoomID, '') as RoomID, isnull(A.Description, '') as Description FROM BillingOthersSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.RevenueID = B.RevenueID Left Outer Join Build_File..tbCoAdmPackage C on A.PrepaidPackage = C.PackageID Left Outer Join Build_File..tbCoRevenueCode D on C.DepartmentIncome = D.RevenueID WHERE ( A.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.RevenueID NOT IN ('PH', 'CS', 'PC', 'CC') AND A.Transdate BETWEEN @ReportDate and @Date and A.Adjust <> 'X' and isnull(A.OPDIDNum,'') = '' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID , A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Location = B.ItemName, DRCR = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' Else Case When B.DrCr = 'D' and Credit = 0 then 'CHARGES' When (B.DrCr = 'C' or (A.Credit <> 0 and B.DrCr <> 'P')) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DrCr = 'P' then 'PROFESSIONAL SERVICES' End End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA', 'TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, isnull(A.PrepaidPackage, '') as PrepaidPackage, D.ItemName as DepartmentIncome, isnull(A.RoomID,'') as RoomID, isnull(A.Description, '') as Description FROM OPBillingOthersSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.RevenueID = B.RevenueID Left Outer Join Build_File..tbCoAdmPackage C on A.PrepaidPackage = C.PackageID Left Outer Join Build_File..tbCoRevenueCode D on C.DepartmentIncome = D.RevenueID WHERE ( A.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.RevenueID NOT IN ('PH', 'CS', 'PC', 'CC','OA') AND A.Transdate BETWEEN @ReportDate and @Date and isnull(A.IDNum,'CASH') <> 'CASH' and A.Adjust <> 'X' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID as RevenueID, A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Case When C.DrCr = 'C' Then C.ItemName + ' - ' + B.ItemName else Case when isnull(A.TargetLocationID,'') <> '' then D.Location else E.Location End End as Location, DRCR = Case When (C.DrCr = 'D' and Credit = 0) then 'CHARGES' When (C.DrCr = 'C' or Credit <> 0) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When C.DrCr = 'P' then 'PROFESSIONAL SERVICES' End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, '' as PrepaidPackage, '' as DepartmentIncome, '' as RoomID, isnull(A.Description,'') as Description FROM BillingDrugsSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID Left Outer Join Build_File..tbCoRevenueCode C on A.SummaryCode = C.RevenueID Left Outer Join Inventory..tbInvLocation D on A.TargetLocationID = D.LocationID Left Outer Join Inventory..tbInvLocation E on A.LocationID = E.LocationID WHERE ( B.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.Transdate BETWEEN @ReportDate and @Date and isnull(A.IDNum,'CASH') <> 'CASH' and isnull(A.OPDIDNum,'') = '' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID as RevenueID, A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Case When C.DrCr = 'C' Then C.ItemName + ' - ' + B.ItemName else Case when isnull(A.TargetLocationID,'') <> '' then D.Location else E.Location End End as Location, DRCR = Case When (C.DrCr = 'D' and Credit = 0) then 'CHARGES' When (C.DrCr = 'C' or Credit <> 0) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When C.DrCr = 'P' then 'PROFESSIONAL SERVICES' End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, '' as PrepaidPackage, '' as DepartmentIncome, '' as RoomID, isnull(A.Description,'') as Description FROM OPBillingDrugsSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID Left Outer Join Build_File..tbCoRevenueCode C on A.SummaryCode = C.RevenueID Left Outer Join Inventory..tbInvLocation D on A.TargetLocationID = D.LocationID Left Outer Join Inventory..tbInvLocation E on A.LocationID = E.LocationID WHERE ( B.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.Transdate BETWEEN @ReportDate and @Date and isnull(A.IDNum,'CASH') <> 'CASH' AND (A.ItemID = @Itemid OR @Itemid = '') ) Z Left Outer Join PATIENT_DATA..tbPatient P ON Z.IdNum = P.IDNum Left Outer Join PATIENT_DATA..tbOutPatient OP ON Z.IdNum = OP.IDNum Left Outer Join PATIENT_DATA..tbMaster B ON B.HospNum = IsNull( P.HospNum, OP.HospNum ) Left Outer Join BUILD_FILE..tbCoRevenueCode C ON Z.RevenueID = C.RevenueID Left Outer Join Billing..tbCashORMaster D on Z.RefNum = D.RefNum Left Outer Join Build_File..tbCoRoom F on Z.RoomID = F.RoomID Left Outer Join Build_File..tbCoStation G on F.StationID = G.StationID Left Outer Join Build_File..tbCoLabExam H on Z.ItemID = H.LabExamID Left Outer Join Build_File..tbCoLabSection I on H.LabSectionID = I.LabSectionID where Z.Amount <> 0 END ELSE IF @PatientType = 'C' BEGIN SELECT Z.RefNum, Z.RevenueID , Z.IDNum, isnull(D.PaymentFrom,'') as PatientName, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome when isnull(Z.RevenueID,'') in ('PC','PH') then 'MEDICINES' when isnull(Z.RevenueID,'') in ('CC','CS') then 'SUPPLIES' else Case when (Z.RevenueID = 'MD' and Z.Amount < 0) then C.ItemName + '- CREDIT MEMO' else C.ItemName End End as [Description], ISNULL( Z.Quantity, 0 ) AS Quantity , CAST( Z.Amount AS Money ) as Amount , CASE WHEN C.Lgrp = 'D' THEN 'B' ELSE 'A' END AS ReportGroup, Z.TransDate, Z.UserID, Z.ItemID, '' as AccountNum, Case when isnull(Z.DepartmentIncome, '') <> '' then Z.DepartmentIncome else Case when Z.RevenueID = 'RA' then isnull(G.Station, Z.Location) when Z.RevenueID = 'LB' then isnull(I.LabSection, Z.Location) when Z.RevenueID = 'MH' then isnull(Z.Description, Z.Location) else Z.Location End End as Location, Z.DrCr, Z.MainGroup, Charges, Credit, isnull(D.Particulars,'') as OncoSlip FROM ( SELECT A.RefNum, A.RevenueID , A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Location = B.ItemName, DRCR = Case When A.RevenueID in ('AF','RV','BB','AA','TB') then 'OTHER TRANSACTIONS' Else Case When B.DrCr = 'D' and Credit = 0 then 'CHARGES' When (B.DrCr = 'C' or (A.Credit <> 0 and B.DrCr <> 'P')) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When B.DrCr = 'P' then 'PROFESSIONAL SERVICES' End End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA', 'TB') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, isnull(A.PrepaidPackage, '') as PrepaidPackage, D.ItemName as DepartmentIncome, '' as RoomID, isnull(A.Description, '') as Description FROM CashBillingOthersSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.RevenueID = B.RevenueID Left Outer Join Build_File..tbCoAdmPackage C on A.PrepaidPackage = C.PackageID Left Outer Join Build_File..tbCoRevenueCode D on C.DepartmentIncome = D.RevenueID WHERE ( A.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.RevenueID NOT IN ('PH', 'CS', 'PC', 'CC') AND A.Transdate BETWEEN @ReportDate and @Date and (isnull(A.IDNum,'CASH') = 'CASH' or A.IDNum = '') and A.Adjust <> 'X' AND (A.ItemID = @Itemid OR @Itemid = '') UNION ALL SELECT A.RefNum, A.RevenueID as RevenueID, A.IDNum, A.ItemID, ISNULL( A.Quantity, 0 ) AS Quantity , CAST( A.Amount AS Money ) as Amount, A.TransDate as TransDate, dbo.fncGetUserInitials(A.UserID) as UserID, Case When C.DrCr = 'C' Then C.ItemName + ' - ' + B.ItemName else Case when isnull(A.TargetLocationID,'') <> '' then D.Location else E.Location End End as Location, DRCR = Case When (C.DrCr = 'D' and Credit = 0) then 'CHARGES' When (C.DrCr = 'C' or Credit <> 0) then 'DEDUCTIONS/PAYMENTS/CREDIT MEMO' When C.DrCr = 'P' then 'PROFESSIONAL SERVICES' End, MainGroup = Case When A.RevenueID in ('AF','RV','BB','AA') then 'OTHER TRANSACTIONS' else '' End, Charges, Credit, '' as PrepaidPackage, '' as DepartmentIncome, '' as RoomID, isnull(A.Description,'') as Description FROM CashBillingDrugsSOA A Left Outer Join Build_File..tbCoRevenueCode B on A.LocationID = B.LocationID Left Outer Join Build_File..tbCoRevenueCode C on A.SummaryCode = C.RevenueID Left Outer Join Inventory..tbInvLocation D on A.TargetLocationID = D.LocationID Left Outer Join Inventory..tbInvLocation E on A.LocationID = E.LocationID WHERE ( B.RevenueID = @RevenueID OR @RevenueID = 'ALL' ) AND A.Transdate BETWEEN @ReportDate and @Date and (isnull(A.IDNum,'CASH') = 'CASH' or A.IDNum = '') AND (A.ItemID = @Itemid OR @Itemid = '') ) Z INNER Join BUILD_FILE..tbCoRevenueCode C ON Z.RevenueID = C.RevenueID Left Outer Join Billing..tbCashORMaster D on Z.RefNum = D.RefNum Left Outer Join Build_File..tbCoRoom F on Z.RoomID = F.RoomID Left Outer Join Build_File..tbCoStation G on F.StationID = G.StationID Left Outer Join Build_File..tbCoLabExam H on Z.ItemID = H.LabExamID Left Outer Join Build_File..tbCoLabSection I on H.LabSectionID = I.LabSectionID where Z.Amount <> 0 END GO USE [Medicare] GO /****** Object: StoredProcedure [dbo].[MedicRep_PaymentDenied] Script Date: 11/14/2012 11:29:06 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'MedicRep_PaymentDenied') EXEC ('CREATE PROC dbo.MedicRep_PaymentDenied AS SELECT 1') GO ALTER PROCEDURE [dbo].[MedicRep_PaymentDenied] @StartDate as varchar(10), @EndDate as varchar(10), @MedType as varchar(1) AS --set @startDate = '01/01/2000' --set @EndDate = '01/10/2007' --set @MedType = '2' select RTrim(IsNull(C.LastName,'') + ', ' + IsNull(C.FirstName,'') + ' ' + IsNull(C.MiddleName,'')) [Patient Name], isnull(a.transdate,'') [Transmittal Date], Convert(varchar(10),B.AdmDate,101) + '-' + Convert(varchar(10),B.DcrDate,101) [Confinement], Cast(IsNull((Select Sum(IsNull(Amount,0)) from tbMedPayment Where IdNum = A.IdNum Group by IdNum),0) - IsNull( ( Select Cast( Sum( IsNull( MedRoomBoard, 0 ) + IsNull( MedDrug, 0 ) + IsNull( MedOthers, 0 ) + IsNull( MedOR, 0 ) ) as Decimal( 12, 2 ) ) from tbmedclaim Where IdNum = A.IdNum ), 0 )as money) [Amount], A.IdNum [IdNum], isnull(A.ReasonDenied, '') as ReasonDenied, isnull(DateDenied, '') as DateDenied, isnull(DateApproved,'') as DateApproved, isnull(DateDeniedMain, '') as DateDeniedMain, isnull(ReasonDeniedMain,'') as ReasonDeniedMain, isnull(DateAppealMain, '') as DateAppealMain, isnull(A.MemberNumber,'') as MemberNumber, isnull(E.Name,'') as MemberType, Convert(varchar(10),B.DcrDate,101) as DcrDate from tbMedPatient A Inner Join Patient_data..tbPatient B On A.IdNum = B.IdNum Inner Join Patient_data..tbMaster C On B.HospNum = C.HospNum Left Outer Join tbMedActual D On A.IdNum = D.IdNum Left Outer Join tbMedType E on A.MemberType = E.Code Where A.PaymentDenied = 1 and B.DcrDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.MemberType = @MedType Union All Select RTrim(IsNull(C.LastName,'') + ', ' + IsNull(C.FirstName,'') + ' ' + IsNull(C.MiddleName,'')) [Patient Name], isnull(a.transdate,'') [Transmittal Date], Convert(varchar(10),B.AdmDate,101) + '-' + Convert(varchar(10),B.DcrDate,101) [Confinement], Cast(IsNull((Select Sum(IsNull(Amount,0)) from tbMedPayment Where IdNum = A.IdNum Group by IdNum),0) - IsNull( ( Select Cast( Sum( IsNull( MedRoomBoard, 0 ) + IsNull( MedDrug, 0 ) + IsNull( MedOthers, 0 ) + IsNull( MedOR, 0 ) ) as Decimal( 12, 2 ) ) from tbmedclaim Where IdNum = A.IdNum ), 0 )as money) [Amount], A.IdNum [IdNum], isnull(A.ReasonDenied, '') as ReasonDenied, isnull(DateDenied, '') as DateDenied, isnull(DateApproved,'') as DateApproved, isnull(DateDeniedMain, '') as DateDeniedMain, isnull(ReasonDeniedMain,'') as ReasonDeniedMain, isnull(DateAppealMain, '') as DateAppealMain, isnull(A.MemberNumber,'') as MemberNumber, isnull(E.Name,'') as MemberType, Convert(varchar(10),B.DcrDate,101) as DcrDate from tbMedPatient A Inner Join Patient_data..tbOutPatient B On A.IdNum = B.IdNum Inner Join Patient_data..tbMaster C On B.HospNum = C.HospNum Left Outer Join tbMedActual D On A.IdNum = D.IdNum Left Outer Join tbMedType E on A.MemberType = E.Code Where A.PaymentDenied = 1 and B.DcrDate Between @StartDate and @EndDate + ' 23:59:59.99' and A.MemberType = @MedType Order by [Patient Name] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'Medic_GetLoadRev') EXEC ('CREATE PROC dbo.Medic_GetLoadRev AS SELECT 1') GO USE [Medicare] GO /****** Object: StoredProcedure [dbo].[Medic_GetLoadRev] Script Date: 11/26/2012 10:03:43 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Medic_GetLoadRev] --'567643','jem','LB' @IDNum as varchar(10), @UserID as varchar(15), @RevenueID as varchar(5) AS Select a.Code,a.Description, [Phic Amount ]=(select isnull(SUM(cast(PhicAmount as money)),0) from medicare..tbmedsoa b where b.idnum = max(a.idnum) and b.RevenueID = (a.revenueid) and isnull(b.itemid,'') = isnull(a.code,'')), a.LocationID, Sum(cast(A.amount as money)) [Amount ], [temp] = (select isnull(SUM(cast(PhicAmount as money)),0) from medicare..tbmedsoa b where b.idnum = max(a.idnum) and b.RevenueID = (a.revenueid) and isnull(b.itemid,'') = isnull(a.code,'')) from Medicare..Medic_DumpTable a left outer join medicare..tbmedsoa b on a.idnum = b.idnum and isnull(a.code,'') = isnull(b.itemid,'') and a.RevenueID = b.RevenueID where a.UserID = @UserID and a.IdNum = @IDNum and a.RevenueID = @RevenueID and amount > 0 group by a.code, a.description, a.revenueid, a.locationid order by a.code GO USE [Medicare] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'MedicRep_PaymentRegister') EXEC ('CREATE PROC dbo.[MedicRep_PaymentRegister] AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[MedicRep_PaymentRegister] Script Date: 11/14/2012 14:55:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO ALTER PROCEDURE [dbo].[MedicRep_PaymentRegister] --'1','or0638020' @MemberType as varchar(1), @OrNumber as varchar(20) AS /*Select IsNull(A.IndexNumber,'') [Index Number], [Adm. #] = Case IsNull(C.IdNum,'') When '' Then IsNull(B.IdNum,'') Else IsNull(C.IdNum,'') End, [Confinement] = Case IsNull(C.IdNum,'') When '' Then Convert(varchar(10),B.AdmDate,101) + '-' + Convert(varchar(10),isnull(B.DcrDate,B.AdmDate),101) Else Convert(varchar(10),C.AdmDate,101) + '-' + Convert(varchar(10),isnull(C.DcrDate,C.AdmDate),101) End, [Patient Name] = Case IsNull(C.IdNum,'') When '' Then IsNull(D.LastName,'') + ', ' + IsNull(D.FirstName,'') + ' ' + IsNull(D.MiddleName,'') Else IsNull(E.LastName,'') + ', ' + IsNull(E.FirstName,'') + ' ' + IsNull(E.MiddleName,'') End, IsNull(H.LastName,'') + ', ' + IsNull(H.FirstName,'') + ' ' + IsNull(H.MiddleName,'') [Member], [Receivable] = (Case When (Select Count(Idnum) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0) > 1 Then Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and OrNumber = @ORnumber), 0 ) as money ) + (Cast( ( Case When A.PTB = 1 Or F.MR = 1 Then --0 Isnull((Select Cast(MedRoomBoard + MedDrug + MedOthers + MedOR as Money) --->> Corrected for MR From tbmedclaim where idnum = A.Idnum),0) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) Else ( ( IsNull(F.MedRoomBoard,0) + IsNull(F.MedDrug,0) + IsNull(F.MedOthers,0) + IsNull(F.MedOR,0) ) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) ) - Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 ), 0 ) as money ) End ) as money ) ) Else Cast( ( Case When A.PTB = 1 Or F.MR = 1 Then --0 Isnull((Select Cast(MedRoomBoard + MedDrug + MedOthers + MedOR as Money) --->> Corrected for MR From tbmedclaim where idnum = A.Idnum),0) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) Else ( ( IsNull(F.MedRoomBoard,0) + IsNull(F.MedDrug,0) + IsNull(F.MedOthers,0) + IsNull(F.MedOR,0) ) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) ) End ) as money ) End), [Payment] = Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and OrNumber = @ORnumber), 0 ) as money ), IsNull(G.OrNumber,'') [O.R. #], [Date Paid] = Case IsNull(G.DatePaid,'') When '' Then '' Else Convert(varchar(10),G.DatePaid,101) End, [TotalPayment] = Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and Ornumber = @OrNumber), 0 ) as money ), [Tax] = (select sum(Tax) from medicare..tbmedpayment where idnum = a.idnum) from Medicare..tbMedPatient A Left Outer Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Left Outer Join Patient_Data..tbOutPatient C On A.IdNum = C.IdNum Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.HospNum Left Outer Join Patient_Data..tbMaster E On C.HospNum = E.HospNum Left Outer Join Medicare..tbMedActual F On A.IdNum = F.IdNum Left Outer Join Medicare..tbMedPayment G On A.IdNum = G.IdNum Left Outer Join Medicare..tbMedMember H On A.MemberNumber = H.MemberNumber Where A.MemberType = @MemberType and G.OrNumber = @OrNumber Order by [Patient Name] */ Select IsNull(A.IndexNumber,'') [Index Number], [Adm. #] = A.Idnum, [Confinement] = Convert(varchar(10),A.AdmDate,101) + '-' + Convert(varchar(10),isnull(A.DcrDate,B.AdmDate),101), [Patient Name] = IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,''), IsNull(H.LastName,'') + ', ' + IsNull(H.FirstName,'') + ' ' + IsNull(H.MiddleName,'') [Member], [Receivable] = (Case When (Select Count(Idnum) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0) > 1 Then Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and OrNumber = @ORnumber), 0 ) as money ) + (Cast( ( Case When A.PTB = 1 Or F.MR = 1 Then --0 Isnull((Select Cast(MedRoomBoard + MedDrug + MedOthers + MedOR as Money) --->> Corrected for MR From tbmedclaim where idnum = A.Idnum),0) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) Else ( ( IsNull(F.MedRoomBoard,0) + IsNull(F.MedDrug,0) + IsNull(F.MedOthers,0) + IsNull(F.MedOR,0) ) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) ) - Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 ), 0 ) as money ) End ) as money ) ) Else Cast( ( Case When A.PTB = 1 Or F.MR = 1 OR Right(A.Idnum,1) = 'D' Then --0 Isnull((Select Cast(MedRoomBoard + MedDrug + MedOthers + MedOR as Money) --->> Corrected for MR From tbmedclaim where idnum = A.Idnum),0) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) Else ( ( IsNull(F.MedRoomBoard,0) + IsNull(F.MedDrug,0) + IsNull(F.MedOthers,0) + IsNull(F.MedOR,0) ) - ( IsNull(F.RefundRoomBoard,0) + IsNull(F.RefundDrug,0) + IsNull(F.RefundOthers,0) + IsNull(F.RefundOR,0) ) ) End ) as money ) End), [Payment] = Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and OrNumber = @ORnumber), 0 ) as money ), IsNull(G.OrNumber,'') [O.R. #], [Date Paid] = Case IsNull(G.DatePaid,'') When '' Then '' Else Convert(varchar(10),G.DatePaid,101) End, [TotalPayment] = Cast( IsNull( ( Select Sum(IsNull(Amount,0)) from Medicare..tbMedPayment Where IdNum = A.IdNum and Denied = 0 and Ornumber = @OrNumber), 0 ) as money ), [PF Payment] = (select sum(payment) from medicare..tbmeddoctors where idnum = a.idnum and ornumber = g.ornumber), [Tax] = (select sum(Tax) from medicare..tbmedpayment where idnum = a.idnum) from Medicare..tbMedPatient A Left Outer Join Patient_Data..tbPatient B On A.IdNum = B.IdNum Left Outer Join Patient_Data..tbOutPatient C On A.IdNum = C.IdNum Left Outer Join Patient_Data..tbMaster D On B.HospNum = D.HospNum Left Outer Join Patient_Data..tbMaster E On C.HospNum = E.HospNum Left Outer Join Medicare..tbMedActual F On A.IdNum = F.IdNum Left Outer Join Medicare..tbMedPayment G On A.IdNum = G.IdNum Left Outer Join Medicare..tbMedMember H On A.MemberNumber = H.MemberNumber Where A.MemberType = @MemberType and G.OrNumber = @OrNumber Order by [Patient Name] GO USE [Medicare] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'MedicRep_GetNewUnderPaidAll') EXEC ('CREATE PROC dbo.[MedicRep_GetNewUnderPaidAll] AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[MedicRep_GetNewUnderPaidAll] Script Date: 11/26/2012 10:03:13 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.MedicRep_GetNewUnderPaid Script Date: 10/11/2010 1:19:55 AM ******/ ALTER PROCEDURE [dbo].[MedicRep_GetNewUnderPaidAll] @strStartDate as varchar(10), @strEndDate as varchar(10) AS Select IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'') [Patient Name], IsNull(A.IDNum,'') IDNum, IsNull(Z.LastName,'') + ', ' + IsNull(Z.FirstName,'') + ' ' + IsNull(Z.MiddleName,'') [Member Name], IsNull(A.MemberNumber,'') MemberNum, Cast( IsNull( MedRoomBoard, 0) As Decimal( 12, 2 ) ) MedRoomBoard, Cast( IsNull( MedDrug, 0 ) As Decimal( 12, 2 ) ) MedDrug, Cast( IsNull( MedOthers, 0 ) As Decimal( 12, 2 ) ) MedOthers, Cast( IsNull( MedOR, 0 ) As Decimal( 12, 2 ) ) MedOR, IsNull( ( Select Cast( Sum( IsNull(RoomBoardAmt,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IDNum ), 0 ) AS RoomBoardAmt, IsNull( ( Select Cast( Sum( IsNull(DrugAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS DrugAmt, IsNull( ( Select Cast( Sum( IsNull(OthersAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS OthersAmt, IsNull( ( Select Cast( Sum( IsNull(ORAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS ORAmt, Convert(Varchar(10), A.AdmDate, 101) + ' - ' + Convert(Varchar(10), A.DcrDate, 101) ConfinementDate, dbo.fn_GetAPVNum(A.IDNum) APVNum, dbo.fn_GetPaymentDate(A.IDNum) ORDate, dbo.fn_GetPaymentORNumber(A.IDNum) ORNum, dbo.fn_GetMemberType(A.MemberType) MemberType From Medicare..tbMedPatient as A Left Outer Join (Select IDNum, Sum(Amount) Amount, Sum(RoomBoardAmt) RoomBoardAmt, Sum(DrugAmt) DrugAmt, Sum(OthersAmt) OthersAmt, Sum(ORAmt) ORAmt From (Select IDNum, IsNull(Amount,0) Amount, IsNull(DrugAmt,0) DrugAmt, IsNull(RoomBoardAmt,0) RoomBoardAmt, IsNull(OthersAmt,0) OthersAmt, IsNull(ORAmt,0) ORAmt From Medicare..tbMedPayment Where DatePaid Between @strStartDate and @strEndDate + ' 23:59:59.99' ) X Group By IDNum ) As B On B.IdNum = A.IdNum Left Outer Join Medicare..tbMedActual As C On C.IdNum = A.IdNum left outer join Medicare..tbMedMember Z on z.MemberNumber = A.membernumber Where ( ( Case IsNull(A.IdNum,'') When '' Then 0 Else Cast( IsNull( MedRoomBoard, 0 ) As Decimal( 12, 2 ) ) + Cast( IsNull( MedDrug, 0 ) As Decimal( 12, 2 ) )+ Cast( IsNull( MedOthers, 0 ) As Decimal( 12, 2 ) ) + Cast( IsNull( MedOR, 0 ) As Decimal( 12, 2 ) ) End ) - ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( (Select IsNull( Cast( Sum(IsNull(Amount,0)) + Sum(IsNull(Tax,0)) as Decimal( 12, 2 ) ), 0 ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0) End ) ) > 0 And B.Amount > 0 Order by [Patient Name] GO USE [Medicare] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'MedicRep_GetNewUnderPaidAll') EXEC ('CREATE PROC dbo.[MedicRep_GetNewUnderPaidAll] AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[MedicRep_GetNewUnderPaid] Script Date: 11/26/2012 10:02:58 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /****** Object: Stored Procedure dbo.MedicRep_GetNewUnderPaid Script Date: 10/11/2010 1:19:55 AM ******/ ALTER PROCEDURE [dbo].[MedicRep_GetNewUnderPaid] --'01/22/2012','10/01/2012','1' @strStartDate as varchar(10), @strEndDate as varchar(10), @strMedType as varchar(1) As Select IsNull(A.LastName,'') + ', ' + IsNull(A.FirstName,'') + ' ' + IsNull(A.MiddleName,'') [Patient Name], IsNull(A.IDNum,'') IDNum, IsNull(Z.LastName,'') + ', ' + IsNull(Z.FirstName,'') + ' ' + IsNull(Z.MiddleName,'') [Member Name], IsNull(A.MemberNumber,'') MemberNum, Cast( IsNull( MedRoomBoard, 0) As Decimal( 12, 2 ) ) MedRoomBoard, Cast( IsNull( MedDrug, 0 ) As Decimal( 12, 2 ) ) MedDrug, Cast( IsNull( MedOthers, 0 ) As Decimal( 12, 2 ) ) MedOthers, Cast( IsNull( MedOR, 0 ) As Decimal( 12, 2 ) ) MedOR, IsNull( ( Select Cast( Sum( IsNull(RoomBoardAmt,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IDNum ), 0 ) AS RoomBoardAmt, IsNull( ( Select Cast( Sum( IsNull(DrugAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS DrugAmt, IsNull( ( Select Cast( Sum( IsNull(OthersAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS OthersAmt, IsNull( ( Select Cast( Sum( IsNull(ORAmt,0) ) as Decimal( 12, 2 ) ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0 ) AS ORAmt, Convert(Varchar(10), A.AdmDate, 101) + ' - ' + Convert(Varchar(10), A.DcrDate, 101) ConfinementDate, dbo.fn_GetAPVNum(A.IDNum) APVNum, dbo.fn_GetPaymentDate(A.IDNum) ORDate, dbo.fn_GetPaymentORNumber(A.IDNum) ORNum From Medicare..tbMedPatient as A Left Outer Join (Select IDNum, Sum(Amount) Amount, Sum(RoomBoardAmt) RoomBoardAmt, Sum(DrugAmt) DrugAmt, Sum(OthersAmt) OthersAmt, Sum(ORAmt) ORAmt From (Select IDNum, IsNull(Amount,0) Amount, IsNull(DrugAmt,0) DrugAmt, IsNull(RoomBoardAmt,0) RoomBoardAmt, IsNull(OthersAmt,0) OthersAmt, IsNull(ORAmt,0) ORAmt From Medicare..tbMedPayment Where DatePaid Between @strStartDate and @strEndDate + ' 23:59:59.99' ) X Group By IDNum ) As B On B.IdNum = A.IdNum left outer join Medicare..tbMedMember Z on A.MemberNumber = Z.membernumber Left Outer Join Medicare..tbMedActual As C On C.IdNum = A.IdNum Where ( ( Case IsNull(A.IdNum,'') When '' Then 0 Else Cast( IsNull( MedRoomBoard, 0 ) As Decimal( 12, 2 ) ) + Cast( IsNull( MedDrug, 0 ) As Decimal( 12, 2 ) )+ Cast( IsNull( MedOthers, 0 ) As Decimal( 12, 2 ) ) + Cast( IsNull( MedOR, 0 ) As Decimal( 12, 2 ) ) End ) - ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( (Select IsNull( Cast( Sum(IsNull(Amount,0)) + Sum(IsNull(Tax,0)) as Decimal( 12, 2 ) ), 0 ) From Medicare..tbMedPayment Where IDNum = A.IDNum ), 0) End ) ) > 0 and A.MemberType = @strMedType And B.Amount > 0 Order by [Patient Name] GO USE [Medicare] GO IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'MedicRep_GetUnPaidNEW') EXEC ('CREATE PROC dbo.[MedicRep_GetUnPaidNEW] AS SELECT 1') GO /****** Object: StoredProcedure [dbo].[MedicRep_GetUnPaidNEW] Script Date: 11/26/2012 09:36:06 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[MedicRep_GetUnPaidNEW] @StartDate as varchar(10), @EndDate as varchar(10) As Select distinct IsNull(D.LastName,'') [LastName], IsNull(D.FirstName,'') [FirstName], IsNull(D.MiddleName,'') [Middle Name], case when right(D.lastname,1) = '.' then right(D.lastname,3) else '' end as [ExtPatient], IsNull(A.IdNum,'') [AdmNum], ISNULL(E.MemberNumber,'') [MemberNum], IsNull(F.LastName,'') [MLastName], IsNull(F.FirstName,'') [MFirstName], IsNull(F.MiddleName,'') [MMiddle Name], case when right(F.lastname,1) = '.' then right(F.lastname,3) else '' end as [ExtMember], convert(Varchar(10), C.AdmDate, 101) [AdmDate], convert(Varchar(10), C.DcrDate, 101) [DcrDate], convert(Varchar(10), F.BirthDate, 101) [BirthDate], IsNull( ( Select Cast( Sum( IsNull( MedRoomBoard, 0 ) + IsNull( MedDrug, 0 ) + IsNull( MedOthers, 0 ) + IsNull( MedOR, 0 ) ) as Decimal( 12, 2 ) ) from tbMedActual Where IdNum = A.IdNum ), 0 ) [PHIC Benefit], IsNull( ( Select Cast( Sum( IsNull( ActualRoomBoard, 0 ) + IsNull( ActualDrug, 0 ) + IsNull( ActualOthers, 0 ) + IsNull( ActualOR, 0 ) ) as Decimal( 12, 2 ) ) from tbMedActual Where IdNum = A.IdNum ), 0 ) [Total Charge] from tbMedActual A Inner Join Patient_Data..tbPatient C On A.IdNum = C.IdNum Inner Join Patient_Data..tbMaster D On C.HospNum = D.HospNum inner join Medicare..tbMedPatient E on A.IdNum = E.IdNum inner join Medicare..tbMedMember F on E.MemberNumber = F.MemberNumber inner join Medicare..tbMedPayment G on C.IdNum = G.IdNum Where ( ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = A.IdNum ), 0 ) End ) - ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( IsNull(Amount,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IdNum )+ ( Select Cast( Sum( IsNull(Tax,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IdNum ), 0 ) End ) ) > 0 and IsNull( ( Select Cast( Sum( IsNull(Amount,0) ) as money ) from tbMedPayment Where IdNum = A.IdNum ) + ( Select Cast( Sum( IsNull(Tax,0) ) as money ) from tbMedPayment Where IdNum = A.IdNum ), 0 ) > 0 and (G.DatePaid Between @StartDate and @EndDate + ' 23:59:59.99') Union All Select distinct IsNull(D.LastName,'') [LastName], IsNull(D.FirstName,'') [FirstName], IsNull(D.MiddleName,'') [Middle Name], case when right(D.lastname,1) = '.' then right(D.lastname,3) else '' end as [ExtPatient], IsNull(A.IdNum,'') [AdmNum], ISNULL(E.MemberNumber,'') [MemberNum], IsNull(F.LastName,'') [MLastName], IsNull(F.FirstName,'') [MFirstName], IsNull(F.MiddleName,'') [MMiddle Name], case when right(F.lastname,1) = '.' then right(F.lastname,3) else '' end as [ExtMember], convert(Varchar(10), C.AdmDate, 101) [AdmDate], convert(Varchar(10), C.DcrDate, 101) [DcrDate], convert(Varchar(10), F.BirthDate, 101) [BirthDate], IsNull( ( Select Cast( Sum( IsNull( MedRoomBoard, 0 ) + IsNull( MedDrug, 0 ) + IsNull( MedOthers, 0 ) + IsNull( MedOR, 0 ) ) as Decimal( 12, 2 ) ) from tbMedActual Where IdNum = A.IdNum ), 0 ) [PHIC Benefit], IsNull( ( Select Cast( Sum( IsNull( ActualRoomBoard, 0 ) + IsNull( ActualDrug, 0 ) + IsNull( ActualOthers, 0 ) + IsNull( ActualOR, 0 ) ) as Decimal( 12, 2 ) ) from tbMedActual Where IdNum = A.IdNum ), 0 ) [Total Charge] from tbMedActual A Inner Join Patient_Data..tbOutPatient C On A.IdNum = C.IdNum Inner Join Patient_Data..tbMaster D On C.HospNum = D.HospNum inner join Medicare..tbMedPatient E on A.IdNum = E.IdNum inner join Medicare..tbMedMember F on E.MemberNumber = F.MemberNumber inner join Medicare..tbMedPayment G on C.IdNum = G.IdNum Where ( ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( ( IsNull( MedRoomBoard, 0 ) - IsNull( RefundRoomBoard, 0) ) + ( IsNull( MedDrug, 0 ) - IsNull( RefundDrug, 0) ) + ( IsNull( MedOthers, 0 ) - IsNull( RefundOthers, 0) ) + ( IsNull( MedOR, 0 ) - IsNull( RefundOR, 0) ) ) as Decimal( 12, 2 ) ) from Medicare..tbMedActual Where IdNum = A.IdNum ), 0 ) End ) - ( Case IsNull(A.IdNum,'') When '' Then 0 Else IsNull( ( Select Cast( Sum( IsNull(Amount,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IdNum )+ ( Select Cast( Sum( IsNull(Tax,0) ) as Decimal( 12, 2 ) ) from Medicare..tbMedPayment Where IdNum = A.IdNum ), 0 ) End ) ) > 0 and IsNull( ( Select Cast( Sum( IsNull(Amount,0) ) as money ) from tbMedPayment Where IdNum = A.IdNum ) + ( Select Cast( Sum( IsNull(Tax,0) ) as money ) from tbMedPayment Where IdNum = A.IdNum ), 0 ) > 0 and (g.datepaid Between @StartDate and @EndDate + ' 23:59:59.99') GO use patient_data go ------------------------------------------------------------- alter table patient_data..tbmaster2 add PHICNum varchar(50) null GO ------------------------------------------------------------- USE [Patient_Data] GO /****** Object: StoredProcedure [dbo].[sp_AOPD_Load_TbMaster] Script Date: 05/21/2012 12:55:59 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_AOPD_Load_TbMaster') EXEC ('CREATE PROC dbo.sp_sp_AOPD_Load_TbMaster AS SELECT 1') GO ALTER PROCEDURE [dbo].[sp_AOPD_Load_TbMaster] @Hospnum as varchar(10) AS Select m.hospnum, isnull(m.lastname,'') as Lastname, isnull(m.firstname,'') as FirstName, isnull(m.middlename,'') as MiddleName, isnull(m.housestreet,'')as HouseStreet, isnull(m.barangay,'') as Barangay, m.Zipcode, (case when isnull(c.town,'') + ', ' + isnull(c.province,'') = ', ' then '' else isnull(c.town,'') + ', ' + isnull(c.province,'') End) as province, isnull(m.telnum,'') as TelNum, m.birthdate as BirthDate, isnull(m.sex,'') as Sex, isnull(m.age,0) as Age, isnull(m2.Employer,'') as Employer, isnull(m2.EmployerAddress,'') as EmployerAddress, isNull(m2.EmployerTelNum,'') as EmployerTelNum, M.CivilStatus , isnull(convert(varchar(10),m.GovDiscountExpiry,101),'') as GovDiscountExpiry, isNull(M.BloodType,'') [BloodType] , isNull(M2.BirthPlace,'') [BirthPlace], isNull(M.Occupation,'') [Occupation] , isNull(N.Nationality,'') [Nationality] , isNull(R.Religion,'') [Religion], isnull(M2.NationalityID,'') AS NationalityID, isnull(M2.ReligionID,'') AS ReligionID, isnull(M.Title,'') AS Title, SSSGSISNum, m2.phicnum from tbmaster m left outer join Build_File..tbcoaddress c on m.zipcode = c.zipcode left outer join tbMaster2 m2 on m.hospNum=m2.HospNum left outer join tbPatient P on m.HospNum=p.HospNum left outer join build_file..tbcoNationality N on N.NationalityID = M2.NationalityID left outer join build_file..tbcoReligion R on R.ReligionID = M2.ReligionID where m.hospnum = @HospNum insert into patient_data..tbopdmenu (MenuID,Menu,Status,MenuGroup,MainMenu)values('81','User Logs','1','A','2') alter table Patient_data..tbHospitalInfo add OtherInfo text insert into patient_data..tbopdmenu (MenuID,Menu,Status,MenuGroup,MainMenu)values('82','User Validation','1','A','2') set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go alter table Patient_data..tbopd_settings add MarkUp bit go ------------------------------------------------------------- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'OPD_SaveOPDSettings') EXEC ('CREATE PROC dbo.OPD_SaveOPDSettings AS SELECT 1') GO ALTER Procedure [dbo].[OPD_SaveOPDSettings] @isAllowNewOPSTatRate varchar(1), @isAllowHolidayRate varchar(1), @isAllowAfterFivePMRate varchar(1), @isAllowWeekendRate varchar(1), @isAllowAfterFiveLabChemOnly varchar(1), @isAllowAfterFiveAllRevenues varchar(1), @OPDStatRate float, @HolidayRate float, @AfterFivePmRate float, @WeekendRate float, @MaxMarkUpRate float, @StatAndAfterFivePMRate float, @StatAndWeekendRate float, @HolidayAndWeekend float, @HolidayAndAfterFivePMRate float, @WeekendAfterFive float, @dtWeekendStartMarkUp smalldatetime, @dtWeekendEndMarkUp smalldatetime, @isAssessmentMarkUp as varchar(1), @isPostChargeMarkup as varchar(1), @dtWeekendStartMarkUp2 smalldatetime, @dtWeekendEndMarkUp2 smalldatetime, @MarkUp as bit as Select top 1 * from Patient_data..tbopd_settings; if @@rowcount > 0 begin Update Patient_data..tbOPd_settings set isAllowNewOPSTatRate = @isAllowNewOPSTatRate, isAllowHolidayRate = @isAllowHolidayRate, isAllowAfterFivePMRate = @isAllowAfterFivePMRate, isAllowWeekendRate = @isAllowWeekendRate, isAllowAfterFiveLabChemOnly = @isAllowAfterFiveLabChemOnly, isAllowAfterFiveAllRevenues = @isAllowAfterFiveAllRevenues, OPDStatRate = @OPDStatRate, HolidayRate = @HolidayRate, AfterFivePmRate = @AfterFivePmRate, WeekendRate = @WeekendRate, MaxMarkUpRate = @MaxMarkUpRate, StatAndAfterFivePMRate = @StatAndAfterFivePMRate, StatAndWeekendRate = @StatAndWeekendRate, HolidayAndWeekend = @HolidayAndWeekend, HolidayAndAfterFivePMRate = @HolidayAndAfterFivePMRate, WeekendAfterFive = @WeekendAfterFive, dtWeekendStartMarkUp = @dtWeekendStartMarkUp, dtWeekendEndMarkUp = @dtWeekendEndMarkUp, isAssesmentMarkup = @isAssessmentMarkUp, isPostChargeMarkUp = @isPostChargeMarkup, dtWeekendStartMarkUp2 = @dtWeekendStartMarkUp2, dtWeekendEndMarkUp2 = @dtWeekendEndMarkUp2, MarkUp = @MarkUp end else begin insert into patient_data..tbopd_settings( isAllowNewOPSTatRate, isAllowHolidayRate, isAllowAfterFivePMRate, isAllowWeekendRate, isAllowAfterFiveLabChemOnly, isAllowAfterFiveAllRevenues,OPDStatRate, HolidayRate, AfterFivePmRate, WeekendRate, MaxMarkUpRate, StatAndAfterFivePMRate, StatAndWeekendRate, HolidayAndWeekend, HolidayAndAfterFivePMRate, WeekendAfterFive, dtWeekendStartMarkUp, dtWeekendEndMarkUp, isAssesmentMarkup, isPostChargeMarkUp, dtWeekendStartMarkUp2,dtWeekendEndMarkUp2,MarkUp) values (@isAllowNewOPSTatRate, @isAllowHolidayRate, @isAllowAfterFivePMRate, @isAllowWeekendRate, @isAllowAfterFiveLabChemOnly, @isAllowAfterFiveAllRevenues,@OPDStatRate, @HolidayRate, @AfterFivePmRate, @WeekendRate, @MaxMarkUpRate, @StatAndAfterFivePMRate, @StatAndWeekendRate, @HolidayAndWeekend, @HolidayAndAfterFivePMRate, @WeekendAfterFive, @dtWeekendStartMarkUp, @dtWeekendEndMarkUp, @isAssessmentMarkUp,@isPostChargeMarkup,@dtWeekendStartMarkUp2,@dtWeekendEndMarkUp2,@MarkUp) end GO --6/1/2012-------------------------------------------- alter table Patient_data..tbOutPatient add isDiabet bit null alter table Patient_data..tbOutPatient add isHomeCare bit null alter table patient_data..tbmaster2 add OfficeNum varchar(50) IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Adm_UpdateMaster2') EXEC ('CREATE PROC dbo.sp_Adm_UpdateMaster2 AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Adm_UpdateMaster2] @HospNum As VarChar(8), @BirthPlace As VarChar(50), @NationalityID As VarChar(2), @ReligionID As VarChar(2), @Spouse As VarChar(50), @Mother As VarChar(50), @Father As VarChar(50), @Employer As VarChar(50), @EmployerAddress As VarChar(50), @EmployerTelNum As VarChar(15), @ContactName As VarChar(50), @ContactAddress As VarChar(50), @ContactRelation As VarChar(50), @ContactTelNum As VarChar(15) , @SpouseAddress varchar(50) , @SpouseTelNum varchar(15) , @FatherAddress varchar(50) , @FatherTelNum varchar(15) , @MotherAddress varchar(50) , @MotherTelNum varchar(15) , @BarangayCaptain varchar(50) , @Position varchar (50) , @EmploymentType varchar(1), @EmploymentLocation varchar(1) , @EmployerFax varchar(15) , @EmployerEmail varchar(50) , @SpouseEmpName varchar(50) , @SpouseEmpAddress varchar(50) , @SpouseEmpTelNum varchar(15) , @SpouseEmpFax varchar(15) , @SpouseEmpEmail varchar(50) , @PHIC varchar(1) , @Insurance varchar(50) , @HouseHold varchar(10) , @Email varchar(50) , @CellNum varchar(15), @OfficeNum varchar(50) AS Declare @NewHospNum VarChar(8) Select @NewHospNum = Hospnum From tbMaster2 Where HospNum = @HospNum; Update tbMaster set Email = @Email, CellNum = @CellNum Where HospNum = @HospNum; If Len(@NewHospNum) > 0 Begin Update tbMaster2 Set BirthPlace = @BirthPlace, NationalityID = @NationalityID, ReligionID = @ReligionID, Spouse = @Spouse, Mother = @Mother, Father = @Father, Employer = @Employer, EmployerAddress = @EmployerAddress, EmployerTelNum = @EmployerTelNum, ContactName = @ContactName, ContactAddress = @ContactAddress, ContactRelation = @ContactRelation, ContactTelNum = @ContactTelNum , SpouseAddress = @SpouseAddress , SpouseTelNum = @SpouseTelNum , FatherAddress = @FatherAddress , FatherTelNum = @FatherTelNum , MotherAddress = @MotherAddress , MotherTelNum = @MotherTelNum , BarangayCaptain = @BarangayCaptain , Position = @Position , EmploymentType = @EmploymentType , EmploymentLocation = @EmploymentLocation , EmployerFax = @EmployerFax , EmployerEmail = @EmployerEmail , SpouseEmpName = @SpouseEmpName , SpouseEmpAddress = @SpouseEmpAddress , SpouseEmpTelNum = @SpouseEmpTelNum , SpouseEmpFax = @SpouseEmpFax , SpouseEmpEmail = @SpouseEmpEmail , PhilHealth = @PHIC , Insurance = @Insurance , HouseHold = @HouseHold, OfficeNum = @OfficeNum Where HospNum = @HospNum ; End Else Begin Insert Into tbMaster2 (HospNum,BirthPlace, NationalityID,ReligionID,Spouse, Mother, Father, Employer, EmployerAddress, EmployerTelNum, ContactName, ContactAddress, ContactRelation, ContactTelNum , SpouseAddress , SpouseTelNum , FatherAddress , FatherTelNum , MotherAddress , MotherTelNum , BarangayCaptain ,Position , EmploymentType,EmploymentLocation, EmployerFax ,EmployerEmail , SpouseEmpName , SpouseEmpAddress , SpouseEmpTelNum , SpouseEmpFax , SpouseEmpEmail, PhilHealth, Insurance, HouseHold, OfficeNum ) Values (@HospNum, @BirthPlace, @NationalityID, @ReligionID, @Spouse, @Mother, @Father, @Employer, @EmployerAddress, @EmployerTelNum, @ContactName, @ContactAddress, @ContactRelation, @ContactTelNum, @SpouseAddress , @SpouseTelNum , @FatherAddress , @FatherTelNum , @MotherAddress , @MotherTelNum , @BarangayCaptain , @Position , @EmploymentType, @EmploymentLocation, @EmployerFax , @EmployerEmail , @SpouseEmpName , @SpouseEmpAddress , @SpouseEmpTelNum , @SpouseEmpFax , @SpouseEmpEmail, @PHIC, @Insurance, @HouseHold, @OfficeNum); End go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_Adm_UpdateMaster2') EXEC ('CREATE PROC dbo.sp_Adm_UpdateMaster2 AS SELECT 1') GO set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_Adm_LoadPatient] @HospNum AS VarChar(8) AS if exists(SELECT * FROM tbMaster M WHERE M.HospNum = @HospNum) begin Select M.HospNum, isnull(M.LastName,'') as LastName, isnull(M.FirstName,'') as FirstName, isnull(M.MiddleName,'') as MiddleName, M.AccountNum, ISNULL(M.HouseStreet,'') HouseStreet, ISNULL(M.Barangay,'') Barangay, ISNULL(M.ZipCode,'') ZipCode, ISNULL(M.Sex,'') Sex, M.BirthDate, M.CivilStatus, ISNULL(M.Occupation,'') Occupation, ISNULL(M.Age,'') Age, ISNULL(M.TelNum,'') TelNum, ISNULL(M.PatientStatus,'') PatientStatus, ISNULL(M.OPDNum,'') OPDNum, ISNULL(M.XrayNum,'') XrayNum, ISNULL(M.UltraNum,'') UltraNum, ISNULL(M.SSSGSISNum,'') SSSGSISNum, ISNULL(M.CTNum,'') CTNum, ISNULL(M2.BirthPlace,'') BirthPlace, ISNULL(M2.NationalityID,'') NationalityID, ISNULL(M2.ReligionID,'') ReligionID, ISNULL(M2.Spouse,'') Spouse, ISNULL(M2.Father,'') Father, ISNULL(M2.Mother,'') Mother, ISNULL(M2.Employer,'') Employer, ISNULL(M2.EmployerAddress, '') EmployerAddress, ISNULL(M2.EmployerTelNum,'') EmployerTelNum, ISNULL(M2.ContactName,'') ContactName, ISNULL(M2.ContactAddress,'') ContactAddress, ISNULL(M2.ContactRelation,'') ContactRelation, ISNULL(M2.ContactTelNum,'') ContactTelNum, ISNULL(M.BloodType,'') BloodType, ISNULL(M2.MotherAddress,'') MotherAddress, ISNULL(M2.MotherTelNum, '') MotherTelNum, ISNULL(M2.FatherAddress,'') FatherAddress, ISNULL(M2.FatherTelNum,'') FatherTelNum, ISNULL(M2.SpouseAddress,'') SpouseAddress, ISNULL(M2.SpouseTelNum,'') SpouseTelNum, ISNULL(M2.barangaycaptain,'') barangaycaptain , ISNULL(M2.Position,'') [Position], ISNULL(M2.EmploymentType,0) [EmploymentType], ISNULL(M2.EmploymentLocation,0) [EmploymentLocation], ISNULL(M2.EmployerFax,'') [EmployerFax] , ISNULL(M2.EmployerEmail,'') [EmployerEmail], ISNULL(M2.SpouseEmpName,'') [SpouseEmpName], ISNULL(M2.SpouseEmpAddress,'') [SpouseEmpAddress], ISNULL(M2.SpouseEmpTelNum,'') [SpouseEmpTelNum], ISNULL(M2.SpouseEmpFax,'') [SpouseEmpFax] , ISNULL(M2.SpouseEmpEmail,'') [SpouseEmpEmail], ISNULL(M2.PhilHealth,0) [PhilHealth], ISNULL(M2.Insurance,'')[Insurance], ISNULL(M2.HouseHold,'') [HouseHold] , ISNULL(M2.OfficeNum,'') [OfficeNum], ISNULL(M.CellNum,'') [CellNum], ISNULL(M.Email,'') [Email] FROM tbMaster M LEFT OUTER JOIN tbMaster2 M2 ON M.HospNum = M2.HospNum WHERE M.HospNum = @HospNum end else begin Select M.HospNum, isnull(M.LastName,'') as LastName, isnull(M.FirstName,'') as FirstName, isnull(M.MiddleName,'') as MiddleName, M.AccountNum, M.HouseStreet, M.Barangay, M.ZipCode, M.Sex, M.BirthDate, M.CivilStatus, M.Occupation, M.Age, M.TelNum, M.PatientStatus, M.OPDNum, M.XrayNum, M.UltraNum, M.SSSGSISNum, M.CTNum, M2.BirthPlace, M2.NationalityID, M2.ReligionID, M2.Spouse, M2.Father, M2.Mother, M2.Employer, M2.EmployerAddress, M2.EmployerTelNum, M2.ContactName, M2.ContactAddress, M2.ContactRelation, M2.ContactTelNum, M.BloodType, M2.MotherAddress, M2.MotherTelNum, M2.FatherAddress, M2.FatherTelNum, M2.SpouseAddress, M2.SpouseTelNum, M2.barangaycaptain , ISNULL(M2.Position,'') [Position], ISNULL(M2.EmploymentType,0) [EmploymentType], ISNULL(M2.EmploymentLocation,0) [EmploymentLocation], ISNULL(M2.EmployerFax,'') [EmployerFax] , ISNULL(M2.EmployerEmail,'') [EmployerEmail], ISNULL(M2.SpouseEmpName,'') [SpouseEmpName], ISNULL(M2.SpouseEmpAddress,'') [SpouseEmpAddress], ISNULL(M2.SpouseEmpTelNum,'') [SpouseEmpTelNum], ISNULL(M2.SpouseEmpFax,'') [SpouseEmpFax] , ISNULL(M2.SpouseEmpEmail,'') [SpouseEmpEmail], ISNULL(M2.PhilHealth,0) [PhilHealth], ISNULL(M2.Insurance,'')[Insurance], ISNULL(M2.HouseHold,'') [HouseHold] ,ISNULL(M2.OfficeNum,'') [OfficeNum], ISNULL(M.CellNum,'') [CellNum], ISNULL(M.Email,'') [Email] FROM tbPastMaster M LEFT OUTER JOIN tbMaster2 M2 ON M.HospNum = M2.HospNum WHERE M.HospNum = @HospNum end go set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'dbo' AND ROUTINE_NAME = 'sp_AOPD_SearchRevenue') EXEC ('CREATE PROC dbo.sp_AOPD_SearchRevenue AS SELECT 1') GO ALTER PROCEDURE [dbo].[sp_AOPD_SearchRevenue] @SearchType varchar(1), @SearchCriteria varchar(50) AS if @SearchType = '0' begin select r.ItemName [Description], r.RevenueID [Code] from BUILD_FILE..tbCoRevenueCode r where ISNULL(r.OPDActive, '') = 'Y' and r.RecordStatus = 'A' and r.ItemName like @SearchCriteria + '%' order by r.ItemName end if @SearchType = '1' begin /*select r.ItemName [Revenue], r.RevenueID, r.RWith [WithItems], r.SearchInventory, r.LocationID, from BUILD_FILE..tbCoRevenueCode r where ISNULL(r.OPDActive, '') = 'Y' and r.RecordStatus = 'A' --AND r.revenueid = 'CT' OR REVENUEID = 'LB' OR REVENUEID = 'EM' OR REVENUEID = 'OX'--AND r.revenueid = 'EL' OR REVENUEID = 'ER' OR REVENUEID = 'EM' OR REVENUEID = 'OX' or r.REVENUEID = 'PT' OR REVENUEID = 'MD' OR REVENUEID = 'PA' and r.RevenueID = @SearchCriteria */ select r.ItemName [Revenue], r.RevenueID, r.RWith [WithItems], r.SearchInventory, r.LocationID,b.Revenueid [InvCode] from BUILD_FILE..tbCoRevenueCode r left join BILLING..tbBillInvCode b on r.Revenueid = b.ServiceID where r.RecordStatus = 'A' AND --(r.revenueid = 'EL' OR r.REVENUEID = 'ER' OR r.REVENUEID = 'EM' OR r.REVENUEID = 'OX') AND r.RevenueID = @SearchCriteria end if @SearchType = '2' begin select Count(*) [RecCount] from BUILD_FILE..tbCoRevenueCode r where ISNULL(r.OPDActive, '') = 'Y' and r.RecordStatus = 'A' --AND r.revenueid = 'CT' OR REVENUEID = 'LB' OR REVENUEID = 'EM' OR REVENUEID = 'OX' --or r.REVENUEID = 'PT' OR REVENUEID = 'MD' OR REVENUEID = 'PA' and r.ItemName like @SearchCriteria + '%' end if @SearchType = '3' --with inventory code begin select r.ItemName [Revenue], r.RevenueID, r.RWith [WithItems], r.SearchInventory, r.LocationID, r.StockCardRevenueID [InventoryCode] from BUILD_FILE..tbCoRevenueCode r where ISNULL(r.OPDActive, '') = 'Y' and r.RecordStatus = 'A' --AND r.revenueid = 'CT' OR REVENUEID = 'LB' OR REVENUEID = 'EM' OR REVENUEID = 'OX'--AND r.revenueid = 'EL' OR REVENUEID = 'ER' OR REVENUEID = 'EM' OR REVENUEID = 'OX' or r.REVENUEID = 'PT' OR REVENUEID = 'MD' OR REVENUEID = 'PA' and r.RevenueID = @SearchCriteria end if @SearchType = '4' begin select r.ItemName [Description], r.RevenueID [Code] from BUILD_FILE..tbCoRevenueCode r where ISNULL(r.OPDActive, '') = 'Y' and r.RecordStatus = 'A' and r.IsPatientCard ='1' and r.ItemName like @SearchCriteria + '%' order by r.ItemName end go USE [Password] GO /****** Object: StoredProcedure [dbo].[sp_Pass_SaveUser] Script Date: 11/06/2013 18:34:41 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_Pass_SaveUser] @EmployeeID varchar(10), @LastName varchar(15), @FirstName varchar(20), @MiddleName varchar(15), @Initial varchar(3), @BirthDate varchar(12), @Password varchar(32), @DepartmentID varchar(4), @OldDepartmentID varchar(4), @Position varchar(25), @RightCode1 varchar(1), @RightCode2 varchar(1) AS DECLARE @Name varchar(50) /* for backcompatibility */ declare @cBirth varchar(5) SET @Name = @LastName + ' ' + @FirstName + ' ' + @MiddleName IF NOT EXISTS( SELECT EmployeeID FROM tbPasswordMain WHERE EmployeeID = @EmployeeID AND DepartmentID = @DepartmentID) INSERT INTO tbPasswordMain (EmployeeID, LastName, FirstName, MiddleName, Initial, BirthDate, Password, DepartmentID, OriginalDepartment, Position, Right_Code1, Right_Code2, ODeptArt, SiteCode) VALUES (@EmployeeID, @LastName, @FirstName, @MiddleName, @Initial, @BirthDate, @Password, @DepartmentID, @OldDepartmentID, @Position, @RightCode1, @RightCode2, '', '') ELSE UPDATE tbPasswordMain SET LastName = @LastName, FirstName = @FirstName, MiddleName = @MiddleName, Initial = @Initial, BirthDate = @BirthDate, [Password] = @Password, DepartmentID = @DepartmentID, OriginalDepartment = @OldDepartmentID, Position = @Position, Right_Code1 = @RightCode1, Right_Code2 = @RightCode2, ODeptArt = '', SiteCode = '' WHERE EmployeeID = @EmployeeID AND DepartmentID = @DepartmentID /* save to master file -- forward compatability */ if isdate(@BirthDate) = 1 begin if cast(@BirthDate as datetime) <= '01/01/1900' begin set @cBirth = '00/00' end else begin set @cBirth = left(@BirthDate, 5) end end else begin set @cBirth = '00/00' end IF NOT EXISTS( SELECT EmployeeID FROM tbPasswordMaster WHERE EmployeeID = @EmployeeID) begin insert into tbPasswordMaster (EmployeeID, LastName, FirstName, MiddleName, Initial, BirthDate, Password) values(@EmployeeID, @LastName, @FirstName, @MiddleName, @Initial, @cBirth, @Password) end else BEGIN update tbPasswordMaster set lastname= @LastName, firstname= @FirstName, middlename= @MiddleName, initial = @Initial, birthdate = @cBirth, password = @Password where employeeid = @employeeid END /* update all employee department password for consistency */ UPDATE tbPasswordMain SET Password = @Password WHERE EmployeeID = @EmployeeID; UPDATE tbPasswordMaster SET Password = @Password WHERE EmployeeID = @EmployeeID; GO