public KhachHangModel Get(string connectString, int Id)
 {
     using (var db = new HMSEntities(connectString))
     {
         try
         {
             return((from x in db.H_KhachHang
                     where !x.IsDeleted && x.Id == Id
                     select new KhachHangModel()
             {
                 Id = x.Id,
                 Ma = x.Code,
                 Ten = x.Name,
                 NSinh = x.Birthday,
                 GTinh = x.Gender,
                 DThoai = x.Phone,
                 DChi = x.Address,
                 TPho = x.City,
                 Huyen = x.District,
                 Phuong = x.Wards,
                 Note = x.Note,
                 NNghiep = (x.H_NgheNghiep != null ? x.H_NgheNghiep.Code : ""),
                 JobId = x.JobId
             }).FirstOrDefault());
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
        public ResponseModel UpdateInfo(string connectString, NhanVienModel model, int accId)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                var acc = db.H_Account.FirstOrDefault(x => !x.IsDeleted && x.Id == accId);
                if (acc != null)
                {
                    var nv = db.H_NhanVien.FirstOrDefault(x => !x.IsDeleted && x.Id == acc.NhanVienId);
                    if (nv != null)
                    {
                        nv.Name    = model.Ten;
                        nv.Address = model.DiaChi;
                        nv.Phone   = model.DienThoai;
                        nv.Note    = model.Note;
                        db.SaveChanges();
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.sms       = "Nhân viên đã bị xóa hoặc không tồn tại trong hệ thống.!";
                    }
                }
                return(result);
            }
        }
Exemple #3
0
        public static AppLab_Parm AddNewParm(AppLab_Parm source)
        {
            var test = new Lab_Parms
            {
                Name      = source.Name,
                Unit      = source.Unit,
                NormarVal = source.NormarVal,
                Price     = source.Price,
                Status    = true,
                Id        = source.Id
            };

            using (var dbContext = new HMSEntities())
            {
                var parm = dbContext.Lab_Parms.FirstOrDefault(p => p.Id == test.Id);
                if (parm != null)
                {
                    parm.Name      = test.Name;
                    parm.Unit      = test.Unit;
                    parm.Price     = test.Price;
                    parm.NormarVal = test.NormarVal;
                }
                else
                {
                    dbContext.Lab_Parms.Add(test);
                }
                dbContext.SaveChanges();
            }
            return(test.Mapper());
        }
Exemple #4
0
        public static AppLab_Test AddUpdateTest(AppLab_Test source)
        {
            var test = new Lab_Tests
            {
                Name     = source.Name,
                Fee      = source.Fee,
                Interval = source.Interval,
                Status   = true,
                Id       = source.Id
            };

            using (var dbContext = new HMSEntities())
            {
                var dbtest = dbContext.Lab_Tests.FirstOrDefault(t => t.Id == source.Id);
                if (dbtest != null)
                {
                    dbtest.Name     = source.Name;
                    dbtest.Fee      = source.Fee;
                    dbtest.Interval = source.Interval;
                }
                else
                {
                    test.CreationDate = DateTime.Now;
                    dbContext.Lab_Tests.Add(test);
                }
                dbContext.SaveChanges();
            }
            return(test.Mapper());
        }
Exemple #5
0
        public AccountModel FindAccount(string connectionString, int accId)
        {
            AccountModel accountModel = null;

            using (var db = new HMSEntities(connectionString))
            {
                var acc = db.H_Account.FirstOrDefault(x => !x.IsDeleted && !x.IsAdmin && x.Id == accId);
                if (acc != null)
                {
                    accountModel        = new AccountModel();
                    accountModel.Id     = acc.Id;
                    accountModel.TenTK  = acc.AccName;
                    accountModel.Avatar = acc.Avatar;
                    if (acc.H_NhanVien != null)
                    {
                        accountModel.HoTen     = acc.H_NhanVien.Name;
                        accountModel.DienThoai = acc.H_NhanVien.Phone;
                        accountModel.DiaChi    = acc.H_NhanVien.Address;
                        accountModel.Note      = acc.H_NhanVien.Note;
                        accountModel.UserId    = acc.NhanVienId;
                        accountModel.ChucVu    = acc.H_NhanVien.H_LoaiNhanVien.Code;
                    }
                }
            }
            return(accountModel);
        }
Exemple #6
0
        public static AppUserDoc UpdateDoc(AppUserDoc source)
        {
            using (var dbContext = new HMSEntities())
            {
                var data = dbContext.AspNetUsers.FirstOrDefault(doc => doc.Id == source.Id);
                if (data != null)
                {
                    data.FirstName = source.FirstName;
                    data.LastName  = source.LastName;
                    data.Fee       = source.Fee;
                    data.Degree    = source.Degree;
                    data.Title     = source.Title;
                    data.ShiftFrom = source.ShiftFrom;
                    data.ShiftToo  = source.ShifTo;
                    data.Email     = source.Email;
                    data.PMDCNo    = source.PMDCNo;


                    data.ShiftDays = source.ShiftDays;
                    dbContext.SaveChanges();
                    return(data.MapToDoc());
                }
            }
            return(source);
        }
        public ResponseModel InsertOrUpdate(string connectString, H_NgheNghiep NhapPT)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (NhapPT.Id == 0)
                {
                    db.H_NgheNghiep.Add(NhapPT);
                }
                else
                {
                    var found = db.H_NgheNghiep.FirstOrDefault(x => !x.IsDeleted && x.Id == NhapPT.Id);
                    if (found != null)
                    {
                        found.Code = NhapPT.Code;
                        found.Note = NhapPT.Note;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.sms       = "Nghề nghiệp này đã bị xóa hoặc không tồn tại trong hệ thống.!";
                    }
                }
                if (result.IsSuccess)
                {
                    db.SaveChanges();
                }
                return(result);
            }
        }
Exemple #8
0
 public List <DichVuModel> Gets(string connectString)
 {
     using (var db = new HMSEntities(connectString))
     {
         try
         {
             return(db.H_DichVu.Where(x => !x.IsDeleted).Select(x => new DichVuModel()
             {
                 Id = x.Id,
                 LoaiCV = x.H_WorkType.Name,
                 MaCV = x.H_Work.Code,
                 TenCV = x.H_Work.Name,
                 LoaiCVId = x.WorkTypeId,
                 CVId = x.WorkId,
                 TGXL = x.TimeProcess,
                 GiaBan = x.Price_Out,
                 GiaMua = x.Price_In,
                 Note = x.Note
             }).ToList());
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Exemple #9
0
        public static App_PatientLabs_Labs UpdatePatientLabs(List <AppLab_Parm_ForPatient> labs)
        {
            using (var dbContext = new HMSEntities())
            {
                var patientLabId = long.MaxValue;
                foreach (var lo in labs)
                {
                    var p = dbContext.PatientLabs_Labs_Parms.FirstOrDefault(o => o.Id == lo.Id);
                    if (p != null)
                    {
                        p.ParmValue = lo.ActualVal ?? "";
                    }
                    patientLabId = lo.PatientLabId;
                }

                var dbtest = dbContext.PatientLabs.FirstOrDefault(t => t.Id == patientLabId);
                if (dbtest != null)
                {
                    if (labs.Any(l => !string.IsNullOrEmpty(l.ActualVal)))
                    {
                        dbtest.Reported = DateTime.Now;
                    }
                }
                dbContext.SaveChanges();
                var allTestDbs = dbContext.PatientLabs_Labs.Include("Lab_Tests").ToList();
                var data       = allTestDbs.Where(o => o.PatientLabId == labs.First().PatientLabId&& o.TestId == labs.First().TestId);
                return(data.FirstOrDefault().MapperHm());
            }
        }
Exemple #10
0
        public static int RemovePatientLab(App_PatientLabs_Labs model)
        {
            using (var dbcontext = new HMSEntities())
            {
                var parms = dbcontext.PatientLabs_Labs_Parms.Where(l => l.PatientLabId == model.PatientLabId && l.TestId == model.TestId).ToList();
                var labs  = dbcontext.PatientLabs_Labs.Where(l => l.PatientLabId == model.PatientLabId && l.TestId == model.TestId).ToList();
                dbcontext.PatientLabs_Labs_Parms.RemoveRange(parms);
                dbcontext.SaveChanges();
                dbcontext.PatientLabs_Labs.RemoveRange(labs);
                dbcontext.SaveChanges();


                var totalFeeTillNow = dbcontext.PatientLabs_Labs.Where(o => o.PatientLabId == model.PatientLabId).ToList().Sum(o => o.Lab_Tests.Fee);

                var rec = dbcontext.PatientLabs.FirstOrDefault(p => p.Id == model.PatientLabId);
                rec.Amount = totalFeeTillNow;
                if (rec.Amount < rec.Discount)
                {
                    rec.Discount   = 0;
                    rec.DiscountBy = "";
                }

                dbcontext.SaveChanges();

                return(totalFeeTillNow);
            }
        }
Exemple #11
0
 public H_Account Get(string connectString, int accId)
 {
     using (var db = new HMSEntities(connectString))
     {
         return(db.H_Account.FirstOrDefault(x => !x.IsDeleted && x.Id == accId));
     }
 }
Exemple #12
0
 public static App_PatientLab GetPatientByMrNo(string mrNo)
 {
     using (var dbContext = new HMSEntities())
     {
         var pdata = dbContext.OPDs.Where(o => o.PatientNo == mrNo);
         if (pdata.Any())
         {
             var source = pdata.First();
             var obj    = new App_PatientLab
             {
                 Id            = 0,
                 Name          = source.Name,
                 PatientNo     = source.PatientNo,
                 RequestedOn   = DateTime.Now.ToString(),
                 Address       = source.Address,
                 Phone         = source.Phone,
                 Age           = source.Age,
                 Gender        = source.Gender,
                 GuardianName  = source.GuardianName,
                 MaritalStatus = source.MartialStatus
             };
             return(obj);
         }
     }
     return(new App_PatientLab());
 }
Exemple #13
0
        public static AppLab_Test AddMixReport(CreateMixReportModel source)
        {
            var test = new Lab_Tests
            {
                Name     = source.Name,
                Fee      = source.Fee,
                Interval = 30,
                Status   = true,
            };

            using (var dbContext = new HMSEntities())
            {
                test.CreationDate = DateTime.Now;
                dbContext.Lab_Tests.Add(test);
                dbContext.SaveChanges();


                foreach (var obj in source.ParmIds)
                {
                    var testMapping = new Lab_Mapping
                    {
                        TestId       = test.Id,
                        ParmId       = obj,
                        CreationDate = DateTime.Now
                    };
                    dbContext.Lab_Mapping.Add(testMapping);
                }
                dbContext.SaveChanges();

                return(test.Mapper());
            }
        }
Exemple #14
0
        public static LabTestResponseModelDd GetLabTestsForMapping(string term)
        {
            var response = new LabTestResponseModelDd
            {
                LabTests = new List <AppLab_TestDd>()
            };

            using (var dbContext = new HMSEntities())
            {
                if (!string.IsNullOrEmpty(term))
                {
                    var tests = dbContext.Lab_Tests
                                .Where(lab => lab.Name.ToLower().Contains(term.ToLower())).ToList();
                    if (tests.Any())
                    {
                        var list = tests.Select(l => l.MapperDd()).ToList();
                        response.LabTests = list;
                    }
                }
                else
                {
                    var tests = dbContext.Lab_Tests.ToList();
                    if (tests.Any())
                    {
                        var list = tests.Select(l => l.MapperDd()).ToList();
                        response.LabTests = list;
                    }
                }
            }
            return(response);
        }
Exemple #15
0
        public static bool UpdatePatientToLab(App_PatientLab source)
        {
            using (var dbContext = new HMSEntities())
            {
                var dbtest = dbContext.PatientLabs.FirstOrDefault(t => t.Id == source.Id);

                if (source.Discount != null && source.Discount > 0)
                {
                    if (dbtest == null || dbtest.Amount == null || source.Discount > dbtest.Amount)
                    {
                        return(false);
                    }
                }


                if (dbtest != null)
                {
                    dbtest.Address       = source.Address;
                    dbtest.Age           = source.Age;
                    dbtest.BloodGroup    = source.BloodGroup;
                    dbtest.Gender        = source.Gender;
                    dbtest.GuardianName  = source.GuardianName;
                    dbtest.Name          = source.Name;
                    dbtest.PerformedBy   = source.PerformedBy;
                    dbtest.Phone         = source.Phone;
                    dbtest.RegisteredBy  = source.RegisteredBy;
                    dbtest.MaritalStatus = source.MaritalStatus;
                    dbtest.Gender        = source.Gender;
                    dbtest.Discount      = source.Discount;
                    dbtest.DiscountBy    = source.DiscountBy;
                }
                dbContext.SaveChanges();
                return(true);
            }
        }
Exemple #16
0
 public static long AddPatientToLab(App_PatientLab PatientInfo)
 {
     using (var dbContext = new HMSEntities())
     {
         var pat     = PatientInfo;
         var patient = new PatientLab
         {
             PatientNo     = pat.PatientNo,
             Name          = pat.Name,
             Age           = pat.Age,
             Gender        = pat.Gender,
             RegisteredBy  = pat.RegisteredBy,
             PerformedBy   = pat.PerformedBy,
             Requested     = DateTime.Now,
             Reported      = null,
             BloodGroup    = pat.BloodGroup,
             GuardianName  = pat.GuardianName,
             Phone         = pat.Phone,
             Address       = pat.Address,
             MaritalStatus = pat.MaritalStatus,
         };
         dbContext.PatientLabs.Add(patient);
         dbContext.SaveChanges();
         return(patient.Id);
     }
 }
        public ActionResult AddComplains(Complain obj)
        {
            try
            {
                HMSEntities db = new HMSEntities();
                //  List<Status> status = db.Status.ToList();
                //  ViewBag.StatusList = new SelectList(status, "StatusID", "StatusName");
                Complain c = new Complain();
                c.Subject      = obj.Subject;
                c.AssignTo     = obj.AssignTo;
                c.Details      = obj.Details;
                c.Priority     = obj.Priority;
                c.CreatedBy    = obj.CreatedBy;
                c.CreationDate = obj.CreationDate;

                db.Complains.Add(c);
                db.SaveChanges();
            }

            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e.ToString());
            }

            return(View(obj));
        }
 public List <NhanVienModel> Gets(string connectString)
 {
     using (var db = new HMSEntities(connectString))
     {
         try
         {
             var userIds = db.H_Account.Where(x => !x.IsDeleted && x.IsAdmin).Select(x => x.NhanVienId).ToList();
             return(db.H_NhanVien.Where(x => !x.IsDeleted && !userIds.Contains(x.Id)).Select(x => new NhanVienModel()
             {
                 Id = x.Id,
                 Ma = x.Code,
                 Ten = x.Name,
                 DienThoai = x.Phone,
                 DiaChi = x.Address,
                 LoaiNV = x.LoaiNVId,
                 strLoaiNV = x.H_LoaiNhanVien.Code,
                 Note = x.Note
             }).ToList());
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Exemple #19
0
        public static OpdFormMetaReaponseModel GetMetaData(OpdFormMetaRequestModel requestModel)
        {
            using (var dbcontext = new HMSEntities())
            {
                var  allForms  = dbcontext.OPDs.ToList();
                var  ruleDate  = DateTime.Now.Date;
                var  patientNo = requestModel.PatientNo?.Trim();
                var  visitNo   = 0;
                var  dailyNo   = 0;
                long serialNo  = 0;

                AppOpd existedform = new AppOpd();
                if (allForms.Any())
                {
                    dailyNo =
                        dbcontext.OPDs.Count(
                            form =>
                            EntityFunctions.TruncateTime(form.DateTime) == ruleDate &&
                            form.DoctorId == requestModel.DoctorId);

                    serialNo = allForms.Count;

                    if (string.IsNullOrEmpty(patientNo))
                    {
                        patientNo = DateTime.Now.Year + "" + DateTime.Now.Month + "-" + DateTime.Now.Day +
                                    (dbcontext.OPDs.Count(form => EntityFunctions.TruncateTime(form.DateTime) == ruleDate) + 1) + "";
                    }
                    else
                    {
                        visitNo = allForms.Count(form => form.PatientNo == patientNo);
                        var tempoForm = allForms.FirstOrDefault(form => form.PatientNo == patientNo);
                        if (tempoForm != null)
                        {
                            existedform = tempoForm.MaptoOpd();
                        }
                    }
                    return(new OpdFormMetaReaponseModel
                    {
                        DateTime = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                        DailyNo = ++dailyNo,
                        PatientNo = patientNo,
                        VisitNo = ++visitNo,
                        SerialNo = ++serialNo,
                        OpdForm = existedform
                    });
                }
            }
            return(new OpdFormMetaReaponseModel
            {
                DateTime = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                DailyNo = 1,
                PatientNo = 1 + "",
                VisitNo = 1,
                SerialNo = 1,
                OpdForm = null
            });
        }
        public ActionResult StuRegister()
        {
            HMSEntities       db          = new HMSEntities();
            List <Department> departments = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(departments, "DepartmentID", "Name");

            return(View());
        }
Exemple #21
0
 public static void DeleteMapping(AppLab_mapping source)
 {
     using (var dbContext = new HMSEntities())
     {
         var dbobj = dbContext.Lab_Mapping.FirstOrDefault(o => o.Id == source.Id);
         dbContext.Lab_Mapping.Remove(dbobj);
         dbContext.SaveChanges();
     }
 }
 public List <ModelSelectItem> GetLookUp(string connectString)
 {
     using (var db = new HMSEntities(connectString))
     {
         return(db.H_NgheNghiep.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem()
         {
             Id = x.Id, Code = x.Code, Name = x.Note
         }).ToList());
     }
 }
        private bool CheckExists(PhuTungModel PhuTung, HMSEntities db)
        {
            H_PhuTung obj = null;

            if (!string.IsNullOrEmpty(PhuTung.Ma))
            {
                obj = db.H_PhuTung.FirstOrDefault(x => !x.IsDeleted && x.Id != PhuTung.Id && x.Code.Trim().ToUpper().Equals(PhuTung.Ma.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
Exemple #24
0
        private bool CheckExists(SellReceiptModel SellReceipt, HMSEntities db)
        {
            H_SellReceipt obj = null;

            if (!string.IsNullOrEmpty(SellReceipt.SoPhieu))
            {
                obj = db.H_SellReceipt.FirstOrDefault(x => !x.IsDeleted && x.Id != SellReceipt.Id && x.SoPhieu.Trim().ToUpper().Equals(SellReceipt.SoPhieu.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
 public List <ModelSelectItem> GetLookUp(string connectString)
 {
     using (var db = new HMSEntities(connectString))
     {
         return(db.H_PhuTung.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem()
         {
             Id = x.Id, Code = x.Code, Name = x.Name, Data = x.Quantities, _double = x.Price_In, _double1 = x.Price_Out
         }).ToList());
     }
 }
        private bool CheckExists(H_NgheNghiep Job, HMSEntities db)
        {
            H_NgheNghiep obj = null;

            if (!string.IsNullOrEmpty(Job.Code))
            {
                obj = db.H_NgheNghiep.FirstOrDefault(x => !x.IsDeleted && x.Id != Job.Id && x.Code.Trim().ToUpper().Equals(Job.Code.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
        private bool CheckExists(H_LoaiNhanVien UserType, HMSEntities db)
        {
            H_LoaiNhanVien obj = null;

            if (!string.IsNullOrEmpty(UserType.Code))
            {
                obj = db.H_LoaiNhanVien.FirstOrDefault(x => !x.IsDeleted && x.Id != UserType.Id && x.Code.Trim().ToUpper().Equals(UserType.Code.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
Exemple #28
0
        private bool CheckExists(H_Model model, HMSEntities db)
        {
            H_Model obj = null;

            if (!string.IsNullOrEmpty(model.Code))
            {
                obj = db.H_Model.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.Code.Trim().ToUpper().Equals(model.Code.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
Exemple #29
0
        public ResponseModel InsertOrUpdate(string connectString, DichVuModel model)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(model, db))
                {
                    H_DichVu DichVu = null;
                    if (model.Id == 0)
                    {
                        DichVu = new H_DichVu()
                        {
                            WorkId      = model.CVId,
                            WorkTypeId  = model.LoaiCVId,
                            TimeProcess = model.TGXL,
                            Price_Out   = model.GiaBan,
                            Price_In    = model.GiaMua,
                            Note        = model.Note
                        };
                        db.H_DichVu.Add(DichVu);
                    }
                    else
                    {
                        var found = db.H_DichVu.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
                        if (found != null)
                        {
                            found.WorkId      = model.CVId;
                            found.WorkTypeId  = model.LoaiCVId;
                            found.TimeProcess = model.TGXL;
                            found.Price_In    = model.GiaMua;
                            found.Price_Out   = model.GiaBan;
                            found.Note        = model.Note;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.sms       = "Công việc đã bị xóa hoặc không tồn tại trong hệ thống.!";
                        }
                    }
                    if (result.IsSuccess)
                    {
                        db.SaveChanges();
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.sms       = "Mã này đã tồn tại trong hệ thống. Vui lòng chọn lại mã khác.";
                }
                return(result);
            }
        }
Exemple #30
0
 public ModelSelectItem FindAccount(string connectionString, string taikhoan, string matkhau)
 {
     using (var db = new HMSEntities(connectionString))
     {
         string hasPass = GlobalFunction.EncryptMD5(matkhau);
         return(db.H_Account.Where(x => x.AccName.Trim() == taikhoan.Trim() && hasPass == x.Password).Select(acc => new ModelSelectItem()
         {
             Id = acc.Id, Code = acc.AccName, Data = acc.Role, Name = acc.H_NhanVien.Name, Data1 = acc.Avatar
         }).FirstOrDefault());
     }
 }