Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Explanation of this script
Message
 
 
To
11/06/2008 08:54:23
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01323043
Message ID:
01323103
Views:
11
OSND is the code used here
Insert Into MedApps.analyzer_edg.dbo.OSND_Appt_ChartIDs ( ChartID )
>	Select Distinct Top 5 Acctno
>		From MedApps.IDX_Data.dbo.Appointments
>			Where POS_Code = @poscode
So you're inserting into OSND_Appt_ChartIDs table 5 accounts from Appointments table where Pos_Code = 'OSND'



>This is a script we got from someone that we are supposed to be able to modify and run. The tables are
>supposed to be named the same and have the same structure, but I'm unfamiliar with SQL scripting and am
>finding this difficult to figure out. If someone has the time, I would appreciate a blow-by-blow explanation
>of what is going on here. For starters, what is "OSND" for?
>
>Sorry for the formatting, but I'm not sure if that makes a difference so I left it as I received it.
>
>
>Set NOCOUNT ON
>
>Declare	@poscode as varchar(10),
>			@posdesc as varchar(100),
>			@acctno as varchar(20),
>			@provcode as varchar(20),
>			@PatientID as varchar(25),
>			@ChartNumber as varchar(30),
>			@Last_Name as varchar(30),
>			@First_Name as varchar(30),
>			@Middle_Initial as varchar(5),
>			@Sex	as char(1),
>			@DOB as char(10),
>			@SSN as char(11),
>			@ID as varchar(20),
>			@LastName as varchar(30),
>			@FirstName as varchar(30),
>			@MiddleInitial as varchar(5),
>			@Title as varchar(10),
>			@Suffix as varchar(10),
>			@UPIN as varchar(20),
>			@Name as varchar(100),
>			@LocID varchar(20),
>			@DocDateTime as varchar(8),
>			@DocumentName as varchar(80),
>			@OldDocDateTime as varchar(22),
>			@OldSubject as varchar(80),
>			@Filename as varchar(50),
>			@path as varchar(50),			
>			@page as varchar(10),
>			@documentid as varchar(40),
>			@SQL as varchar(8000),
>			@COPYSCRIPT as nvarchar(4000),
>			@CREATEDIRSCRIPT as nvarchar(4000),
>			@DELETEDIRSCRIPT as nvarchar(4000),
>			@Folder as varchar(100),
>			@Export_FileName as varchar(100),
>			@Merge_Script as nvarchar(4000)
>
>Set @poscode = 'OSND'
>Set @Merge_Script = ''
>
>Delete MedApps.analyzer_edg.dbo.OSND_ChartIDs
>Delete MedApps.analyzer_edg.dbo.OSND_Appt_ChartIDs
>Delete MedApps.analyzer_edg.dbo.A4XMLConversionCompleted
>
>Insert Into MedApps.analyzer_edg.dbo.OSND_Appt_ChartIDs ( ChartID )
>	Select Distinct Top 5 Acctno
>		From MedApps.IDX_Data.dbo.Appointments
>			Where POS_Code = @poscode
>
>Insert Into MedApps.analyzer_edg.dbo.OSND_ChartIDs ( ChartID )
>	Select Distinct (P.ChartID)
>		From AllscriptsDB.Impact.dbo.Patients P
>			Inner Join AllscriptsDB.Impact.dbo.Doc_Header H
>				On H.PatientID = P.PatientID
>			Where P.OrgID = '0'
>			And	P.ChartID in (	Select ChartID
>											From MedApps.analyzer_edg.dbo.OSND_Appt_ChartIDs )
>
>While (Select Count(Processed) From MedApps.analyzer_edg.dbo.OSND_ChartIDs Where Processed = '0') > 0
>	Begin
>
>		Select Top 1 @Acctno = ChartID
>			From MedApps.analyzer_edg.dbo.OSND_ChartIDs
>				Where Processed = '0'
>
>		Declare Patient cursor
>				Forward_Only
>				Read_Only
>			For
>				Select	Distinct
>							IsNull(convert(varchar(8),H.Date,112),'') As DocumentDate,
>							IsNull(H.DocumentName,''),
>							IsNull(H.DocumentID,''),
>							IsNull(FT.Description,'')
>				From AllscriptsDB.Impact.dbo.Patients P
>					Inner Join AllscriptsDB.Impact.dbo.Doc_Header H
>						On H.PatientID = P.PatientID
>					Inner Join AllscriptsDB.Impact.dbo.Folder_Template FT
>						On H.FolderID = FT.FolderID
>					Where P.ChartID = @acctno
>
>		Open Patient
>	
>		Fetch Next
>			From Patient
>				Into	@DocDateTime,
>						@DocumentName,
>						@documentid,
>						@Folder
>	
>		While @@Fetch_Status = 0
>			Begin
>				Declare Page Cursor
>						Forward_Only
>						Read_Only
>					For
>						Select	DD.Path,
>									DD.FileName,
>									DD.Page
>							From AllscriptsDB.Impact.dbo.Doc_Detail DD
>								Where DocumentId = @documentid
>									Order By DD.FileName,
>												DD.Page
>
>				Open Page
>
>				Fetch Next
>					From Page
>						Into	@path,
>								@filename,
>								@page
>
>				While @@Fetch_Status = 0
>					Begin
>
>						If @Page = 1
>							Begin
>								Print	@acctno +
>										',' +
>										@Folder +
>										',' +
>										@DocumentName +
>										',' +
>										@DocDateTime +
>										',' +
>										@FileName
>
>								Set @Export_FileName = @FileName
>								
>								Set @Merge_Script = '\\allscriptsscan\ImpactMDImages\' + @path + @filename + ','
>							End
>						If @Page <> 1
>							Begin
>								Set @Merge_Script = @Merge_Script + '\\allscriptsscan\ImpactMDImages\' + @path + @filename + ','
>							End
>
>						Fetch Next
>							From Page
>								Into	@path,
>										@filename,
>										@page
>					End
>					Close Page
>				Deallocate Page
>
>				Set @Merge_Script = Left(@Merge_Script,len(ltrim(rtrim(@Merge_Script))) -1)
>
>				Set @Merge_Script = @Merge_Script + '|\\meddevstage\Export_Images\OSND|' + @Export_FileName
>
>				Set @Merge_Script = 'C:\Tiff\Tiff_Merger.exe "' + @Merge_Script + '"'
>
>				exec master.dbo.xp_cmdshell @Merge_Script, no_output
>
>				Fetch Next
>					From Patient
>						Into	@DocDateTime,
>								@DocumentName,
>								@documentid,
>								@Folder
>	
>			End
>		Close Patient
>		Deallocate Patient							
>
>		Update MedApps.analyzer_edg.dbo.OSND_ChartIDs
>			Set Processed = '1'
>				Where ChartID = @AcctNo
>				And	Processed = '0'
>
>	End
>
>Set NOCOUNT OFF
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform