#include "DrewsExtras/DrewsAsteriskFunctions.conf"


[general]
static=yes
writeprotect=no
autofallthrough=yes
clearglobalvars=no
priorityjumping=no

[incoming]
exten => 481,1,NoOp(--------------FDMC Incoming Call----------------)
;-------------- MANUAL OVERRIDE CLOSING BELOW------------------------
;	same => n,GotoIfTime(12:00-17:00,,*,24,dec?fdmc_night,s,1)
;-------------- MANUAL OVERRIDE CLOSING ABOVE------------------------
	same => n,GotoIfTime(09:00-11:00,sat,*,*?fdmc_voice_menu,s,1)	;Open 9-11 on all Saturdays
	same => n,GotoIfTime(*,fri,*,*?fdmc_night,s,1)			;Closed ALL fridays
	same => n,Gosub(subTimeOfDay,start,1(fdmc_night,fdmc_voice_menu,07:30-18:30)) ; Open 7:30-6:30 all other days

[fdmc_users]
exten => *201,1,Dial(SIP/FDMC_09_0000_0716,,b(paging^addheader^1))
exten => 201,1,Macro(stdvoicemail,SIP/FDMC_09_0000_0716,20,201)               ; Operator 1
exten => *211,1,Dial(SIP/FDMC_09_0001_0716,,b(paging^addheader^1))
exten => 211,1,Macro(stdvoicemail,SIP/FDMC_09_0001_0716,20,211)               ; Registration 4
exten => *299,1,Dial(SIP/FDMC_09_0002_0716,,b(paging^addheader^1))
exten => 299,1,Macro(stdvoicemail,SIP/FDMC_09_0002_0716,20,299)               ; FNP Thornhill
exten => *301,1,Dial(SIP/FDMC_09_0004_0716,,b(paging^addheader^1))
exten => 301,1,Macro(stdvoicemail,SIP/FDMC_09_0004_0716,20,301)               ; Pt. Assist (MEDS)
exten => *302,1,Dial(SIP/FDMC_09_0005_0716,,b(paging^addheader^1))
exten => 302,1,Macro(stdvoicemail,SIP/FDMC_09_0005_0716,20,302)               ; Referrals
exten => *303,1,Dial(SIP/FDMC_09_0006_0716,,b(paging^addheader^1))
exten => 303,1,Macro(stdvoicemail,SIP/FDMC_09_0006_0716,20,303)               ; Registration 2
exten => *304,1,Dial(SIP/FDMC_09_0007_0716,,b(paging^addheader^1))
exten => 304,1,Macro(stdvoicemail,SIP/FDMC_09_0007_0716,20,304)               ;Registration 3
exten => *306,1,Dial(SIP/FDMC_09_0008_0716,,b(paging^addheader^1))
exten => 306,1,Macro(stdvoicemail,SIP/FDMC_09_0008_0716,20,306)               ;Registration 1
exten => *308,1,Dial(SIP/FDMC_09_0011_0716,,b(paging^addheader^1))
exten => 308,1,Macro(stdvoicemail,SIP/FDMC_09_0009_0716,20,308)               ;Insurance
exten => *309,1,Dial(SIP/FDMC_09_0011_0716,,b(paging^addheader^1))
exten => 309,1,Macro(stdvoicemail,SIP/FDMC_09_0010_0716,20,309)               ;Insurance
exten => *310,1,Dial(SIP/FDMC_09_0011_0716,,b(paging^addheader^1))
exten => 310,1,Macro(stdvoicemail,SIP/FDMC_09_0011_0716,20,310)               ;CPL Staff (LAB)
exten => *311,1,Dial(SIP/FDMC_09_0012_0716,,b(paging^addheader^1))
exten => 311,1,Macro(stdvoicemail,SIP/FDMC_09_0012_0716,20,311)               ;HR Coordinator
exten => *312,1,Dial(SIP/FDMC_09_0013_0716,,b(paging^addheader^1))
exten => 312,1,Macro(stdvoicemail,SIP/FDMC_09_0013_0716,20,312)               ;Accounting/Claims 2
exten => *313,1,Dial(SIP/FDMC_09_0014_0716,,b(paging^addheader^1))
exten => 313,1,Macro(stdvoicemail,SIP/FDMC_09_0014_0716,20,313)               ;Thornhill NS
exten => *315,1,Dial(SIP/FDMC_09_0015_0716,,b(paging^addheader^1))
exten => 315,1,Macro(stdvoicemail,SIP/FDMC_09_0015_0716,20,315)               ;FNP Calhoun
exten => *316,1,Dial(SIP/FDMC_09_0016_0716,,b(paging^addheader^1))
exten => 316,1,Macro(stdvoicemail,SIP/FDMC_09_0016_0716,20,316)               ;Administrator
exten => *317,1,Dial(SIP/FDMC_09_0017_0716,,b(paging^addheader^1))
exten => 317,1,Macro(stdvoicemail,SIP/FDMC_09_0017_0716,20,317)               ;Vanessa
exten => *318,1,Dial(SIP/FDMC_09_0018_0716,,b(paging^addheader^1))
exten => 318,1,Macro(stdvoicemail,SIP/FDMC_09_0018_0716,20,318)               ;Open
exten => *319,1,Dial(SIP/FDMC_09_0019_0716,,b(paging^addheader^1))
exten => 319,1,Macro(stdvoicemail,SIP/FDMC_09_0019_0716,20,319)               ;Earhart NS
exten => *320,1,Dial(SIP/FDMC_09_0020_0716,,b(paging^addheader^1))
exten => 320,1,Macro(stdvoicemail,SIP/FDMC_09_0020_0716,20,320)               ;Front Office Sup.
exten => *321,1,Dial(SIP/FDMC_09_0021_0716,,b(paging^addheader^1))
exten => 321,1,Macro(stdvoicemail,SIP/FDMC_09_0021_0716,20,321)               ;New Phone
exten => *322,1,Dial(SIP/FDMC_09_0022_0716,,b(paging^addheader^1))
exten => 322,1,Macro(stdvoicemail,SIP/FDMC_09_0022_0716,20,322)               ;Dr. Earhart
exten => *324,1,Dial(SIP/FDMC_09_0024_0716,,b(paging^addheader^1))
exten => 324,1,Macro(stdvoicemail,SIP/FDMC_09_0024_0716,20,324)               ;Webre NS
exten => *325,1,Dial(SIP/FDMC_09_0025_0716,,b(paging^addheader^1))
exten => 325,1,Macro(stdvoicemail,SIP/FDMC_09_0025_0716,20,325)               ;New Phone
exten => *326,1,Dial(SIP/FDMC_09_0026_0716,,b(paging^addheader^1))
exten => 326,1,Macro(stdvoicemail,SIP/FDMC_09_0026_0716,20,326)               ;FNP Webre
exten => *327,1,Dial(SIP/FDMC_09_0027_0716,,b(paging^addheader^1))
exten => 327,1,Macro(stdvoicemail,SIP/FDMC_09_0027_0716,20,327)               ;Accounting/Claims 5
exten => *328,1,Dial(SIP/FDMC_09_0028_0716,,b(paging^addheader^1))
exten => 328,1,Macro(stdvoicemail,SIP/FDMC_09_0028_0716,20,328)               ;Accounting/Claims 3
exten => *329,1,Dial(SIP/FDMC_09_0029_0716,,b(paging^addheader^1))
exten => 329,1,Macro(stdvoicemail,SIP/FDMC_09_0029_0716,20,329)               ;Marshall NS
exten => *333,1,Dial(SIP/FDMC_09_0031_0716,,b(paging^addheader^1))
exten => 333,1,Macro(stdvoicemail,SIP/FDMC_09_0031_0716,20,333)               ;Bauerschlag NS
exten => *334,1,Dial(SIP/FDMC_09_0032_0716,,b(paging^addheader^1))
exten => 334,1,Macro(stdvoicemail,SIP/FDMC_09_0032_0716,20,334)               ;Dr. Marshall
exten => *337,1,Dial(SIP/FDMC_09_0033_0716,,b(paging^addheader^1))
exten => 337,1,Macro(stdvoicemail,SIP/FDMC_09_0033_0716,20,337)               ;Dr. Skelton
exten => *339,1,Dial(SIP/FDMC_09_0034_0716,,b(paging^addheader^1))
exten => 339,1,Macro(stdvoicemail,SIP/FDMC_09_0034_0716,20,339)               ;Skelton NS
exten => *340,1,Dial(SIP/FDMC_09_0035_0716,,b(paging^addheader^1))
exten => 340,1,Macro(stdvoicemail,SIP/FDMC_09_0035_0716,20,340)               ;Earhart NS
exten => *341,1,Dial(SIP/FDMC_09_0036_0716,,b(paging^addheader^1))
exten => 341,1,Macro(stdvoicemail,SIP/FDMC_09_0036_0716,20,341)               ;Calhoun NS
exten => *342,1,Dial(SIP/FDMC_09_0037_0716,,b(paging^addheader^1))
exten => 342,1,Macro(stdvoicemail,SIP/FDMC_09_0037_0716,20,342)               ;Dr. Teague
exten => *343,1,Dial(SIP/FDMC_09_0038_0716,,b(paging^addheader^1))
exten => 343,1,Macro(stdvoicemail,SIP/FDMC_09_0038_0716,20,343)               ;Teague NS
exten => *344,1,Dial(SIP/FDMC_09_0039_0716,,b(paging^addheader^1))
exten => 344,1,Macro(stdvoicemail,SIP/FDMC_09_0039_0716,20,344)               ;Accounting/Claims 1
exten => *345,1,Dial(SIP/FDMC_09_0040_0716,,b(paging^addheader^1))
exten => 345,1,Macro(stdvoicemail,SIP/FDMC_09_0040_0716,20,345)               ;Coder
exten => *348,1,Dial(SIP/FDMC_09_0041_0716,,b(paging^addheader^1))
exten => 348,1,Macro(stdvoicemail,SIP/FDMC_09_0041_0716,20,348)               ;Billing Supervisor
exten => *349,1,Dial(SIP/FDMC_09_0042_0716,,b(paging^addheader^1))
exten => 349,1,Macro(stdvoicemail,SIP/FDMC_09_0042_0716,20,349)               ;Accounting/Claims 4

exten => 400,1,Queue(fdmc-main-queue)
;exten => 401,1,Queue(calhoun-queue)
exten => 401,1,Goto(341,1)
;exten => 402,1,Queue(marshall-queue)
exten => 402,1,Goto(329,1)
;exten => 403,1,Queue()
;exten => 404,1,Queue(thornhill-queue)
exten => 404,1,Goto(313,1)
;exten => 405,1,Queue(earhart-queue)
exten => 405,1,Goto(319,1)
;exten => 406,1,Queue(seely-queue)
exten => 406,1,Goto(325,1)
;exten => 407,1,Queue(webre-queue)
exten => 407,1,Goto(324,1)
;exten => 408,1,Queue(teague-queue)
exten => 408,1,Goto(343,1)
;exten => 409,1,Queue(bauerschlag-queue)
exten => 409,1,Goto(333,1)
;exten => 410,1,Queue()
exten => 411,1,Queue(fdmc-billing-queue)
exten => 412,1,Queue(fdmc-referral-queue)

exten => *60,1,Dial(SIP/FDMC_09_0034_0716&SIP/FDMC_09_0038_0716&SIP/FDMC_09_0031_0716&SIP/FDMC_09_0029_0716&SIP/FDMC_09_0024_0716&SIP/FDMC_09_0025_0716&SIP/FDMC_09_0017_0716&SIP/FDMC_09_0036_0716&SIP/FDMC_09_0014_0716&SIP/FDMC_09_0019_0716,,b(paging^addheader^1))

exten => *90,1,Goto(recording,s,1)
exten => *98,1,VoicemailMain(@default)

exten => 555,1,Goto(incoming,481,1) ; DELETE ME, JUST FOR TESTING

;Handle 911 calls, even if 9911 dialed. -DD 4-14-2016
exten => 9911,1,Set(CALLERID(num)=5555555555)
                same => n,NoOp(911 Call!!!)
                same => n,Dial(DAHDI/G1/${EXTEN:1})
exten => 911,1,Set(CALLERID(num)=5555555555)
                same => n,NoOp(911 Call!!!)
                same => n,Dial(DAHDI/G1/${EXTEN})

;Send all 5 digit or longer numbers into the long distance handler and eventually the local handler -DD 4-14-2016
exten => _XXXXX.,1,Gosub(subLongdistance,${EXTEN},1(5555555555))

include => queuelogin
include => to_cb
include => parkedcalls

[to_cb]
;exten => 1111,1,Gosub(subFaxHandler,start,1(25)); Fax
exten => 239,1,Dial(DAHDI/25)
	same => n,Voicemail(239@default)
exten => 246,1,Dial(DAHDI/26)
	same => n,Voicemail(246@default)
exten => 305,1,Dial(DAHDI/27)
	same => n,Voicemail(305@default)
exten => 307,1,Dial(DAHDI/28)
	same => n,Voicemail(307@default)
exten => 330,1,Dial(DAHDI/29)
	same => n,Voicemail(330@default)


;exten => *60,1,Dial(DAHDI/30) ;Paging Extension

exten => 111,1,Gosub(subFaxHandler,start,1(31)); Fax
exten => 112,1,Gosub(subFaxHandler,start,1(32)); Fax
exten => 113,1,Gosub(subFaxHandler,start,1(33)); Fax
exten => 114,1,Gosub(subFaxHandler,start,1(34)); Fax
exten => 115,1,Gosub(subFaxHandler,start,1(35)); Fax
exten => 116,1,Gosub(subFaxHandler,start,1(36)); Fax
exten => 117,1,Gosub(subFaxHandler,start,1(37)); Fax
exten => 118,1,Gosub(subFaxHandler,start,1(38)); Fax
exten => 119,1,Gosub(subFaxHandler,start,1(39)); Fax
exten => 120,1,Gosub(subFaxHandler,start,1(40)); Fax


exten => _XXXXX.,1,Gosub(subLongdistance,${EXTEN},1(5555555555))
include => fdmc_users

[fdmc_voice_menu]
exten => s,1,Answer()
	same => n,Wait(0.5)
	same => n,Background(fdmc-main-annoucement)
	same => n,WaitExten(5)
	same => n,Queue(fdmc-main-queue)
	same => n,NoOp(******** QUEUE MISSED *******)
	same => n,Goto(fdmc_night,s,1)
exten => 1,1,Goto(fdmc_docs_submenu,s,1)
exten => 2,1,Background(fdmc-fax-address)
exten => 3,1,Playback(fdmc-spanish-announcement)
        same => n,Goto(fdmc_voice_menu,s,4);Drop them right after the annoucement to the wait exten
exten => 4,1,Goto(fdmc_users,201,1) ; Medical Records
exten => 5,1,Goto(fdmc_users,302,1) ; Referrals (May need to send to the referrals queue??)
exten => 6,1,Goto(fdmc_users,301,1) ; RX Assistance
exten => 0,1,Queue(fdmc-main-queue)
exten => *,1,Goto(fdmc_voice_menu,s,1)
exten => _XXX,1,Goto(fdmc_users,${EXTEN},1)

[fdmc_docs_submenu]
exten => s,1,Background(fdmc-doctor-selection)
	same => n,WaitExten(5)
	same => n,Goto(fdmc_docs_submenu,s,1)
exten => 1,1,Goto(fdmc_users,401,1) ; Calhoun Queue
exten => 2,1,Goto(fdmc_users,402,1) ; Marshall Queue
;exten => 3,1,Goto(fdmc_users,403,1) ; New Queue
exten => 4,1,Goto(fdmc_users,404,1) ; Thornhill Queue
exten => 5,1,Goto(fdmc_users,405,1) ; Earhart Queue
exten => 6,1,Goto(fdmc_users,406,1) ; Seely Queue
exten => 7,1,Goto(fdmc_users,407,1) ; Webre Queue
exten => 8,1,Goto(fdmc_users,408,1) ; Teague Queue
exten => 9,1,Goto(fdmc_users,409,1) ; Bauerschlag Queue
;exten => 10,1,Goto(fdmc_users,410,1) ; New Queue
exten => *,1,Goto(fdmc_voice_menu,s,1)

	

[fdmc_night]
exten => s,1,Answer()
	same => n,Wait(1)
	same => n,Background(fdmc-after-hours-annoucement)
	same => n,WaitExten(5)
	same => n,Hangup()
exten => _XXX,1,Goto(fdmc_users,${EXTEN},1)


[queuelogin]
exten => *20,1,Macro(queueloginout,fdmc-main-queue)
exten => *21,1,Macro(queueloginout,calhoun-queue)
exten => *22,1,Macro(queueloginout,marshall-queue)
;exten => *23,1,Macro(queueloginout,new-queue)
exten => *24,1,Macro(queueloginout,thornhill-queue)
exten => *25,1,Macro(queueloginout,earhart-queue)
exten => *26,1,Macro(queueloginout,seely-queue)
exten => *27,1,Macro(queueloginout,webre-queue)
exten => *28,1,Macro(queueloginout,teague-queue)
exten => *29,1,Macro(queueloginout,bauerschlag-queue)
;exten => *30,1,Macro(queueloginout,new-queue)
exten => *31,1,Macro(queueloginout,fdmc-billing-queue)
exten => *32,1,Macro(queueloginout,fdmc-referral-queue)


[localVoicePrompts]
exten => 7481*1,1,Gosub(subRecordFile,start,1(fdmc-main-annoucement)) ; Family Diagnostic Medicine Clinic Main annoucement
exten => 7481*2,1,Gosub(subRecordFile,start,1(fdmc-after-hours-annoucement)) ;" except after hours
exten => 7481*3,1,Gosub(subRecordFile,start,1(fdmc-doctor-selection))	; Doctor selection annoucements
exten => 7481*4,1,Gosub(subRecordFile,start,1(fdmc-spanish-announcement)) ;Same as main except spanish.
exten => 7481*5,1,Gosub(subRecordFile,start,1(fdmc-fax-address)) 	; fax and address...
