Retrieving values of multidimensional array using menu

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
donsonmd
Posts: 55
Joined: 19 Feb 2017, 05:57

Retrieving values of multidimensional array using menu

Post by donsonmd » 14 Sep 2021, 21:54

Hello, I am trying to retrieve array values using menu. The array has a {{Afluria vaccine code: Afluria admin code}, {Engerix vaccine code: Engerix admin code}...}} type of structure. It's about vaccine administration. The examples I am posting is only some part.

In the menu, you need to make 3 selections:

1. Vaccine types: Afluria or Engerix.
2. Vaccine codes (v): pediatric (P), Adult non Medicare (A), and Medicare (M). Combinations are possible as some have the same codes such as PAM or AM.
3. Comments on the number of vaccination (c): some vaccines are supposed to be given more than one time as a series. c_B (booster), c_1 (1st shot), ...
4. Once the above three are selected, vaccine administration codes (a) will be automatically determined.

Now, you can get 3 values for each vaccine.

1. For Afluria
Vaccines.Afluria.v_PAM (vaccine codes for P, A and M are all the same)
Vaccines.Afluria.a_P
Vaccines.Afluria.n (single shot only needed)

2. For Engerix
Vaccines.Engerix.v_AM (vaccine codes for A and M are all the same)
Vaccines.Engerix.a_M
Vaccines.Engerix.n_B (booster shot)

I have come up with below so far:

Code: Select all

Afluria := {}, Engerix := {}, Vaccines := {}

Afluria := {v_PAM: "90686: Vaccine, Afluria IIV4, 0.5 mL, IM (≥3 yo)"
		, a_P: "90460: Admin, one vaccine, non-MC, (≤18 yo, w/ counseling)"
		, a_A: "90471: Admin, one vaccine, non-MC"
		, A_M: "G0008: Admin, influenza vaccine, MC"
		, n: "Afluria was administered today."}

EngerixB := {v_P: "90744: Vaccine, Engerix-B, 0.5 mL, IM (<20 yo)"
		, v_AM: "90746: Vaccine, Engerix-B, 1.0 mL, IM (≥20 yo)"
		, a_P: "90460: Admin, one vaccine, non-MC (≤18 yo, w/ counseling)"
		, a_A: "90471: Admin, one vaccine, non-MC"
		, a_M: "G0010: Admin, hepatitis B vaccine, MC"
		, n_B: "One booster vaccination of HBV was administered today."
		, n_1: "The first dose of HBV vaccine was administered today. Patient will be scheduled for the second one in a month."
		, n_2: "The second dose of HBV vaccine was administered today. Patient will be scheduled for the third one in five months."
		, n_3: "The third dose of HBV vaccine was administered today."}

Vaccines := {Afluria: Afluria, Engerix: Engerix}

VaccinationHandler()
{
Global Afluria := {}, Engerix := {}, Vaccines := {}
Global Vaccine_type, Vaccine_code, Admin_code

Menu, SubFlu, Add, Pediatric, FluHandler
Menu, SubFlu, Add, Adult (NonMC), FluHandler
Menu, SubFlu, Add, Medicare, FluHandler
Menu, Vaccination, Add, Influenza, :SubFlu
Menu, SubPed, Add, Booster Vac., HBVHandler
Menu, SubPed, Add, 1st Vac., HBVHandler
Menu, SubPed, Add, 2nd Vac., HBVHandler
Menu, SubPed, Add, 3rd Vac., HBVHandler
Menu, SubHBV, Add, Pediatric, :SubPed
Menu, SubAdu, Add, Booster Vac., HBVHandler
Menu, SubAdu, Add, 1st Vac., HBVHandler
Menu, SubAdu, Add, 2nd Vac., HBVHandler
Menu, SubAdu, Add, 3rd Vac., HBVHandler
Menu, SubHBV, Add, Adult (NonMC), :SubAdu
Menu, SubMC, Add, Booster Vac., HBVHandler
Menu, SubMC, Add, 1st Vac., HBVHandler
Menu, SubMC, Add, 2nd Vac., HBVHandler
Menu, SubMC, Add, 3rd Vac., HBVHandler
Menu, SubHBV, Add, Medicare, :SubMC
Menu, Vaccination, Add, Hepatitis B, :SubHBV

FluHandler:
Vaccine_type := "Afluria"
Vaccine_code := "v_PAM"
NumVac := "n"
If (A_ThisMenuItem = "Pediatric")
    Admin_code := "a_P"
Else If (A_ThisMenuItem = "Adult (NonMC)")
    Admin_code := "a_A"
Else If (A_ThisMenuItem = "Medicare")
    Admin_code := "a_M"
Return

HBVHandler:
Vaccine_type := "Engerix"
If (A_ThisMenu = "SubPedc")
(
    Vaccine_code := "v_P"
    Admin_code := "a_P"
)
Else If (A_ThisMenu = "Adult (NonMC)")
(
    Vaccine_code := "v_AM"
    Admin_code := "a_A"
)

Else If (A_ThisMenu = "Medicare")
(
    Vaccine_code := "v_AM"
    Admin_code := "a_M"
)

If (A_ThisMenuItem = "Booster Vac.")
    NumVac := "n_B"
Else If (A_ThisMenuItem = "1st Vac.")
    NumVac := "n_1"
Else If (A_ThisMenuItem = "2nd Vac.")
    NumVac := "n_2"
Else If (A_ThisMenuItem = "3rd Vac.")
    NumVac := "n_3"
Return


F12::
VaccinationHandler()
Sleep, 300
Printing()
Return

Printing()
{
; For Hepatitis B Vaccination
SendInput, % Vaccines.%Vaccine_type%.%Vaccine_code%
SendInput, % Vaccines.%Vaccine_type%.%Admin_code%
SendInput, % Vaccines.%Vaccine_type%.%NumVac%
}
So,

Code: Select all

SendInput, % Vaccines.Engerix.v_AM
works. But, why are these two below not working?

Code: Select all

SendInput, % Vaccines.%Vaccine_type%.%Vaccine_code%

Code: Select all

SendInput, % Vaccines.%Vaccine_type%[%Vaccine_code%]


How can a variable be used to refer to the array's keys? Please teach me. Thank you.
Last edited by donsonmd on 19 Sep 2021, 10:18, edited 5 times in total.
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Retrieving values of multidimensional array using menu

Post by Hellbent » 14 Sep 2021, 22:30

There are many ways to skin this cat.
Here are to examples (pseudo code)

Code: Select all

;structure

;method 1

;create 2 objects. 


;The first object contains all your key:values 
;Note that you can use strings with spaces as the keys.
;This means that the items in your menu can be the actual key names of the data to get.
AllItems := { "This is a key name with spaces" : "this is the value" }

;The second object holds your output

Output := { Vaccine_type : "" , Vaccine_code : "" }



;When you select an item from the menu
SomeMenuLabel:
	Output[ A_ThisMenu ] := AllItems[ A_ThisMenuItem ]  
	return



;=========================================


;Method 2 


;Create multiple objects for your inputs

Afluria := { "Use Menu Item Names Here" : "Value"  }

;etc 


;Create a output object
Output := { Vaccine_type : "" , Vaccine_code : "" }



;When you select an item from the menu
VaccineTypeLabel:
	Output.Vaccine_type := %A_ThisMenu%[ A_ThisMenuItem ]  
	return




donsonmd
Posts: 55
Joined: 19 Feb 2017, 05:57

Re: Retrieving values of multidimensional array using menu

Post by donsonmd » 19 Sep 2021, 01:31

Thank you @Hellbent for your ideas. I had to modify the original posting a little to have myself understood better. Could you answer my new question? Thank you.
User avatar
boiler
Posts: 16706
Joined: 21 Dec 2014, 02:44

Re: Retrieving values of multidimensional array using menu

Post by boiler » 19 Sep 2021, 01:39

donsonmd wrote: I had to modify the original posting a little to have myself understood better. Could you answer my new question?
Please don’t modify your posts after others have replied to them. Now we can’t see what it was that Hellbent originally replied to, and his post may not make sense when the original context is removed. Just post again with your clarifications.
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Retrieving values of multidimensional array using menu

Post by just me » 19 Sep 2021, 04:38

Code: Select all

Vaccines[Vaccine_type, Vaccine_code]
donsonmd
Posts: 55
Joined: 19 Feb 2017, 05:57

Re: Retrieving values of multidimensional array using menu

Post by donsonmd » 19 Sep 2021, 10:01

Oh, I see, @boiler. Sorry I didn't think that far. I'll make an addendum next time. Thanks for the advice.

And @just me,

Code: Select all

SendInput, % Vaccines[Afluria, a_P]
doesn't work. Am I missing something?
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Retrieving values of multidimensional array using menu

Post by Hellbent » 19 Sep 2021, 15:16

donsonmd wrote:
19 Sep 2021, 10:01

Code: Select all

SendInput, % Vaccines[Afluria, a_P]
doesn't work. Am I missing something?
You need to wrap literal strings ( the names of the keys you are using ) in quotes.

Code: Select all

Vaccines[Afluria]
;should be 
Vaccines["Afluria"] 
;if "Afluria" is the name of a obj.key


;what you have would work in a case like this.

var := "Afluria"
Vaccines[ var ]



Code: Select all

SendInput, % Vaccines["Afluria", "a_P" ]
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Retrieving values of multidimensional array using menu

Post by just me » 20 Sep 2021, 06:28

As far as I understand you want to use variables instead of hard-coded strings to access the array:

Code: Select all

Vaccine_type := "Afluria" ; assigned by the menu handler
Vaccine_code := "a_P"     ; assigned by the menu handler
...
Result := Vaccines[Vaccine_type, Vaccine_code]
Post Reply

Return to “Ask for Help (v1)”