コード例 #1
0
        public CommonStatus AddUpdatePatientRxData(int patientID, RxData rxData, int LoggedInuserID)
        {
            CommonStatus cs = new CommonStatus(false);

            try
            {
                using (PatientPortalEntities ent = new PatientPortalEntities())
                {
                    var username = (from u in ent.TB_PortalUser where u.PortalUser_ID == LoggedInuserID select u.UserName).FirstOrDefault();

                    if (rxData.RxData_ID == 0)
                    {
                        TB_RxData r = new TB_RxData();
                        r.RxDate        = rxData.RxDate;
                        r.RxDoctor      = rxData.RxDoctor;
                        r.Prescription1 = rxData.Prescription1;
                        r.Prescription2 = rxData.Prescription2;
                        r.Prescription3 = rxData.Prescription3;
                        r.Prescription4 = rxData.Prescription4;
                        r.Prescription5 = rxData.Prescription5;
                        r.CreateDate    = DateTime.Now;
                        r.CreatedBy     = username;

                        ent.TB_RxData.Add(r);
                        ent.SaveChanges();

                        TB_PatientRxData pr = new TB_PatientRxData();
                        pr.Patient_ID = patientID;
                        pr.RxData_ID  = r.RxData_ID;
                        pr.CreateDate = DateTime.Now;
                        pr.CreatedBy  = username;
                        ent.TB_PatientRxData.Add(pr);
                        ent.SaveChanges();
                    }
                    else
                    {
                        var r = (from p in ent.TB_RxData where p.RxData_ID == rxData.RxData_ID select p).FirstOrDefault();

                        if (r != null)
                        {
                            r.RxDate        = rxData.RxDate;
                            r.RxDoctor      = rxData.RxDoctor;
                            r.Prescription1 = rxData.Prescription1;
                            r.Prescription2 = rxData.Prescription2;
                            r.Prescription3 = rxData.Prescription3;
                            r.Prescription4 = rxData.Prescription4;
                            r.Prescription5 = rxData.Prescription5;
                            r.UpdateDate    = DateTime.Now;
                            r.UpdatedBy     = username;

                            ent.SaveChanges();
                        }
                    }

                    cs.Set(true, "", null);
                }
            }
            catch (Exception ex)
            {
                cs.Set(false, ex.Message, null);
            }

            return(cs);
        }
コード例 #2
0
        public CommonStatus AddUpdatePatient(Patient patient, int LoggedInuserID)
        {
            CommonStatus cs = new CommonStatus(false);

            try
            {
                using (PatientPortalEntities ent = new PatientPortalEntities())
                {
                    //check for duplicate user;
                    //var dup = (from u in ent.TB_Patient where u.First_Name == patient.First_Name && u.Last_Name == patient.Last_Name && u.DateOfBirth.Date == patient.DateOfBirth.Date select u).FirstOrDefault();

                    var username = (from u in ent.TB_PortalUser where u.PortalUser_ID == LoggedInuserID select u.UserName).FirstOrDefault();

                    if (patient.Patient_ID == 0)
                    {
                        var dup = ent.TB_Patient.Where(u => u.First_Name == patient.First_Name && u.Last_Name == patient.Last_Name && u.DateOfBirth == patient.DateOfBirth).FirstOrDefault();
                        if (dup == null)
                        {
                            TB_Patient tp = new TB_Patient();
                            tp.First_Name  = patient.First_Name;
                            tp.Last_Name   = patient.Last_Name;
                            tp.DateOfBirth = patient.DateOfBirth;
                            tp.PhoneNumber = patient.PhoneNumber;
                            tp.IsActive    = true;
                            tp.CreateDate  = DateTime.Now;
                            tp.CreatedBy   = username;

                            ent.TB_Patient.Add(tp);
                            ent.SaveChanges();

                            cs.Set(true, "", null);
                        }
                        else
                        {
                            cs.Set(false, "Patient with same first name, last name and dateof birth found.", null);
                        }
                    }
                    else
                    {
                        var pt = (from p in ent.TB_Patient where p.Patient_ID == patient.Patient_ID select p).FirstOrDefault();

                        if (pt != null)
                        {
                            pt.First_Name  = patient.First_Name;
                            pt.Last_Name   = patient.Last_Name;
                            pt.DateOfBirth = patient.DateOfBirth;
                            pt.PhoneNumber = patient.PhoneNumber;
                            pt.UpdateDate  = DateTime.Now;
                            pt.UpdatedBy   = username;

                            ent.SaveChanges();

                            cs.Set(true, "", null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                cs.Set(false, ex.Message, null);
            }

            return(cs);
        }