public PatientDetail GetPatientDetail(string patientNumber, string consentFormType, string location)
        {
            //PatientDetail patientDetail = null;
            //System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            //var conStr = config.AppSettings.Settings["DBConnection"].Value;
            //using (var sqlConnection = new SqlConnection(conStr))
            //{
            //    using (var sqlDataAdapter = new SqlDataAdapter("select * from Patient where PatientId=" + patientNumber, sqlConnection))
            //    {
            //        var dataset = new DataSet();
            //        sqlDataAdapter.Fill(dataset);
            //        if (dataset.Tables.Count > 0)
            //        {
            //            if (dataset.Tables[0].Rows.Count > 0)
            //            {
            //                DataRow record = dataset.Tables[0].Rows[0];
            //                patientDetail = new PatientDetail
            //                                    {
            //                                        name = record["FullName"].ToString(),
            //                                        age = Convert.ToInt16(record["Age"]),
            //                                        gender = record["Gender"].ToString(),
            //                                        MRHash = record["MR#"].ToString(),
            //                                        AttnDr = "Mr. Mathew Thomas",
            //                                        AdmDate = Convert.ToDateTime(record["AdmDate"]),
            //                                        DOB = Convert.ToDateTime(record["BirthDate"]),
            //                                        PatientHash = record["Patient#"].ToString()
            //                                    };
            //                try
            //                {
            //                    patientDetail.PrimaryDoctorId = record["PrimaryDoctor"].ToString();
            //                }
            //                catch (Exception)
            //                {
            //                    patientDetail.PrimaryDoctorId = string.Empty;
            //                }
            //                try
            //                {
            //                    patientDetail.AssociatedDoctorId = record["AssociatedDoctor"].ToString();
            //                }
            //                catch (Exception)
            //                {
            //                    patientDetail.AssociatedDoctorId = string.Empty;
            //                }
            //            }
            //        }
            //    }
            //}
            //return patientDetail;

            PatientDetail patientDetail = null;
            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            var conStr = config.AppSettings.Settings["BethesdaDBConnection"].Value;
            using (var sqlConnection = new SqlConnection(conStr))
            {
                using (var sqlDataAdapter = new SqlDataAdapter("BMH_Consent_GetCurrentCensus", sqlConnection))
                {
                    sqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                    sqlDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@Entity", SqlDbType.NVarChar)).Value = location;
                    sqlDataAdapter.SelectCommand.CommandTimeout = 0;

                    var dataset = new DataSet();
                    sqlDataAdapter.Fill(dataset);
                    if (dataset.Tables.Count > 0)
                    {
                        if (dataset.Tables[0].Rows.Count > 0)
                        {
                            DataRow record = dataset.Tables[0].Rows.Cast<DataRow>().FirstOrDefault(row => row["PatientAccountID"].ToString() == patientNumber);
                            if (record != null)
                            {
                                patientDetail = new PatientDetail
                                                    {
                                                        name = record["FullName"].ToString(),
                                                        age = record["Age"].ToString(),
                                                        gender = record["Sex"].ToString(),
                                                        MRHash = record["MRN"].ToString(),
                                                        AttnDr = record["AttPhysicianName"].ToString(),
                                                        AdmDate = Convert.ToDateTime(record["VisitStartDateTime"]),
                                                        DOB = Convert.ToDateTime(record["BirthDate"]),
                                                        PatientHash = record["PatientAccountID"].ToString()
                                                    };
                                try
                                {
                                    patientDetail.PrimaryDoctorId = record["PrimaryDoctor"].ToString();
                                }
                                catch (Exception)
                                {
                                    patientDetail.PrimaryDoctorId = string.Empty;
                                }
                                try
                                {
                                    patientDetail.AssociatedDoctorId = record["AssociatedDoctor"].ToString();
                                }
                                catch (Exception)
                                {
                                    patientDetail.AssociatedDoctorId = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            return patientDetail;
        }
 public PatientDetail GetPatientDetail(string patientNumber, string ConsentFormType)
 {
     PatientDetail patientDetail = null;
     using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ToString()))
     {
         using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from Patient where PatientId=" + patientNumber, sqlConnection))
         {
             DataSet dataset = new DataSet();
             sqlDataAdapter.Fill(dataset);
             if (dataset.Tables.Count > 0)
             {
                 if (dataset.Tables[0].Rows.Count > 0)
                 {
                     DataRow record = dataset.Tables[0].Rows[0];
                     patientDetail = new PatientDetail();
                     patientDetail.name = record["FullName"].ToString();
                     patientDetail.age = Convert.ToInt16(record["Age"]);
                     patientDetail.gender = record["Gender"].ToString();
                     patientDetail.MRHash = record["MR#"].ToString();
                     patientDetail.AttnDr = "Mr. Mathew Thomas";
                     patientDetail.AdmDate = DateTime.Now.AddDays(-2);
                     patientDetail.DOB = Convert.ToDateTime(record["BirthDate"]);
                     try
                     {
                         patientDetail.PrimaryDoctorId = record["PrimaryDoctor"].ToString();
                     }
                     catch (Exception)
                     {
                         patientDetail.PrimaryDoctorId = string.Empty;
                     }
                     try
                     {
                         patientDetail.AssociatedDoctorId = record["AssociatedDoctor"].ToString();
                     }
                     catch (Exception)
                     {
                         patientDetail.AssociatedDoctorId = string.Empty;
                     }
                     using (SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from Treatments where PatientID='" + patientNumber + "' AND ConsentFormType='" + ConsentFormType + "'", sqlConnection))
                     {
                         dataset = new DataSet();
                         sqlDataAdapter2.Fill(dataset);
                         if (dataset.Tables.Count > 0)
                         {
                             if (dataset.Tables[0].Rows.Count > 0)
                             {
                                 if (dataset.Tables[0].Rows[0]["Procedures"] != null)
                                     patientDetail.ProcedureName = dataset.Tables[0].Rows[0]["Procedures"].ToString();
                                 if (dataset.Tables[0].Rows[0]["UnableToSignReason"] != null)
                                     patientDetail.UnableToSignReason = dataset.Tables[0].Rows[0]["UnableToSignReason"].ToString();
                                 if (dataset.Tables[0].Rows[0]["Translatedby"] != null)
                                     patientDetail.Translatedby = dataset.Tables[0].Rows[0]["Translatedby"].ToString();
                                 patientDetail.StatementOfConsent = null;
                                 if (dataset.Tables[0].Rows[0]["StatementType"] != null && !string.IsNullOrEmpty(dataset.Tables[0].Rows[0]["StatementType"].ToString()))
                                 {
                                     patientDetail.StatementOfConsent = new StatementOfConsent();
                                     using (SqlDataAdapter sqlDataAdapterSC = new SqlDataAdapter("select * from StatementOfConsent where Id=" + dataset.Tables[0].Rows[0]["StatementType"], sqlConnection))
                                     {
                                         DataSet datasetSC = new DataSet();
                                         sqlDataAdapterSC.Fill(datasetSC);
                                         if (datasetSC.Tables.Count > 0)
                                         {
                                             if (datasetSC.Tables[0].Rows.Count > 0)
                                             {
                                                 if (datasetSC.Tables[0].Rows[0]["AutologousUnits"] != null && datasetSC.Tables[0].Rows[0]["AutologousUnits"].ToString() == "1")
                                                     patientDetail.StatementOfConsent.AutologousUnits = true;
                                                 if (datasetSC.Tables[0].Rows[0]["DirectedUnits"] != null && datasetSC.Tables[0].Rows[0]["DirectedUnits"].ToString() == "1")
                                                     patientDetail.StatementOfConsent.DirectedUnits = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return patientDetail;
 }