Esempio n. 1
0
        private void AddPatientRecord()
        {
            if (!VerifyRequiredFields())
            {
                return;
            }

            DateTime         dateOfBirth = (DateTime)DOB;
            SQLiteConnection connection  = OpenConnection("Patients");

            string cmdString = "";

            if (string.IsNullOrWhiteSpace(Middlename))
            {
                cmdString = @"SELECT COUNT(*) FROM PatientData WHERE Firstname = @firstname" +
                            " AND Lastname = @lastname AND DOB = @dob AND Gender = @gender AND ST_Number = @streetNumber AND Postcode = @postcode";
            }
            else
            {
                cmdString = @"SELECT COUNT(*) FROM PatientData WHERE Firstname = @firstname AND Middlename = @middlename " +
                            " AND Lastname = @lastname AND DOB = @dob AND Gender = @gender AND ST_Number = @streetNumber AND Postcode = @postcode";
            }

            SQLiteCommand cmd = new SQLiteCommand(cmdString, connection);

            cmd.Prepare();
            cmd.Parameters.Add("@firstname", DbType.String).Value = Firstname.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            if (!string.IsNullOrWhiteSpace(Middlename))
            {
                cmd.Parameters.Add("@middlename", DbType.String).Value = Middlename.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            }
            cmd.Parameters.Add("@lastname", DbType.String).Value     = Lastname.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            cmd.Parameters.Add("@dob", DbType.String).Value          = dateOfBirth.ToString("dd/MM/yyyy");
            cmd.Parameters.Add("@gender", DbType.String).Value       = Gender;
            cmd.Parameters.Add("@streetNumber", DbType.String).Value = AddressNo;
            cmd.Parameters.Add("@postcode", DbType.String).Value     = Postcode.Replace(" ", "").ToUpper();

            //  Checks if record already exists, if it does a prompt is shown to the user,
            //  user decides if duplicate record is required.
            int recordsFound = Convert.ToInt32(cmd.ExecuteScalar());

            if (recordsFound > 0)
            {
                string createDuplicate = Confirmation("Are you sure?",
                                                      "Patient Record with identical information already exists. Are you sure you want to create another record with this data?");
                if (createDuplicate != "Yes")
                {
                    return;
                }
            }


            // Record added to patient database.

            if (string.IsNullOrWhiteSpace(Middlename))
            {
                cmdString = @"INSERT INTO PatientData (Firstname, Lastname, DOB, Gender, ST_Number, Postcode) 
                            VALUES (@firstname, @lastname, @dob, @gender, @streetNumber, @postcode)";
            }
            else
            {
                cmdString = @"INSERT INTO PatientData (Firstname, Middlename, Lastname, DOB, Gender, ST_Number, Postcode) 
                            VALUES (@firstname, @middlename, @lastname, @dob, @gender, @streetNumber, @postcode)";
            }

            cmd = new SQLiteCommand(cmdString, connection);
            cmd.Prepare();
            cmd.Parameters.Add("@firstname", DbType.String).Value = Firstname.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            if (!string.IsNullOrEmpty(Middlename))
            {
                cmd.Parameters.Add("@middlename", DbType.String).Value = Middlename.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            }
            cmd.Parameters.Add("@lastname", DbType.String).Value     = Lastname.ToLower(new System.Globalization.CultureInfo("en-UK", false));
            cmd.Parameters.Add("@dob", DbType.String).Value          = dateOfBirth.ToString("dd/MM/yyyy");
            cmd.Parameters.Add("@gender", DbType.String).Value       = Gender;
            cmd.Parameters.Add("@streetNumber", DbType.String).Value = AddressNo;
            cmd.Parameters.Add("@postcode", DbType.String).Value     = Postcode.Replace(" ", "").ToUpper();
            cmd.ExecuteNonQuery();

            Success("Success", "Record created. You can now proceed to create an appointment.");
            connection.Close();
        }