public ServiceResponse <bool> Create(PatientTests patient, int appointmentId)
        {
            var now         = DateTime.UtcNow;
            var appointment = _db.Appointment.Find(appointmentId);

            if (appointment != null)
            {
                try
                {
                    var tests = new PatientTests
                    {
                        IsBloodPressure     = patient.IsBloodPressure,
                        IsCancer            = patient.IsCancer,
                        IsHIV               = patient.IsHIV,
                        Prescription        = patient.Prescription,
                        IsSugarDiabetes     = patient.IsSugarDiabetes,
                        NextAppointmentDate = patient.NextAppointmentDate,
                        CreatedOn           = now,
                        UpdatedOn           = now,
                        AppointmentId       = appointment.Id
                    };

                    _db.PatientTests.Add(tests);
                    _db.SaveChanges();

                    return(new ServiceResponse <bool>
                    {
                        IsSuccess = true,
                        Message = "Success!",
                        Time = now,
                        Data = true
                    });
                }
                catch (Exception e)
                {
                    return(new ServiceResponse <bool>
                    {
                        IsSuccess = false,
                        Message = e.StackTrace,
                        Time = now,
                        Data = false
                    });
                }
            }
            else
            {
                return(new ServiceResponse <bool>
                {
                    Data = false,
                    Message = "Could not find Appointment with that Id",
                    IsSuccess = false,
                    Time = now
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete a patient from the system using patientId
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServiceResponse <bool> DeletePatient(int id)
        {
            var now = DateTime.UtcNow;

            try
            {
                var patient = _db.Patients.Find(id);

                if (patient == null)
                {
                    return(new ServiceResponse <bool>
                    {
                        Message = $"Could not find a patient with this Id {id}!",
                        Time = now,
                        IsSuccess = false,
                        Data = false
                    });
                }

                _db.Patients.Remove(patient);
                _db.SaveChanges();

                return(new ServiceResponse <bool>
                {
                    Message = $"Patient with Id {id} has been removed successfully!",
                    Time = now,
                    IsSuccess = true,
                    Data = true
                });
            }
            catch (Exception e)
            {
                return(new ServiceResponse <bool>
                {
                    Message = e.StackTrace,
                    Time = now,
                    IsSuccess = false,
                    Data = false
                });
            }
        }