<?xml version="1.0"?>
<vxml version="2.0" xml:lang="en-GB">

	<var name="menu_choice" />
	<var name="doctors_name" />
	<var name="patient_ssn" />
	<var name="meds" />
	<var name="confirm" />
	<var name="tries" expr="0" />

	<link event="help">
		<grammar type="application/x-gsl" mode="voice">
		[help]
		</grammar>
	</link>

	<link event="event.exit">
		<grammar type="application/x-gsl" mode="voice">
		[quit back goodbye]
		</grammar>
	</link>

	<catch event="event.exit">
		<exit />
	</catch>








<!-- INTRODUCTORY HELLO AND GREETING -->
	<form id="hello_form">
		<block>
			<audio>Welcome to Mobile Prescriptions. Hello doctor.</audio>
			<goto next="#menu_form" />
		</block>
	</form>





<!-- MENU -->
	<form id="menu_form">

		<field name="menu_choice">

			<grammar type="application/x-gsl" mode="voice">
			<![CDATA[
			[
				[dtmf-1 (doctor ?name) (doctors name) (my name) name first one]		{<menu_choice "doctors_name">}
				[dtmf-2 (?patient social security ?number) (s s n) second two]		{<menu_choice "SSN">}
				[dtmf-3 medicine medicines meds prescriptions scrip third three]	{<menu_choice "Medicine">}
				[dtmf-4 confirm confirmation done fourth four]						{<menu_choice "Confirm">}
			]
			]]>
			</grammar>

			<prompt count="1">
				<audio>Please type or choose: 1, Doctor Name, 2, Patient Social Security Number, 3, Medicine, or 4, Confirm. Say help to repeat this menu.</audio>
			</prompt>

			<prompt count="2">
				<audio>Please choose: Doctor Name, Patient Social Security Number, Medicine, or Confirm.</audio>
			</prompt>

			<prompt count="3">
				<audio>Can you hear me now? Please choose: 1 Doctor Name, 2 Patient Social Security Number, 3 Medicine, or 4 Confirm.</audio>
			</prompt>

			<catch event="noinput nomatch">
				<assign name="tries" expr="tries+1"/>

				<if cond="tries &gt;= 3">
					<audio>We seem to be having trouble connecting. Please try again later. Good-bye!</audio>
					<disconnect />
				</if>

				<audio>I'm sorry. I didn't get that. Please repeat your choice or say help.</audio>
				<reprompt />
			</catch>

			<help>
				<audio src="http://naturalsound.svc.tellme.com/common-audio/help-se.wav">Starting again.</audio>
				<reprompt />
			</help>

			<filled>
				<if cond="menu_choice == 'doctors_name'">
					<goto next="#get_doctors_name" />
					<exit />
				</if>
				<if cond="menu_choice == 'SSN'">
					<goto next="#get_patient_ssn" />
					<exit />
				</if>
				<if cond="menu_choice == 'Medicine'">
					<goto next="#get_meds" />
					<exit />
				</if>
				<if cond="menu_choice == 'Confirm'">
					<goto next="#get_confirm" />
					<exit />
				</if>
			</filled>

		</field>
	</form>






<!-- GET DOCTOR'S NAME -->
	<form id="get_doctors_name">

	<field name="doctors_name">
		<prompt>
			<audio>Hello doctor. Please say your name.</audio>
		</prompt>

		<grammar type="application/x-gsl" mode="voice">
		<![CDATA[
		[
			[anderson]	{<doctors_name "anderson">}
			[arron]		{<doctors_name "arron">}
			[ehrmann]	{<doctors_name "ehrmann">}
			[ha]		{<doctors_name "ha">}
			[kim]		{<doctors_name "kim">}
			[lam]		{<doctors_name "lam">}
			[park]		{<doctors_name "park">}
			[reddy]		{<doctors_name "reddy">}
			[shin]		{<doctors_name "shin">}
			[smith]		{<doctors_name "smith">}
			[wen]		{<doctors_name "wen">}
			[]			{<doctors_name "">}
		]
		]]>
		</grammar>

		<catch event="noinput nomatch">
			<audio>Thank you doctor <value expr="doctors_name"/>. </audio>
			<goto next="#menu_form" />
		</catch>

		<filled>
			<assign name="document.doctors_name" expr="doctors_name"/>
			<audio>Thank you doctor <value expr="doctors_name"/>. </audio>
			<goto next="#menu_form" />
		</filled>

	</field>
	</form>








<!-- GET PATIENT'S SSN -->
	<form id="get_patient_ssn">
	<field name="patient_ssn" type="digits?length=9" modal="true">
		<prompt>
			<audio>Please type or say the patient's social security number.</audio>
		</prompt>

		<noinput>
			<audio>I'm sorry. I didn't hear you.</audio>
			<reprompt />
		</noinput>

		<filled>
			<assign name="document.patient_ssn" expr="patient_ssn"/>
			<goto next="#menu_form" />
		</filled>
	</field>
	</form>






<!-- GET MEDICINE SELECTION -->
	<form id="get_meds">

	<field name="meds">
		<prompt>
			<audio>Please type or choose: 1, asprin, 2, prozac, 3, claritin or, 4, penicillin.</audio>
		</prompt>

		<grammar type="application/x-gsl" mode="voice">
		<![CDATA[
		[
			[dtmf-1 aspirin 1]		{<meds "Aspirin">}
			[dtmf-2 prozac 2]		{<meds "Prozac">}
			[dtmf-3 claritin 3]		{<meds "Claritin">}
			[dtmf-4 penicillin 4]	{<meds "Penicillin">}
			[]						{<meds "">}
		]
		]]>
		</grammar>

		<filled>
			<assign name="document.meds" expr="meds"/>
			<audio>You chose <value expr="meds"/>.</audio>
			<goto next="#menu_form" />
		</filled>

	</field>
	</form>


<!-- GET MEDICINE SELECTION -->
	<form id="get_confirm">

	<field name="confirm">
		<prompt>
			<audio>Please confirm:</audio>
			<audio>Doctor's name is <value expr="doctors_name"/>.</audio>
			<audio>Social security number is <value expr="patient_ssn"/>.</audio>
			<audio>Medicine is <value expr="meds"/>.</audio>
			<audio>Is this correct? Say confirm or reset.</audio>
		</prompt>

		<grammar type="application/x-gsl" mode="voice">
		<![CDATA[
		[
			[confirm correct (o k) (that's right) yes fine good great perfect]	{<confirm "true">}
			[reset false no (start over) (start again) nope]			{<confirm "false">}
		]
		]]>
		</grammar>

		<catch event="noinput nomatch">
			<audio>I'm sorry. I didn't get that.</audio>
			<reprompt />
		</catch>
	
		<filled>
		<!-- check to see that the other variables are filled -->
			<if cond="doctors_name == null">
				<audio>You are missing doctor's name.</audio>
				<goto next="#get_doctors_name" />
				<exit />
			<else/>
				<audio src="http://naturalsound.svc.tellme.com/common-audio/listnext-se.wav">Doctor's name OK.</audio>
			</if>
			<if cond="patient_ssn == null">
				<audio>You are missing the patient's social security number.</audio>
				<goto next="#get_patient_ssn" />
				<exit />
			<else/>
				<audio src="http://naturalsound.svc.tellme.com/common-audio/listnext-se.wav">Patient's S S N OK.</audio>
			</if>
			<if cond="meds == null">
				<audio>You are missing the prescription.</audio>
				<goto next="#get_meds" />
				<exit />
			<else/>
				<audio src="http://naturalsound.svc.tellme.com/common-audio/listnext-se.wav">Medicine is OK.</audio>
			</if>
			<if cond="confirm == 'true'">
				<audio>Thank you for using Mobile prescriptions. Good-bye!</audio>
				<disconnect />
				<exit />
			<else/>
				<audio>Confirmation is not true.</audio>
			</if>
			<if cond="confirm == 'false'">
				<clear namelist="doctors_name"/>
				<clear namelist="patient_ssn"/>
				<clear namelist="meds"/>
				<clear namelist="confirm"/>
				<goto next="#hello_form" />
				<exit />
			<else/>
				<audio>Confirmation is not false.</audio>
			</if>
		</filled>
	</field>

	</form>

</vxml>

