Jump to content

GUI Inefficiencies


Recommended Posts

In a nutshell I made a program that was designed to replace a front desk sign in sheet. It is a super hacky fix in many ways. The program and all of its support files (including the MSAccess database) are stored on a network drive and each user has a shortcut to the executable.

When the executable it launched the program reads 4 small images for buttons and 4 small ini files (less than 50 lines total) for control settings than draws the gui, which is mostly just a listviewbox that refreshes every 2 minutes.

This program has been running fine on most computers but there are a few that are having an issue (the older ones I’m sure). 5% of the computers (or so) are having serious latency issues with their Citrix applications. I have confirmed that my program is the issue because the Citrix app lags while its running and the problem immediately fixes itself when you close my application, in addition it immediately lags again when you start it back up. My program doesn’t seem to be effected, this only happens when the user is actively using the Citrix app (ie NOT using my program).

I make no claims of being an expert programmer and I didn’t really think about system performance when I wrote it (I just assumed any PC could handle it). When I look at system resources I am only taking up 23k (so like the 5-8th program down the list). Is there something I am doing wrong when creating the GUI? I'm assuming there is some standard "you should never do ....when making a UI loop" or something.

I have included the part of my program that draws the GUI (all other functions are called on demand or every 2 minutes so are unlikely the issue since this is a constant issue that only appears when my program is NOT being used).

Thanks!

#include <Array.au3>
#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <guilistview.au3>
#include <GuiRichEdit.au3>
#NoTrayIcon
;Checks to see if the kill file exsists (for upgrade/hot fix purposes)
If FileExists(@scriptdir & "\kill.txt") Then
MsgBox(0,"Error", "The system is currently being updated. You will now be logged out.",5)
Exit
EndIf
Opt("GUIOnEventMode", 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN WINDOW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$mainwindow = GuiCreate("Patient Tracker 2.0", @DesktopWidth, @DesktopHeight, 0, 0,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")
GUISetState(@SW_SHOW,$mainwindow)

$font = "Comic Sans MS"
GUISetFont(12, 400, 0, $font) ; will display underlined characters
$btnnew = GUICtrlCreateButton("New",10, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnnew, @ScriptDir & "\Icons\new.bmp")
GUICtrlSetOnEvent($btnnew, "FunNew")
GUICtrlSetTip($btnnew, "Create New Patient")

$btnrefresh = GUICtrlCreateButton("Refresh",90, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnrefresh, @ScriptDir & "\Icons\refresh.bmp")
GUICtrlSetOnEvent($btnrefresh, "FunRead")
GUICtrlSetTip($btnrefresh, "Refresh List")
$btnfilter = GUICtrlCreateButton("Filter",170, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnfilter, @ScriptDir & "\Icons\filter.bmp")
GUICtrlSetOnEvent($btnfilter, "FunFilters")
GUICtrlSetTip($btnfilter, "Change Filter / Search Criteria")

$btnwait = GUICtrlCreateButton("Wait",250, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnwait, @ScriptDir & "\Icons\wait.bmp")
GUICtrlSetOnEvent($btnwait, "FunWait")
GUICtrlSetTip($btnwait, "Current Wait Time")
GUICtrlSetState($btnwait, $GUI_DISABLE)

$btnuser = GUICtrlCreateButton(@UserName,@DesktopWidth - 250, 25,200)
GUICtrlSetOnEvent($btnuser, "FunChangeUser")
GUICtrlSetTip($btnwait, "Current User Name")
; MENU
$filemenu1 = GuiCtrlCreateMenu("File")
$fileitem11 = GUICtrlCreateMenuItem("New Patient", $filemenu1)
GUICtrlSetOnEvent($fileitem11, "FunNew")
$fileitem12 = GUICtrlCreateMenuItem("Filter", $filemenu1)
GUICtrlSetOnEvent($fileitem12,"FunFilters")
$fileitem13 = GUICtrlCreateMenuItem("Exit", $filemenu1)
GUICtrlSetOnEvent($fileitem13,"FunClose")

$filemenu2 = GuiCtrlCreateMenu("Help")
$fileitem21 = GUICtrlCreateMenuItem("What's New", $filemenu2)
$fileitem22 = GUICtrlCreateMenu("Reference", $filemenu2)
$fileitem221 = GUICtrlCreateMenuItem("Front Desk", $fileitem22)
$fileitem222 = GUICtrlCreateMenuItem("Registration", $fileitem22)
$fileitem223 = GUICtrlCreateMenuItem("Tech", $fileitem22)
GUICtrlSetOnEvent($fileitem21, "FunVersion")
GUICtrlSetOnEvent($fileitem221, "FunFront")
GUICtrlSetOnEvent($fileitem222, "FunReg")
GUICtrlSetOnEvent($fileitem223, "FunTech")

;List
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)
Global $mainlist = GUICtrlCreateListView("", 10, 90, @DesktopWidth - 20, @DesktopHeight - 200, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($mainlist, $iExListViewStyle)
GUICtrlSetOnEvent($mainlist, "FunEdit")
$columnlabels = StringSplit(IniRead("listview.ini","LISTVIEW","COLUMNSLABEL","ERROR|ERROR") & "|ID","|")
$columnwidth = StringSplit(IniRead("listview.ini","LISTVIEW","COLUMNSWIDTH","100|100") & "|0","|")

$i = 1
While $i < UBound($columnlabels)
_GUICtrlListView_AddColumn($mainlist, $columnlabels[$i], $columnwidth[$i])
$i = $i + 1
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GLOBAL VARIABLES;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $dropdown1order
Global $tablename = @MDAY
Global $varcombo1
Global $varcombo2
Global $varcombo1default
Global $varcombo2default
Global $varcheckbox1
Global $radio1[10]
Global $chkbox1[10]
Global $cmbstatus1
Global $cmbstatus2
Global $fieldstring = "ID|LastName|FirstName|Notes|"
Global $TheQuery[100]
Global $combocheckbox[10]
Global $combocheckbox2[10]
Global $columnlabels
Global $columnwidth
Global $columntranslate
$columntranslate = IniRead("listview.ini","LISTVIEW", "COLUMNSTRANSLATE", "BLANK")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CHILD PATIENT WINDOW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$childGui2 = GUICreate("Add/Edit Patient", IniRead("Patient.ini", "GUI", "WIDTH", 500), IniRead("Patient.ini", "GUI", "HEIGHT", 500), 100, 100, BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
$lbllast = GUICtrlCreateLabel("Last Name", 10,10)
$iptlast = GUICtrlCreateInput("", 20, 35, 150,20,0x0008)
$lblfirst = GUICtrlCreateLabel("First Name", 10,65)
$lblID = GUICtrlCreateLabel("",-500,100,0)
$iptfirst = GUICtrlCreateInput("", 20, 90, 150,20,0x0008)
$btnpromote = GUICtrlCreateButton("Promote",20,250,120)
$btnDemote = GUICtrlCreateButton("Demote", 170,250,120)
$btnaudit = GUICtrlCreateButton("Audit", 330, 250,120)
$iptnotes = GUICtrlCreateInput("",10, 300, 480, 150)
$btnaddupdate = GUICtrlCreateButton("Add", 30, 460,150)
$btnaddcancel = GUICtrlCreateButton("Cancel", 180, 460,150)
$btnaddelete = GUICtrlCreateButton("Delete", 330, 460,150)

GUICtrlSetOnEvent($btnDemote,"FunDemote")
GUICtrlSetOnEvent($btnpromote,"FunPromote")
GUICtrlSetOnEvent($btnaudit,"FunCreateAudit")
GUICtrlSetOnEvent($btnaddupdate,"FunAdd_Update")
GUICtrlSetOnEvent($btnaddcancel,"FunPTClose")
GUICtrlSetOnEvent($btnaddelete,"FunDelete_Update")
FunPopulatePatient() ;Loads the patient.ini file to populate the patient window UI
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CHILD FILTER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;only filters on combo1 and checkbox1 at the moment
$childGui = GUICreate("Filters", IniRead("Filter.ini", "GUI", "WIDTH",300), IniRead("Filter.ini", "GUI", "Height",300), 300,100,BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
$childbtnclose = GUICtrlCreateButton("Close Filter Window", 10,270, 280)
GUICtrlSetOnEvent($childbtnclose,"FunChildClose")
GUICtrlCreateLabel(IniRead("filter.ini", "GUI", "CHECKBOX1LABEL ", "Modality"),10, 10)
$lblfilter2 = GUICtrlCreateLabel(IniRead("filter.ini", "GUI", "DROPDOWN1LABEL", "Modality"),IniRead("filter.ini", "GUI", "CHECKBOX1LABELWIDTH ", "Modality") + 25,10)
GUICtrlCreateLabel("Auto Refresh (Mins)",10,200)
$childcmbtime = GUICtrlCreateCombo("", 10, 220)
$refreshtime = 2;IniRead(@scriptdir & "\config\" & @username & ".ini", "Defaults","refresh",0)
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10", $refreshtime)
FunPopulateFilter() ;reads inifiles and sets control

FunRead() ;function that queries the database and populates the listbox
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
$zz = 1
_GUICtrlListView_RegisterSortCallBack($mainlist)
While 1
If $zz > $refreshtime * 600 Then
If FileExists(@scriptdir & "\kill.txt") Then
MsgBox(0,"Error", "The system is currently being updated. You will now be logged out.",5)
Exit
Else
FunRead()
$zz = 1
EndIf
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $mainlist
_GUICtrlListView_SortItems($mainlist, GUICtrlGetState($mainlist))
EndSwitch

$zz = $zz + 1
;$msg = GUIGetMsg()
Sleep(100)
WEnd
_GUICtrlListView_UnRegisterSortCallBack($mainlist)
Edited by Melba23
Fixed tags
Link to comment
Share on other sites

When posting code please wrap it in [autoit][/autoit] tags.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Just letting you know, this:

Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $mainlist
            _GUICtrlListView_SortItems($mainlist, GUICtrlGetState($mainlist))
    EndSwitch

Won't work with this:

Opt("GUIOnEventMode", 1)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Have you done any testing to see when your program begins to consume an inordinate amount of resources (i.e. as soon as it is launched, as soon as the child gui is launched, after clicking a specific button, etc.)?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Where are the rest of the functions that this script uses? Because it quite possibly is inside one of those, because this script doesn't have anything obvious as to why it happens.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The odd thing is it does it right away. I tested it and if I launch my script and immediatly alt tab into Citrix I get a delay. Here is the full code though it is a bit long. There is also 1 device that cannot even launch the application.

Here is the full code

#include <Array.au3>
#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <guilistview.au3>
#include <GuiRichEdit.au3>
#include <String.au3>
#NoTrayIcon
;Checks to see if the kill file exsists (for upgrade/hot fix purposes)
If FileExists(@scriptdir & "\kill.txt") Then
MsgBox(0,"Error", "The system is currently being updated. You will now be logged out.",5)
Exit
EndIf
Opt("GUIOnEventMode", 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN WINDOW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$mainwindow = GuiCreate("Patient Tracker 2.0", @DesktopWidth, @DesktopHeight, 0, 0,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")
GUISetState(@SW_SHOW,$mainwindow)

$font = "Comic Sans MS"
GUISetFont(12, 400, 0, $font) ; will display underlined characters
$btnnew = GUICtrlCreateButton("New",10, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnnew, @ScriptDir & "\Icons\new.bmp")
GUICtrlSetOnEvent($btnnew, "FunNew")
GUICtrlSetTip($btnnew, "Create New Patient")

$btnrefresh = GUICtrlCreateButton("Refresh",90, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnrefresh, @ScriptDir & "\Icons\refresh.bmp")
GUICtrlSetOnEvent($btnrefresh, "FunRead")
GUICtrlSetTip($btnrefresh, "Refresh List")
$btnfilter = GUICtrlCreateButton("Filter",170, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnfilter, @ScriptDir & "\Icons\filter.bmp")
GUICtrlSetOnEvent($btnfilter, "FunFilters")
GUICtrlSetTip($btnfilter, "Change Filter / Search Criteria")

$btnwait = GUICtrlCreateButton("Wait",250, 10, 70, 70, $BS_BITMAP)
GUICtrlSetImage($btnwait, @ScriptDir & "\Icons\wait.bmp")
GUICtrlSetOnEvent($btnwait, "FunWait")
GUICtrlSetTip($btnwait, "Current Wait Time")
GUICtrlSetState($btnwait, $GUI_DISABLE)

$btnuser = GUICtrlCreateButton(@UserName,@DesktopWidth - 250, 25,200)
GUICtrlSetOnEvent($btnuser, "FunChangeUser")
GUICtrlSetTip($btnwait, "Current User Name")
; MENU
$filemenu1 = GuiCtrlCreateMenu("File")
$fileitem11 = GUICtrlCreateMenuItem("New Patient", $filemenu1)
GUICtrlSetOnEvent($fileitem11, "FunNew")
$fileitem12 = GUICtrlCreateMenuItem("Filter", $filemenu1)
GUICtrlSetOnEvent($fileitem12,"FunFilters")
$fileitem13 = GUICtrlCreateMenuItem("Exit", $filemenu1)
GUICtrlSetOnEvent($fileitem13,"FunClose")

$filemenu2 = GuiCtrlCreateMenu("Help")
$fileitem21 = GUICtrlCreateMenuItem("What's New", $filemenu2)
$fileitem22 = GUICtrlCreateMenu("Reference", $filemenu2)
$fileitem221 = GUICtrlCreateMenuItem("Front Desk", $fileitem22)
$fileitem222 = GUICtrlCreateMenuItem("Registration", $fileitem22)
$fileitem223 = GUICtrlCreateMenuItem("Tech", $fileitem22)
GUICtrlSetOnEvent($fileitem21, "FunVersion")
GUICtrlSetOnEvent($fileitem221, "FunFront")
GUICtrlSetOnEvent($fileitem222, "FunReg")
GUICtrlSetOnEvent($fileitem223, "FunTech")

;List
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)
Global $mainlist = GUICtrlCreateListView("", 10, 90, @DesktopWidth - 20, @DesktopHeight - 200, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($mainlist, $iExListViewStyle)
GUICtrlSetOnEvent($mainlist, "FunEdit")
$columnlabels = StringSplit(IniRead("listview.ini","LISTVIEW","COLUMNSLABEL","ERROR|ERROR") & "|ID","|")
$columnwidth = StringSplit(IniRead("listview.ini","LISTVIEW","COLUMNSWIDTH","100|100") & "|0","|")

$i = 1
While $i < UBound($columnlabels)
_GUICtrlListView_AddColumn($mainlist, $columnlabels[$i], $columnwidth[$i])
$i = $i + 1
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GLOBAL VARIABLES;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $dropdown1order
Global $tablename = @MDAY
Global $varcombo1
Global $varcombo2
Global $varcombo1default
Global $varcombo2default
Global $varcheckbox1
Global $radio1[10]
Global $chkbox1[10]
Global $cmbstatus1
Global $cmbstatus2
Global $fieldstring = "ID|LastName|FirstName|Notes|"
Global $TheQuery[100]
Global $combocheckbox[10]
Global $combocheckbox2[10]
Global $columnlabels
Global $columnwidth
Global $columntranslate
$columntranslate = IniRead("listview.ini","LISTVIEW", "COLUMNSTRANSLATE", "BLANK")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CHILD PATIENT WINDOW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$childGui2 = GUICreate("Add/Edit Patient", IniRead("Patient.ini", "GUI", "WIDTH", 500), IniRead("Patient.ini", "GUI", "HEIGHT", 500), 100, 100, BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
$lbllast = GUICtrlCreateLabel("Last Name", 10,10)
$iptlast = GUICtrlCreateInput("", 20, 35, 150,20,0x0008)
$lblfirst = GUICtrlCreateLabel("First Name", 10,65)
$lblID = GUICtrlCreateLabel("",-500,100,0)
$iptfirst = GUICtrlCreateInput("", 20, 90, 150,20,0x0008)
$btnpromote = GUICtrlCreateButton("Promote",20,250,120)
$btnDemote = GUICtrlCreateButton("Demote", 170,250,120)
$btnaudit = GUICtrlCreateButton("Audit", 330, 250,120)
$iptnotes = GUICtrlCreateInput("",10, 300, 480, 150)
$btnaddupdate = GUICtrlCreateButton("Add", 30, 460,150)
$btnaddcancel = GUICtrlCreateButton("Cancel", 180, 460,150)
$btnaddelete = GUICtrlCreateButton("Delete", 330, 460,150)

GUICtrlSetOnEvent($btnDemote,"FunDemote")
GUICtrlSetOnEvent($btnpromote,"FunPromote")
GUICtrlSetOnEvent($btnaudit,"FunCreateAudit")
GUICtrlSetOnEvent($btnaddupdate,"FunAdd_Update")
GUICtrlSetOnEvent($btnaddcancel,"FunPTClose")
GUICtrlSetOnEvent($btnaddelete,"FunDelete_Update")
FunPopulatePatient() ;Loads the patient.ini file to populate the patient window UI
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CHILD FILTER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;only filters on combo1 and checkbox1 at the moment
$childGui = GUICreate("Filters", IniRead("Filter.ini", "GUI", "WIDTH",300), IniRead("Filter.ini", "GUI", "Height",300), 300,100,BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
$childbtnclose = GUICtrlCreateButton("Close Filter Window", 10,270, 280)
GUICtrlSetOnEvent($childbtnclose,"FunChildClose")
GUICtrlCreateLabel(IniRead("filter.ini", "GUI", "CHECKBOX1LABEL ", "Modality"),10, 10)
$lblfilter2 = GUICtrlCreateLabel(IniRead("filter.ini", "GUI", "DROPDOWN1LABEL", "Modality"),IniRead("filter.ini", "GUI", "CHECKBOX1LABELWIDTH ", "Modality") + 25,10)
GUICtrlCreateLabel("Auto Refresh (Mins)",10,200)
$childcmbtime = GUICtrlCreateCombo("", 10, 220)
$refreshtime = 2;IniRead(@scriptdir & "\config\" & @username & ".ini", "Defaults","refresh",0)
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10", $refreshtime)
FunPopulateFilter()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CHILD Wait;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;only filters on combo1 and checkbox1 at the moment
$childGui3 = GUICreate("Wait Time Check", 200, 200, 300,100,BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
$childbtncalc = GUICtrlCreateButton("Check Wait Time", 10,150)
GUICtrlSetOnEvent($childbtncalc,"FunWaitTimeCalc")
GUICtrlCreateLabel("Choose Modality",20,20)
$childcmbmodality = GUICtrlCreateCombo("", 10, 50)
GUICtrlSetData(-1, "CT|XR|MR|US", 'CT')
GUICtrlCreateLabel("Choose Schedule Status",20,80)
$childcmbstatus = GUICtrlCreateCombo("", 10, 110)
GUICtrlSetData(-1, "WALK-IN|SCHEDULED", 'WALK-IN')

FunRead()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
$zz = 1
_GUICtrlListView_RegisterSortCallBack($mainlist)
While 1
If $zz > $refreshtime * 600 Then
If FileExists(@scriptdir & "\kill.txt") Then
MsgBox(0,"Error", "The system is currently being updated. You will now be logged out.",5)
Exit
Else
FunRead()
$zz = 1
EndIf
EndIf

$zz = $zz + 1
Sleep(250)
WEnd
_GUICtrlListView_UnRegisterSortCallBack($mainlist)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunPopulateListView($Parse)

_GUICtrlListView_DeleteAllItems ($mainlist)
$i = 1
While $Parse[$i] <> ""
GUICtrlCreateListViewItem($Parse[$i],$mainlist)
$i = $i + 1
WEnd
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunClean($theQuery)

;First extract modality info from filters, save them to an array $filtermodalities
$i = 1
$z = 1
$tempfiltermodalaties = ""
While $i < UBound($combocheckbox)
If GUICtrlRead($combocheckbox[$i]) = $GUI_CHECKED Then
If $z = 1 Then
    $tempfiltermodalaties = ControlGetText("Filters","",$combocheckbox[$i])
    $z = $z + 1
Else
    $tempfiltermodalaties = $tempfiltermodalaties & "~" & ControlGetText("Filters","",$combocheckbox[$i])
    $z = $z + 1 
EndIf
EndIf
$i = $i + 1
WEnd
$filtermodalaties = StringSplit($tempfiltermodalaties, "~")

Local $theQuery2[200]
$columntranslate2 = StringSplit($columntranslate,"|")
$z = 1
While $theQuery[$z] <> ""
$splitquery = StringSplit($theQuery[$z],"|")
$cleanstring = ""
$i = 1
While $i < UBound($columntranslate2)
Select
    Case $columntranslate2[$i] = "ID"
     $cleanstring = $cleanstring & $splitquery[1] & "|"
    Case $columntranslate2[$i] = "LastName"
     $cleanstring = $cleanstring & $splitquery[2] & "|"
    Case $columntranslate2[$i] = "FirstName"
     $cleanstring = $cleanstring & $splitquery[3] & "|"
    Case $columntranslate2[$i] = "TotalTime"
     $cleanstring = $cleanstring & FunTimeDeltaTotal($splitquery) & "|"
    Case $columntranslate2[$i] = "CurrentStatusTime"
     $cleanstring = $cleanstring & FunTimeDeltaCurrent($splitquery) & "|"
    Case $columntranslate2[$i] = "Combo1"
     $cleanstring = $cleanstring & $splitquery[6] & "|"
    Case $columntranslate2[$i] = "Combo2"
     $cleanstring = $cleanstring & $splitquery[7] & "|"
    Case $columntranslate2[$i] = "Check1"
     $cleanstring = $cleanstring & StringReplace($splitquery[8], "~", " ") & "|"
    Case $columntranslate2[$i] = "Radio1"
     $cleanstring = $cleanstring & $splitquery[9] & "|"
    Case $columntranslate2[$i] = "Check2"
     $cleanstring = $cleanstring & $splitquery[10] & "|"
    Case $columntranslate2[$i] = "Radio2"
     $cleanstring = $cleanstring & $splitquery[11] & "|"
    Case $columntranslate2[$i] = "Notes"
     $cleanstring = $cleanstring & $splitquery[12] & "|"
    Case $columntranslate2[$i] = "ExactDay"
     $cleanstring = $cleanstring & $splitquery[13] & "|"
    Case $columntranslate2[$i] = "BlankField"
     $cleanstring = $cleanstring & $splitquery[14] & "|"
    Case $columntranslate2[$i] = "Lock"
     $cleanstring = $cleanstring & $splitquery[15] & "|"
EndSelect
$i = $i + 1
WEnd

$TheQuery2[$z] = $cleanstring
$z= $z + 1
Wend
Return($TheQuery2)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunRead()

$TheQuery = ""
Global $TheQuery[100]
Local $title,$adoCon,$dbname,$adoRs, $_output
; create connection
$adoCon = ObjCreate("ADODB.Connection")
$dbname = @ScriptDir & "\" & "Patient Database.mdb"
; this is for Access 2007 / 2010 according to Microsoft
$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)
; create recordset
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$query = "SELECT * FROM "& $tablename & " WHERE (Combo1 = "
;Looking for status in filters
$i = 1
$z = 1
While $i < UBound($combocheckbox2)
If GUICtrlRead($combocheckbox2[$i]) = $GUI_CHECKED Then
If $z = 1 Then
    $query = $query & "'" & ControlGetText("Filters","",$combocheckbox2[$i]) & "'"
    $z = $z + 1
Else
    $query = $query & " or Combo1 = '" & ControlGetText("Filters","",$combocheckbox2[$i]) & "'"
    $z = $z + 1 
EndIf
EndIf
$i = $i + 1
WEnd
If $z > 1 Then ;make sure there is a status selected
$query = $query & ") AND ("
; Looking for modalaties in filters
$i = 1
$z = 1
While $i < UBound($combocheckbox)
If GUICtrlRead($combocheckbox[$i]) = $GUI_CHECKED Then
    If $z = 1 Then
     $query = $query & "Check1 LIKE '%" & ControlGetText("Filters","",$combocheckbox[$i]) & "%'"
     $z = $z + 1
    Else
     $query = $query & " or Check1 LIKE '%" & ControlGetText("Filters","",$combocheckbox[$i]) & "%'"
     $z = $z + 1    
    EndIf
EndIf
$i = $i + 1
WEnd

$query = $query & ");"
If $z > 1 Then ;make sure a modality was selected
$adoRs.Open ($query, $adoCon)
$i = 1
While $i < 99
    if $adoRs.RecordCount then
     If not ($adoRs.EOF) Then
     $TheQuery[$i] = $adoRs.Fields("ID").Value & "|" & _StringEncrypt(0,$adoRs.Fields("LastName").Value,"RandoPassword321") & "|" & _StringEncrypt(0,$adoRs.Fields("FirstName").Value,"RandoPassword321") & "|" & _
         $adoRs.Fields("TotalTime").Value & "|" & $adoRs.Fields("CurrentStatusTime").Value & "|" & $adoRs.Fields("Combo1").Value & "|" & _
         $adoRs.Fields("Combo2").Value & "|" & $adoRs.Fields("Check1").Value & "|" & $adoRs.Fields("Radio1").Value & "|" & _
         $adoRs.Fields("Check2").Value & "|" & $adoRs.Fields("Radio2").Value & "|" & $adoRs.Fields("Notes").Value & "|" & _
         $adoRs.Fields("ExactDay").Value & "|" & $adoRs.Fields("BlankField").Value & "|" & $adoRs.Fields("Lock").Value  
     $adoRs.MoveNext
     Else
     ExitLoop
     Endif
    EndIf
    $i = $i + 1
WEnd
EndIf
EndIf
FunPopulateListView(FunClean($TheQuery))
$adoCon.Close
_GUICtrlListView_SortItems($mainlist, GUICtrlGetState($mainlist))
_GUICtrlListView_SortItems($mainlist, GUICtrlGetState($mainlist))

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunSQL($type, $data)

Select
Case $type = "Add"
$fields = StringSplit($fieldstring,"|")
$info = Stringsplit($data,"|")
$query = "INSERT INTO "& $tablename & " ( ID"
$i = 2

While $i < UBound($info)

$query = $query & ", " & $fields[$i]
$i = $i + 1

WEnd

$query = $query & ", TotalTime, CurrentStatusTime, ExactDay ) VALUES ( '" & $info[1] & "'"
$i = 2
While $i < UBound($info)

$query = $query & ", '" & $info[$i] & "'"
$i = $i + 1

WEnd
$query = $query & ", '" & @HOUR & ":" & @MIN & "', '" & @HOUR & ":" & @MIN & "', '" & @Mon & "/" & @MDAY & "');"
Case $type = "Update"
$fields = StringSplit($fieldstring,"|")
$info = Stringsplit($data,"|")
$query = "Update "& $tablename & " SET LastName = '" & $info[2] & "'"
$i = 3

While $i < UBound($info)

$query = $query & ", " & $fields[$i] & " = '" & $info[$i] & "'"
$i = $i + 1

WEnd
$query = $query & ", CurrentStatusTime = '" & @HOUR & ":" & @MIN & "', ExactDay = '" & @Mon & "/" & @MDAY & "' Where ID = " & $info[1] & ";"
Case $type = "Delete"
$fields = StringSplit($fieldstring,"|")
$info = Stringsplit($data,"|")
$query = "Update "& $tablename & " SET LastName = '" & $info[2] & "'"
$i = 3

While $i < UBound($info)

$query = $query & ", " & $fields[$i] & " = '" & $info[$i] & "'"
$i = $i + 1

WEnd
$query = $query & " Where ID = " & $info[1] & ";"
;$query = "Update "& $tablename & " SET LastName = 'MUD', FirstName = 'MYNAME' Where ID = 42129;"
$fields = StringSplit($fieldstring,"|")
$info = Stringsplit($data,"|")
$query = "Update "& $tablename & " SET Combo1 = 'DELETE' Where ID = " & $info[1] & ";"

EndSelect

Local $title,$adoCon,$dbname,$adoRs, $_output
$adoCon = ObjCreate("ADODB.Connection")
$dbname = @ScriptDir & "\" & "Patient Database.mdb"
$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.open($query, $adoCon)
$adoCon.Close
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunFinishCheck($fields,$info)

$i = 1
While $i < UBound($fields)
If $fields[$i] = "Combo1" Then
If $info[$i] = "Finished" Then
    Return 1
Else
    Return 0
EndIf
EndIf
$i = $i + 1
WEnd

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunExtract()
Local $extractstring
$extractstring = GUICtrlRead($lblID)
$extractstring = $extractstring & "|" & _StringEncrypt(1,StringReplace(GUICtrlRead($iptlast), "'",""),"RandoPassword321")
$extractstring = $extractstring & "|" & _StringEncrypt(1,StringReplace(GUICtrlRead($iptfirst), "'",""),"RandoPassword321")
$extractstring = $extractstring & "|" & StringReplace(GUICtrlRead($iptnotes), "'","")
$extractstring = $extractstring & "|"
$i = 1
While $i < 10
If GUICtrlRead($chkbox1[$i]) = "1" Then
$extractstring = $extractstring & "~" & ControlGetText ("Add/Edit Patient", "", $chkbox1[$i] )
EndIf
$i = $i + 1
WEnd
$extractstring = $extractstring & "|" & GUICtrlRead($cmbstatus1)
; $extractstring = $extractstring & "|" & GUICtrlRead($cmbstatus2)
$extractstring = $extractstring & "|"

$i = 1
While $i < 10
If GUICtrlRead($radio1[$i]) = "1" Then
$extractstring = $extractstring & ControlGetText ("Add/Edit Patient", "", $radio1[$i] )
EndIf
$i = $i + 1
WEnd

Return $extractstring
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunEdit()
If GUICtrlRead(GUICtrlRead($mainlist)) <> "0" Then
$listviewstring = StringSplit(GUICtrlRead(GUICtrlRead($mainlist)),"|")
If $listviewstring[1] <> "" And $listviewstring[1] <> GUICtrlRead($btnuser) Then
    MsgBox(0,"Ooops", "You have locked a patient at the same time as " & $listviewstring[1])
Else
     ;Set combo1 to default
    If GUICtrlGetState($cmbstatus1) > 0 Then
     GUICtrlSetData($cmbstatus1, "")
     GUICtrlSetData($cmbstatus1,$varcombo1,$varcombo1default)
    EndIf
    ;Set combo2 to default
    If GUICtrlGetState($cmbstatus2) > 0 Then
     GUICtrlSetData($cmbstatus2, "")
     GUICtrlSetData($cmbstatus2,$varcombo2,$varcombo2default)
    EndIf
    ;Set radio1 to default
    $i = 1
    While $i < 10
     If GUICtrlGetState($chkbox1[$i]) > 0 Then GUICtrlSetState($chkbox1[$i],$GUI_UNCHECKED)
     $i = $i + 1
    WEnd
    ;Set checkbox1 to default
    GUICtrlSetData($btnaddupdate,"Edit")
    GUICtrlSetState($btnnew,$GUI_DISABLE)
    GUICtrlSetState($btnrefresh,$GUI_DISABLE)
    GUICtrlSetState($btnfilter,$GUI_DISABLE)
    GUICtrlSetState($btnuser,$GUI_DISABLE)
    GUICtrlSetState($mainlist,$GUI_DISABLE)
    GUICtrlSetData($iptlast,"")
    GUICtrlSetData($iptfirst,"")
    GUICtrlSetData($iptnotes,"")
    GUICtrlSetState($radio1[1], $GUI_CHECKED)
    $i = 1
    While $i < UBound($chkbox1)
     GUICtrlSetState($chkbox1[$i] ,$GUI_UNCHECKED)
     $i = $i + 1
    WEnd
    
    GUISetState(@SW_SHOW, $childGui2)
    $columntranslate2 = StringSplit($columntranslate,"|")
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "LastName" Then GUICtrlSetData($iptlast,$listviewstring[$i])
     $i = $i + 1
    WEnd
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "FirstName" Then GUICtrlSetData($iptfirst,$listviewstring[$i])
     $i = $i + 1
    WEnd
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "Notes" Then GUICtrlSetData($iptnotes,$listviewstring[$i])
     $i = $i + 1
    WEnd
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "ID" Then GUICtrlSetData($lblID,$listviewstring[$i])
     $i = $i + 1
    WEnd
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "Combo1" Then GUICtrlSetData($cmbstatus1,$listviewstring[$i])
     $i = $i + 1
    WEnd
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "Combo2" Then GUICtrlSetData($cmbstatus2,$listviewstring[$i])
     $i = $i + 1
    WEnd
    
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "Radio1" Then GUICtrlSetData($radio1, $listviewstring[$i])
     $i = $i + 1
    WEnd
    $i = 1
    While $i < Ubound($columntranslate2)
     If $columntranslate2[$i] = "Check1" Then
     $modalitysplit = StringSplit($listviewstring[$i]," ")
     $n = 1
    
     While $n < UBound($chkbox1)
     $j = 1
     While $j < UBound($modalitysplit)
        If ControlGetText("Add/Edit Patient","",$chkbox1[$n]) = StringReplace(StringReplace($modalitysplit[$j]," ", ""),"|","") Then GUICtrlSetState($chkbox1[$n] ,$GUI_CHECKED)
        $j = $j + 1
     WEnd
     $n = $n + 1
     Wend
     EndIf
     $i = $i + 1
    WEnd
    $lockname = FunLockCheck()
    If $lockname <> "" And $lockname <> GUICtrlRead($btnuser) Then
     MsgBox(0,"Ooops", "You have locked a patient at the same time as " & $lockname)
    Else
     FunLockPatient("Lock")
     GUISetState(@SW_SHOW, $childGui2)
     FunAudit("Opened Patient")
     Sleep(1500)
     $lockname = FunLockCheck()
     If $lockname <> "" And $lockname <> GUICtrlRead($btnuser) Then MsgBox(0,"Ooops", "You have locked a patient at the same time as " & $lockname)
    EndIf
EndIf
EndIf
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunLockPatient($type)
Select
Case $type = "Lock"

$query = "Update "& $tablename & " SET Lock = '" & GUICtrlRead($btnuser) & "' Where ID = " & GUICtrlRead($lblID) & ";"

Case $type = "UnLock"

$query = "Update "& $tablename & " SET Lock = '' Where ID = " & GUICtrlRead($lblID) & ";"

EndSelect

Local $title,$adoCon,$dbname,$adoRs, $_output
$adoCon = ObjCreate("ADODB.Connection")
$dbname = @ScriptDir & "\" & "Patient Database.mdb"
$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.open($query, $adoCon)
$adoCon.Close

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunLockCheck()

$query = "SELECT * FROM "& $tablename & " WHERE ID=" & GUICtrlRead($lblID) & ";"
Local $title,$adoCon,$dbname,$adoRs, $_output
$adoCon = ObjCreate("ADODB.Connection")
$dbname = @ScriptDir & "\" & "Patient Database.mdb"
$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.open($query, $adoCon)
$lockname = $adoRs.fields("lock").value
$adoCon.Close
Return $lockname
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunAdd_Update()
$data = FunExtract()
$error = FunCheck($data)
If $error = "Passed" Then
If GUICtrlRead($btnaddupdate) = "Add" Then
    FunSQL("Add", $data)
    FunAudit("Added Patient")
EndIf
If GUICtrlRead($btnaddupdate) = "Edit" Then
    FunSQL("Update", $data)
    FunAudit("Edited Patient")
EndIf
FunPtClose()
FunLockPatient("UnLock")
Else
MsgBox(0,"Error", "Please fill in " & $error)
EndIf

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunCheck($stringcheck)

If GUICtrlRead($iptlast) = "" Then Return " the Last Name field"
If GUICtrlRead($iptfirst) = "" Then Return " the First Name field"
$i = 1
$j = 0
While $i < UBound($chkbox1)
If GUICtrlRead($chkbox1[$i]) = "1" Then
$j = $j + 1
EndIf
$i = $i + 1
WEnd
If $j < 1 Then Return "a Modality"
Return "Passed"

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunDelete_Update()
$msgconfirmation = MsgBox(4,"Delete Confirmation", "Are you SURE you want to delete this patient? This action cannot be undone!")
If $msgconfirmation = 6 Then
If GUICtrlRead($btnaddupdate) = "Edit" Then
$data = FunExtract()
FunSQL("Delete", $data)
FunPtClose()
FunAudit("Deleted Patient")
FunLockPatient("UnLock")
Else
MsgBox(0,"No action taken", "Nothing to Delete")
Endif
EndIf

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunAudit($action)

$passingstring = FunExtract() & "|" & $action & "|" & GUICtrlRead($btnuser) & "|" & @HOUR & ":" & @MIN & ":" & @SEC & "|" & @ComputerName & @CRLF
$file = FileOpen(@ScriptDir & "\" & @MON & "_" & @MDAY & "_audit.txt", 1)
If $file = -1 Then
MsgBox(0, "Error", "Unable to log audit, please contact Ben.")
Exit
EndIf
FileWrite($file, $passingstring)
FileClose($file)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunChangeUser()

Global $guiusername = GUICreate("Change Username",200,100,@DesktopWidth/2 - 100, @DesktopHeight/2 - 50 , BitOR($WS_POPUP, $WS_THICKFRAME), $WS_EX_MDICHILD, $mainwindow)
GUISetState(@SW_SHOW,$guiusername)
Global $iptnewuser = GUICtrlCreateInput(Guictrlread($btnuser), 20,20, 160)
$btnchildusername = GUICtrlCreateButton(" Save ", 70, 60)
GUICtrlSetOnEvent($btnchildusername,"FunUpdateUser")

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunUpdateUser()

GUICtrlSetData($btnuser,GUICtrlRead($iptnewuser))
GUIDelete($guiusername)

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunDemote()

$i = UBound($dropdown1order) - 1
While $i > 0
If Guictrlread($cmbstatus1) = $dropdown1order[$i] Then
If $i > 1 Then GUICtrlSetData($cmbstatus1, $dropdown1order[$i-1])
ExitLoop
EndIf

$i = $i - 1
WEnd

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunPromote()

$i = 1
$j = 1
While $i < UBound($dropdown1order)
If Guictrlread($cmbstatus1) <> $dropdown1order[$i] Then
$j = $j + 1
EndIf
$i = $i + 1
WEnd

If $j = UBound($dropdown1order) Then
GUICtrlSetData($cmbstatus1, $dropdown1order[$j-1])
EndIf

$i = 1
While $i < UBound($dropdown1order)
If Guictrlread($cmbstatus1) = $dropdown1order[$i] Then
If $i < UBound($dropdown1order) - 1 Then GUICtrlSetData($cmbstatus1, $dropdown1order[$i+1])
ExitLoop
EndIf

$i = $i + 1
WEnd
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunCreateListView()


EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunPtClose()

;zzz If GUICtrlRead($lblID) <> "" Then FunLock(GUICtrlRead($lblID), 0)
GUICtrlSetState($btnnew,$GUI_ENABLE)
GUICtrlSetState($btnrefresh,$GUI_ENABLE)
GUICtrlSetState($btnfilter,$GUI_ENABLE)
GUICtrlSetState($btnuser,$GUI_ENABLE)
GUICtrlSetState($mainlist,$GUI_ENABLE)
;zzz GUICtrlSetState($mainlist,$GUI_ENABLE)
GUISetState(@SW_HIDE,$childGui2)
FunLockPatient("UnLock")
FunAudit("Closed Patient")
FunRead()
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunNew()

GUICtrlSetData( $btnaddupdate, "Add")
GUICtrlSetData($lblID,Random(-99999,99999,1))
;Set combo1 to default
If GUICtrlGetState($cmbstatus1) > 0 Then
GUICtrlSetData($cmbstatus1, "")
GUICtrlSetData($cmbstatus1,$varcombo1,$varcombo1default)
EndIf
;Set combo2 to default
If GUICtrlGetState($cmbstatus2) > 0 Then
GUICtrlSetData($cmbstatus2, "")
GUICtrlSetData($cmbstatus2,$varcombo2,$varcombo2default)
EndIf
;Set radio1 to default
$i = 1
While $i < 10
If GUICtrlGetState($chkbox1[$i]) > 0 Then GUICtrlSetState($chkbox1[$i],$GUI_UNCHECKED)
$i = $i + 1
WEnd

;Set check boxes to default
$i = 1
While $i < UBound($chkbox1)
GUICtrlSetState($chkbox1[$i] ,$GUI_UNCHECKED)
$i = $i + 1
WEnd
;Set checkbox1 to default
GUICtrlSetData($btnaddupdate,"Add")
GUICtrlSetState($btnnew,$GUI_DISABLE)
GUICtrlSetState($btnrefresh,$GUI_DISABLE)
GUICtrlSetState($btnfilter,$GUI_DISABLE)
GUICtrlSetState($btnuser,$GUI_DISABLE)
GUICtrlSetData($iptlast,"")
GUICtrlSetData($iptfirst,"")
GUICtrlSetData($iptnotes,"")
GUICtrlSetState($radio1[1], $GUI_CHECKED)
GUISetState(@SW_SHOW, $childGui2)

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunChildClose()

GUISetState(@SW_HIDE, $childGui)
$i = 1
While $i < UBound($combocheckbox)
If $combocheckbox[$i] <> "" Then
IniWrite(@scriptdir & "\config\" & @username & ".ini", "DEFAULTS","Check1" & $i, GUICtrlRead($combocheckbox[$i]))
EndIf
$i = $i + 1
WEnd

$i = 1
While $i < UBound($combocheckbox2)
If $combocheckbox2[$i] <> "" Then
IniWrite(@scriptdir & "\config\" & @username & ".ini", "DEFAULTS","Check2" & $i, GUICtrlRead($combocheckbox2[$i]))
EndIf
$i = $i + 1
WEnd

GUISetState(@SW_HIDE, $childGui)
GUISwitch($mainwindow)
FunRead()
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunFilters()

GUISetState(@SW_SHOW, $childGui)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunClose()

Exit

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunPopulateFilter()
$combocheckboxz = StringSplit($varcheckbox1,"|")
$combocheckbox2z = StringSplit($varcombo1,"|")
;Check Box 1
$i = 1
While $i < UBound($combocheckboxz)
If $combocheckboxz[$i] <> "" Then
$combocheckbox[$i]= GUICtrlCreatecheckbox($combocheckboxz[$i], 25, 25 * $i)
EndIf
$i = $i + 1
WEnd

;Check Box 2
$i = 1
While $i < UBound($combocheckbox2z)
If $combocheckbox2z[$i] <> "" Then
$combocheckbox2[$i]= GUICtrlCreatecheckbox($combocheckbox2z[$i], 155, 25 * $i)
EndIf
$i = $i + 1
WEnd
$i = 1
While $i < UBound($combocheckbox)
If $combocheckbox[$i] <> "" Then
If IniRead(@scriptdir & "\config\" & @username & ".ini","DEFAULTS", "Check1" & $i, "1") = 1 Then GUICtrlSetState($combocheckbox[$i],$GUI_CHECKED)
EndIf
$i = $i + 1
WEnd

$i = 1
While $i < UBound($combocheckbox2)
If $combocheckbox2[$i] <> "" Then
If IniRead(@scriptdir & "\config\" & @username & ".ini","DEFAULTS", "Check2" & $i, "1") = 1 Then GUICtrlSetState($combocheckbox2[$i],$GUI_CHECKED)
EndIf
$i = $i + 1
WEnd
GUISetState(@SW_HIDE, $childGui)
GUISwitch($mainwindow)
FunRead()
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunPopulatePatient()
;Check Box 1
If IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_1", "BLANK") <> "BLANK" Then
$fieldstring = $fieldstring & "Check1|"
$i = 1
While $i < 10

If IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_" & $i, "BLANK") <> "BLANK" Then
    If $i = 1 Then
     $chkbox1[$i]= GUICtrlCreatecheckbox(IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_" & $i, "BLANK"), 20, 275,IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_" & $i & "WIDTH", "100"))
     $varcheckbox1 = GUICtrlRead($chkbox1[1],1)
    Else
     $pos = ControlGetPos("Add/Edit Patient","",$chkbox1[$i-1])
     $chkbox1[$i]= GUICtrlCreateCheckbox(IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_" & $i, "BLANK"), $pos[0] +$pos[2], 275,IniRead("Patient.ini", "CHECKBOX1", "CHECKBOX1_" & $i & "WIDTH", "100"))
     $varcheckbox1 = $varcheckbox1 & "|" & GUICtrlRead($chkbox1[$i],1)
    EndIf
EndIf
$i = $i + 1
WEnd
EndIf
;Drop down 1
If IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_LABEL ", "BLANK") <> "BLANK" Then
$fieldstring = $fieldstring & "Combo1|"
GUICtrlCreateLabel(IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_LABEL ", "BLANK"), 10, 120)
$cmbstatus1 = GUICtrlCreateCombo("", 20, 145,200)
$varcombo1 = IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_1", "BLANK")
$dropdown1order = StringSplit(IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_ORDER", "BLANK"),"|")
$i = 1
While $i < 10
$i = $i + 1
If IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_" & $i, "BLANK") <> "BLANK" Then
    $varcombo1 = $varcombo1 & "|" & IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_" & $i, "BLANK")
Else
    ExitLoop
EndIf

WEnd
$i = 1
$varcombo1default = IniRead("Patient.ini", "DROPDOWN1", "DROPDOWN1_DEFAULT", "BLANK")
GUICtrlSetData(-1, $varcombo1,$varcombo1default)
EndIf

;Drop down 2
If IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_LABEL ", "BLANK") <> "BLANK" Then
$fieldstring = $fieldstring & "Combo2|"
GUICtrlCreateLabel(IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_LABEL ", "BLANK"), 10, 175)
$cmbstatus2 = GUICtrlCreateCombo("", 20, 200,200)
$varcombo2 = IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_1", "BLANK")
$i = 1
While $i < 10
$i = $i + 1
If IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_" & $i, "BLANK") <> "BLANK" Then
    $varcombo2 = $varcombo2 & "|" & IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_" & $i, "BLANK")
Else
    ExitLoop
EndIf

WEnd
$i = 1
$varcombo2default = IniRead("Patient.ini", "DROPDOWN2", "DROPDOWN2_DEFAULT", "BLANK")
GUICtrlSetData(-1, $varcombo2,$varcombo2default)
EndIf
;Radio 1
If IniRead("Patient.ini", "RADIO1", "RADIO1_1", "BLANK") <> "BLANK" Then
GUIStartGroup()
$fieldstring = $fieldstring & "Radio1|"
$i = 1
While $i < 10

If IniRead("Patient.ini", "RADIO1", "RADIO1_" & $i, "BLANK") <> "BLANK" Then
    If $i <> 1 Then
     $pos = ControlGetPos("Add/Edit Patient","",$radio1[$i-1])
     $radio1[$i] = GUICtrlCreateRadio(IniRead("Patient.ini", "RADIO1", "RADIO1_" & $i, "BLANK"), $pos[0] +$pos[2], 225,IniRead("Patient.ini", "RADIO1", "RADIO1_"& $i &"WIDTH ", "100"))
    Else
     $radio1[$i] = GUICtrlCreateRadio(IniRead("Patient.ini", "RADIO1", "RADIO1_" & $i, "BLANK"), 20, 225,IniRead("Patient.ini", "RADIO1", "RADIO1_"& $i &"WIDTH ", "100"))
    EndIf
Else
    ExitLoop
EndIf
$i = $i+1
WEnd
GUICtrlSetState($radio1[1], $GUI_CHECKED)
EndIf

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunWaitTimeCalc()

GUISetState(@SW_HIDE, $childGui3)
Local $TheQuery2[200]

$query = "SELECT * FROM "& $tablename & " WHERE Combo1 = 'Finished' AND Check1 = '~" & GUICtrlRead($childcmbmodality) & "' AND RADIO1 = '" & GUICtrlRead($childcmbstatus) & "';"

Local $title,$adoCon,$dbname,$adoRs, $_output
$adoCon = ObjCreate("ADODB.Connection")
$dbname = @ScriptDir & "\" & "Patient Database.mdb"
$adoCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.open($query, $adoCon)

$i = 1
While $i < 99
    if $adoRs.RecordCount then
     If not ($adoRs.EOF) Then
     $TheQuery2[$i] = $adoRs.Fields("TotalTime").Value & "|" & $adoRs.Fields("CurrentStatusTime").Value & "|" & $adoRs.Fields("Combo1").Value
    
     $adoRs.MoveNext
     Else
     ExitLoop
     Endif
    EndIf
    $i = $i + 1
WEnd
_ArrayDisplay($TheQuery2)
$adoCon.Close
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunWait()

GUISetState(@SW_SHOW, $childGui3)

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunVersion()
MsgBox(0,"Whats New", "Added in 1.2" & @CRLF & _
"Add help file" & @CRLF & _
"Make pending ONLY work with waiting for front desk" & @CRLF & _
"Add tilde infront of ID on audit trail" & @CRLF & _
"Fix pending button on filters" & @CRLF & _
"Add Delete confirmation" & @CRLF & _
"Fix Patient window locks" & @CRLF & _
"Add File<Close menu option" & @CRLF & _
"Fixed problem with adding a new patint from drop down" & @CRLF & _
"Allow window to move or be closed if 'Edit' window is open" & @CRLF & _
"Make columns and sort stay for refresh" & @CRLF & _
"Add a date sensitive querey to SQL string" & @CRLF & _
"Increase name field length")
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunFront()

MsgBox(0,"Front Desk Operating Instructions", "Open the application by clicking Patient tracker icon on your desktop." & @CRLF & _
"Check your filters to set it according to your job requirement by clicking on magnifying glass and clicking the appropriate boxes." & @CRLF & _
"Transfer all the patients on sign in sheet to Patient tracker." & @CRLF & _
"To add a patient left click on + sign and input last and first name, modality and add the patient. Use pending if you don’t know the modality." & @CRLF & _
"Process patients according to the status time on patient tracker." & @CRLF & _
"Lock the patient by double clicking on the patient name as soon as you start working on the patient. It will open the window where you can change patient status. Leave the window open till you are done with the patient." & @CRLF & _
"Promote to the next status as soon as patient is ready." & @CRLF & _
"Transfer patient to problem status if there is issues with processing the patient. Please add notes, your initials and time in free text notes area.")


EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunReg()

MsgBox(0,"Registration Operating Instructions", "Open the application by clicking Patient tracker icon on your desktop." & @CRLF & _
"Check your filters to set it according to your job requirement by clicking on magnifying glass and clicking the appropriate boxes." & @CRLF & _
"After picking the patient paperwork make sure to lock the patient by double clicking on the patient name. It will open the window where you can change patient status. Leave the window open till you are done with the patient." & @CRLF & _
"Promote to the next status as soon as patient is ready." & @CRLF & _
"Transfer patient to problem status if there is issue with processing the patient. Please add notes, your initials and time in free text notes area.")
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunTech()

MsgBox(0,"Tech Operating Instructions", "Open the application by clicking Patient tracker icon on your desktop." & @CRLF & _
"Check your filters to set it according to your job requirement by clicking on magnifying glass and clicking the appropriate boxes." & @CRLF & _
"X-Ray, CT and MRI please lock the patients when you have them in scan rooms by double clicking on the patient name. It will open the window where you can change patient status. Leave the window open till you are done with the patient." & @CRLF & _
"Promote to the next status as soon as patient is done." & @CRLF & _
"For multi modality patients simply take off check mark from your modality and leave the status same till patient is done from all the exams for the day.")
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
Local $iHeight, $iWidth
$iWidth = BitAND($lParam, 0xFFFF) ; _WinAPI_LoWord
$iHeight = BitShift($lParam, 16) ; _WinAPI_HiWord
_WinAPI_MoveWindow($mainlist, 10, 90, $iWidth - 20, $iHeight - 200)
Return $GUI_RUNDEFMSG

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam

Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
$hWndListView = $mainlist
If Not IsHWnd($mainlist) Then $hWndListView = GUICtrlGetHandle($mainlist)

$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")

Local $tStruct = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;int Item", $lParam)
If @error Then Return
Switch DllStructGetData($tStruct, "Code")
     Case $NM_DBLCLK
         Local $iIndex = DllStructGetData($tStruct, "Item")
         FunEdit()
Case $LVN_COLUMNCLICK ; A column was clicked
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
_GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
sleep(500)
EndSwitch
;Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG

EndFunc ;==>On_WM_NOTIFY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunCreateAudit()
$varID = GUICtrlRead($lblID)
$file = FileOpen(@ScriptDir & "\" & @MON & "_" & @MDAY & "_audit.txt", 0)
If $file = -1 Then
MsgBox(0, "Error", "Unable to retrieve log, please contact Ben.")
Exit
EndIf
Dim $auditarray[1000]
Dim $auditresult[50]
$i = 1
$j = 1
While 1
$line = FileReadLine($file,$i)
If @error = -1 Then ExitLoop
$currentline = StringSplit($line,"|")
If $currentline[1] = $varID Then
$auditresult[$j] = $line
$j = $j + 1
EndIf

$i = $i + 1
WEnd
FileClose($file)
$i = 1
While $auditresult[$i] <> ""
$encryptbreak = StringSplit($auditresult[$i],"|")
$encryptbreak[2] = _StringEncrypt(0,$encryptbreak[2],"RandoPassword321")
$encryptbreak[3] = _StringEncrypt(0,$encryptbreak[3],"RandoPassword321")

$j = 1
While $j < UBound($encryptbreak)
$encryptfix = $encryptbreak[$j]
$j = $j + 1
WEnd
$auditresult[$i] = $encryptfix
$i = $i + 1
WEnd

_ArrayDisplay($auditresult)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunTimeDeltaTotal($time1)
If $time1[6] = "Finished" Then
$timesplit = StringSplit($time1[4],":")
$timesplit2 = StringSplit($time1[5],":")

$hourdelta = $timesplit2[1] - $timesplit[1]
If $timesplit2[2] > $timesplit[2] Then
$mindelta = $timesplit2[2] - $timesplit[2]
Else
$mindelta = (60 - $timesplit[2]) + $timesplit2[2]
$hourdelta = $hourdelta - 1
EndIf

Return ( $hourdelta * 60 ) + $mindelta
Else
$timesplit = StringSplit($time1[4],":")
$hourdelta = @HOUR - $timesplit[1]
If @MIN > $timesplit[2] Then
$mindelta = @MIN - $timesplit[2]
Else
$mindelta = (60 - $timesplit[2]) + @MIN
$hourdelta = $hourdelta - 1
EndIf
Return ( $hourdelta * 60 ) + $mindelta
EndIf

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunTimeDeltaCurrent($time1)
If $time1[6] = "Finished" Then
Return "~"
Else
$timesplit = StringSplit($time1[5],":")
$hourdelta = @HOUR - $timesplit[1]
If @MIN > $timesplit[2] Then
$mindelta = @MIN - $timesplit[2]
Else
$mindelta = (60 - $timesplit[2]) + @MIN
$hourdelta = $hourdelta - 1
EndIf
Return ( $hourdelta * 60 ) + $mindelta
EndIf

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunSetFilters()

If FileExists(@scriptdir & "\config\" & @username & ".ini") = 0 Then

FileCopy ( @scriptdir & "\config\config.ini", @scriptdir & "\config\" & @username & ".ini",1)
EndIf
$i = 1
While

If IniRead(@scriptdir & "\config\" & @username & ".ini", "Defaults","CT",0) = 1 Then GUICtrlSetState($childchkct,$GUI_CHECKED)
WEnd
EndFunc
Edited by boogieoompa
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...