Пример #1
0
        private void ImportData()
        {
            TAssignDetail objAssignDetail = null;
            TAssignInfo objAsignInfo = null;
            TPatientExam objPatientExam = null;
            TPatientInfo objPatientInfo = null;
            string SoCMND = "";
            string sNgaySinh = "";
            string sGioiTinh = "";
            string sCoQuan = "";
            string sChucVu = "";
            byte btGioitinh = 0;
            string sDiaChi = "";
            string sSDT = "";
            string sMaNV = "";
            var dtNgaySinh = new DateTime();
            _lstAssignDetail.Clear();
            if (!chkGhepLo.Checked) LaySoLoImportExcel();
            int iSTT = 1;
            _Value = 0;
            try
            {
                DateTime sysdate = BusinessHelper.GetSysDateTime();

                #region Get AssignInfo

                objAsignInfo = new TAssignInfo();
                objAsignInfo.ExamId = -1;
                objAsignInfo.TreatId = -1;
                objAsignInfo.PatientDeptId = -1;
                objAsignInfo.PatientCode = SoCMND;
                objAsignInfo.ServiceId = -1;
                objAsignInfo.ServiceTypeId = -1;
                objAsignInfo.RegDate = dtNgayNhap.Value;
                objAsignInfo.PaymentStatus = 0;
                objAsignInfo.CreatedBy = globalVariables.UserName;
                objAsignInfo.CreateDate = sysdate;
                objAsignInfo.ObjectTypeId = -1;
                objAsignInfo.MaKhoaThien = "KSK";
                objAsignInfo.Actived = 0;
                objAsignInfo.NoiTru = 0;

                objAsignInfo.IsPHIDvuKtheo = 0;

                #endregion

                #region Get AssignDetail

                foreach (DataRow dr in m_dtAssignDetail.Rows)
                {
                    objAssignDetail = new TAssignDetail();
                    objAssignDetail.ExamId = -1;
                    objAssignDetail.ServiceId = Convert.ToInt16(dr["Service_Id"]);
                    objAssignDetail.ServiceDetailId = Convert.ToInt16(dr["ServiceDetail_Id"]);
                    objAssignDetail.DiagPerson = Convert.ToInt16(dr["Diag_Person"]);
                    objAssignDetail.DiscountRate = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Discount_Rate"], 0));
                    objAssignDetail.DiscountType = Convert.ToByte(Utility.ByteDbnull(dr["Discount_Type"], 0));
                    objAssignDetail.OriginPrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Origin_Price"], 0));
                    objAssignDetail.DiscountPrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Discount_Price"], 0));
                    objAssignDetail.SurchargePrice = Convert.ToDecimal(Utility.DecimaltoDbnull(dr["Surcharge_Price"], 0));
                    objAssignDetail.UserId = globalVariables.UserName;
                    if (!string.IsNullOrEmpty(dr["Assign_Type_Id"].ToString()))
                        objAssignDetail.AssignTypeId = Convert.ToByte(Utility.ByteDbnull(dr["Assign_Type_Id"], 0));
                    else
                        objAssignDetail.AssignTypeId = 0;
                    objAssignDetail.InputDate = dtNgayNhap.Value;
                    objAssignDetail.PaymentStatus = 0;
                    objAssignDetail.IsCancel = 0;
                    objAssignDetail.IsPayment = 0;
                    objAssignDetail.ObjectTypeId = 1;
                    objAssignDetail.Quantity = Convert.ToInt32(dr["Quantity"]);
                    objAssignDetail.AssignDetailStatus = 0;
                    objAssignDetail.BhytStatus = 0;
                    objAssignDetail.DisplayOnReport = 0;
                    objAssignDetail.GiaBhytCt = 0;
                    objAssignDetail.PaymentId = 0;
                    objAssignDetail.ChoPhepIn = 0;
                    _lstAssignDetail.Add(objAssignDetail);
                }

                foreach (GridEXRow row in grdData.GetCheckedRows())
                {
                    string patient_code = Utility.sDbnull(row.Cells["patient_code"].Value, "");
                    if (patient_code == "")
                    {
                        _BussinessImportExcel = new BussinessImportExcel();

                        #region Get PatientInfo

                        SoCMND = ChuanHoaChuoi(row.Cells["CMT"].Value.ToString());
                        sNgaySinh = ChuanHoaChuoi(row.Cells["NGAY_SINH"].Value.ToString());
                        sGioiTinh = ChuanHoaChuoi(row.Cells["GIOI_TINH"].Value.ToString());
                        sCoQuan = ChuanHoaChuoi(row.Cells["CO_QUAN"].Value.ToString());
                        sChucVu = ChuanHoaChuoi(row.Cells["CHUC_VU"].Value.ToString());
                        sSDT = ChuanHoaChuoi(row.Cells["SDT"].Value.ToString());
                        sMaNV = ChuanHoaChuoi(row.Cells["Ma_NV"].Value.ToString());
                        // sDiaChi = ChuanHoaChuoi(row.Cells["DIA_CHI"].Value.ToString());
                        sDiaChi = ChuanHoaChuoi(row.Cells["DIACHI"].Value.ToString());
                        if (sGioiTinh.ToLower().Equals("m")) btGioitinh = 0;
                        else if (sGioiTinh.ToLower().Equals("f")) btGioitinh = 1;
                        else if (sGioiTinh.ToLower().Equals("nam")) btGioitinh = 0;
                        else if (sGioiTinh.ToLower().Equals("nữ")) btGioitinh = 1;
                        else btGioitinh = 2;

                        if (string.IsNullOrEmpty(SoCMND)) SoCMND = dtNgayNhap.Value.ToString("yyyyMMdd") + "@" + iSTT;
                        objPatientInfo = new TPatientInfo();
                        objPatientInfo.CountryId = 1;
                        objPatientInfo.DanToc = 1;
                        objPatientInfo.IdentifyNum = SoCMND;
                        objPatientInfo.InputDate = dtNgayNhap.Value;
                        objPatientInfo.Locked = 0;
                        objPatientInfo.PatientJob = sChucVu;
                        objPatientInfo.PatientName = ChuanHoaChuoi(row.Cells["HO_TEN"].Value.ToString());
                        objPatientInfo.PatientEmail = sMaNV;
                        objPatientInfo.PatientPhone = sSDT;
                        objPatientInfo.PatientAddr = sDiaChi;
                        objPatientInfo.PatientSex = btGioitinh;
                        objPatientInfo.Offices = sCoQuan;
                        objPatientInfo.UserId = globalVariables.UserName;
                        objPatientInfo.NgayTao = sysdate;
                        int namsinh = DateTime.Now.Year;
                        DateTime ngay_sinh = DateTime.Now;
                        if (!string.IsNullOrEmpty(sNgaySinh))
                        {
                            try
                            {
                                if (sNgaySinh.TrimStart().TrimEnd() == "")
                                {
                                    namsinh = BusinessHelper.GetSysDateTime().Year;
                                    ngay_sinh = new DateTime(namsinh, 1, 1);
                                }
                                if (sNgaySinh.TrimStart().TrimEnd().Length == 4)
                                {
                                    namsinh = Utility.Int32Dbnull(sNgaySinh, BusinessHelper.GetSysDateTime().Year);
                                    ngay_sinh = new DateTime(namsinh, 1, 1);
                                }
                                else
                                {
                                    ngay_sinh = Convert.ToDateTime(sNgaySinh);
                                    namsinh = ngay_sinh.Year;
                                }
                            }
                            catch
                            {
                            }
                            objPatientInfo.PatientBirth = ngay_sinh;
                            objPatientInfo.YearOfBirth = (Int16) namsinh;
                        }
                        objPatientInfo.SoLo = Convert.ToInt32(txtLo.Text);

                        #endregion

                        #region Get PatientExam

                        objPatientExam = new TPatientExam();
                        objPatientExam.PatientCode = SoCMND;
                        objPatientExam.ObjectTypeId = 1;
                        objPatientExam.HosTrans = 0;
                        objPatientExam.InputDate = objPatientInfo.InputDate;
                        objPatientExam.UserId = objPatientInfo.UserId;
                        objPatientExam.HosStatus = 0;
                        objPatientExam.DiscountRate = 0;
                        objPatientExam.Locked = 0;
                        objPatientExam.IndentityNo = 1;
                        objPatientExam.DisplayOnReport = 0;
                        objPatientExam.NgayTao = objPatientInfo.NgayTao;
                        objPatientExam.NguoiTao = objPatientInfo.UserId;
                        objPatientExam.MaKhoaThien = "KSK";
                        objPatientExam.MaDoiTuong = "DV";
                        objPatientExam.EmergencyHos = 0;

                        #endregion

                        objAsignInfo.Barcode =
                            ChuanHoaChuoi(Utility.sDbnull(row.Cells[TAssignInfo.Columns.Barcode].Value, ""));

                        iSTT = iSTT + 1;

                        row.BeginEdit();
                        string sMaDonVi = "";
                        string errMsg = "";

                        if (
                            !_BussinessImportExcel.Save(objPatientInfo, objPatientExam, objAsignInfo, _lstAssignDetail,
                                dtNgayNhap.Value, sMaDonVi, ref errMsg))
                        {
                            row.Cells["_Error"].Value = 1;
                            _decFailed = _decFailed + 1;
                            Utility.ShowMsg(
                                "Import dữ liệu không thành công. Bạn hãy nhấn vào nút tìm kiếm theo lô và thực hiện xóa trước khi import lại.\n" +
                                errMsg);
                            return;
                        }
                        _Value = _Value + 1;
                        row.Cells["_Error"].Value = 0;
                        row.Cells["patient_code"].Value = objPatientExam.PatientCode;
                        row.Cells["patient_id"].Value = objPatientExam.PatientId;
                        row.Cells["assign_code"].Value = objAsignInfo.MaChidinh;
                        row.Cells["assign_id"].Value = objAsignInfo.AssignId;
                        row.EndEdit();
                        SetValue4Prg(progressImport, 1);
                        Application.DoEvents();
                        //if (iSTT % 10 == 0) System.Threading.Thread.Sleep(1000);
                        //Application.DoEvents();

                        #endregion
                    }
                    else
                    {
                        SetValue4Prg(progressImport, 1);
                        Application.DoEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMsg("Import dữ liệu không thành công" + ex.Message);
            }
        }
Пример #2
0
        public bool Save(TPatientInfo objPatientInfo, TPatientExam objPatientExam, TAssignInfo objAssignInfo, List<TAssignDetail> lstAssignDetail, DateTime dtNgayNhap, string MaDonVi,ref string errMsg)
        {
            Logger log = LogManager.GetCurrentClassLogger();    
            string PatientID = "";
            string PatientCode = "";
            string _AssignCode = "";
            SqlQuery query = null;
            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    using (SharedDbConnectionScope shs = new SubSonic.SharedDbConnectionScope())
                    {
                        TAssignInfoCollection _lstAssign=new Select().From(TAssignInfo.Schema)
                            .Where(TAssignInfo.Columns.Barcode).IsEqualTo(objAssignInfo.Barcode)
                            .And(TAssignInfo.Columns.RegDate).IsEqualTo(objAssignInfo.RegDate.Date)
                            .ExecuteAsCollection<TAssignInfoCollection>();
                        if (_lstAssign.Count > 0)
                        {
                            Utility.ShowMsg("Barcode " + objAssignInfo.Barcode + " đã được một bệnh nhân khác sử dụng trong ngày " + objAssignInfo.RegDate.Date.ToString("dd/MM/yyyy") + "\nĐề nghị bạn kiểm tra lại");
                            return false;
                        }
                        //PatientID = this.GetPatientID(dtNgayNhap.ToString("yyyyMMdd"), MaDonVi);
                        //PatientCode = this.GetPatientCode();
                        //Barcode = this.GetBarcode();
                        PatientCode = BusinessHelper.GeneratePatientCode();
                        _AssignCode = BusinessHelper.NOITIET_KetNoi_SinhMaBarCode_CD(objPatientExam.MaKhoaThien);
                        #region Save PatientInfo
                        //query = new Select().From(KskTPatientInfo.Schema).Where(KskTPatientInfo.Columns.PatientId).IsEqualTo(PatientID);
                        //if (query.GetRecordCount() > 0)
                        //{
                        //    PatientID = this.GetPatientID(dtNgayNhap.ToString("yyyyMMdd"), MaDonVi);
                        //}
                        //objPatientInfo.PatientId = PatientID;
                        if (objPatientInfo.IdentifyNum.Contains("@")) objPatientInfo.IdentifyNum = "";
                        objPatientInfo.IsNew = true;                        
                        objPatientInfo.Save();
                        #endregion

                        #region Save PatientExam
                        objPatientExam.IsNew = true;
                        objPatientExam.PatientId = objPatientInfo.PatientId;
                        objPatientExam.PatientCode = PatientCode;
                        objPatientExam.Save();
                        query = new Select().From(TPatientExam.Schema)
                                    .Where(TPatientExam.Columns.PatientCode).IsEqualTo(PatientCode)
                                    .And(TPatientExam.Columns.PatientId).IsNotEqualTo(objPatientInfo.PatientId);
                        if (query.GetRecordCount() > 0)
                        {
                            //PatientCode = this.GetPatientCode();
                            PatientCode = BusinessHelper.GeneratePatientCode();
                            new Update(TPatientExam.Schema)
                                .Set(TPatientExam.Columns.PatientCode).EqualTo(PatientCode)
                                .Where(TPatientExam.Columns.PatientId).IsEqualTo(objPatientInfo.PatientId)
                                .And(TPatientExam.Columns.PatientCode).IsEqualTo(objPatientExam.PatientCode)
                                .Execute();
                        }
                        #endregion

                        #region Save AssignInfo
                        objAssignInfo.IsNew = true;
                        objAssignInfo.PatientCode = PatientCode;
                        objAssignInfo.PatientId = objPatientInfo.PatientId;
                        objAssignInfo.AssignCode = _AssignCode;
                        objAssignInfo.MaChidinh = _AssignCode;
                        objAssignInfo.Save();
                        query = new Select().From(TAssignInfo.Schema).Where(TAssignInfo.Columns.AssignCode).IsEqualTo(_AssignCode).And(TAssignInfo.Columns.PatientId).IsNotEqualTo(objPatientInfo.PatientId).And(TAssignInfo.Columns.PatientCode).IsNotEqualTo(PatientCode);
                        if (query.GetRecordCount() > 0)
                        {
                            //Barcode = this.GetBarcode();
                            _AssignCode = BusinessHelper.NOITIET_KetNoi_SinhMaBarCode_CD(objPatientExam.MaKhoaThien);
                            new Update(TAssignInfo.Schema)
                                .Set(TAssignInfo.Columns.AssignCode).EqualTo(_AssignCode)
                                .Set(TAssignInfo.Columns.MaChidinh).EqualTo(_AssignCode)
                                .Where(TAssignInfo.Columns.PatientCode).IsEqualTo(PatientCode)
                                .And(TAssignInfo.Columns.PatientId).IsNotEqualTo(objPatientInfo.PatientId)
                                .Execute();
                        }
                        #endregion

                        #region Save AssignDetail
                        for (int i = 0; i < lstAssignDetail.Count; i++)
                        {
                           
                            lstAssignDetail[i].IsNew = true;
                            lstAssignDetail[i].DaGuiCls=1;
                            lstAssignDetail[i].ModifyDate = BusinessHelper.GetSysDateTime();
                            lstAssignDetail[i].ModifyBy = globalVariables.UserName;
                            lstAssignDetail[i].NguoiGuiCls = globalVariables.UserName;
                            lstAssignDetail[i].NgayGuiCls = BusinessHelper.GetSysDateTime();
                            lstAssignDetail[i].AssignId = objAssignInfo.AssignId;
                            lstAssignDetail[i].Save();
                        }
                        #endregion
                    }
                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                log.Error(ex.Message);                    
                return false;
            }
            return true;
        }