private void cmdDelete_Click(object sender, EventArgs e)
 {
     if (cmbName.SelectedItem != null)
     {
         ComboBoxItem    item  = (ComboBoxItem)cmbName.SelectedItem;
         DepartmentValue value = (DepartmentValue)item.Value;
         Department      dept  = new Department();
         dept.Id          = Int32.Parse(value.Id);
         dept.Description = value.Description;
         try
         {
             if (MessageBox.Show("Do you really want to delete?", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 if (NpgsqlDatabaseImpl.GetInstance().DeleteObject(dept))
                 {
                     MessageBox.Show("Department deleted!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     cmbName.SelectedItem = null;
                     txtDescription.Text  = null;
                 }
             }
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("constraint"))
             {
                 MessageBox.Show("Can't delete this department. It has doctor/patient records attached ", "Deletion not allowed!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MessageBox.Show("Failed to delete Department: " + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemplo n.º 2
0
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            StringBuilder query = new StringBuilder();

            query.Append("SELECT doctor_id, name, phone, email, qualification, specialization FROM doctor ");
            query.Append(string.Format(" WHERE name ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR phone ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR email ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR qualification ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR specialization ilike '%{0}%'", txtSearch.Text));
            query.Append(" ORDER BY name");
            DbRecord  record = NpgsqlDatabaseImpl.GetInstance().GetData(query.ToString());
            DataTable table  = new DataTable();

            table.Columns.Add("ID");
            table.Columns.Add("Name");
            table.Columns.Add("Qualification");
            table.Columns.Add("Specialization");
            table.Columns.Add("Phone");
            table.Columns.Add("Email");
            foreach (List <object> row in record.Records)
            {
                DataRow dr = table.NewRow();
                dr["ID"]             = row[0].ToString();
                dr["Name"]           = row[1].ToString();
                dr["Phone"]          = row[2].ToString();
                dr["Email"]          = row[3].ToString();
                dr["Qualification"]  = row[4].ToString();
                dr["Specialization"] = row[5].ToString();
                table.Rows.Add(dr);
            }
            dgSearch.DataSource = table;
        }
Exemplo n.º 3
0
 private void frmRegisterPat_Load(object sender, EventArgs e)
 {
     if (_id != null)
     {
         string query = "SELECT id, pat_id, name, address, nic, " +
                        " phone, email, gender, dob " +
                        " FROM  patient WHERE pat_id = '" + _id + "'";
         DbRecord rec = NpgsqlDatabaseImpl.GetInstance().GetData(query);
         if (rec != null && rec.RowCount == 1)
         {
             txtId.Text      = rec.Records[0][1].ToString();
             txtId.Enabled   = false;
             txtName.Text    = rec.Records[0][2].ToString();
             txtAddress.Text = rec.Records[0][3].ToString();
             txtNIC.Text     = rec.Records[0][4].ToString();
             txtPhone.Text   = rec.Records[0][5].ToString();
             txtEmail.Text   = rec.Records[0][6].ToString();
             if (rec.Records[0][7].ToString().Equals("Male"))
             {
                 optMale.Checked = true;
             }
             else
             {
                 optFemale.Checked = true;
             }
             dateDOB.Text = rec.Records[0][8].ToString();
         }
     }
 }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (!this.ValidateData())
            {
                MessageBox.Show("Fill all the fields", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Department department = new Department();

            try
            {
                if (cmbName.SelectedItem == null)
                {
                    department.Name = cmbName.Text;
                    department.Id   = 0;
                }
                else
                {
                    ComboBoxItem item = (ComboBoxItem)cmbName.SelectedItem;
                    department.Name = item.Text;
                    DepartmentValue value = (DepartmentValue)item.Value;
                    department.Id = int.Parse(value.Id);
                }

                department.Description = txtDescription.Text;

                if (NpgsqlDatabaseImpl.GetInstance().AddObject(department))
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Text = department.Name;
                    DepartmentValue value = new DepartmentValue();
                    value.Id          = department.Id.ToString();
                    value.Description = department.Description;
                    item.Value        = value;
                    if (!this.FindDepartment(item))
                    {
                        cmbName.Items.Insert(0, item);
                        cmbName.SelectedIndex = 0;
                    }

                    MessageBox.Show("Department Saved ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Failed to save Department", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save Department: " + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            String docId = "";

            if (lstDoctors.SelectedItem != null)
            {
                docId = ((ComboBoxItem)lstDoctors.SelectedItem).Value.ToString();

                StringBuilder query = new StringBuilder();
                query.Append("SELECT pt.name, dc.name, pv.visit_ref_number, to_char(pv.visit_date,'DD/MM/YYYY'), pv.visit_notes, to_char(pv.followup_date, 'DD/MM/YYYY'), pt.pat_id, pv.visit_cost FROM patient_visit pv, patient pt, doctor dc " +
                             " WHERE pt.id = pv.patient_id" +
                             " AND dc.id = pv.doctor_id AND" +
                             " dc.id = " + docId +
                             " AND to_date(to_char(pv.visit_date,'DD/MM/YYYY'),'DD/MM/YYYY') between to_date('" + dateFrom.Text + "', 'DD/MM/YYYY')" +
                             " AND to_date('" + dateTo.Text + "', 'DD/MM/YYYY')");
                query.Append(" ORDER BY pv.visit_date");
                DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData(query.ToString());
                if (_records != null)
                {
                    _records.Clear();
                }
                else
                {
                    _records = new DataTable();
                    _records.Columns.Add("VisitReferenceNumber");
                    _records.Columns.Add("PatientNumber");
                    _records.Columns.Add("PatientName");
                    _records.Columns.Add("DoctorName");
                    _records.Columns.Add("VisitDate");
                    _records.Columns.Add("Notes");
                    _records.Columns.Add("FollowUpDate");
                    _records.Columns.Add("VisitCost");
                }
                foreach (List <object> row in record.Records)
                {
                    DataRow dr = _records.NewRow();
                    dr["VisitReferenceNumber"] = row[2].ToString();
                    dr["PatientNumber"]        = row[6].ToString();
                    dr["PatientName"]          = row[0].ToString();
                    dr["DoctorName"]           = row[1].ToString();
                    dr["VisitDate"]            = row[3].ToString();
                    dr["Notes"]        = row[4].ToString();
                    dr["FollowUpDate"] = row[5].ToString();
                    dr["VisitCost"]    = row[7].ToString();
                    _records.Rows.Add(dr);
                }
                dgSearch.DataSource = _records;
            }
        }
Exemplo n.º 6
0
        private void frmPatReport_Load(object sender, EventArgs e)
        {
            string query = "SELECT id, name" +
                           " FROM  doctor";
            DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData(query);

            if (record != null)
            {
                foreach (List <object> row in record.Records)
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Text  = row[1].ToString();
                    item.Value = row[0];
                    lstDoctors.Items.Add(item);
                }
            }
        }
Exemplo n.º 7
0
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            StringBuilder query = new StringBuilder();

            query.Append("SELECT pt.name, dc.name, pv.visit_ref_number, to_char(pv.visit_date,'DD/MM/YYYY HH24:MI'), pv.visit_notes, to_char(pv.followup_date, 'DD/MM/YYYY HH24:MI'), pt.pat_id FROM patient_visit pv, patient pt, doctor dc " +
                         " WHERE pt.id = pv.patient_id" +
                         " AND dc.id = pv.doctor_id AND (");
            query.Append(string.Format(" pt.name ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR pt.phone ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR pt.email ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR pt.nic ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR pv.visit_ref_number ilike '%{0}%' ", txtSearch.Text));
            query.Append(string.Format(" OR pt.pat_id ilike '%{0}%' ", txtSearch.Text));
            query.Append(string.Format(" OR dc.name ilike '%{0}%' ", txtSearch.Text));
            query.Append(string.Format(" OR pv.visit_notes ilike '%{0}%' ", txtSearch.Text));
            query.Append(string.Format(" OR to_char(pv.visit_date, 'DD/MM/YYYY') ilike '%{0}%' ", txtSearch.Text));
            query.Append(string.Format(" OR to_char(pv.followup_date,'DD/MM/YYYY') ilike '%{0}%' )", txtSearch.Text));
            query.Append(" ORDER BY pv.visit_date");
            DbRecord  record = NpgsqlDatabaseImpl.GetInstance().GetData(query.ToString());
            DataTable table  = new DataTable();

            table.Columns.Add("VisitReferenceNumber");
            table.Columns.Add("PatientNumber");
            table.Columns.Add("PatientName");
            table.Columns.Add("DoctorName");
            table.Columns.Add("VisitDate");
            table.Columns.Add("Notes");
            table.Columns.Add("FollowUpDate");

            foreach (List <object> row in record.Records)
            {
                DataRow dr = table.NewRow();
                dr["VisitReferenceNumber"] = row[2].ToString();
                dr["PatientNumber"]        = row[6].ToString();
                dr["PatientName"]          = row[0].ToString();
                dr["DoctorName"]           = row[1].ToString();
                dr["VisitDate"]            = row[3].ToString();
                dr["Notes"]        = row[4].ToString();
                dr["FollowUpDate"] = row[5].ToString();
                table.Rows.Add(dr);
            }
            dgSearch.DataSource = table;
        }
        private void frmRegisterDept_Load(object sender, EventArgs e)
        {
            DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name, description FROM  department ORDER BY name");

            foreach (List <object> row in record.Records)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Text = row[1].ToString();
                DepartmentValue value = new DepartmentValue();
                value.Id          = row[0].ToString();
                value.Description = row[2].ToString();
                item.Value        = value;
                cmbName.Items.Add(item);
            }
            if (cmbName.Items != null && cmbName.Items.Count > 0)
            {
                cmbName.SelectedIndex = 0;
            }
        }
Exemplo n.º 9
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            PatientVisit visit = new PatientVisit();

            visit.DoctorId       = Int32.Parse(((ComboBoxItem)cmbDoctor.SelectedItem).Value.ToString());
            visit.PatientId      = Int32.Parse(((ComboBoxItem)cmbPatient.SelectedItem).Value.ToString());
            visit.Followup       = chkFollowup.Checked;
            visit.FollowupDate   = dateFollowup.Value;
            visit.FollowupReason = txtReason.Text;
            visit.VisitDate      = dateVisit.Value;
            visit.Notes          = txtVisitNotes.Text;
            visit.VisitCost      = Int32.Parse(visitCost.Value.ToString());
            if (this.txtVisitRefNumber.Text == null ||
                this.txtVisitRefNumber.Text.Length < 10)
            {
                visit.VisitRefNumber = Utils.RandomString(10);
            }
            else
            {
                visit.VisitRefNumber = txtVisitRefNumber.Text;
            }

            try
            {
                if (NpgsqlDatabaseImpl.GetInstance().AddObject(visit))
                {
                    this.txtVisitRefNumber.Text    = visit.VisitRefNumber;
                    this.txtVisitRefNumber.Enabled = false;
                    MessageBox.Show("Patient Visit Saved ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmdPrint.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Failed to save Patient Visit", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save Patient Visit", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 10
0
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            StringBuilder query = new StringBuilder();

            query.Append("SELECT pat_id, name, address, phone, email, nic, gender FROM patient ");
            query.Append(string.Format(" WHERE name ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR phone ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR pat_id ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR email ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR nic ilike '%{0}%'", txtSearch.Text));
            query.Append(string.Format(" OR address ilike '%{0}%'", txtSearch.Text));
            query.Append(" ORDER BY name");
            DbRecord  record = NpgsqlDatabaseImpl.GetInstance().GetData(query.ToString());
            DataTable table  = new DataTable();

            table.Columns.Add("PatientNumber");
            table.Columns.Add("Name");
            table.Columns.Add("Address");
            table.Columns.Add("Phone");
            table.Columns.Add("Email");
            table.Columns.Add("NIC");
            table.Columns.Add("Gender");
            foreach (List <object> row in record.Records)
            {
                DataRow dr = table.NewRow();
                dr["PatientNumber"] = row[0].ToString();
                dr["Name"]          = row[1].ToString();
                dr["Address"]       = row[2].ToString();
                dr["Phone"]         = row[3].ToString();
                dr["Email"]         = row[4].ToString();
                dr["NIC"]           = row[5].ToString();
                dr["Gender"]        = row[6].ToString();
                table.Rows.Add(dr);
            }
            dgSearch.DataSource = table;
        }
Exemplo n.º 11
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (!ValidateData())
            {
                MessageBox.Show("Fill all the fields", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!validateEmail())
            {
                MessageBox.Show("Email address is invalid.", "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Utils.isValidNIC(txtNIC.Text))
            {
                MessageBox.Show("NIC is invalid.", "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Utils.isValidPhone(txtPhone.Text))
            {
                MessageBox.Show("Phone number is invalid.", "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            Patient patient = new Patient();

            patient.Name        = txtName.Text;
            patient.Nic         = txtNIC.Text;
            patient.Phone       = txtPhone.Text;
            patient.Email       = txtEmail.Text;
            patient.DateOfBirth = dateDOB.Value;
            if (this.txtId.Text == null ||
                this.txtId.Text.Length < 10)
            {
                patient.PatientId = Utils.RandomString(10);
            }
            else
            {
                patient.PatientId = txtId.Text;
            }

            if (optFemale.Checked)
            {
                patient.Gender = "Female";
            }
            else
            {
                patient.Gender = "Male";
            }
            patient.Address = txtAddress.Text;
            try
            {
                if (NpgsqlDatabaseImpl.GetInstance().AddObject(patient))
                {
                    this.txtId.Text    = patient.PatientId;
                    this.txtId.Enabled = false;
                    MessageBox.Show("Patient Saved ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmdPrint.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Failed to save patient", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save patient", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 12
0
        private void frmPatVisits_Load(object sender, EventArgs e)
        {
            txtVisitRefNumber.Enabled = false;

            DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name FROM  doctor ORDER BY 2");

            foreach (List <object> row in record.Records)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Text  = row[1].ToString();
                item.Value = row[0];
                cmbDoctor.Items.Add(item);
            }
            if (cmbDoctor.Items != null && cmbDoctor.Items.Count > 0)
            {
                cmbDoctor.SelectedIndex = 0;
            }

            record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name, pat_id FROM  patient ORDER BY 2");
            foreach (List <object> row in record.Records)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Text  = string.Format("{0} - ( {1} )", row[1].ToString(), row[2].ToString());
                item.Value = row[0];
                cmbPatient.Items.Add(item);
            }
            if (cmbPatient.Items != null && cmbPatient.Items.Count > 0)
            {
                cmbPatient.SelectedIndex = 0;
            }

            if (_id != null)
            {
                string query = "SELECT pv.visit_ref_number, pat.name, doc.name, pv.visit_date, " +
                               "pv.visit_notes, pv.followup, pv.followup_date, pv.followup_reason, pv.visit_cost" +
                               " FROM public.patient_visit pv, patient pat, doctor doc " +
                               " WHERE pv.doctor_id =  doc.id" +
                               " AND pv.patient_id = pat.id" +
                               " AND pv.visit_ref_number = '" + _id + "'";

                DbRecord rec = NpgsqlDatabaseImpl.GetInstance().GetData(query);
                if (rec != null && rec.RowCount == 1)
                {
                    txtVisitRefNumber.Text = rec.Records[0][0].ToString();
                    int patIndex = cmbPatient.FindString(rec.Records[0][1].ToString());
                    if (patIndex >= 0)
                    {
                        cmbPatient.SelectedItem = cmbPatient.Items[patIndex];
                    }
                    int docIndex = cmbDoctor.FindString(rec.Records[0][2].ToString());
                    if (docIndex >= 0)
                    {
                        cmbDoctor.SelectedItem = cmbDoctor.Items[docIndex];
                    }
                    dateVisit.Text     = rec.Records[0][3].ToString();
                    txtVisitNotes.Text = rec.Records[0][4].ToString();
                    bool isFollowUp = false;
                    if (rec.Records[0][5] != null)
                    {
                        isFollowUp = bool.Parse(rec.Records[0][5].ToString());
                    }
                    if (isFollowUp)
                    {
                        chkFollowup.Checked = true;
                    }
                    else
                    {
                        chkFollowup.Checked = false;
                    }
                    dateFollowup.Text = rec.Records[0][6].ToString();
                    txtReason.Text    = rec.Records[0][7].ToString();
                    visitCost.Value   = Decimal.Parse(rec.Records[0][8].ToString());
                }
            }
        }
Exemplo n.º 13
0
        private void frmRegisterDocs_Load(object sender, EventArgs e)
        {
            string qualification  = "";
            string specialization = "";
            string dept           = "";

            if (_doctorid != null)
            {
                string query = "SELECT id, doctor_id, name, address, " +
                               " qualification, specialization, phone, " +
                               " email, schedule, gender, department_id " +
                               " FROM  doctor WHERE doctor_id = '" + _doctorid + "'";
                DbRecord rec = NpgsqlDatabaseImpl.GetInstance().GetData(query);
                if (rec != null && rec.RowCount == 1)
                {
                    txtId.Text       = rec.Records[0][1].ToString();
                    txtId.Enabled    = false;
                    txtName.Text     = rec.Records[0][2].ToString();
                    txtAddress.Text  = rec.Records[0][3].ToString();
                    qualification    = rec.Records[0][4].ToString();
                    specialization   = rec.Records[0][5].ToString();
                    txtPhone.Text    = rec.Records[0][6].ToString();
                    txtEmail.Text    = rec.Records[0][7].ToString();
                    txtSchedule.Text = rec.Records[0][8].ToString();
                    if (rec.Records[0][9].ToString().Equals("Male"))
                    {
                        optMale.Checked = true;
                    }
                    else
                    {
                        optFemale.Checked = true;
                    }
                    dept = rec.Records[0][9].ToString();
                }
            }

            DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name, description FROM  department ORDER BY name");

            foreach (List <object> row in record.Records)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Text = row[1].ToString();
                DepartmentValue value = new DepartmentValue();
                value.Id          = row[0].ToString();
                value.Description = row[2].ToString();
                item.Value        = value;
                cmbDept.Items.Add(item);
                if (row[0].ToString().Equals(dept))
                {
                    cmbDept.SelectedItem = item;
                }
            }
            if (cmbDept.Items != null &&
                cmbDept.Items.Count > 0 &&
                cmbDept.SelectedItem == null)
            {
                cmbDept.SelectedIndex = 0;
            }

            record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT DISTINCT specialization  FROM  doctor ORDER BY 1");
            foreach (List <object> row in record.Records)
            {
                cmbSpecialization.Items.Add(row[0].ToString());
                if (row[0].ToString().Equals(specialization))
                {
                    cmbSpecialization.SelectedItem = cmbSpecialization.Items[cmbSpecialization.Items.Count - 1];
                }
            }

            if (cmbSpecialization.Items != null &&
                cmbSpecialization.Items.Count > 0 &&
                cmbSpecialization.SelectedItem == null)
            {
                cmbSpecialization.SelectedIndex = 0;
            }

            record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT DISTINCT qualification  FROM  doctor ORDER BY 1");
            foreach (List <object> row in record.Records)
            {
                cmbQualification.Items.Add(row[0].ToString());
                if (row[0].ToString().Equals(qualification))
                {
                    cmbQualification.SelectedItem = cmbQualification.Items[cmbQualification.Items.Count - 1];
                }
            }
            if (cmbQualification.Items != null &&
                cmbQualification.Items.Count > 0 &&
                cmbQualification.SelectedItem == null)
            {
                cmbQualification.SelectedIndex = 0;
            }
        }
Exemplo n.º 14
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (!ValidateData())
            {
                MessageBox.Show("One or more fields are empty.", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!validateEmail())
            {
                MessageBox.Show("Email address is invalid.", "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Utils.isValidPhone(txtPhone.Text))
            {
                MessageBox.Show("Phone number is invalid.", "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            {
                Doctor doctor = new Doctor();
                doctor.Name         = txtName.Text;
                doctor.Address      = txtAddress.Text;
                doctor.DepartmentId = Int32.Parse(((DepartmentValue)((ComboBoxItem)cmbDept.SelectedItem).Value).Id);
                doctor.Phone        = txtPhone.Text;
                doctor.Email        = txtEmail.Text;
                if (cmbQualification.SelectedValue != null)
                {
                    doctor.Qualification = cmbQualification.SelectedValue.ToString();
                }
                else
                {
                    doctor.Qualification = cmbQualification.Text;
                }

                if (cmbSpecialization.SelectedValue != null)
                {
                    doctor.Specialization = cmbSpecialization.SelectedValue.ToString();
                }
                else
                {
                    doctor.Specialization = cmbSpecialization.Text;
                }
                doctor.Schedule = txtSchedule.Text;
                doctor.Gender   = "Male";
                if (optFemale.Checked)
                {
                    doctor.Gender = "Female";
                }
                if (this.txtId.Text == null ||
                    this.txtId.Text.Length < 10)
                {
                    doctor.DoctorId = Utils.RandomString(10);
                }
                else
                {
                    doctor.DoctorId = txtId.Text;
                }

                try
                {
                    if (NpgsqlDatabaseImpl.GetInstance().AddObject(doctor))
                    {
                        this.txtId.Text    = doctor.DoctorId;
                        this.txtId.Enabled = false;
                        MessageBox.Show("Doctor Saved ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Failed to save Doctor", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to save Doctor: " + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }