public void AddAnesView(ProcedureParticipantDetails participantDetails)
		{
			try
			{
				anesadded = true;
				UIView view = uvProviderView.ViewWithTag(AnesCount+100);
				if (view != null) {
					UIButton checkbtn=(UIButton)view.ViewWithTag(2);
					if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
						new UIAlertView("Anes Info", "Please Update Anes"+AnesCount+" Record."
												, null, "ok", null).Show();
						return; 
					}
				}

				AnesCount = AnesCount + 1;
				UIView  uvblock=new UIView();
				uvblock.Tag = AnesCount+100;
				uvblock.Frame = new CoreGraphics.CGRect (0, Anesheight, 497, 100);
				Anesheight = Anesheight+100;
				UILabel lbltitle=new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
				lbltitle.Text="Anes ("+AnesCount+"):";	

				UITextView hideid=new UITextView();
				hideid.Hidden=true;
				UIButton anesNameBtn = new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
				anesNameBtn.Tag =  2;
				anesNameBtn.Layer.BorderWidth = 1;
				anesNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
				anesNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
				if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
						anesNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
						anesNameBtn.Tag =  participantDetails.ProcParticipantID;
				} else {
					if (AnesCount == 1) {
						if(iProPQRSPortableLib.Consts.Role.Trim().ToLower() == "anesthesiologist")
							anesNameBtn.SetTitle (iProPQRSPortableLib.Consts.LoginUserFullName, UIControlState.Normal);
						
							if(participantDetails == null)
								participantDetails = new ProcedureParticipantDetails();
						
//							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserLastName.ToLower() && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserFirstName.ToLower());
							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName == iProPQRSPortableLib.Consts.UserLastName && x.FirstName == iProPQRSPortableLib.Consts.UserFirstName);
							if(userDetails != null)
							{
								participantDetails.UserID = userDetails.ID;
								participantDetails.ProcParticipantID = 0;
								participantDetails.RoleID = 2;
								participantDetails.Name = anesNameBtn.CurrentTitle;
								if(anesNameBtn != null && anesNameBtn.CurrentTitle.Trim() != string.Empty){
									AddUpdateProcedureParticipants(participantDetails,anesNameBtn);
								}
							}
					}
				}
				anesNameBtn.Layer.CornerRadius = 5; 
				anesNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
				anesNameBtn.TouchUpInside += async delegate {
					try
					{
						if(listOfAnestheologists.Count > 0){
							if(participantDetails == null)
								participantDetails = new ProcedureParticipantDetails();

							participantDetails.RoleID = 2;
							BindParticipantsPopupover(listOfAnestheologists,anesNameBtn,(int)anesNameBtn.Frame.Y,participantDetails);
						}
					}
					catch{
						
					}
			};
			UILabel slblstar = new UILabel (new CoreGraphics.CGRect (214, 47, 10, 41));
			slblstar.Text = "*";
			slblstar.TextColor = UIColor.Red;

			UILabel lblstart= new UILabel(new CoreGraphics.CGRect(135, 50,80,30));
			lblstart.Text = "Start Time";

			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			UIButton startTimeBtn=new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Tag=11;
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);			
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				if(dt.ToString("HH:mm") == "00:00")
					startTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					startTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
			}
			if(participantDetails != null)
				{
				startTimeBtn.Tag = participantDetails.ProcParticipantID;
					ProcParticipantID=participantDetails.ProcParticipantID;
				}
				if(participantDetails == null && PrevHourTime !=0){
					if(PrevminTime != 60){						
						PrevminTime=+PrevminTime+1;
					}
					DateTime dt=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,PrevHourTime,PrevminTime,0);

				
					string strtime=PrevHourTime.ToString();
					strtime=dt.ToString("HH:mm");
					if(dt.ToString("HH:mm") == "00:00")
						strtime = string.Empty;;

					startTimeBtn.SetTitle(strtime,UIControlState.Normal);
				}
			startTimeBtn.TouchUpInside += async delegate {
					
					if(anesNameBtn.Tag==2)
					{
						new UIAlertView("Anes Info", "Please Select Anes Name"
							, null, "ok", null).Show();
						return;							
					}

				TimePicker  tp = new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {								
						participantDetails.StartTime = tp.SelectedTime;
						if(tp.SelectedTime == "00:00")
							tp.SelectedTime = string.Empty;
						
						startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);

						participantDetails.EndTime = endTimeBtn.CurrentTitle;
						participantDetails.ProcParticipantID=Convert.ToInt16(anesNameBtn.Tag);
						UpdateProcedureParticipants(participantDetails,anesNameBtn);

//						try
//						{
//					if (participantDetails == null)
//						participantDetails = new ProcedureParticipantDetails ();
//
//
//					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
//					participantDetails.EndTime = endTimeBtn.CurrentTitle;
//					participantDetails.StartTime = startTimeBtn.CurrentTitle;
//
//					if(!string.IsNullOrEmpty(anesNameBtn.CurrentTitle)){
//						if(selectedAnestheologistList.Count > 0){
//							if(startTimeBtn.Tag != 0){
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										participantDetails.ProcParticipantID = (int)ProcParticipantID;
//							}else{
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name.Trim().ToLower() == anesNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//										participantDetails.ProcParticipantID=selectedAnestheologistList.Find(x => x.Name !=null &&  x.Name.Trim().ToLower() == anesNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//										//participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										//participantDetails.ProcParticipantID =ProcParticipantID;
//
//							}
//						}else{
//									UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName != null && x.LastName.Trim().ToLower() + ", " + x.LastName !=null && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.LoginUserFullName.Trim().ToLower());
//							participantDetails.UserID = userDetails.ID;
//						}
//						participantDetails.RoleID = 2;
//						UpdateProcedureParticipants(participantDetails,anesNameBtn);
//					}
//						}
//						catch (Exception ex)
//						{
//							
//						}
				};
			};

			UILabel elblstar = new UILabel (new CoreGraphics.CGRect (403, 47, 10, 41));
			elblstar.Text = "*";
			elblstar.TextColor = UIColor.Red;

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,80,30));
			lblendtime.Text = "End Time";

//			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
					if(dt.ToString("HH:mm") == "00:00")
						endTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
					else
						endTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
					
					if(dt.ToString("HH:mm") != "00:00"){
						PrevHourTime=dt.Hour;
						PrevminTime=dt.Minute;
					}
			}	
			if(participantDetails != null)
				endTimeBtn.Tag = participantDetails.ProcParticipantID;
			
			endTimeBtn.TouchUpInside += async delegate {

					if(anesNameBtn.Tag==2)
					{
						new UIAlertView("Anes Info", "Please Select Anes Name"
							, null, "ok", null).Show();
						return;							
					}

				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {	
						participantDetails.EndTime = tp.SelectedTime;
						if(tp.SelectedTime == "00:00")
							tp.SelectedTime = string.Empty;
						
						endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
						participantDetails.StartTime = startTimeBtn.CurrentTitle;

						participantDetails.ProcParticipantID=Convert.ToInt16(anesNameBtn.Tag);
						UpdateProcedureParticipants(participantDetails,anesNameBtn);

						if(tp.SelectedTime != string.Empty){
							DateTime dt=Convert.ToDateTime(tp.SelectedTime);
							PrevHourTime=dt.Hour;
							PrevminTime=dt.Minute;
						}
//						try
//						{
//					if (participantDetails == null)
//						participantDetails = new ProcedureParticipantDetails ();
//					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
//					participantDetails.EndTime = endTimeBtn.CurrentTitle;
//					participantDetails.StartTime = startTimeBtn.CurrentTitle;
//
//					if(!string.IsNullOrEmpty(anesNameBtn.CurrentTitle)){
//						if(selectedAnestheologistList.Count > 0){
//							if(endTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == endTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)endTimeBtn.Tag;
//							}else{
//
//									//	if(selectedAnestheologistList.Count> 0 && selectedAnestheologistList[0].Name != null )
//										//{
//									//	participantDetails.UserID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name == anesNameBtn.CurrentTitle).UserID;
//										//participantDetails.ProcParticipantID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name == anesNameBtn.CurrentTitle).ProcParticipantID;
//										//}
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										participantDetails.ProcParticipantID =ProcParticipantID;
//
//							}
//
//						}else{
//							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName.Trim().ToLower() + ", " + x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.LoginUserFullName.Trim().ToLower());
//							participantDetails.UserID = userDetails.ID;
//						}
//						participantDetails.RoleID = 2;
//						UpdateProcedureParticipants(participantDetails,anesNameBtn);
//					}
//						}
//						catch (Exception ex)
//						{
//							
//						}
				};
			};

			hideid.Tag=4;
				hideid.Text=anesNameBtn.Tag.ToString();
			uvblock.Add(lblstart);
			uvblock.Add(slblstar);
			uvblock.Add(anesNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(elblstar);
			uvblock.Add(endTimeBtn);
			uvblock.Add(hideid);
			Anesstarttimebtn=startTimeBtn;
			Anesendtimebtn=endTimeBtn;
			UIView uvsp=new UIView(new CGRect(0,96,497,1));
			uvsp.BackgroundColor=UIColor.Black;
			UIView uvleftline=new UIView(new CGRect(497,0,1,100));
			uvleftline.BackgroundColor=UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			if ((Anesheight - crnahheight) >= 100) {			    
				uvProviderView.Frame = new CGRect (0, 100, 1008, float.Parse (Anesheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (Anesheight.ToString ())+100 , 1008, 800);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + Anesheight + 200);
			}
			}
			catch (Exception ex){
				string str = "";
			}
		}
		public void AddProviderView(ProcedureParticipantDetails participantDetails)
		{
			UIView view = uvProviderView.ViewWithTag(AnesCount+100);
			if (view != null) {
				UIButton checkbtn=(UIButton)view.ViewWithTag(2);
				if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
					new UIAlertView("Anes Info", "Please Update Anes"+AnesCount+" Record."
											, null, "ok", null).Show();
					return; 
				}
			}

			AnesCount = AnesCount + 1;
			UIView  uvblock=new UIView();
			uvblock.Tag = AnesCount+100;
			uvblock.Frame = new CoreGraphics.CGRect (0, Anesheight, 497, 100);
			Anesheight = Anesheight+100;
			UILabel lbltitle=new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
			lbltitle.Text="Anes ("+AnesCount+"):";			    		    
			UIButton nesNameBtn = new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
			nesNameBtn.Tag =  2;
			nesNameBtn.Layer.BorderWidth = 1;
			nesNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			nesNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
				nesNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
			}
			nesNameBtn.Layer.CornerRadius = 5; 
			nesNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			nesNameBtn.TouchUpInside += async delegate {
				if(listOfAnestheologists.Count > 0){
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					participantDetails.RoleID = 2;
					BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				}
			};
			UILabel lblstart= new UILabel(new CoreGraphics.CGRect(145, 50,85,30));
			lblstart.Text = "Start Time";
			UIButton startTimeBtn=new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				//dt.ToString("HH:mm");
				startTimeBtn.SetTitle (dt.ToString("HH:mm tt"), UIControlState.Normal);

			}
			startTimeBtn.TouchUpInside+= (object sender, EventArgs e) => {
				TimePicker  tp = new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {		
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();
					
					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					participantDetails.StartTime = startTimeBtn.TitleLabel.Text;
					//BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				};
			};

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,85,30));
			lblendtime.Text = "End Time";
			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
				//dt.ToString("HH:mm");
				endTimeBtn.SetTitle (dt.ToString("HH:mm tt"), UIControlState.Normal);
			}		
			endTimeBtn.TouchUpInside += async delegate {
				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {		
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();
					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					participantDetails.EndTime = endTimeBtn.TitleLabel.Text;
					//BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				};
			};



			uvblock.Add(lblstart);
			uvblock.Add(nesNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(endTimeBtn);
			UIView uvsp=new UIView(new CGRect(0,96,497,1));
			uvsp.BackgroundColor=UIColor.Black;
			UIView uvleftline=new UIView(new CGRect(497,0,1,100));
			uvleftline.BackgroundColor=UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			if ((Anesheight - crnahheight) >= 100) {			    
				uvProviderView.Frame = new CGRect (0, 100, 1008, float.Parse (Anesheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (Anesheight.ToString ())+100 , 1008, 520);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + Anesheight + 200);
			}


		}
		public void AddCRNAView(ProcedureParticipantDetails participantDetails)
		{
			crnaadded = true;
			UIView view = uvProviderView.ViewWithTag(crnacount+200);
			if (view != null) {
				UIButton checkbtn = (UIButton)view.ViewWithTag(2);
				if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
					new UIAlertView("CRNA Info", "Please Update CRNA"+crnacount+" Record."
						, null, "ok", null).Show();
					return; 
				}
			}


			crnacount = crnacount + 1;
			UIView  uvblock= new UIView();
			uvblock.Tag = crnacount+200;
			uvblock.Frame = new CoreGraphics.CGRect (498, crnahheight, 530, 100);
			crnahheight=crnahheight+100;
			UITextView hideid=new UITextView();
			hideid.Hidden=true;
			UILabel lbltitle= new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
			lbltitle.Text="CRNA ("+crnacount+"):";			    		    
			UIButton crnaNameBtn=new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
			crnaNameBtn.Tag =  2;
			crnaNameBtn.Layer.BorderWidth = 1;
			crnaNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			crnaNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
				crnaNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
				crnaNameBtn.Tag = participantDetails.ProcParticipantID;
			} else {
//				if (crnacount ==1 && crnaNameBtn.Tag == 2 && !string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)) {
				if (crnacount ==1 && crnaNameBtn.Tag == 2) {
					if(iProPQRSPortableLib.Consts.Role.Trim().ToLower() == "crna")
						crnaNameBtn.SetTitle (iProPQRSPortableLib.Consts.LoginUserFullName, UIControlState.Normal);
					
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					UserDetails userDetails = null;
					try{
						userDetails = listOfCRNAs.Find (x => x.LastName == iProPQRSPortableLib.Consts.UserLastName && x.FirstName == iProPQRSPortableLib.Consts.UserFirstName);
//						 userDetails = listOfCRNAs.Find (x => x.LastName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserLastName.ToLower() && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserFirstName.ToLower());
					}catch(Exception ex){
						Console.WriteLine ("AddCRNAView Ex: "+ex.Message);
					}

					if (userDetails != null) {
						participantDetails.UserID = userDetails.ID;
						participantDetails.ProcParticipantID = 0;
						participantDetails.RoleID = 6;
						participantDetails.Name = crnaNameBtn.CurrentTitle;//crnaNameBtn.CurrentTitle.Trim();
						if (crnaNameBtn != null && crnaNameBtn.CurrentTitle.Trim () != string.Empty) {
							AddUpdateProcedureParticipants (participantDetails, crnaNameBtn);
						}
					}
				}
			}


			crnaNameBtn.Layer.CornerRadius = 5; 
			crnaNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			crnaNameBtn.TouchUpInside += async delegate {
				if(listOfCRNAs.Count > 0){
					
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					participantDetails.RoleID = 6;
					BindParticipantsPopupover(listOfCRNAs,crnaNameBtn,(int)crnaNameBtn.Frame.Y,participantDetails);
				}
			};
			UILabel slblstar = new UILabel (new CoreGraphics.CGRect (214, 47, 10, 41));
			slblstar.Text = "*";
			slblstar.TextColor = UIColor.Red;

			UILabel lblstart = new UILabel(new CoreGraphics.CGRect(135, 50,80,30));
			lblstart.Text = "Start Time";
			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			UIButton startTimeBtn= new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Tag = 11;
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				//dt.ToString("HH:mm");
				if(dt.ToString("HH:mm") == "00:00")
					startTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					startTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
			}

			if(participantDetails != null)
				startTimeBtn.Tag = participantDetails.ProcParticipantID;

			if(participantDetails == null && PrevcrnaHourTime !=0)
			{
				if(PrevcrnaminTime != 60)
				{						
					//PrevHourTime=PrevHourTime+1;
					PrevcrnaminTime=+PrevcrnaminTime+1;
				}
				DateTime dt=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,PrevcrnaHourTime,PrevcrnaminTime,0);


				string strtime=PrevHourTime.ToString();
				strtime=dt.ToShortTimeString();
				startTimeBtn.SetTitle(strtime,UIControlState.Normal);
			}

			startTimeBtn.TouchUpInside += (object sender, EventArgs e) => {
				if(crnaNameBtn.Tag==2)
				{
					new UIAlertView("Anes Info", "Please Select CRNA Name"
						, null, "ok", null).Show();
					return;							
				}
				TimePicker  tp= new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {
					try
					{
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();

					participantDetails.StartTime = tp.SelectedTime;
					if(tp.SelectedTime == "00:00")
						tp.SelectedTime = string.Empty;

					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					
					participantDetails.EndTime = endTimeBtn.CurrentTitle;
					participantDetails.ProcParticipantID= Convert.ToInt16(crnaNameBtn.Tag);

					if(!string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)){
						if(selectedCRNAList.Count > 0){
//							participantDetails.UserID = selectedCRNAList[(int)(startTimeBtn.Tag - 1)].UserID;
//							participantDetails.ProcParticipantID = selectedCRNAList[(int)(startTimeBtn.Tag - 1)].ProcParticipantID;
//
//							if(startTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedCRNAList.Find(x => x.ProcParticipantID == startTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)startTimeBtn.Tag;
//							}else{
//									participantDetails.UserID = selectedCRNAList.Find(x => x.Name!= null && x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//									participantDetails.ProcParticipantID = selectedCRNAList.Find(x => x.Name!= null && x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//							}

							participantDetails.RoleID = 6;
							UpdateProcedureParticipants(participantDetails,crnaNameBtn);
						}
					}
					}
					catch
					{
						
					}
				};
			};

			UILabel elblstar = new UILabel (new CoreGraphics.CGRect (403, 47, 10, 41));
			elblstar.Text = "*";
			elblstar.TextColor = UIColor.Red;

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,80,30));
			lblendtime.Text = "End Time";
			endTimeBtn.Tag = 22;
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
				//dt.ToString("HH:mm");
				if(dt.ToString("HH:mm") == "00:00")
					endTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					endTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);

				if(dt.ToString("HH:mm") != "00:00"){
					PrevcrnaHourTime=dt.Hour;
					PrevcrnaminTime=dt.Minute;
				}
			}	

			if(participantDetails != null)
				endTimeBtn.Tag = participantDetails.ProcParticipantID;
			
			endTimeBtn.TouchUpInside += async delegate {
				if(crnaNameBtn.Tag==2)
				{
					new UIAlertView("Anes Info", "Please Select CRNA Name"
						, null, "ok", null).Show();
					return;							
				}


				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {		
					try
					{
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();

					participantDetails.EndTime = tp.SelectedTime;
					if(tp.SelectedTime == "00:00")
						tp.SelectedTime = string.Empty;

					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					

					participantDetails.StartTime = startTimeBtn.CurrentTitle;
					participantDetails.ProcParticipantID= Convert.ToInt16(crnaNameBtn.Tag);

					if(tp.SelectedTime != string.Empty){
						DateTime dt=Convert.ToDateTime(tp.SelectedTime);
						PrevcrnaHourTime=dt.Hour;
						PrevcrnaminTime=dt.Minute;
					}

					if(!string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)){
						if(selectedCRNAList.Count > 0){

//							if(endTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedCRNAList.Find(x => x.ProcParticipantID == endTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)startTimeBtn.Tag;
//							}else{
//									participantDetails.UserID = selectedCRNAList.Find(x => x.Name!= null &&  x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//									participantDetails.ProcParticipantID = selectedCRNAList.Find(x => x.Name!= null &&  x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//							}

							participantDetails.RoleID = 6;
							UpdateProcedureParticipants(participantDetails,crnaNameBtn);
						}
					}
					}
					catch
					{
						
					}

				};
			};
			hideid.Tag=4;
			hideid.Text=crnaNameBtn.Tag.ToString();
			uvblock.Add(lblstart);
			uvblock.Add (slblstar);
			uvblock.Add(crnaNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(endTimeBtn);
			uvblock.Add (elblstar);
			uvblock.Add(hideid);
			crnaStarttime = startTimeBtn;
			crnaendtime = endTimeBtn;
			UIView uvsp = new UIView(new CGRect(0,96,520,1));
			uvsp.BackgroundColor = UIColor.Black;
			UIView uvleftline = new UIView(new CGRect(0,0,1,100));
			uvleftline.BackgroundColor = UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			//Anesheight - crnahheight
			if (( crnahheight-Anesheight) >= 100) {
				uvProviderView.Frame = new CGRect (0,100, 1008, float.Parse (crnahheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (crnahheight.ToString ())+100 , 1008, 800);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + crnahheight + 200);
			}


		}
		public override void ViewDidLoad ()
		{
			
			base.ViewDidLoad ();
			wvpatient.EndEditing (true);
			BackBtn.TouchUpInside+= (object sender, EventArgs e) => {
				this.NavigationController.PopViewController(true);
			};
			mMenu.ValueChanged+= (object sender, EventArgs e) => {

				wvpatient.EvaluateJavascript("bindPanel("+mMenu.SelectedSegment+")");
			};
			BtnSubmit.TouchUpInside+=async (object sender, EventArgs e) => {
				AppDelegate.pb.Start(this.View,"Please wait...");
				string str=wvpatient.EvaluateJavascript("GetTextboxValue()");
				XmlSerializer xs = new XmlSerializer(typeof(ProfileInfo));
				ProfileInfo objpi = (ProfileInfo)xs.Deserialize(new StringReader(str));

				PQRSServices services=new PQRSServices();
				Patient Profile=new Patient();

				if(patientProcedureDetails!=null)
					Profile.ID=patientProcedureDetails.PatientID;
				else
					Profile.ID=0;				
				Profile.cbEmergency=objpi.cbEmergency;

				if(mPatient!=null)
					Profile.CreatedOn = mPatient.OperationDate;
				else
					Profile.CreatedOn = DateTime.Now.ToShortDateString();
			
				Profile.ddlASAType=objpi.ddlASAType;
				Profile.ddlEncounterType=objpi.ddlEncounterType;
				Profile.LastModifiedDate=DateTime.Now.ToShortDateString();
				Profile.FacilityID=iProPQRSPortableLib.Consts.SelectedFacilityID;
				Profile.FirstName=objpi.Firstname;
				Profile.LastName=objpi.Lastname;
				Profile.DOB=objpi.DOB;	
				Profile.MRN=objpi.MRN;
				ReceiveContext result1 = await AppDelegate.Current.pqrsMgr.AddUpdatePatintInfo (Profile);
				Patient piResult=null;
				if(string.IsNullOrEmpty(result1.message))
				{
					piResult = (Patient)JsonConvert.DeserializeObject(result1.result.ToString() , typeof(Patient));
					//new UIAlertView("Patient Info", "Successfully Saved."
					//	, null, "ok", null).Show();
				}
				else
				{
					new UIAlertView("Patient eroor", result1.message
						, null, "ok", null).Show();
				}
				PatientProcedureFullDetails PDetails=new PatientProcedureFullDetails();
				if(patientProcedureDetails!=null)
				{
					PDetails.ID=patientProcedureDetails.ProcID;
					PDetails.PatientID=patientProcedureDetails.PatientID.ToString();
					PDetails.StatusID=patientProcedureDetails.StatusID.ToString();
				}
				else
				{
					if(piResult==null)
					{
						PDetails.ID=0;
						PDetails.PatientID="0";
					}
					else
					{

						PDetails.ID=0;
						PDetails.PatientID=piResult.ID.ToString();
					}	
				}


				PDetails.Mrn=objpi.MRN;
				PDetails.OperationDate=objpi.OperationDate;
				//PDetails.PatientID=objpi.PatientID;
				//PDetails.Location=objpi.Location;
				//PDetails.ORNumber=objpi.;
				PDetails.Anesthesiologist=objpi.Anesthesiologist1_label;
				PDetails.Anesthesiologist1=objpi.Anesthesiologist2_label;
				PDetails.Anesthesiologist2=objpi.Anesthesiologist2_label;
				PDetails.Anesthesiologist3=objpi.Anesthesiologist2_label;
				PDetails.Crna=objpi.CRNA1_label;
				PDetails.Crna1=objpi.CRNA1_label;
				PDetails.Crna2=objpi.CRNA2_label;
				PDetails.Crna3=objpi.CRNA3_label;
				//PDetails.RlfTime1=objpi.tim;
				//PDetails.RlfTime2
				//PDetails.RlfTime3
				//PDetails.RlfTime4
				PDetails.CrnaRlfTime1=objpi.CrnaStrtTime1;
				PDetails.CrnaRlfTime2=objpi.CrnaStrtTime2;
				PDetails.Surgeon=objpi.Surgeon;
				PDetails.Surgeon2=objpi.Surgeon2;

				PDetails.Surgeon3=objpi.Surgeon3;
			    //PDetails.Procedures=objpi.Procedures1;
				//PDetails.Diagnosis=objpi.CRNA4_label;
				//PDetails.ScheduleStartTime=objpi.;
				//PDetails.StatusID=objpi.CRNA4_label;
				//PDetails.RoomIn=objpi.CRNA4_label;
				PDetails.AnesStart=objpi.AnesStrtTime1;
				//PDetails.SurgeryStart=objpi.OperationDate;
				//PDetails.IncisionTime=objpi.time;
				//PDetails.SurgeryEnd=objpi.CRNA4_label;
				PDetails.AnesEnd=objpi.AnesEndTime1;
				PDetails.LastUpdatedTime=DateTime.Now.ToString();
				//PDetails.tbPreIndBP=objpi.CRNA4_label;
				//PDetails.tbPreIndP=objpi.CRNA4_label;
				//PDetails.tbPreIndSPO2=objpi.CRNA4_label;
				//PDetails.tbPreIndResp=objpi.CRNA4_label;
				PDetails.Procedure1=objpi.Procedures1;
				PDetails.Procedure2=objpi.Procedures2;
				PDetails.Procedure3=objpi.Procedures3;
				PDetails.Procedure4=objpi.Procedures4;
				PDetails.ProcedureCode1=objpi.ProcedureCode1;
				PDetails.ProcedureCode2=objpi.ProcedureCode2;
				PDetails.ProcedureCode3=objpi.ProcedureCode3;
				PDetails.ProcedureCode4=objpi.ProcedureCode4;
				//PDetails.ProcedureUnit1
				//PDetails.ProcedureUnit2
				//PDetails.ProcedureUnit3
				//PDetails.ProcedureUnit4
				PDetails.Diagnosis1=objpi.Diagnosis1;
				PDetails.Diagnosis2=objpi.Diagnosis2;
				PDetails.Diagnosis3=objpi.Diagnosis3;
				PDetails.Diagnosis4=objpi.Diagnosis4;

				PDetails.DiagnosisCode1=objpi.DiagnosisCode1;
				PDetails.DiagnosisCode2=objpi.DiagnosisCode2;
				PDetails.DiagnosisCode3=objpi.DiagnosisCode3;
				PDetails.DiagnosisCode4=objpi.DiagnosisCode4;
				//DiagnosisUnit1
				//DiagnosisUnit2
				//DiagnosisUnit3
				//DiagnosisUnit4
				//Modifier1
				//Modifier2
				//Modifier3
				//Modifier4
				PDetails.Duration=objpi.delayedDuration;
				//SurveyComplete
				//BillingInfo
				//PDFStatus
				//PatientClass
				//CancellationReason
				PDetails.CancellationReasonID=objpi.ddlCancellationReasons;
				//OrderNumber
				PDetails.ddlEncounterType=objpi.ddlEncounterType;
				PDetails.ddlASAType=objpi.ddlASAType;
				PDetails.cbEmergency=objpi.cbEmergency;
				PDetails.Anesthesiologist4=objpi.Anesthesiologist4;
				//RlfTime3
				PDetails.Crna4=objpi.CRNA4_label;
				//CrnaRlfTime3
				//Srna1
				//Srna2
				//SrnaRlfTime1
				//Source
				//Induction
				PDetails.AnesStrtTime1=objpi.AnesStrtTime1;
				PDetails.AnesEndTime1=objpi.AnesEndTime1;
				PDetails.AnesStrtTime2=objpi.AnesStrtTime2;
				PDetails.AnesEndTime2=objpi.AnesEndTime2;
				PDetails.AnesStrtTime3=objpi.AnesStrtTime3;
				PDetails.AnesEndTime3=objpi.AnesEndTime3;
				PDetails.AnesStrtTime4=objpi.AnesStrtTime4;
				PDetails.AnesEndTime4=objpi.AnesEndTime4;
				PDetails.CrnaStrtTime1=objpi.CrnaStrtTime1;
				PDetails.CrnaEndTime1=objpi.CrnaEndTime1;
				PDetails.CrnaStrtTime2=objpi.CrnaStrtTime2;
				PDetails.CrnaEndTime2=objpi.CrnaEndTime2;
				PDetails.CrnaStrtTime3=objpi.CrnaStrtTime3;
				PDetails.CrnaEndTime3=objpi.CrnaEndTime3;
				PDetails.CrnaStrtTime4=objpi.CrnaStrtTime4;
				PDetails.CrnaEndTime4=objpi.CrnaEndTime4;
				//SrnaStrtTime1
				//SrnaEndTime1
				//ListType
				ReceiveContext result2=await services.UpdatePatintProcedureInfo(PDetails);
				if(string.IsNullOrEmpty(result2.message))
				{
					BtnSubmit.Enabled=false;
					AppDelegate.pb.Stop();
					new UIAlertView("Patient Procedure Info", "Successfully Saved."
						, null, "ok", null).Show();
				}
				else
				{
					AppDelegate.pb.Stop();
					new UIAlertView("Patient eroor", result2.message
						, null, "ok", null).Show();
				}


				//Nahid Ahmed Testing patient upload
//				Patient pat = new Patient();
//				pat.ID = 17517;
//				pat.MRN = "54576576876";
//				pat.FirstName = "John6";
//				pat.LastName = "DoelMansuri";
//				pat.Sex = "M";
//				pat.Height = "5)6";
//				pat.Weight = "67";
//				pat.Allergies = "Tablet";
//				pat.PersonProvidingInfo = "Patient";
//				pat.DOB = "1962-02-02T00:00:00";
//				pat.AccountNo = "3564546466";
//				AppDelegate.Current.pqrsMgr.UploadPatientData(pat);

			};
			this.NavigationController.NavigationBarHidden = true;		
			if (mPatient != null && mPatient.PatientID != null) {
				lblPatientName.Text = mPatient.PatientName;
				lblhmrn.Text = "MRN :" + mPatient.MRN;
				lblAccount.Text = "ACCT :" + mPatient.AccountNo;
			} else {
				lblPatientName.Text = "";
				lblhmrn.Text = "";
				lblAccount.Text = "";
			}
			LoadWevView ();
			wvpatient.LoadFinished+= WvPatientProcedure_LoadFinished;
			#region ShouldStartLoad
			wvpatient.ShouldStartLoad = (webView, request, navType) => {
				string requestString=request.Url.Description;
				string param=string.Empty;
				if(requestString.Contains("pro://showAlert/"))
				{
					string message=requestString.Remove(0,15);
					AlertMsg(message);
				}
				else if(requestString.Contains("pro://openDatePicker/"))
				{
					param=requestString.Remove(0,22);
					string[] pary=param.Split(',');
					string mCurrentTextBoxID=pary[0];
					float x=float.Parse(pary[1]);
					float y=float.Parse(pary[2]);
					if(mCurrentTextBoxID=="OperationDate" || mCurrentTextBoxID=="DOB")
					{
						DatePicker  dp=new DatePicker();
						dp.PresentFromPopover(wvpatient,x,y);
						dp._ValueChanged += delegate {	
							int age = DateTime.Now.Year - dp.SelectedDateValue.Year;
							//this.mPatient.DOB = dp.SelectedDate;
							SetTextboxValue(mCurrentTextBoxID,dp.SelectedDate);
							SetTextboxValue("Age",age.ToString());
						};
					}
					else
					{
						TimePicker  tp=new TimePicker();
						tp.PresentFromPopover(wvpatient,x,y);
						tp._ValueChanged += delegate {						
							SetTextboxValue(mCurrentTextBoxID,tp.SelectedTime);
						};
					}

				}
				else if(requestString.Contains("pro://openCodePicker/Diagnosis"))
				{
					param=requestString.Remove(0,22);
					string[] pary=param.Split(',');
					string currentDiagnosticCodeTextID = string.Empty;

					if(requestString.Contains("Diagnosis1"))
						currentDiagnosticCodeTextID = "DiagnosisCode1";
					else if(requestString.Contains("Diagnosis2"))
						currentDiagnosticCodeTextID = "DiagnosisCode2";
					else if(requestString.Contains("Diagnosis3"))
						currentDiagnosticCodeTextID = "DiagnosisCode3";
					else if(requestString.Contains("Diagnosis4"))
						currentDiagnosticCodeTextID = "DiagnosisCode4";

					bool itemPreviouslySearched = false;

					string lastSelectedProcedures = ReadFile("lastSelectedDiagnosis.txt");
					if(lastSelectedProcedures != string.Empty){
						lastSelectedProceduresObj = (ProcedureDiagnosticMaster)JsonConvert.DeserializeObject(lastSelectedProcedures,typeof(ProcedureDiagnosticMaster));
						foreach (DataResults item in lastSelectedProceduresObj.results) {
							if(item.Name != null){
								if(item.Name.ToLower().Contains(pary[4].ToLower())){
									itemPreviouslySearched = true;
									break;
								}
							}
						}
					}

					if(cp != null){
						if(cp.popover != null)
							cp.popover.Dismiss(false);
					}


					if(itemPreviouslySearched){
						int uvWidth=280;
						List<CodePickerModel> list=SetDataSource(out uvWidth);
						string mCurrentTextBoxID=pary[0];
						float x=float.Parse(pary[1]);
						float y=float.Parse(pary[2]);
						cp	=new CodePicker(this,uvWidth);
						cp.PresentFromPopover(wvpatient,x,y,uvWidth);
						cp.DataSource=list;
						cp._ValueChanged += delegate {						
							SetTextboxValue(mCurrentTextBoxID,cp.SelectedText);
							SetTextboxValue(currentDiagnosticCodeTextID,cp.SelectedCodeValue);
						}; 
					}else{
						if(pary[4].Replace("%20"," ").Trim().Length > 0)
							DownloadData("ICD9",pary,currentDiagnosticCodeTextID);
					}
				}
				else if(requestString.Contains("pro://openCodePicker/Procedures"))
				{
					param=requestString.Remove(0,22);
					string[] pary=param.Split(',');

					string currentProceduresCodeTextID = string.Empty;

					if(requestString.Contains("Procedures1"))
						currentProceduresCodeTextID = "ProcedureCode1";
					else if(requestString.Contains("Procedures2"))
						currentProceduresCodeTextID = "ProcedureCode2";
					else if(requestString.Contains("Procedures3"))
						currentProceduresCodeTextID = "ProcedureCode3";
					else if(requestString.Contains("Procedures4"))
						currentProceduresCodeTextID = "ProcedureCode4";
					
					bool itemPreviouslySearched = false;

					string lastSelectedProcedures = ReadFile("lastSelectedProcedures.txt");
					if(lastSelectedProcedures != string.Empty){
						lastSelectedProceduresObj = (ProcedureDiagnosticMaster)JsonConvert.DeserializeObject(lastSelectedProcedures,typeof(ProcedureDiagnosticMaster));
						foreach (DataResults item in lastSelectedProceduresObj.results) {
							if(item.Name != null){
								if(item.Name.ToLower().Contains(pary[4].ToLower())){
									itemPreviouslySearched = true;
									break;
								}
							}
						}
					}
						
 					if(cp != null){
						if(cp.popover != null)
							cp.popover.Dismiss(false);
					}
					
					if(itemPreviouslySearched){
						int uvWidth=280;
						List<CodePickerModel> list=SetDataSource(out uvWidth);
						string mCurrentTextBoxID=pary[0];
						float x=float.Parse(pary[1]);
						float y=float.Parse(pary[2]);
						cp	=new CodePicker(this,uvWidth);

						if(pary[4].Trim().Length > 0)
							cp.PresentFromPopover(wvpatient,x,y,uvWidth);
						
						cp.DataSource=list;
						cp._ValueChanged += delegate {	
							SetTextboxValue(mCurrentTextBoxID,cp.SelectedText);
							SetTextboxValue(currentProceduresCodeTextID,cp.SelectedCodeValue);
						}; 
					}else{
						if(pary[4].Replace("%20"," ").Trim().Length > 0)
							DownloadData("CPT",pary,currentProceduresCodeTextID);
					}
				}
				else if(requestString.Contains("ipro://Checkmrncode/"))
				{

					param = requestString.Remove(0, 23);
					string[] pary = param.Split(',');
					string mCurrentTextBoxID = pary[3];
					float x = float.Parse(pary[1]);
					float y = float.Parse(pary[2]);
					string mrn=wvpatient.EvaluateJavascript("GetVal('"+mCurrentTextBoxID+"')");
					PQRSServices serv=new PQRSServices();
					ReceiveContext context=new ReceiveContext();
					if(!string.IsNullOrEmpty(mrn))
					{
						AppDelegate.pb.Start(this.View,"Checking MRN number");

						InvokeOnMainThread ( async () =>  {
							context=await serv.CheckExistingPatintInfo(mrn,"1");
							string strtemp=context.result.ToString();
							List<Patient> objpi = (List<Patient>)JsonConvert.DeserializeObject(context.result.ToString() , typeof(List<Patient>));
							//"MRN", "Firstname", "Lastname","DOB","Age","ddlEncounterType","ddlASAType","cbEmergency"
							Patient tempProfil;
							if(objpi.Count>0)
							{
								if(objpi.Count>1)
								{

									int maxval=FindMaxID(objpi);
									tempProfil=objpi.Find(u=>u.ID==maxval);
								}
								else
								{								
									tempProfil=objpi[0];
								}
								SetTextboxValue("Firstname",tempProfil.FirstName);
								SetTextboxValue("Lastname",tempProfil.LastName);
								if(!string.IsNullOrEmpty(tempProfil.DOB))
								{
									SetTextboxValue("DOB",tempProfil.DOB);
									var now = float.Parse(DateTime.Now.ToString("yyyy.MMdd"));
									var dob = float.Parse(Convert.ToDateTime(tempProfil.DOB).ToString("yyyy.MMdd"));
									var age = (int)(now - dob);
									SetTextboxValue("Age", age.ToString());
								}							
								lblhmrn.Text = "MRN :" + tempProfil.MRN;
								lblAccount.Text = "ACCT :" + tempProfil.AccountNo;
								lblPatientName.Text = tempProfil.FirstName+" , "+tempProfil.LastName;
								SetTextboxValue("ddlEncounterType",tempProfil.ddlEncounterType);
								SetTextboxValue("ddlASAType",tempProfil.ddlASAType);
								SetTextboxValue("cbEmergency",tempProfil.cbEmergency);
								AppDelegate.pb.Stop();
							}
							else
							{
								SetTextboxValue("Firstname","");
								SetTextboxValue("Lastname","");
								SetTextboxValue("DOB","");
								SetTextboxValue("Age", "");
								lblhmrn.Text = "";
								lblAccount.Text = "";
								lblPatientName.Text = "";
								SetTextboxValue("ddlEncounterType","");
								SetTextboxValue("ddlASAType","");
								SetTextboxValue("cbEmergency","");
								AppDelegate.pb.Stop();
							}

						});
					}


				}
                else if (requestString.Contains("ipro://mopenCodePicker/"))
                {
					wvpatient.KeyboardDisplayRequiresUserAction = false;
					UIView ruv=wvpatient.InputAccessoryView;
					if(ruv!=null)
						ruv.Hidden=true;
					
                    mCodePicker mcp;

                    param = requestString.Remove(0, 23);
                    string[] pary = param.Split(',');
                    string mCurrentTextBoxID = pary[0];
                    float x = float.Parse(pary[1]);
                    float y = float.Parse(pary[2]);
                    if (mCurrentTextBoxID == "AnesthesiaTech")
                    {
						int uvwidth;
						List<CodePickerModel> alist=mSetDataSource(AnesthesiaTech.Split(','), out  uvwidth);
						mcp = new mCodePicker(this,uvwidth);
                        // need to set Selected Items
                        if (ATlist.Count > 0)
                            mcp.SelectedItems = ATlist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);
						mcp.mDataSource(alist);
                        mcp._ValueChanged += delegate
                        {
                            ATlist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in ATlist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    else if (mCurrentTextBoxID == "Lines")
                    {
						int uvwidth;
						List<CodePickerModel> list=mSetDataSource(Lines.Split(','), out  uvwidth);
                        mcp = new mCodePicker(this);
                        // need to set Selected Items
                        if (Linelist.Count > 0)
                            mcp.SelectedItems = Linelist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);
						mcp.mDataSource(list);
                        mcp._ValueChanged += delegate
                        {
                            Linelist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in Linelist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    else if (mCurrentTextBoxID == "CVCSterileTec")
                    {
						int uvwidth;
						List<CodePickerModel> list=mSetDataSource(CVCSterileTec.Split(','), out  uvwidth);
						mcp = new mCodePicker(this,uvwidth);
                        mcp.Setwidth();
                        // need to set Selected Items
                        if (CVCTlist.Count > 0)
                            mcp.SelectedItems = CVCTlist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);

						mcp.mDataSource(list);
                        mcp._ValueChanged += delegate
                        {
                            CVCTlist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in CVCTlist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    else if (mCurrentTextBoxID == "NerveBlack")
                    {
						int uvwidth;
						List<CodePickerModel> list=mSetDataSource(NerveBlack.Split(','), out uvwidth);
						mcp = new mCodePicker(this,uvwidth);
                        // need to set Selected Items
                        if (NBlist.Count > 0)
                            mcp.SelectedItems = NBlist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);
						mcp.mDataSource(list);
                        mcp._ValueChanged += delegate
                        {
                            NBlist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in NBlist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    else if (mCurrentTextBoxID == "SterileTec")
                    {
						int uvwidth;
						List<CodePickerModel> list=mSetDataSource(SterileTec.Split(','), out uvwidth);
						mcp = new mCodePicker(this,uvwidth);
                        // need to set Selected Items
                        if (STlist.Count > 0)
                            mcp.SelectedItems = STlist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);
						mcp.mDataSource(list);
                        mcp._ValueChanged += delegate
                        {
                            STlist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in STlist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    else if (mCurrentTextBoxID == "SpecialTech")
                    {
						int uvwidth;
						List<CodePickerModel> list=mSetDataSource(SpecialTech.Split(','), out uvwidth);
						mcp = new mCodePicker(this,uvwidth);
                        // need to set Selected Items
                        if (SPTlist.Count > 0)
                            mcp.SelectedItems = SPTlist;
                        //
						mcp.PresentFromPopover(wvpatient, x, y,uvwidth);
						mcp.mDataSource(list);
                        mcp._ValueChanged += delegate
                        {
                            SPTlist = mcp.SelectedItems;
                            string finalText = string.Empty;
                            foreach (var item in SPTlist)
                            {
                                finalText = finalText + ", " + item.ItemText;
                            }
                            SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
                        };
                    }
                    wvpatient.ResignFirstResponder();
                }
				return true;
			};
			#endregion
			// Perform any additional setup after loading the view, typically from a nib.
		}