Pharmacy Brand/Generic Hotsring Display for Drugs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Pharmacy Brand/Generic Hotsring Display for Drugs

Post by The_One_True_Rick » 06 Jun 2023, 12:23

This recognizes a list of common brand and generic drugs names while you are typing them and offers suggestions for the drug you are typing. You can press enter if the list is narrowed down to 1 to send that drug or just pick it from the list. The list will display beneath the line you are typing and narrow itself down while you type. Brand names will have the generic in parenthesis after the brand name. List disappears as soon as you type more than 6 letters or as soon as is realizes you are typing a word that is not a drug name from the list. Works well for the most part but I just got it working so any help or suggestions is appreciated. The cursor changes to hand while you are over the list but blinks a lot between that and the i-bar at least for me because it is also somehow picking up the edit box from my gui that is underneath the list. If anyone knows how to make the list appear uniform by making all edit boxes the same size as the longest edit box that would also look better. You'll have to change or remove the context sensitivity parts on your end to get it working because right now it only works in the medications edit box on my intake from gui. Sending the drug name with the enter button also feels a little slow right now but I had to slow it down to get it working, would appreciate it if anyone knows a better way.

Code: Select all

OnMessage(0x0200, "Mouse_Move")
OnMessage(0x0201, "WM_LBUTTONDOWN")

Medication_InputHook := InputHook("V", "{Space}{Enter}")
Medication_InputHook.OnEnd := Func("InputHook_End")
Medication_InputHook.OnChar := Func("InputHook_Char")
Medication_InputHook.NotifyNonText := true
Medication_InputHook.KeyOpt("{Backspace}", "N")
Medication_InputHook.OnKeyDown := Func("Backspace_Func")
Medication_InputHook.Start()

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/Hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
Prednisone
Tacrolimus (Prograf)
Cyclosporine (Neoral)
Mycophenolate Mofetil (CellCept)
Imuran (Azathioprine)
Rapamune (Rapamycin, Sirolimus)
Rosiglitazone (Avandia)
Pioglitazone (Actos)
Acarbose (Precose)
Miglitol (Glyset)
Colesevelam (Welchol)
Bromocriptine (Cycloset)
Nateglinide (Starlix)
Repaglinide (Prandin)
Glimepiride (Amaryl)
Glimepiride/Pioglitazone (Duetact)
Gliclazide
Glipizide
Glipizide ER (Glipizide XL, Glucotrol XL)
Glipizide/Metformin (Metaglip)
Glyburide (Micronase, Glynase, Diabeta)
Glyburide/Metformin (Glucovance)
Metformin (Axpinet, Diagemet, Glucient, Glucophage, Metabet)
Bexaglifloxin (Brenzavvy)
Canagliflozin (Invokana)
Dapagliflozin (Farxiga)
Empagliflozin (Jardiance)
Ertugliflozin (Steglatro)
Dulaglutide (Trulicity)
Exenatide (Byetta)
Exenatide ER (Bydureon)
Liraglutide (Victoza)
Lixisenatide (Adlyxin)
Semaglutide (Ozempic)
Alogliptin (Nesina)
Linagliptin (Tradjenta)
Saxagliptin (Onglyza)
Sitagliptin (Januvia)
Teriflunomide (Aubagio)
Dimethyl Fumarate (Tecfidera)
Diroximel Fumarate (Vumerity)
Monomethyl Fumarate (Bafiertam)
Fingolimod (Gilenya)
Siponimod (Mayzent)
Ozanimod (Zeposia)
Ponesimod (Ponvory)
Amiodarone (Cordarone, Pacerone)
Flecainide (Tambocor)
Procainamide (Procan, Procanbid)
Propafenone (Rythmol)
Quinidine
Tocainide (Tonocarid)
Lamotrigine (Lamictal)
Carbamazepine (Tegretol, Curatil)
Valproate (Dyzantil, Epilim, Episenta, Epival)
Levetiracetam (Keppra, Desitrend)
Topiramate (Topamax)
Brivaracetam
)

Loop, Parse, Drug_List, `n
	{
	RegExMatch(A_LoopField, "iO)(\w+(?:(\s|\/)\w+)?)", Generic_Pat)
	Drug_Generic_Tag := Generic_Pat.Value(1)
	if (A_Index = 1)
		Drug_List_2.= Drug_Generic_Tag
	else
		Drug_List_2.= "`n" Drug_Generic_Tag
	RegExMatch(A_LoopField, "iO)(?:\()(.*)(?:\))", Brand_List_Pat)
	Current_Drug_Brand_List := Brand_List_Pat.Value(1)
	if (Current_Drug_Brand_List != "")
		{
		Brand_Array := StrSplit(Current_Drug_Brand_List , ", ")
		for each, Brand in Brand_Array
			{
			Drug_Brand_Tag := RegExReplace(A_LoopField, "(\w*(?:.\w*)?)\s\((.*)\)", Brand " ($1)")
			Drug_List_2.= "`n" Drug_Brand_Tag
			}
		}
	}

Sort, Drug_List_2, U
Drugs := StrSplit(Drug_List_2, "`n")

Generate_Hotstrings:

#if (Active_Control("Consult_GUI") = "Edit7")
Hotkey, If, (Active_Control("Consult_GUI") = "Edit7")

Array_Of_Active_Hotstrings := []
List_Of_Active_Hotstrings := ""

Loop, 4 ; creates a hotstring for each drug on list, each drug has 4 hotsrings linked to the first 3-6 letters of the drug on the list
	{
	Abbreviation_Length := 3+(A_Index-1)
	For All, Drug in Drugs
		{
		NewStr := SubStr(Drug, 1, Abbreviation_Length)
		Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		Array_Of_Active_Hotstrings.Push(NewStr)
		}
	}

Loop, % Array_Of_Active_Hotstrings.MaxIndex()
	List_Of_Active_Hotstrings.= Array_Of_Active_Hotstrings[A_Index] "`n"
return

Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0
Gui, Drugs:Color, 0x254C5A, 0x254C5A
Gui, Drugs:font, s13 bold

Loop, Parse, Drug_List_2, `n
	{
	Drug_Name := RegExReplace(A_ThisHotkey, "(:C1B0X\*:)", "")
	if (Drug_Name ~= "i)" SubStr(A_LoopField, 1, Length))
		Gui, Drugs:Add, Edit, cWhite vE%A_Index%, %A_LoopField%
	}

CoordMode, Caret , Screen
Caret_Y := A_CaretY + 30
Gui, Drugs:Show, x%A_CaretX% y%Caret_Y% NA, Drugs
WinGet, Drugs_GUI_ID , ID, Drugs

Hotkey, If,
#if
return

InputHook_End(ih){
	;Reason := ih.EndReason
	KeyName := ih.EndKey
	Current_String := ih.Input
	Backspace_Number := StrLen(Current_String) + 1
	if (KeyName = "Enter") && if WinExist("Drugs")
		{
		WinGetText, GUI_Text, Drugs
		Sleep, 20
		GUI_Text := StrReplace(GUI_Text, "`r`n" , "")
		SendEvent, {Backspace %Backspace_Number%}
		Sleep, 10
		SendInput, %GUI_Text%
		Gui, Drugs: Destroy
		}
	else if (KeyName = "Space")
		Gui, Drugs: Destroy
	ih.Start()
}

InputHook_Char(ih, char){
	Current_String := ih.Input
	if Current_String not in List_Of_Active_Hotstrings
		Gui, Drugs: Destroy
}

Backspace_Func(){
	Gui, Drugs: Destroy
}

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}

#IfWinExist, Drugs
~LButton::
MouseGetPos, , , MouseWin, ctrl
if (MouseWin != Drugs_GUI_ID) || if (ctrl ~= "Edit\d+") = false
	Gui, Drugs: Destroy
else
	{
	}
return
#IfWinExist,

WM_LBUTTONDOWN(){
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
}

Mouse_Move(wParam, lParam, msg, hwnd){
	static
	hCurs := DllCall("LoadCursor", "Int", 0, "Int", 32649, "UInt")

	if (msg = 0x0200)
		{
		MouseGetPos,,,,ctrl
		if (ctrl ~= "Edit\d+") && if WinExist("Drugs")
			DllCall("SetCursor", "UInt", hCurs)
		return
		}
}

Return to “Ask for Help (v1)”