public void BindPopupover(List<iProPQRSPortableLib.Option> items,List<string> Selecteditems,UIButton btnField,int FrameY,string labelName)
		{
			int uvwidth;
			ATlist.Clear ();
			List<CodePickerModel> alist = SetTypeDataSource(items, out  uvwidth);

			mcp = new mCodePicker(this,uvwidth);
			mcp.TypeOfList = "Options";



			if (ATlist.Count > 0)
				mcp.SelectedItems = ATlist;


			float x = 10;//(float)btnField.Frame.X;
			float y = 10;//(float)btnField.Frame.Y+FrameY;

			mcp.PresentFromPopover(btnField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				ATlist = mcp.SelectedItems;
				string finalText = " ";

				List<AttribType>  procalist=new List<AttribType>();
				AttribType procitem; 
				int ProcID=0;
				if(procedureDetails != null && procedureDetails.ID != 0)
					ProcID = procedureDetails.ID;

				foreach (var item in ATlist)
				{					
					procitem = new AttribType();
					procitem.ProcAttribTypeID = item.ItemID;
					procitem.ProcID = ProcID;
					procitem.Value = item.ItemCode;
					procitem.IsHighLighted = false;
					procalist.Add(procitem);
					procitem = null;
					finalText = item.ItemText;
				}
				btnField.SetTitle(finalText.Trim(),UIControlState.Normal);;

				foreach (var sitem in Selecteditems) {
					string spid = ATlist.Where(w=>w.ItemCode == sitem).Select(s=>s.ItemCode).SingleOrDefault();
					if(spid == string.Empty)
					{
						procitem=new AttribType();
						procitem.ProcAttribTypeID = items[0].ProcAttribTypeID;
						procitem.ProcID = ProcID;
						procitem.Value = "";
						procitem.IsHighLighted=false;
						procalist.Add(procitem);
						procitem=null;
					}
				}


				if(procalist != null && procalist.Count > 0 ){
					var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
					if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK"){
						Console.WriteLine ("Patient Info. Successfully Saved.");
//						new UIAlertView("Procedure Info", "Successfully Saved.", null, "ok", null).Show();
					}else{
						new UIAlertView("Error", procAttribtsobject.message, null, "ok", null).Show();
					}
				}

				if(labelName == "CVCSterileTech"){
					selectedLineCVCSterileTechIds.Clear();
					foreach (var item in ATlist) {
						selectedLineCVCSterileTechIds.Add(item.ItemCode);
					}
				}

				ATlist.Clear();
			};
		}
예제 #2
0
 public mCodePickerSource(mCodePicker mhomeController)
 {
     this.mCodePickerController = mhomeController;
     this.typeOfList = mhomeController.TypeOfList;
     indexedtableitems = new Dictionary<string,List<CodePickerModel>> ();
     foreach (var t in mCodePickerController.DataSource) {
         if (indexedtableitems.ContainsKey (t.ItemText [0].ToString ().ToUpper())) {
             indexedtableitems [t.ItemText [0].ToString ().ToUpper()].Add (t);
         } else {
             indexedtableitems.Add (t.ItemText [0].ToString ().ToUpper(), new List<CodePickerModel> (){ t });
         }
     }
     keys = indexedtableitems.Keys.OrderBy (o=>o.ToString()).ToArray();
 }
		public void BindPopupover(List<iProPQRSPortableLib.Type> items,List<int> Selecteditems,UILabel lblField,int FrameY,string labelName)
		{
			int uvwidth;
			ATlist.Clear();
			items.Sort((xx,yy)=> xx.Label.CompareTo(yy.Label));
			List<CodePickerModel> alist = SetTypeDataSource(items, out  uvwidth);
			mcp = new mCodePicker(this,uvwidth,alist);
			// need to set Selected Items
			if (Selecteditems != null && Selecteditems.Count > 0) {
				CodePickerModel sitem;	
				foreach (var item in Selecteditems) {
					sitem = new CodePickerModel ();
					sitem.ItemText = iProPQRSPortableLib.Consts.ProcAttribTypes.result.Types.Where(u=>u.ProcAttribTypeID==item).Select(s=>s.Label).Single();
					sitem.ItemID = item;
					ATlist.Add (sitem);
				}
			}

			if (ATlist.Count > 0)
				mcp.SelectedItems = ATlist;
			//

			float x = (float)lblField.Frame.X;
			float y = (float)lblField.Frame.Y+FrameY;

			mcp.PresentFromPopover(lblField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				int ProcID=0;
				if(procedureDetails != null && procedureDetails.ID != 0)
					ProcID = procedureDetails.ID;
				
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					string finalText = string.Empty;
					List<AttribType>  procalist=new List<AttribType>();
					AttribType procitem; 


					foreach (var item in ATlist){					
						procitem=new AttribType();
						procitem.ProcAttribTypeID=item.ItemID;
						procitem.ProcID=ProcID;
						procitem.Value = "1";
						procitem.IsHighLighted=false;
						procalist.Add(procitem);
						procitem=null;
						finalText = finalText + "," + item.ItemText;
					}
					//				SetTextboxValue(mCurrentTextBoxID, finalText.TrimStart(','));
					lblField.Text = finalText.TrimStart(',');
					int mw=MeasureTextLine(finalText);
					int maxheight=30;
					if(mw>500)
					{
						maxheight=60;
						lblField.Lines=2;
					}
					else if(mw> 1000)
					{
						maxheight=90;
						lblField.Lines=2;
					}
					CoreGraphics.CGRect fram=lblField.Frame;
					fram.Height=maxheight;
					lblField.Frame=fram;
					foreach (var sitem in Selecteditems) {
						int spid = ATlist.Where(w=>w.ItemID == sitem).Select(s=>s.ItemID).SingleOrDefault();
						if(spid==0)
						{
							procitem=new AttribType();
							procitem.ProcAttribTypeID=sitem;
							procitem.ProcID=ProcID;
							procitem.Value="";
							procitem.IsHighLighted=false;
							procalist.Add(procitem);
							procitem=null;
						}
					}

					if(procalist != null && procalist.Count > 0 ){
						var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
						if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK")
						{
							Console.WriteLine("Procedure Info. Successfully Saved.");	
	//						new UIAlertView("Procedure Info", "Successfully Saved.", null, "ok", null).Show();
						}else{
							NavigationController.PopToRootViewController(true);
							Console.WriteLine("Procedure Info. Save failed.");	
	//						new UIAlertView("Error", procAttribtsobject.message, null, "ok", null).Show();
						}
					}

					if(labelName=="AnesthesiaTechs"){
						selectedAnesTechTypesIds.Clear();
						foreach (var item in ATlist) {
							selectedAnesTechTypesIds.Add(item.ItemID);
						}
					}else if(labelName=="NerveBlock"){
						selectedNerveBlockIds.Clear();
						foreach (var item in ATlist) {
							selectedNerveBlockIds.Add(item.ItemID);
						}
					}else if(labelName=="SpecialTechs"){
						selectedSpecialTechIds.Clear();
						foreach (var item in ATlist) {
							selectedSpecialTechIds.Add(item.ItemID);
						}
					}

					ATlist.Clear();
				}
				else
				{
					List<AttribType>  procalist=new List<AttribType>();
					AttribType procitem; 

					foreach (var sitem in Selecteditems) {
						int spid = ATlist.Where(w=>w.ItemID == sitem).Select(s=>s.ItemID).SingleOrDefault();
						if(spid==0)
						{
							procitem=new AttribType();
							procitem.ProcAttribTypeID=sitem;
							procitem.ProcID=ProcID;
							procitem.Value="";
							procitem.IsHighLighted=false;
							procalist.Add(procitem);
							procitem=null;
						}
					}

					if(procalist != null && procalist.Count > 0 ){
						var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
						if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK")
						{
							Console.WriteLine("Procedure Info. Successfully Saved.");	
							//						new UIAlertView("Procedure Info", "Successfully Saved.", null, "ok", null).Show();
						}else{
							NavigationController.PopToRootViewController(true);
							Console.WriteLine("Procedure Info. Save failed.");	
							//						new UIAlertView("Error", procAttribtsobject.message, null, "ok", null).Show();
						}
					}
					if(labelName=="SpecialTechs")
						selectedSpecialTechIds.Clear();
					else if(labelName=="SpecialTechs")
						selectedSpecialTechIds.Clear();
					else if(labelName=="NerveBlock")
						selectedNerveBlockIds.Clear();
					
					lblField.Text="";
				}
				UpdateProcedureStatus ();
			};
		}
		public void BindParticipantsPopupover(List<UserDetails> listOfUsers,UIButton btnField,int FrameY,ProcedureParticipantDetails participantDetails)
		{
			
			if(btnField.CurrentTitle != "" && btnField.CurrentTitle != null){
				RemovePreviousParticipant(btnField,participantDetails.RoleID);
			}

			int uvwidth;
			ATlist.Clear();
			List<CodePickerModel> alist = SetParticipantsDataSource(listOfUsers, out  uvwidth);
			mcp = new mCodePicker(this,uvwidth,alist);
			mcp.TypeOfList = "Participants";

			float x = (float)btnField.Frame.X;
			float y = (float)btnField.Frame.Y+FrameY;

			mcp.PresentFromPopover(btnField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				try
				{
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					btnField.SetTitle(" " + ATlist[0].ItemText,UIControlState.Normal);
					participantDetails.UserID = ATlist[0].ItemID;
					ATlist.Clear();
					if(participantDetails.ProcParticipantID == 0)
					{
						participantDetails.ProcParticipantID = 0;
						participantDetails.Name = btnField.CurrentTitle.Trim();
						AddUpdateProcedureParticipants(participantDetails,btnField);
					}
					else
					{
						UpdateProcedureParticipants(participantDetails,btnField);
					}
				}
				}
				catch
				{
					
				}

			};

		}
		public void BindPopupover(List<iProPQRSPortableLib.Option> items,List<Tuple<string,string>> Selecteditems,UILabel lblField,int FrameY,UILabel hidenval)
		{
			int uvwidth;
			ATlist.Clear ();
			List<CodePickerModel> alist = SetTypeDataSource(items, out  uvwidth);

			mcp = new mCodePicker(this,uvwidth);
			mcp.TypeOfList = "Options";

			// need to set Selected Items
			if (Selecteditems != null && Selecteditems.Count > 0) {
				CodePickerModel sitem;	
				if (Selecteditems != null && Selecteditems.Count > 0 && !string.IsNullOrEmpty(Selecteditems[0].Item1)) {
					sitem = new CodePickerModel ();
					sitem = alist.Where (u => u.ItemID == Convert.ToInt16 (Selecteditems[0].Item1) && u.ItemCode == Selecteditems[0].Item2).SingleOrDefault ();
					if(sitem != null)
					  ATlist.Add (sitem);
				}

			}
			if (ATlist.Count > 0)
				mcp.SelectedItems = ATlist;


			float x = (float)lblField.Frame.X;
			float y = (float)lblField.Frame.Y+FrameY;

			mcp.PresentFromPopover(lblField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				List<AttribType>  procalist=new List<AttribType>();
				AttribType procitem; 
				int ProcID=0;
				if(procedureDetails != null && procedureDetails.ID != 0)
					ProcID = procedureDetails.ID;
				
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					string finalText = " ";				

					foreach (var sitem in Selecteditems) {
						if(!string.IsNullOrEmpty(sitem.Item1) && !string.IsNullOrEmpty(sitem.Item2))
						{
							string spid = ATlist.Where( w => w.ItemID == Convert.ToInt16(sitem.Item1) && w.ItemCode == sitem.Item2).Select(s=>s.ItemCode).SingleOrDefault();
							if(spid == null)
							{
								procitem=new AttribType();
								procitem.ProcAttribTypeID = Convert.ToInt16(sitem.Item1);
								procitem.ProcID = ProcID;
								procitem.Value = "";
								procitem.IsHighLighted=false;
								procalist.Add(procitem);
								procitem=null;
							}
						}
					}

					foreach (var item in ATlist)
					{					
						procitem = new AttribType();
						procitem.ProcAttribTypeID = item.ItemID;
						procitem.ProcID = ProcID;
						procitem.Value = item.ItemCode;
						procitem.IsHighLighted = false;
						procalist.Add(procitem);
						procitem = null;
						finalText = finalText + ", " + item.ItemText;
					}
					lblField.Text = finalText.Trim().TrimStart(',');




					if(procalist != null && procalist.Count > 0 ){
						var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
						if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK"){
							Console.WriteLine("Procedure, Info. Successfully Saved.");	
							//						new UIAlertView("Procedure Info", "Successfully Saved."
							//							, null, "ok", null).Show();
						}else{
							Console.WriteLine("Procedure,  Info. Save failed.");	
							//						new UIAlertView("Error", procAttribtsobject.message
							//							, null, "ok", null).Show();
						}//
					}
					foreach (var item in ATlist) {
						hidenval.Tag=item.ItemID;
						hidenval.Text=item.ItemCode;
					}
					ATlist.Clear();

					int lbldescwidth = 40;
					lblField.Lines = 1;
					int lbltextcount = lblField.Text.Length;
					if (lbltextcount < 58) {
						lbldescwidth = 40;
						lblField.Lines = 1;
					} else if (lbltextcount > 58 && lbltextcount < 114) {
						lbldescwidth = 55;
						lblField.Lines = 2;
					} else if (lbltextcount > 114) {
						lbldescwidth = 75;
						lblField.Lines = 3;
					}

					lblField.Frame = new CoreGraphics.CGRect (500, 8, 480, lbldescwidth);

				}

			};
		}
		public void BindPopupover(List<iProPQRSPortableLib.Option> items,List<string> Selecteditems,UILabel lblField,int FrameY,string labelName)
		{
			int uvwidth;
			ATlist.Clear ();
			List<CodePickerModel> alist = SetTypeDataSource(items, out  uvwidth);

			mcp = new mCodePicker(this,uvwidth);
			mcp.TypeOfList = "Options";

			// need to set Selected Items
			if (Selecteditems != null && Selecteditems.Count > 0) {
				CodePickerModel sitem;	
				foreach (var item in Selecteditems) {
					if (item != "selected") {
						sitem = new CodePickerModel ();
						sitem.ItemText = alist.Where (u => u.ItemCode == item).Select (s => s.ItemText).Single ();
						sitem.ItemID = items [0].ProcAttribTypeID; //For all Options, the ProcTypeID will be same
						sitem.ItemCode = item;
						ATlist.Add (sitem);
					}
				}
			}
			if (ATlist.Count > 0)
				mcp.SelectedItems = ATlist;
			

			float x = (float)lblField.Frame.X;
			float y = (float)lblField.Frame.Y+FrameY;

			mcp.PresentFromPopover(lblField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				int ProcID=0;
				if(procedureDetails != null && procedureDetails.ID != 0)
					ProcID = procedureDetails.ID;
				
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					string finalText = " ";

					List<AttribType>  procalist=new List<AttribType>();
					AttribType procitem; 


					foreach (var item in ATlist)
					{					
						procitem = new AttribType();
						procitem.ProcAttribTypeID = item.ItemID;
						procitem.ProcID = ProcID;
						procitem.Value = item.ItemCode;
						procitem.IsHighLighted = false;
						procalist.Add(procitem);
						procitem = null;
						finalText = finalText + ", " + item.ItemText;
					}
					lblField.Text = finalText.Trim().TrimStart(',');

					foreach (var sitem in Selecteditems) {
						string spid = ATlist.Where(w=>w.ItemCode == sitem).Select(s=>s.ItemCode).SingleOrDefault();
						if(spid == null)
						{
							procitem=new AttribType();
							procitem.ProcAttribTypeID = items[0].ProcAttribTypeID;
							procitem.ProcID = ProcID;
							procitem.Value = "";
							procitem.IsHighLighted=false;
							procalist.Add(procitem);
							procitem=null;
						}
					}


					if(procalist != null && procalist.Count > 0 ){
						var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
						if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK"){
							Console.WriteLine("Procedure, " +labelName + " Info. Successfully Saved.");	
	//						new UIAlertView("Procedure Info", "Successfully Saved."
	//							, null, "ok", null).Show();
						}else{
							Console.WriteLine("Procedure, " +labelName + " Info. Save failed.");	
	//						new UIAlertView("Error", procAttribtsobject.message
	//							, null, "ok", null).Show();
						}
					}
		
					if(labelName == "CVCSterileTech"){
						selectedLineCVCSterileTechIds.Clear();
						foreach (var item in ATlist) {
							selectedLineCVCSterileTechIds.Add(item.ItemCode);
						}
					}
					ATlist.Clear();
				}
				else
				{
					List<AttribType>  procalist=new List<AttribType>();
					AttribType procitem; 

					foreach (var sitem in Selecteditems) {
						string spid = ATlist.Where(w=>w.ItemCode == sitem).Select(s=>s.ItemCode).SingleOrDefault();
						if(spid == null)
						{
							procitem=new AttribType();
							procitem.ProcAttribTypeID = items[0].ProcAttribTypeID;
							procitem.ProcID = ProcID;
							procitem.Value = "";
							procitem.IsHighLighted=false;
							procalist.Add(procitem);
							procitem=null;
						}
					}

					if(procalist != null && procalist.Count > 0 ){
						var procAttribtsobject  = await AppDelegate.Current.pqrsMgr.UpdateProcAttribs(procalist);
						if(procAttribtsobject != null && procAttribtsobject.status != null && procAttribtsobject.status.ToUpper() == "OK"){
							Console.WriteLine("Procedure, " +labelName + " Info. Successfully Saved.");	
							//						new UIAlertView("Procedure Info", "Successfully Saved."
							//							, null, "ok", null).Show();
						}else{
							Console.WriteLine("Procedure, " +labelName + " Info. Save failed.");	
							//						new UIAlertView("Error", procAttribtsobject.message
							//							, null, "ok", null).Show();
						}
					}
					if(labelName == "CVCSterileTech"){
						selectedLineCVCSterileTechIds.Clear();

					}
					lblField.Text="";
				}
			};
		}
		private void BindAnesthesiaTechniques(string[] anesTechItems)
		{
			int uvwidth;
			List<CodePickerModel> alist=mSetDataSource(anesTechItems, out  uvwidth);
			mcp = new mCodePicker(this,uvwidth);
			// need to set Selected Items
			if (ATlist.Count > 0)
				mcp.SelectedItems = ATlist;
			//

			float x = (float)txtAnesthesiaTechs.Frame.X;
			float y = (float)txtAnesthesiaTechs.Frame.Y;

			mcp.PresentFromPopover(txtAnesthesiaTechs, 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(','));
				txtAnesthesiaTechs.Text = finalText.TrimStart(',');
			};
		}
		public void BindSurgeonPopupover(List<SurgeonDetails> listOfSurgeons,UILabel lblField,int FrameY)
		{
			int uvwidth;
			ATlist.Clear();
			List<CodePickerModel> alist = SetSurgeonDataSource(listOfSurgeons, out  uvwidth);
			mcp = new mCodePicker(this,uvwidth);
			mcp.TypeOfList = "Surgeons";

			float x = (float)lblField.Frame.X;
			float y = (float)lblField.Frame.Y + FrameY;

			mcp.PresentFromPopover(lblField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					lblField.Text =  " " + ATlist[0].ItemText;

					ProcedureSurgeonDetails procSurgeon = new ProcedureSurgeonDetails();
					procSurgeon.Name = lblField.Text;
					procSurgeon.SurgeonID = ATlist[0].ItemID;
					procSurgeon.ProcID = procedureDetails.ID;
					if(selectedSurgeon.Count >0)
						procSurgeon.ProcSurgeonID = selectedSurgeon[0].ProcSurgeonID;
					else
						procSurgeon.ProcSurgeonID = 0;
					AddUpdateProcedureSurgeon(procSurgeon);
					ATlist.Clear();
				}
			};
		}
		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.
		}