kshahzad
Starting Member
45 Posts |
Posted - 2013-07-18 : 16:56:28
|
[code]USE [myNIC_PROD]GO/****** Object: StoredProcedure [dbo].[NIC_REPORTS_GetReferal] Script Date: 07/18/2013 20:51:38 ******/SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[NIC_REPORTS_GetReferal]@lPhysician int,@lOffice int,@SDate datetime,@EDate datetimeASSET TRANSACTION ISOLATION LEVEL READ COMMITTEDDECLARE @lEnterprise intSELECT @lEnterprise=lEnterprise FROM Office WHERE lID=@lOffice/*select b.szlast + ', ' + b.szfirst as szPhysicianName, c.szlast + ', ' + c.szfirst as szPatientName, a.dDateCreated, a.dCheckForReport, a.nPriority from consultants a, physician b, patient c where a.lphysician = b.lid and a.lphysician in (select lPhysician from map_physiciantooffice where loffice = @lOffice) and c.lid in (select lpatient from address where lid = a.lpatientaddress)and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 order by a.dDateCreated, szPatientName, a.nPriority desc*/select a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ap.szfirst + ' ' + ap.szlast as szphysicianname, ap.szorganization as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN alliedHealthProviders AP ON a.lAlliedProvider=AP.lid LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere a.nRecordStatus=1 AND DATEDIFF(d, @SDate, a.dDateCreated) >= 0 AND DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, r.szfirst + ' ' + r.szlast as szphysicianname, r.szdepartment as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToRolodex d ON a.lID = d.lConsultants JOIN Rolodex r ON r.lID = d.lRolodex LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directoryAB ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directoryab' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directorybc ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directorybc' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directorynb ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directorynb' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directoryns ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directoryns' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directoryon ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directoryon' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLUNIONselect a.dDateCreated, a.dCheckForReport, a.nPriority, p.szfirst + ' ' + p.szlast as szpatientname, ds.szfirst + ' ' + ds.szlast as szphysicianname, '' as szfacility, phys.szFirst + ' ' + phys.szLast AS szOrderedByfrom consultants a INNER JOIN Map_ConsultationToProgressNote map ON a.lID=map.lConsultant INNER JOIN ProgressNote PN ON map.lProgressNote=PN.lID INNER JOIN Office o ON PN.lOffice=o.lID Join patient p on p.lid=PN.lPatient JOIN Map_ConsultantsToDirectory d ON a.lID = d.lConsultants JOIN state s on s.lid = d.lDirectoryState JOIN directorysk ds on ds.lid = d.lDirectory LEFT JOIN Physician phys ON a.lPhysician=phys.lIDwhere s.szDirectoryTableName = 'directorysk' and a.nRecordStatus=1 and DATEDIFF(d, @SDate, a.dDateCreated) >= 0 and DATEDIFF(d, @EDate, a.dDateCreated) <= 0 AND o.lID=@lOffice AND a.dLastPrinted IS NOT NULLorder by szPatientName, a.dDateCreated, szfacility, a.nPriority desc[/code] |
|