Last active
February 29, 2024 21:20
-
-
Save aclud/344afd5aa1fe121ecc53659b6625ac73 to your computer and use it in GitHub Desktop.
Large vbscript to compare disparate databases and provide actionable output or automatically repair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'sample large script comparing data from two disparate databases (MSSQL and Sybase) where no data warehouse is available to identify anomalies | |
'auto-selects database if only one, UI provides input to select if multiple valid databases | |
'queries pulled into arrays and compared then logged for categorization and action to be taken on like data, continues running/pause mode if DB connection severed | |
'non-compiled code provides UI via browser, encrypted config file to run/resume/perform incremental, and licensing for traceability | |
'tool provides method to read input from file or crawl databases for anomalies | |
Dim strScriptVer, strScriptNamePath, strScriptPath, strLogDirectory, strLogFile, strErrorImageLogFile, strErrorStudyLogFile | |
Dim strInCkeys, LogKeepSize, ConfigFile, strNoConfSave, strRunFromTxtFile | |
' ******************* options ******************************** | |
strScriptVer = "0.54" 'version | |
strScriptNamePath = WScript.ScriptFullName 'full name | |
strScriptPath = Left(strScriptNamePath, Len(strScriptNamePath) - Len(WScript.Scriptname)-1) 'full path | |
strLogDirectory = strScriptPath & "\log" 'directory to keep logfiles in | |
strLogFile = "sopcheck.log" 'main log file name | |
strErrorImageLogFile = "error-instances.log" 'error log file name | |
strErrorStudyLogFile = "error-studydetails.log" 'error log file name | |
strInCkeys = strScriptPath & "\***REMOVED***.txt" 'file containing ***REMOVED***s that can be automatically checked | |
strRepairCkeys = strScriptPath & "\repair.txt" 'file containing ***REMOVED***s that can be automatically checked and repaired, if possible | |
LogKeepSize = 5 'rotate a logfile if it's size is greater that this value in MB | |
ConfigFile = strScriptPath & "\config.acl" 'full path to configuration file | |
strNoConfSave = False 'default to always save config file | |
strRunFromTxtFile = False 'default to always run sequentially | |
strAttemptRepair = False 'default to No so script does not connect to Production and attempt repairs | |
' ******************* end of options ************************* | |
' setup basic objects | |
Dim runCount, imgCount, strStudiesChecked, imgFailCount, studyFailCount, objExplorer, strIEOpen, sqlSybConn, sqlSybPRODConn, sqlSybRs, sqlEAConn, sqlEARs | |
Dim strSybPass, strSybPassd, strErrCount, strMaintAvail, SQLCheckMaint | |
Dim WshShell, fso | |
strConnectTimeLeft = 360 'how many seconds to wait if the database connection is interrupted and error handler is called | |
runCount = 1 'how many times looped | |
imgCount = 0 'how many images checked | |
strStudiesChecked = 0 'how many studies processed (actual studies that exist on ***REMOVED***, not just counter) | |
imgFailCount = 0 'how many images not on ***REMOVED*** under proper study uid | |
studyFailCount = 0 'how many studies are affected | |
strErrCount = 0 'how many errors encountered | |
strIEOpen = False 'default to false as Internet Explorer is not yet open | |
strLogFl = strLogDirectory & "\" & strLogFile 'Simplify calling log file by full path later | |
strUtilTitle ="***REMOVED***" & strScriptVer 'Title of Application | |
Set WshShell = WScript.CreateObject("WScript.Shell") | |
'disable IE window reuse | |
DisableReUse = WshShell.RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\AllowWindowReuse",0,"REG_DWORD") | |
AddBlanktoTrusted = WshShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\blank\about",2,"REG_DWORD") | |
Set fso = WScript.CreateObject("Scripting.FileSystemObject") | |
'write new config file if one does not exist and fill in some defaults | |
If Not fso.FileExists(ConfigFile) Then | |
strLastCkey = 0 | |
strChecksPerRun = 0 | |
strCheckInterval = 0.1 | |
strSybPort = ***REMOVED*** | |
strSybWorkstation = "***REMOVED***" | |
strSybDisconnTime = 60 | |
Call fnWriteConf() | |
End If | |
'attempt to read config file | |
If fso.FileExists(ConfigFile) Then | |
aCfg = fso.OpenTextFile(ConfigFile).ReadAll() | |
On Error Resume Next | |
Err.Clear | |
ExecuteGlobal aCfg | |
If Err <> 0 Then | |
Call fnWriteLog("Configuration file contains errors, exiting", strLogFl) | |
bMsgErrReadConfig = MsgBox("Configuration file contains errors, exiting",16,strUtilTitle) | |
WScript.Quit | |
End If | |
On Error Goto 0 | |
strStopAt = strLastCkey + strChecksPerRun | |
Else | |
Call fnWriteLog("Configuration file does not exist! Exiting", strLogFl) | |
NoConfigMsg = MsgBox("No Config file exists",16,strUtilTitle) | |
WScript.quit | |
End If | |
'Run it, do the work | |
Call fnPrepIE() | |
Call fnCheckCode(strAppKey) | |
If Not fso.FileExists(strInCkeys) Then 'don't show this if strInCkeys exists | |
Call fnStartStatus() | |
End If | |
Call fnStartup() | |
Call fndbSybaseConnect("startup") | |
'if strInCkeys exists, check all ***REMOVED***s in it | |
Dim strInCkeysCount, arrInCkeys, R, strTrimmedInCkey | |
If fso.FileExists(strInCkeys) Then | |
strNoConfSave = True | |
strRunFromTxtFile = True | |
Set objInCkeys = fso.OpenTextFile(strInCkeys) | |
strInCkeys = objInCkeys.ReadAll | |
strInCkeysCount = objinckeys.Line | |
Call fnWriteLog("Found ***REMOVED*** input file, comparing " & strInCkeysCount & " entries from this file between ***REMOVED*** and the EA", strLogFl) | |
arrInCkeys = Split(strInCkeys, vbCrLf) | |
For R=0 To UBound(arrInCkeys) | |
strTrimmedInCkey = Trim(arrInCkeys(R)) | |
If IsNumeric(strTrimmedInCkey) Then | |
If InStr(strTrimmedInCkey, ".") Then | |
Call fnWriteLog("Skipping invalid ***REMOVED***: " & strTrimmedInCkey, strLogFl) | |
ElseIf strTrimmedInCkey > 0 Then | |
Call fnCompare(strTrimmedInCkey) | |
End If | |
Else | |
If strTrimmedInCkey <> "" Then | |
Call fnWriteLog("Skipping invalid ***REMOVED***: " & strTrimmedInCkey, strLogFl) | |
End If | |
End If | |
Next | |
'if strRepairCkeys exists, check all ***REMOVED***s in it, repairing anything that can be automatically repaired | |
ElseIf fso.FileExists(strRepairCkeys) Then | |
strAttemptRepair = True | |
WScript.Echo "strAttemptRepair " & strAttemptRepair | |
strNoConfSave = True | |
strRunFromTxtFile = True | |
Set objInCkeys = fso.OpenTextFile(strInCkeys) | |
strInCkeys = objInCkeys.ReadAll | |
strInCkeysCount = objinckeys.Line | |
Call fnWriteLog("Found ***REMOVED*** repair file, comparing " & strInCkeysCount & " entries from this file between ***REMOVED*** and the ***REMOVED*** and attempting repairs where possible", strLogFl) | |
arrInCkeys = Split(strInCkeys, vbCrLf) | |
For R=0 To UBound(arrInCkeys) | |
strTrimmedInCkey = Trim(arrInCkeys(R)) | |
If IsNumeric(strTrimmedInCkey) Then | |
If InStr(strTrimmedInCkey, ".") Then | |
Call fnWriteLog("Skipping invalid ***REMOVED***: " & strTrimmedInCkey, strLogFl) | |
ElseIf strTrimmedInCkey > 0 Then | |
Call fnCompare(strTrimmedInCkey) | |
End If | |
Else | |
If strTrimmedInCkey <> "" Then | |
Call fnWriteLog("Skipping invalid ***REMOVED***: " & strTrimmedInCkey, strLogFl) | |
End If | |
End If | |
Next | |
'if nothing else, run like normal | |
Else | |
Do Until strLastCkey = strStopAt 'loop through until all ckeys checked | |
Call fnCompare(strLastCkey+1) | |
Loop | |
End If | |
'clean up | |
If strIEOpen = True Then | |
objExplorer.Visible = 0 | |
objExplorer.Quit | |
End If | |
Call fnDonePopup() 'call the popup if the IE on quit fails to do so | |
Set arrSybSops = Nothing | |
Set strSybSops = Nothing | |
Set strSybStudyUID = Nothing | |
Set strSybImgCnt = Nothing | |
Set sqlSybRs = Nothing | |
Set sqlSybConn = Nothing | |
Set fso = Nothing | |
Function fnCompare(strSybStudyCkey) 'check if all sops in a ***REMOVED*** study exist under the same ea study by study uid | |
'prep work | |
'If start of utility, write to log and update IE | |
If (runCount = 1)Then | |
If strNoConfSave = False Then | |
Call fnWriteLog("Started with ***REMOVED*** " & strSybStudyCkey & ", continuing to ***REMOVED*** " & strStopAt & ", checking a total of " & FormatNumber((strStopAt-strSybStudyCkey),0,-1,-1,-1) & " studies", strLogFl) | |
Call fnUpdateIE("Started with ***REMOVED***: " & strSybStudyCkey-1 & "<BR>Continuing to ***REMOVED***: " & strStopAt & "<BR>Total studies being compared: " & FormatNumber((strStopAt-strSybStudyCkey+1),0,-1,-1,-1)) | |
End If | |
End If | |
WScript.Sleep (strCheckInterval*1000) | |
If strRunFromTxtFile = True Then | |
strPercentComplete = FormatPercent(R/UBound(arrInCkeys),0) | |
End If | |
If Right(runCount,2) = "00" Then | |
Call fnWriteConf() | |
If ((Right(runCount,3) = "000") And ((strStopAt-strSybStudyCkey)) <> 0) Then | |
If strRunFromTxtFile = True Then 'write log out for ***REMOVED***s in file | |
Call fnWriteLog("Completed ***REMOVED*** " & strSybStudyCkey & " (" & strPercentComplete & "), processed " & FormatNumber(imgCount,0,-1,-1,-1) & " instances in " & FormatNumber(strStudiesChecked,0,-1,-1,-1) & " studies, " & FormatNumber((strInCkeysCount-R),0,-1,-1,-1) & " studies left to process", strLogFl) | |
End If | |
If strRunFromTxtFile = False Then 'write log out for standard run | |
Call fnWriteLog("Completed ***REMOVED*** " & strSybStudyCkey & " (" & FormatPercent(runCount/strChecksPerRun,2) & "), processed " & FormatNumber(imgCount,0,-1,-1,-1) & " instances in " & FormatNumber(strStudiesChecked,0,-1,-1,-1) & " studies, " & FormatNumber((strStopAt-strSybStudyCkey),0,-1,-1,-1) & " studies left to process", strLogFl) | |
End If | |
fnLogMgr strLogFl, objLogFile | |
fnLogMgr StrLogDirectory & "\" & strErrorImageLogFile, objLogFile | |
fnLogMgr StrLogDirectory & "\" & strErrorStudyLogFile, objLogFile | |
End If | |
End If | |
If (runCount > 1 And strIEOpen = True And strRunFromTxtFile = True) Then 'HTML for ***REMOVED***s in file | |
'try to use above? strPercentComplete = FormatPercent(R/UBound(arrInCkeys),0) | |
If R/UBound(arrInCkeys)*100 < 1 Then strPerCentComplete = 1 | |
strProgBar = "<style type='text/css'>table {font-size: 11;}</style><CENTER><TABLE border='1' cellpadding='0' cellspacing='0' width='90%'><TR><TD width='" & strPercentComplete & "%' bgcolor='blue'> </TD><TD> </TD></TR></TABLE></CENTER>" | |
strHTML = "<CENTER><table width='90%' border='0'><tr><td style='width:80%'>Completed ***REMOVED***:</td><td style='width:20%;text-align:right'>" & strTrimmedInCkey & "</td></tr><tr><td>Instances processed:</td><td style='text-align:right'>" & FormatNumber(imgCount,0,-1,-1,-1) & "</td></tr>" _ | |
& "<tr><td>Studies processed:</td><td style='text-align:right'>" & FormatNumber(strStudiesChecked,0,-1,-1,-1) & "</td></tr><tr><td>Studies left to process:</td><td style='text-align:right'>" & FormatNumber((strInCkeysCount-R),0,-1,-1,-1) & "</td></tr><tr><td>Possible anomalies identified:</td><td style='text-align:right'>" & FormatNumber(imgFailCount,0,-1,-1,-1) & "</td></tr><tr><td>Studies affected:</td><td style='text-align:right'>" & FormatNumber(studyFailCount,0,-1,-1,-1) & "</td></tr><td colspan='2'><hr width='90%'></td><tr><td colspan='2'><CENTER>" & strProgBar & "</td></tr></table>" | |
Call fnUpdateIE(strHTML) | |
ElseIf (runCount > 3 And strIEOpen = True And strRunFromTxtFile = False) Then 'HTML for standard run | |
strPercentComplete = FormatPercent(runCount/strChecksPerRun,0) | |
If runCount/strChecksPerRun*100 < 1 Then strPerCentComplete = 1 | |
strProgBar = "<style type='text/css'>table {font-size: 11;}</style><CENTER><TABLE border='1' cellpadding='0' cellspacing='0' width='90%'><TR><TD width='" & strPercentComplete & "%' bgcolor='blue'> </TD><TD> </TD></TR></TABLE></CENTER>" | |
strHTML = "<CENTER><table width='90%' border='0'><tr><td style='width:80%'>Completed ***REMOVED***:</td><td style='width:20%;text-align:right'>" & strSybStudyCkey-1 & "</td></tr><tr><td>Instances processed:</td><td style='text-align:right'>" & FormatNumber(imgCount,0,-1,-1,-1) & "</td></tr>" _ | |
& "<tr><td>Studies processed:</td><td style='text-align:right'>" & FormatNumber(strStudiesChecked,0,-1,-1,-1) & "</td></tr><tr><td>Studies left to process:</td><td style='text-align:right'>" & FormatNumber((strStopAt-strSybStudyCkey),0,-1,-1,-1) & "</td></tr><tr><td>Possible anomalies identified:</td><td style='text-align:right'>" & FormatNumber(imgFailCount,0,-1,-1,-1) & "</td></tr><tr><td>Studies affected:</td><td style='text-align:right'>" & FormatNumber(studyFailCount,0,-1,-1,-1) & "</td></tr><td colspan='2'><hr width='90%'></td><tr><td colspan='2'><CENTER>" & strProgBar & "</td></tr></table>" | |
Call fnUpdateIE(strHTML) | |
End If | |
runCount = runCount + 1 | |
strLastCkey = strLastCkey + 1 | |
'SQL queries | |
SQLSybStudyUID = "SELECT study_instance_uid FROM ***REMOVED***..***REMOVED*** WHERE lta_stat='Y' AND ***REMOVED***=" & strSybStudyCkey '& " and ***REMOVED*** not in (select ***REMOVED*** from ***REMOVED***..***REMOVED*** where ***REMOVED*** in (1,2) and request_type='A')" | |
SQLSybSopUID = "SELECT ***REMOVED*** as arr from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & " union all select ***REMOVED*** as arr from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & " union all select ***REMOVED*** as arr from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey | |
'get study instance uid | |
Set sqlSybRs = WScript.CreateObject("ADODB.RecordSet") | |
sqlSybRs.CursorType = adOpenForwardOnly | |
On Error Resume Next | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybStudyUID, sqlSybConn | |
If Err.Number <> 0 Then | |
Call fnWriteLog("Unable to obtain sybase study uid for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the sybase connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybaseConnect("study uid") | |
Else | |
If Not sqlSybRS.EOF Then | |
strSybStudyUID = sqlSybRs("study_instance_uid") | |
End If | |
sqlSybRs.Close | |
End If | |
On Error Goto 0 | |
'turn all sop uid's into an array | |
If Not IsEmpty(strSybStudyUID) Then | |
strStudiesChecked = strStudiesChecked + 1 | |
Dim arrSybSops() 'create the array | |
On Error Resume Next | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybSopUID, sqlSybConn | |
If Err.Number <> 0 Then | |
Call fnWriteLog("Unable to obtain sybase sop instances for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the sybase connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybaseConnect("array build") | |
Else | |
i=0 | |
Do Until sqlSybRS.EOF | |
ReDim Preserve arrSybSops(i) | |
arrSybSops(i) = sqlSybRs("arr") | |
i=i+1 | |
sqlSybRs.MoveNext | |
Loop | |
str***REMOVED***SopCount = i | |
sqlSybRs.Close | |
End If | |
On Error Goto 0 | |
If fnArryStuffed(arrSybSops) = True Then | |
imgCount = imgCount + UBound(arrSybSops)+1 | |
End If | |
'grab all sops from ***REMOVED*** database | |
SQLEAImageUID = "select [00080018] as easop from ***REMOVED*** i, ***REMOVED*** s, ***REMOVED*** t where t.id1=s._id1 and s.id2=i._id2 and t.[0020000D]='" & strSybStudyUID & "'" | |
Set sqlEARs = WScript.CreateObject("ADODB.RecordSet") | |
sqlEARs.CursorType = 3 | |
On Error Resume Next | |
Err.Clear | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open SQLEAImageUID, sqlEAConn | |
If Err <> 0 Then | |
Do Until sqlEARs.State = 1 | |
Err.Clear | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open SQLEAImageUID, sqlEAConn | |
If Err <> 0 Then | |
Call fndbEAConnect() | |
End If | |
Loop | |
End If | |
'turn all image uids into an array | |
ReDim arrEASops(sqlEARs.RecordCount) | |
i=0 | |
Do Until sqlEARS.EOF | |
arrEASops(i) = sqlEARs("easop") | |
i=i+1 | |
sqlEARs.MoveNext | |
Loop | |
sqlEARs.Close | |
On Error Goto 0 | |
' compare the image level outputs | |
strBadImage=0 | |
strGoodImage=1 | |
For Each strElementFirst In arrSybSops | |
blnExistsInSecond = False | |
For Each strElementSecond In arrEASops | |
If strElementFirst = strElementSecond Then | |
blnExistsInSecond = True | |
strGoodImage = strGoodImage + 1 | |
'used for testing, adds logging for image matches | |
'Call fnWriteLog("ok^" & strSybStudyCkey & "^" & strElementFirst, strLogFl) | |
Exit For | |
End If | |
Next | |
If Not blnExistsInSecond Then | |
'TODO: add ***REMOVED*** queries here to see if the image exists on the ***REMOVED*** under ***REMOVED*** | |
SQLEAImageDetail = "if exists (select 1 from ***REMOVED*** where [00080018] ='" & strElementFirst & "') begin select 'Y' as RESULT end else begin select 'N' as RESULT end" | |
strEAImageDetails = "Y" 'place holder to record if all images on ***REMOVED*** in study level log | |
Set sqlEARs = WScript.CreateObject("ADODB.RecordSet") | |
sqlEARs.CursorType = 3 | |
On Error Resume Next | |
Err.Clear | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open SQLEAImageDetail, sqlEAConn | |
If Err <> 0 Then | |
Do Until sqlEARs.State = 1 | |
Err.Clear | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open SQLEAImageUID, sqlEAConn | |
If Err <> 0 Then | |
Call fndbEAConnect() | |
End If | |
Loop | |
End If | |
strEAImageDetail = sqlEARs("RESULT") | |
If strEAImageDetail = "N" Then strEAImageDetails = "N" | |
sqlEARs.Close | |
On Error Goto 0 | |
'write to image level log file | |
Call fnWriteLog(strSybStudyCkey & vbTab & strEAImageDetail & vbTab & strElementFirst, strLogDirectory & "\" & strErrorImageLogFile) | |
imgFailCount = imgFailCount + 1 | |
strBadImage = strBadImage + 1 | |
End If | |
Next | |
If strBadImage > 0 Then | |
studyFailCount = studyFailCount + 1 | |
'grab some info from sybase about the study | |
SQLSybMoreInfo = "select 'strImageCount'=(select count(*) from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & "),'strKOSCount'=(select count(*) from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & "),'strPSCount'=(select count(*) from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & "),'strArcAddressCount'=(select count(*) from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & "),'strArcAddressMaxVer'=(select max(version) from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & "),'strAccessionNr'=(select ***REMOVED*** from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey & ")" | |
On Error Resume Next | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybMoreInfo, sqlSybConn | |
If Err.Number <> 0 Then | |
Call fnWriteLog("Unable to obtain study details for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the sybase connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybaseConnect("study details") | |
Else | |
If Not sqlSybRS.EOF Then | |
strImageCount = sqlSybRs("strImageCount") | |
strKOSCount = sqlSybRs("strKOSCount") | |
strPSCount = sqlSybRs("strPSCount") | |
strArcAddressCount = sqlSybRs("strArcAddressCount") | |
strArcAddressMaxVer = sqlSybRs("strArcAddressMaxVer") | |
strAccessionNr = sqlSybRs("strAccessionNr") | |
End If | |
sqlSybRs.Close | |
End If | |
On Error Goto 0 | |
'get some details on the sts stat for the study | |
SQLSybSTSDetails = "select sts_stat from ***REMOVED***..***REMOVED*** where ***REMOVED***=" & strSybStudyCkey | |
On Error Resume Next | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybSTSDetails, sqlSybConn | |
If Err.Number <> 0 Then | |
Call fnWriteLog("Unable to obtain ***REMOVED*** details for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the ***REMOVED*** connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybaseConnect("sts_stat details") | |
Else | |
strSybSTSDetail = "" | |
Do Until sqlSybRS.EOF | |
strSybSTSDetail = strSybSTSDetail & sqlSybRs("sts_stat") | |
sqlSybRs.MoveNext | |
Loop | |
sqlSybRs.Close | |
If InStr(strSybSTSDetail,"Y") Then | |
strSybSTSStat = "Y" | |
ElseIf InStr(strSybSTSDetail,"I") Then | |
strSybSTSStat = "I" | |
ElseIf InStr(strSybSTSDetail,"N") Then | |
strSybSTSStat = "N" | |
End If | |
End If | |
'get some details on the lta_stat of the images | |
SQLSybImageLTAStat = "SELECT lta_stat as lta from ***REMOVED***..image where ***REMOVED***=" & strSybStudyCkey & " union all select lta_stat as lta from ***REMOVED***..presentation_state where ***REMOVED***=" & strSybStudyCkey & " union all select lta_stat as lta from ***REMOVED***..kos_document where ***REMOVED***=" & strSybStudyCkey | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybImageLTAStat, sqlSybConn | |
If Err.Number <> 0 Then | |
Call fnWriteLog("Unable to obtain image lta_stat details for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the ***REMOVED*** connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybaseConnect("lta_stat details") | |
Else | |
strSybLTAImageN = 0 | |
strSybLTAImageY = 0 | |
strSybLTAImageO = 0 | |
Do Until sqlSybRs.EOF | |
If sqlSybRs("lta") = "Y" Then | |
strSybLTAImageY = strSybLTAImageY + 1 | |
ElseIf sqlSybRs("lta") = "N" Then | |
strSybLTAImageN = strSybLTAImageN + 1 | |
Else | |
strSybLTAImageO = strSybLTAImageO + 1 | |
End If | |
sqlSybRs.MoveNext | |
Loop | |
sqlSybRs.Close | |
strSybLTAImage = "Y=" & strSybLTAImageY | |
If strSybLTAImageN > 0 Then | |
strSybLTAImage = strSybLTAImage & ",N=" & strSybLTAImageN | |
End If | |
If strSybLTAImageO > 0 Then | |
strSybLTAImage = strSybLTAImage & ",Other=" & strSybLTAImageO | |
End If | |
'attempt to do some updates in production instance of sybase to repair problem | |
If strAttemptRepair = True Then | |
'dont forget to dim everything globally, or do i need to bother since no other function hits prod? | |
Call fnSybPRODInsertArchiveQueue(strSybStudyCkey) | |
End If | |
End If | |
On Error Goto 0 | |
'write to study level log file | |
Call fnWriteLog(strSybStudyCkey & vbTab & str***REMOVED***SopCount & vbTab & UBound(arrEASops) & vbTab & strImageCount & vbTab & strKOSCount & vbTab & strPSCount & vbTab & strArcAddressCount & vbTab & strArcAddressMaxVer & vbTab & strSybSTSStat & vbTab & strEAImageDetails & vbTab & strSybLTAImage & vbTab & strAccessionNr & vbTab & strSybStudyUID, strLogDirectory & "\" & strErrorStudyLogFile) | |
End If | |
End If | |
End Function | |
Function fnWriteLog(fin,flog) 'Function for writing messages to the log file, input is message then log name | |
'Create log directory if it doesn't exist | |
If Not fso.FolderExists(strLogDirectory) Then | |
fso.CreateFolder(strLogDirectory) | |
End If | |
strLogMsg = "Log: " & Date() & " " & FormatDateTime(Now, 4) & ":" & fnPad(DatePart("S",Now),2) & " [" & runCount & "] " 'left portion of logging messages | |
Dim strWriteLine,strLine,fsa,strNewFile | |
Set fsa = WScript.CreateObject("Scripting.FileSystemObject") | |
'If Not fsa.FileExists(strLogDirectory & "\" & strErrorStudyLogFile) Then strNewFile = 1 | |
If Not fsa.FileExists(flog) Then strNewFile = 1 | |
Set strWriteLine = fsa.OpenTextFile(flog, 8, True) | |
If flog = strLogDirectory & "\" & strLogFile Then 'main log file | |
strWriteLine.WriteLine(strLogMsg & fin) | |
ElseIf flog = strLogDirectory & "\" & strErrorStudyLogFile Then 'study log file for excel doc | |
If strNewFile = 1 Then | |
strWriteLine.WriteLine("***REMOVED***" & vbTab & "***REMOVED*** Sops Count" & vbTab & "***REMOVED*** Sops Count" & vbTab & "***REMOVED*** Image Count" & vbTab & "***REMOVED*** KOS Count" & vbTab & "***REMOVED*** PS Count" & vbTab & "arc_address Count" & vbTab & "Highest ***REMOVED*** version" & vbTab & "***REMOVED***" & vbTab & "All anomalies on ***REMOVED***" & vbTab & "Image ***REMOVED***" & vbTab & "Accession #" & vbTab & "Study UID") | |
End If | |
strWriteLine.WriteLine(fin) | |
ElseIf flog = strLogDirectory & "\" & strErrorImageLogFile Then 'image log file for excel doc | |
If strNewFile = 1 Then | |
strWriteLine.WriteLine("***REMOVED***" & vbTab & "Exists on ***REMOVED***" & vbTab & "Instance UID") | |
End If | |
strWriteLine.WriteLine(fin) | |
Else 'all others | |
strWriteLine.WriteLine(fin) | |
End If | |
strWriteLine.Close | |
Set strWriteLine = Nothing | |
Set fsa = Nothing | |
Set strLogF = Nothing | |
End Function | |
Function fnStartup() 'startup function, called before any work is done | |
'confirm this is an ***REMOVED*** | |
Dim scrArchive, strEAgetDBName, strArchiveCount, scrStorage, strEABuildNr | |
On Error Resume Next | |
'figure out ea build, make sure it's an ***REMOVED***...quit if not - can be used later to do different things based on ***REMOVED*** version | |
Err.Clear | |
Set scrStorage = WScript.CreateObject("***REMOVED***") | |
If Err <> 0 Then | |
Call fnWriteLog("Could not connect to ***REMOVED*** on this system, exiting", strLogFl) | |
bMsgErrCOMArchive = MsgBox("Could not connect to ***REMOVED*** on this system, exiting",16,strUtilTitle) | |
objExplorer.Quit | |
WScript.Quit | |
End If | |
strEABuildNr = ***REMOVED***.***REMOVED*** | |
strEAgetDBName = "select ***REMOVED***,***REMOVED*** from ***REMOVED***..***REMOVED***" | |
Set sqlEARs = WScript.CreateObject("ADODB.RecordSet") | |
sqlEARs.CursorType = 3 | |
On Error Resume Next | |
Err.Clear | |
'grab archive information from RSAdmin | |
If strEADatabase = "" Then | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open strEAgetDBName, sqlEAConn | |
If Err <> 0 Then | |
Do Until sqlEARs.State = 1 | |
strErrCount = strErrCount + 1 | |
Err.Clear | |
If sqlEARs.State <> 0 Then | |
sqlEARs.Close | |
End If | |
Err.Clear | |
sqlEARs.Open strEAgetDBName, sqlEAConn | |
If Err <> 0 Then | |
Call fndbEAConnect() | |
End If | |
Loop | |
End If | |
strArchiveCount = sqlEARs.RecordCount | |
If strArchiveCount = 0 Then | |
Call fnWriteLog("Could not determine number of ***REMOVED*** ***REMOVED*** ***REMOVED***, exiting", strLogFl) | |
bMsgErrDetArchive = MsgBox("Could not determine number of ***REMOVED*** ***REMOVED*** ***REMOVED***, exiting",16,strUtilTitle) | |
objExplorer.Quit | |
WScript.Quit | |
ElseIf strArchiveCount = 1 Then | |
strEADatabase = sqlEARs("DBName") | |
Call fnWriteLog("Automatically selected ***REMOVED*** Database: " & strEADatabase, strLogFl) | |
Else | |
ReDim arrEAArchives(sqlEARs.RecordCount - 1,1) | |
i = 0 | |
Do Until sqlEARS.EOF | |
arrEAArchives(i,0) = sqlEARs("ArchiveName") | |
arrEAArchives(i,1) = sqlEARs("DBName") | |
sqlEARs.MoveNext | |
i = i + 1 | |
Loop | |
'If multiple archives found, present the user with a list and allow them to select the one connected to ***REMOVED*** | |
For i = 0 To UBound(arrEAArchives,1) | |
If i = 0 Then strCheck = """ CHECKED" | |
If i > 0 Then strCheck = """" | |
strHTMLea = strHTMLea & "<INPUT TYPE=""RADIO"" ID=""UserInput"" NAME=""UserInput"" Value=""" & arrEAArchives(i,1) & strCheck & ">" & arrEAArchives(i,0) & "<BR>" | |
Next | |
strHTML = "Multiple ***REMOVED*** ***REMOVED*** detected...<BR>" _ | |
& "Please select the Virtual Archive ***REMOVED*** utilizes:<BR><BR>" _ | |
& "<INPUT TYPE=""HIDDEN"" ID=""OK"" NAME=""OK"" VALUE=""0"">" _ | |
& strHTMLea _ | |
& "<BR><INPUT TYPE=""SUBMIT"" VALUE=""OK"" OnClick=""VBScript:OK.Value=1"">" | |
Call fnUpdateIE(strHTML) | |
Call fnIEChangeCursor("default") | |
Do Until objExplorer.Document.All.OK.Value = 1 | |
WScript.Sleep 500 | |
Loop | |
For i = 0 To objExplorer.Document.All.UserInput.Length - 1 | |
If objExplorer.Document.All.UserInput(i).Checked Then | |
strEADatabase = objExplorer.Document.All.UserInput(i).Value | |
Exit For | |
End If | |
Next | |
strEADBSet = 1 | |
Call fnWriteLog("User selected ***REMOVED*** ***REMOVED***: " & strEADatabase, strLogFl) | |
Call fnIEChangeCursor("progress") | |
End If | |
sqlEARs.Close | |
End If | |
'quit if the Sybase port is not set to MAINT | |
If strSybPort <> ***REMOVED*** Then | |
msgQuitMaint = "This utility can only run against the MAINT Server" | |
bQuitMaint = MsgBox(msgQuitMaint,16,strUtilTitle) | |
objExplorer.Quit | |
WScript.Quit | |
End If | |
'grab Sybase IP if it's not in config | |
If strSybServer = "" Then | |
strSybServer = fnIEUserInput("Enter Sybase server IP Address:", 20, "Text") | |
If strSybServer = "" Then | |
objExplorer.Quit | |
WScript.quit | |
End If | |
End If | |
'grab sybase pass if it's not in config | |
If strSybPass = "" Then | |
msgInPass = fnIEUserInput("Enter Sybase MAINT server ***REMOVED*** password:", 20, "Password") | |
' msgInPass = InputBox("Enter Sybase MAINT server ***REMOVED*** password:", strUtilTitle) | |
For icr=1 To Len(msgInPass) | |
strSybPass=strSybPass & fnGenString(3) & fnPad(Asc(Mid(msgInPass,icr,1)),3) | |
Next | |
End If | |
If msgInPass = "" Then | |
If strSybPass = "" Then | |
strSybPass = "***REMOVED***" | |
End If | |
End If | |
'work with Sybase pass | |
***REMOVED*** | |
***REMOVED*** | |
***REMOVED*** | |
***REMOVED*** | |
Else | |
Set objRegEx = New RegExp | |
objRegEx.IgnoreCase = True | |
objRegEx.Global = True | |
objRegEx.Pattern = "[^0-9]" | |
e=objRegEx.Replace(strSybPass,"") | |
ide=1 | |
Do Until ide => Len(e) | |
***REMOVED*** | |
***REMOVED*** | |
Loop | |
End If | |
'find out how long to pause if the sybase connection is dropped | |
If strSybDisconnTime = "" Then | |
Do Until ((strSybDisconnTime > 14) And (strSybDisconnTime < 721)) | |
bMsgstrSybDisconnTime = "Enter the number of minutes to pause" & vbCrLf & "if the sybase connection is dropped:" & vbCrLf & "Hint: this happens for each full backup" | |
strSybDisconnTime = InputBox(bMsgstrSybDisconnTime, strUtilTitle,"15") | |
If strSybDisconnTime = "" Then | |
objExplorer.Quit | |
WScript.Quit | |
ElseIf strSybDisconnTime < 15 Then | |
strMgDisconnShort = "The minimum allowed time is 15 minutes." & vbCrLf & "You entered: " & strSybDisconnTime & vbCrLf & "Please try again." | |
bMsgDisconnShort = MsgBox(strMgDisconnShort,48,strUtilTitle) | |
ElseIf strSybDisconnTime > 720 Then | |
strMgDisconnShort = "The maximum allowed time is 720 minutes." & vbCrLf & "You entered: " & strSybDisconnTime & vbCrLf & "Please try again." | |
bMsgDisconnShort = MsgBox(strMgDisconnShort,48,strUtilTitle) | |
End If | |
Loop | |
End If | |
'if config file says all of ***REMOVED*** was previously checked, figure out if an incremental check is wanted | |
If strAll***REMOVED*** = "Yes" Then | |
Set sqlSybConn = WScript.CreateObject("ADODB.Connection") | |
sqlSybConn.ConnectionString = "Provider=Sybase.ASEOLEDBProvider.2;Server Name=" & strSybServer & ";Server Port Address=" & strSybPort & ";Initial Catalog=***REMOVED***..ser ID=***REMOVED***Password=" & strSybPassd & ";Workstation ID=" & strSybWorkstation & ";UseCursor=1" | |
Call fnUpdateIE("Attempting to connect to ***REMOVED***...") | |
Err.Clear | |
sqlSybConn.Open | |
If Err.Number <> 0 Then | |
Call fnSybNoConn(Err.Description) | |
End If | |
Set sqlSybRs = WScript.CreateObject("ADODB.RecordSet") | |
sqlSybRs.CursorType = adOpenForwardOnly | |
'get highest ***REMOVED*** in database | |
SQLSybmaxstudyckey = "SELECT max(***REMOVED***) as strMaxStudyCkey from study" | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybmaxstudyckey, sqlSybConn | |
If Not sqlSybRS.EOF Then | |
strMaxStudyCkeyout = sqlSybRs("strMaxStudyCkey") | |
End If | |
sqlSybRs.Close | |
sqlSybConn.Close | |
Set sqlSybRs = Nothing | |
Set sqlSybConn = Nothing | |
Call fnUpdateIE("Connected to ***REMOVED***...") | |
If Not fso.FileExists(strInCkeys) Then 'don't show this if strInCkeys exists | |
msgAll***REMOVED*** = "The last study ckey compared was: " & strLastCkey & vbCrLf & "The highest study ckey in ***REMOVED*** is: " & strMaxStudyCkeyout & vbCrLf & vbCrLf & "Do you want to perform an incremental check?" & vbCrLf & "(start @ ckey " & strLastCkey & ", end @ ckey " & strMaxStudyCkeyout & ")" | |
bmsgAll***REMOVED*** = MsgBox(msgAll***REMOVED***,67+512,strUtilTitle) | |
Select Case bmsgAll***REMOVED*** | |
Case 2 'cancel | |
objExplorer.Quit | |
WScript.quit | |
Case 6 'yes | |
strChecksPerRun = strMaxStudyCkeyout - strLastCkey | |
strStopAt = strLastCkey + strChecksPerRun | |
'strAll***REMOVED*** = 1 | |
Case 7 'no | |
strChecksPerRun = 0 | |
Case Else | |
objExplorer.Quit | |
WScript.Quit | |
End Select | |
End If | |
End If | |
'if strChecksPerRun = 0 ask if entire DB should be checked | |
If strChecksPerRun = 0 Then | |
Set sqlSybConn = WScript.CreateObject("ADODB.Connection") | |
sqlSybConn.ConnectionString = "Provider=Sybase.ASEOLEDBProvider.2;Server Name=" & strSybServer & ";Server Port Address=" & strSybPort & ";Initial Catalog=***REMOVED***..ser ID=sa;Password=" & strSybPassd & ";Workstation ID=" & strSybWorkstation & ";UseCursor=1" | |
Call fnUpdateIE("Attempting to connect to ***REMOVED***...") | |
Err.Clear | |
sqlSybConn.Open | |
If Err.Number <> 0 Then | |
Call fnSybNoConn(Err.Description) | |
End If | |
Set sqlSybRs = WScript.CreateObject("ADODB.RecordSet") | |
sqlSybRs.CursorType = adOpenForwardOnly | |
'get highest ***REMOVED*** in database | |
SQLSybmaxstudyckey = "SELECT max(***REMOVED***) as strMaxStudyCkey from study" | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
sqlSybRs.Open SQLSybmaxstudyckey, sqlSybConn | |
If Not sqlSybRS.EOF Then | |
strMaxStudyCkeyout = sqlSybRs("strMaxStudyCkey") | |
End If | |
sqlSybRs.Close | |
sqlSybConn.Close | |
Set sqlSybRs = Nothing | |
Set sqlSybConn = Nothing | |
Call fnUpdateIE("Connected to ***REMOVED***...") | |
WScript.Sleep 1000 | |
If Not fso.FileExists(strInCkeys) Then 'don't show this if strInCkeys exists | |
objExplorer.Visible = 0 | |
msgbWholedb = "Do you want to compare the entire ***REMOVED*** database?" | |
bWholedb = MsgBox(msgbWholedb,67+512,strUtilTitle) | |
Select Case bWholedb | |
Case 2 'cancel | |
objExplorer.Quit | |
WScript.quit | |
Case 6 'yes | |
strLastCkey = 0 | |
strChecksPerRun = strMaxStudyCkeyout | |
strStopAt = strLastCkey + strChecksPerRun | |
strAll***REMOVED*** = "Yes" | |
Case 7 'no | |
strLastCkey = InputBox("Enter the starting ***REMOVED***:",strUtilTitle)-1 | |
strAll***REMOVED*** = "No" | |
If IsNumeric(strLastCkey) = False Then | |
bmsgInvalLastCkey = MsgBox("The starting ***REMOVED*** is not valid, exiting.",16,strUtilTitle) | |
strNoEndMsg = True | |
objExplorer.Quit | |
WScript.quit | |
Else | |
strLastCkey = CLng(strLastCkey) | |
strAll***REMOVED*** = "No" | |
End If | |
strChecksPerRun = InputBox("Enter the number of ***REMOVED***s to check:",strUtilTitle) | |
If IsNumeric(strChecksPerRun) = False Then | |
bmsgInvalChecksPerRun = MsgBox("The number of ***REMOVED***s to check is not valid, exiting.",16,strUtilTitle) | |
strNoEndMsg = True | |
objExplorer.Quit | |
WScript.quit | |
Else | |
strChecksPerRun = CLng(strChecksPerRun) | |
End If | |
strStopAt = CLng(strLastCkey) + CLng(strChecksPerRun) | |
If (strStopAt < strLastCkey Or strLastCkey > strMaxStudyCkeyout) Then | |
bmsgStopAtLessLastCkey = MsgBox("The number of ***REMOVED***s to check is not valid, exiting.",16,strUtilTitle) | |
strNoEndMsg = True | |
objExplorer.Quit | |
WScript.Quit | |
End If | |
Case Else | |
objExplorer.Quit | |
WScript.Quit | |
End Select | |
objExplorer.Visible = 1 | |
End If | |
End If | |
Call fnWriteConf() | |
End Function | |
Function fnLogMgr(aLogFile, ByRef oLog) 'manages the log files | |
Call fnUpdateIE("Performing maintenance...") | |
Dim tLogFile | |
Const ForAppending = 8 | |
If fso.FileExists(aLogFile) Then | |
Set oLog = fso.GetFile(aLogFile) | |
If (oLog.Size > (LogKeepSize*1048576)) Or (oLog.Path=ConfigFile) Then | |
Call fnWriteLog("Performing Maintenance on " & aLogFile, strLogFl) | |
oLog.name = Left(oLog.Name,InStr(oLog.Name,".")-1) & "-" & DatePart("YYYY",Now()) & fnPad(DatePart("M",Now()),2) & fnPad(DatePart("D",Now()),2) & fnPad(DatePart("h",Now()),2) & fnPad(DatePart("n",Now()),2) & fnPad(DatePart("s",Now()),2) & ".log" | |
WScript.Sleep 10000 | |
tLogFile = fso.GetTempName | |
tLogFile = fso.GetSpecialFolder(2) & "\" & tLogFile | |
Set oLog = fso.CreateTextFile(tLogFile) | |
oLog.Close | |
WScript.Sleep 10000 | |
fso.MoveFile tLogFile, aLogFile | |
End If | |
Set oLog = fso.OpenTextFile(aLogFile, 8, True) | |
' Else | |
' Set oLog = fso.CreateTextFile(aLogFile) | |
End If | |
Set oLog = Nothing | |
End Function | |
Function fnPad(aStr, aSize) 'pads a string to the left with zeros to the size input to the function | |
If Len(aStr) < aSize Then | |
fnPad = String((aSize - Len(aStr)), "0") & Trim(aStr) | |
Else | |
fnPad = aStr | |
End If | |
End Function | |
Function fnGenString(iLen) 'generates a random string of letters the length of iLen | |
For i=1 To iLen | |
***REMOVED*** | |
Next | |
fnGenString=sRandStr | |
End Function | |
Function fnWriteConf() 'writes the config file - called frequently in case utility is forcefully ended | |
If strNoConfSave = False Then | |
If strLastCkey = "" Then | |
strLastCkey = 0 | |
End If | |
If strChecksPerRun = "" Then | |
strChecksPerRun = 0 | |
End If | |
Const ForReading = 1, ForWriting = 2, ForAppending = 8 | |
Set fso = WScript.CreateObject("Scripting.FileSystemObject") | |
Set fsc = fso.OpenTextFile(ConfigFile, ForWriting, True) | |
fsc.WriteLine("' no lines should be added to this config file, it is managed by the utility") | |
fsc.WriteLine("***REMOVED***") | |
fsc.WriteLine("***REMOVED***" ' Number of studies to check each time the utility runs") | |
fsc.WriteLine("***REMOVED*** ***REMOVED*** = """ & strAll***REMOVED*** & """ 'record of whether or not the entire ***REMOVED*** database was selected") | |
fsc.WriteLine("***REMOVED*** = " & ***REMOVED*** & " 'Wait time in seconds between ***REMOVED*** checks") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' IP Address of Sybase Server") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' Port for Sybase server - ***REMOVED*** is MAINT, 20000 is Production") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' Encrypted pass") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' Appears in sp_who output as hostname") | |
' fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' IP Address of EA Server") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' Database name of EA that ***REMOVED*** writes to") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' minutes to pause if sybase connection drops (full backups, etc.)") | |
fsc.WriteLine("***REMOVED*** = """ & ***REMOVED*** & """ ' license") | |
fsc.Close | |
Set fsc = Nothing | |
End If | |
End Function | |
Function fnDonePopup() 'displays dialog box with status when complete or stopped by user | |
DoneMsgText = "Comparison completed, see log for details" & vbCrLf & vbCrLf & FormatNumber(imgCount,0,-1,-1,-1) & " instances in " & FormatNumber((strChecksPerRun-(strStopAt-strLastCkey)),0,-1,-1,-1) & " studies processed" & vbCrLf & FormatNumber(imgFailCount,0,-1,-1,-1) & " instances in " & FormatNumber(studyFailCount,0,-1,-1,-1) & " studies need further investigation" | |
DoneMsg = MsgBox(DoneMsgText,64,strUtilTitle) | |
End Function | |
Function fnPrepIE() 'prepare IE when the utility starts | |
Set objExplorer = WScript.CreateObject("InternetExplorer.Application", "IE_") | |
objExplorer.Navigate "about:blank" | |
objExplorer.ToolBar = 0 | |
objExplorer.StatusBar = 0 | |
objExplorer.Width = 400 | |
objExplorer.Height = 220 | |
objExplorer.Visible = 1 | |
objExplorer.Document.Body.Style.Cursor = "wait" | |
objExplorer.Document.Body.style.fontFamily="Verdana, Arial, Helvetica, sans-serif" | |
objExplorer.Document.Body.style.fontSize="10pt" | |
objExplorer.Document.Body.style.backgroundcolor="#cecece" | |
objExplorer.Document.Title = strUtilTitle | |
Call fnUpdateIE("Currently processing...") | |
WScript.sleep 2000 | |
strIEOpen = True | |
End Function | |
Function fnCheckCode(strAppKey) | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED***, ***REMOVED*** | |
End Function | |
Function IE_onQuit() 'writes config file, show popup and end nicely if IE closes | |
strIEOpen = False | |
If runCount > 1 Then | |
If strRunFromTxtFile = True Then | |
Call fnWriteLog("Compared " & FormatNumber(imgCount,0,-1,-1,-1) & " instances in " & FormatNumber(strStudiesChecked,0,-1,-1,-1) & " studies, " & FormatNumber(imgFailCount,0,-1,-1,-1) & " instances in " & FormatNumber(studyFailCount,0,-1,-1,-1) & " studies need further investigation.", strLogFl) | |
Else | |
Call fnWriteLog("Ended with ***REMOVED*** " & strLastCkey & ", compared " & FormatNumber(imgCount,0,-1,-1,-1) & " instances in " & FormatNumber(strStudiesChecked,0,-1,-1,-1) & " studies, " & FormatNumber(imgFailCount,0,-1,-1,-1) & " instances in " & FormatNumber(studyFailCount,0,-1,-1,-1) & " studies need further investigation.", strLogFl) | |
End If | |
End If | |
Call fnWriteConf() | |
If ((strStopAt-strLastCkey <> 0 Or strNoEndMsg = True) And strRunFromTxtFile = False) Then | |
Call fnDonePopup() | |
End If | |
WScript.Quit | |
End Function | |
Function fnUpdateIE(inHTML) 'updates the IE gui for status update | |
On Error Resume Next | |
If objExplorer.ReadyState = 4 Then '4 = READYSTATE_COMPLETE - Object has received all of its data | |
objExplorer.Document.Body.InnerHTML = inHTML | |
End If | |
On Error Goto 0 | |
End Function | |
Function fnIEUserInput(inPrompt,inSize,inType) | |
Call fnIEChangeCursor("default") | |
Call fnUpdateIE("<DIV><P>" & inPrompt _ | |
& "</P>" & vbCrLf _ | |
& "<P><INPUT TYPE=""" & inType & """ SIZE=""" & inSize & """ " _ | |
& "ID=""UserInput""></P>" & vbCrLf _ | |
& "<P><INPUT TYPE=""hidden"" ID=""OK"" " _ | |
& "NAME=""OK"" VALUE=""0"">" _ | |
& "<INPUT TYPE=""submit"" VALUE="" OK "" " _ | |
& "OnClick=""VBScript:OK.Value=1""></P></DIV>") | |
Do Until objExplorer.Document.All.OK.Value = 1 | |
WScript.Sleep 500 | |
Loop | |
fnIEUserInput = objExplorer.Document.All.UserInput.Value | |
Call fnIEChangeCursor("progress") | |
End Function | |
Function fnIEChangeCursor(inStyle) 'sets the cursor style within IE | |
'http://msdn.microsoft.com/en-us/library/aa358795(VS.85).aspx | |
objexplorer.Document.Body.Style.Cursor = inStyle | |
End Function | |
Function fnStartStatus() 'Displays status of where utility left off and allows user to change if necessary | |
If (strLastCkey <> 0 And strChecksPerRun <> 0 And strAll***REMOVED*** = "No") Then | |
msgbStartStat = "Comparison starting at ***REMOVED*** " & strLastCkey+1 & ", continuing to ***REMOVED*** " & strStopAt & "." & vbCrLf & FormatNumber(strChecksPerRun,0,-1,-1,-1) & " ***REMOVED***s will be compared." & vbCrLf & vbCrLf & "Is this correct?" | |
bStartStat = MsgBox(msgbStartStat,68,strUtilTitle) | |
If bStartStat=7 Then '7 is no | |
strChecksPerRun = 0 'this causes popups to ask questions about config | |
End If | |
End If | |
End Function | |
Function fnErrHand() 'handle database connection errors | |
Call fnWriteLog("Database Error: " & Err.Number & ", source: " & Err.Source & ", description: " & Err.Description, strLogFl) | |
Do Until strConnectTimeLeft = 0 | |
Call fnUpdateIE("Database connection interrupted<BR>Connect attempt " & strErrCount & "<BR>Reconnecting in " & strConnectTimeLeft & " seconds<BR>") | |
WScript.Sleep 1000 | |
strConnectTimeLeft = strConnectTimeLeft - 1 | |
Loop | |
' If strErrCount = 5 Then | |
' bMsgErrHandQuit = MsgBox("Utility exiting, see log for details",16,strUtilTitle) | |
' objExplorer.Quit | |
' WScript.Quit | |
' End If | |
Err.Clear | |
End Function | |
Function fndbSybaseConnect(inFrom) 'setup sybase connection | |
On Error Resume Next | |
Err.Clear | |
a = sqlSybConn.State | |
If Err = 424 Then | |
Set sqlSybConn = WScript.CreateObject("ADODB.Connection") | |
sqlSybConn.ConnectionString = "Provider=Sybase.ASEOLEDBProvider.2;Server Name=" & strSybServer & ";Server Port Address=" & strSybPort & ";Initial Catalog=***REMOVED***;User ID=***REMOVED***;Password=" & ***REMOVED*** & ";Workstation ID=" & ***REMOVED*** & ";UseCursor=1" | |
End If | |
If inFrom <> "fndbCheckMaint" Then | |
Call fnWriteLog("Opening connection to ***REMOVED*** @ " & strSybServer & ", port " & strSybPort & " as " & strSybWorkstation & " (Hint: 'sp_who sa' output will show this name)", strLogFl) | |
End If | |
Do Until sqlSybConn.State = 1 | |
Err.Clear | |
sqlSybConn.Open | |
If Err.Number <> 0 Then | |
strErrCount = strErrCount + 1 | |
Call fnErrHand() | |
End If | |
Loop | |
On Error Goto 0 | |
End Function | |
Function fndbSybasePRODConnect(inFrom) 'setup sybase connection | |
On Error Resume Next | |
Err.Clear | |
b = sqlSybPRODConn.State | |
If Err = 424 Then | |
Set sqlSybPRODConn = WScript.CreateObject("ADODB.Connection") | |
sqlSybPRODConn.ConnectionString = "Provider=Sybase.ASEOLEDBProvider.2;Server Name=" & strSybServer & ";Server Port Address=***REMOVED***;Initial Catalog=master;User ID=***REMOVED***;Password=***REMOVED***;Workstation ID=" & ***REMOVED*** & ";UseCursor=1" | |
End If | |
Call fnWriteLog("Opening connection to ***REMOVED*** @ " & strSybServer & ", port ***REMOVED*** as " & strSybWorkstation & " (Hint: 'sp_who ***REMOVED***' output will show this name)", strLogFl) | |
Do Until sqlSybPRODConn.State = 1 | |
Err.Clear | |
sqlSybPRODConn.Open | |
If Err.Number <> 0 Then | |
strErrCount = strErrCount + 1 | |
Call fnErrHand() | |
End If | |
Loop | |
On Error Goto 0 | |
End Function | |
Function fndbEAConnect() ' setup EA datbase connection | |
If strEADatabase <> "" Then | |
Call fnWriteLog("Opening connection to EA, database " & strEADatabase, strLogFl) | |
End If | |
On Error Resume Next | |
Set sqlEAConn = WScript.CreateObject("ADODB.Connection") | |
sqlEAConn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=***REMOVED***" | |
***REMOVED*** | |
***REMOVED*** | |
Do Until sqlEAConn.State = 1 | |
Err.Clear | |
sqlEAConn.open | |
If Err <> 0 Then | |
strErrCount = strErrCount + 1 | |
Call fnErrHand() | |
End If | |
Loop | |
If Not IsEmpty(strEADatabase) Then | |
sqlEAConn.DefaultDatabase = ***REMOVED*** | |
Else | |
sqlEAConn.DefaultDatabase = ***REMOVED*** | |
End If | |
On Error Goto 0 | |
End Function | |
Function fnArryStuffed(arrIn) 'determines if an array has any data in it - true means data is in the array | |
fnArryStuffed = False | |
If IsArray(arrIn) Then | |
On Error Resume Next | |
upper = UBound(arrIn) | |
If (Err.Number = 0) And (upper >= 0) Then fnArryStuffed = True | |
On Error Goto 0 | |
End If | |
End Function | |
Function fnSleepyTime(inSleepTimeMins,inReason) 'pause during incremental load times | |
'do this in case value is not legit | |
inSleepTimeMins2 = inSleepTimeMins | |
If IsNumeric(inSleepTimeMins2) Then | |
inSleepTimeMins2 = Abs(inSleepTimeMins2) 'make sure it's a positive number | |
Else | |
inSleepTimeMins2 = 10 | |
End If | |
'write to the log file and close database connections (sybase takes 60 seconds to clear from sp_who) | |
sqlSybConn.Close | |
Call fnWriteLog("Closing connection to ***REMOVED*** @ " & strSybServer & ", port " & strSybPort, strLogFl) | |
sqlEAConn.Close | |
Call fnWriteLog("Closing connection to ***REMOVED*** database " & strEADatabase, strLogFl) | |
Call fnWriteLog("Paused for " & inSleepTimeMins2 & " minutes " & inReason, strLogFl) | |
'update IE and hang out until the time passes | |
Do Until inSleepTimeMins2 = -1 'this will add a minute for sybase close time and make sure it still works if user sets sleep time to 0 | |
strSec = 59 | |
Do Until strSec = 0 | |
strSec = strSec - 1 | |
WScript.Sleep 1000 | |
Call fnUpdateIE("Paused " & inReason & "<BR><BR>" & vbCrLf & "Resuming in " & fnPad(inSleepTimeMins2,2) & ":" & fnPad(strSec,2) & " (mm:ss).") | |
Loop | |
inSleepTimeMins2 = inSleepTimeMins2 - 1 | |
Loop | |
strMaintAvail = "" | |
Do Until strMaintAvail = "MAINT_AVAILABLE" 'make sure a backup job is not in progress | |
Call fndbCheckMaint(strSybDisconnTime) | |
Loop | |
End Function | |
Function fndbCheckMaint(inCheckIntervalMins) 'Check to see if MAINT is undergoing a backup/load | |
'find out if any backups are in progress on ***REMOVED*** | |
inCheckIntervalMins2 = inCheckIntervalMins | |
Call fnWriteLog("Checking ***REMOVED*** @ " & strSybServer & ", port " & strSybPort & " to see if any backups are in progress", strLogFl) | |
SQLCheckMaint = "if exists (select 1 from master..sysprocesses where hostname in ('***REMOVED***', '***REMOVED***', '***REMOVED***.. '***REMOVED***', '***REMOVED***', '***REMOVED***')) begin select 'MAINT_BUSY' as RESULT end else begin select 'MAINT_AVAILABLE' as RESULT end" | |
On Error Resume Next | |
If sqlSybConn.State <> 1 Then | |
Call fndbSybaseConnect("fndbCheckMaint") | |
End If | |
Err.Clear | |
If sqlSybRs.State <> 0 Then | |
sqlSybRs.Close | |
End If | |
Err.Clear | |
sqlSybRs.Open SQLCheckMaint, sqlSybConn | |
If Err = 0 Then | |
strMaintAvail = sqlSybRs("RESULT") | |
If strMaintAvail <> "MAINT_AVAILABLE" Then | |
Call fnWriteLog("Paused for " & inCheckIntervalMins2 & " minutes because a ***REMOVED*** backup task is in progress", strLogFl) | |
'update IE and hang out until the time passes | |
Do Until inCheckIntervalMins2 = -1 'this will add a minute for sybase close time and make sure it still works if user sets sleep time to 0 | |
strSec = 59 | |
Do Until strSec = 0 | |
strSec = strSec - 1 | |
WScript.Sleep 1000 | |
Call fnUpdateIE("Paused because a ***REMOVED*** backup task is in progress<BR><BR>" & vbCrLf & "Checking again in " & fnPad(inCheckIntervalMins2,2) & ":" & fnPad(strSec,2) & " (mm:ss).") | |
Loop | |
inCheckIntervalMins2 = inCheckIntervalMins2 - 1 | |
Loop | |
End If | |
Else | |
Call fnErrHand() | |
End If | |
sqlrs.Close | |
sqlSybConn.Close | |
On Error Goto 0 | |
End Function | |
Function fnSybNoConn(inMsg) | |
objExplorer.Visible = 0 | |
MsgFailConn = "Could not connect to Sybase @ " & strSybServer & vbCrLf & inMsg | |
Call fnWriteLog(Replace(Replace(MsgFailConn, Chr(13), ": "),Chr(10),""), strLogFl) | |
bMsgFailConn = MsgBox(MsgFailConn,16,strUtilTitle) | |
strSybServer = "" | |
strSybPass = "" | |
Call fnWriteConf() | |
objExplorer.Quit | |
WScript.Quit | |
End Function | |
Function fndbSybPRODInsertArchiveQueue(inckey) | |
Set sqlSybPRODRs = WScript.CreateObject("ADODB.RecordSet") | |
sqlSybPRODRs.CursorType = adOpenForwardOnly | |
On Error Resume Next | |
If sqlSybPRODRs.State <> 0 Then | |
sqlSybPRODRs.Close | |
End If | |
'????sqlSybPRODRs.Open SQLSybPROD, sqlSybPRODConn | |
If Err.Number <> 0 Then | |
'Call fnWriteLog("Unable to obtain sybase study uid for ***REMOVED*** " & strSybStudyCkey, strLogFl) | |
WScript.Sleep 1000 | |
Call fnSleepyTime(5,"because the sybase connection is temporarily unavailable") | |
strSybStudyCkey = strSybStudyCkey - 2 | |
Call fndbSybasePRODConnect("study uid") | |
Else | |
If Not sqlSybPRODRS.EOF Then | |
'strSybStudyUID = sqlSybRs("study_instance_uid") | |
End If | |
sqlSybPRODRs.Close | |
End If | |
On Error Goto 0 | |
'fndbSybasePRODConnect | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment