Exemplo n.º 1
0
        private List <Entities.Patient> GetPatients(IDataReader reader)
        {
            var patients = new List <Entities.Patient>();

            while (reader.Read())
            {
                PatientPersonalHistory patientPersonalHistory = new PatientPersonalHistory();
                PatientExerciseHistory patientExerciseHistory = new PatientExerciseHistory();

                var patient = new Entities.Patient
                {
                    PatientId                = DRE.GetNullableInt32(reader, "patient_id", 0),
                    PatientCode              = DRE.GetNullableInt32(reader, "patient_code", null),
                    Title                    = DRE.GetNullableString(reader, "title", null),
                    FirstName                = DRE.GetNullableString(reader, "first_name", null),
                    MiddleName               = DRE.GetNullableString(reader, "middle_name", null),
                    LastName                 = DRE.GetNullableString(reader, "last_name", null),
                    FullName                 = DRE.GetNullableString(reader, "full_name", null),
                    Address                  = DRE.GetNullableString(reader, "address", null),
                    Gender                   = DRE.GetNullableString(reader, "gender", null),
                    DateOfBirth              = DRE.GetNullableString(reader, "date_of_birth", null),
                    ContactNos               = DRE.GetNullableString(reader, "contact_nos", null),
                    ContactNo1               = DRE.GetNullableString(reader, "contact_no_1", null),
                    ContactNo2               = DRE.GetNullableString(reader, "contact_no_2", null),
                    MobileNo1                = DRE.GetNullableString(reader, "mobile_no_1", null),
                    MobileNo2                = DRE.GetNullableString(reader, "mobile_no_2", null),
                    EmailId                  = DRE.GetNullableString(reader, "email_id", null),
                    PANNo                    = DRE.GetNullableString(reader, "pan_no", null),
                    Department               = DRE.GetNullableString(reader, "department", null),
                    Designation              = DRE.GetNullableString(reader, "designation", null),
                    EmployerId               = DRE.GetNullableInt32(reader, "employer_id", null),
                    EmployerName             = DRE.GetNullableString(reader, "employer_name", null),
                    PatientPersonalHistory   = patientPersonalHistory.GetPatientPersonalHistoriesByPatientId(DRE.GetInt32(reader, "patient_id")),
                    PatientExerciseHistories = patientExerciseHistory.GetPatientExerciseHistoriesByPatientId(DRE.GetInt32(reader, "patient_id"))
                };

                patients.Add(patient);
            }

            return(patients);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="patient"></param>
        /// <returns></returns>
        public Int32 SavePatient(Entities.Patient patient)
        {
            var patientId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction transaction = conn.BeginTransaction())
                {
                    try
                    {
                        var patientPersonalHistoryId = 0;
                        var patientExerciseHistoryId = 0;

                        if (patient != null)
                        {
                            if (patient.PatientId == null || patient.PatientId == 0)
                            {
                                patientId = AddPatient(patient, transaction);
                            }
                            else if (patient.ModifiedBy != null || patient.ModifiedBy > 0)
                            {
                                patientId = UpdatePatient(patient, transaction);
                            }
                            else if (patient.IsDeleted == true)
                            {
                                var result = DeletePatient(patient, transaction);


                                if (result)
                                {
                                    patientId = (int)patient.PatientId;
                                }
                                else
                                {
                                    patientId = 1;
                                }
                            }

                            if (patientId > 0)
                            {
                                if (patient.PatientPersonalHistory != null)
                                {
                                    PatientPersonalHistory personalHistory = new PatientPersonalHistory();

                                    patient.PatientPersonalHistory.PatientId = patientId;

                                    patientPersonalHistoryId = personalHistory.SavePatientPersonalHistory(patient.PatientPersonalHistory, transaction);

                                    if (patientPersonalHistoryId < 0)
                                    {
                                        patientId = -1;
                                    }
                                }

                                if (patient.PatientExerciseHistories != null)
                                {
                                    if (patient.PatientExerciseHistories.Count > 0)
                                    {
                                        foreach (Entities.PatientExerciseHistory patientExerciseHistory in patient.PatientExerciseHistories)
                                        {
                                            PatientExerciseHistory exerciseHistory = new PatientExerciseHistory();

                                            patientExerciseHistory.PatientId = patientId;

                                            patientExerciseHistoryId = exerciseHistory.SavePatientExerciseHistory(patientExerciseHistory, transaction);

                                            if (patientExerciseHistoryId < 0)
                                            {
                                                patientId = -1;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (patientId > 0)
                        {
                            transaction.Commit();
                        }
                        else
                        {
                            transaction.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        patientId = -1;
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }


            return(patientId);
        }