public static PatientTreatmentDeseaseList GetAllTreatmentDeseasest(string identification)
        {
            List <PatientTreatmentDeseaseModel> treatments = new List <PatientTreatmentDeseaseModel>();

            using (MySqlConnection conn = ConecctionModel.conn)
            {
                conn.Open();
                string       SP  = AppManagement.SP_GetAllTreatmentDeseases;
                MySqlCommand cmd = new MySqlCommand(SP, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@identification", identification);


                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    PatientTreatmentDeseaseModel treatment = new PatientTreatmentDeseaseModel();
                    treatment.Identification = rdr["id_patient"].ToString();
                    treatment.Type           = Convert.ToInt32(rdr["type"]);
                    treatment.Description    = rdr["description"].ToString();

                    treatments.Add(treatment);
                }

                rdr.Close();

                return(new PatientTreatmentDeseaseList {
                    IsSuccessful = true, ResponseMessage = AppManagement.MSG_GetAllTreatments_Success, PatientTreatmentDeseases = treatments
                });
            }
        }
Beispiel #2
0
        public static ResponsePatient GetPatient(string identification)
        {
            PatientModel patient = null;

            using (MySqlConnection conn = ConecctionModel.conn)
            {
                conn.Open();
                string       SP  = AppManagement.SP_GetPatient;
                MySqlCommand cmd = new MySqlCommand(SP, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@p_id_patient", identification);

                using (MySqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        patient = new PatientModel()
                        {
                            Identification = rdr["id_patient"].ToString(),
                            IdParent       = rdr["id_parent"].ToString(),
                            Name           = rdr["name"].ToString(),
                            BirthDate      = Convert.ToDateTime(rdr["birth_date"]),
                            Age            = Convert.ToInt32(rdr["age"]),
                            Ethnic         = new EthnicModel()
                            {
                                Id   = Convert.ToInt32(rdr["id_ethnic_group"]),
                                Name = rdr["ethnic_name"].ToString()
                            },
                            Gender = rdr["gender"].ToString()
                        };
                    }
                }
            }

            if (patient.IsNotNull())
            {
                patient.Treatments = PatientTreatmentDeseaseModel.GetAllTreatmentDeseasest(patient.Identification).PatientTreatmentDeseases;


                patient.Attachments = AttachmentsModel.GetAllAttachments(patient.Identification).ResponseAttachments;

                patient.Cases = PatientCaseModel.GetAllPatientCases(patient.Identification).PatientCases;
            }

            return(new ResponsePatient {
                IsSuccessful = true, ResponseMessage = AppManagement.MSG_GetPatient_Success, Patient = patient
            });
        }
        public static Response SaveTreatmentDeseases(PatientTreatmentDeseaseModel patienttreatmentdesease, MySqlConnection conn = null)
        {
            if (conn != null)
            {
                conn = ConecctionModel.conn;

                string       SP  = AppManagement.SP_InsertPatientsTreatmentDeseases;
                MySqlCommand cmd = new MySqlCommand(SP, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@identification", patienttreatmentdesease.Identification);
                cmd.Parameters.AddWithValue("@type", patienttreatmentdesease.Type);
                cmd.Parameters.AddWithValue("@Description", patienttreatmentdesease.Description);

                MySqlDataReader rdr = cmd.ExecuteReader();

                rdr.Close();

                if (rdr.RecordsAffected != 0)
                {
                    return new Response {
                               IsSuccessful = true, ResponseMessage = AppManagement.MSG_SaveTreatment_Success
                    }
                }
                ;

                return(new Response {
                    IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Failure
                });
            }
            else
            {
                using (conn = ConecctionModel.conn)
                {
                    conn.Open();

                    string       SP  = AppManagement.SP_InsertPatientsTreatmentDeseases;
                    MySqlCommand cmd = new MySqlCommand(SP, conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@identification", patienttreatmentdesease.Identification);
                    cmd.Parameters.AddWithValue("@type", patienttreatmentdesease.Type);
                    cmd.Parameters.AddWithValue("@Description", patienttreatmentdesease.Description);

                    MySqlDataReader rdr = cmd.ExecuteReader();

                    rdr.Close();

                    if (rdr.RecordsAffected != 0)
                    {
                        return new Response {
                                   IsSuccessful = true, ResponseMessage = AppManagement.MSG_SaveTreatment_Success
                        }
                    }
                    ;

                    return(new Response {
                        IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Failure
                    });
                }
            }
        }
Beispiel #4
0
        public static Response SavePatient(PatientModel patient)
        {
            ResponsePatients patients = PatientModel.GetAll(patient.IdParent);

            if (patients.IsSuccessful)
            {
                if ((patients.IsNotNull() && patients.Patients.Count < 5) || patients.IsNull())
                {
                    MySqlTransaction tr = null;
                    try
                    {
                        int rowAffected = 0;
                        using (MySqlConnection conn = ConecctionModel.conn)
                        {
                            conn.Open();

                            tr = conn.BeginTransaction();

                            string       SP  = AppManagement.SP_InsertPatients;
                            MySqlCommand cmd = new MySqlCommand(SP, conn);
                            cmd.CommandType = CommandType.StoredProcedure;

                            cmd.Parameters.AddWithValue("@id_patient", patient.Identification);
                            cmd.Parameters.AddWithValue("@id_parent", patient.IdParent);
                            cmd.Parameters.AddWithValue("@name", patient.Name);
                            cmd.Parameters.AddWithValue("@birth_date", patient.BirthDate);
                            cmd.Parameters.AddWithValue("@age", patient.Age);
                            cmd.Parameters.AddWithValue("@gender", patient.Gender);
                            cmd.Parameters.AddWithValue("@id_ethnic_group", patient.Ethnic.Id);

                            rowAffected = cmd.ExecuteNonQuery();

                            if (rowAffected != 0)
                            {
                                if (patient.Treatments.IsNotNull())
                                {
                                    foreach (var treatment in patient.Treatments)
                                    {
                                        if (!PatientTreatmentDeseaseModel.SaveTreatmentDeseases(treatment, conn).IsSuccessful)
                                        {
                                            tr.Rollback();
                                            return(new Response {
                                                IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Failure
                                            });
                                        }
                                    }
                                }
                                tr.Commit();
                                return(new Response {
                                    IsSuccessful = true, ResponseMessage = AppManagement.MSG_SaveTreatment_Success
                                });
                            }
                            else
                            {
                                tr.Rollback();
                                return(new Response {
                                    IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Failure
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        tr.Rollback();

                        if (ex.ToString().Contains("PRIMARY"))
                        {
                            return(new Response {
                                IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Duplicate
                            });
                        }
                        else
                        {
                            return(new Response {
                                IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_Failure
                            });
                        }
                    }
                }
                else
                {
                    return(new Response {
                        IsSuccessful = false, ResponseMessage = AppManagement.MSG_SaveTreatment_MaxPatients
                    });
                }
            }
            else
            {
                return(new Response {
                    IsSuccessful = false, ResponseMessage = patients.ResponseMessage
                });
            }
        }