public void Insert(int IdPhieuXuat,int IdThuoc,int SoLuong,decimal DonGia,decimal PhuThu,decimal BnhanChitra,decimal BhytChitra,int? PtramBhyt,string ChiDan,string CachDung,string ChidanThem,string SolanDung,string SoluongDung,DateTime? NgayTao,string NguoiTao,int? IdChitietdonthuoc,int? IdDonthuoc)
        {
            TXuatthuocTheodon item = new TXuatthuocTheodon();

            item.IdPhieuXuat = IdPhieuXuat;

            item.IdThuoc = IdThuoc;

            item.SoLuong = SoLuong;

            item.DonGia = DonGia;

            item.PhuThu = PhuThu;

            item.BnhanChitra = BnhanChitra;

            item.BhytChitra = BhytChitra;

            item.PtramBhyt = PtramBhyt;

            item.ChiDan = ChiDan;

            item.CachDung = CachDung;

            item.ChidanThem = ChidanThem;

            item.SolanDung = SolanDung;

            item.SoluongDung = SoluongDung;

            item.NgayTao = NgayTao;

            item.NguoiTao = NguoiTao;

            item.IdChitietdonthuoc = IdChitietdonthuoc;

            item.IdDonthuoc = IdDonthuoc;

            item.Save(UserName);
        }
Beispiel #2
0
        /// <summary>
        /// HÀM THỰC HIỆN VIECJ CHO PHÉP CẬP NHẬP ĐƠN THUỐC
        /// </summary>
        /// <returns></returns>
        public ActionResult LinhThuocBenhNhan(KcbDonthuoc objDonthuoc,KcbDonthuocChitiet []arrPresDetails, TPhieuXuatthuocBenhnhan objXuatBnhan)
        {
            try
            {
                HisDuocProperties hisDuocProperties=new HisDuocProperties();
                using (var scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        hisDuocProperties = PropertyLib._HisDuocProperties;
                        objXuatBnhan.IdBenhnhan = objDonthuoc.IdBenhnhan;
                        objXuatBnhan.MaLuotkham = objDonthuoc.MaLuotkham;
                        objXuatBnhan.MaPhieu = THU_VIEN_CHUNG.MaPhieuXuatBN();
                        objXuatBnhan.Noitru = Utility.ByteDbnull(objDonthuoc.Noitru);
                        objXuatBnhan.TenKhongdau = Utility.UnSignedCharacter(objXuatBnhan.TenBenhnhan);
                        objXuatBnhan.IdDonthuoc = Utility.Int32Dbnull(objDonthuoc.IdDonthuoc);
                        objXuatBnhan.IsNew = true;
                        objXuatBnhan.Save();
                        Int32 PtramBHYT = 0;
                        SqlQuery sqlQuery = new Select().From(KcbLuotkham.Schema).Where(
                            KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objDonthuoc.MaLuotkham)
                            .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objDonthuoc.IdBenhnhan);
                        KcbLuotkham objLuotkham = sqlQuery.ExecuteSingle<KcbLuotkham>();
                        if(objLuotkham!=null)
                        {
                            PtramBHYT = Utility.Int32Dbnull(objLuotkham.PtramBhyt);
                        }
                        foreach (KcbDonthuocChitiet objDetail in arrPresDetails)
                        {
                            ActionResult actionResult = TruThuocTrongKho(objDonthuoc,objDetail, objXuatBnhan);
                            switch (actionResult)
                            {
                                case ActionResult.NotEnoughDrugInStock:
                                    return actionResult;
                                    break;
                            }
                            //REM lại để tránh trường hợp vi phạm phần nội trú. Đơn thuốc được cấp phát nhiều lần
                            //new Delete().From(TXuatthuocTheodon.Schema)
                            //    .Where(TXuatthuocTheodon.Columns.IdChitietdonthuoc).IsEqualTo(objDetail.IdChitietdonthuoc).Execute();
                            TXuatthuocTheodon objThuocCt=new TXuatthuocTheodon();
                            objThuocCt.IdPhieuXuat = Utility.Int32Dbnull(objXuatBnhan.IdPhieu);
                            objThuocCt.IdThuoc = Utility.Int32Dbnull(objDetail.IdThuoc);
                            objThuocCt.NgayTao = globalVariables.SysDate;
                            objThuocCt.SoLuong = Utility.Int32Dbnull(objDetail.SoLuong);
                            objThuocCt.NguoiTao = globalVariables.UserName;
                            objThuocCt.PhuThu = Utility.DecimaltoDbnull(objDetail.PhuThu);
                            objThuocCt.DonGia = Utility.DecimaltoDbnull(objDetail.DonGia);

                          //  objThuocCt.gi = Utility.DecimaltoDbnull(objDetail.DonGia);
                            objThuocCt.BnhanChitra = Utility.DecimaltoDbnull(objDetail.BnhanChitra);
                            objThuocCt.BhytChitra = Utility.DecimaltoDbnull(objDetail.BhytChitra);
                            objThuocCt.ChiDan = Utility.sDbnull(objDetail.MotaThem);
                            objThuocCt.ChidanThem = Utility.sDbnull(objDetail.ChidanThem);
                            objThuocCt.SolanDung = Utility.sDbnull(objDetail.SolanDung);
                            objThuocCt.SoluongDung = Utility.sDbnull(objDetail.SoluongDung);
                            objThuocCt.CachDung = Utility.sDbnull(objDetail.CachDung);
                            objThuocCt.PtramBhyt = PtramBHYT;
                            objThuocCt.IdChitietdonthuoc = Utility.Int32Dbnull(objDetail.IdChitietdonthuoc);
                            objThuocCt.IdDonthuoc = Utility.Int32Dbnull(objDetail.IdDonthuoc);
                           // objThuocCt.LoaiDonThuoc = 0;
                            objThuocCt.IsNew = true;
                            objThuocCt.Save();
                        }
                        sqlQuery = new Select().From(KcbDonthuocChitiet.Schema)
                            .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc)
                            .And(KcbDonthuocChitiet.Columns.TrangThai).IsEqualTo(0);
                        int status = sqlQuery.GetRecordCount()<=0?1:0;
                        new Update(KcbDonthuoc.Schema)
                                  .Set(KcbDonthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                                  .Set(KcbDonthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                                  .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(status)
                                  .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc).Execute();
                    }
                    scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("loi trong qua trinh cap don thuoc {0}", exception);
                return ActionResult.Error;
            }
        }
Beispiel #3
0
        public ActionResult LinhThuocBenhNhanTaiQuay(long Pres_ID, Int16 id_kho, DateTime ngaythuchien)
        {
            try
            {
                string ErrMsg = "";
                HisDuocProperties hisDuocProperties = new HisDuocProperties();
                using (TransactionScope scope = new TransactionScope())
                {

                    hisDuocProperties = PropertyLib._HisDuocProperties;
                    KcbDonthuoc objDonthuoc = KcbDonthuoc.FetchByID(Pres_ID);
                    KcbDanhsachBenhnhan objBenhnhan = KcbDanhsachBenhnhan.FetchByID(objDonthuoc.IdBenhnhan);
                    KcbLuotkham objLuotkham = null;//KH vãng lai ko có thông tin lượt khám
                    TPhieuXuatthuocBenhnhan objXuatBnhan = CreatePhieuXuatBenhNhan(objDonthuoc, objBenhnhan, objLuotkham);
                    objXuatBnhan.NgayXacnhan = ngaythuchien;
                    objXuatBnhan.MaPhieu = THU_VIEN_CHUNG.MaPhieuXuatBN();
                    objXuatBnhan.IdKho = id_kho;
                    objXuatBnhan.IsNew = true;
                    objXuatBnhan.Save();
                    Int32 PtramBHYT = 0;
                    if (objLuotkham != null)
                    {
                        PtramBHYT = Utility.Int32Dbnull(objLuotkham.PtramBhyt);
                    }
                    KcbDonthuocChitietCollection lstDetail
                        = new Select().From(KcbDonthuocChitiet.Schema)
                        .Where(KcbDonthuocChitiet.IdDonthuocColumn).IsEqualTo(objDonthuoc.IdDonthuoc)
                        .And(KcbDonthuocChitiet.Columns.IdKho).IsEqualTo(id_kho)
                        .ExecuteAsCollection<KcbDonthuocChitietCollection>();
                    //Chỉ việc trừ theo chi tiết do ngay khi kê đơn đã tự động xác định các thuốc cần trừ trong kho theo id_thuockho
                    foreach (KcbDonthuocChitiet objDetail in lstDetail)
                    {
                        TThuockho objTThuockho = new Select().From(TThuockho.Schema)
                            .Where(TThuockho.IdThuockhoColumn).IsEqualTo(objDetail.IdThuockho)
                            .ExecuteSingle<TThuockho>();
                        //Kiểm tra xem thuốc còn đủ hay không?
                        if (objTThuockho.SoLuong < objDetail.SoLuong)
                        {
                            //Sau này có thể mở rộng thêm code tự động dò và xác định lại Id_thuockho cho các chi tiết đơn thuốc
                            return ActionResult.NotEnoughDrugInStock;
                        }
                        UpdateXuatChiTietBN(objDonthuoc, objDetail, objTThuockho, objDetail.SoLuong, objXuatBnhan);
                        StoredProcedure sp = SPs.ThuocXuatkho(Utility.Int32Dbnull(objTThuockho.IdKho),
                                                                      Utility.Int32Dbnull(objTThuockho.IdThuoc, -1),
                                                                      objTThuockho.NgayHethan, objDetail.GiaNhap, Utility.DecimaltoDbnull(objDetail.GiaBan),
                                                                      Utility.DecimaltoDbnull(objTThuockho.Vat), objDetail.SoLuong, objTThuockho.IdThuockho, objTThuockho.MaNhacungcap, objTThuockho.SoLo, PropertyLib._HisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, ErrMsg);

                        sp.Execute();

                        new Update(KcbDonthuocChitiet.Schema)
               .Set(KcbDonthuocChitiet.Columns.TrangThai).EqualTo(1)
               .Set(KcbDonthuocChitiet.Columns.NgayXacnhan).EqualTo(ngaythuchien)
               .Where(KcbDonthuocChitiet.Columns.IdChitietdonthuoc).IsEqualTo(objDetail.IdChitietdonthuoc).Execute();

                        //REM lại để tránh trường hợp vi phạm phần nội trú. Đơn thuốc được cấp phát nhiều lần
                        TXuatthuocTheodon objThuocCt = new TXuatthuocTheodon();
                        objThuocCt.IdPhieuXuat = Utility.Int32Dbnull(objXuatBnhan.IdPhieu);
                        objThuocCt.IdThuoc = Utility.Int32Dbnull(objDetail.IdThuoc);
                        objThuocCt.NgayTao = globalVariables.SysDate;
                        objThuocCt.SoLuong = Utility.Int32Dbnull(objDetail.SoLuong);
                        objThuocCt.NguoiTao = globalVariables.UserName;
                        objThuocCt.PhuThu = Utility.DecimaltoDbnull(objDetail.PhuThu);
                        objThuocCt.DonGia = Utility.DecimaltoDbnull(objDetail.DonGia);

                        objThuocCt.BnhanChitra = Utility.DecimaltoDbnull(objDetail.BnhanChitra);
                        objThuocCt.BhytChitra = Utility.DecimaltoDbnull(objDetail.BhytChitra);
                        objThuocCt.ChiDan = Utility.sDbnull(objDetail.MotaThem);
                        objThuocCt.ChidanThem = Utility.sDbnull(objDetail.ChidanThem);
                        objThuocCt.SolanDung = Utility.sDbnull(objDetail.SolanDung);
                        objThuocCt.SoluongDung = Utility.sDbnull(objDetail.SoluongDung);
                        objThuocCt.CachDung = Utility.sDbnull(objDetail.CachDung);
                        objThuocCt.PtramBhyt = PtramBHYT;
                        objThuocCt.IdChitietdonthuoc = Utility.Int32Dbnull(objDetail.IdChitietdonthuoc);
                        objThuocCt.IdDonthuoc = Utility.Int32Dbnull(objDetail.IdDonthuoc);
                        objThuocCt.IsNew = true;
                        objThuocCt.Save();
                    }
                    SqlQuery sqlQuery = new Select().From(KcbDonthuocChitiet.Schema)
                         .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc)
                         .And(KcbDonthuocChitiet.Columns.TrangThai).IsEqualTo(0);
                    int status = sqlQuery.GetRecordCount() <= 0 ? 1 : 0;
                    new Update(KcbDonthuoc.Schema)
                              .Set(KcbDonthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                              .Set(KcbDonthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                              .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(status)
                              .Set(KcbDonthuoc.Columns.NgayHuyxacnhan).EqualTo(null)
                              .Set(KcbDonthuoc.Columns.NguoiHuyxacnhan).EqualTo("")
                              .Set(KcbDonthuoc.Columns.LydoHuyxacnhan).EqualTo("")
                              .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc).Execute();
                    scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("loi trong qua trinh cap don thuoc {0}", exception);
                return ActionResult.Error;
            }
        }
Beispiel #4
0
        /// <summary>
        /// HÀM THỰC HIỆN VIECJ CHO PHÉP CẬP NHẬP ĐƠN THUỐC
        /// </summary>
        /// <returns></returns>
        public ActionResult Linhthuocnoitru(KcbDonthuoc objDonthuoc, TPhieuXuatthuocBenhnhan objXuatBnhan, int ID_KHO_XUAT, DateTime ngaythuchien)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    string THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC = THU_VIEN_CHUNG.Laygiatrithamsohethong("THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC", "0", false);
                    HisDuocProperties hisDuocProperties = new HisDuocProperties();
                    objXuatBnhan.IdBenhnhan = objDonthuoc.IdBenhnhan;
                    objXuatBnhan.MaLuotkham = objDonthuoc.MaLuotkham;
                    objXuatBnhan.MaPhieu = THU_VIEN_CHUNG.MaPhieuXuatBN();
                    objXuatBnhan.Noitru = Utility.ByteDbnull(objDonthuoc.Noitru);
                    objXuatBnhan.TenKhongdau = Utility.UnSignedCharacter(objXuatBnhan.TenBenhnhan);
                    objXuatBnhan.IdDonthuoc = Utility.Int32Dbnull(objDonthuoc.IdDonthuoc);
                    objXuatBnhan.IsNew = true;
                    objXuatBnhan.Save();
                    Int32 PtramBHYT = 0;
                    SqlQuery sqlQuery = new Select().From(KcbLuotkham.Schema).Where(
                        KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objDonthuoc.MaLuotkham)
                        .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objDonthuoc.IdBenhnhan);
                    KcbLuotkham objLuotkham = sqlQuery.ExecuteSingle<KcbLuotkham>();
                    if (objLuotkham != null)
                    {
                        PtramBHYT = Utility.Int32Dbnull(objLuotkham.PtramBhyt);
                    }
                    sqlQuery = new Select().From(TPhieuCapphatChitiet.Schema)
                        .Where(TPhieuCapphatChitiet.Columns.IdCapphat).IsEqualTo(objXuatBnhan.IdCapphat)
                        .And(TPhieuCapphatChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc);

                    TPhieuCapphatChitietCollection objDPhieuCapphatCtCollection =
                        sqlQuery.ExecuteAsCollection<TPhieuCapphatChitietCollection>();
                    foreach (TPhieuCapphatChitiet objCapphatDetail in objDPhieuCapphatCtCollection)
                    {
                        KcbDonthuocChitiet objDetail = new Select().From(KcbDonthuocChitiet.Schema)
                            .Where(KcbDonthuocChitiet.Columns.IdChitietdonthuoc).IsEqualTo(objCapphatDetail.IdChitietdonthuoc)
                            .ExecuteSingle<KcbDonthuocChitiet>();
                        if (objDetail == null) return ActionResult.Exceed;
                        objDetail.SetColumnValue("id_kho", ID_KHO_XUAT);
                        ActionResult actionResult = TruThuocTrongKho_Noitru(objDonthuoc,objCapphatDetail, objDetail, objXuatBnhan, ID_KHO_XUAT, ngaythuchien);
                        switch (actionResult)
                        {
                            case ActionResult.NotEnoughDrugInStock:
                                return actionResult;
                        }

                        TXuatthuocTheodon objThuocCt = new TXuatthuocTheodon();
                        objThuocCt.IdPhieuXuat = Utility.Int32Dbnull(objXuatBnhan.IdPhieu);
                        objThuocCt.IdThuoc = Utility.Int32Dbnull(objCapphatDetail.IdThuoc);
                        objThuocCt.NgayTao = globalVariables.SysDate;
                        objThuocCt.SoLuong = objCapphatDetail.SoLuong;
                        objThuocCt.NguoiTao = globalVariables.UserName;
                        objThuocCt.PhuThu = Utility.DecimaltoDbnull(objDetail.PhuThu);
                        objThuocCt.DonGia = Utility.DecimaltoDbnull(objDetail.DonGia);
                        objThuocCt.BnhanChitra = Utility.DecimaltoDbnull(objDetail.BnhanChitra);
                        objThuocCt.BhytChitra = Utility.DecimaltoDbnull(objDetail.BhytChitra);
                        objThuocCt.ChiDan = Utility.sDbnull(objDetail.MotaThem);
                        objThuocCt.ChidanThem = Utility.sDbnull(objDetail.ChidanThem);
                        objThuocCt.SolanDung = Utility.sDbnull(objDetail.SolanDung);
                        objThuocCt.SoluongDung = Utility.sDbnull(objDetail.SoluongDung);
                        objThuocCt.CachDung = Utility.sDbnull(objDetail.CachDung);
                        objThuocCt.PtramBhyt = PtramBHYT;
                        objThuocCt.IdChitietdonthuoc = Utility.Int32Dbnull(objCapphatDetail.IdChitietdonthuoc);
                        objThuocCt.IdDonthuoc = Utility.Int32Dbnull(objCapphatDetail.IdThuoc);
                        objThuocCt.IsNew = true;
                        objThuocCt.Save();
                        if (THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC == "1")
                        {
                            objCapphatDetail.ThucLinh = objCapphatDetail.SoLuong;
                            objCapphatDetail.IsNew = false;
                            objCapphatDetail.MarkOld();
                            objCapphatDetail.Save();
                        }
                    }
                    byte DA_LINH = (byte)(THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC == "1" ? 1 : 0);

                    new Update(TPhieuCapphatChitiet.Schema)
                        .Set(TPhieuCapphatChitiet.Columns.DaLinh).EqualTo(DA_LINH)

                        .Set(TPhieuCapphatChitiet.Columns.IdPhieuxuatthuocBenhnhan).EqualTo(objXuatBnhan.IdPhieu)
                        .Where(TPhieuCapphatChitiet.Columns.IdCapphat).IsEqualTo(objXuatBnhan.IdCapphat).Execute();
                    sqlQuery = new Select().From(KcbDonthuocChitiet.Schema)
                                .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc)
                                .And(KcbDonthuocChitiet.Columns.TrangThai).IsEqualTo(0);
                    int status = sqlQuery.GetRecordCount() <= 0 ? 1 : 0;
                    new Update(KcbDonthuoc.Schema)
                              .Set(KcbDonthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                              .Set(KcbDonthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                              .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(status)
                              .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc).Execute();
                    scope.Complete();
                }

                return ActionResult.Success;
            }
            catch (Exception exception)
            {
                log.Error("loi trong qua trinh cap don thuoc {0}", exception);
                return ActionResult.Error;

            }
        }