演習 5 : Lookup ルーチン、バージョン 1
-
スタジオを開始し、新規ルーチンを作成します。このルーチンも lookup1.mac として、SAMPLES ネームスペースで利用可能できます。
-
以下のコードを入力します。
mylookup ; display an ordered list of matches ; user can enter a valid date of birth main ; main section ; start looping for { do getsubmit() ; let user submit a string for lookup quit:(submit = "") } quit getsubmit() [submit] ; ask user what to search for, and take appropriate action { read !, "Lookup: ", submit quit:(submit = "") ; user entered nothing ; figure out what user entered if (submit = "?") { ; display help do help() quit } if $$validDOB^mydatent( submit ) { ; use validDOB^datent to verify the DOB write "...finding birthday" do dob() quit } } help() ; display different types of lookups { write !, "You can enter:", !?10, "* date of birth", !! } dob() [submit] ; perform dob lookup ; no partial matches { set intdob = $$validDOB^mydatent( submit ) ; convert dob ; is the date of birth in the index? if '$data( ^PersonI("DOB", intdob) ) { ; determine if there are any matches write "...no matches" quit } set loopid = "" ; loop through IDs, and number them for count = 1 : 1 { set loopid = $order( ^PersonI("DOB", intdob, loopid) ) quit:(loopid = "") write !, count, ") " do display( loopid ) } } display(id) ; given an ID, get data and write it { set rec = ^PersonD( id ) set name = $piece(rec, "^", 1) set phone = $piece(rec, "^", 2) set intdob = $piece(rec, "^", 3) write name, ?20, phone, ?35, $zdate(intdob, 2) }
-
[ファイル]→[保存] をクリックします。
-
ファイル名に mylookup を指定し、[ファイルの種類] フィールドで “Macro Routine” を指定します。[名前を付けて保存] をクリックします。
-
ターミナルを開始し、SAMPLES ネームスペースで do ^mylookup と入力してルーチンを実行します。