Ejemplo n.º 1
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;
        }