Cadence Pt Preferences

Trying to scale this down a bit. any ideas?

//This script will read from a spreadsheet and schedule an existing patient with patient preferences for CAD001
////////////////////////////////////////////////////////////////
// Setting up the datasheets and tabs for the script
set myDB to (file:ResourcePath(“APPTesting.xlsx”), type:“excel”, writeable:“Yes”)
//set Patientdata to the records of mydb
//set Patientdata to the records of table (“IP”) of mydb
set Patientdata to the records of table (“AMB”) of mydb
//set Patientdata to the records of table (“ED”) of mydb

///////////////////////////////////////////////////////
//global status list
put 1 into seq
global patient
global curenv
global status

/////////////////////////////////////////////////////
//Place environment login script heredo
(Run “Login Environments/POC”)
(Run “Login Environments/TST”)
(Run “Login Environments/TST2”)
/////////////////////////////////////////////////////
//Login as scheduler
(Run “User Logins/Lmiley”)

Run “MISC/Environment ID”
put (“Wednesday”, “Thursday”, “Friday”) into Week

repeat with each patient of Patientdata by reference
if patient.admission equals “no template” or if patient.admission equals “scheduled”
next repeat
end if
log "we are on PT "&&the counter

if ImageFound (text:"Report Settings", searchrectangle: (566,158,1304,360), waitfor:3)
	typetext altkey, "c"
end if
Run "MISC/Chg location"
wait 1
if ImageFound (text:"Report Settings", searchrectangle: (734,100,1152,245), waitfor:7)
	typetext altkey, "c"
end if
if ImageFound(text:"Appts", searchrectangle: (69,14,1621,69), waitfor: 2) is false
	if ImageFound (text:"Report Settings", searchrectangle: (734,100,1152,245), waitfor:7)
		typetext altkey, "c"
	end if
else
	click ImageLocation(text:"Appts", searchrectangle: (69,14,1621,69), waitfor: 2)
	//Click "Appt"
end if

if ImageFound(text:"Patient Lookup", searchrectangle: (583,330,1258,441))
	Run "MISC/MRNSelect"
	typetext return, return
	if ImageFound(text:"Break-the-Glass", searchrectangle: (687,193,1235,331), waitfor:1)
		typetext "Scheduling", return, tab, tab, tab
		typetext "model", return
	end if
end if
//if there is an appointment will need to go to the next pt or validate information
if ImageFound(text:"Appt Desk", searchrectangle: (239,73,590,159), waitfor: 2)
	click ImageLocation(text:"Appt Desk", searchrectangle: (239,73,590,159))
end if
//checking for a previous schedule
put ReadText((244,600,1660,726)) into sched
log sched
if sched is not empty
	put "scheduled" into patient.admission
	Run "MISC/Close Tab"
	next repeat
	
	//Updating Patient Preferences
else if imagefound (text:"Appt Desk", searchrectangle: (239,73,590,159), waitfor: 3)
	click ImageLocation(text:"Appt Desk", searchrectangle: (239,73,590,159), waitfor: 3)
end if
click ImageLocation(text:"Patient Options", searchrectangle: (237,152,1212,215))
if ImageFound(text:"Scheduling Preferences", searchrectangle: (611,141,863,500)) is false
	click ImageLocation(text:"Patient Options", searchrectangle: (611,141,863,500))
end if
click ImageLocation(text:"Scheduling Preferences", searchrectangle: (611,141,863,500))
put ImageLocation(text:"Days of the week", searchrectangle: (229,138,528,457)) into dayloc
log dayloc
Click (item 1 of dayloc + 150,(item 2 of dayloc))
typetext "Wednesday", tab
typetext "Thursday", tab
typetext "Friday", tab
typetext altkey, "a"

Run "Cadence/Scheduling/Scheduling"
Run "Cadence/Scheduling/Search Sched"
Run "Cadence/Creating HAR Sched"
Run "Cadence/Visit Info"
Run "Cadence/Confirmation Script"


//Confirming the patient schedule- this will pull the information from an area and group it together and compare
if ImageFound(text:"Appointment Desk", searchrectangle: (223,119,512,192)) is false
	click ImageLocation(text:"Appt Desk", searchrectangle: (229,82,716,137))
end if
put ("Mon", "Tue", "Sat", "Sun") into Badday
Put ("Wed", "Thu", "Fri") into Goodday
put ReadText((244,600,1660,726)) into sched
log sched

if any item of badday is in sched
	put "Failed" into Patient.CAD001
	log "no go"
else 
	put "Passed" into patient.CAD001
	log "good"
end if

if sched is empty
	typetext altkey, "s"
	if ImageFound(text:"Date ", searchrectangle: (885,421,1035,525))
		typetext return
		put "no date" into patient.admission
		if patient.cad001 is empty
			put "failed" into patient.cad001
		end if
		Run "MISC/Close Tab"
		next repeat		
	end if
end if
put "scheduled" into patient.admission
Run "MISC/Close Tab"

end repeat

(* //Another Date Warning for unavailable day
if ImageFound(text:"Date ", searchrectangle: (891,418,1064,544),waitfor: 1)
typetext return
Put “no date” into patient.admission
Run “MISC/Close Tab”
next repeat
end if*)

(* //Provider error schedule- need more infor of where this error occurs
if ImageFound(text:“Provider Schedule Display”, searchrectangle: (836,265,1092,333),waitfor: 1)
typetext return
end if
)
(
//Beginning to search the schedule for an open appt
Click (text:“Name”, searchrectangle: (234,206,1416,231))

//trying to read text till blank
put (311,231,1625,251) into aptloc
put readtext (311,231,1625,251) into apt
log apt
repeat until apt is empty
	log apt
	put (aptloc+(0,23,0,23)) into aptloc--puts searchrectangle coordinates in new line for aptloc
	put readtext (aptloc) into apt--reads new searchrectangle 
	log apt
	log aptloc
end repeat
click center(aptloc)
typetext return
typetext altkey, "s"
typetext altkey, "a"*)

(*//run registration for scheduling
//if the post visit questionnaire appears
if imagefound (text:“Appt Infor”, searchrectangle: (234,80,903,139))
Click imagelocation (text:“Appt Infor”, searchrectangle: (234,80,903,139))
else
if imagefound (text:“Registration”, searchrectangle: (234,80,903,139))
Click imagelocation (text:“Registration”, searchrectangle: (234,80,903,139))
end if
end if
if ImageFound(text:“Visit Questionnaire”, searchrectangle: (469,185,722,272), waitfor: 10)
typetext “no”, tab, return
typetext altkey, “a”
//appt question warning for pt to be seen the next day
if ImageFound(text:“Appointment Questionaires Warning”, searchrectangle: (816,366,1094,404))
typetext return
end if
end if
//Finding the private encounter, selecting guarantor account and self pay
Run “Cadence/Visit Info”
Run “Cadence/Creating HAR Sched”
Run “Cadence/Confirmation Script”
put “scheduled” into patient.admission
Run “MISC/Close Tab”

end repeat*)

(* put [“one”, “twp”, “tree”] into A
put [“twp”, “one”, “tree”] into B
log A sorted alphabetic equals B sorted alphabetic *)

(* //add writing to the datasheet and go to next patient
if ImageFound(text:“Date Warnings”, searchrectangle: (801,440,1146,627))
typetext altkey, “g”
put “Date Warning” into patient.admission
Run “MISC/Close Tab”

end if*)

(* if ImageFound(text:“Provider”, searchrectangle: (842,360,1084,422),waitfor:4)
//put EveryImageLocation(text:“30283”, searchrectangle: (709,368,1213,700)) into provid
put patient.prov into provid
put EveryImageLocation(text:provid, searchrectangle: (709,368,1213,700)) into providloc
click item 1 of providloc
typetext altkey, “a”
end if*)

(*//Confirming the patient schedule- this will pull the information from an area and group it together and compare
click ImageLocation(text:“Preferences”, searchrectangle: (1382,141,1693,615))
put ImageLocation(text:“Days of the week”, searchrectangle: (229,138,528,457)) into dayloc
log dayloc
Click (item 1 of dayloc + 150,(item 2 of dayloc))
//need to group the days of the week and compare
put (“Wednesday”, “Thursday”, “Friday”) into Week
SetRemoteClipboard “”
Repeat at least once until day is empty
SetRemoteClipboard “”
typetext controlkey, “c”
put RemoteClipboard() into day
if day is “”
Exit repeat
end if
log day
insert RemoteClipboard() after weekval
typetext tabkey
end repeat

(* put [“one”, “twp”, “tree”] into A
put [“twp”, “one”, “tree”] into B
log A sorted alphabetic equals B sorted alphabetic *)

if week sorted alphabetic equals weekval sorted alphabetic
put “passed” into patient.comments
log “correct”
else
log “nogo”
put “Failed” into Patient.comments
end if
typetext tabkey

typetext “t”, tab, return*)

(* Click (text:“Department”, searchrectangle: (1351,204,1460,299))
put everyimagelocation (text:“Department”, searchrectangle: (802,187,890,241)) into deploc
click (item 1 of item 1 of deploc , (item 2 of item 1 of deploc + 18))
typetext patient.unit, tab*)

(*if week sorted alphabetic equals weekval sorted alphabetic
put “PT Pref Passed” into patient.comments
log “correct”
else
log “PT Pref Failed”
put “PT Pref Failed” into Patient.comments
end if *)

(* repeat until itsdone contains “100.000”
put apt (apt+(200,-10,285,0)) into apt
typetext “r”
log “spam the R key every 10 seconds for”&&packnumTST
log “Percent done”&&itsdone
log “packstatus”&&packstatus
wait 10
end repeat*)

//Select PT Preferences-There may not be a schedule to refer to but a recommended solution instead. this section will get through that part
(* //typetext altkey, “u”
set the SearchRectangle to (1363,607,1503,657)
if ImageFound(“PTpref”) is false
Click ImageLocation(text:“Use patient prefs”, searchrectangle: (1363,607,1503,657), waitfor: 3)
end if*)
//Check to see if the travel screening appears at this point. should not
(* if ImageFound(text:“Travel”, searchrectangle: (870,157,1048,202))
Run “Cadence/Travel Screen SCH”
end if*)

(*
if patient.admission equals “no template” or if patient.admission equals “date warning”
Run “MISC/Close Tab”
next repeat
end if

//Date Warning for unavailable day- may not need
if ImageFound(text:"Date ", searchrectangle: (885,421,1035,525), waitfor: 3)
typetext return
put “no date” into patient.admission
Run “MISC/Close Tab”
next repeat
end if

//if there was a template error this will go to the next patient. this has to go right after the scheduling search schedule script
if patient.admission equals “no template” or if patient.admission equals “date warning”
Run “MISC/Close Tab”
next repeat
end if

//HAR and Visit has been run during the search sched. need to validate the schedule before finishing
if ImageFound(text:“Confirmation”, searchrectangle: (62,167,270,269), waitfor: 3)
typetext altkey, “c”
end if*)

Your code is pretty good, but I am curious about what you are ultimately trying to accomplish. It seems that much of your code is dedicated to finding available slots. If you are testing the provider template, searching for available days vs. non-available days would be a requirement. If you are automating visit creation however, and if it is less important as to whether a particular day is on a provider’s template, use a EMP that has superoverbook security, and you can trim much of the code away. Alternately, I look for the first available green block, take it, and then read the scheduled date and time from Appointment Details and write it back to my Excel.

Let me know if either of these ideas works for you.
Dave